Version: 9.16.0
CppContainer.hxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
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
33namespace 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
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
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);
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;
122 bool loadComponentLibrary(const std::string & componentName);
123 CppComponent * createComponentInstance(const std::string & componentName);
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(); }
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
Base class for all component instances.
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::map< std::string, std::string > getResourceProperties(const std::string &name) const
std::string getFullPlacementId(const Task *askingNode) const
std::map< std::string, std::string > getProperties() const
void unregisterComponentInstance(CppComponent *C)
bool loadComponentLibrary(const std::string &componentName)
std::string getProperty(const std::string &name) const
void checkCapabilityToDealWith(const ComponentInstance *inst) const
void addComponentName(const std::string &name)
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
void setProperty(const std::string &name, const std::string &value)
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)
static LocalContainer * _singleton
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.
Proc * p
Definition: driver.cxx:216
void(* RunFunction)(void *, const char *, int, int, Any **, Any **, returnInfo *)
void(* PingFunction)()
void *(* InitFunction)()
void(* TerminateFunction)(void **)
def h(x, y, destx, desty)
Definition: graph.py:272
LocalLibrary(void *h, InitFunction i, RunFunction r, PingFunction p, TerminateFunction t)
TerminateFunction terminateHandle