cmpiBrokerExt.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Novell, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Novell, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00035 #include "cmpisrv.h"
00036 //#include "OW_CIMException.hpp"
00037 //#include "OW_CIMProperty.hpp"
00038 //#include "OW_CIMObjectPath.hpp"
00039 //#include "OW_ProviderEnvironmentIFC.hpp"
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 // Factory section
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; // detached arg not supported. 
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; // spec says none defined yet. 
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    try
00242    {
00243       OpenWBEM::Condition* lcond = (OpenWBEM::Condition*)cond; 
00244       OpenWBEM::Mutex* mux = (OpenWBEM::Mutex*) mutex; 
00245       OpenWBEM::NonRecursiveMutexLock lock(mux); 
00246       lcond->wait(*mux); 
00247    }
00248    catch(...)
00249    {
00250       return 1; 
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,  // mbExtExitThread, 
00275    mbExtCancelThread, 
00276    mbExtThreadSleep, 
00277    mbExtThreadOnce, 
00278    NULL, // mbExtCreateThreadKey, 
00279    NULL, // mbExtDestroyThreadKey, 
00280    NULL, // mbExtGetThreadSpecific, 
00281    NULL, // mbExtSetThreadSpecific, 
00282    mbExtNewMutex, 
00283    mbExtDestroyMutex, 
00284    mbExtLockMutex,
00285    mbExtUnlockMutex, 
00286    NULL, // mbExtNewCondition, 
00287    NULL, // mbExtDestroyCondition, 
00288    NULL, // mbExtCondWait, 
00289    NULL, // mbExtTimedCondWait, 
00290    NULL, // mbExtSignalCondition 
00291 };
00292 
00293 CMPIBrokerExtFT *CMPI_BrokerExt_Ftab=&brokerExt_FT;
00294 
00295 
00296 

Generated on Thu Feb 9 08:47:48 2006 for openwbem by  doxygen 1.4.6