X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2FCppContainer.cxx;h=af5aec92ac6ecb97b2a6ace9ab8da26ea109aedd;hb=7dd1d2d397e8222594e688c681a098b5459110fe;hp=e43f6265a36283aaf6dfe421ef0c4a22138ba9c0;hpb=a84e60a749da66dffb73297fa5082b70b9d62f7d;p=modules%2Fyacs.git diff --git a/src/runtime/CppContainer.cxx b/src/runtime/CppContainer.cxx index e43f6265a..af5aec92a 100644 --- a/src/runtime/CppContainer.cxx +++ b/src/runtime/CppContainer.cxx @@ -1,6 +1,32 @@ +// Copyright (C) 2006-2016 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + #include #include +#ifdef WIN32 +#include +#define dlopen LoadLibrary +#define dlclose FreeLibrary +#define dlsym GetProcAddress +#else #include +#endif #include "CppContainer.hxx" #include "CppComponent.hxx" @@ -11,6 +37,8 @@ using namespace YACS::ENGINE; +char CppContainer::KIND[]="Cpp"; + //#define _DEVDEBUG_ #include "YacsTrace.hxx" @@ -44,17 +72,27 @@ void CppContainer::lock() void CppContainer::unLock() { - _mutex.unlock(); + _mutex.unLock(); +} + +std::string CppContainer::getKind() const +{ + return KIND; } -bool CppContainer::isAlreadyStarted() const +bool CppContainer::isAlreadyStarted(const Task *askingNode) const { return NULL != _trueCont; } -void CppContainer::start() throw (YACS::Exception) +void CppContainer::start(const Task *askingNode) throw (YACS::Exception) { - _trueCont = LocalContainer::get(); + _trueCont = LocalContainer::get(); +} + +void CppContainer::shutdown(int level) +{ + } Container *CppContainer::clone() const @@ -68,61 +106,69 @@ Container *CppContainer::clone() const return new CppContainer(*this); } -bool CppContainer::loadComponentLibrary(const std::string & componentName) throw (YACS::Exception) +Container *CppContainer::cloneAlways() const { - if (_trueCont) + return new CppContainer(*this); +} + +bool CppContainer::loadComponentLibrary(const std::string & componentName) throw (YACS::Exception) + { + if (_trueCont) { - LocalLibrary L = _trueCont->loadComponentLibrary(componentName); - return L.good(); + LocalLibrary L = _trueCont->loadComponentLibrary(componentName); + return L.good(); } - else + else { - std::string mesg = "CppContainer not started"; - throw YACS::Exception(mesg); + std::string mesg = "CppContainer not started"; + throw YACS::Exception(mesg); + } + return false; } - return false; -} CppComponent * CppContainer::createComponentInstance(const std::string & componentName, int /* studyID */) { - DEBTRACE("CppContainer::createComponentInstance"); - if (_trueCont) - return _trueCont->createComponentInstance(componentName.c_str()); - else + DEBTRACE("CppContainer::createComponentInstance"); + if (_trueCont) + return _trueCont->createComponentInstance(componentName.c_str()); + else { - std::string mesg = "CppContainer not started"; - throw YACS::Exception(mesg); + std::string mesg = "CppContainer not started"; + throw YACS::Exception(mesg); } } void CppContainer::createInternalInstance(const std::string & name, void *&obj, - RunFunction &r, TerminateFunction &t) + RunFunction &r, TerminateFunction &t) { - DEBTRACE("CppContainer::createInternalInstance"); - if (_trueCont) - _trueCont->createInternalInstance(name.c_str(), obj, r, t); - else - { - std::string mesg = "CppContainer not started"; - throw YACS::Exception(mesg); - } + DEBTRACE("CppContainer::createInternalInstance"); + if (_trueCont) + _trueCont->createInternalInstance(name.c_str(), obj, r, t); + else + { + std::string mesg = "CppContainer not started"; + throw YACS::Exception(mesg); + } } -void CppContainer::unregisterComponentInstance(CppComponent * C) +void CppContainer::unregisterComponentInstance(CppComponent *compo) { - if (_trueCont) - { - _trueCont->unregisterComponentInstance(C); - } + if (_trueCont) + _trueCont->unregisterComponentInstance(compo); } -std::string CppContainer::getPlacementId() const +std::string CppContainer::getPlacementId(const Task *askingNode) const { - return "/"; + return "/"; } -void CppContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw (Exception) +std::string CppContainer::getFullPlacementId(const Task *askingNode) const +{ + return "/"; +} + +void CppContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception) { if(inst->getKind()!=CppComponent::KIND) throw Exception("CppContainer::checkCapabilityToDealWith : CppContainer is not able to deal with this type of ComponentInstance."); @@ -153,31 +199,31 @@ LocalContainer * LocalContainer::get() void LocalContainer::destroy() { - if (NULL == _singleton) - return; - - // destroy all component instances - _instance_mapMutex.lock(); // lock - std::multimap::iterator iI, iJ; - for (iI=_instance_map.begin(); iI != _instance_map.end(); iI = iJ) + if (NULL == _singleton) + return; + + // destroy all component instances + _instance_mapMutex.lock(); // lock + std::multimap::iterator iI, iJ; + for (iI=_instance_map.begin(); iI != _instance_map.end(); iI = iJ) { - iJ = iI++; - iI->second->setContainer(NULL); - delete iI->second; + iJ = iI++; + iI->second->setContainer(NULL); + delete iI->second; } - _instance_map.clear(); - _instance_mapMutex.unlock(); // unlock - - // unload all dynamic libraries - _library_mapMutex.lock(); - std::map::iterator iL; - for (iL=_library_map.begin(); iL != _library_map.end(); iL++) - dlclose(iL->second.handle); - _library_map.clear(); - _library_mapMutex.unlock(); - - delete _singleton; - _singleton = NULL; + _instance_map.clear(); + _instance_mapMutex.unLock(); // unlock + + // unload all dynamic libraries + _library_mapMutex.lock(); + std::map::iterator iL; + for (iL=_library_map.begin(); iL != _library_map.end(); iL++) + dlclose(iL->second.handle); + _library_map.clear(); + _library_mapMutex.unLock(); + + delete _singleton; + _singleton = NULL; } @@ -206,12 +252,12 @@ CppComponent * LocalContainer::createComponentInstance(const char * name) C = new CppComponent(o, r, t, name); _instance_mapMutex.lock(); // lock to be alone _instance_map.insert(std::pair(name, C)); - _instance_mapMutex.unlock(); // unlock + _instance_mapMutex.unLock(); // unlock return C; } void LocalContainer::createInternalInstance(const char *name, void *&obj, - RunFunction &r, TerminateFunction &t) + RunFunction &r, TerminateFunction &t) { LocalLibrary L; @@ -234,23 +280,14 @@ void LocalContainer::createInternalInstance(const char *name, void *&obj, void LocalContainer::unregisterComponentInstance(CppComponent * C) { - _instance_mapMutex.lock(); // lock to be alone - _instance_map.erase(C->getName()); - _instance_mapMutex.unlock(); // unlock + _instance_mapMutex.lock(); // lock to be alone + _instance_map.erase(C->getCompoName()); + _instance_mapMutex.unLock(); // unlock } -//============================================================================= -/*! - * load a new component class (C++ implementation) - * \param componentName like COMPONENT - * try to load libCOMPONENTLocal.so - * \return true if dlopen successfull or already done, false otherwise - */ -//============================================================================= - inline void toupper (std::string & s) { - transform (s.begin (), s.end (), s.begin (), (int(*)(int)) toupper); + transform (s.begin (), s.end (), s.begin (), (int(*)(int)) toupper); } LocalLibrary LocalContainer::loadComponentLibrary(const std::string & aCompName, const char * prefix, bool forcedLoad) @@ -286,7 +323,7 @@ LocalLibrary LocalContainer::loadComponentLibrary(const std::string & aCompName } } -#ifndef WNT +#ifndef WIN32 std::string impl_name = std::string ("lib") + aCompName + std::string("Local.so"); if(sprefix != "") impl_name = sprefix + std::string("/") + impl_name; @@ -296,17 +333,25 @@ LocalLibrary LocalContainer::loadComponentLibrary(const std::string & aCompName #endif DEBTRACE("impl_name = " << impl_name); - void* handle; -#if defined( WNT ) - handle = dlopen( impl_name.c_str() , 0 ) ; +#if defined( WIN32 ) + HMODULE handle; + handle = dlopen( impl_name.c_str() ) ; #else + void* handle; handle = dlopen( impl_name.c_str() , RTLD_LAZY ) ; #endif const char * sError; - sError = dlerror(); +#if defined( WIN32 ) + sError = "Not available here !"; +#endif +#if defined( WIN32 ) + if (!handle) +#else + sError = dlerror(); if ((sError = dlerror()) || !handle) +#endif { std::stringstream msg; msg << "Can't load shared library : " << impl_name @@ -318,7 +363,11 @@ LocalLibrary LocalContainer::loadComponentLibrary(const std::string & aCompName void *ihandle, *rhandle, *phandle = NULL, *thandle = NULL; ihandle = dlsym(handle, "__init"); +#if defined( WIN32 ) + if (!ihandle) +#else if (sError = dlerror()) +#endif { dlclose(handle); std::stringstream msg; @@ -329,7 +378,11 @@ LocalLibrary LocalContainer::loadComponentLibrary(const std::string & aCompName } rhandle = dlsym(handle, "__run"); +#if defined( WIN32 ) + if (!rhandle) +#else if (sError = dlerror()) +#endif { dlclose(handle); std::stringstream msg; @@ -340,7 +393,11 @@ LocalLibrary LocalContainer::loadComponentLibrary(const std::string & aCompName } thandle = dlsym(handle, "__terminate"); +#if defined( WIN32 ) + if (!thandle) +#else if (sError = dlerror()) +#endif { dlclose(handle); std::stringstream msg;