00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035 #include "cmpisrv.h"
00036
00037
00038
00039
00040 #include "OW_Logger.hpp"
00041 #include "OW_String.hpp"
00042 #include "OW_Thread.hpp"
00043 #include "OW_ThreadOnce.hpp"
00044 #include <cstring>
00045
00046 namespace
00047 {
00048 const OpenWBEM::String COMPONENT_NAME("ow.provider.cmpi.ifc");
00049 }
00050
00051 #define CM_LOGGER() \
00052 (* static_cast<OpenWBEM::ProviderEnvironmentIFCRef *>(CMPI_ThreadContext::getBroker()->hdl))->getLogger(COMPONENT_NAME)
00053
00054
00055 using namespace OW_NAMESPACE;
00056
00057
00058 static char* mbExtResolveFileName(const char* libName)
00059 {
00060 try
00061 {
00062 String slibName(libName);
00063 String fileName;
00064 #if defined(OW_WIN32)
00065 fileName = slibName + String(".dll");
00066 #elif defined(OW_HPUX)
00067 fileName = String("lib") + slibName + String(".sl");
00068 #elif defined(OW_DARWIN)
00069 fileName = String("lib") + slibName + String(".dylib");
00070 #else
00071 fileName = String("lib") + slibName + String(".so");
00072 #endif
00073
00074 return strdup(fileName.c_str());
00075 }
00076 catch(...)
00077 {
00078 return 0;
00079 }
00080 }
00081
00082 class CMPIThread : public OpenWBEM::Thread
00083 {
00084 public:
00085 CMPIThread(CMPI_THREAD_RETURN (CMPI_THREAD_CDECL *start)(void *),
00086 void *param)
00087 : m_start(start)
00088 , m_param(param)
00089 , m_rval(0)
00090 {
00091 }
00092 CMPI_THREAD_RETURN getReturnValue() const { return m_rval; }
00093
00094 protected:
00095 virtual Int32 run()
00096 {
00097 m_rval = m_start(m_param);
00098 return 0;
00099 }
00100
00101 private:
00102 CMPI_THREAD_RETURN (CMPI_THREAD_CDECL *m_start)(void*);
00103 void* m_param;
00104 CMPI_THREAD_RETURN m_rval;
00105 };
00106
00107 CMPI_THREAD_TYPE mbExtNewThread (CMPI_THREAD_RETURN (CMPI_THREAD_CDECL *start)(void *),
00108 void *parm, int detached)
00109 {
00110 (void)detached;
00111 CMPIThread* newThread = new CMPIThread(start, parm);
00112 newThread->start();
00113 CMPI_THREAD_TYPE rval = (CMPI_THREAD_TYPE)newThread;
00114 return rval;
00115 }
00116
00117 int mbExtJoinThread (CMPI_THREAD_TYPE thread, CMPI_THREAD_RETURN *retval )
00118 {
00119 try
00120 {
00121 CMPIThread* theThread = (CMPIThread*)thread;
00122 theThread->join();
00123 (*retval) = theThread->getReturnValue();
00124 delete theThread;
00125 }
00126 catch(...)
00127 {
00128 return 1;
00129 }
00130 return 0;
00131 }
00132
00133 int mbExtExitThread (CMPI_THREAD_RETURN return_code)
00134 {
00135 return -1;
00136 }
00137
00138 int mbExtCancelThread (CMPI_THREAD_TYPE thread)
00139 {
00140 try
00141 {
00142 CMPIThread* theThread = (CMPIThread*)thread;
00143 theThread->cancel();
00144 }
00145 catch(...)
00146 {
00147 return 1;
00148 }
00149 return 0;
00150 }
00151
00152 int mbExtThreadSleep (CMPIUint32 msec)
00153 {
00154 try
00155 {
00156 OpenWBEM::Thread::sleep(msec);
00157 }
00158 catch(...)
00159 {
00160 return 1;
00161 }
00162 return 0;
00163 }
00164
00165 int mbExtThreadOnce (int *once, void (*init)(void))
00166 {
00167 try
00168 {
00169 callOnce(*reinterpret_cast<OnceFlag*>(once), init);
00170 }
00171 catch(...)
00172 {
00173 return 1;
00174 }
00175 return 0;
00176 }
00177
00178 int mbExtCreateThreadKey (CMPI_THREAD_KEY_TYPE *key, void (*cleanup)(void*))
00179 {
00180 return -1;
00181 }
00182
00183 int mbExtDestroyThreadKey (CMPI_THREAD_KEY_TYPE key)
00184 {
00185 return -1;
00186 }
00187
00188 void *mbExtGetThreadSpecific (CMPI_THREAD_KEY_TYPE key)
00189 {
00190 return 0;
00191 }
00192
00193 int mbExtSetThreadSpecific (CMPI_THREAD_KEY_TYPE key, void * value)
00194 {
00195 return -1;
00196 }
00197
00198 CMPI_MUTEX_TYPE mbExtNewMutex (int opt)
00199 {
00200 (void) opt;
00201 OpenWBEM::Mutex* mux = new OpenWBEM::Mutex;
00202 CMPI_MUTEX_TYPE rval = (CMPI_MUTEX_TYPE)mux;
00203 return rval;
00204 }
00205
00206 void mbExtDestroyMutex (CMPI_MUTEX_TYPE arg)
00207 {
00208 OpenWBEM::Mutex* mux = (OpenWBEM::Mutex*)arg;
00209 delete mux;
00210 }
00211
00212 void mbExtLockMutex (CMPI_MUTEX_TYPE arg)
00213 {
00214 OpenWBEM::Mutex* mux = (OpenWBEM::Mutex*)arg;
00215 mux->acquire();
00216 }
00217
00218 void mbExtUnlockMutex (CMPI_MUTEX_TYPE arg)
00219 {
00220 OpenWBEM::Mutex* mux = (OpenWBEM::Mutex*)arg;
00221 mux->release();
00222 }
00223
00224 CMPI_COND_TYPE mbExtNewCondition (int opt)
00225 {
00226 OpenWBEM::Condition* cond = new OpenWBEM::Condition;
00227 CMPI_COND_TYPE rval = (CMPI_COND_TYPE)cond;
00228 return rval;
00229 }
00230
00231 void mbExtDestroyCondition (CMPI_COND_TYPE arg)
00232 {
00233 OpenWBEM::Condition* cond = (OpenWBEM::Condition*)arg;
00234 delete cond;
00235 }
00236
00237 int mbExtCondWait (CMPI_COND_TYPE cond,
00238 CMPI_MUTEX_TYPE mutex)
00239 {
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 return 0;
00255 }
00256
00257 int mbExtTimedCondWait (CMPI_COND_TYPE cond,
00258 CMPI_MUTEX_TYPE mutex, struct timespec *wait)
00259 {
00260 return 0;
00261 }
00262
00263 int mbExtSignalCondition (CMPI_COND_TYPE cond)
00264 {
00265 return 0;
00266 }
00267
00268
00269 static CMPIBrokerExtFT brokerExt_FT={
00270 CMPICurrentVersion,
00271 mbExtResolveFileName,
00272 mbExtNewThread,
00273 mbExtJoinThread,
00274 NULL,
00275 mbExtCancelThread,
00276 mbExtThreadSleep,
00277 mbExtThreadOnce,
00278 NULL,
00279 NULL,
00280 NULL,
00281 NULL,
00282 mbExtNewMutex,
00283 mbExtDestroyMutex,
00284 mbExtLockMutex,
00285 mbExtUnlockMutex,
00286 NULL,
00287 NULL,
00288 NULL,
00289 NULL,
00290 NULL,
00291 };
00292
00293 CMPIBrokerExtFT *CMPI_BrokerExt_Ftab=&brokerExt_FT;
00294
00295
00296