CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
RxDynamicModule.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 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
44template<class T, class TInterface = T>
45class 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; }
66public:
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
97typedef 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) \
106OdRxModule* 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() \
122STATIC_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) \
139ODRX_DEFINE_STATIC_APPLICATION(moduleName, ModuleClassName)
140
145#define ODRX_END_STATIC_MODULE_MAP() \
146{ 0, 0 } };
147
151#define ODRX_DECLARE_EXTERN_STATIC_MODULE_MAP extern STATIC_MODULE_DESC g_ODRX_STATIC_MODULE_MAP[];
152
154
155#define ODRX_INIT_STATIC_MODULE_MAP() odrxInitStaticModuleMap(g_ODRX_STATIC_MODULE_MAP)
156
157#define ODRX_DEFINE_STATIC_MODULE(_UserModuleClass)\
158\
159 static OdRxModule* g_pSingletonModule##_UserModuleClass = 0;\
160\
161ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(_UserModuleClass)\
162{\
163 return OdRxStaticModule<_UserModuleClass >::createModule(szModuleName);\
164}
165
177template<class T, class TInterface = T>
179{
180 ODRX_HEAP_OPERATORS();
181
182 OdRefCounter m_nLockCount;
183 OdString m_sName;
184
185 OdRxPseudoStaticModule(const OdString& sName)
186 : m_nLockCount(0)
187 , m_sName(sName)
188 { }
189 void addRef()
190 {
191 ++m_nLockCount;
192 }
193 void release()
194 {
195 ODA_ASSERT(m_nLockCount);
196 --m_nLockCount;
197 if (m_nLockCount == 0){
198 delete this;
199 }
200 }
201 long numRefs() const { return m_nLockCount; }
202public:
209 void* sysData() { return 0; }
210
218 {
219 return new OdRxPseudoStaticModule(name);
220 }
221
225 void deleteModule() { delete this; }
226
230 OdString moduleName() const { return m_sName; }
231};
232
233// For internal use only
234#define ODRX_DEFINE_PSEUDO_STATIC_MODULE(_UserModuleClass)\
235 ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(_UserModuleClass)\
236{\
237 return OdRxPseudoStaticModule<_UserModuleClass >::createModule(szModuleName);\
238}
239
240#if defined(_TOOLKIT_IN_DLL_)
241
242//IR.111706. MacOS X dynamic library loading.
243#if defined(__GNUC__) && defined(__APPLE__) // GNU compiler MacOS X
244
245#define ODRX_STATIC_MODULE_PATH "{5CEAD1EF-4D33-48fe-99E4-E09176BCF088}/"
246
247#define ODRX_STATIC_APP_MODULE_NAME(AppName) (OdString(ODRX_STATIC_MODULE_PATH) + AppName + DEFAULT_MODULE_EXTENSION_DOT_W)
248
249void deleteModuleObject();
250
259template<class T, class TInterface = T>
260class OdRxMacModule : public T
261{
262 OdRefCounter m_nLockCount;
263 void *m_hModule;
264 const OdString m_name;
265
266 OdRxMacModule(void *hModule, const OdString name)
267 : m_nLockCount(0)
268 , m_hModule(hModule)
269 , m_name(name)
270 {}
271 void addRef()
272 {
273 ++m_nLockCount;
274 }
275 void release()
276 {
277 ODA_ASSERT(m_nLockCount);
278 --m_nLockCount;
279 }
280 long numRefs() const { return m_nLockCount; }
282public:
286 void* sysData() { return m_hModule; }
287
295 static OdRxMacModule* createModule(void *hModule, const OdString name)
296 {
297 return new OdRxMacModule(hModule, name);
298 }
299
303 void deleteModule()
304 {
305 deleteModuleObject();
306 delete this;
307 }
308
312 OdString moduleName() const
313 {
314 return m_name;
315 }
316};
317
321#define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass)\
322ODRX_ALLOC_OPERATORS()\
323 static OdRxModule* g_pSingletonModule = 0;\
324 extern "C" { \
325 __attribute__ ((visibility("default"))) \
326 OdRxModule* odrxCreateModuleObject(void *hModule, OdChar *name)\
327{\
328 if(!g_pSingletonModule)\
329{\
330 g_pSingletonModule = OdRxMacModule<_UserModuleClass >::createModule(hModule, name);\
331 hModule = NULL;\
332}\
333 return g_pSingletonModule;\
334}\
335 void odrxGetAPIVersion(int& nMajorVersion, int& nMinorVersion,\
336 int& nMajorBuildVersion, int& nMinorBuildVersion)\
337{\
338 nMajorVersion = TD_MAJOR_VERSION;\
339 nMinorVersion = TD_MINOR_VERSION;\
340 nMajorBuildVersion = TD_MAJOR_BUILD;\
341 nMinorBuildVersion = TD_MINOR_BUILD;\
342}\
343}\
344 void deleteModuleObject()\
345{\
346 g_pSingletonModule = NULL;\
347}
348
349#elif defined(__GNUC__) && !defined(_WIN32)
350
351#define ODRX_STATIC_MODULE_PATH "{5CEAD1EF-4D33-48fe-99E4-E09176BCF088}/"
352
353#define ODRX_STATIC_APP_MODULE_NAME(AppName) (OdString(ODRX_STATIC_MODULE_PATH) + AppName + DEFAULT_MODULE_EXTENSION_DOT_W)
354
355void deleteModuleObject();
356
365template<class T, class TInterface = T>
366class OdRxUnixModule : public T
367{
368 OdRefCounter m_nLockCount;
369 void *m_hModule;
370 const OdString m_name;
371protected:
372 OdRxUnixModule(void *hModule, const OdString name)
373 : m_nLockCount(0)
374 , m_hModule(hModule)
375 , m_name(name)
376 {}
377private:
378 void addRef()
379 {
380 ++m_nLockCount;
381 }
382 void release()
383 {
384 ODA_ASSERT(m_nLockCount);
385 --m_nLockCount;
386 }
387 long numRefs() const { return m_nLockCount; }
389public:
393 void* sysData() { return m_hModule; }
394
402 static OdRxUnixModule* createModule(void *hModule, const OdString name)
403 {
404 return new OdRxUnixModule(hModule, name);
405 }
406
410 void deleteModule()
411 {
412 deleteModuleObject();
413 delete this;
414 }
415
419 OdString moduleName() const
420 {
421 return m_name;
422 }
423};
424
429#define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass)\
430ODRX_ALLOC_OPERATORS()\
431 static OdRxModule* g_pSingletonModule = 0;\
432\
433class OdRxUnixModule##_UserModuleClass : public OdRxUnixModule<_UserModuleClass>\
434{\
435 ODRX_HEAP_OPERATORS();\
436 OdRxUnixModule##_UserModuleClass(void *hModule, const OdString name)\
437 : OdRxUnixModule<_UserModuleClass>(hModule, name)\
438 {\
439 }\
440public:\
441 static _UserModuleClass* createModule(void *hModule, const OdString name) \
442 { \
443 return new OdRxUnixModule##_UserModuleClass(hModule, name);\
444 }\
445\
446 virtual void deleteModule()\
447 {\
448 g_pSingletonModule = 0;\
449 delete this;\
450 }\
451};\
452\
453 extern "C" { \
454 __attribute__ ((visibility("default"))) \
455 OdRxModule* odrxCreateModuleObject(void *hModule, OdChar *name)\
456{\
457 if(!g_pSingletonModule)\
458{\
459 g_pSingletonModule = OdRxUnixModule##_UserModuleClass::createModule(hModule, name);\
460 hModule = NULL;\
461}\
462 return g_pSingletonModule;\
463}\
464 __attribute__ ((visibility("default"))) \
465 void odrxGetAPIVersion(int& nMajorVersion, int& nMinorVersion,\
466 int& nMajorBuildVersion, int& nMinorBuildVersion)\
467{\
468 nMajorVersion = TD_MAJOR_VERSION;\
469 nMinorVersion = TD_MINOR_VERSION;\
470 nMajorBuildVersion = TD_MAJOR_BUILD;\
471 nMinorBuildVersion = TD_MINOR_BUILD;\
472}\
473}\
474 void deleteModuleObject()\
475{\
476 g_pSingletonModule = NULL;\
477}\
478
479#else //defined(__GNUC__)
480
481#define ODRX_STATIC_MODULE_PATH "{5CEAD1EF-4D33-48fe-99E4-E09176BCF088}/"
482
483#define ODRX_STATIC_APP_MODULE_NAME(AppName) (OdString(ODRX_STATIC_MODULE_PATH) + AppName + DEFAULT_MODULE_EXTENSION_DOT_W)
484
485#ifdef __BORLANDC__
486
487
496template<class T, class TInterface = T>
497class OdRxWin32Module : public T
498{
499 OdRefCounter m_nLockCount;
500 HMODULE m_hModule;
501 const OdString m_sModuleName;
502 OdRxWin32Module() : m_nLockCount(0) { }
503 void addRef()
504 {
505 ++m_nLockCount;
506 }
507 void release()
508 {
509 ODA_ASSERT(m_nLockCount);
510 --m_nLockCount;
511 }
512 long numRefs() const { return m_nLockCount; }
513 OdRxWin32Module(HMODULE hModule , const OdString name )
514 : m_nLockCount(0)
515 , m_hModule(hModule)
516 , m_sModuleName(name)
517 {}
519public:
523 void* sysData() { return reinterpret_cast<void*>(m_hModule); }
524
532 static OdRxWin32Module* createModule(HMODULE hModule, const OdString name ) { return new OdRxWin32Module(hModule,name); }
533
537 void deleteModule()
538 {
539 g_pSingletonModule = 0;
540 delete this;
541 }
542
546 OdString moduleName() const
547 {
548 return m_sModuleName;
549 }
550};
551
555#define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass)\
556ODRX_ALLOC_OPERATORS()\
557static OdRxModule* g_pSingletonModule = 0;\
558 extern "C" {\
559__declspec(dllexport) OdRxModule* odrxCreateModuleObject(HMODULE& hModule, const OdChar *name)\
560{\
561 if(!g_pSingletonModule)\
562 {\
563 g_pSingletonModule = OdRxWin32Module<_UserModuleClass >::createModule(hModule, name);\
564 hModule = 0;\
565 }\
566 return g_pSingletonModule;\
567}\
568__declspec(dllexport) void odrxGetAPIVersion(int& nMajorVersion, int& nMinorVersion,\
569 int& nMajorBuildVersion, int& nMinorBuildVersion)\
570{\
571 nMajorVersion = TD_MAJOR_VERSION;\
572 nMinorVersion = TD_MINOR_VERSION;\
573 nMajorBuildVersion = TD_MAJOR_BUILD;\
574 nMinorBuildVersion = TD_MINOR_BUILD;\
575}\
576}\
577
578#else //__BORLANDC__
579
580void deleteModuleObject();
581
590template<class T, class TInterface = T>
591class OdRxWin32Module : public T
592{
593 OdRefCounter m_nLockCount;
594 HMODULE m_hModule;
595 OdRxWin32Module() : m_nLockCount(0) { }
596 void addRef()
597 {
598 ++m_nLockCount;
599 }
600 void release()
601 {
602 ODA_ASSERT(m_nLockCount);
603 --m_nLockCount;
604 }
605 long numRefs() const { return m_nLockCount; }
606 OdRxWin32Module(HMODULE hModule )
607 : m_nLockCount(0)
608 , m_hModule(hModule)
609 {}
611public:
615 void* sysData() { return reinterpret_cast<void*>(m_hModule); }
616
624 static OdRxWin32Module* createModule(HMODULE hModule) { return new OdRxWin32Module(hModule); }
625
629 void deleteModule()
630 {
631 deleteModuleObject();
632 delete this;
633 }
634
638 OdString moduleName() const
639 {
640 wchar_t buffer[_MAX_PATH];
641 ::GetModuleFileNameW(m_hModule, buffer, _MAX_PATH );
642 return buffer;
643 }
644};
645
646
650#define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass)\
651ODRX_ALLOC_OPERATORS()\
652static OdRxModule* g_pSingletonModule = 0;\
653 extern "C" {\
654__declspec(dllexport) OdRxModule* odrxCreateModuleObject(HMODULE& hModule)\
655{\
656 if(!g_pSingletonModule)\
657 {\
658 g_pSingletonModule = OdRxWin32Module<_UserModuleClass >::createModule(hModule);\
659 hModule = 0;\
660 }\
661 return g_pSingletonModule;\
662}\
663__declspec(dllexport) void odrxGetAPIVersion(int& nMajorVersion, int& nMinorVersion,\
664 int& nMajorBuildVersion, int& nMinorBuildVersion)\
665{\
666 nMajorVersion = TD_MAJOR_VERSION;\
667 nMinorVersion = TD_MINOR_VERSION;\
668 nMajorBuildVersion = TD_MAJOR_BUILD;\
669 nMinorBuildVersion = TD_MINOR_BUILD;\
670}\
671}\
672 void deleteModuleObject()\
673{\
674 g_pSingletonModule = NULL;\
675}
676
677#endif //__BORLANDC__
678
679
680
681#endif //defined(__GNUC__) && defined(__APPLE__)
682
683# define ODRX_GET_MODULE_OBJECT(_UserModuleClass) g_pSingletonModule
684
685#else //#ifdef _TOOLKIT_IN_DLL_ ////////////////////////////////////////////////////////////////////////////////
686
687#define ODRX_STATIC_MODULE_PATH ""
688
689#define ODRX_STATIC_APP_MODULE_NAME(AppName) AppName
690
691#define ODRX_DEFINE_DYNAMIC_MODULE(_UserModuleClass) ODRX_DEFINE_STATIC_MODULE(_UserModuleClass)
692
693# define ODRX_GET_MODULE_OBJECT(_UserModuleClass) g_pSingletonModule##_UserModuleClass
694
695
696#endif //#ifdef _TOOLKIT_IN_DLL_ ////////////////////////////////////////////////////////////////////////////////
697
698
699
700#if defined(_TOOLKIT_IN_DLL_) && (defined(_MSC_VER) || (defined(_WIN32) && defined(__GNUC__)))
701
705#define DISABLE_THREAD_LIBRARY_CALLS()\
706extern "C" int APIENTRY DllMain(HINSTANCE h, DWORD reason, LPVOID ) {\
707 if(reason==DLL_PROCESS_ATTACH)\
708 DisableThreadLibraryCalls((HMODULE)h);\
709 return TRUE;\
710}
711
712#else
713
714#define DISABLE_THREAD_LIBRARY_CALLS()
715
716#endif //#if defined(_TOOLKIT_IN_DLL_) && defined(_MSC_VER)
717
718
719#include "TD_PackPop.h"
720
721#endif // _OD_RXDYNAMICMODULE_H_
722
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:57
#define ODRX_HEAP_OPERATORS()
Definition: OdHeap.h:76
int OdRefCounter
Definition: OdMutex.h:487
#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
static OdRxModule * createModule(const OdString &name)
OdString moduleName() const
GLuint buffer
Definition: gles2_ext.h:178
GLuint const GLchar * name
Definition: gles2_ext.h:265
StaticModuleEntryPoint entryPoint
const wchar_t * szAppName