1 // Copyright (C) 2006-2020 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");
64 if (this->_weight>0)fnode->setWeight(this->_weight);
68 void script (const myfunc& f)
70 DEBTRACE( "remote_script: " << f._code )
71 YACS::ENGINE::InlineNode *node;
72 node=theRuntime->createScriptNode(this->_kind,this->_name);
73 node->setScript(f._code);
74 node->setExecutionMode("remote");
75 if (this->_weight>0)node->setWeight(this->_weight);
81 DEBTRACE( "remote_post " << this->_node->getName() )
82 if(this->_state == "disabled")this->_node->exDisabledState();
85 if(currentProc->containerMap.count(this->_container) != 0)
87 // a container with name (this->_container) exists. Use it
88 this->_node->setContainer(currentProc->containerMap[this->_container]);
90 else if(this->_container == "" && currentProc->containerMap.count("DefaultContainer") != 0)
92 // a container with name (this->_container) does not exist
93 //a default container is defined : use it
94 this->_node->setContainer(currentProc->containerMap["DefaultContainer"]);
97 std::cerr << "WARNING: Unknown container and no DefaultContainer " << this->_container << " will be ignored" << std::endl;
105 void remotetypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
107 DEBTRACE( "remotetypeParser::onStart: " << el )
108 std::string element(el);
109 parser* pp=&parser::main_parser;
110 this->maxcount("kind",1,element);
111 this->maxcount("function",1,element);
112 this->maxcount("script",1,element);
113 this->maxcount("load",1,element);
114 this->maxchoice(t1,1,element);
116 if(element == "kind")pp=&stringtypeParser::stringParser;
117 else if(element == "load")pp=&loadtypeParser::loadParser;
118 else if(element == "function")pp=&functypeParser::funcParser;
119 else if(element == "script")pp=&codetypeParser::codeParser;
120 else if(element == "property")pp=&propertytypeParser::propertyParser;
121 else if(element == "inport")pp=&inporttypeParser<>::inportParser;
122 else if(element == "outport")pp=&outporttypeParser<>::outportParser;
124 this->SetUserDataAndPush(pp);
130 template <class T> remotetypeParser<T> remotetypeParser<T>::remoteParser; // instanciate static class attribute
132 } // end of namespace YACS