1 mday 1.1 //%////-*-c++-*-////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mday 1.1 //
23 // Author: Mike Day (mdday@us.ibm.com) <<< Wed Mar 13 20:49:40 2002 mdd >>>
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #ifndef Pegasus_Module_Controller_h
30 #define Pegasus_Module_Controller_h
31
32 #include <Pegasus/Common/Config.h>
33 #include <Pegasus/Common/Message.h>
34 #include <Pegasus/Common/Exception.h>
35 #include <Pegasus/Common/IPC.h>
36 #include <Pegasus/Common/Thread.h>
37 #include <Pegasus/Common/AsyncOpNode.h>
38 #include <Pegasus/Common/Cimom.h>
39 #include <Pegasus/Common/CimomMessage.h>
40 #include <Pegasus/Common/MessageQueueService.h>
|
41 mday 1.14 #include <Pegasus/Common/peg_authorization.h>
|
42 mday 1.11
43
|
44 mday 1.1 PEGASUS_NAMESPACE_BEGIN
45
46 class ModuleController;
47
|
48 mday 1.9
|
49 mday 1.18 class PEGASUS_COMMON_LINKAGE pegasus_module
|
50 mday 1.9 {
51 private:
|
52 mday 1.18 class module_rep : public pegasus_auth_handle
|
53 mday 1.5 {
54 public:
|
55 mday 1.18 typedef pegasus_auth_handle Base;
56
|
57 mday 1.5 module_rep(ModuleController *controller,
58 const String & name,
59 void *module_address,
|
60 mday 1.10 Message * (*receive_message)(Message *, void *),
61 void (*async_callback)(Uint32, Message *, void *),
62 void (*shutdown_notify)(Uint32 code, void *));
|
63 mday 1.5
|
64 mday 1.9 ~module_rep(void) ;
65
|
66 mday 1.17 Boolean operator == (const module_rep *rep) const
|
67 mday 1.9 { if (rep == this ) return true; return false; }
|
68 mday 1.5
69 Boolean operator == (const module_rep &rep) const
|
70 mday 1.9 { if (rep == *this) return true; return false; }
|
71 mday 1.5
72 Boolean operator == (void *rep) const
|
73 mday 1.9 { if ( (void *)this == rep ) return true; return false; }
|
74 mday 1.5
75 void reference(void) { _reference_count++; }
76 void dereference(void) { _reference_count--; }
77 Uint32 reference_count(void) { return _reference_count.value(); }
78 const String & get_name(void) const { return _name; }
79 void *get_module_address(void) const { return _module_address; }
|
80 mday 1.9
81 Message * module_receive_message(Message *msg);
|
82 mday 1.5
|
83 mday 1.9 void _send_async_callback(Uint32 msg_handle, Message *msg);
|
84 mday 1.5
|
85 mday 1.9 void _send_shutdown_notify(void);
86 void lock(void) { _thread_safety.lock(pegasus_thread_self()); }
87 void unlock(void) { _thread_safety.unlock(); }
|
88 mday 1.18
89 Boolean authorized(void) ;
90 Boolean authorized(Uint32);
91 Boolean authorized(Uint32, Uint32);
92
|
93 mday 1.9 private:
|
94 mday 1.5 module_rep(void);
95 module_rep(const module_rep & );
|
96 mday 1.17 module_rep & operator= (const module_rep & rep);
|
97 mday 1.9
|
98 mday 1.17
|
99 mday 1.5 Mutex _thread_safety;
100 ModuleController *_controller;
101 String _name;
102 AtomicInt _reference_count;
|
103 mday 1.9 AtomicInt _shutting_down;
|
104 mday 1.6
|
105 mday 1.5 void *_module_address;
|
106 mday 1.10 Message * (*_receive_message)(Message *, void *);
107 void (*_async_callback)(Uint32, Message *, void *);
108 void (*_shutdown_notify)(Uint32 code, void *);
|
109 mday 1.5
|
110 mday 1.10 static Message * default_receive_message(Message *msg, void *inst)
|
111 mday 1.9 { throw NotImplemented("Module Receive");}
|
112 mday 1.5
|
113 mday 1.10 static void default_async_callback(Uint32 handle, Message *msg, void *inst)
|
114 mday 1.9 { throw NotImplemented("Module Async Receive"); }
|
115 mday 1.5
|
116 mday 1.10 static void default_shutdown_notify(Uint32 code, void *inst)
|
117 mday 1.9 { return; }
118
|
119 mday 1.10 static Message * closed_receive_message(Message *msg, void *inst)
|
120 mday 1.9 { throw ModuleClosed();}
121
|
122 mday 1.10 static void closed_async_callback(Uint32 handle, Message *msg, void *inst)
|
123 mday 1.9 { throw ModuleClosed(); }
|
124 mday 1.5
125 friend class ModuleController;
126 };
|
127 mday 1.7
|
128 mday 1.1 public:
|
129 mday 1.3 pegasus_module(ModuleController *controller,
130 const String &id,
131 void *module_address,
|
132 mday 1.10 Message * (*receive_message)(Message *, void *),
133 void (*async_callback)(Uint32, Message *, void *),
134 void (*shutdown_notify)(Uint32 code, void *)) ;
|
135 mday 1.5
|
136 mday 1.17 pegasus_module(const pegasus_module & mod);
137 pegasus_module & operator= (const pegasus_module & mod);
138
|
139 mday 1.18 virtual ~pegasus_module(void);
|
140 mday 1.3
|
141 mday 1.18 virtual Boolean authorized(Uint32 operation);
142 virtual Boolean authorized(void);
|
143 mday 1.16
|
144 mday 1.4 Boolean operator == (const pegasus_module *mod) const;
145 Boolean operator == (const pegasus_module & mod) const ;
146 Boolean operator == (const String & mod) const;
147 Boolean operator == (const void *mod) const;
148
|
149 mday 1.5 const String & get_name(void) const;
|
150 mday 1.3
|
151 mday 1.2 // introspection interface
|
152 mday 1.5 Boolean query_interface(const String & class_id, void **object_ptr) const;
|
153 mday 1.16
|
154 mday 1.1
155 private:
|
156 mday 1.18
|
157 mday 1.17 module_rep *_rep;
|
158 mday 1.3
159 pegasus_module(void);
|
160 mday 1.6 Boolean _rcv_msg(Message *) ;
|
161 mday 1.9 Message * _receive_message(Message *msg);
162 void _send_async_callback(Uint32 msg_handle, Message *msg) ;
163 void _send_shutdown_notify(void);
164 Boolean _shutdown(void);
|
165 mday 1.16 bitset<32> _allowed_operations;
|
166 mday 1.6
167 void reference(void) { _rep->reference(); }
168 void dereference(void) { _rep->dereference(); }
|
169 mday 1.5 friend class ModuleController;
170 };
|
171 mday 1.4
172
|
173 mday 1.1 class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService
174 {
175
|
176 mday 1.11
|
177 mday 1.1 public:
|
178 mday 1.5 typedef MessageQueueService Base;
|
179 mday 1.1
|
180 mday 1.14 static const Uint32 GET_CLIENT_HANDLE;
181 static const Uint32 REGISTER_MODULE;
182 static const Uint32 DEREGISTER_MODULE;
183 static const Uint32 FIND_SERVICE;
184 static const Uint32 FIND_MODULE_IN_SERVICE;
185 static const Uint32 GET_MODULE_REFERENCE;
186 static const Uint32 MODULE_SEND_WAIT;
187 static const Uint32 MODULE_SEND_WAIT_MODULE;
188 static const Uint32 MODULE_SEND_ASYNC;
189 static const Uint32 MODULE_SEND_ASYNC_MODULE;
190 static const Uint32 BLOCKING_THREAD_EXEC;
191 static const Uint32 ASYNC_THREAD_EXEC;
192 static const Uint32 CLIENT_SEND_WAIT;
193 static const Uint32 CLIENT_SEND_WAIT_MODULE;
194 static const Uint32 CLIENT_SEND_ASYNC;
195 static const Uint32 CLIENT_SEND_ASYNC_MODULE;
|
196 mday 1.15 static const Uint32 CLIENT_BLOCKING_THREAD_EXEC;
197 static const Uint32 CLIENT_ASYNC_THREAD_EXEC;
198
|
199 mday 1.14
|
200 mday 1.11 private:
|
201 mday 1.18 class client_handle : public pegasus_auth_handle
|
202 mday 1.11 {
203 public:
|
204 mday 1.18 typedef pegasus_auth_handle Base;
|
205 mday 1.14
|
206 mday 1.18 client_handle(const pegasus_identity & id)
207 :Base(id) ,
|
208 mday 1.16 allowed_operations( GET_CLIENT_HANDLE |
209 FIND_SERVICE |
210 FIND_MODULE_IN_SERVICE |
211 GET_MODULE_REFERENCE |
212 CLIENT_SEND_WAIT |
213 CLIENT_SEND_WAIT_MODULE |
214 CLIENT_SEND_ASYNC |
215 CLIENT_SEND_ASYNC_MODULE |
216 CLIENT_BLOCKING_THREAD_EXEC |
217 CLIENT_ASYNC_THREAD_EXEC)
218 {
219
220 }
221
|
222 mday 1.17 ~client_handle(void)
223 {
224 }
225
|
226 mday 1.18 virtual Boolean authorized(Uint32, Uint32);
|
227 mday 1.14 virtual Boolean authorized(Uint32 operation);
228 virtual Boolean authorized(void);
|
229 mday 1.18 bitset<32> allowed_operations;
|
230 mday 1.11
231 };
232
233 public:
234
235
|
236 mday 1.6 ModuleController(const char *name);
237 ModuleController(const char *name,
238 Sint16 min_threads,
239 Sint16 max_threads,
240 struct timeval & create_thread,
241 struct timeval & destroy_thread,
242 struct timeval & deadlock);
243
244
|
245 mday 1.7 ~ModuleController(void);
|
246 mday 1.1
|
247 mday 1.11 static ModuleController & get_client_handle(const String & controller_name,
248 void **handle);
249
250
|
251 mday 1.1 // module api
|
252 mday 1.9 static ModuleController & register_module(const String & controller_name,
253 const String & module_name,
254 void *module_address,
|
255 mday 1.10 Message * (*receive_message)(Message *, void *),
256 void (*async_callback)(Uint32, Message *, void *),
257 void (*shutdown_notify)(Uint32, void *),
258 pegasus_module **instance = NULL)
|
259 mday 1.9 throw(AlreadyExists, IncompatibleTypes);
|
260 mday 1.3
|
261 mday 1.11 Boolean deregister_module(const String & module_name)
262 throw(Permission);
|
263 mday 1.2
|
264 mday 1.7 Uint32 find_service(pegasus_module & handle, const String & name) throw(Permission);
|
265 mday 1.2
|
266 mday 1.7 Uint32 find_module_in_service(pegasus_module & handle,
267 const String & module_name)
268 throw(Permission, IPCException);
269
270
271 pegasus_module * get_module_reference(pegasus_module & my_handle,
272 const String & module_name)
273 throw(Permission);
|
274 mday 1.1
|
275 mday 1.2 // send a message to another service
|
276 mday 1.7 AsyncReply *ModuleSendWait(pegasus_module & handle,
|
277 mday 1.2 Uint32 destination_q,
|
278 mday 1.7 AsyncRequest *request) throw(Permission, IPCException);
|
279 mday 1.1
|
280 mday 1.2 // send a message to another module via another service
|
281 mday 1.7 AsyncReply *ModuleSendWait(pegasus_module & handle,
|
282 mday 1.2 Uint32 destination_q,
283 String & destination_module,
|
284 mday 1.7 AsyncRequest *message) throw(Permission, Deadlock, IPCException);
|
285 mday 1.2
|
286 mday 1.11 // send an async message to another service
|
287 mday 1.2 Boolean ModuleSendAsync(pegasus_module & handle,
|
288 mday 1.1 Uint32 msg_handle,
|
289 mday 1.2 Uint32 destination_q,
|
290 mday 1.9 AsyncRequest *message) throw(Permission, IPCException);
|
291 mday 1.1
|
292 mday 1.11 // send an async message to another module via another service
|
293 mday 1.2 Boolean ModuleSendAsync(pegasus_module & handle,
|
294 mday 1.1 Uint32 msg_handle,
|
295 mday 1.2 Uint32 destination_q,
296 String & destination_module,
|
297 mday 1.9 AsyncRequest *message) throw(Permission, IPCException);
|
298 mday 1.1
|
299 mday 1.7 void blocking_thread_exec(pegasus_module & handle,
300 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
301 void *parm) throw(Permission, Deadlock, IPCException);
302 void async_thread_exec(pegasus_module & handle,
303 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
304 void *parm) throw(Permission, Deadlock, IPCException);
|
305 mday 1.14
|
306 mday 1.7 Boolean verify_handle(pegasus_module *);
|
307 mday 1.1 protected:
|
308 kumpf 1.8 // ATTN-RK-P2-20010322: These methods are pure virtual in superclass
309 virtual void handleEnqueue(void) {}
310 virtual void handleEnqueue(Message *) {}
|
311 mday 1.9 virtual void _handle_async_request(AsyncRequest *rq);
312 virtual void _handle_async_callback(AsyncOpNode *op);
|
313 mday 1.1
314 private:
|
315 mday 1.7 static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
|
316 mday 1.2 DQueue<pegasus_module> _modules;
|
317 mday 1.1 ThreadPool _thread_pool;
|
318 mday 1.2 };
|
319 mday 1.1
320
|
321 mday 1.4
322
323
324
325
|
326 mday 1.1 PEGASUS_NAMESPACE_END
327
328
|
329 mday 1.4 #endif // Pegasus_Module_Controller_H
|