1 martin 1.74 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.75 //
|
3 martin 1.74 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.75 //
|
10 martin 1.74 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.75 //
|
17 martin 1.74 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.75 //
|
20 martin 1.74 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.75 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.74 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.75 //
|
28 martin 1.74 //////////////////////////////////////////////////////////////////////////
|
29 mday 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "ModuleController.h"
|
33 kumpf 1.62 #include <Pegasus/Common/MessageLoader.h>
34 #include <Pegasus/Common/InternalException.h>
35
|
36 mday 1.1 PEGASUS_NAMESPACE_BEGIN
37
38 PEGASUS_USING_STD;
|
39 david.dillard 1.51
|
40 kumpf 1.62 RegisteredModuleHandle::RegisteredModuleHandle(
41 const String& name,
42 void* module_address,
|
43 venkat.puvvada 1.71 Message* (*receive_message)(Message *, void *))
|
44 kumpf 1.62 : _name(name),
45 _module_address(module_address),
|
46 venkat.puvvada 1.71 _module_receive_message(receive_message)
|
47 mday 1.6 {
|
48 kumpf 1.62 PEGASUS_ASSERT(_module_receive_message != 0);
|
49 mday 1.6 }
50
|
51 kumpf 1.62 RegisteredModuleHandle::~RegisteredModuleHandle()
|
52 mday 1.6 {
53 }
|
54 david.dillard 1.51
|
55 kumpf 1.62 const String & RegisteredModuleHandle::get_name() const
|
56 mday 1.6 {
|
57 kumpf 1.62 return _name;
|
58 mday 1.6 }
59
|
60 kumpf 1.65 Message* RegisteredModuleHandle::_receive_message(Message* msg)
|
61 mday 1.2 {
|
62 kumpf 1.62 return _module_receive_message(msg, _module_address);
|
63 mday 1.2 }
64
|
65 kumpf 1.65 ModuleController::ModuleController(const char* name)
|
66 venkat.puvvada 1.72 : Base(name),
|
67 kumpf 1.65 _modules()
|
68 david.dillard 1.51 {
|
69 mday 1.3 }
70
|
71 kumpf 1.5 ModuleController::~ModuleController()
72 {
|
73 kumpf 1.65 RegisteredModuleHandle* module;
|
74 kumpf 1.5
|
75 kumpf 1.65 try
76 {
77 module = _modules.remove_front();
78 while (module)
79 {
80 delete module;
81 module = _modules.remove_front();
82 }
83 }
84 catch (...)
85 {
86 }
|
87 kumpf 1.5 }
|
88 mday 1.3
|
89 venkat.puvvada 1.71 void ModuleController::register_module(
|
90 kumpf 1.65 const String& module_name,
91 void* module_address,
|
92 venkat.puvvada 1.71 Message* (*receive_message)(Message *, void *))
|
93 mday 1.3 {
|
94 kumpf 1.65 RegisteredModuleHandle *module;
|
95 venkat.puvvada 1.71 // see if the module already exists in this controller.
96 RegisteredModulesList::AutoLock lock(_modules);
97 module = _modules.front();
98 while (module != NULL)
|
99 kumpf 1.65 {
|
100 venkat.puvvada 1.71 if (module->get_name() == module_name)
|
101 kumpf 1.65 {
|
102 venkat.puvvada 1.71 MessageLoaderParms parms(
103 "Common.ModuleController.MODULE",
104 "module \"$0\"",
105 module_name);
106 throw AlreadyExistsException(parms);
|
107 kumpf 1.65 }
|
108 venkat.puvvada 1.71 module = _modules.next_of(module);
|
109 kumpf 1.65 }
110 // the module does not exist, go ahead and create it.
111 module = new RegisteredModuleHandle(
112 module_name,
113 module_address,
|
114 venkat.puvvada 1.71 receive_message);
115 _modules.insert_back(module);
|
116 mday 1.16 }
117
|
118 venkat.puvvada 1.80 void ModuleController::handleEnqueue(Message *message)
119 {
120 if (message->getType() == CIM_PROCESS_INDICATION_RESPONSE_MESSAGE)
121 {
122 CIMProcessIndicationResponseMessage *response =
123 (CIMProcessIndicationResponseMessage*)message;
124 PEGASUS_ASSERT(!response->oopAgentName.size());
125 IndicationRouter::notify(response);
126 return;
127 }
128 PEGASUS_ASSERT(false);
129 }
130
|
131 kumpf 1.65 void ModuleController::_handle_async_request(AsyncRequest* rq)
|
132 mday 1.6 {
|
133 kumpf 1.66 if (rq->getType() == ASYNC_ASYNC_MODULE_OP_START)
|
134 kumpf 1.65 {
|
135 venkat.puvvada 1.79 // find the target modules
|
136 kumpf 1.65 RegisteredModuleHandle* target;
137 Message* module_result = NULL;
138
|
139 venkat.puvvada 1.79 CIMRequestMessage *request =
140 static_cast<CIMRequestMessage*>(
141 static_cast<AsyncModuleOperationStart *>(rq)->_act);
142
143 MessageType reqType = request->getType();
144 if (reqType == CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE ||
145 reqType == CIM_SUBSCRIPTION_INIT_COMPLETE_REQUEST_MESSAGE ||
146 reqType == CIM_INDICATION_SERVICE_DISABLED_REQUEST_MESSAGE)
147 {
148 // Note: Since control providers are not loaded/unloaded
149 // dynamically, and the requests processed here arrives after
150 // registering the all control providers, acquiring the lock
151 // on modules list is not required.
152 // Process the request on each control provider by iterating
153 // through modules list. Since called functions returns null
154 // responses for these requests, build the single response after
155 // the request is processed with all control providers.
156 target = _modules.front();
157 while (target != NULL)
158 {
159 module_result = target->_receive_message(
160 venkat.puvvada 1.79 static_cast<AsyncModuleOperationStart *>(rq)->_act);
161 target = _modules.next_of(target);
162 }
163 module_result = request->buildResponse();
|
164 marek 1.81 // Do NOT remove the new operator !!!
165 // The constructor of AsyncModuleOperationResult does use its this
166 // pointer to put itself into a linked list
167 //
168 // see _res->put_async(this); in AsyncModuleOperationResult()
169 // in file pegasus/src/Pegasus/Common/CimomMessage.cpp
170 new AsyncModuleOperationResult(
|
171 venkat.puvvada 1.79 rq->op,
172 async_results::OK,
173 static_cast<AsyncModuleOperationStart *>(rq)->_target_module,
174 module_result);
175 _complete_op_node(rq->op);
176 return;
177 }
178
|
179 kumpf 1.65 {
|
180 venkat.puvvada 1.71 RegisteredModulesList::AutoLock lock(_modules);
|
181 kumpf 1.65 target = _modules.front();
182 while (target != NULL)
183 {
184 if (target->get_name() ==
185 static_cast<AsyncModuleOperationStart *>(rq)->
186 _target_module)
187 {
188 break;
189 }
190
191 target = _modules.next_of(target);
192 }
193 }
194
195 if (target)
196 {
197 // ATTN: This statement was taken out of the _module_lock block
198 // above because that caused all requests to control providers to
199 // be serialized. There is now a risk that the control provider
200 // module may be deleted after the lookup and before this call.
201 // See Bugzilla 3120.
202 kumpf 1.65 module_result = target->_receive_message(
203 static_cast<AsyncModuleOperationStart *>(rq)->_act);
204 }
205
206 if (module_result == NULL)
207 {
208 module_result = new AsyncReply(
|
209 kumpf 1.66 ASYNC_REPLY,
|
210 kumpf 1.65 MessageMask::ha_async | MessageMask::ha_reply,
211 rq->op,
|
212 venkat.puvvada 1.77 async_results::CIM_NAK);
|
213 kumpf 1.65 }
214
|
215 marek 1.81 // Do NOT remove the new operator !!!
216 // The constructor of AsyncModuleOperationResult does use its this
217 // pointer to put itself into a linked list
218 //
219 // see _res->put_async(this); in AsyncModuleOperationResult constructor
220 // in file pegasus/src/Pegasus/Common/CimomMessage.cpp
221 new AsyncModuleOperationResult(
|
222 kumpf 1.65 rq->op,
223 async_results::OK,
224 static_cast<AsyncModuleOperationStart *>(rq)->_target_module,
225 module_result);
|
226 venkat.puvvada 1.73 _complete_op_node(rq->op);
|
227 kumpf 1.65 }
228 else
229 Base::_handle_async_request(rq);
230 }
|
231 david.dillard 1.51
|
232 kumpf 1.65 void ModuleController::_handle_async_callback(AsyncOpNode* op)
233 {
234 Base::_handle_async_callback(op);
|
235 mday 1.6 }
|
236 mday 1.12
|
237 kumpf 1.59 ModuleController* ModuleController::getModuleController()
|
238 mday 1.16 {
|
239 kumpf 1.65 MessageQueue* messageQueue =
240 MessageQueue::lookup(PEGASUS_QUEUENAME_CONTROLSERVICE);
241 PEGASUS_ASSERT(messageQueue != 0);
242
243 MessageQueueService* service =
244 dynamic_cast<MessageQueueService*>(messageQueue);
245 PEGASUS_ASSERT(service != 0);
|
246 david.dillard 1.51
|
247 kumpf 1.65 return static_cast<ModuleController*>(service);
|
248 mday 1.16 }
249
|
250 kumpf 1.65 AsyncReply* ModuleController::ClientSendWait(
251 Uint32 destination_q,
252 AsyncRequest* request)
|
253 mday 1.16 {
|
254 venkat.puvvada 1.71 request->dest = destination_q;
255 AsyncReply* reply = Base::SendWait(request);
256 return reply;
|
257 mday 1.16 }
258
|
259 kumpf 1.59 Boolean ModuleController::ClientSendForget(
|
260 kumpf 1.65 Uint32 destination_q,
261 AsyncRequest* message)
|
262 mday 1.19 {
|
263 venkat.puvvada 1.71 message->dest = destination_q;
264 return SendForget(message);
|
265 mday 1.19 }
266
|
267 venkat.puvvada 1.80 void ModuleController::_indicationDeliveryRoutine(
|
268 venkat.puvvada 1.79 CIMProcessIndicationRequestMessage* request)
269 {
270 if (!request->operationContext.contains(AcceptLanguageListContainer::NAME))
271 {
272 request->operationContext.insert(
273 AcceptLanguageListContainer(AcceptLanguageList()));
274 }
275
276 ModuleController *mc = getModuleController();
277
278 Uint32 _indicationServiceQueueId = mc->find_service_qid(
279 PEGASUS_QUEUENAME_INDICATIONSERVICE);
280
|
281 venkat.puvvada 1.80 request->queueIds = QueueIdStack(
282 mc->getQueueId(), _indicationServiceQueueId);
|
283 venkat.puvvada 1.79
284 AsyncLegacyOperationStart * asyncRequest =
285 new AsyncLegacyOperationStart(
286 0,
287 _indicationServiceQueueId,
288 request);
289
290 mc->SendForget(asyncRequest);
291 }
292
|
293 venkat.puvvada 1.80 void ModuleController::indicationCallback(
294 CIMProcessIndicationRequestMessage* request)
295 {
296 IndicationRouter router =
297 IndicationRouter(request, _indicationDeliveryRoutine);
298
299 router.deliverAndWaitForStatus();
300 }
301
|
302 mday 1.1 PEGASUS_NAMESPACE_END
|