26 #include <libxml/parser.h> 
   27 #include <libxml/tree.h> 
   32 #include <sys/types.h> 
   47 using namespace YACS::ENGINE;
 
   52 static YACS::BASES::Mutex 
MUTEX;
 
   55   : _script(other._script), 
ServiceNode(other, father)
 
   69   return new XmlNode(*
this,father);
 
   96   char dir[]=
"yacsXXXXXX";
 
  102     GetTempPath(MAX_PATH+1, mdir);
 
  103     CreateDirectory(mdir, NULL);
 
  105     char* mdir=mkdtemp(dir);
 
  109         perror(
"mkdtemp failed");
 
  110         std::cerr << 
"Problem in mkdtemp " << dir << 
" " << mdir << std::endl;
 
  111         throw Exception(
"Execution problem in mkdtemp");
 
  114   std::string sdir(dir);
 
  115   std::string input=sdir+
"/input";
 
  116   std::ofstream 
f(input.c_str());
 
  117   f<<
"<methodCall> <methodName>" << 
_method << 
"</methodName> <params>"<<std::endl;
 
  118   DEBTRACE(
"---------------XmlNode::inputs---------------");
 
  119   list<InputPort *>::iterator iter;
 
  125       const char* ob=p->
getXml();
 
  127       f<<
"<param>" << ob << 
"</param>"<<std::endl;
 
  129   f<<
"</params>"<<std::endl;
 
  130   f<<
"</methodCall>"<<std::endl;
 
  132   DEBTRACE(
"--------------XmlNode::calculation---------------" << 
_ref );
 
  133   std::string call=sdir+
"/run.sh";
 
  134   std::ofstream 
run(call.c_str());
 
  135   run << 
"#!/bin/sh" << std::endl;
 
  136   run << 
"cd " << sdir << std::endl;
 
  138     run << 
_ref << 
"> stdout 2>&1 " << std::endl;
 
  140     run << 
"../"<<
_ref << 
"> stdout 2>&1 " << std::endl;
 
  143   chmod(call.c_str(),00777);
 
  145   std::string call2=
"/bin/sh "+call;
 
  146   int ret=system(call2.c_str());
 
  149       std::cerr << 
"Problem: " << ret << std::endl;
 
  153   std::string output=sdir+
"/output";
 
  155   doc = xmlReadFile(output.c_str(), NULL, 0);
 
  158       DEBTRACE(
"Failed to parse " << output);
 
  162   cur = xmlDocGetRootElement(doc);
 
  169   if (xmlStrcmp(cur->name, (
const xmlChar *) 
"methodResponse")) 
 
  171       DEBTRACE(
"document of the wrong type, root node != methodResponse");
 
  175   cur = cur->xmlChildrenNode;
 
  176   xmlBufferPtr buf=xmlBufferCreate();
 
  177   list<OutputPort *>::iterator iter2;
 
  185       if ((!xmlStrcmp(cur->name, (
const xmlChar *)
"fault")))
 
  191       if ((!xmlStrcmp(cur->name, (
const xmlChar *)
"params")))
 
  193           xmlNodePtr cur0 = cur->xmlChildrenNode;
 
  196               if ((!xmlStrcmp(cur0->name, (
const xmlChar *)
"param")))
 
  198                   xmlNodePtr cur1 = cur0->xmlChildrenNode;
 
  201                       if ((!xmlStrcmp(cur1->name, (
const xmlChar *)
"value")))
 
  203                           xmlNodePtr cur2=cur1->xmlChildrenNode;
 
  206                               if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"int")))
 
  214                                       throw Exception(
"Execution problem:mismatch in output numbers");
 
  217                                   xmlNodeDump(buf,doc,cur1,0,0);
 
  219                                   p->
put(xmlBufferContent(buf));
 
  221                               if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"double")))
 
  229                                       throw Exception(
"Execution problem:mismatch in output numbers");
 
  232                                   xmlNodeDump(buf,doc,cur1,0,0);
 
  234                                   p->
put(xmlBufferContent(buf));
 
  236                               if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"string")))
 
  244                                       throw Exception(
"Execution problem:mismatch in output port numbers");
 
  247                                   xmlNodeDump(buf,doc,cur1,0,0);
 
  249                                   p->
put(xmlBufferContent(buf));
 
  251                               if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"boolean")))
 
  259                                       throw Exception(
"Execution problem:mismatch in output port numbers");
 
  262                                   xmlNodeDump(buf,doc,cur1,0,0);
 
  264                                   p->
put(xmlBufferContent(buf));
 
  266                               if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"objref")))
 
  274                                       throw Exception(
"Execution problem:mismatch in output port numbers");
 
  277                                   xmlNodeDump(buf,doc,cur1,0,0);
 
  279                                   p->
put(xmlBufferContent(buf));
 
  281                               if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"struct")))
 
  289                                       throw Exception(
"Execution problem:mismatch in output port numbers");
 
  292                                   xmlNodeDump(buf,doc,cur1,0,0);
 
  294                                   p->
put(xmlBufferContent(buf));
 
  296                               if ((!xmlStrcmp(cur2->name, (
const xmlChar *)
"array")))
 
  303                                       xmlNodeDump(buf,doc,cur1,0,0);
 
  305                                       p->
put(xmlBufferContent(buf));
 
  310                                       xmlNodePtr cur3=cur2->xmlChildrenNode;
 
  313                                           if ((!xmlStrcmp(cur3->name, (
const xmlChar *)
"data")))
 
  315                                               xmlNodePtr cur4=cur3->xmlChildrenNode;
 
  318                                                   if ((!xmlStrcmp(cur4->name, (
const xmlChar *)
"value")))
 
  326                                                           throw Exception(
"Execution problem:mismatch in output port numbers");
 
  329                                                       xmlNodeDump(buf,doc,cur4,0,0);
 
  332                                                       p->
put(xmlBufferContent(buf));