1 martin 1.49 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.50 //
|
3 martin 1.49 // 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.50 //
|
10 martin 1.49 // 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.50 //
|
17 martin 1.49 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.50 //
|
20 martin 1.49 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.50 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.49 // 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.50 //
|
28 martin 1.49 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.4 //
|
30 kamal.locahana 1.45 //%////////////////////////////////////////////////////////////////////////////
|
31 mike 1.4
32 #ifndef Pegasus_MessageQueue_h
33 #define Pegasus_MessageQueue_h
34
35 #include <Pegasus/Common/Config.h>
36 #include <Pegasus/Common/Message.h>
|
37 kumpf 1.43 #include <Pegasus/Common/Mutex.h>
|
38 kumpf 1.44 #include <Pegasus/Common/List.h>
|
39 kumpf 1.27 #include <Pegasus/Common/Linkage.h>
|
40 mike 1.4
41 PEGASUS_NAMESPACE_BEGIN
42
43 /** The MessageQueue class represents a queue abstraction and is used by
44 modules to exchange messages. Methods are provided for enqueuing,
45 dequeuing, removing, iterating messages. Some methods are virtual and
46 may be overriden but subclasses to modify the behavior.
|
47 mike 1.14
48 <h1>A Word about using the find() Methods</h1>
49
50 There are two find() methods. One that takes a queue id and one that
51 takes a name. The time complexity of the former is O(1); whereas, the
52 time complexity of the latter is O(n). Therefore, use the queue id form
53 since it is more efficient.
|
54 mike 1.4 */
55 class PEGASUS_COMMON_LINKAGE MessageQueue
56 {
|
57 david.dillard 1.34 public:
|
58 mike 1.4
|
59 david.dillard 1.34 /** This constructor places this object on a queue table which is
60 maintained by this class. Each message queue has a queue-id (which
61 may be obtained by calling getQueueId()). The queue-id may be passed
62 to lookupQueue() to obtain a pointer to the corresponding queue).
63 */
|
64 venkat.puvvada 1.52 MessageQueue(const char *name);
|
65 david.dillard 1.34
66 /** Removes this queue from the queue table. */
67 virtual ~MessageQueue();
68
69 /** Enques a message (places it at the back of the queue).
70 @param message pointer to message to be enqueued.
71 @exception NullPointer exception if message parameter is null.
72 */
73 virtual void enqueue(Message* message);
74
75 /** Dequeues a message (removes it from the front of the queue).
76 @return pointer to message or zero if queue is empty.
77 */
78 virtual Message* dequeue();
79
|
80 sahana.prabhakar 1.53 /**
81 This function will indicate whether the MessageQueue is active or not.
82 By default this function will return true and do nothing else.
83 */
84 virtual Boolean isActive();
85
|
86 david.dillard 1.34 /** Returns true if there are no messages on the queue. */
|
87 kamal.locahana 1.45 Boolean isEmpty() const { return (Boolean) _messageList.is_empty(); }
|
88 david.dillard 1.34
89 /** Returns the number of messages on the queue. */
|
90 kamal.locahana 1.45 Uint32 getCount() const { return (Uint32) _messageList.size(); }
|
91 david.dillard 1.34
92 /** Retrieve the queue id for this queue. */
93 Uint32 getQueueId() const throw() { return _queueId; }
94
95 /** Provide a string name for this queue to be used by the print method.
96 */
97 const char* getQueueName() const;
98
99 /** This method is called after a message has been enqueued. This default
100 implementation does nothing. Derived classes may override this to
101 take some action each time a message is enqueued (for example, this
102 method could handle the incoming message in the thread of the caller
103 of enqueue()).
104 */
105 virtual void handleEnqueue() ;
106
107 /** Lookup a message queue from a queue id. Note this is an O(1) operation.
108 */
109 static MessageQueue* lookup(Uint32 queueId);
110
111 /** Lookup a message given a queue name. NOte this is an O(N) operation.
112 david.dillard 1.34 */
113 static MessageQueue* lookup(const char *name);
114
115 /** Get the next available queue id. It always returns a non-zero
116 queue id an monotonically increases and finally wraps (to one)
117 after reaching the maximum unsigned 32 bit integer.
118 */
119 static Uint32 getNextQueueId();
120
|
121 aruran.ms 1.37 /** Put the queue id into the stack.
122 */
123 static void putQueueId(Uint32 queueId);
124
|
125 david.dillard 1.34 protected:
126 Uint32 _queueId;
127 char *_name;
128
129 private:
|
130 kumpf 1.44 List<Message, Mutex> _messageList;
|
131 mike 1.4 };
132
133 PEGASUS_NAMESPACE_END
134
135 #endif /* Pegasus_MessageQueue_h */
|