Version: 9.16.0
YACS::ENGINE::CppComponent Class Reference

#include <CppComponent.hxx>

Inheritance diagram for YACS::ENGINE::CppComponent:
Collaboration diagram for YACS::ENGINE::CppComponent:

Public Member Functions

 CppComponent (const std::string &name)
 CppComponent constructor. More...
 
 CppComponent (void *obj, RunFunction r, TerminateFunction t, const std::string &name)
 
 CppComponent (const CppComponent &other)
 CppComponent copy constructor. More...
 
virtual ~CppComponent ()
 
void run (const char *service, int nbIn, int nbOut, Any **argIn, Any **argOut)
 
virtual std::string getKind () const
 Return the component kind. More...
 
virtual std::string getKindForNode () const
 
virtual void load (Task *askingNode)
 Load the component instance. More...
 
virtual void unload (Task *askingNode)
 Unload the component. More...
 
virtual bool isLoaded (Task *askingNode) const
 Is the component instance already loaded ? More...
 
virtual ServiceNodecreateNode (const std::string &name)
 
virtual YACS::ENGINE::ComponentInstanceclone () const
 Clone the component instance. More...
 
virtual YACS::ENGINE::ComponentInstancecloneAlways () const
 
- Public Member Functions inherited from YACS::ENGINE::ComponentInstance
 ComponentInstance (const std::string &name)
 
 ComponentInstance (const ComponentInstance &other)
 
const std::string & getCompoName () const
 
const std::string & getInstanceName () const
 
void setName (const std::string &name)
 
virtual void setAnonymous (bool anon)
 
virtual bool isAnonymous ()
 
int getNumId () const
 
virtual bool setContainer (Container *cont)
 
ContainergetContainer () const
 
virtual void load (Task *askingNode)=0
 Load the component instance. More...
 
virtual void unload (Task *askingNode)=0
 Unload the component instance. More...
 
virtual bool isLoaded (Task *askingNode) const =0
 Indicate if the component instance is loaded (true) or not. More...
 
virtual void attachOnCloning () const
 
virtual void dettachOnCloning () const
 
bool isAttachedOnCloning () const
 
virtual std::string getFileRepr () const
 For dump in file. More...
 
virtual ServiceNodecreateNode (const std::string &name)=0
 
virtual ComponentInstanceclone () const =0
 
virtual ComponentInstancecloneAlways () const =0
 
virtual std::string getKind () const
 Return the component kind. More...
 
virtual std::string getKindForNode () const
 
virtual void shutdown (int level)
 
- Public Member Functions inherited from YACS::ENGINE::PropertyInterface
virtual ~PropertyInterface ()
 
virtual void setProperty (const std::string &name, const std::string &value)
 
virtual std::string getProperty (const std::string &name)
 Get a property value given its name. More...
 
std::map< std::string, std::string > getProperties () const
 
virtual void setProperties (std::map< std::string, std::string > properties)
 
- Public Member Functions inherited from YACS::ENGINE::RefCounter
unsigned int getRefCnt () const
 
void incrRef () const
 
bool decrRef () const
 

Static Public Attributes

static const char KIND [] = "Cpp"
 
- Static Public Attributes inherited from YACS::ENGINE::ComponentInstance
static const char KIND [] =""
 
- Static Public Attributes inherited from YACS::ENGINE::RefCounter
static unsigned int _totalCnt =0
 

Protected Attributes

void * __obj
 
YACS::ENGINE::RunFunction __run
 
YACS::ENGINE::TerminateFunction __terminate
 
- Protected Attributes inherited from YACS::ENGINE::ComponentInstance
std::string _compoName
 WARNING : _compoName identify only the component type. More...
 
std::string _instanceName
 WARNING : _InstanceName has a strong semantic. It discriminates ComponentInstance instances each other. More...
 
int _numId
 
Container_container
 
bool _isAttachedOnCloning
 
bool _anonymous
 
- Protected Attributes inherited from YACS::ENGINE::PropertyInterface
std::map< std::string, std::string > _propertyMap
 
- Protected Attributes inherited from YACS::ENGINE::RefCounter
unsigned int _cnt
 

Additional Inherited Members

- Protected Member Functions inherited from YACS::ENGINE::ComponentInstance
virtual ~ComponentInstance ()
 
- Protected Member Functions inherited from YACS::ENGINE::RefCounter
 RefCounter ()
 
 RefCounter (const RefCounter &other)
 
virtual ~RefCounter ()
 
- Static Protected Attributes inherited from YACS::ENGINE::ComponentInstance
static const char NULL_FILE_REPR [] ="No repr specified for ComponentInstance"
 
static int _total = 0
 

Detailed Description

Definition at line 44 of file CppComponent.hxx.

Constructor & Destructor Documentation

◆ CppComponent() [1/3]

