Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / engine / ComponentInstance.hxx
1 #ifndef __COMPONENTINSTANCE_HXX__
2 #define __COMPONENTINSTANCE_HXX__
3
4 #include "RefCounter.hxx"
5
6 #include <list>
7 #include <string>
8
9 namespace YACS
10 {
11   namespace ENGINE
12   {
13     class Container;
14     class ServiceNode;
15
16 /*! \brief Base class for all component instances.
17  *
18  *
19  * This is an abstract class that must be specialized in runtime.
20  * Specialized classes must provide implementation for loading of
21  * a component (load method) unloading (unload method) and an 
22  * information method (isLoaded) about the state of the component
23  *
24  * A component instance is used by one or more ServiceNode to execute
25  * services of this component instance
26  *
27  * \see ServiceNode
28  */
29     class ComponentInstance : public RefCounter
30     {
31     protected:
32       virtual ~ComponentInstance();
33     public:
34       ComponentInstance(const std::string& name);
35       ComponentInstance(const ComponentInstance& other);
36       const std::string& getCompoName() const { return _compoName; }
37       const std::string& getInstanceName() const { return _instanceName; }
38       int getNumId() const { return _numId; }
39       virtual void setContainer(Container *cont);
40       Container *getContainer() const { return _container; }
41 //! Load the component instance
42       virtual void load() = 0;
43 //! Unload the component instance
44       virtual void unload() = 0;
45 //! Indicate if the component instance is loaded (true) or not
46       virtual bool isLoaded() = 0;
47       virtual void attachOnCloning() const;
48       virtual void dettachOnCloning() const;
49       bool isAttachedOnCloning() const;
50 //! For dump in file
51       virtual std::string getFileRepr() const;
52       virtual ServiceNode* createNode(const std::string& name)=0;
53       virtual ComponentInstance *clone() const = 0;
54 //! Return the component kind
55 /*!
56  * A runtime can provide several implementations of a component instance.
57  * Each implementation has a different kind. A ComponentInstance can be 
58  * associated to a ServiceNode is they have the same kind.
59  */
60       virtual std::string getKind() const;
61       static const char KIND[];
62     protected:
63       //! \b WARNING : _compoName identify only the component type.
64       std::string _compoName;
65       //! \b WARNING : _InstanceName has a strong semantic. It discriminates ComponentInstance instances each other.
66       std::string _instanceName;
67       int _numId;
68       Container *_container;
69       mutable bool _isAttachedOnCloning;
70     protected:
71       static const char NULL_FILE_REPR[];
72       static int _total;
73     };
74   }
75 }
76
77 #endif