1 karl 1.39 //%2003////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.39 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
|
7 mike 1.2 //
|
8 mike 1.5 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 chip 1.30 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12 mike 1.2 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
|
14 kumpf 1.31 //
|
15 chip 1.30 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
16 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
18 chip 1.30 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
21 mike 1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Mike Day (mdday@us.ibm.com)
27 //
|
28 a.arora 1.40 // Modified By: Amit K Arora, IBM (amita@in.ibm.com) for Bug#1188
|
29 mike 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32
33 #ifndef Pegasus_AsyncOpNode_h
34 #define Pegasus_AsyncOpNode_h
35
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/Message.h>
38 #include <Pegasus/Common/OperationContext.h>
39 #include <Pegasus/Common/internal_dq.h>
40 #include <Pegasus/Common/IPC.h>
|
41 kumpf 1.35 #include <Pegasus/Common/Linkage.h>
|
42 mike 1.2
43 PEGASUS_NAMESPACE_BEGIN
|
44 mike 1.5
|
45 mike 1.2 #define ASYNC_OPFLAGS_UNKNOWN 0x00000000
46 #define ASYNC_OPFLAGS_INTERVAL_REPEAT 0x00000010
47 #define ASYNC_OPFLAGS_INDICATION 0x00000020
48 #define ASYNC_OPFLAGS_REMOTE 0x00000040
49 #define ASYNC_OPFLAGS_LOCAL_OUT_OF_PROC 0x00000080
50 #define ASYNC_OPFLAGS_PHASED 0x00000001
51 #define ASYNC_OPFLAGS_PARTIAL 0x00000002
52 #define ASYNC_OPFLAGS_NORMAL 0x00000000
53 #define ASYNC_OPFLAGS_SINGLE 0x00000008
54 #define ASYNC_OPFLAGS_MULTIPLE 0x00000010
55 #define ASYNC_OPFLAGS_TOTAL 0x00000020
|
56 mday 1.13 #define ASYNC_OPFLAGS_META_DISPATCHER 0x00000040
|
57 mday 1.17 #define ASYNC_OPFLAGS_FIRE_AND_FORGET 0x00000080
58 #define ASYNC_OPFLAGS_SIMPLE_STATUS 0x00000100
59 #define ASYNC_OPFLAGS_CALLBACK 0x00000200
|
60 mday 1.20 #define ASYNC_OPFLAGS_FORWARD 0x00000400
|
61 mday 1.24 #define ASYNC_OPFLAGS_PSEUDO_CALLBACK 0x00000800
|
62 mday 1.26 #define ASYNC_OPFLAGS_SAFE_CALLBACK 0x00001000
|
63 mike 1.2
64 #define ASYNC_OPSTATE_UNKNOWN 0x00000000
65 #define ASYNC_OPSTATE_OFFERED 0x00000001
66 #define ASYNC_OPSTATE_DECLINED 0x00000002
67 #define ASYNC_OPSTATE_STARTED 0x00000004
68 #define ASYNC_OPSTATE_PROCESSING 0x00000008
|
69 chip 1.30 #define ASYNC_OPSTATE_DELIVER 0x00000010
|
70 mike 1.2 #define ASYNC_OPSTATE_RESERVE 0x00000020
71 #define ASYNC_OPSTATE_COMPLETE 0x00000040
72 #define ASYNC_OPSTATE_TIMEOUT 0x00000080
73 #define ASYNC_OPSTATE_CANCELLED 0x00000100
74 #define ASYNC_OPSTATE_PAUSED 0x00000200
|
75 mday 1.12 #define ASYNC_OPSTATE_SUSPENDED 0x00000400
|
76 mday 1.3 #define ASYNC_OPSTATE_RESUMED 0x00000800
|
77 mday 1.8 #define ASYNC_OPSTATE_ORPHANED 0x00001000
|
78 mday 1.12 #define ASYNC_OPSTATE_RELEASED 0x00002000
|
79 mike 1.2
|
80 mday 1.8 class Cimom;
|
81 mday 1.23 class Thread;
|
82 mday 1.13
|
83 mike 1.2 class PEGASUS_COMMON_LINKAGE AsyncOpNode
84 {
|
85 mday 1.26
|
86 mday 1.38 // public:
87 // static void * operator new(size_t );
88 // static void operator delete( void *, size_t);
89 // private:
90 // static AsyncOpNode * _headOfFreeList;
91 // static const int BLOCK_SIZE;
92 // static Mutex _alloc_mut;
|
93 mike 1.2 public:
94
95 AsyncOpNode(void);
96 ~AsyncOpNode(void);
|
97 chip 1.30
|
98 mike 1.2 Boolean operator == (const void *key) const;
99 Boolean operator == (const AsyncOpNode & node) const;
|
100 mday 1.9
|
101 mday 1.12 void get_timeout_interval(struct timeval *buffer) ;
|
102 mday 1.9 void set_timeout_interval(const struct timeval *interval);
|
103 chip 1.30
|
104 mike 1.2 Boolean timeout(void) ;
105
106 OperationContext & get_context(void) ;
107
|
108 mday 1.4 void put_request(const Message *request) ;
|
109 mday 1.13 Message *get_request(void) ;
|
110 chip 1.30
|
111 mday 1.4 void put_response(const Message *response) ;
|
112 mday 1.13 Message *get_response(void) ;
|
113 chip 1.30
|
114 mike 1.2 Uint32 read_state(void) ;
115 void write_state(Uint32) ;
|
116 chip 1.30
|
117 mike 1.2 Uint32 read_flags(void);
118 void write_flags(Uint32);
|
119 chip 1.30
|
120 mike 1.2 void lock(void) throw(IPCException);
121 void unlock(void) throw(IPCException);
122 void udpate(void) throw(IPCException);
123 void deliver(const Uint32 count) throw(IPCException);
124 void reserve(const Uint32 size) throw(IPCException);
125 void processing(void) throw(IPCException) ;
126 void processing(OperationContext *context) throw(IPCException);
127 void complete(void) throw(IPCException) ;
128 void complete(OperationContext *context) throw(IPCException);
|
129 mday 1.12 void release(void);
|
130 mday 1.10 void wait(void);
|
131 chip 1.30
132
|
133 mike 1.2 private:
134 Semaphore _client_sem;
135 Mutex _mut;
|
136 mday 1.16 unlocked_dq<Message> _request;
|
137 chip 1.30 unlocked_dq<Message> _response;
138
|
139 mike 1.2 OperationContext _operation_list;
140 Uint32 _state;
141 Uint32 _flags;
142 Uint32 _offered_count;
143 Uint32 _total_ops;
144 Uint32 _completed_ops;
|
145 mday 1.15 Uint32 _user_data;
|
146 mday 1.17 Uint32 _completion_code;
|
147 mday 1.19 MessageQueue *_op_dest;
|
148 chip 1.30
|
149 mike 1.2 struct timeval _start;
150 struct timeval _lifetime;
151 struct timeval _updated;
152 struct timeval _timeout_interval;
153
154 AsyncOpNode *_parent;
155 unlocked_dq<AsyncOpNode> _children;
156
157 void _reset(unlocked_dq<AsyncOpNode> *dst_q);
158
|
159 mday 1.9 // the lifetime member is for cache management by the cimom
|
160 mike 1.2 void _set_lifetime(struct timeval *lifetime) ;
|
161 mday 1.12 Boolean _check_lifetime(void) ;
|
162 mike 1.2
163 Boolean _is_child(void) ;
164 Uint32 _is_parent(void) ;
165 Boolean _is_my_child(const AsyncOpNode & caller) const;
166 void _make_orphan( AsyncOpNode & parent) ;
167 void _adopt_child(AsyncOpNode *child) ;
168 void _disown_child(AsyncOpNode *child) ;
|
169 chip 1.30 void (*_async_callback)(AsyncOpNode *,
170 MessageQueue *,
|
171 mday 1.18 void *);
|
172 mday 1.26 void (*__async_callback)(Message *, void *, void *);
|
173 mday 1.23 // << Tue Mar 12 14:44:51 2002 mdd >>
|
174 chip 1.30 // pointers for async callbacks - don't use
|
175 mday 1.19 AsyncOpNode *_callback_node;
|
176 mday 1.21 MessageQueue *_callback_response_q;
|
177 mday 1.19 void *_callback_ptr;
|
178 mday 1.26 void *_callback_parameter;
179 void *_callback_handle;
|
180 mday 1.28 Condition *_callback_notify;
|
181 chip 1.30
|
182 mday 1.22 MessageQueue *_callback_request_q;
|
183 mday 1.23 // << Tue Mar 12 14:44:53 2002 mdd >>
|
184 chip 1.30 // pointers to help static class message handlers - don't use
|
185 mday 1.23 MessageQueue *_service_ptr;
186 Thread *_thread_ptr;
|
187 chip 1.30
|
188 mday 1.8 friend class cimom;
|
189 mday 1.10 friend class MessageQueueService;
|
190 mday 1.29 friend class ProviderManagerService;
|
191 mday 1.37 friend class BinaryMessageHandler;
|
192 mday 1.32 public:
193 // << Tue Jun 4 16:44:09 2002 mdd >>
194 // debug artifact
195 Uint32 _source_queue;
|
196 mday 1.34 // << Fri Jul 19 08:41:45 2002 mdd >>
197 // debugging utility
198 // careful - wipes out current value of *buf
199 void print_to_buffer(Sint8 **buf);
|
200 a.arora 1.40 String print_to_string(void);
|
201 mike 1.2 };
202
203
204 inline Boolean AsyncOpNode::operator == (const void *key) const
205 {
206 if (key == (void *)this)
207 return true;
208 return false;
209 }
210
211 inline Boolean AsyncOpNode::operator == (const AsyncOpNode & node) const
212 {
213 return AsyncOpNode::operator==((const void *)&node);
214 }
215
|
216 mday 1.9
|
217 chip 1.30 inline void AsyncOpNode::get_timeout_interval(struct timeval *buffer)
|
218 mday 1.9 {
219 if(buffer != 0)
220 {
|
221 mday 1.12 _mut.lock( pegasus_thread_self() );
|
222 mday 1.9 buffer->tv_sec = _timeout_interval.tv_sec;
223 buffer->tv_usec = _timeout_interval.tv_usec;
|
224 mday 1.12 _mut.unlock();
|
225 mday 1.9 }
226 return;
227 }
228
229 inline void AsyncOpNode::set_timeout_interval(const struct timeval *interval)
230 {
231 if(interval != 0)
232 {
|
233 mday 1.12 _mut.lock(pegasus_thread_self());
|
234 mday 1.9 _timeout_interval.tv_sec = interval->tv_sec;
235 _timeout_interval.tv_usec = interval->tv_usec;
|
236 mday 1.12 gettimeofday(&_updated, NULL);
237 _mut.unlock();
|
238 mday 1.9 }
239 }
240
241
|
242 chip 1.30 inline Boolean AsyncOpNode::timeout(void)
|
243 mike 1.2 {
244 struct timeval now;
245 gettimeofday(&now, NULL);
|
246 mday 1.12 Boolean ret = false;
247 _mut.lock(pegasus_thread_self());
|
248 mday 1.15 if((_updated.tv_sec + _timeout_interval.tv_sec ) < now.tv_sec)
249 if((_updated.tv_usec + _timeout_interval.tv_usec ) < now.tv_usec)
|
250 mday 1.12 ret = true;
251 _mut.unlock();
252 return ret;
|
253 mike 1.2 }
254
|
255 mday 1.4 // context is now a locked list
|
256 mday 1.3 inline OperationContext & AsyncOpNode::get_context(void)
|
257 mike 1.2 {
|
258 mday 1.9 gettimeofday(&_updated, NULL);
|
259 mike 1.2 return _operation_list;
260 }
261
|
262 mday 1.16
|
263 chip 1.30 inline void AsyncOpNode::put_request(const Message *request)
|
264 mike 1.2 {
|
265 mday 1.12 _mut.lock(pegasus_thread_self());
|
266 mday 1.9 gettimeofday(&_updated, NULL);
|
267 mday 1.21 if( false == _request.exists(reinterpret_cast<void *>(const_cast<Message *>(request))) )
|
268 mday 1.16 _request.insert_last( const_cast<Message *>(request) ) ;
|
269 mday 1.15
|
270 mday 1.16 // _request = const_cast<Message *>(request);
|
271 chip 1.30
|
272 mday 1.12 _mut.unlock();
|
273 mike 1.2 }
274
|
275 chip 1.30 inline Message * AsyncOpNode::get_request(void)
|
276 mike 1.2 {
|
277 mday 1.12 Message *ret;
278 _mut.lock(pegasus_thread_self());
|
279 mday 1.9 gettimeofday(&_updated, NULL);
|
280 mday 1.16 ret = _request.remove_first() ;
|
281 mday 1.12 _mut.unlock();
282 return ret;
|
283 mike 1.2 }
284
|
285 chip 1.30 inline void AsyncOpNode::put_response(const Message *response)
|
286 mike 1.2 {
|
287 mday 1.12 _mut.lock(pegasus_thread_self());
|
288 mday 1.9 gettimeofday(&_updated, NULL);
|
289 mday 1.21 if (false == _response.exists(reinterpret_cast<void *>(const_cast<Message *>(response))))
|
290 mday 1.16 _response.insert_last( const_cast<Message *>(response) );
|
291 mday 1.12 _mut.unlock();
|
292 mike 1.2 }
293
|
294 chip 1.30 inline Message * AsyncOpNode::get_response(void)
|
295 mike 1.2 {
|
296 mday 1.12 Message *ret;
297
298 _mut.lock(pegasus_thread_self());
|
299 mday 1.15 // gettimeofday(&_updated, NULL);
|
300 mday 1.16 ret = _response.remove_first();
301 // ret = _response;
|
302 chip 1.30
|
303 mday 1.12 _mut.unlock();
304 return ret;
|
305 mike 1.2 }
306
307 inline Uint32 AsyncOpNode::read_state(void)
308 {
|
309 mday 1.12 _mut.lock(pegasus_thread_self());
|
310 mday 1.9 gettimeofday(&_updated, NULL);
|
311 mday 1.12 Uint32 ret = _state;
312 _mut.unlock();
313 return ret;
|
314 chip 1.30
|
315 mike 1.2 }
316
317 inline void AsyncOpNode::write_state(Uint32 state)
318 {
|
319 mday 1.12 _mut.lock(pegasus_thread_self());
|
320 mday 1.9 gettimeofday(&_updated, NULL);
|
321 mike 1.2 _state = state;
|
322 mday 1.12 _mut.unlock();
|
323 mike 1.2 }
324
325 inline Uint32 AsyncOpNode::read_flags(void)
326 {
|
327 mday 1.12 _mut.lock(pegasus_thread_self());
|
328 mday 1.9 gettimeofday(&_updated, NULL);
|
329 mday 1.12 Uint32 ret = _flags;
330 _mut.unlock();
331 return ret;
|
332 mike 1.2 }
333
334 inline void AsyncOpNode::write_flags(Uint32 flags)
|
335 chip 1.30 {
|
336 mday 1.12 _mut.lock(pegasus_thread_self());
|
337 mday 1.9 gettimeofday(&_updated, NULL);
|
338 mike 1.2 _flags = flags;
|
339 mday 1.12 _mut.unlock();
|
340 mike 1.2 }
341
342
|
343 chip 1.30 inline void AsyncOpNode::lock(void)
344 throw(IPCException)
|
345 mike 1.2 {
346 _mut.lock(pegasus_thread_self());
347 }
348
|
349 chip 1.30 inline void AsyncOpNode::unlock(void)
350 throw(IPCException)
|
351 mike 1.2 {
352 _mut.unlock();
353 }
354
355 inline void AsyncOpNode::udpate(void)
356 throw(IPCException)
357 {
358 _mut.lock(pegasus_thread_self());
359 gettimeofday(&_updated, NULL);
360 _mut.unlock();
361 return;
362 }
363
|
364 chip 1.30 inline void AsyncOpNode::deliver(const Uint32 count)
|
365 mike 1.2 throw(IPCException)
366 {
367 _mut.lock(pegasus_thread_self());
368 _completed_ops = count;
|
369 mday 1.15 _state |= ASYNC_OPSTATE_DELIVER;
|
370 mike 1.2 gettimeofday(&_updated, NULL);
371 _mut.unlock();
372 return;
373 }
374
375 inline void AsyncOpNode::reserve(const Uint32 size)
376 throw(IPCException)
377 {
378 _mut.lock(pegasus_thread_self());
379 _total_ops = size;
|
380 mday 1.15 _state |= ASYNC_OPSTATE_RESERVE;
|
381 mike 1.2 gettimeofday(&_updated, NULL);
382 _mut.unlock();
383 return;
384 }
385
|
386 chip 1.30 inline void AsyncOpNode::processing(void)
|
387 mike 1.2 throw(IPCException)
388 {
389 _mut.lock(pegasus_thread_self());
|
390 mday 1.15 _state |= ASYNC_OPSTATE_PROCESSING;
|
391 mike 1.2 gettimeofday(&_updated, NULL);
392 _mut.unlock();
393 return;
394 }
395
396 // con will be empty upon return of this member function
|
397 chip 1.30 inline void AsyncOpNode::processing(OperationContext *con)
|
398 mike 1.2 throw(IPCException)
399 {
400 _mut.lock(pegasus_thread_self());
|
401 mday 1.15 _state |= ASYNC_OPSTATE_PROCESSING;
|
402 mike 1.2 gettimeofday(&_updated, NULL);
|
403 chip 1.30
404 /*
|
405 mike 1.2 context *c = con->remove_context();
406 while(c != 0)
407 {
408 _operation_list.add_context(c);
409 c = con->remove_context();
410 }
|
411 chip 1.30 */
|
412 mike 1.2 _mut.unlock();
413 return;
414 }
415
|
416 chip 1.30 inline void AsyncOpNode::complete(void)
|
417 mike 1.2 throw(IPCException)
418 {
419 _mut.lock(pegasus_thread_self());
|
420 mday 1.15 _state |= ASYNC_OPSTATE_COMPLETE;
|
421 mike 1.2 gettimeofday(&_updated, NULL);
422 _mut.unlock();
|
423 mday 1.12
|
424 mike 1.2 return;
425 }
426
427 inline void AsyncOpNode::complete(OperationContext *con)
428 throw(IPCException)
429 {
430 _mut.lock(pegasus_thread_self());
|
431 mday 1.15 _state |= ASYNC_OPSTATE_COMPLETE;
|
432 mike 1.2 gettimeofday(&_updated, NULL);
|
433 chip 1.30 /*
|
434 mike 1.2 context *c = con->remove_context();
435 while(c != 0)
436 {
437 _operation_list.add_context(c);
438 c = con->remove_context();
439 }
|
440 chip 1.30 */
|
441 mike 1.2 _mut.unlock();
|
442 mday 1.10 }
443
444 inline void AsyncOpNode::wait(void)
445 {
446 _client_sem.wait();
|
447 mike 1.2 }
448
|
449 mday 1.12 inline void AsyncOpNode::release(void)
450 {
451 _mut.lock(pegasus_thread_self());
452 _state |= ASYNC_OPSTATE_RELEASED;
453 _mut.unlock();
454 }
455
|
456 chip 1.30 inline void AsyncOpNode::_set_lifetime(struct timeval *lifetime)
|
457 mike 1.2 {
|
458 mday 1.12 _mut.lock(pegasus_thread_self());
|
459 mike 1.2 _lifetime.tv_sec = lifetime->tv_sec;
460 _lifetime.tv_usec = lifetime->tv_usec;
|
461 mday 1.12 _mut.unlock();
|
462 mike 1.2 }
463
|
464 chip 1.30 inline Boolean AsyncOpNode::_check_lifetime(void)
|
465 mike 1.2 {
466 struct timeval now;
|
467 chip 1.30
|
468 mike 1.2 gettimeofday(&now, NULL);
469 if((_start.tv_sec + _lifetime.tv_sec ) >= now.tv_sec)
470 if((_start.tv_usec + _lifetime.tv_usec ) >= now.tv_usec)
471 return true;
472 return false;
473 }
474
475 inline Boolean AsyncOpNode::_is_child(void)
476 {
477 if (_parent != 0)
478 return true;
479 return false;
480 }
481
482 inline Uint32 AsyncOpNode::_is_parent(void)
483 {
484 return _children.count();
485 }
486
487 inline Boolean AsyncOpNode::_is_my_child(const AsyncOpNode & caller) const
|
488 chip 1.30 {
|
489 mike 1.2 if ( _parent == &caller )
490 return true;
491 return false;
492 }
493
|
494 chip 1.30 inline void AsyncOpNode::_make_orphan( AsyncOpNode & parent)
|
495 mike 1.2 {
496 if( _parent == &parent )
497 {
498 _parent = NULL;
499 parent._children.remove(this);
500 }
501 else
502 throw Permission(pegasus_thread_self());
503 }
504
|
505 chip 1.30 inline void AsyncOpNode::_adopt_child(AsyncOpNode *child)
|
506 mike 1.2 {
507 if(child == NULL)
508 throw NullPointer();
509 if(true == child->_is_child())
510 throw Permission(pegasus_thread_self());
511 child->_parent = this;
512 _children.insert_last(child);
513 }
|
514 chip 1.30
|
515 mike 1.2 inline void AsyncOpNode::_disown_child(AsyncOpNode *child)
516 {
517 if(child == NULL)
518 throw NullPointer();
519 if( false == child->_is_child() || false == child->_is_my_child( *this ))
520 throw Permission(pegasus_thread_self());
521 child->_make_orphan( *this );
522 _children.remove(child);
|
523 chip 1.30 }
|
524 mike 1.2
525 PEGASUS_NAMESPACE_END
526
527 #endif //Pegasus_AsyncOpNode_h
|