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 PEGASUS_NAMESPACE_BEGIN
42
43 mday 1.1 class ModuleController;
44
|
45 mday 1.9
46 class PEGASUS_COMMON_LINKAGE pegasus_module
47 {
48 private:
|
49 mday 1.5 class PEGASUS_COMMON_LINKAGE module_rep
50 {
51 public:
52 module_rep(ModuleController *controller,
53 const String & name,
54 void *module_address,
|
55 mday 1.7 Message * (*receive_message)(Message *),
|
56 mday 1.5 void (*async_callback)(Uint32, Message *),
|
57 mday 1.9 void (*shutdown_notify)(Uint32 code));
|
58 mday 1.5
|
59 mday 1.9 ~module_rep(void) ;
60
|
61 mday 1.5
62 Boolean operator == (const module_rep *rep) const
|
63 mday 1.9 { if (rep == this ) return true; return false; }
|
64 mday 1.5
65 Boolean operator == (const module_rep &rep) const
|
66 mday 1.9 { if (rep == *this) return true; return false; }
|
67 mday 1.5
68 Boolean operator == (void *rep) const
|
69 mday 1.9 { if ( (void *)this == rep ) return true; return false; }
|
70 mday 1.5
71 void reference(void) { _reference_count++; }
72 void dereference(void) { _reference_count--; }
73 Uint32 reference_count(void) { return _reference_count.value(); }
74 const String & get_name(void) const { return _name; }
75 void *get_module_address(void) const { return _module_address; }
|
76 mday 1.9
77 Message * module_receive_message(Message *msg);
|
78 mday 1.5
|
79 mday 1.9 void _send_async_callback(Uint32 msg_handle, Message *msg);
|
80 mday 1.5
|
81 mday 1.9 void _send_shutdown_notify(void);
82 void lock(void) { _thread_safety.lock(pegasus_thread_self()); }
83 void unlock(void) { _thread_safety.unlock(); }
84 private:
|
85 mday 1.5 module_rep(void);
86 module_rep(const module_rep & );
87 module_rep& operator= (const module_rep & );
|
88 mday 1.9
|
89 mday 1.5 Mutex _thread_safety;
90 ModuleController *_controller;
91 String _name;
92 AtomicInt _reference_count;
|
93 mday 1.9 AtomicInt _shutting_down;
|
94 mday 1.6
|
95 mday 1.5 void *_module_address;
|
96 mday 1.7 Message * (*_receive_message)(Message *);
|
97 mday 1.5 void (*_async_callback)(Uint32, Message *);
98 void (*_shutdown_notify)(Uint32 code);
99
|
100 mday 1.7 static Message * default_receive_message(Message *msg)
|
101 mday 1.9 { throw NotImplemented("Module Receive");}
|
102 mday 1.5
103 static void default_async_callback(Uint32 handle, Message *msg)
|
104 mday 1.9 { throw NotImplemented("Module Async Receive"); }
|
105 mday 1.5
106 static void default_shutdown_notify(Uint32 code)
|
107 mday 1.9 { return; }
108
109 static Message * closed_receive_message(Message *msg)
110 { throw ModuleClosed();}
111
112 static void closed_async_callback(Uint32 handle, Message *msg)
113 { throw ModuleClosed(); }
|
114 mday 1.5
115 friend class ModuleController;
116 };
|
117 mday 1.7
|
118 mday 1.1 public:
119
|
120 mday 1.3 pegasus_module(ModuleController *controller,
121 const String &id,
122 void *module_address,
|
123 mday 1.7 Message * (*receive_message)(Message *),
|
124 mday 1.5 void (*async_callback)(Uint32, Message *),
125 void (*shutdown_notify)(Uint32 code)) ;
126
|
127 mday 1.9 ~pegasus_module(void);
|
128 mday 1.3
|
129 mday 1.4 pegasus_module & operator= (const pegasus_module & mod);
130 Boolean operator == (const pegasus_module *mod) const;
131 Boolean operator == (const pegasus_module & mod) const ;
132 Boolean operator == (const String & mod) const;
133 Boolean operator == (const void *mod) const;
134
|
135 mday 1.5 const String & get_name(void) const;
|
136 mday 1.3
|
137 mday 1.2 // introspection interface
|
138 mday 1.5 Boolean query_interface(const String & class_id, void **object_ptr) const;
|
139 mday 1.1
140 private:
|
141 mday 1.3
142 module_rep *_rep;
143 pegasus_module(void);
|
144 mday 1.5 pegasus_module(const pegasus_module & mod);
|
145 mday 1.6 Boolean _rcv_msg(Message *) ;
|
146 mday 1.9 Message * _receive_message(Message *msg);
147 void _send_async_callback(Uint32 msg_handle, Message *msg) ;
148 void _send_shutdown_notify(void);
149 Boolean _shutdown(void);
|
150 mday 1.6
151 void reference(void) { _rep->reference(); }
152 void dereference(void) { _rep->dereference(); }
|
153 mday 1.5 friend class ModuleController;
154 };
|
155 mday 1.4
156
|
157 mday 1.1 class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService
158 {
159
160 public:
|
161 mday 1.5 typedef MessageQueueService Base;
|
162 mday 1.1
|
163 mday 1.6 ModuleController(const char *name);
164 ModuleController(const char *name,
165 Sint16 min_threads,
166 Sint16 max_threads,
167 struct timeval & create_thread,
168 struct timeval & destroy_thread,
169 struct timeval & deadlock);
170
171
|
172 mday 1.7 ~ModuleController(void);
|
173 mday 1.1
174 // module api
|
175 mday 1.9 static ModuleController & register_module(const String & controller_name,
176 const String & module_name,
177 void *module_address,
178 Message * (*receive_message)(Message *),
179 void (*async_callback)(Uint32, Message *),
180 void (*shutdown_notify)(Uint32))
181 throw(AlreadyExists, IncompatibleTypes);
|
182 mday 1.3
|
183 mday 1.5 Boolean deregister_module(const String & module_name);
|
184 mday 1.2
|
185 mday 1.7 Uint32 find_service(pegasus_module & handle, const String & name) throw(Permission);
|
186 mday 1.2
|
187 mday 1.7 Uint32 find_module_in_service(pegasus_module & handle,
188 const String & module_name)
189 throw(Permission, IPCException);
190
191
192 pegasus_module * get_module_reference(pegasus_module & my_handle,
193 const String & module_name)
194 throw(Permission);
|
195 mday 1.1
|
196 mday 1.2 // send a message to another service
|
197 mday 1.7 AsyncReply *ModuleSendWait(pegasus_module & handle,
|
198 mday 1.2 Uint32 destination_q,
|
199 mday 1.7 AsyncRequest *request) throw(Permission, IPCException);
|
200 mday 1.1
|
201 mday 1.2 // send a message to another module via another service
|
202 mday 1.7 AsyncReply *ModuleSendWait(pegasus_module & handle,
|
203 mday 1.2 Uint32 destination_q,
204 String & destination_module,
|
205 mday 1.7 AsyncRequest *message) throw(Permission, Deadlock, IPCException);
|
206 mday 1.2
207 // send a message to another service
208 Boolean ModuleSendAsync(pegasus_module & handle,
|
209 mday 1.1 Uint32 msg_handle,
|
210 mday 1.2 Uint32 destination_q,
|
211 mday 1.9 AsyncRequest *message) throw(Permission, IPCException);
|
212 mday 1.1
|
213 mday 1.2 // send a message to another module via another service
214 Boolean ModuleSendAsync(pegasus_module & handle,
|
215 mday 1.1 Uint32 msg_handle,
|
216 mday 1.2 Uint32 destination_q,
217 String & destination_module,
|
218 mday 1.9 AsyncRequest *message) throw(Permission, IPCException);
|
219 mday 1.1
|
220 mday 1.7 void blocking_thread_exec(pegasus_module & handle,
221 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
222 void *parm) throw(Permission, Deadlock, IPCException);
223 void async_thread_exec(pegasus_module & handle,
224 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
225 void *parm) throw(Permission, Deadlock, IPCException);
226 Boolean verify_handle(pegasus_module *);
|
227 mday 1.1 protected:
|
228 kumpf 1.8 // ATTN-RK-P2-20010322: These methods are pure virtual in superclass
229 virtual void handleEnqueue(void) {}
230 virtual void handleEnqueue(Message *) {}
|
231 mday 1.9 virtual void _handle_async_request(AsyncRequest *rq);
232 virtual void _handle_async_callback(AsyncOpNode *op);
|
233 mday 1.1
234 private:
|
235 mday 1.7 static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
|
236 mday 1.2 DQueue<pegasus_module> _modules;
|
237 mday 1.1 ThreadPool _thread_pool;
|
238 mday 1.2 };
|
239 mday 1.1
240
|
241 mday 1.4
242
243
244
245
|
246 mday 1.1 PEGASUS_NAMESPACE_END
247
248
|
249 mday 1.4 #endif // Pegasus_Module_Controller_H
|