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 a.arora 1.41 // Alagaraja Ramasubramanian (alags_raj@in.ibm.com) for Bug#1090
|
30 mike 1.2 //
31 //%/////////////////////////////////////////////////////////////////////////////
32
33
34 #ifndef Pegasus_AsyncOpNode_h
35 #define Pegasus_AsyncOpNode_h
36
37 #include <Pegasus/Common/Config.h>
38 #include <Pegasus/Common/Message.h>
39 #include <Pegasus/Common/OperationContext.h>
40 #include <Pegasus/Common/internal_dq.h>
41 #include <Pegasus/Common/IPC.h>
|
42 kumpf 1.35 #include <Pegasus/Common/Linkage.h>
|
43 mike 1.2
44 PEGASUS_NAMESPACE_BEGIN
|
45 mike 1.5
|
46 mike 1.2 #define ASYNC_OPFLAGS_UNKNOWN 0x00000000
47 #define ASYNC_OPFLAGS_INTERVAL_REPEAT 0x00000010
48 #define ASYNC_OPFLAGS_INDICATION 0x00000020
49 #define ASYNC_OPFLAGS_REMOTE 0x00000040
50 #define ASYNC_OPFLAGS_LOCAL_OUT_OF_PROC 0x00000080
51 #define ASYNC_OPFLAGS_PHASED 0x00000001
52 #define ASYNC_OPFLAGS_PARTIAL 0x00000002
53 #define ASYNC_OPFLAGS_NORMAL 0x00000000
54 #define ASYNC_OPFLAGS_SINGLE 0x00000008
55 #define ASYNC_OPFLAGS_MULTIPLE 0x00000010
56 #define ASYNC_OPFLAGS_TOTAL 0x00000020
|
57 mday 1.13 #define ASYNC_OPFLAGS_META_DISPATCHER 0x00000040
|
58 mday 1.17 #define ASYNC_OPFLAGS_FIRE_AND_FORGET 0x00000080
59 #define ASYNC_OPFLAGS_SIMPLE_STATUS 0x00000100
60 #define ASYNC_OPFLAGS_CALLBACK 0x00000200
|
61 mday 1.20 #define ASYNC_OPFLAGS_FORWARD 0x00000400
|
62 mday 1.24 #define ASYNC_OPFLAGS_PSEUDO_CALLBACK 0x00000800
|
63 mday 1.26 #define ASYNC_OPFLAGS_SAFE_CALLBACK 0x00001000
|
64 mike 1.2
65 #define ASYNC_OPSTATE_UNKNOWN 0x00000000
66 #define ASYNC_OPSTATE_OFFERED 0x00000001
67 #define ASYNC_OPSTATE_DECLINED 0x00000002
68 #define ASYNC_OPSTATE_STARTED 0x00000004
69 #define ASYNC_OPSTATE_PROCESSING 0x00000008
|
70 chip 1.30 #define ASYNC_OPSTATE_DELIVER 0x00000010
|
71 mike 1.2 #define ASYNC_OPSTATE_RESERVE 0x00000020
72 #define ASYNC_OPSTATE_COMPLETE 0x00000040
73 #define ASYNC_OPSTATE_TIMEOUT 0x00000080
74 #define ASYNC_OPSTATE_CANCELLED 0x00000100
75 #define ASYNC_OPSTATE_PAUSED 0x00000200
|
76 mday 1.12 #define ASYNC_OPSTATE_SUSPENDED 0x00000400
|
77 mday 1.3 #define ASYNC_OPSTATE_RESUMED 0x00000800
|
78 mday 1.8 #define ASYNC_OPSTATE_ORPHANED 0x00001000
|
79 mday 1.12 #define ASYNC_OPSTATE_RELEASED 0x00002000
|
80 mike 1.2
|
81 mday 1.8 class Cimom;
|
82 mday 1.23 class Thread;
|
83 mday 1.13
|
84 mike 1.2 class PEGASUS_COMMON_LINKAGE AsyncOpNode
85 {
|
86 mday 1.26
|
87 mday 1.38 // public:
88 // static void * operator new(size_t );
89 // static void operator delete( void *, size_t);
90 // private:
91 // static AsyncOpNode * _headOfFreeList;
92 // static const int BLOCK_SIZE;
93 // static Mutex _alloc_mut;
|
94 mike 1.2 public:
95
96 AsyncOpNode(void);
97 ~AsyncOpNode(void);
|
98 chip 1.30
|
99 mike 1.2 Boolean operator == (const void *key) const;
100 Boolean operator == (const AsyncOpNode & node) const;
|
101 mday 1.9
|
102 mday 1.12 void get_timeout_interval(struct timeval *buffer) ;
|
103 mday 1.9 void set_timeout_interval(const struct timeval *interval);
|
104 chip 1.30
|
105 mike 1.2 Boolean timeout(void) ;
106
107 OperationContext & get_context(void) ;
108
|
109 mday 1.4 void put_request(const Message *request) ;
|
110 mday 1.13 Message *get_request(void) ;
|
111 chip 1.30
|
112 mday 1.4 void put_response(const Message *response) ;
|
113 mday 1.13 Message *get_response(void) ;
|
114 chip 1.30
|
115 mike 1.2 Uint32 read_state(void) ;
116 void write_state(Uint32) ;
|
117 chip 1.30
|
118 mike 1.2 Uint32 read_flags(void);
119 void write_flags(Uint32);
|
120 chip 1.30
|
121 mike 1.2 void lock(void) throw(IPCException);
122 void unlock(void) throw(IPCException);
123 void udpate(void) throw(IPCException);
124 void deliver(const Uint32 count) throw(IPCException);
125 void reserve(const Uint32 size) throw(IPCException);
126 void processing(void) throw(IPCException) ;
127 void processing(OperationContext *context) throw(IPCException);
128 void complete(void) throw(IPCException) ;
129 void complete(OperationContext *context) throw(IPCException);
|
130 mday 1.12 void release(void);
|
131 mday 1.10 void wait(void);
|
132 chip 1.30
133
|
134 mike 1.2 private:
135 Semaphore _client_sem;
136 Mutex _mut;
|
137 mday 1.16 unlocked_dq<Message> _request;
|
138 chip 1.30 unlocked_dq<Message> _response;
139
|
140 mike 1.2 OperationContext _operation_list;
141 Uint32 _state;
142 Uint32 _flags;
143 Uint32 _offered_count;
144 Uint32 _total_ops;
145 Uint32 _completed_ops;
|
146 mday 1.15 Uint32 _user_data;
|
147 mday 1.17 Uint32 _completion_code;
|
148 mday 1.19 MessageQueue *_op_dest;
|
149 chip 1.30
|
150 mike 1.2 struct timeval _start;
151 struct timeval _lifetime;
152 struct timeval _updated;
153 struct timeval _timeout_interval;
154
155 AsyncOpNode *_parent;
156 unlocked_dq<AsyncOpNode> _children;
157
158 void _reset(unlocked_dq<AsyncOpNode> *dst_q);
159
|
160 mday 1.9 // the lifetime member is for cache management by the cimom
|
161 mike 1.2 void _set_lifetime(struct timeval *lifetime) ;
|
162 mday 1.12 Boolean _check_lifetime(void) ;
|
163 mike 1.2
164 Boolean _is_child(void) ;
165 Uint32 _is_parent(void) ;
166 Boolean _is_my_child(const AsyncOpNode & caller) const;
167 void _make_orphan( AsyncOpNode & parent) ;
168 void _adopt_child(AsyncOpNode *child) ;
169 void _disown_child(AsyncOpNode *child) ;
|
170 chip 1.30 void (*_async_callback)(AsyncOpNode *,
171 MessageQueue *,
|
172 mday 1.18 void *);
|
173 mday 1.26 void (*__async_callback)(Message *, void *, void *);
|
174 mday 1.23 // << Tue Mar 12 14:44:51 2002 mdd >>
|
175 chip 1.30 // pointers for async callbacks - don't use
|
176 mday 1.19 AsyncOpNode *_callback_node;
|
177 mday 1.21 MessageQueue *_callback_response_q;
|
178 mday 1.19 void *_callback_ptr;
|
179 mday 1.26 void *_callback_parameter;
180 void *_callback_handle;
|
181 mday 1.28 Condition *_callback_notify;
|
182 chip 1.30
|
183 mday 1.22 MessageQueue *_callback_request_q;
|
184 mday 1.23 // << Tue Mar 12 14:44:53 2002 mdd >>
|
185 chip 1.30 // pointers to help static class message handlers - don't use
|
186 mday 1.23 MessageQueue *_service_ptr;
187 Thread *_thread_ptr;
|
188 chip 1.30
|
189 mday 1.8 friend class cimom;
|
190 mday 1.10 friend class MessageQueueService;
|
191 mday 1.29 friend class ProviderManagerService;
|
192 mday 1.37 friend class BinaryMessageHandler;
|
193 mday 1.32 public:
194 // << Tue Jun 4 16:44:09 2002 mdd >>
195 // debug artifact
196 Uint32 _source_queue;
|
197 mday 1.34 // << Fri Jul 19 08:41:45 2002 mdd >>
198 // debugging utility
199 // careful - wipes out current value of *buf
200 void print_to_buffer(Sint8 **buf);
|
201 a.arora 1.40 String print_to_string(void);
|
202 mike 1.2 };
203
204
205 inline Boolean AsyncOpNode::operator == (const void *key) const
206 {
207 if (key == (void *)this)
208 return true;
209 return false;
210 }
211
212 inline Boolean AsyncOpNode::operator == (const AsyncOpNode & node) const
213 {
214 return AsyncOpNode::operator==((const void *)&node);
215 }
216
|
217 mday 1.9
|
218 chip 1.30 inline void AsyncOpNode::get_timeout_interval(struct timeval *buffer)
|
219 mday 1.9 {
220 if(buffer != 0)
221 {
|
222 a.arora 1.41 AutoMutex autoMut(_mut);
|
223 mday 1.9 buffer->tv_sec = _timeout_interval.tv_sec;
224 buffer->tv_usec = _timeout_interval.tv_usec;
|
225 a.arora 1.41 } // mutex unlocks here
|
226 mday 1.9 return;
227 }
228
229 inline void AsyncOpNode::set_timeout_interval(const struct timeval *interval)
230 {
231 if(interval != 0)
232 {
|
233 a.arora 1.41 AutoMutex autoMut(_mut);
|
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 a.arora 1.41 } // mutex unlocks here
|
238 mday 1.9 }
239
240
|
241 chip 1.30 inline Boolean AsyncOpNode::timeout(void)
|
242 mike 1.2 {
243 struct timeval now;
244 gettimeofday(&now, NULL);
|
245 mday 1.12 Boolean ret = false;
|
246 a.arora 1.41
247 AutoMutex autoMut(_mut);
|
248 mday 1.15 if((_updated.tv_sec + _timeout_interval.tv_sec ) < now.tv_sec)
|
249 a.arora 1.41 if((_updated.tv_usec + _timeout_interval.tv_usec ) < now.tv_usec)
250 ret = true;
251
|
252 mday 1.12 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 a.arora 1.41 AutoMutex autoMut(_mut);
|
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 mike 1.2 }
273
|
274 chip 1.30 inline Message * AsyncOpNode::get_request(void)
|
275 mike 1.2 {
|
276 mday 1.12 Message *ret;
|
277 a.arora 1.41 AutoMutex autoMut(_mut);
|
278 mday 1.9 gettimeofday(&_updated, NULL);
|
279 mday 1.16 ret = _request.remove_first() ;
|
280 a.arora 1.41
|
281 mday 1.12 return ret;
|
282 mike 1.2 }
283
|
284 chip 1.30 inline void AsyncOpNode::put_response(const Message *response)
|
285 mike 1.2 {
|
286 a.arora 1.41 AutoMutex autoMut(_mut);
|
287 mday 1.9 gettimeofday(&_updated, NULL);
|
288 mday 1.21 if (false == _response.exists(reinterpret_cast<void *>(const_cast<Message *>(response))))
|
289 mday 1.16 _response.insert_last( const_cast<Message *>(response) );
|
290 mike 1.2 }
291
|
292 chip 1.30 inline Message * AsyncOpNode::get_response(void)
|
293 mike 1.2 {
|
294 mday 1.12 Message *ret;
295
|
296 a.arora 1.41 AutoMutex autoMut(_mut);
|
297 mday 1.15 // gettimeofday(&_updated, NULL);
|
298 mday 1.16 ret = _response.remove_first();
299 // ret = _response;
|
300 chip 1.30
|
301 a.arora 1.41
|
302 mday 1.12 return ret;
|
303 mike 1.2 }
304
305 inline Uint32 AsyncOpNode::read_state(void)
306 {
|
307 a.arora 1.41
308 AutoMutex autoMut(_mut);
|
309 mday 1.9 gettimeofday(&_updated, NULL);
|
310 mday 1.12 Uint32 ret = _state;
|
311 a.arora 1.41
|
312 mday 1.12 return ret;
|
313 chip 1.30
|
314 mike 1.2 }
315
316 inline void AsyncOpNode::write_state(Uint32 state)
317 {
|
318 a.arora 1.41 AutoMutex autoMut(_mut);
|
319 mday 1.9 gettimeofday(&_updated, NULL);
|
320 mike 1.2 _state = state;
321 }
322
323 inline Uint32 AsyncOpNode::read_flags(void)
324 {
|
325 a.arora 1.41 AutoMutex autoMut(_mut);
|
326 mday 1.9 gettimeofday(&_updated, NULL);
|
327 mday 1.12 Uint32 ret = _flags;
|
328 a.arora 1.41
|
329 mday 1.12 return ret;
|
330 mike 1.2 }
331
332 inline void AsyncOpNode::write_flags(Uint32 flags)
|
333 chip 1.30 {
|
334 a.arora 1.41 AutoMutex autoMut(_mut);
|
335 mday 1.9 gettimeofday(&_updated, NULL);
|
336 mike 1.2 _flags = flags;
337 }
338
339
|
340 chip 1.30 inline void AsyncOpNode::lock(void)
341 throw(IPCException)
|
342 mike 1.2 {
343 _mut.lock(pegasus_thread_self());
344 }
345
|
346 chip 1.30 inline void AsyncOpNode::unlock(void)
347 throw(IPCException)
|
348 mike 1.2 {
349 _mut.unlock();
350 }
351
352 inline void AsyncOpNode::udpate(void)
353 throw(IPCException)
354 {
|
355 a.arora 1.41 AutoMutex autoMut(_mut);
|
356 mike 1.2 gettimeofday(&_updated, NULL);
|
357 a.arora 1.41
|
358 mike 1.2 return;
359 }
360
|
361 chip 1.30 inline void AsyncOpNode::deliver(const Uint32 count)
|
362 mike 1.2 throw(IPCException)
363 {
|
364 a.arora 1.41 AutoMutex autoMut(_mut);
|
365 mike 1.2 _completed_ops = count;
|
366 mday 1.15 _state |= ASYNC_OPSTATE_DELIVER;
|
367 mike 1.2 gettimeofday(&_updated, NULL);
|
368 a.arora 1.41
|
369 mike 1.2 return;
370 }
371
372 inline void AsyncOpNode::reserve(const Uint32 size)
373 throw(IPCException)
374 {
|
375 a.arora 1.41 AutoMutex autoMut(_mut);
|
376 mike 1.2 _total_ops = size;
|
377 mday 1.15 _state |= ASYNC_OPSTATE_RESERVE;
|
378 mike 1.2 gettimeofday(&_updated, NULL);
|
379 a.arora 1.41
|
380 mike 1.2 return;
381 }
382
|
383 chip 1.30 inline void AsyncOpNode::processing(void)
|
384 mike 1.2 throw(IPCException)
385 {
|
386 a.arora 1.41 AutoMutex autoMut(_mut);
|
387 mday 1.15 _state |= ASYNC_OPSTATE_PROCESSING;
|
388 mike 1.2 gettimeofday(&_updated, NULL);
|
389 a.arora 1.41
|
390 mike 1.2 return;
391 }
392
393 // con will be empty upon return of this member function
|
394 chip 1.30 inline void AsyncOpNode::processing(OperationContext *con)
|
395 mike 1.2 throw(IPCException)
396 {
|
397 a.arora 1.41 AutoMutex autoMut(_mut);
|
398 mday 1.15 _state |= ASYNC_OPSTATE_PROCESSING;
|
399 mike 1.2 gettimeofday(&_updated, NULL);
|
400 chip 1.30
401 /*
|
402 mike 1.2 context *c = con->remove_context();
403 while(c != 0)
404 {
405 _operation_list.add_context(c);
406 c = con->remove_context();
407 }
|
408 chip 1.30 */
|
409 a.arora 1.41
|
410 mike 1.2 return;
411 }
412
|
413 chip 1.30 inline void AsyncOpNode::complete(void)
|
414 mike 1.2 throw(IPCException)
415 {
|
416 a.arora 1.41 AutoMutex autoMut(_mut);
|
417 mday 1.15 _state |= ASYNC_OPSTATE_COMPLETE;
|
418 mike 1.2 gettimeofday(&_updated, NULL);
|
419 a.arora 1.41
|
420 mday 1.12
|
421 mike 1.2 return;
422 }
423
424 inline void AsyncOpNode::complete(OperationContext *con)
425 throw(IPCException)
426 {
|
427 a.arora 1.41 AutoMutex autoMut(_mut);
|
428 mday 1.15 _state |= ASYNC_OPSTATE_COMPLETE;
|
429 mike 1.2 gettimeofday(&_updated, NULL);
|
430 chip 1.30 /*
|
431 mike 1.2 context *c = con->remove_context();
432 while(c != 0)
433 {
434 _operation_list.add_context(c);
435 c = con->remove_context();
436 }
|
437 chip 1.30 */
|
438 a.arora 1.41
|
439 mday 1.10 }
440
441 inline void AsyncOpNode::wait(void)
442 {
443 _client_sem.wait();
|
444 mike 1.2 }
445
|
446 mday 1.12 inline void AsyncOpNode::release(void)
447 {
|
448 a.arora 1.41 AutoMutex autoMut(_mut);
|
449 mday 1.12 _state |= ASYNC_OPSTATE_RELEASED;
|
450 a.arora 1.41
|
451 mday 1.12 }
452
|
453 chip 1.30 inline void AsyncOpNode::_set_lifetime(struct timeval *lifetime)
|
454 mike 1.2 {
|
455 a.arora 1.41 AutoMutex autoMut(_mut);
|
456 mike 1.2 _lifetime.tv_sec = lifetime->tv_sec;
457 _lifetime.tv_usec = lifetime->tv_usec;
|
458 a.arora 1.41
|
459 mike 1.2 }
460
|
461 chip 1.30 inline Boolean AsyncOpNode::_check_lifetime(void)
|
462 mike 1.2 {
463 struct timeval now;
|
464 chip 1.30
|
465 mike 1.2 gettimeofday(&now, NULL);
466 if((_start.tv_sec + _lifetime.tv_sec ) >= now.tv_sec)
467 if((_start.tv_usec + _lifetime.tv_usec ) >= now.tv_usec)
468 return true;
469 return false;
470 }
471
472 inline Boolean AsyncOpNode::_is_child(void)
473 {
474 if (_parent != 0)
475 return true;
476 return false;
477 }
478
479 inline Uint32 AsyncOpNode::_is_parent(void)
480 {
481 return _children.count();
482 }
483
484 inline Boolean AsyncOpNode::_is_my_child(const AsyncOpNode & caller) const
|
485 chip 1.30 {
|
486 mike 1.2 if ( _parent == &caller )
487 return true;
488 return false;
489 }
490
|
491 chip 1.30 inline void AsyncOpNode::_make_orphan( AsyncOpNode & parent)
|
492 mike 1.2 {
493 if( _parent == &parent )
494 {
495 _parent = NULL;
496 parent._children.remove(this);
497 }
498 else
499 throw Permission(pegasus_thread_self());
500 }
501
|
502 chip 1.30 inline void AsyncOpNode::_adopt_child(AsyncOpNode *child)
|
503 mike 1.2 {
504 if(child == NULL)
505 throw NullPointer();
506 if(true == child->_is_child())
507 throw Permission(pegasus_thread_self());
508 child->_parent = this;
509 _children.insert_last(child);
510 }
|
511 chip 1.30
|
512 mike 1.2 inline void AsyncOpNode::_disown_child(AsyncOpNode *child)
513 {
514 if(child == NULL)
515 throw NullPointer();
516 if( false == child->_is_child() || false == child->_is_my_child( *this ))
517 throw Permission(pegasus_thread_self());
518 child->_make_orphan( *this );
519 _children.remove(child);
|
520 chip 1.30 }
|
521 mike 1.2
522 PEGASUS_NAMESPACE_END
523
524 #endif //Pegasus_AsyncOpNode_h
|