24 #define dlopen LoadLibrary
25 #define dlclose FreeLibrary
26 #define dlsym GetProcAddress
53 DEBTRACE(
"CppContainer::CppContainer()");
65 DEBTRACE(
"CppContainer::~CppContainer()");
123 std::string mesg =
"CppContainer not started";
131 DEBTRACE(
"CppContainer::createComponentInstance");
136 std::string mesg =
"CppContainer not started";
144 DEBTRACE(
"CppContainer::createInternalInstance");
149 std::string mesg =
"CppContainer not started";
174 throw Exception(
"CppContainer::checkCapabilityToDealWith : CppContainer is not able to deal with this type of ComponentInstance.");
207 std::multimap<std::string, CppComponent *>::iterator iI, iJ;
211 iI->second->setContainer(NULL);
219 std::map<std::string, LocalLibrary>::iterator iL;
221 dlclose(iL->second.handle);
254 _instance_map.insert(std::pair<std::string, CppComponent *>(name, C));
264 std::map<std::string, LocalLibrary>::iterator foundL =
_library_map.find(name);
290 transform (s.begin (), s.end (), s.begin (), (
int(*)(
int))
toupper);
303 std::map<std::string, LocalLibrary >::iterator itLib
315 std::string s = aCompName +
"_ROOT_DIR";
317 const char *
t = getenv(s.c_str());
322 sprefix +=
"/lib/salome";
328 std::string impl_name = std::string (
"lib") + aCompName + std::string(
"Local.dylib");
330 std::string impl_name = std::string (
"lib") + aCompName + std::string(
"Local.so");
333 impl_name = sprefix + std::string(
"/") + impl_name;
335 std::string impl_name = aCompName + std::string(
"Local.dll");
336 impl_name = sprefix + std::string(
"\\") + impl_name;
338 DEBTRACE(
"impl_name = " << impl_name);
343 size_t length = strlen(impl_name.c_str()) +
sizeof(char);
344 wchar_t* aPath =
new wchar_t[length + 1];
345 memset(aPath,
'\0', length);
346 mbstowcs(aPath, impl_name.c_str(), length);
348 const char* aPath = fullLibName.c_str();
350 handle = dlopen( aPath ) ;
353 handle = dlopen( impl_name.c_str() , RTLD_LAZY ) ;
358 sError =
"Not available here !";
365 if ((sError = dlerror()) || !handle)
368 std::stringstream msg;
369 msg <<
"Can't load shared library : " << impl_name
370 <<
" (dlopen error : " << sError <<
") at "
371 << __FILE__ <<
":" << __LINE__;
375 void *ihandle, *rhandle, *phandle = NULL, *thandle = NULL;
377 ihandle = dlsym(handle,
"__init");
381 if (sError = dlerror())
385 std::stringstream msg;
386 msg <<
"Library " << impl_name
387 <<
" doesn't contains initialization function (" << sError <<
") at "
388 << __FILE__ <<
":" << __LINE__;
392 rhandle = dlsym(handle,
"__run");
396 if (sError = dlerror())
400 std::stringstream msg;
401 msg <<
"Library " << impl_name
402 <<
" doesn't contains main switch function (" << sError <<
") at "
403 << __FILE__ <<
":" << __LINE__;
407 thandle = dlsym(handle,
"__terminate");
411 if (sError = dlerror())
415 std::stringstream msg;
416 msg <<
"Library " << impl_name
417 <<
" doesn't contains terminate function (" << sError <<
") at "
418 << __FILE__ <<
":" << __LINE__;
421 phandle = dlsym(handle,
"__ping");
432 std::map<std::string, LocalLibrary >::iterator itLib
437 dlclose(itLib->second.handle);
void toupper(std::string &s)
Base class for all component instances.
const std::string & getCompoName() const
virtual std::string getKind() const
Return the component kind.
bool _isAttachedOnCloning
void createInternalInstance(const std::string &componentName, void *&obj, RunFunction &r, TerminateFunction &t)
YACS::ENGINE::Container * clone() const
WARNING ! clone behaviour MUST be in coherence with what is returned by isAttachedOnCloning() method
Container * cloneAlways() const
std::string getFullPlacementId(const Task *askingNode) const
void unregisterComponentInstance(CppComponent *C)
bool loadComponentLibrary(const std::string &componentName)
void checkCapabilityToDealWith(const ComponentInstance *inst) const
std::string getPlacementId(const Task *askingNode) const
std::string getKind() const
CppComponent * createComponentInstance(const std::string &componentName)
void start(const Task *askingNode)
LocalContainer * _trueCont
YACS::BASES::Mutex _mutex
bool isAlreadyStarted(const Task *askingNode) const
static YACS::ENGINE::LocalContainer * get()
void unLoadComponentLibrary(const std::string &aCompName)
LocalLibrary loadComponentLibrary(const std::string &, const char *prefix=NULL, bool forcedLoad=false)
static std::map< std::string, LocalLibrary > _library_map
YACS::BASES::Mutex _instance_mapMutex
void unregisterComponentInstance(CppComponent *C)
virtual ~LocalContainer()
static LocalContainer * _singleton
friend class CppComponent
static std::multimap< std::string, CppComponent * > _instance_map
YACS::BASES::Mutex _library_mapMutex
void createInternalInstance(const char *componentName, void *&obj, RunFunction &r, TerminateFunction &t)
CppComponent * createComponentInstance(const char *componentName)
Find or create a new C++ component instance.
void(* RunFunction)(void *, const char *, int, int, Any **, Any **, returnInfo *)
void(* TerminateFunction)(void **)
TerminateFunction terminateHandle