CppComponent::CppComponent ( const std::string &  name)

CppComponent constructor.

Definition at line 86 of file CppComponent.cxx.

86 : ComponentInstance(name), __obj(0), __run(0),__terminate(0)
87{
89 /* This part of code has been commented because the load part is supposed to do that !
90 if (!_container->isAlreadyStarted(0))
91 _container->start(0);
92 CppContainer * _containerC = dynamic_cast<CppContainer *> (_container);
93 _containerC->createInternalInstance(name, __obj, __run, __terminate);*/
94}
ComponentInstance(const std::string &name)
YACS::ENGINE::TerminateFunction __terminate
YACS::ENGINE::RunFunction __run
static const char KIND[]
Definition: CppNode.hxx:62
virtual Container * createContainer(const std::string &kind="")
Definition: Runtime.cxx:221
YACSLIBENGINE_EXPORT Runtime * getRuntime()
Definition: Runtime.cxx:61

References YACS::ENGINE::ComponentInstance::_container, YACS::ENGINE::Runtime::createContainer(), YACS::ENGINE::getRuntime(), and YACS::ENGINE::CppNode::KIND.

Referenced by clone(), and cloneAlways().

◆ CppComponent() [2/3]

YACS::ENGINE::CppComponent::CppComponent ( void *  obj,
RunFunction  r,
TerminateFunction  t,
const std::string &  name 
)
inline

◆ CppComponent() [3/3]

CppComponent::CppComponent ( const CppComponent other)

CppComponent copy constructor.

Definition at line 97 of file CppComponent.cxx.

98{
100 /* This part of code has been commented because the load part is supposed to do that !
101 if (!_container->isAlreadyStarted(0))
102 _container->start(0);
103 CppContainer * _containerC = dynamic_cast<CppContainer *> (_container);
104 _containerC->createInternalInstance(_compoName, __obj, __run, __terminate);*/
105}
std::string _compoName
WARNING : _compoName identify only the component type.

References YACS::ENGINE::ComponentInstance::_container, YACS::ENGINE::Runtime::createContainer(), YACS::ENGINE::getRuntime(), and YACS::ENGINE::CppNode::KIND.

◆ ~CppComponent()

CppComponent::~CppComponent ( )
virtual

Definition at line 107 of file CppComponent.cxx.

108{
109 DEBTRACE("CppComponent::~CppComponent()");
111 if (_container)
112 ((CppContainer *) _container)->unregisterComponentInstance(this);
113}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References __obj, __terminate, YACS::ENGINE::ComponentInstance::_container, and DEBTRACE.

Member Function Documentation

◆ clone()

ComponentInstance * CppComponent::clone ( ) const
virtual

Clone the component instance.

Implements YACS::ENGINE::ComponentInstance.

Definition at line 215 of file CppComponent.cxx.

216{
218 {
219 incrRef();
220 return (ComponentInstance*) (this);
221 }
222 else
223 return new CppComponent(*this);
224}
Base class for all component instances.
CppComponent(const std::string &name)
CppComponent constructor.

References YACS::ENGINE::ComponentInstance::_isAttachedOnCloning, CppComponent(), and YACS::ENGINE::RefCounter::incrRef().

◆ cloneAlways()

YACS::ENGINE::ComponentInstance * CppComponent::cloneAlways ( ) const
virtual

Implements YACS::ENGINE::ComponentInstance.

Definition at line 226 of file CppComponent.cxx.

227{
228 return new CppComponent(*this);
229}

References CppComponent().

◆ createNode()

ServiceNode * CppComponent::createNode ( const std::string &  name)
virtual

Implements YACS::ENGINE::ComponentInstance.

Definition at line 207 of file CppComponent.cxx.

208{
209 CppNode* node=new CppNode(name);
210 node->setComponent(this);
211 return node;
212}
Class for C++ Nodes (in process component)
Definition: CppNode.hxx:47
virtual void setComponent(ComponentInstance *compo)
Associate an existing component instance to this service node AND check the consistency regarding the...

References YACS::ENGINE::ServiceNode::setComponent().

◆ getKind()

std::string CppComponent::getKind ( ) const
virtual

Return the component kind.

A runtime can provide several implementations of a component instance. Each implementation has a different kind. A ComponentInstance can be associated to a ServiceNode is they have the same kind.

Reimplemented from YACS::ENGINE::ComponentInstance.

Definition at line 75 of file CppComponent.cxx.

76{
77 return CppComponent::KIND;
78}
static const char KIND[]

References KIND.

◆ getKindForNode()

std::string CppComponent::getKindForNode ( ) const
virtual

Reimplemented from YACS::ENGINE::ComponentInstance.

Definition at line 80 of file CppComponent.cxx.

81{
82 return CppComponent::KIND;
83}

References KIND.

◆ isLoaded()

