00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef PLUGINRESOURCE_H
00011 #define PLUGINRESOURCE_H
00012
00013 #include "ExecutableAgent.h"
00014 #include "ExportAgent.h"
00015 #include "ImportAgent.h"
00016 #include "ObjectResource.h"
00017 #include "PlugIn.h"
00018 #include "PlugInManagerServices.h"
00019 #include "Resource.h"
00020
00021 #include <algorithm>
00022 #include <string>
00023 #include <vector>
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 class PlugInObject
00034 {
00035 public:
00036 class Args
00037 {
00038 public:
00039 Args() :
00040 mpPlugIn(NULL),
00041 mNeedToCreate(false) {}
00042
00043 Args(std::string plugInName) :
00044 mPlugInName(plugInName),
00045 mpPlugIn(NULL),
00046 mNeedToCreate(true) {}
00047
00048 Args(char* plugInName) :
00049 mPlugInName(plugInName),
00050 mpPlugIn(NULL),
00051 mNeedToCreate(true) {}
00052
00053 Args(PlugIn* pPlugIn) :
00054 mpPlugIn(pPlugIn),
00055 mNeedToCreate(false) {}
00056
00057 std::string mPlugInName;
00058 PlugIn* mpPlugIn;
00059 bool mNeedToCreate;
00060 };
00061
00062 PlugIn* obtainResource(const Args& args) const
00063 {
00064 if (args.mpPlugIn != NULL)
00065 {
00066 return args.mpPlugIn;
00067 }
00068 if (!args.mNeedToCreate)
00069 {
00070 return NULL;
00071 }
00072 Service<PlugInManagerServices> pPlugInManager;
00073 PlugIn* pPlugIn = pPlugInManager->createPlugIn(args.mPlugInName);
00074 return pPlugIn;
00075 }
00076
00077 void releaseResource(const Args& args, PlugIn* pPlugIn) const
00078 {
00079 Service<PlugInManagerServices> pPlugInManager;
00080 pPlugInManager->destroyPlugIn(pPlugIn);
00081 }
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 class PlugInResource : public Resource<PlugIn, PlugInObject>
00094 {
00095 public:
00096
00097
00098
00099 explicit PlugInResource() :
00100 Resource<PlugIn, PlugInObject>(PlugInObject::Args())
00101 {}
00102
00103
00104
00105
00106
00107
00108
00109 explicit PlugInResource(const std::string& plugInName) :
00110 Resource<PlugIn, PlugInObject>(PlugInObject::Args(plugInName))
00111 {}
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 explicit PlugInResource(PlugIn* pPlugIn) :
00122 Resource<PlugIn, PlugInObject>(pPlugIn, PlugInObject::Args(pPlugIn))
00123 {}
00124 };
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 class ExecutableResource : public FactoryResource<ExecutableAgent>
00135 {
00136 public:
00137
00138
00139
00140
00141
00142
00143
00144
00145 explicit ExecutableResource(Progress* pProgress = NULL, bool batch = true)
00146 {
00147 ExecutableAgent* pAgent = get();
00148 if (pAgent != NULL)
00149 {
00150 pAgent->instantiate(pProgress, batch);
00151 }
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 explicit ExecutableResource(const std::string& plugInName, const std::string& menuCommand = std::string(),
00163 Progress* pProgress = NULL, bool batch = true)
00164 {
00165 ExecutableAgent* pAgent = get();
00166 if (pAgent != NULL)
00167 {
00168 pAgent->instantiate(plugInName, menuCommand, pProgress, batch);
00169 }
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 explicit ExecutableResource(PlugIn* pPlugIn, const std::string& menuCommand = std::string(),
00181 Progress* pProgress = NULL, bool batch = true)
00182 {
00183 ExecutableAgent* pAgent = get();
00184 if (pAgent != NULL)
00185 {
00186 pAgent->instantiate(pPlugIn, menuCommand, pProgress, batch);
00187 }
00188 }
00189 };
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 class ImporterResource : public FactoryResource<ImportAgent>
00200 {
00201 public:
00202
00203
00204
00205
00206
00207
00208
00209
00210 ImporterResource(Progress* pProgress = NULL, bool batch = true)
00211 {
00212 ImportAgent* pAgent = get();
00213 if (pAgent != NULL)
00214 {
00215 pAgent->instantiate(pProgress, batch);
00216 }
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 ImporterResource(const std::string& importerName, Progress* pProgress = NULL, bool batch = true)
00228 {
00229 ImportAgent* pAgent = get();
00230 if (pAgent != NULL)
00231 {
00232 pAgent->instantiate(importerName, pProgress, batch);
00233 }
00234 }
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 ImporterResource(const std::string& importerName, const std::string& filename, Progress* pProgress = NULL,
00245 bool batch = true)
00246 {
00247 ImportAgent* pAgent = get();
00248 if (pAgent != NULL)
00249 {
00250 pAgent->instantiate(importerName, filename, pProgress, batch);
00251 }
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 ImporterResource(const std::string& importerName, const std::vector<std::string>& filenames,
00263 Progress* pProgress = NULL, bool batch = true)
00264 {
00265 ImportAgent* pAgent = get();
00266 if (pAgent != NULL)
00267 {
00268 pAgent->instantiate(importerName, filenames, pProgress, batch);
00269 }
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 ImporterResource(const std::string& importerName,
00281 const std::map<std::string, std::vector<ImportDescriptor*> >& datasets,
00282 Progress* pProgress = NULL, bool batch = true)
00283 {
00284 ImportAgent* pAgent = get();
00285 if (pAgent != NULL)
00286 {
00287 pAgent->instantiate(importerName, datasets, pProgress, batch);
00288 }
00289 }
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 ImporterResource(PlugIn* pPlugIn, const std::map<std::string, std::vector<ImportDescriptor*> >& descriptors,
00300 Progress* pProgress = NULL, bool batch = true)
00301 {
00302 ImportAgent* pAgent = get();
00303 if (pAgent != NULL)
00304 {
00305 pAgent->instantiate(pPlugIn, descriptors, pProgress, batch);
00306 }
00307 }
00308 };
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 class ExporterResource : public FactoryResource<ExportAgent>
00319 {
00320 public:
00321
00322
00323
00324
00325
00326
00327
00328
00329 ExporterResource(Progress* pProgress = NULL, bool batch = true)
00330 {
00331 ExportAgent* pAgent = get();
00332 if (pAgent != NULL)
00333 {
00334 pAgent->instantiate(pProgress, batch);
00335 }
00336 }
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346 ExporterResource(std::string exporterName, Progress* pProgress = NULL, bool batch = true)
00347 {
00348 ExportAgent* pAgent = get();
00349 if (pAgent != NULL)
00350 {
00351 pAgent->instantiate(exporterName, pProgress, batch);
00352 }
00353 }
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 ExporterResource(PlugIn* pPlugIn, Progress* pProgress = NULL, bool batch = true)
00364 {
00365 ExportAgent* pAgent = get();
00366 if (pAgent != NULL)
00367 {
00368 pAgent->instantiate(pPlugIn, pProgress, batch);
00369 }
00370 }
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 ExporterResource(std::string exporterName, SessionItem* pItem, FileDescriptor* pFileDescriptor,
00381 Progress* pProgress = NULL, bool batch = true)
00382 {
00383 ExportAgent* pAgent = get();
00384 if (pAgent != NULL)
00385 {
00386 pAgent->instantiate(exporterName, pItem, pFileDescriptor, pProgress, batch);
00387 }
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 ExporterResource(PlugIn* pPlugIn, SessionItem* pItem, FileDescriptor* pFileDescriptor,
00399 Progress* pProgress = NULL, bool batch = true)
00400 {
00401 ExportAgent* pAgent = get();
00402 if (pAgent != NULL)
00403 {
00404 pAgent->instantiate(pPlugIn, pItem, pFileDescriptor, pProgress, batch);
00405 }
00406 }
00407 };
00408
00409 #endif