(file) Return to CMPI_BrokerExt.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPI

  1 schuur 1.1 //%2003////////////////////////////////////////////////////////////////////////
  2            //
  3            // 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            //
  8            // Permission is hereby granted, free of charge, to any person obtaining a copy
  9            // 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            // 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            //
 15            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16            // 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            // 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            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22 schuur 1.1 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23            //
 24            //==============================================================================
 25            //
 26            // Author:      Adrian Schuur, schuur@de.ibm.com
 27            //
 28            // Modified By:
 29            //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #include "CMPI_Version.h"
 33            
 34            #include "CMPI_Object.h"
 35            #include "CMPI_Broker.h"
 36            #include "CMPI_Ftabs.h"
 37            #include "CMPI_String.h"
 38            #include "CMPI_SelectExp.h"
 39            
 40            #include <Pegasus/Common/CIMName.h>
 41            #include <Pegasus/Common/CIMPropertyList.h>
 42            #include <Pegasus/ProviderManager2/ProviderManager.h>
 43 schuur 1.1 #include <Pegasus/Common/Thread.h>
 44            
 45            #if defined (CMPI_VER_85)
 46 schuur 1.4   #include <Pegasus/Common/MessageLoader.h>
 47 schuur 1.1 #endif
 48            
 49            #include <stdarg.h>
 50            #include <string.h>
 51            
 52 schuur 1.4 #if defined(CMPI_PLATFORM_WIN32_IX86_MSVC)
 53              #include <sys/timeb.h>
 54            #endif
 55            
 56 schuur 1.1 PEGASUS_USING_STD;
 57            PEGASUS_NAMESPACE_BEGIN
 58            
 59            static char *resolveFileName (const char *filename)
 60            {
 61               String pn=ProviderManager::_resolvePhysicalName(filename);
 62               CString n=pn.getCString();
 63               return strdup((const char*)n);
 64            }
 65            
 66            struct thrd_data {
 67               CMPI_THREAD_RETURN(CMPI_THREAD_CDECL*pgm)(void*);
 68               void *parm;
 69            };
 70            
 71 schuur 1.3 static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL start_driver(void *parm)
 72 schuur 1.1 {
 73                Thread* my_thread = (Thread*)parm;
 74                thrd_data *pp = (thrd_data*)my_thread->get_parm();
 75                thrd_data data=*pp;
 76                delete pp;
 77            
 78 schuur 1.4     return (PEGASUS_THREAD_RETURN)(data.pgm)(data.parm);
 79 schuur 1.1 }
 80            
 81            static CMPI_THREAD_TYPE newThread
 82                    (CMPI_THREAD_RETURN (CMPI_THREAD_CDECL *start )(void *), void *parm, int detached)
 83            {
 84               thrd_data *data=new thrd_data();
 85 schuur 1.4    data->pgm=(CMPI_THREAD_RETURN (CMPI_THREAD_CDECL *)(void*))start;
 86 schuur 1.1    data->parm=parm;
 87            
 88 schuur 1.3    Thread *t=new Thread(
 89                    (PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *)(void*))start_driver,data,detached==1);
 90 schuur 1.1    t->run();
 91               return (CMPI_THREAD_TYPE)t;
 92            }
 93            
 94 schuur 1.2 
 95            
 96            static int joinThread (CMPI_THREAD_TYPE thread, CMPI_THREAD_RETURN *returnCode)
 97            {
 98               ((Thread*)thread)->join();
 99 schuur 1.4    *returnCode=(CMPI_THREAD_RETURN)((Thread*)thread)->get_exit();
100 schuur 1.2    return 0;
101            }
102            
103             static int exitThread(CMPI_THREAD_RETURN return_code)
104             {
105 schuur 1.4     Thread::getCurrent()->exit_self((PEGASUS_THREAD_RETURN)return_code);
106 schuur 1.2     return 0;
107             }
108            
109             static int cancelThread(CMPI_THREAD_TYPE thread)
110             {
111                ((Thread*)thread)->cancel();
112                return 0;
113             }
114            
115             static int threadSleep(CMPIUint32 msec)
116             {
117                Thread::getCurrent()->sleep(msec);
118                return 0;
119             }
120            
121            static int threadOnce (int *once, void (*init)(void))
122 schuur 1.1 {
123 schuur 1.2    if (*once==0) {
124                  *once=1;
125                  (init)();
126               }
127               return *once;
128            }
129            
130            
131            static int createThreadKey(CMPI_THREAD_KEY_TYPE *key, void (*cleanup)(void*))
132            {
133               return pegasus_key_create((PEGASUS_THREAD_KEY_TYPE*)key);
134            }
135            
136            static int destroyThreadKey(CMPI_THREAD_KEY_TYPE key)
137            {
138               return pegasus_key_delete(key);
139 schuur 1.1 }
140            
141            static void *getThreadSpecific(CMPI_THREAD_KEY_TYPE key)
142            {
143               return pegasus_get_thread_specific(key);
144            }
145            
146 schuur 1.2 static  int setThreadSpecific(CMPI_THREAD_KEY_TYPE key, void * value)
147 schuur 1.1 {
148               return pegasus_set_thread_specific(key,value);
149            }
150            
151            
152            static CMPI_MUTEX_TYPE newMutex (int opt)
153            {
154               Mutex *m=new Mutex();
155               return m;
156            }
157            
158            static void destroyMutex (CMPI_MUTEX_TYPE m)
159            {
160               delete ((Mutex*)m);
161            }
162            
163            static void lockMutex (CMPI_MUTEX_TYPE m)
164            {
165               ((Mutex*)m)->lock(pegasus_thread_self());
166            }
167            
168 schuur 1.1 static void unlockMutex (CMPI_MUTEX_TYPE m)
169            {
170               ((Mutex*)m)->unlock();
171            }
172            
173            
174            
175            static CMPI_COND_TYPE newCondition (int opt)
176            {
177               Condition *c=new Condition();
178               return c;
179            }
180            
181            static void destroyCondition (CMPI_COND_TYPE c)
182            {
183               delete (Condition*)c;
184            }
185            
186 schuur 1.5 static int condWait (CMPI_COND_TYPE c, CMPI_MUTEX_TYPE m)
187            {
188               // need to take care of mutex
189               ((Condition*)c)->unlocked_wait(Thread::getCurrent()->self());
190               return 0;
191            }
192            
193 schuur 1.1 static int timedCondWait(CMPI_COND_TYPE c, CMPI_MUTEX_TYPE m, struct timespec *wait)
194            {
195 schuur 1.2 
196            /* this is not truely mapping to pthread_timed_wait
197               but will work for the time beeing
198            */
199               int msec;
200 schuur 1.4    struct timespec next=*wait;
201            
202            #if defined(CMPI_PLATFORM_WIN32_IX86_MSVC)
203               struct timeval {
204                  long tv_sec;
205                  long tv_usec;
206               }now;
207               struct _timeb timebuffer;
208            
209               _ftime( &timebuffer );
210               now.tv_sec=timebuffer.time;
211               now.tv_usec=timebuffer.millitm*1000; 
212            #else 
213 schuur 1.2    struct timeval now;
214               gettimeofday(&now, NULL);
215 schuur 1.4 #endif
216            
217 schuur 1.2    if (next.tv_nsec>1000000000) {
218                  next.tv_sec+=next.tv_nsec/1000000000;
219                  next.tv_nsec=next.tv_nsec%1000000000;
220               }
221               msec=(next.tv_sec-now.tv_sec)*1000;
222               msec+=(next.tv_nsec/1000000)-(now.tv_usec/1000);
223            
224               Thread::getCurrent()->sleep(msec);
225               return 0;
226 schuur 1.1 }
227            
228            
229 schuur 1.2 static int signalCondition(CMPI_COND_TYPE cond)
230            {
231               ((Condition*)cond)->signal(Thread::getCurrent()->self());
232               return 0;
233            }
234            
235 schuur 1.1 static CMPIBrokerExtFT brokerExt_FT={
236                 CMPICurrentVersion,
237                 resolveFileName,
238 schuur 1.2 
239 schuur 1.1      newThread,
240 schuur 1.2      joinThread,
241                 exitThread,
242                 cancelThread,
243                 threadSleep,
244                 threadOnce,
245            
246 schuur 1.1      createThreadKey,
247 schuur 1.2      destroyThreadKey,
248 schuur 1.1      getThreadSpecific,
249                 setThreadSpecific,
250 schuur 1.2 
251 schuur 1.1      newMutex,
252                 destroyMutex,
253                 lockMutex,
254                 unlockMutex,
255 schuur 1.2 
256 schuur 1.1      newCondition,
257                 destroyCondition,
258 schuur 1.5      condWait,
259 schuur 1.1      timedCondWait,
260 schuur 1.5      signalCondition                       // Signal not supported yet
261 schuur 1.1 };
262            
263            CMPIBrokerExtFT *CMPI_BrokerExt_Ftab=&brokerExt_FT;
264            
265            
266            PEGASUS_NAMESPACE_END
267            
268            
269            

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2