00001 #ifndef PluginsH
00002 #define PluginsH
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00038
00039
00040 #include <Graphics.hpp>
00041 #include <controls.hpp>
00042 #include <extctrls.hpp>
00043 #include <vector>
00044
00045 #include "CoreMainHeader.h"
00046 #include "SmallString.h"
00047 #include "SimpleList.h"
00048 #include "ExtendedUUID.h"
00049 #include "DynamicPackage.h"
00050 #include "EventSystem.h"
00051 #include "RegistryUnit.h"
00052
00053
00054
00055 extern NEMESIS_CORE_PACKAGE class CPluginsDatabase PluginsDatabase;
00056
00057 DECLARE_EVENT(SET_NEW_LANGUAGE);
00058
00059
00060
00061
00062
00063 #define START_INIT void PACKAGE InitPoint(CPluginObjectDescription* descrip){
00064 #define INIT_OBJECT(object) if( descrip->GetObjectUUID() == object.GetObjectUUID() ) descrip->Connect(object);
00065 #define END_INIT }
00066
00067 #define START_INFO void PACKAGE InfoPoint(const CExtUUID& objectuuid,CExtUUID& category,Graphics::TIcon* icon){
00068 #define INFO_OBJECT(object,module) if( objectuuid == object.GetObjectUUID() ){category = object.GetCategory();if(icon)module->ImageList->GetIcon(object.GetImageIndex(),icon);}
00069 #define END_INFO }
00070
00071 #define START_DEPENDENCY void PACKAGE InitDependency(CPluginModule* p_module){ CExtUUID uuid;
00072 #define ADD_DEPENDENCY(object) if( uuid.LoadFromString(object) == true) p_module->AddDependencyPlugin(uuid);
00073 #define END_DEPENDENCY }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 class CComObject;
00095 class CVisObject;
00096 class CPluginObjectDescription;
00097 class CPluginModule;
00098 class CPluginObjectInfo;
00099
00100 typedef void* __fastcall (*_CCreateObject)(CPluginObjectInfo* objinfo,void* masterowner);
00101
00102 extern CPluginObjectInfo CoreGenericObjectInfo;
00103
00104
00105
00106
00107
00108
00109
00111
00117 class NEMESIS_CORE_PACKAGE CPluginObjectInfo{
00118 public:
00119 __fastcall CPluginObjectInfo(
00120 const CExtUUID& objectuuid,
00121 const CExtUUID& categoryuuid,
00122 const int imageindex,
00123 _CCreateObject createobject
00124 );
00125
00126
00127 inline const CSmallString __fastcall GetLocaleString(const CSmallString& univalue);
00128 inline const CExtUUID& __fastcall GetCategory(void) const;
00129 inline const CExtUUID& __fastcall GetObjectUUID(void) const;
00130 inline CPluginModule* __fastcall GetPluginModule(void) const;
00131 inline int __fastcall GetImageIndex(void) const;
00132 inline int __fastcall GetRealImageIndex(void) const;
00133
00134
00135
00136
00137
00138
00139 void __fastcall CreateObject(void);
00140 void __fastcall DestroyObject(void);
00141
00142
00143 private:
00144 CExtUUID ObjectUUID;
00145 CExtUUID CategoryUUID;
00146 const int ImageIndex;
00147 _CCreateObject CreateObjectPoint;
00148 CPluginObjectDescription* ObjectDescription;
00149
00150 friend class CPluginObjectDescription;
00151 };
00152
00153
00154
00156
00159 class NEMESIS_CORE_PACKAGE CPluginObjectDescription{
00160 public:
00161 __fastcall CPluginObjectDescription(CPluginModule* module,
00162 const CExtUUID& objectuuid,
00163 const CExtUUID& categoryuuid,
00164 int imageindex
00165 );
00166
00167 __fastcall ~CPluginObjectDescription(void);
00168
00169
00170
00171 inline const CSmallString& __fastcall GetName(void) const;
00172 inline const int __fastcall GetImage(void) const;
00173 inline const CSmallString& __fastcall GetCaption(void) const;
00174 inline const CSmallString& __fastcall GetHint(void) const;
00175 inline const CExtUUID& __fastcall GetCategory(void) const;
00176 inline const CExtUUID& __fastcall GetObjectUUID(void) const;
00177 inline int __fastcall GetObjectCount(void) const;
00178
00179
00180
00181 CComObject* __fastcall CreateComObject(void* masterowner);
00182 CVisObject* __fastcall CreateVisObject(void* masterowner);
00183
00184
00185
00186 inline CPluginModule* __fastcall GetPluginModule(void) const;
00187
00188
00189
00190
00191
00192 void __fastcall Connect(CPluginObjectInfo& info);
00193
00194
00195 private:
00196 CPluginModule* PluginModule;
00197 CPluginObjectInfo* ObjectInfo;
00198
00199 CExtUUID ObjectUUID;
00200 CExtUUID CategoryUUID;
00201
00202 int ImageIndex;
00203 int ObjectCounter;
00204
00205 _CCreateObject CreateObjectA;
00206
00207 void __fastcall ObjectIsBeforeCreate(void);
00208 void __fastcall ObjectIsDestroyed(void);
00209 void __fastcall UpdateLocalization(void);
00210
00211 friend class CPluginModule;
00212 friend class CPluginObjectInfo;
00213 };
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 typedef int _CInstallCallBackFunction;
00224
00225 typedef bool (*_CInstallPoint)(_CInstallCallBackFunction installfunction);
00226
00227
00228
00229 typedef bool (*_CInitPoint)(CPluginObjectDescription* descrip);
00230 typedef void (*_CAboutPoint)(void);
00231 typedef const CSmallString (*_CLocalePoint)(const CSmallString& univalue);
00232 typedef void (*_CInfoPoint)(const CExtUUID& objectuuid,CExtUUID& category,Graphics::TIcon* icon);
00233 typedef void (*_CInitializePlugin)(void);
00234 typedef void (*_CFinalizePlugin)(void);
00235 typedef void (*_CInitDependency)(CPluginModule* p_module);
00236
00237
00238
00239 class CPluginsDatabase;
00240
00242
00245 class NEMESIS_CORE_PACKAGE CPluginModule{
00246 public:
00247 enum EMode{
00248 ALWAYS_LOAD,
00249 LOAD_IN_USE,
00250 UNLOAD_ALWAYS,
00251 };
00252
00253
00254
00255 __fastcall CPluginModule(CPluginsDatabase* base,const CExtUUID& uuid);
00256 __fastcall ~CPluginModule(void);
00257
00258 bool __fastcall InitializeModule(EMode mode = UNLOAD_ALWAYS,bool temporary=false);
00259
00260
00261
00262 inline const CSmallString& __fastcall GetName(void) const;
00263 inline const CExtUUID& __fastcall GetPluginUUID(void) const;
00264 inline EMode __fastcall GetMode(void) const;
00265 void __fastcall About(void);
00266
00267
00268
00269 inline bool __fastcall IsModuleLoaded(void) const;
00270 inline bool __fastcall IsTemporary(void) const;
00271
00272
00273
00274 void __fastcall SetTemporaryStatus(bool temporary);
00275 void __fastcall SetMode(EMode mode);
00276 void __fastcall SetRemoveObjectStatus(bool status);
00277
00278
00279
00280 inline CSimpleList<CPluginObjectDescription>& __fastcall GetDescriptionList(void);
00281 CPluginObjectDescription* __fastcall FindDescription(const CSmallString& name);
00282 const CSmallString __fastcall GetLocaleString(const CSmallString& univalue);
00283
00284
00285
00286 void __fastcall TryUnload(void);
00287
00288
00289
00290
00291
00292
00293 void __fastcall AddDependencyPlugin(const CExtUUID& uuid);
00294
00295
00296 bool __fastcall SetLanguage(void);
00297 LCID __fastcall GetDefaultLanguage(void);
00298
00299
00300 private:
00301 CPluginsDatabase* DataBase;
00302
00303 CSimpleList<CPluginObjectDescription> PluginObjectDescriptions;
00304 CSmallString PluginName;
00305 CSmallString Path;
00306 CExtUUID PluginUUID;
00307 vector<CExtUUID> DependenciesList;
00308 CDynamicPackage Module;
00309 EMode Mode;
00310 bool Temporary;
00311 bool RemoveObject;
00312 int ObjectCounter;
00313 LCID DefaultLanguage;
00314
00315
00316 _CInitPoint InitPoint;
00317 _CAboutPoint AboutPoint;
00318 _CLocalePoint LocalePoint;
00319 _CInfoPoint InfoPoint;
00320 _CInitializePlugin InitializePlugin;
00321 _CFinalizePlugin FinalizePlugin;
00322 _CInitDependency InitDependency;
00323
00324
00325
00326 bool __fastcall LoadDataFromRegistry(void);
00327
00328 CPluginObjectDescription* __fastcall AddDescription(const CExtUUID& objectuuid,
00329 const CExtUUID& categoryuuid,
00330 int imageindex
00331 );
00332
00333 bool __fastcall LoadModule(bool only_load=false);
00334 void __fastcall UnloadModule(void);
00335 bool __fastcall LoadDependencyModules(void);
00336
00337
00338 bool __fastcall ConectAllDescription(void);
00339 bool __fastcall UpdateLocalization(void);
00340
00341 friend class CPluginObjectDescription;
00342 friend class CPluginObjectInfo;
00343 };
00344
00345
00346
00347
00348
00349 enum EPluginsChangeAction{
00350 MSG_PLUGIN_OBJECT_DESCRIPTION_CHANGE,
00351 MSG_PLUGIN_MODULE_CHANGE,
00352 };
00353
00354 typedef void __fastcall (__closure* TPluginsAction)(EPluginsChangeAction action,
00355 void* Sender);
00356
00357
00358
00360
00363 class NEMESIS_CORE_PACKAGE CPluginsDatabase{
00364 public:
00365
00366 __fastcall CPluginsDatabase(void);
00367 __fastcall ~CPluginsDatabase(void);
00368
00369
00370 bool __fastcall Init(void);
00371 bool __fastcall Clear(void);
00372
00373
00374 bool __fastcall SetLanguage(LCID language);
00375 CSmallString __fastcall GetCurrentLanguageString(void);
00376 CSmallString __fastcall GetLanguageString(LCID language);
00377 LCID __fastcall GetCurrentLanguage(void);
00378 CSmallString __fastcall GetLanguageResPath(void);
00379
00380 bool __fastcall StartEnumLanguages(void);
00381 bool __fastcall GetLanguage(LCID& lcid);
00382 void __fastcall EndEnumLanguages(void);
00383
00384
00385 const CExtUUID& __fastcall GetObjectCategory(const CUUID& object_uuid);
00386 bool __fastcall GetExtObjectType(const CUUID& object_uuid,CExtUUID& extobject_uuid);
00387
00388 CComObject* __fastcall CreateComObject(const CUUID& object_uuid,void* masterobject=NULL);
00389 CVisObject* __fastcall CreateVisObject(const CUUID& object_uuid,void* masterobject=NULL);
00390
00391 bool __fastcall FindObjectExt(const CSmallString& name,const CUUID& object_uuid,CUUID& ext_uuid);
00392 bool __fastcall FindObjectExtValue(const CSmallString& name,const CUUID& object_uuid,CSmallString& ext_value);
00393
00394
00395 CSmallString __fastcall GetModuleRegName(const CExtUUID& module_uuid);
00396 CSmallString __fastcall GetObjectRegName(const CUUID& object_uuid);
00397 CSmallString __fastcall GetObjectRegName(CPluginObjectDescription* p_pod);
00398
00399
00400
00401
00402 bool __fastcall LoadFromRegistry(void);
00403 bool __fastcall SaveToRegistry(void);
00404
00405
00406
00407 bool __fastcall AddPlugin(const CExtUUID& uuid,CPluginModule::EMode mode = CPluginModule::UNLOAD_ALWAYS,bool temp=false);
00408 bool __fastcall RemovePlugin(const CSmallString& name);
00409 void __fastcall SetFlushTimeForUnload(unsigned int time);
00410
00411
00412
00413 CSimpleList<CPluginModule>& __fastcall GetModuleList(void);
00414 CSimpleList<CPluginObjectDescription>& __fastcall GetPluginDescriptionList(void);
00415 TImageList* __fastcall GetImageList(void);
00416 TImageList* __fastcall GetLargeImageList(void);
00417 inline const CSmallString& __fastcall GetExtensionsList(void) const;
00418
00419
00420
00421 int __fastcall AddImage(Graphics::TIcon* icon);
00422
00423 bool __fastcall CompletePluginsDatabase(void);
00424
00425 bool __fastcall ReleaseTemporaryPlugins(void);
00426
00427
00428
00429 void __fastcall NotifyDescriptionChange(CPluginObjectDescription* changedobject);
00430 void __fastcall NotifyModuleChange(CPluginModule* changedmodule);
00431
00432
00433 private:
00434 CSimpleList<CPluginModule> PluginModules;
00435 CSimpleList<CPluginObjectDescription> ObjectDescriptions;
00436 TImageList* ImageList;
00437 TImageList* LargeImageList;
00438 TTimer* FlushTimer;
00439 TPluginsAction FOnAction;
00440 CSmallString PluginsPath;
00441 CSmallString MainKeyPath;
00442 CSmallString UserKeyPath;
00443 CSmallString ExtensionsList;
00444
00445
00446 LCID CurrentLanguage;
00447 CSmallString LanguageResPath;
00448 CSmallString MainProgramName;
00449 LCID MainProgramDefLanguage;
00450 CRegistry LangReg;
00451 int LangIndex;
00452
00453 void __fastcall OnFlushTimer(TObject* Sender);
00454 bool __fastcall SetMainProgramLanguage(void);
00455
00456 friend class CPluginModule;
00457
00458
00459
00460 public:
00461 __property TPluginsAction OnAction = {read=FOnAction, write=FOnAction};
00462 };
00463
00464
00465
00466
00467
00468
00469
00470
00471 const CSmallString __fastcall CPluginObjectInfo::GetLocaleString(const CSmallString& univalue)
00472 {
00473 return(ObjectDescription->GetPluginModule()->GetLocaleString(univalue));
00474 }
00475
00476
00477
00478 const CExtUUID& __fastcall CPluginObjectInfo::GetCategory(void) const
00479 {
00480 return(CategoryUUID);
00481 }
00482
00483
00484
00485 const CExtUUID& __fastcall CPluginObjectInfo::GetObjectUUID(void) const
00486 {
00487 return(ObjectUUID);
00488 }
00489
00490
00491
00492 inline CPluginModule* __fastcall CPluginObjectInfo::GetPluginModule(void) const
00493 {
00494 return(ObjectDescription->GetPluginModule());
00495 }
00496
00497
00498
00499 inline int __fastcall CPluginObjectInfo::GetImageIndex(void) const
00500 {
00501 return(ImageIndex);
00502 }
00503
00504
00505
00506 inline int __fastcall CPluginObjectInfo::GetRealImageIndex(void) const
00507 {
00508 if( ObjectDescription == NULL ) return(-1);
00509 return(ObjectDescription->GetImage());
00510 }
00511
00512
00513
00514
00515
00516
00517 inline const CSmallString& __fastcall CPluginObjectDescription::GetName(void) const
00518 {
00519 return(ObjectUUID.GetClassName());
00520 }
00521
00522
00523
00524 inline const int __fastcall CPluginObjectDescription::GetImage(void) const
00525 {
00526 return(ImageIndex);
00527 }
00528
00529
00530
00531 inline const CSmallString& __fastcall CPluginObjectDescription::GetCaption(void) const
00532 {
00533 return(ObjectUUID.GetLocaleClassName());
00534 }
00535
00536
00537
00538 inline const CSmallString& __fastcall CPluginObjectDescription::GetHint(void) const
00539 {
00540 return(ObjectUUID.GetLocaleClassHint());
00541 }
00542
00543
00544
00545 inline const CExtUUID& __fastcall CPluginObjectDescription::GetCategory(void) const
00546 {
00547 return(CategoryUUID);
00548 }
00549
00550
00551
00552 inline const CExtUUID& __fastcall CPluginObjectDescription::GetObjectUUID(void) const
00553 {
00554 return(ObjectUUID);
00555 }
00556
00557
00558
00559 inline int __fastcall CPluginObjectDescription::GetObjectCount(void) const
00560 {
00561 return(ObjectCounter);
00562 }
00563
00564
00565
00566 inline CPluginModule* __fastcall CPluginObjectDescription::GetPluginModule(void) const
00567 {
00568 return(PluginModule);
00569 }
00570
00571
00572
00573
00574
00575 inline const CSmallString& __fastcall CPluginModule::GetName(void) const
00576 {
00577 return(PluginName);
00578 }
00579
00580
00581
00582 inline CPluginModule::EMode __fastcall CPluginModule::GetMode(void) const
00583 {
00584 return(Mode);
00585 }
00586
00587
00588
00589 inline const CExtUUID& __fastcall CPluginModule::GetPluginUUID(void) const
00590 {
00591 return(PluginUUID);
00592 }
00593
00594
00595
00596 inline bool __fastcall CPluginModule::IsModuleLoaded(void) const
00597 {
00598 return(Module != NULL);
00599 }
00600
00601
00602
00603 inline bool __fastcall CPluginModule::IsTemporary(void) const
00604 {
00605 return(Temporary);
00606 }
00607
00608
00609
00610 inline CSimpleList<CPluginObjectDescription>& __fastcall CPluginModule::GetDescriptionList(void)
00611 {
00612 return(PluginObjectDescriptions);
00613 }
00614
00615
00616
00617 inline CSimpleList<CPluginModule>& __fastcall CPluginsDatabase::GetModuleList(void)
00618 {
00619 return(PluginModules);
00620 }
00621
00622
00623
00624 inline CSimpleList<CPluginObjectDescription>& __fastcall CPluginsDatabase::GetPluginDescriptionList(void)
00625 {
00626 return(ObjectDescriptions);
00627 }
00628
00629
00630
00631 inline TImageList* __fastcall CPluginsDatabase::GetImageList(void)
00632 {
00633 return(ImageList);
00634 }
00635
00636
00637
00638 inline TImageList* __fastcall CPluginsDatabase::GetLargeImageList(void)
00639 {
00640 return(LargeImageList);
00641 }
00642
00643
00644
00645 inline const CSmallString& __fastcall CPluginsDatabase::GetExtensionsList(void) const
00646 {
00647 return(ExtensionsList);
00648 }
00649
00650
00651
00652 #endif