1 martin 1.59 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.60 //
|
3 martin 1.59 // 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.60 //
|
10 martin 1.59 // 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.60 //
|
17 martin 1.59 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.60 //
|
20 martin 1.59 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.60 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.59 // 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.60 //
|
28 martin 1.59 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.4 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
|
32 mike 1.5 #include <Pegasus/Common/HashTable.h>
|
33 kumpf 1.19 #include <Pegasus/Common/Tracer.h>
|
34 kumpf 1.51 #include <Pegasus/Common/CimomMessage.h>
|
35 mike 1.4 #include "MessageQueue.h"
|
36 mike 1.48 #include "IDFactory.h"
37
|
38 mike 1.4 PEGASUS_USING_STD;
39
40 PEGASUS_NAMESPACE_BEGIN
41
|
42 mike 1.5 typedef HashTable<Uint32, MessageQueue*, EqualFunc<Uint32>, HashFunc<Uint32> >
43 QueueTable;
44
|
45 mday 1.33 static QueueTable _queueTable(256);
|
46 mday 1.28 static Mutex q_table_mut ;
|
47 mike 1.5
|
48 sahana.prabhakar 1.61 static IDFactory _qidFactory;
|
49 mday 1.35
|
50 david.dillard 1.43 Uint32 MessageQueue::getNextQueueId()
|
51 mike 1.5 {
|
52 mike 1.48 return _qidFactory.getID();
|
53 aruran.ms 1.46 }
|
54 chip 1.8
|
55 aruran.ms 1.46 void MessageQueue::putQueueId(Uint32 queueId)
56 {
|
57 sahana.prabhakar 1.61 _qidFactory.putID(queueId);
|
58 aruran.ms 1.46 }
|
59 mday 1.24
|
60 venkat.puvvada 1.62 MessageQueue::MessageQueue(const char* name)
61 : _queueId(getNextQueueId())
|
62 mike 1.5 {
|
63 mike 1.16 //
64 // Copy the name:
65 //
66
|
67 david.dillard 1.43 PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::MessageQueue()");
|
68 kumpf 1.19
|
69 mike 1.16 if (!name)
|
70 david.dillard 1.43 name = "";
|
71 mike 1.16
72 _name = new char[strlen(name) + 1];
73 strcpy(_name, name);
74
|
75 marek 1.55 PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
|
76 sahana.prabhakar 1.61 "MessageQueue::MessageQueue name = %s, queueId = %u", name, _queueId));
|
77 kumpf 1.19
|
78 mike 1.16 //
79 // Insert into queue table:
80 //
|
81 a.arora 1.38 AutoMutex autoMut(q_table_mut);
|
82 david.dillard 1.43 while (!_queueTable.insert(_queueId, this))
83 ;
|
84 chip 1.8
|
85 david.dillard 1.43 PEG_METHOD_EXIT();
|
86 mike 1.5 }
87
88 MessageQueue::~MessageQueue()
89 {
90 // ATTN-A: thread safety!
|
91 kumpf 1.25 PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::~MessageQueue()");
|
92 marek 1.55 PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
|
93 kumpf 1.56 "MessageQueue::~MessageQueue queueId = %i, name = %s",
94 _queueId,
95 _name));
|
96 kumpf 1.19
|
97 a.arora 1.38 {
|
98 david.dillard 1.43 AutoMutex autoMut(q_table_mut);
99 _queueTable.remove(_queueId);
|
100 a.arora 1.38 } // mutex unlocks here
|
101 david.dillard 1.43
|
102 mike 1.16 // Free the name:
|
103 david.dillard 1.43
|
104 mike 1.16 delete [] _name;
|
105 kumpf 1.19
|
106 aruran.ms 1.46 // Return the queue id.
107
108 putQueueId(_queueId);
|
109 joyce.j 1.41
|
110 kumpf 1.25 PEG_METHOD_EXIT();
|
111 chip 1.8 }
112
|
113 kumpf 1.37 void MessageQueue::enqueue(Message* message)
|
114 mike 1.4 {
|
115 kumpf 1.25 PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::enqueue()");
|
116 kumpf 1.19
|
117 kumpf 1.52 PEGASUS_ASSERT(message != 0);
|
118 mike 1.7
|
119 marek 1.55 PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
|
120 marek 1.57 "Queue name: [%s], Message: [%s]",
121 getQueueName(),
|
122 marek 1.55 MessageTypeToString(message->getType())));
|
123 david.dillard 1.43
|
124 kumpf 1.52 _messageList.insert_back(message);
|
125 david.dillard 1.43
|
126 mday 1.22 handleEnqueue();
|
127 kumpf 1.25 PEG_METHOD_EXIT();
|
128 mday 1.15 }
129
|
130 david.dillard 1.43 Message* MessageQueue::dequeue()
|
131 mike 1.4 {
|
132 kumpf 1.25 PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::dequeue()");
133
|
134 kumpf 1.52 Message* message = _messageList.remove_front();
135
|
136 kumpf 1.25 PEG_METHOD_EXIT();
|
137 kumpf 1.52 return message;
|
138 mike 1.4 }
139
|
140 sahana.prabhakar 1.63 Boolean MessageQueue::isActive()
141 {
142 return true;
143 }
144
|
145 mike 1.7 const char* MessageQueue::getQueueName() const
|
146 mike 1.5 {
|
147 david.dillard 1.43 return _name;
|
148 mike 1.5 }
149
|
150 david.dillard 1.43 MessageQueue* MessageQueue::lookup(Uint32 queueId)
|
151 mike 1.5 {
|
152 kumpf 1.19
|
153 mike 1.5 MessageQueue* queue = 0;
|
154 a.arora 1.38 AutoMutex autoMut(q_table_mut);
|
155 chip 1.8
|
156 mike 1.5 if (_queueTable.lookup(queueId, queue))
|
157 mike 1.7 {
|
158 david.dillard 1.43 return queue;
|
159 mike 1.7 }
|
160 chip 1.8
|
161 mike 1.7 // Not found!
|
162 mike 1.5
|
163 marek 1.57 PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL1,
|
164 marek 1.55 "MessageQueue::lookup failure queueId = %u", queueId));
|
165 kumpf 1.19
|
166 mike 1.4 return 0;
|
167 mike 1.6 }
|
168 mike 1.7
169
|
170 david.dillard 1.43 MessageQueue* MessageQueue::lookup(const char *name)
|
171 mike 1.7 {
|
172 kumpf 1.19
|
173 kumpf 1.54 if (name == NULL)
|
174 david.dillard 1.43 throw NullPointer();
|
175 chip 1.8
|
176 david.dillard 1.43 AutoMutex autoMut(q_table_mut);
|
177 kumpf 1.54 for (QueueTable::Iterator i = _queueTable.start(); i; i++)
178 {
|
179 mike 1.7 // ATTN: Need to decide how many characters to compare in queue names
|
180 kumpf 1.54 if (!strcmp(((MessageQueue *)i.value())->getQueueName(), name))
|
181 david.dillard 1.43 {
|
182 kumpf 1.54 return (MessageQueue *)i.value();
|
183 david.dillard 1.43 }
184 }
|
185 chip 1.8
|
186 marek 1.57 PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL1,
|
187 marek 1.55 "MessageQueue::lookup failure - name = %s", name));
|
188 kumpf 1.19
|
189 david.dillard 1.43 return 0;
|
190 mike 1.7 }
191
|
192 mike 1.6
193 void MessageQueue::handleEnqueue()
194 {
195
|
196 mike 1.4 }
197
198 PEGASUS_NAMESPACE_END
|