1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef _REMOTEPARSERS_HXX_
21 #define _REMOTEPARSERS_HXX_
23 #include "inlineParsers.hxx"
25 extern YACS::ENGINE::Proc* currentProc;
26 extern YACS::ENGINE::Runtime* theRuntime;
31 template <class T=YACS::ENGINE::InlineNode*>
32 struct remotetypeParser:public inlinetypeParser<T>
34 static remotetypeParser<T> remoteParser;
36 virtual void onStart(const XML_Char* el, const XML_Char** attr);
37 virtual void onEnd(const char *el,parser* child)
39 DEBTRACE( "remotetypeParser::onEnd: " << el )
40 std::string element(el);
41 if(element == "kind")this->kind(((stringtypeParser*)child)->post()); // inherited
42 else if(element == "function")this->function(((functypeParser*)child)->post());
43 else if(element == "script")this->script(((codetypeParser*)child)->post());
44 else if(element == "load") this->load(((loadtypeParser*)child)->post());
45 else if(element == "property")this->property(((propertytypeParser*)child)->post());
46 else if(element == "inport") this->inport(((inporttypeParser<myinport>*)child)->post());
47 else if(element == "outport") this->outport(((outporttypeParser<myoutport>*)child)->post());
50 virtual void load (const loadon& l)
52 DEBTRACE( "remotenode_load: " << l._container);
53 this->_container=l._container;
56 void function (const myfunc& f)
58 DEBTRACE( "remote_function: " << f._code )
59 YACS::ENGINE::InlineFuncNode *fnode;
60 fnode=theRuntime->createFuncNode(this->_kind,this->_name);
61 fnode->setScript(f._code);
62 fnode->setFname(f._name);
63 fnode->setExecutionMode("remote");
67 void script (const myfunc& f)
69 DEBTRACE( "remote_script: " << f._code )
70 YACS::ENGINE::InlineNode *node;
71 node=theRuntime->createScriptNode(this->_kind,this->_name);
72 node->setScript(f._code);
73 node->setExecutionMode("remote");
79 DEBTRACE( "remote_post " << this->_node->getName() )
80 if(this->_state == "disabled")this->_node->exDisabledState();
83 if(currentProc->containerMap.count(this->_container) != 0)
85 // a container with name (this->_container) exists. Use it
86 this->_node->setContainer(currentProc->containerMap[this->_container]);
88 else if(this->_container == "" && currentProc->containerMap.count("DefaultContainer") != 0)
90 // a container with name (this->_container) does not exist
91 //a default container is defined : use it
92 this->_node->setContainer(currentProc->containerMap["DefaultContainer"]);
95 std::cerr << "WARNING: Unknown container and no DefaultContainer " << this->_container << " will be ignored" << std::endl;
103 void remotetypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
105 DEBTRACE( "remotetypeParser::onStart: " << el )
106 std::string element(el);
107 parser* pp=&parser::main_parser;
108 this->maxcount("kind",1,element);
109 this->maxcount("function",1,element);
110 this->maxcount("script",1,element);
111 this->maxcount("load",1,element);
112 this->maxchoice(t1,1,element);
114 if(element == "kind")pp=&stringtypeParser::stringParser;
115 else if(element == "load")pp=&loadtypeParser::loadParser;
116 else if(element == "function")pp=&functypeParser::funcParser;
117 else if(element == "script")pp=&codetypeParser::codeParser;
118 else if(element == "property")pp=&propertytypeParser::propertyParser;
119 else if(element == "inport")pp=&inporttypeParser<>::inportParser;
120 else if(element == "outport")pp=&outporttypeParser<>::outportParser;
122 this->SetUserDataAndPush(pp);
128 template <class T> remotetypeParser<T> remotetypeParser<T>::remoteParser; // instanciate static class attribute
130 } // end of namespace YACS