1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#ifndef _SERVICEI_H
#define _SERVICEI_H
// here is where we define some helper implementations of the service factory
// interface
#include "service.h"
#include "waservicefactoryi.h"
#include "waservicefactorybase.h"
#include "waservicefactoryt.h"
#include "waservicefactorytsingle.h"
#include <bfc/ptrlist.h>
#include <bfc/foreach.h>
// DEPRECATED
#define waService waServiceFactory
#define waServiceT waServiceFactoryT
#define waServiceTSingle waServiceFactoryTSingle
// Declaring services via macros
// ie:
// BEGIN_SERVICES(YourClass_Svc)
// DECLARE_SERVICE(SomeSvcCreator<YourServiceClass1>);
// DECLARE_SERVICE(SomeSvcCreator<YourServiceClass2>);
// DECLARE_SERVICE(SomeSvcCreator<YourServiceClass3>);
// DECLARE_SERVICETMULTI(svc_serviceclass, YourMultiInstanceServiceClass1>);
// DECLARE_SERVICETMULTI(svc_serviceclass, YourMultiInstanceServiceClass2>);
// DECLARE_SERVICETMULTI(svc_serviceclass, YourMultiInstanceServiceClass3>);
// DECLARE_SERVICETSINGLE(svc_serviceclass, YourSingleInstanceServiceClass1>);
// DECLARE_SERVICETSINGLE(svc_serviceclass, YourSingleInstanceServiceClass2>);
// DECLARE_SERVICETSINGLE(svc_serviceclass, YourSingleInstanceServiceClass3>);
// END_SERVICES(YourClass_Svc, _YourClass_Svc);
// The macro DECLARE_MODULE_SVCMGR should be defined in your main cpp file if you are compiling
// a standalone exe without using the Application class. In this case you should also add
// MODULE_SVCMGR_ONINIT(); in your app startup and MODULE_SVCMGR_ONSHUTDOWN() in your app shutdown
// (class Application does this already)
// You can use BEGIN_SYS_SERVICES to declare a service that is initialized in priority and
// shutdown late (normal version inits late, shutdowns early)
class StaticServices {
public:
virtual void registerServices()=0;
virtual void unregisterServices()=0;
};
class AutoServiceList : public PtrList<StaticServices> {
public:
AutoServiceList()
{
#ifdef _WIN32 // PORT ME
OutputDebugStringA(">\n");
#endif
}
};
class StaticServiceMgr {
public:
AutoServiceList __m_modules;
AutoServiceList __m_modules2;
};
#define DECLARE_MODULE_SVCMGR StaticServiceMgr *staticServiceMgr = NULL;
extern StaticServiceMgr *staticServiceMgr;
#define MODULE_SVCMGR_ONINIT() { \
foreach(staticServiceMgr->__m_modules) \
staticServiceMgr->__m_modules.getfor()->registerServices(); \
endfor; \
}
#define MODULE_SVCMGR_ONINIT2() { \
foreach(staticServiceMgr->__m_modules2) \
staticServiceMgr->__m_modules2.getfor()->registerServices(); \
endfor; \
}
#define MODULE_SVCMGR_ONSHUTDOWN() { \
foreach(staticServiceMgr->__m_modules) \
staticServiceMgr->__m_modules.getfor()->unregisterServices(); \
endfor; \
}
#define MODULE_SVCMGR_ONSHUTDOWN2() { \
foreach(staticServiceMgr->__m_modules2) \
staticServiceMgr->__m_modules2.getfor()->unregisterServices(); \
endfor; \
}
#define INIT_MODULE_SVCMGR() \
if (!staticServiceMgr) staticServiceMgr = new StaticServiceMgr;
#define BEGIN_SERVICES(CLASSNAME) \
class CLASSNAME : public StaticServices { \
public: \
CLASSNAME() { \
INIT_MODULE_SVCMGR() \
staticServiceMgr->__m_modules.addItem(this); \
} \
virtual ~CLASSNAME() {} \
virtual void registerServices() { \
ASSERT(staticServiceMgr);
#define BEGIN_SERVICES_DEBUG(CLASSNAME, TEXT) \
class CLASSNAME : public StaticServices { \
public: \
CLASSNAME() { \
INIT_MODULE_SVCMGR() \
OutputDebugString("Registering "); \
OutputDebugString(TEXT); \
OutputDebugString("\n"); \
staticServiceMgr->__m_modules.addItem(this); \
} \
virtual ~CLASSNAME() {} \
virtual void registerServices() { \
ASSERT(staticServiceMgr);
#define BEGIN_SYS_SERVICES(CLASSNAME) \
class CLASSNAME : public StaticServices { \
public: \
CLASSNAME() { \
INIT_MODULE_SVCMGR() \
staticServiceMgr->__m_modules2.addItem(this); \
} \
virtual ~CLASSNAME() {} \
virtual void registerServices() {
#define DECLARE_SERVICE(INSTANTIATIONCODE) \
registerService(new INSTANTIATIONCODE);
#define DECLARE_SERVICE_DEBUG(INSTANTIATIONCODE, TEXT) \
OutputDebugString("Starting "); \
OutputDebugString(TEXT); \
OutputDebugString("\n"); \
registerService(new INSTANTIATIONCODE);
#define DECLARE_SERVICETMULTI(SVCTYPE, SVCCLASS) \
registerService(new waServiceFactoryT<SVCTYPE, SVCCLASS>);
#define DECLARE_SERVICETMULTI_DEBUG(SVCTYPE, SVCCLASS, TEXT) \
OutputDebugString("Starting "); \
OutputDebugString(TEXT); \
OutputDebugString("\n"); \
registerService(new waServiceFactoryT<SVCTYPE, SVCCLASS>);
#define DECLARE_SERVICETSINGLE(SVCTYPE, SVCCLASS) \
registerService(new waServiceFactoryTSingle<SVCTYPE, SVCCLASS>);
#define DECLARE_SERVICETSINGLE_DEBUG(SVCTYPE, SVCCLASS, TEXT) \
OutputDebugString("Starting "); \
OutputDebugString(TEXT); \
OutputDebugString("\n"); \
registerService(new waServiceFactoryTSingle<SVCTYPE, SVCCLASS>, TEXT);
#define END_SERVICES(CLASSNAME, INSTANCENAME) \
} \
virtual void unregisterServices() { \
foreach(services) \
waServiceFactoryI *svc = services.getfor(); \
WASABI_API_SVC->service_deregister(svc); \
delete svc; \
endfor; \
services.removeAll();\
} \
private: \
void registerService(waServiceFactoryI *svc) { \
if (svc != NULL) { \
services.addItem(svc); \
WASABI_API_SVC->service_register(svc); \
} \
} \
PtrList<waServiceFactoryI> services; \
}; \
CLASSNAME INSTANCENAME;
#endif
|