bool CppComponent::isLoaded ( Task askingNode) const
virtual

Is the component instance already loaded ?

Implements YACS::ENGINE::ComponentInstance.

Definition at line 160 of file CppComponent.cxx.

161{
162 return NULL != __obj;
163}

References __obj.

◆ load()

void CppComponent::load ( Task askingNode)
virtual

Load the component instance.

Implements YACS::ENGINE::ComponentInstance.

Definition at line 165 of file CppComponent.cxx.

166{
167 if (!_container)
168 {
170 }
171
172 if(_container)
173 {
174 CppContainer *containerC(dynamic_cast< CppContainer *> (_container));
175 if(!containerC)
176 throw Exception("The type of container should be CPP for component CPP !");
177 containerC->lock();//To be sure
178 if(!_container->isAlreadyStarted(askingNode))
179 {
180 try
181 {
182 _container->start(askingNode);
183 }
184 catch(Exception& e)
185 {
186 containerC->unLock();
187 throw e;
188 }
189 }
190 containerC->unLock();
191 containerC->lock();//To be sure
192
193 bool isLoadable(containerC->loadComponentLibrary(_compoName));
194 if (isLoadable)
195 containerC->createInternalInstance(_compoName, __obj, __run, __terminate);
196
197 if(NULL == __obj)
198 {
199 containerC->unLock();
200 throw Exception("CppComponent::load : Error while trying to create a new component.");
201 }
202 containerC->unLock();
203 return;
204 }
205}
virtual void start(const Task *askingNode)=0
virtual bool isAlreadyStarted(const Task *askingNode) const =0

References __obj, __run, __terminate, YACS::ENGINE::ComponentInstance::_compoName, YACS::ENGINE::ComponentInstance::_container, YACS::ENGINE::Runtime::createContainer(), YACS::ENGINE::CppContainer::createInternalInstance(), YACS::ENGINE::getRuntime(), YACS::ENGINE::Container::isAlreadyStarted(), YACS::ENGINE::CppNode::KIND, YACS::ENGINE::CppContainer::loadComponentLibrary(), YACS::ENGINE::CppContainer::lock(), YACS::ENGINE::Container::start(), and YACS::ENGINE::CppContainer::unLock().

◆ run()

void CppComponent::run ( const char *  service,
int  nbIn,
int  nbOut,
Any **  argIn,
Any **  argOut 
)

Definition at line 115 of file CppComponent.cxx.

117{
118 int i;
119 returnInfo return_code;
120
121#ifdef _DEVDEBUG_
122 std::ostringstream sDebug;
123 sDebug << getInstanceName() << "::" << service << "(";
124 for (i=0; i<nbIn; i++) {
125 sDebug << *(argIn[i]);
126 if (i<nbIn-1)
127 sDebug << ", ";
128 }
129 sDebug << ")";
130#endif
131
132 __run(__obj, service, nbIn, nbOut, argIn, argOut, &return_code);
133
134 if (return_code.code != 0) {
135#ifdef _DEVDEBUG_
136 std::cerr << sDebug << " ???" << std::endl;
137#endif
138 throw YACS::Exception(return_code.message);
139 }
140
141#ifdef _DEVDEBUG_
142 if (nbOut > 0) {
143 sDebug << "->";
144 for (i=0; i<nbOut; i++) {
145 sDebug << " " << *(argOut[i]);
146 }
147 }
148 DEBTRACE(sDebug.str());
149#endif
150}
const std::string & getInstanceName() const

References __obj, __run, YACS::ENGINE::returnInfo::code, DEBTRACE, YACS::ENGINE::ComponentInstance::getInstanceName(), yacsorb.CORBAEngineTest::i, and YACS::ENGINE::returnInfo::message.

Referenced by YACS::ENGINE::CppNode::execute().

◆ unload()

void CppComponent::unload ( Task askingNode)
virtual

Unload the component.

Implements YACS::ENGINE::ComponentInstance.

Definition at line 153 of file CppComponent.cxx.

154{
155 //Not implemented
156 DEBTRACE("CppComponent::unload : not implemented ");
157}

References DEBTRACE.

Member Data Documentation

◆ __obj

void* YACS::ENGINE::CppComponent::__obj
protected

Definition at line 69 of file CppComponent.hxx.

Referenced by isLoaded(), load(), run(), and ~CppComponent().

◆ __run

YACS::ENGINE::RunFunction YACS::ENGINE::CppComponent::__run
protected

Definition at line 70 of file CppComponent.hxx.

Referenced by load(), and run().

◆ __terminate

YACS::ENGINE::TerminateFunction YACS::ENGINE::CppComponent::__terminate
protected

Definition at line 71 of file CppComponent.hxx.

Referenced by load(), and ~CppComponent().

◆ KIND

const char CppComponent::KIND = "Cpp"
static

The documentation for this class was generated from the following files: