Version: 8.3.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) throw (YACS::Exception)
 
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::ComponentInstance
clone () const
 Clone the component instance. More...
 
virtual
YACS::ENGINE::ComponentInstance
cloneAlways () 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 attachOnCloning () const
 
virtual void dettachOnCloning () const
 
bool isAttachedOnCloning () const
 
virtual std::string getFileRepr () const
 For dump in file. More...
 
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 ()
 

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 ()
 
- 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::CppComponent ( const std::string &  name)

CppComponent constructor.

Definition at line 86 of file CppComponent.cxx.

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

Referenced by clone(), and cloneAlways().

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 }
YACS::ENGINE::CppComponent::CppComponent ( void *  obj,
RunFunction  r,
TerminateFunction  t,
const std::string &  name 
)
inline

Definition at line 48 of file CppComponent.hxx.

50  : __obj(obj), __run(r), __terminate(t), ComponentInstance(name) {}
CppComponent::CppComponent ( const CppComponent other)

CppComponent copy constructor.

Definition at line 97 of file CppComponent.cxx.

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

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 }
CppComponent::~CppComponent ( )
virtual

Definition at line 107 of file CppComponent.cxx.

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

108 {
109  DEBTRACE("CppComponent::~CppComponent()");
111  if (_container)
112  ((CppContainer *) _container)->unregisterComponentInstance(this);
113 }

Member Function Documentation

ComponentInstance * CppComponent::clone ( ) const
virtual

Clone the component instance.

Implements YACS::ENGINE::ComponentInstance.

Definition at line 215 of file CppComponent.cxx.

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

216 {
218  {
219  incrRef();
220  return (ComponentInstance*) (this);
221  }
222  else
223  return new CppComponent(*this);
224 }
YACS::ENGINE::ComponentInstance * CppComponent::cloneAlways ( ) const
virtual

Implements YACS::ENGINE::ComponentInstance.

Definition at line 226 of file CppComponent.cxx.

References CppComponent().

227 {
228  return new CppComponent(*this);
229 }
ServiceNode * CppComponent::createNode ( const std::string &  name)
virtual

Implements YACS::ENGINE::ComponentInstance.

Definition at line 207 of file CppComponent.cxx.

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

208 {
209  CppNode* node=new CppNode(name);
210  node->setComponent(this);
211  return node;
212 }
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.

References KIND.

76 {
77  return CppComponent::KIND;
78 }
std::string CppComponent::getKindForNode ( ) const
virtual

Reimplemented from YACS::ENGINE::ComponentInstance.

Definition at line 80 of file CppComponent.cxx.

References KIND.

81 {
82  return CppComponent::KIND;
83 }
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.

References __obj.

161 {
162  return NULL != __obj;
163 }
void CppComponent::load ( Task askingNode)
virtual

Load the component instance.

Implements YACS::ENGINE::ComponentInstance.

Definition at line 165 of file CppComponent.cxx.

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().

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 }
void CppComponent::run ( const char *  service,
int  nbIn,
int  nbOut,
Any **  argIn,
Any **  argOut 
) throw (YACS::Exception)

Definition at line 115 of file CppComponent.cxx.

References YACS::ENGINE::returnInfo::code, DEBTRACE, CORBAEngineTest::i, and YACS::ENGINE::returnInfo::message.

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

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 }
void CppComponent::unload ( Task askingNode)
virtual

Unload the component.

Implements YACS::ENGINE::ComponentInstance.

Definition at line 153 of file CppComponent.cxx.

References DEBTRACE.

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

Member Data Documentation

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

Definition at line 69 of file CppComponent.hxx.

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

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

Definition at line 70 of file CppComponent.hxx.

Referenced by load().

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

Definition at line 71 of file CppComponent.hxx.

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

const char CppComponent::KIND = "Cpp"
static

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