CFx SDK Documentation  2022 SP0
RxDynamicModule.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 
25 #ifndef _OD_RXDYNAMICMODULE_H_
26 #define _OD_RXDYNAMICMODULE_H_
27 
28 #include "RxModule.h"
29 #include "TDVersion.h"
30 #include "OdString.h"
31 #include "OdAllocOp.h"
33 
34 #include "TD_PackPush.h"
35 
44 template<class T, class TInterface = T>
45 class OdRxStaticModule : public T
46 {
47  ODRX_HEAP_OPERATORS();
48 
49  OdRefCounter m_nLockCount;
50  OdString m_sName;
51 
52  OdRxStaticModule(const OdString& sName)
53  : m_nLockCount(0)
54  , m_sName(sName)
55  { }
56  void addRef()
57  {
58  ++m_nLockCount;
59  }
60  void release()
61  {
62  ODA_ASSERT(m_nLockCount);
63  --m_nLockCount;
64  }
65  long numRefs() const { return m_nLockCount; }
66 public:
73  void* sysData() { return 0; }
74 
82  {
83  return new OdRxStaticModule(name);
84  }
85 
89  void deleteModule() { delete this; }
90 
94  OdString moduleName() const { return m_sName; }
95 };
96 
97 typedef OdRxModule* (*StaticModuleEntryPoint)(const OdString& szModuleName);
98 
99 #define ODRX_STATIC_MODULE_ENTRY_POINT(_UserModuleClass) odrxCreateModuleObject_For_##_UserModuleClass
100 
105 #define ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(_UserModuleClass) \
106 OdRxModule* ODRX_STATIC_MODULE_ENTRY_POINT(_UserModuleClass)(const OdString& szModuleName)
107 
112 {
113  const wchar_t* szAppName;
115 };
116 
121 #define ODRX_BEGIN_STATIC_MODULE_MAP() \
122 STATIC_MODULE_DESC g_ODRX_STATIC_MODULE_MAP[] = {
123 
133 #define ODRX_DEFINE_STATIC_APPLICATION(AppName, ModuleClassName) \
134 { AppName, ODRX_STATIC_MODULE_ENTRY_POINT(ModuleClassName) },
135 
138 #define ODRX_DEFINE_STATIC_APPMODULE(moduleName, ModuleClassName) \
139 ODRX_DEFINE_STATIC_APPLICATION(moduleName, ModuleClassName)
140 
145 #define ODRX_END_STATIC_MODULE_MAP() \
146 { 0, 0 } };
147 
149 
150 #define ODRX_INIT_STATIC_MODULE_MAP() odrxInitStaticModuleMap(g_ODRX_STATIC_MODULE_MAP)
151 
152 #define ODRX_DEFINE_STATIC_MODULE(_UserModuleClass)\
153 \
154  static OdRxModule* g_pSingletonModule##_UserModuleClass = 0;\
155 \
156 ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(_UserModuleClass)\
157 {\
158  return OdRxStaticModule<_UserModuleClass >::createModule(szModuleName);\
159 }
160 
172 template<class T, class TInterface = T>
173 class OdRxPseudoStaticModule : public T
174 {
175  ODRX_HEAP_OPERATORS();
176 
177  OdRefCounter m_nLockCount;
178  OdString m_sName;
179 
180  OdRxPseudoStaticModule(const OdString& sName)
181  : m_nLockCount(0)
182  , m_sName(sName)
183  { }
184  void addRef()
185  {
186  ++m_nLockCount;
187  }
188  void release()
189  {
190  ODA_ASSERT(m_nLockCount);
191  --m_nLockCount;
192  if (m_nLockCount == 0){
193  delete this;
194  }
195  }
196  long numRefs() const { return m_nLockCount; }
197 public:
204  void* sysData() { return 0; }
205 
213  {
214  return new OdRxPseudoStaticModule(name);
215  }
216 
220  void deleteModule() { delete this; }
221 
225  OdString moduleName() const { return m_sName; }
226 };
227 
228 // For internal use only
229 #define ODRX_DEFINE_PSEUDO_STATIC_MODULE(_UserModuleClass)\
230  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(_UserModuleClass)\
231 {\
232  return OdRxPseudoStaticModule<_UserModuleClass >::createModule(szModuleName);\
233 }
234 
235 #if defined(_TOOLKIT_IN_DLL_) && !defined(__MWERKS__)
236 
237 //IR.111706. MacOS X dynamic library loading.
238 #if defined(__GNUC__) && defined(__APPLE__) // GNU compiler MacOS X
239 
240 #define ODRX_STATIC_MODULE_PATH "{5CEAD1EF-4D33-48fe-99E4-E09176BCF088}/"
241 
242 #define ODRX_STATIC_APP_MODULE_NAME(AppName) (OdString(ODRX_STATIC_MODULE_PATH) + AppName + DEFAULT_MODULE_EXTENSION_DOT_W)
243 
244 void deleteModuleObject();
245 
254 template<class T, class TInterface = T>
255 class OdRxMacModule : public T
256 {
257  OdRefCounter m_nLockCount;
258  void *m_hModule;
259  const OdString m_name;
260 
261  OdRxMacModule(void *hModule, const OdString name)
262  : m_nLockCount(0)
263  , m_hModule(hModule)
264  , m_name(name)
265  {}
266  void addRef()
267  {
268  ++m_nLockCount;
269  }
270  void release()
271  {
272  ODA_ASSERT(m_nLockCount);
273  --m_nLockCount;
274  }
275  long numRefs() const { return m_nLockCount; }
277 public:
281  void* sysData() { return m_hModule; }
282 
290  static OdRxMacModule* createModule(void *hModule, const OdString name)
291  {
292  return new OdRxMacModule(hModule, name);
293  }
294 
298  void deleteModule()
299  {
300  deleteModuleObject();
301  delete this;
302  }
303 
307  OdString moduleName() const
308  {
309  return m_name;
310  }
311 };
312 
316 #define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass)\
317 ODRX_ALLOC_OPERATORS()\
318  static OdRxModule* g_pSingletonModule = 0;\
319  extern "C" { \
320  __attribute__ ((visibility("default"))) \
321  OdRxModule* odrxCreateModuleObject(void *hModule, OdChar *name)\
322 {\
323  if(!g_pSingletonModule)\
324 {\
325  g_pSingletonModule = OdRxMacModule<_UserModuleClass >::createModule(hModule, name);\
326  hModule = NULL;\
327 }\
328  return g_pSingletonModule;\
329 }\
330  void odrxGetAPIVersion(int& nMajorVersion, int& nMinorVersion,\
331  int& nMajorBuildVersion, int& nMinorBuildVersion)\
332 {\
333  nMajorVersion = TD_MAJOR_VERSION;\
334  nMinorVersion = TD_MINOR_VERSION;\
335  nMajorBuildVersion = TD_MAJOR_BUILD;\
336  nMinorBuildVersion = TD_MINOR_BUILD;\
337 }\
338 }\
339  void deleteModuleObject()\
340 {\
341  g_pSingletonModule = NULL;\
342 }
343 
344 #elif defined(__GNUC__) && !defined(_WIN32)
345 
346 #define ODRX_STATIC_MODULE_PATH "{5CEAD1EF-4D33-48fe-99E4-E09176BCF088}/"
347 
348 #define ODRX_STATIC_APP_MODULE_NAME(AppName) (OdString(ODRX_STATIC_MODULE_PATH) + AppName + DEFAULT_MODULE_EXTENSION_DOT_W)
349 
350 void deleteModuleObject();
351 
360 template<class T, class TInterface = T>
361 class OdRxUnixModule : public T
362 {
363  OdRefCounter m_nLockCount;
364  void *m_hModule;
365  const OdString m_name;
366 protected:
367  OdRxUnixModule(void *hModule, const OdString name)
368  : m_nLockCount(0)
369  , m_hModule(hModule)
370  , m_name(name)
371  {}
372 private:
373  void addRef()
374  {
375  ++m_nLockCount;
376  }
377  void release()
378  {
379  ODA_ASSERT(m_nLockCount);
380  --m_nLockCount;
381  }
382  long numRefs() const { return m_nLockCount; }
384 public:
388  void* sysData() { return m_hModule; }
389 
397  static OdRxUnixModule* createModule(void *hModule, const OdString name)
398  {
399  return new OdRxUnixModule(hModule, name);
400  }
401 
405  void deleteModule()
406  {
407  deleteModuleObject();
408  delete this;
409  }
410 
414  OdString moduleName() const
415  {
416  return m_name;
417  }
418 };
419 
424 #define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass)\
425 ODRX_ALLOC_OPERATORS()\
426  static OdRxModule* g_pSingletonModule = 0;\
427 \
428 class OdRxUnixModule##_UserModuleClass : public OdRxUnixModule<_UserModuleClass>\
429 {\
430  ODRX_HEAP_OPERATORS();\
431  OdRxUnixModule##_UserModuleClass(void *hModule, const OdString name)\
432  : OdRxUnixModule<_UserModuleClass>(hModule, name)\
433  {\
434  }\
435 public:\
436  static _UserModuleClass* createModule(void *hModule, const OdString name) \
437  { \
438  return new OdRxUnixModule##_UserModuleClass(hModule, name);\
439  }\
440 \
441  virtual void deleteModule()\
442  {\
443  g_pSingletonModule = 0;\
444  delete this;\
445  }\
446 };\
447 \
448  extern "C" { \
449  __attribute__ ((visibility("default"))) \
450  OdRxModule* odrxCreateModuleObject(void *hModule, OdChar *name)\
451 {\
452  if(!g_pSingletonModule)\
453 {\
454  g_pSingletonModule = OdRxUnixModule##_UserModuleClass::createModule(hModule, name);\
455  hModule = NULL;\
456 }\
457  return g_pSingletonModule;\
458 }\
459  __attribute__ ((visibility("default"))) \
460  void odrxGetAPIVersion(int& nMajorVersion, int& nMinorVersion,\
461  int& nMajorBuildVersion, int& nMinorBuildVersion)\
462 {\
463  nMajorVersion = TD_MAJOR_VERSION;\
464  nMinorVersion = TD_MINOR_VERSION;\
465  nMajorBuildVersion = TD_MAJOR_BUILD;\
466  nMinorBuildVersion = TD_MINOR_BUILD;\
467 }\
468 }\
469  void deleteModuleObject()\
470 {\
471  g_pSingletonModule = NULL;\
472 }\
473 
474 #else //defined(__GNUC__)
475 
476 #define ODRX_STATIC_MODULE_PATH "{5CEAD1EF-4D33-48fe-99E4-E09176BCF088}/"
477 
478 #define ODRX_STATIC_APP_MODULE_NAME(AppName) (OdString(ODRX_STATIC_MODULE_PATH) + AppName + DEFAULT_MODULE_EXTENSION_DOT_W)
479 
480 #ifdef __BORLANDC__
481 
482 
491 template<class T, class TInterface = T>
492 class OdRxWin32Module : public T
493 {
494  OdRefCounter m_nLockCount;
495  HMODULE m_hModule;
496  const OdString m_sModuleName;
497  OdRxWin32Module() : m_nLockCount(0) { }
498  void addRef()
499  {
500  ++m_nLockCount;
501  }
502  void release()
503  {
504  ODA_ASSERT(m_nLockCount);
505  --m_nLockCount;
506  }
507  long numRefs() const { return m_nLockCount; }
508  OdRxWin32Module(HMODULE hModule , const OdString name )
509  : m_nLockCount(0)
510  , m_hModule(hModule)
511  , m_sModuleName(name)
512  {}
514 public:
518  void* sysData() { return reinterpret_cast<void*>(m_hModule); }
519 
527  static OdRxWin32Module* createModule(HMODULE hModule, const OdString name ) { return new OdRxWin32Module(hModule,name); }
528 
532  void deleteModule()
533  {
534  g_pSingletonModule = 0;
535  delete this;
536  }
537 
541  OdString moduleName() const
542  {
543  return m_sModuleName;
544  }
545 };
546 
550 #define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass)\
551 ODRX_ALLOC_OPERATORS()\
552 static OdRxModule* g_pSingletonModule = 0;\
553  extern "C" {\
554 __declspec(dllexport) OdRxModule* odrxCreateModuleObject(HMODULE& hModule, const OdChar *name)\
555 {\
556  if(!g_pSingletonModule)\
557  {\
558  g_pSingletonModule = OdRxWin32Module<_UserModuleClass >::createModule(hModule, name);\
559  hModule = 0;\
560  }\
561  return g_pSingletonModule;\
562 }\
563 __declspec(dllexport) void odrxGetAPIVersion(int& nMajorVersion, int& nMinorVersion,\
564  int& nMajorBuildVersion, int& nMinorBuildVersion)\
565 {\
566  nMajorVersion = TD_MAJOR_VERSION;\
567  nMinorVersion = TD_MINOR_VERSION;\
568  nMajorBuildVersion = TD_MAJOR_BUILD;\
569  nMinorBuildVersion = TD_MINOR_BUILD;\
570 }\
571 }\
572 
573 #else //__BORLANDC__
574 
575 void deleteModuleObject();
576 
585 template<class T, class TInterface = T>
586 class OdRxWin32Module : public T
587 {
588  OdRefCounter m_nLockCount;
589  HMODULE m_hModule;
590  OdRxWin32Module() : m_nLockCount(0) { }
591  void addRef()
592  {
593  ++m_nLockCount;
594  }
595  void release()
596  {
597  ODA_ASSERT(m_nLockCount);
598  --m_nLockCount;
599  }
600  long numRefs() const { return m_nLockCount; }
601  OdRxWin32Module(HMODULE hModule )
602  : m_nLockCount(0)
603  , m_hModule(hModule)
604  {}
606 public:
610  void* sysData() { return reinterpret_cast<void*>(m_hModule); }
611 
619  static OdRxWin32Module* createModule(HMODULE hModule) { return new OdRxWin32Module(hModule); }
620 
624  void deleteModule()
625  {
626  deleteModuleObject();
627  delete this;
628  }
629 
633  OdString moduleName() const
634  {
635  wchar_t buffer[_MAX_PATH];
636  ::GetModuleFileNameW(m_hModule, buffer, _MAX_PATH );
637  return buffer;
638  }
639 };
640 
641 
645 #define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass)\
646 ODRX_ALLOC_OPERATORS()\
647 static OdRxModule* g_pSingletonModule = 0;\
648  extern "C" {\
649 __declspec(dllexport) OdRxModule* odrxCreateModuleObject(HMODULE& hModule)\
650 {\
651  if(!g_pSingletonModule)\
652  {\
653  g_pSingletonModule = OdRxWin32Module<_UserModuleClass >::createModule(hModule);\
654  hModule = 0;\
655  }\
656  return g_pSingletonModule;\
657 }\
658 __declspec(dllexport) void odrxGetAPIVersion(int& nMajorVersion, int& nMinorVersion,\
659  int& nMajorBuildVersion, int& nMinorBuildVersion)\
660 {\
661  nMajorVersion = TD_MAJOR_VERSION;\
662  nMinorVersion = TD_MINOR_VERSION;\
663  nMajorBuildVersion = TD_MAJOR_BUILD;\
664  nMinorBuildVersion = TD_MINOR_BUILD;\
665 }\
666 }\
667  void deleteModuleObject()\
668 {\
669  g_pSingletonModule = NULL;\
670 }
671 
672 #endif //__BORLANDC__
673 
674 
675 
676 #endif //defined(__GNUC__) && defined(__APPLE__)
677 
678 # define ODRX_GET_MODULE_OBJECT(_UserModuleClass) g_pSingletonModule
679 
680 #else //#ifdef _TOOLKIT_IN_DLL_ ////////////////////////////////////////////////////////////////////////////////
681 
682 #define ODRX_STATIC_MODULE_PATH ""
683 
684 #define ODRX_STATIC_APP_MODULE_NAME(AppName) AppName
685 
686 #define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass) ODRX_DEFINE_STATIC_MODULE(_UserModuleClass)
687 
688 # define ODRX_GET_MODULE_OBJECT(_UserModuleClass) g_pSingletonModule##_UserModuleClass
689 
690 
691 #endif //#ifdef _TOOLKIT_IN_DLL_ ////////////////////////////////////////////////////////////////////////////////
692 
693 
694 
695 #if defined(_TOOLKIT_IN_DLL_) && (defined(_MSC_VER) || (defined(_WIN32) && defined(__GNUC__)))
696 
700 #define DISABLE_THREAD_LIBRARY_CALLS()\
701 extern "C" int APIENTRY DllMain(HINSTANCE h, DWORD reason, LPVOID ) {\
702  if(reason==DLL_PROCESS_ATTACH)\
703  DisableThreadLibraryCalls((HMODULE)h);\
704  return TRUE;\
705 }
706 
707 #else
708 
709 #define DISABLE_THREAD_LIBRARY_CALLS()
710 
711 #endif //#if defined(_TOOLKIT_IN_DLL_) && defined(_MSC_VER)
712 
713 
714 #include "TD_PackPop.h"
715 
716 #endif // _OD_RXDYNAMICMODULE_H_
717 
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
#define ODRX_HEAP_OPERATORS()
Definition: OdHeap.h:74
int OdRefCounter
Definition: OdMutex.h:436
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
OdRxModule *(* StaticModuleEntryPoint)(const OdString &szModuleName)
FIRSTDLL_EXPORT void odrxInitStaticModuleMap(STATIC_MODULE_DESC *pMap)
static OdRxModule * createModule(const OdString &name)
OdString moduleName() const
OdString moduleName() const
static OdRxModule * createModule(const OdString &name)
GLuint buffer
Definition: gles2_ext.h:178
GLuint const GLchar * name
Definition: gles2_ext.h:265
StaticModuleEntryPoint entryPoint
const wchar_t * szAppName