-// Copyright (C) 2006-2012 CEA/DEN, EDF R&D
+// Copyright (C) 2006-2023 CEA, EDF
//
// 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.
+// 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
#include <iostream>
#include <sstream>
-#ifdef WNT
+#ifdef WIN32
#include <windows.h>
#define dlopen LoadLibrary
#define dlclose FreeLibrary
using namespace YACS::ENGINE;
+char CppContainer::KIND[]="Cpp";
+
//#define _DEVDEBUG_
#include "YacsTrace.hxx"
void CppContainer::unLock()
{
- _mutex.unlock();
+ _mutex.unLock();
+}
+
+std::string CppContainer::getKind() const
+{
+ return KIND;
}
-bool CppContainer::isAlreadyStarted(const ComponentInstance *inst) const
+bool CppContainer::isAlreadyStarted(const Task *askingNode) const
{
return NULL != _trueCont;
}
-void CppContainer::start(const ComponentInstance *inst) throw (YACS::Exception)
+void CppContainer::start(const Task *askingNode)
{
_trueCont = LocalContainer::get();
}
+void CppContainer::shutdown(int level)
+{
+
+}
+
Container *CppContainer::clone() const
{
if(_isAttachedOnCloning)
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)
+ {
+ 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 */)
+CppComponent * CppContainer::createComponentInstance(const std::string & componentName)
{
- 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)
{
- 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 ComponentInstance *inst) const
+std::string CppContainer::getPlacementId(const Task *askingNode) const
{
return "/";
}
-std::string CppContainer::getFullPlacementId(const ComponentInstance *inst) const
+std::string CppContainer::getFullPlacementId(const Task *askingNode) const
{
return "/";
}
-void CppContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
+void CppContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const
{
if(inst->getKind()!=CppComponent::KIND)
throw Exception("CppContainer::checkCapabilityToDealWith : CppContainer is not able to deal with this type of ComponentInstance.");
void LocalContainer::destroy()
{
- if (NULL == _singleton)
- return;
-
- // destroy all component instances
- _instance_mapMutex.lock(); // lock
- std::multimap<std::string, CppComponent *>::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<std::string, CppComponent *>::iterator iI, iJ;
+ for (iI=_instance_map.begin(); iI != _instance_map.end(); iI = iJ)
{
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<std::string, LocalLibrary>::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<std::string, LocalLibrary>::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;
}
C = new CppComponent(o, r, t, name);
_instance_mapMutex.lock(); // lock to be alone
_instance_map.insert(std::pair<std::string, CppComponent *>(name, C));
- _instance_mapMutex.unlock(); // unlock
+ _instance_mapMutex.unLock(); // unlock
return C;
}
void LocalContainer::unregisterComponentInstance(CppComponent * C)
{
- _instance_mapMutex.lock(); // lock to be alone
- _instance_map.erase(C->getCompoName());
- _instance_mapMutex.unlock(); // unlock
+ _instance_mapMutex.lock(); // lock to be alone
+ _instance_map.erase(C->getCompoName());
+ _instance_mapMutex.unLock(); // unlock
}
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)
}
}
-#ifndef WNT
+#ifndef WIN32
+#ifdef __APPLE__
+ std::string impl_name = std::string ("lib") + aCompName + std::string("Local.dylib");
+#else
std::string impl_name = std::string ("lib") + aCompName + std::string("Local.so");
+#endif
if(sprefix != "")
impl_name = sprefix + std::string("/") + impl_name;
#else
#endif
DEBTRACE("impl_name = " << impl_name);
-#if defined( WNT )
+#if defined( WIN32 )
HMODULE handle;
- handle = dlopen( impl_name.c_str() ) ;
+#if defined(UNICODE)
+ size_t length = strlen(impl_name.c_str()) + sizeof(char);
+ wchar_t* aPath = new wchar_t[length + 1];
+ memset(aPath, '\0', length);
+ mbstowcs(aPath, impl_name.c_str(), length);
+#else
+ const char* aPath = fullLibName.c_str();
+#endif
+ handle = dlopen( aPath ) ;
#else
void* handle;
handle = dlopen( impl_name.c_str() , RTLD_LAZY ) ;
#endif
const char * sError;
-#if defined( WNT )
+#if defined( WIN32 )
sError = "Not available here !";
#endif
-#if defined( WNT )
+#if defined( WIN32 )
if (!handle)
#else
sError = dlerror();
void *ihandle, *rhandle, *phandle = NULL, *thandle = NULL;
ihandle = dlsym(handle, "__init");
-#if defined( WNT )
+#if defined( WIN32 )
if (!ihandle)
#else
if (sError = dlerror())
}
rhandle = dlsym(handle, "__run");
-#if defined( WNT )
+#if defined( WIN32 )
if (!rhandle)
#else
if (sError = dlerror())
}
thandle = dlsym(handle, "__terminate");
-#if defined( WNT )
+#if defined( WIN32 )
if (!thandle)
#else
if (sError = dlerror())