26 #include <libxml/parser.h>
27 #include <libxml/tree.h>
32 #include <sys/types.h>
52 static YACS::BASES::Mutex
MUTEX;
55 : _script(other._script),
ServiceNode(other, father)
69 return new XmlNode(*
this,father);
96 char dir[]=
"yacsXXXXXX";
102 wchar_t mdir[512 + 1];
106 GetTempPath(MAX_PATH+1, mdir);
107 CreateDirectory(mdir, NULL);
109 char* mdir=mkdtemp(dir);
113 perror(
"mkdtemp failed");
114 std::cerr <<
"Problem in mkdtemp " << dir <<
" " << mdir << std::endl;
115 throw Exception(
"Execution problem in mkdtemp");
118 std::string sdir(dir);
119 std::string input=sdir+
"/input";
120 std::ofstream
f(input.c_str());
121 f<<
"<methodCall> <methodName>" <<
_method <<
"</methodName> <params>"<<std::endl;
122 DEBTRACE(
"---------------XmlNode::inputs---------------");
123 list<InputPort *>::iterator iter;
128 DEBTRACE(
"port kind: " <<
p->edGetType()->kind());
129 const char* ob=
p->getXml();
131 f<<
"<param>" << ob <<
"</param>"<<std::endl;
133 f<<
"</params>"<<std::endl;
134 f<<
"</methodCall>"<<std::endl;
136 DEBTRACE(
"--------------XmlNode::calculation---------------" <<
_ref );
137 std::string call=sdir+
"/run.sh";
138 std::ofstream
run(call.c_str());
139 run <<
"#!/bin/sh" << std::endl;
140 run <<
"cd " << sdir << std::endl;
142 run <<
_ref <<
"> stdout 2>&1 " << std::endl;
144 run <<
"../"<<
_ref <<
"> stdout 2>&1 " << std::endl;
147 chmod(call.c_str(),00777);
149 std::string call2=
"/bin/sh "+call;
150 int ret=system(call2.c_str());
153 std::cerr <<
"Problem: " << ret << std::endl;
157 std::string output=sdir+
"/output";
159 doc = xmlReadFile(output.c_str(), NULL, 0);
162 DEBTRACE(
"Failed to parse " << output);
166 cur = xmlDocGetRootElement(
doc);
173 if (xmlStrcmp(cur->name, (
const xmlChar *)
"methodResponse"))
175 DEBTRACE(
"document of the wrong type, root node != methodResponse");
179 cur = cur->xmlChildrenNode;
180 xmlBufferPtr buf=xmlBufferCreate();
181 list<OutputPort *>::iterator iter2;
189 if ((!xmlStrcmp(cur->name, (
const xmlChar *)
"fault")))
195 if ((!xmlStrcmp(cur->name, (
const xmlChar *)
"params")))
197 xmlNodePtr cur0 = cur->xmlChildrenNode;
200 if ((!xmlStrcmp(cur0->name, (
const xmlChar *)
"param")))
202 xmlNodePtr cur1 = cur0->xmlChildrenNode;
205 if ((!xmlStrcmp(cur1->name, (
const xmlChar *)
"value")))
207 xmlNodePtr cur2=cur1->xmlChildrenNode;
210 if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"int")))
218 throw Exception(
"Execution problem:mismatch in output numbers");
221 xmlNodeDump(buf,
doc,cur1,0,0);
223 p->put(xmlBufferContent(buf));
225 if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"double")))
233 throw Exception(
"Execution problem:mismatch in output numbers");
236 xmlNodeDump(buf,
doc,cur1,0,0);
238 p->put(xmlBufferContent(buf));
240 if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"string")))
248 throw Exception(
"Execution problem:mismatch in output port numbers");
251 xmlNodeDump(buf,
doc,cur1,0,0);
253 p->put(xmlBufferContent(buf));
255 if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"boolean")))
263 throw Exception(
"Execution problem:mismatch in output port numbers");
266 xmlNodeDump(buf,
doc,cur1,0,0);
268 p->put(xmlBufferContent(buf));
270 if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"objref")))
278 throw Exception(
"Execution problem:mismatch in output port numbers");
281 xmlNodeDump(buf,
doc,cur1,0,0);
283 p->put(xmlBufferContent(buf));
285 if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"struct")))
293 throw Exception(
"Execution problem:mismatch in output port numbers");
296 xmlNodeDump(buf,
doc,cur1,0,0);
298 p->put(xmlBufferContent(buf));
300 if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"array")))
307 xmlNodeDump(buf,
doc,cur1,0,0);
309 p->put(xmlBufferContent(buf));
314 xmlNodePtr cur3=cur2->xmlChildrenNode;
317 if ((!xmlStrcmp(cur3->name, (
const xmlChar *)
"data")))
319 xmlNodePtr cur4=cur3->xmlChildrenNode;
322 if ((!xmlStrcmp(cur4->name, (
const xmlChar *)
"value")))
330 throw Exception(
"Execution problem:mismatch in output port numbers");
333 xmlNodeDump(buf,
doc,cur4,0,0);
336 p->put(xmlBufferContent(buf));
static YACS::BASES::Mutex MUTEX
Base class for all composed nodes.
std::string getName() const
int getNumberOfOutputPorts() const
std::list< InputPort * > _setOfInputPort
std::list< OutputPort * > _setOfOutputPort
Base class for all nodes.
std::string _implementation
Class for XML Output Ports.
Class for calculation node associated with a component service.
virtual std::string getScript() const
Node * simpleClone(ComposedNode *father, bool editionOnly) const
virtual std::string getKind() const
Return the service node kind.
virtual void setScript(const std::string &script)
XmlNode(const XmlNode &other, ComposedNode *father)
static const char IMPL_NAME[]
virtual void setRef(const std::string &ref)
Associate a new component instance to this service node.
def ref(target, callback=None)