1 karl 1.14 //%2006////////////////////////////////////////////////////////////////////////
|
2 schuur 1.1 //
|
3 karl 1.10 // 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 schuur 1.1 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.10 // 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.11 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.14 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 schuur 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // 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 // 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.10 //
|
21 schuur 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // 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 // 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 // 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 // Author: Adrian Schuur, schuur@de.ibm.com
33 //
|
34 a.arora 1.9 // Modified By: Amit K Arora, IBM (amita@in.ibm.com) for Bug#1917
|
35 schuur 1.1 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include "CMPI_Version.h"
39
|
40 konrad.r 1.13 #include <Pegasus/ProviderManager2/CMPI/CMPIProvider.h>
|
41 schuur 1.1 #include "CMPI_Object.h"
42 #include "CMPI_Broker.h"
43 #include "CMPI_Ftabs.h"
44 #include "CMPI_String.h"
45 #include "CMPI_SelectExp.h"
46
47 #include <Pegasus/Common/CIMName.h>
|
48 mike 1.15 #include <Pegasus/Common/Time.h>
|
49 schuur 1.1 #include <Pegasus/Common/CIMPropertyList.h>
50 #include <Pegasus/ProviderManager2/ProviderManager.h>
51 #include <Pegasus/Common/Thread.h>
|
52 konrad.r 1.12 #include <Pegasus/Common/Tracer.h>
|
53 a.arora 1.9 #include <Pegasus/Common/AutoPtr.h>
|
54 mike 1.15 #include <Pegasus/Common/Condition.h>
|
55 schuur 1.1
56 #if defined (CMPI_VER_85)
|
57 schuur 1.4 #include <Pegasus/Common/MessageLoader.h>
|
58 schuur 1.1 #endif
59
60 #include <stdarg.h>
61 #include <string.h>
62
|
63 schuur 1.4 #if defined(CMPI_PLATFORM_WIN32_IX86_MSVC)
64 #include <sys/timeb.h>
65 #endif
66
|
67 schuur 1.1 PEGASUS_NAMESPACE_BEGIN
68
|
69 mike 1.15 class ConditionWithMutex
70 {
71 public:
72 ConditionWithMutex() { }
73 ~ConditionWithMutex() { }
74 void signal() { _cond.signal(); }
75 void wait() { _cond.wait(_mutex); }
76
77 private:
78 Mutex _mutex;
79 Condition _cond;
80 };
81
|
82 david.dillard 1.8 extern "C" {
83 struct thrd_data {
84 CMPI_THREAD_RETURN(CMPI_THREAD_CDECL*pgm)(void*);
|
85 konrad.r 1.13 void *parm;
86 CMPIProvider *provider;
|
87 david.dillard 1.8 };
88 }
|
89 schuur 1.7
|
90 mike 1.15 static ThreadReturnType PEGASUS_THREAD_CDECL start_driver(void *parm)
|
91 schuur 1.7 {
|
92 mike 1.15 ThreadReturnType rc;
|
93 schuur 1.7 Thread* my_thread = (Thread*)parm;
94 thrd_data *pp = (thrd_data*)my_thread->get_parm();
95 thrd_data data=*pp;
|
96 konrad.r 1.13
|
97 schuur 1.7 delete pp;
|
98 mike 1.15 rc = (ThreadReturnType)(data.pgm)(data.parm);
|
99 schuur 1.7
|
100 konrad.r 1.13 // Remove the thread from the watch-list (and clean it up).
101 data.provider->removeThreadFromWatch( my_thread);
102 return rc;
|
103 schuur 1.7 }
104
|
105 konrad.r 1.13
106
|
107 schuur 1.6 extern "C" {
108
109 static char *resolveFileName (const char *filename)
110 {
111 String pn=ProviderManager::_resolvePhysicalName(filename);
112 CString n=pn.getCString();
113 return strdup((const char*)n);
114 }
|
115 schuur 1.1
|
116 schuur 1.6 static CMPI_THREAD_TYPE newThread
117 (CMPI_THREAD_RETURN (CMPI_THREAD_CDECL *start )(void *), void *parm, int detached)
118 {
|
119 konrad.r 1.13 const CMPIBroker *brk = CM_BROKER;
120 const CMPI_Broker *broker = (CMPI_Broker*)brk;
121
|
122 a.arora 1.9 AutoPtr<thrd_data> data(new thrd_data());
|
123 schuur 1.6 data->pgm=(CMPI_THREAD_RETURN (CMPI_THREAD_CDECL *)(void*))start;
124 data->parm=parm;
|
125 konrad.r 1.13 data->provider = broker->provider;
126 Thread *t=new Thread(start_driver,data.get(),detached==1);
|
127 schuur 1.6
|
128 konrad.r 1.13 broker->provider->addThreadToWatch(t);
|
129 a.arora 1.9 data.release();
|
130 konrad.r 1.13
|
131 konrad.r 1.12 ThreadStatus rtn = PEGASUS_THREAD_OK;
132 while ( (rtn = t->run()) != PEGASUS_THREAD_OK)
133 {
|
134 konrad.r 1.13 if (rtn == PEGASUS_THREAD_INSUFFICIENT_RESOURCES)
|
135 mike 1.15 Threads::yield();
|
136 konrad.r 1.13 else
|
137 konrad.r 1.12 {
|
138 konrad.r 1.13 Tracer::trace(TRC_PROVIDERMANAGER, Tracer::LEVEL2, \
139 "Could not allocate provider thread (%p) for %s provider.",
140 t, (const char *)broker->name.getCString());
141 broker->provider->removeThreadFromWatch(t);
142 delete t; t = 0;
143 break;
|
144 konrad.r 1.12 }
145 }
|
146 konrad.r 1.13 if (rtn == PEGASUS_THREAD_OK)
147 {
148 Tracer::trace(TRC_PROVIDERMANAGER, Tracer::LEVEL2,
149 "Started provider thread (%p) for %s.",
150 t, (const char *)broker->name.getCString());
151 }
|
152 schuur 1.6 return (CMPI_THREAD_TYPE)t;
153 }
|
154 schuur 1.1
155
|
156 schuur 1.2
|
157 schuur 1.6 static int joinThread (CMPI_THREAD_TYPE thread, CMPI_THREAD_RETURN *returnCode)
158 {
159 ((Thread*)thread)->join();
160 *returnCode=(CMPI_THREAD_RETURN)((Thread*)thread)->get_exit();
161 return 0;
162 }
163
164 static int exitThread(CMPI_THREAD_RETURN return_code)
165 {
|
166 mike 1.15 Thread::getCurrent()->exit_self((ThreadReturnType)return_code);
|
167 schuur 1.6 return 0;
168 }
|
169 schuur 1.2
|
170 schuur 1.6 static int cancelThread(CMPI_THREAD_TYPE thread)
171 {
172 ((Thread*)thread)->cancel();
173 return 0;
174 }
175
176 static int threadSleep(CMPIUint32 msec)
177 {
178 Thread::getCurrent()->sleep(msec);
179 return 0;
180 }
|
181 schuur 1.2
|
182 schuur 1.6 static int threadOnce (int *once, void (*init)(void))
183 {
184 if (*once==0) {
185 *once=1;
186 (init)();
187 }
188 return *once;
|
189 schuur 1.2 }
190
191
|
192 schuur 1.6 static int createThreadKey(CMPI_THREAD_KEY_TYPE *key, void (*cleanup)(void*))
193 {
|
194 mike 1.15 return TSDKey::create((TSDKeyType*)key);
|
195 schuur 1.6 }
196
197 static int destroyThreadKey(CMPI_THREAD_KEY_TYPE key)
198 {
|
199 mike 1.15 return TSDKey::destroy(key);
|
200 schuur 1.6 }
|
201 schuur 1.2
|
202 schuur 1.6 static void *getThreadSpecific(CMPI_THREAD_KEY_TYPE key)
203 {
|
204 mike 1.15 return TSDKey::get_thread_specific(key);
|
205 schuur 1.6 }
|
206 schuur 1.1
|
207 schuur 1.6 static int setThreadSpecific(CMPI_THREAD_KEY_TYPE key, void * value)
208 {
|
209 mike 1.15 return TSDKey::set_thread_specific(key,value);
|
210 schuur 1.6 }
|
211 schuur 1.1
212
|
213 schuur 1.6 static CMPI_MUTEX_TYPE newMutex (int opt)
214 {
215 Mutex *m=new Mutex();
216 return m;
217 }
|
218 schuur 1.1
|
219 schuur 1.6 static void destroyMutex (CMPI_MUTEX_TYPE m)
220 {
221 delete ((Mutex*)m);
222 }
|
223 schuur 1.1
|
224 schuur 1.6 static void lockMutex (CMPI_MUTEX_TYPE m)
225 {
|
226 mike 1.15 ((Mutex*)m)->lock();
|
227 schuur 1.6 }
|
228 schuur 1.1
|
229 schuur 1.6 static void unlockMutex (CMPI_MUTEX_TYPE m)
230 {
231 ((Mutex*)m)->unlock();
232 }
|
233 schuur 1.1
234
235
|
236 schuur 1.6 static CMPI_COND_TYPE newCondition (int opt)
237 {
|
238 mike 1.15 ConditionWithMutex *c=new ConditionWithMutex();
|
239 schuur 1.6 return c;
240 }
|
241 schuur 1.1
|
242 schuur 1.6 static void destroyCondition (CMPI_COND_TYPE c)
243 {
|
244 mike 1.15 delete (ConditionWithMutex*)c;
|
245 schuur 1.6 }
|
246 schuur 1.1
|
247 schuur 1.6 static int condWait (CMPI_COND_TYPE c, CMPI_MUTEX_TYPE m)
248 {
249 // need to take care of mutex
|
250 mike 1.15 ((ConditionWithMutex*)c)->wait();
|
251 schuur 1.6 return 0;
252 }
|
253 schuur 1.1
|
254 schuur 1.6 static int timedCondWait(CMPI_COND_TYPE c, CMPI_MUTEX_TYPE m, struct timespec *wait)
255 {
|
256 schuur 1.5
|
257 schuur 1.6 int msec;
258 struct timespec next=*wait;
259 #if defined(CMPI_PLATFORM_WIN32_IX86_MSVC)
260 struct timeval {
261 long tv_sec;
262 long tv_usec;
263 }now;
264 struct _timeb timebuffer;
|
265 konrad.r 1.13 #endif
266
267 /* this is not truely mapping to pthread_timed_wait
268 but will work for the time beeing
269 */
|
270 schuur 1.6
|
271 konrad.r 1.13 #if defined(CMPI_PLATFORM_WIN32_IX86_MSVC)
|
272 schuur 1.6 _ftime( &timebuffer );
273 now.tv_sec=timebuffer.time;
274 now.tv_usec=timebuffer.millitm*1000;
275 #else
276 struct timeval now;
|
277 mike 1.15 Time::gettimeofday(&now);
|
278 schuur 1.6 #endif
279
280 if (next.tv_nsec>1000000000) {
281 next.tv_sec+=next.tv_nsec/1000000000;
282 next.tv_nsec=next.tv_nsec%1000000000;
283 }
284 msec=(next.tv_sec-now.tv_sec)*1000;
285 msec+=(next.tv_nsec/1000000)-(now.tv_usec/1000);
|
286 schuur 1.2
|
287 schuur 1.6 Thread::getCurrent()->sleep(msec);
288 return 0;
|
289 schuur 1.2 }
290
|
291 schuur 1.1
|
292 schuur 1.6 static int signalCondition(CMPI_COND_TYPE cond)
293 {
|
294 mike 1.15 ((ConditionWithMutex*)cond)->signal();
|
295 schuur 1.6 return 0;
296 }
|
297 schuur 1.1
|
298 schuur 1.2 }
299
|
300 schuur 1.1 static CMPIBrokerExtFT brokerExt_FT={
301 CMPICurrentVersion,
302 resolveFileName,
|
303 schuur 1.2
|
304 schuur 1.1 newThread,
|
305 schuur 1.2 joinThread,
306 exitThread,
307 cancelThread,
308 threadSleep,
309 threadOnce,
310
|
311 schuur 1.1 createThreadKey,
|
312 schuur 1.2 destroyThreadKey,
|
313 schuur 1.1 getThreadSpecific,
314 setThreadSpecific,
|
315 schuur 1.2
|
316 schuur 1.1 newMutex,
317 destroyMutex,
318 lockMutex,
319 unlockMutex,
|
320 schuur 1.2
|
321 schuur 1.1 newCondition,
322 destroyCondition,
|
323 schuur 1.5 condWait,
|
324 schuur 1.1 timedCondWait,
|
325 schuur 1.5 signalCondition // Signal not supported yet
|
326 schuur 1.1 };
327
328 CMPIBrokerExtFT *CMPI_BrokerExt_Ftab=&brokerExt_FT;
329
330
331 PEGASUS_NAMESPACE_END
332
333
334
|