Version: 8.3.0
CppContainer.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef __Cpp_CONTAINER_HXX__
21 #define __Cpp_CONTAINER_HXX__
22 
23 #include <map>
24 #include <string>
25 #include "Mutex.hxx"
26 #include "Container.hxx"
27 #include "CppComponent.hxx"
28 
29 #ifdef WIN32
30 #include <windows.h>
31 #endif
32 
33 namespace YACS
34 {
35  namespace ENGINE
36  {
37 
38  struct LocalLibrary {
39 
40 #if defined( WIN32 )
41  HMODULE handle;
42 #else
43  void * handle;
44 #endif
45 
50 
51 #if defined( WIN32 )
53 #else
55 #endif
57  : handle(h), initHandle(i), runHandle(r),
58  pingHandle(p), terminateHandle(t) {}
60  : handle(NULL), initHandle(NULL), runHandle(NULL),
61  pingHandle(NULL), terminateHandle(NULL) {}
62 
63  bool good() {
64  return (handle != NULL) && (initHandle != NULL) &&
65  (runHandle != NULL) && (terminateHandle != NULL);
66  }
67 
68  };
69 
70  // Local container singleton
72 
73  friend class CppComponent;
74 
75  public:
76 
77  static YACS::ENGINE::LocalContainer * get();
78  void destroy();
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);
86 
87  protected:
88 
90  virtual ~LocalContainer();
91 
93  static std::map<std::string, LocalLibrary > _library_map; // libraries, loaded
94  static std::multimap<std::string, CppComponent *> _instance_map;
95 
96 
97  private:
99 
100 
101  };
102 
103  class CppContainer : public Container
104  {
105  friend class CppComponent;
106  friend class LocalContainer;
107  public:
108  CppContainer();
109  virtual ~CppContainer();
110  std::string getKind() const;
111  bool isAlreadyStarted(const Task *askingNode) const;
112  void start(const Task *askingNode) throw (YACS::Exception);
113  void shutdown(int level);
114  std::string getPlacementId(const Task *askingNode) const;
115  std::string getFullPlacementId(const Task *askingNode) const;
117  Container *cloneAlways() const;
118  void lock();
119  void unLock();
120 
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);
127  //
128  void setProperty(const std::string& name,const std::string& value) { }
129  std::string getProperty(const std::string& name) const { return std::string(); }
130  void clearProperties() { }
131  void addComponentName(const std::string& name) { }
132  std::map<std::string,std::string> getProperties() const { return std::map<std::string,std::string>(); }
133  std::map<std::string,std::string> getResourceProperties(const std::string& name) const { return std::map<std::string,std::string>(); }
134  //
135  public:
136  static char KIND[];
137  protected:
138  YACS::BASES::Mutex _mutex;
140 
141  };
142  };
143 };
144 
145 #endif
146