Subversion Repositories tpanel

Rev

Rev 21 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 97
Line 35... Line 35...
35
 
35
 
36
RESOURCE_LIST_T TPrjResources::findResourceType(const std::string& type)
36
RESOURCE_LIST_T TPrjResources::findResourceType(const std::string& type)
37
{
37
{
38
    DECL_TRACER("TPrjResources::findResourceType(const std::string& type)");
38
    DECL_TRACER("TPrjResources::findResourceType(const std::string& type)");
39
 
39
 
-
 
40
    if (mResources.size() == 0)
-
 
41
        return RESOURCE_LIST_T();
-
 
42
 
40
    vector<RESOURCE_LIST_T>::iterator iter;
43
    vector<RESOURCE_LIST_T>::iterator iter;
41
 
44
 
42
    for (iter = mResources.begin(); iter != mResources.end(); iter++)
45
    for (iter = mResources.begin(); iter != mResources.end(); iter++)
43
    {
46
    {
44
        if (iter->type.compare(type) == 0)
47
        if (iter->type.compare(type) == 0)
Line 116... Line 119...
116
    }
119
    }
117
 
120
 
118
    return RESOURCE_T();
121
    return RESOURCE_T();
119
}
122
}
120
 
123
 
-
 
124
size_t TPrjResources::getResourceIndex(const string& type)
-
 
125
{
-
 
126
    DECL_TRACER("TPrjResources::getResourceIndex(const string& type)");
-
 
127
 
-
 
128
    if (mResources.size() == 0)
-
 
129
        return npos;
-
 
130
 
-
 
131
    vector<RESOURCE_LIST_T>::iterator iter;
-
 
132
    size_t idx = 0;
-
 
133
 
-
 
134
    for (iter = mResources.begin(); iter != mResources.end(); iter++)
-
 
135
    {
-
 
136
        idx++;
-
 
137
 
-
 
138
        if (iter->type.compare(type) == 0)
-
 
139
            return idx;
-
 
140
    }
-
 
141
 
-
 
142
    return npos;
-
 
143
}
-
 
144
 
121
bool TPrjResources::setResource(const string& name, const string& scheme, const string& host, const string& path, const string& file, const string& user, const string& pw, int refresh)
145
bool TPrjResources::setResource(const string& name, const string& scheme, const string& host, const string& path, const string& file, const string& user, const string& pw, int refresh)
122
{
146
{
123
    DECL_TRACER("TPrjResources::setResource(const string& name, const string& scheme, const string& host, const string& path, const string& file, const string& user, const string& pw, int refresh)");
147
    DECL_TRACER("TPrjResources::setResource(const string& name, const string& scheme, const string& host, const string& path, const string& file, const string& user, const string& pw, int refresh)");
124
 
148
 
125
    if (mResources.size() == 0 || mResources[0].ressource.size() == 0)
149
    if (mResources.size() == 0)
126
        return false;
150
        return false;
127
 
151
 
-
 
152
    vector<RESOURCE_LIST_T>::iterator itRlist;
-
 
153
 
-
 
154
    for (itRlist = mResources.begin(); itRlist != mResources.end(); ++itRlist)
-
 
155
    {
-
 
156
        if (itRlist->type.compare("image") == 0)
-
 
157
            break;
-
 
158
    }
-
 
159
 
-
 
160
    if (itRlist == mResources.end())
-
 
161
    {
-
 
162
        MSG_ERROR("There was no resource type \"image\" found in the resources!");
-
 
163
        return false;
-
 
164
    }
-
 
165
 
128
    vector<RESOURCE_T> list = mResources[0].ressource;
166
    vector<RESOURCE_T> list = itRlist->ressource;
129
    vector<RESOURCE_T>::iterator iter;
167
    vector<RESOURCE_T>::iterator iter;
130
 
168
 
131
    for (iter = list.begin(); iter != list.end(); iter++)
169
    for (iter = list.begin(); iter != list.end(); iter++)
132
    {
170
    {
133
        if (iter->name.compare(name) == 0)
171
        if (iter->name.compare(name) == 0)
Line 155... Line 193...
155
            if (refresh >= 0)
193
            if (refresh >= 0)
156
                res.refresh = refresh;
194
                res.refresh = refresh;
157
 
195
 
158
            list.erase(iter);
196
            list.erase(iter);
159
            list.push_back(res);
197
            list.push_back(res);
160
            RESOURCE_LIST_T rlist = mResources[0];
-
 
-
 
198
 
161
            rlist.ressource.clear();
199
            itRlist->ressource.clear();
162
            rlist.ressource = list;
200
            itRlist->ressource = list;
163
            mResources.erase(mResources.begin());
-
 
164
            mResources.push_back(rlist);
-
 
165
            return true;
201
            return true;
166
        }
202
        }
167
    }
203
    }
168
 
204
 
169
    return false;
205
    return false;
170
}
206
}
-
 
207
 
-
 
208
bool TPrjResources::addResource(const string& name, const string& scheme, const string& host, const string& path, const string& file, const string& user, const string& pw, int refresh)
-
 
209
{
-
 
210
    DECL_TRACER("TPrjResources::addResource(const string& name, const string& scheme, const string& host, const string& path, const string& file, const string& user, const string& pw, int refresh)");
-
 
211
 
-
 
212
    vector<RESOURCE_LIST_T>::iterator itRlist;
-
 
213
 
-
 
214
    if (mResources.size() == 0)
-
 
215
    {
-
 
216
        RESOURCE_LIST_T rl;
-
 
217
        rl.type = "image";
-
 
218
        mResources.push_back(rl);
-
 
219
        itRlist = mResources.begin();
-
 
220
    }
-
 
221
    else
-
 
222
    {
-
 
223
        // Find the resource container
-
 
224
        for (itRlist = mResources.begin(); itRlist != mResources.end(); ++itRlist)
-
 
225
        {
-
 
226
            if (itRlist->type.compare("image") == 0)
-
 
227
                break;
-
 
228
        }
-
 
229
    }
-
 
230
 
-
 
231
    if (itRlist == mResources.end())
-
 
232
    {
-
 
233
        MSG_ERROR("There is no resouce container called \"image\"!");
-
 
234
        return false;
-
 
235
    }
-
 
236
 
-
 
237
    RESOURCE_T r;
-
 
238
    r.name = name;
-
 
239
    r.protocol = scheme;
-
 
240
    r.host = host;
-
 
241
    r.path = path;
-
 
242
    r.file = file;
-
 
243
    r.user = user;
-
 
244
    r.password = pw;
-
 
245
    r.refresh = refresh;
-
 
246
 
-
 
247
    // Make sure the resource does not already exist
-
 
248
    if (itRlist->ressource.size() == 0)
-
 
249
    {
-
 
250
        itRlist->ressource.push_back(r);
-
 
251
        return true;
-
 
252
    }
-
 
253
 
-
 
254
    vector<RESOURCE_T>::iterator iter;
-
 
255
 
-
 
256
    for (iter = itRlist->ressource.begin(); iter != itRlist->ressource.end(); iter++)
-
 
257
    {
-
 
258
        if (iter->name == name)
-
 
259
        {
-
 
260
            iter->protocol = scheme;
-
 
261
            iter->host = host;
-
 
262
            iter->path = path;
-
 
263
            iter->file = file;
-
 
264
            iter->user = user;
-
 
265
            iter->password = pw;
-
 
266
            iter->refresh = refresh;
-
 
267
            return true;
-
 
268
        }
-
 
269
    }
-
 
270
 
-
 
271
    itRlist->ressource.push_back(r);
-
 
272
    return true;
-
 
273
}