1 #include "RuntimeSALOME.hxx"
2 #include "CppComponent.hxx"
3 #include "CppContainer.hxx"
4 #include "TypeCode.hxx"
6 #include "DynLibLoader.hxx"
8 using namespace YACS::ENGINE;
15 #include "YacsTrace.hxx"
17 const char CppComponent::KIND[] = "Cpp";
19 static std::ostream & operator<<(std::ostream & f, const Any & A)
21 const TypeCode * t = A.getType();
30 f << "(type Double) " << A.getDoubleValue();
33 f << "(type Int) " << A.getIntValue();
36 f << "(type String) " << A.getStringValue();
39 f << "(type Bool) " << A.getBoolValue();
45 f << "(type Sequence) ";
48 const SequenceAny * sA = dynamic_cast<const SequenceAny *>(&A);
49 for (i=0; i<sA->size(); i++)
50 f << " " << *((*sA)[i]);
57 std::string CppComponent::getKind() const
59 return CppComponent::KIND;
62 //! CppComponent constructor
63 CppComponent::CppComponent(const std::string &name) : ComponentInstance(name)
65 _container = getRuntime()->createContainer(CppNode::KIND);
66 if (!_container->isAlreadyStarted())
69 CppContainer * _containerC = dynamic_cast<CppContainer *> (_container);
70 _containerC->createInternalInstance(name, __obj, __run, __terminate);
73 //! CppComponent copy constructor
74 CppComponent::CppComponent(const CppComponent& other) : ComponentInstance(other._name), __run(other.__run),
75 __terminate(other.__terminate), __obj(0)
77 _container = getRuntime()->createContainer(CppNode::KIND);
78 if (!_container->isAlreadyStarted())
81 CppContainer * _containerC = dynamic_cast<CppContainer *> (_container);
82 _containerC->createInternalInstance(_name, __obj, __run, __terminate);
85 CppComponent::~CppComponent()
87 DEBTRACE("CppComponent::~CppComponent()");
88 if (__terminate) __terminate(&__obj);
90 ((CppContainer *) _container)->unregisterComponentInstance(this);
93 void CppComponent::run (const char * service, int nbIn, int nbOut,
94 Any ** argIn, Any ** argOut) throw (YACS::Exception)
97 returnInfo return_code;
100 std::ostringstream sDebug;
101 sDebug << _name << "::" << service << "(";
102 for (i=0; i<nbIn; i++) {
103 sDebug << *(argIn[i]);
110 __run(__obj, service, nbIn, nbOut, argIn, argOut, &return_code);
112 if (return_code.code != 0) {
114 std::cerr << sDebug << " ???" << std::endl;
116 throw YACS::Exception(return_code.message);
122 for (i=0; i<nbOut; i++) {
123 sDebug << " " << *(argOut[i]);
126 DEBTRACE(sDebug.str());
130 //! Unload the component
131 void CppComponent::unload()
134 DEBTRACE("CppComponent::unload : not implemented ");
137 //! Is the component instance already loaded ?
138 bool CppComponent::isLoaded()
140 return NULL != __obj;
143 void CppComponent::load()
146 _container = getRuntime()->createContainer(CppNode::KIND);
151 CppContainer * containerC= dynamic_cast< CppContainer *> (_container);
153 containerC->lock();//To be sure
154 if(!_container->isAlreadyStarted())
162 containerC->unLock();
166 containerC->unLock();
167 containerC->lock();//To be sure
169 YACS::BASES::DynLibLoader D(_name + "Local");
171 bool isLoadable = containerC->loadComponentLibrary(_name);
173 containerC->createInternalInstance(_name, __obj, __run, __terminate);
177 containerC->unLock();
178 throw Exception("CppComponent::load : Error while trying to create a new component.");
180 containerC->unLock();
186 ServiceNode* CppComponent::createNode(const std::string& name)
188 CppNode* node=new CppNode(name);
189 node->setComponent(this);
193 //! Clone the component instance
194 ComponentInstance* CppComponent::clone() const
196 if(_isAttachedOnCloning)
199 return (ComponentInstance*) (this);
202 return new CppComponent(*this);