1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __Cpp_CONTAINER_HXX__
21 #define __Cpp_CONTAINER_HXX__
26 #include "Container.hxx"
27 #include "CppComponent.hxx"
46 InitFunction initHandle;
47 RunFunction runHandle;
48 PingFunction pingHandle;
49 TerminateFunction terminateHandle;
52 LocalLibrary(HMODULE h, InitFunction i, RunFunction r,
54 LocalLibrary(void *h, InitFunction i, RunFunction r,
56 PingFunction p, TerminateFunction t)
57 : handle(h), initHandle(i), runHandle(r),
58 pingHandle(p), terminateHandle(t) {}
60 : handle(NULL), initHandle(NULL), runHandle(NULL),
61 pingHandle(NULL), terminateHandle(NULL) {}
64 return (handle != NULL) && (initHandle != NULL) &&
65 (runHandle != NULL) && (terminateHandle != NULL);
70 // Local container singleton
71 class LocalContainer {
73 friend class CppComponent;
77 static YACS::ENGINE::LocalContainer * get();
79 LocalLibrary loadComponentLibrary(const std::string &, const char * prefix = NULL,
80 bool forcedLoad = false);
81 CppComponent * createComponentInstance(const char * componentName);
82 void createInternalInstance(const char * componentName,
83 void *& obj, RunFunction &r, TerminateFunction &t);
84 void unLoadComponentLibrary(const std::string & aCompName);
85 void unregisterComponentInstance(CppComponent * C);
90 virtual ~LocalContainer();
92 YACS::BASES::Mutex _instance_mapMutex, _library_mapMutex;
93 static std::map<std::string, LocalLibrary > _library_map; // libraries, loaded
94 static std::multimap<std::string, CppComponent *> _instance_map;
98 static LocalContainer *_singleton;
103 class CppContainer : public Container {
105 friend class CppComponent;
106 friend class LocalContainer;
111 virtual ~CppContainer();
112 bool isAlreadyStarted(const ComponentInstance *inst) const;
113 void start(const ComponentInstance *inst) throw (YACS::Exception);
114 std::string getPlacementId(const ComponentInstance *inst) const;
115 std::string getFullPlacementId(const ComponentInstance *inst) const;
116 YACS::ENGINE::Container *clone() const;
121 void checkCapabilityToDealWith(const ComponentInstance *inst) const throw (YACS::Exception);
122 bool loadComponentLibrary(const std::string & componentName) throw (YACS::Exception);
123 CppComponent * createComponentInstance(const std::string & componentName, int studyID = 0);
124 void createInternalInstance(const std::string & componentName,
125 void *& obj, RunFunction &r, TerminateFunction &t);
126 void unregisterComponentInstance(CppComponent * C);
129 YACS::BASES::Mutex _mutex;
130 LocalContainer * _trueCont;