(file) Return to MessageQueue.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 karl  1.38 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.4  //
  3 karl  1.32 // 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 karl  1.30 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.32 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.33 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.38 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.4  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15 chip  1.11 // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18 mike  1.4  // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20 karl  1.38 // 
 21 chip  1.11 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.4  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24 chip  1.11 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27 mike  1.4  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34            #ifndef Pegasus_MessageQueue_h
 35            #define Pegasus_MessageQueue_h
 36            
 37            #include <Pegasus/Common/Config.h>
 38            #include <Pegasus/Common/Message.h>
 39 kumpf 1.43 #include <Pegasus/Common/Mutex.h>
 40 kumpf 1.44 #include <Pegasus/Common/List.h>
 41 kumpf 1.27 #include <Pegasus/Common/Linkage.h>
 42 mike  1.4  
 43            PEGASUS_NAMESPACE_BEGIN
 44            
 45            /** The MessageQueue class represents a queue abstraction and is used by
 46                modules to exchange messages. Methods are provided for enqueuing,
 47                dequeuing, removing, iterating messages. Some methods are virtual and
 48                may be overriden but subclasses to modify the behavior.
 49 mike  1.14 
 50                <h1>A Word about Queue Ids</h1>
 51            
 52                You may pass a specific queue id to the MessageQueue() constructor. The
 53                default is to call MessageQueue::getNextQueueId() to obtain one. Only pass
 54                queue ids generated by calling MessageQueue::getNextQueueId() to this
 55 david.dillard 1.34     constructor. Otherwise, you might end up with two queues with the same
 56 mike          1.14     queue id.
 57                    
 58                        A technique we encourage, is to declare global queue ids like this:
 59                    
 60 mday          1.16     <pre>
 61                        extern const Uint32 GROCERY_QUEUE_ID;
 62                        </pre>
 63 mike          1.14 
 64                        And then define them like this:
 65                    
 66 mday          1.16     <pre>
 67                        const Uint32 GROCERY_QUEUE_ID = MessageQueue::getNextQueueId();
 68                        </pre>
 69 mike          1.14 
 70                        And then pass them to the constructor of MessageQueue (from the derived
 71                        class). In this way you will secure a unique constant identifier by which
 72                        you may refer to a queue later on.
 73                    
 74                        <h1>A Word about using the find() Methods</h1>
 75                    
 76                        There are two find() methods. One that takes a queue id and one that
 77                        takes a name. The time complexity of the former is O(1); whereas, the
 78                        time complexity of the latter is O(n). Therefore, use the queue id form
 79                        since it is more efficient.
 80 mike          1.4  */
 81                    class PEGASUS_COMMON_LINKAGE MessageQueue
 82                    {
 83 david.dillard 1.34 public:
 84 mike          1.4  
 85 david.dillard 1.34     /** This constructor places this object on a queue table which is
 86                        maintained by this class. Each message queue has a queue-id (which
 87                        may be obtained by calling getQueueId()). The queue-id may be passed
 88                        to lookupQueue() to obtain a pointer to the corresponding queue).
 89                    
 90                        @param queueId the queue id to be used by this object. ONLY PASS IN
 91                        QUEUE IDS WHICH WERE GENERATED USING MessageQueue::getNextQueueId().
 92                        Otherwise, you might end up with more than one queue with the same
 93                        queue id.
 94                        */
 95                        MessageQueue(
 96                            const char *name,
 97                            Boolean async = false,
 98                            Uint32 queueId = MessageQueue::getNextQueueId());
 99                    
100                        /** Removes this queue from the queue table. */
101                        virtual ~MessageQueue();
102                    
103                        /** Enques a message (places it at the back of the queue).
104                        @param message pointer to message to be enqueued.
105                        @exception  NullPointer exception if message parameter is null.
106 david.dillard 1.34     @exception  IPCException if socket call has an error
107                        */
108                        virtual void enqueue(Message* message);
109                    
110                        /** allows a caller to determine if this message queue is asynchronous or
111                        not.
112                        */
113                        virtual Boolean isAsync() const { return _async; }
114                    
115                        /** Dequeues a message (removes it from the front of the queue).
116                        @return pointer to message or zero if queue is empty.
117                        @exception IPCException Thrown if an IPC error occurs.
118                        */
119                        virtual Message* dequeue();
120                    
121                        /** Returns true if there are no messages on the queue. */
122 kumpf         1.44     Boolean isEmpty() const { return _messageList.is_empty(); }
123 david.dillard 1.34 
124                        /** Returns the number of messages on the queue. */
125 kumpf         1.44     Uint32 getCount() const { return _messageList.size(); }
126 david.dillard 1.34 
127                        /** Retrieve the queue id for this queue. */
128                        Uint32 getQueueId() const throw() { return _queueId; }
129                    
130                        Uint32 get_capabilities() const throw()
131                        {
132                            return _capabilities;
133                        }
134                    
135                        /** Provide a string name for this queue to be used by the print method.
136                         */
137                        const char* getQueueName() const;
138                    
139                        /** This method is called after a message has been enqueued. This default
140                        implementation does nothing. Derived classes may override this to
141                        take some action each time a message is enqueued (for example, this
142                        method could handle the incoming message in the thread of the caller
143                        of enqueue()).
144                        */
145                        virtual void handleEnqueue() ;
146                    
147 david.dillard 1.34     /** This method <b>may</b> be called prior to enqueueing an message.
148                        the message queue can inform the caller that it does not want
149                        to handle the message by returning false **/
150                    
151                        virtual Boolean messageOK(const Message *msg) { return true ;}
152                    
153                        /** Lookup a message queue from a queue id. Note this is an O(1) operation.
154                        @exception IPCException Thrown if an IPC error occurs.
155                         */
156                        static MessageQueue* lookup(Uint32 queueId);
157                    
158                        /** Lookup a message given a queue name. NOte this is an O(N) operation.
159                        @exception IPCException Thrown if an IPC error occurs.
160                         */
161                        static MessageQueue* lookup(const char *name);
162                    
163                        /** Get the next available queue id. It always returns a non-zero
164                        queue id an monotonically increases and finally wraps (to one)
165                        after reaching the maximum unsigned 32 bit integer.
166                        @exception IPCException Thrown if an IPC error occurs.
167                        */
168 david.dillard 1.34     static Uint32 getNextQueueId();
169                    
170 aruran.ms     1.37     /** Put the queue id into the stack.
171                        */
172                        static void putQueueId(Uint32 queueId);
173                    
174 david.dillard 1.34 protected:
175                        Uint32 _queueId;
176                        char *_name;
177                        Uint32 _capabilities;
178                    
179                    private:
180 kumpf         1.44     List<Message, Mutex> _messageList;
181 david.dillard 1.34     Boolean _async;
182 mike          1.4  };
183                    
184                    PEGASUS_NAMESPACE_END
185                    
186                    #endif /* Pegasus_MessageQueue_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2