Version: 8.3.0
YACS::ENGINE::Runtime Class Referenceabstract

#include <Runtime.hxx>

Inheritance diagram for YACS::ENGINE::Runtime:
Collaboration diagram for YACS::ENGINE::Runtime:

Public Member Functions

virtual void init ()
 
virtual void fini ()
 
virtual CatalogloadCatalog (const std::string &sourceKind, const std::string &path)
 Load a catalog of calculation to use as factory. More...
 
virtual InlineFuncNodecreateFuncNode (const std::string &kind, const std::string &name)
 
virtual InlineNodecreateScriptNode (const std::string &kind, const std::string &name)
 
virtual ServiceNodecreateRefNode (const std::string &kind, const std::string &name)
 
virtual ServiceNodecreateCompoNode (const std::string &kind, const std::string &name)
 
virtual ServiceInlineNodecreateSInlineNode (const std::string &kind, const std::string &name)
 
virtual DataNodecreateInDataNode (const std::string &kind, const std::string &name)
 
virtual DataNodecreateOutDataNode (const std::string &kind, const std::string &name)
 
virtual ComponentInstancecreateComponentInstance (const std::string &name, const std::string &kind="")
 
virtual ContainercreateContainer (const std::string &kind="")
 
virtual ProccreateProc (const std::string &name)
 
virtual BloccreateBloc (const std::string &name)
 
virtual WhileLoopcreateWhileLoop (const std::string &name)
 
virtual ForLoopcreateForLoop (const std::string &name)
 
virtual ForEachLoopcreateForEachLoop (const std::string &name, TypeCode *type)
 
virtual OptimizerLoopcreateOptimizerLoop (const std::string &name, const std::string &algLib, const std::string &factoryName, bool algInitOnFile, const std::string &kind="", Proc *procForTypes=NULL)
 
virtual SwitchcreateSwitch (const std::string &name)
 
virtual TypeCodecreateInterfaceTc (const std::string &id, const std::string &name, std::list< TypeCodeObjref * > ltc)
 
virtual TypeCodecreateSequenceTc (const std::string &id, const std::string &name, TypeCode *content)
 
virtual TypeCodeStructcreateStructTc (const std::string &id, const std::string &name)
 
virtual InputPortcreateInputPort (const std::string &name, const std::string &impl, Node *node, TypeCode *type)=0
 
virtual OutputPortcreateOutputPort (const std::string &name, const std::string &impl, Node *node, TypeCode *type)=0
 
virtual InputDataStreamPortcreateInputDataStreamPort (const std::string &name, Node *node, TypeCode *type)
 
virtual OutputDataStreamPortcreateOutputDataStreamPort (const std::string &name, Node *node, TypeCode *type)
 
virtual InputPortadapt (InputPort *source, const std::string &impl, TypeCode *type, bool init=false)=0 throw (ConversionException)
 
virtual InputPortadapt (InPropertyPort *source, const std::string &impl, TypeCode *type, bool init=false)=0 throw (ConversionException)
 
virtual void * convertNeutral (TypeCode *type, Any *data)
 Convert a YACS::ENGINE::Any object to an external object with type type. More...
 
virtual std::string convertNeutralAsString (TypeCode *type, Any *data)
 Convert a YACS::ENGINE::Any object to a string to be used in GUI for example. More...
 
virtual void removeRuntime ()
 
virtual ~Runtime ()
 
virtual void setCatalogLoaderFactory (const std::string &name, CatalogLoader *factory)
 Add a catalog loader factory to the map _catalogLoaderFactoryMap under the name name. More...
 
CataloggetBuiltinCatalog ()
 Get the catalog of base nodes (elementary and composed) More...
 
virtual void addCatalog (Catalog *catalog)
 Add a catalog of types and nodes to the runtime. More...
 
virtual TypeCodegetTypeCode (const std::string &name)
 Get a typecode by its name from runtime catalogs. More...
 

Public Attributes

std::map< std::string,
CatalogLoader * > 
_catalogLoaderFactoryMap
 

Static Public Attributes

static const char RUNTIME_ENGINE_INTERACTION_IMPL_NAME [] ="Neutral"
 
static YACS::ENGINE::TypeCode_tc_double = 0
 
static YACS::ENGINE::TypeCode_tc_int = 0
 
static YACS::ENGINE::TypeCode_tc_bool = 0
 
static YACS::ENGINE::TypeCode_tc_string = 0
 
static YACS::ENGINE::TypeCode_tc_file = 0
 
static YACS::ENGINE::TypeCode_tc_stringpair = 0
 
static YACS::ENGINE::TypeCode_tc_propvec = 0
 

Protected Member Functions

 Runtime ()
 

Protected Attributes

std::set< std::string > _setOfImplementation
 
Catalog_builtinCatalog
 
std::vector< Catalog * > _catalogs
 

Static Protected Attributes

static Runtime_singleton = 0
 

Friends

RuntimegetRuntime () throw (Exception)
 

Detailed Description

Definition at line 67 of file Runtime.hxx.

Constructor & Destructor Documentation

Runtime::~Runtime ( )
virtual

Definition at line 143 of file Runtime.cxx.

References _singleton, _tc_bool, _tc_double, _tc_file, _tc_int, _tc_string, YACS::ENGINE::RefCounter::_totalCnt, DEBTRACE, and YACS::ENGINE::RefCounter::decrRef().

144 {
145  delete _builtinCatalog;
146  DEBTRACE( "_tc_double refcnt: " << Runtime::_tc_double->getRefCnt() );
147  DEBTRACE( "_tc_int refcnt: " << Runtime::_tc_int->getRefCnt() );
148  DEBTRACE( "_tc_bool refcnt: " << Runtime::_tc_bool->getRefCnt() );
149  DEBTRACE( "_tc_string refcnt: " << Runtime::_tc_string->getRefCnt() );
150  DEBTRACE( "_tc_file refcnt: " << Runtime::_tc_file->getRefCnt() );
156  for(std::vector<Catalog *>::iterator it=_catalogs.begin();it !=_catalogs.end();it++)
157  (*it)->decrRef();
159  DEBTRACE( "Total YACS::ENGINE::Refcount: " << RefCounter::_totalCnt );
160 }
Runtime::Runtime ( )
protected

Definition at line 68 of file Runtime.cxx.

References YACS::ENGINE::Executor::_maxThreads, _tc_bool, _tc_double, _tc_file, _tc_int, _tc_propvec, _tc_string, _tc_stringpair, YACS::ENGINE::Executor::_threadStackSize, YACS::ENGINE::TypeCodeStruct::addMember(), YACS::ENGINE::Bool, DEBTRACE, YACS::ENGINE::Double, YACS::ENGINE::RefCounter::incrRef(), YACS::ENGINE::Int, YACS::ENGINE::String, and YACS::traceLevel.

69 {
70  DEBTRACE("Runtime::Runtime");
75  Runtime::_tc_file = new TypeCodeObjref("file", "file");
76  TypeCodeStruct * stringpair = new TypeCodeStruct("stringpair", "stringpair");
77  stringpair->addMember("name", Runtime::_tc_string);
78  stringpair->addMember("value", Runtime::_tc_string);
79  Runtime::_tc_stringpair = stringpair;
80  Runtime::_tc_propvec = new TypeCodeSeq("propvec", "propvec", Runtime::_tc_stringpair);
81  DEBTRACE( "_tc_double refcnt: " << Runtime::_tc_double->getRefCnt() );
82  DEBTRACE( "_tc_int refcnt: " << Runtime::_tc_int->getRefCnt() );
83  DEBTRACE( "_tc_bool refcnt: " << Runtime::_tc_bool->getRefCnt() );
84  DEBTRACE( "_tc_string refcnt: " << Runtime::_tc_string->getRefCnt() );
85  DEBTRACE( "_tc_file refcnt: " << Runtime::_tc_file->getRefCnt() );
86  DEBTRACE( "_tc_stringpair refcnt: " << Runtime::_tc_stringpair->getRefCnt() );
87  DEBTRACE( "_tc_propvec refcnt: " << Runtime::_tc_propvec->getRefCnt() );
88  _builtinCatalog = new Catalog("builtins");
89  std::map<std::string,TypeCode*>& typeMap=_builtinCatalog->_typeMap;
90  /* All composed node creations are moved to RuntimeSALOME::initBuiltins.
91  It is not safe to have all those calls to virtual functions (create*)
92  in the constructor. */
94  typeMap["double"]=Runtime::_tc_double;
96  typeMap["int"]=Runtime::_tc_int;
98  typeMap["bool"]=Runtime::_tc_bool;
100  typeMap["string"]=Runtime::_tc_string;
102  typeMap["file"]=Runtime::_tc_file;
104  typeMap["stringpair"]=Runtime::_tc_stringpair;
106  typeMap["propvec"]=Runtime::_tc_propvec;
107 
108  // Get dynamic trace level
110  char* valenv=getenv("YACS_TRACELEVEL");
111  if(valenv)
112  {
113  std::istringstream iss(valenv);
114  int temp;
115  if (iss >> temp)
116  YACS::traceLevel=temp;
117  }
118 
119  // Get max threads number
120  char *maxThreadStr = getenv("YACS_MAX_THREADS");
121  if (maxThreadStr != NULL)
122  {
123  int maxThreads = atoi(maxThreadStr);
124  DEBTRACE("maxThreads = " << maxThreads);
125  if (maxThreads > 0) Executor::_maxThreads = maxThreads;
126  }
127 
128  // Get thread stack size
129  char *threadStackSizeStr = getenv("YACS_THREADS_STACK_SIZE");
130  if (threadStackSizeStr != NULL)
131  {
132  size_t threadStackSize = strtoul(threadStackSizeStr, NULL, 0);
133  DEBTRACE("threadStackSize = " << threadStackSize);
134  if (threadStackSize > 0) Executor::_threadStackSize = threadStackSize;
135  }
136 }

Member Function Documentation

virtual InputPort* YACS::ENGINE::Runtime::adapt ( InputPort source,
const std::string &  impl,
TypeCode type,
bool  init = false 
) throw (ConversionException)
pure virtual
virtual InputPort* YACS::ENGINE::Runtime::adapt ( InPropertyPort source,
const std::string &  impl,
TypeCode type,
bool  init = false 
) throw (ConversionException)
pure virtual

Implemented in YACS::ENGINE::RuntimeSALOME.

void Runtime::addCatalog ( Catalog catalog)
virtual

Add a catalog of types and nodes to the runtime.

These catalogs are searched when calling getTypeCode method

Definition at line 318 of file Runtime.cxx.

References YACS::ENGINE::RefCounter::incrRef().

Referenced by YACS::HMI::GenericGui::GenericGui(), and main().

319 {
320  _catalogs.push_back(catalog);
321  catalog->incrRef();
322 }
void * Runtime::convertNeutral ( TypeCode type,
Any data 
)
virtual

Convert a YACS::ENGINE::Any object to an external object with type type.

This method is used to convert Neutral objects to script languages. For example Python language. The runtime has one external script language. The object is returned as a void * because engine knows nothing about external script language.

Parameters
type,:the type of the converted object if the conversion is possible
data,:the object to convert
Returns
the converted object

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 350 of file Runtime.cxx.

351 {
352  throw Exception("convertNeutral is not implemented by your runtime");
353 }
std::string Runtime::convertNeutralAsString ( TypeCode type,
Any data 
)
virtual

Convert a YACS::ENGINE::Any object to a string to be used in GUI for example.

engine package does not provide a conversion to string. It has to be implemented in the runtime package.

Parameters
type,:the type of the object to convert
data,:the object to convert
Returns
the string representation of the object

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 364 of file Runtime.cxx.

Referenced by YACS::ENGINE::AnyOutputPort::getAsString(), and YACS::ENGINE::AnyInputPort::getAsString().

365 {
366  throw Exception("convertNeutralAsString is not implemented by your runtime");
367 }
Bloc * Runtime::createBloc ( const std::string &  name)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 231 of file Runtime.cxx.

Referenced by YACS::bloctypeParser< T >::name().

232 {
233  return new Bloc(name);
234 }
ComponentInstance * Runtime::createComponentInstance ( const std::string &  name,
const std::string &  kind = "" 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 215 of file Runtime.cxx.

Referenced by YACS::ENGINE::Proc::createComponentInstance(), YACS::inlinetypeParser< T >::function(), and YACS::ENGINE::ServiceNode::setRef().

217 {
218  throw Exception("ComponentInstance factory not implemented");
219 }
ServiceNode * Runtime::createCompoNode ( const std::string &  kind,
const std::string &  name 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 205 of file Runtime.cxx.

Referenced by YACS::servicetypeParser< T >::component(), YACS::servicetypeParser< T >::componentinstance(), and YACS::ENGINE::SessionCataLoader::importComponent().

206 {
207  throw Exception("CompoNode factory not implemented");
208 }
Container * Runtime::createContainer ( const std::string &  kind = "")
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 221 of file Runtime.cxx.

Referenced by YACS::ENGINE::CppComponent::CppComponent(), and YACS::ENGINE::CppComponent::load().

222 {
223  throw Exception("Container factory not implemented");
224 }
ForEachLoop * Runtime::createForEachLoop ( const std::string &  name,
TypeCode type 
)
virtual
ForLoop * Runtime::createForLoop ( const std::string &  name)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 246 of file Runtime.cxx.

Referenced by YACS::forlooptypeParser< T >::name().

247 {
248  return new ForLoop(name);
249 }
InlineFuncNode * Runtime::createFuncNode ( const std::string &  kind,
const std::string &  name 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 190 of file Runtime.cxx.

Referenced by YACS::remotetypeParser< T >::function(), YACS::inlinetypeParser< T >::function(), and YACS::servertypeParser< T >::loadcontainer().

191 {
192  throw Exception("FuncNode factory not implemented");
193 }
DataNode * Runtime::createInDataNode ( const std::string &  kind,
const std::string &  name 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 180 of file Runtime.cxx.

Referenced by YACS::presettypeParser< T >::create().

181 {
182  throw Exception("InDataNode factory not implemented");
183 }
InputDataStreamPort * Runtime::createInputDataStreamPort ( const std::string &  name,
Node node,
TypeCode type 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 264 of file Runtime.cxx.

Referenced by YACS::ENGINE::ElementaryNode::createInputDataStreamPort().

265 {
266  return new InputDataStreamPort(name,node,type);
267 }
virtual InputPort* YACS::ENGINE::Runtime::createInputPort ( const std::string &  name,
const std::string &  impl,
Node node,
TypeCode type 
)
pure virtual
TypeCode * Runtime::createInterfaceTc ( const std::string &  id,
const std::string &  name,
std::list< TypeCodeObjref * >  ltc 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 162 of file Runtime.cxx.

References YACS::ENGINE::TypeCode::interfaceTc().

Referenced by YACS::ENGINE::SessionCataLoader::loadTypes().

164 {
165  return TypeCode::interfaceTc(id.c_str(),name.c_str(),ltc);
166 }
OptimizerLoop * Runtime::createOptimizerLoop ( const std::string &  name,
const std::string &  algLib,
const std::string &  factoryName,
bool  algInitOnFile,
const std::string &  kind = "",
Proc procForTypes = NULL 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 258 of file Runtime.cxx.

Referenced by YACS::optimizerlooptypeParser< T >::postAttr().

260 {
261  return new OptimizerLoop(name,algLib,factoryName,algInitOnFile, true, procForTypes);
262 }
DataNode * Runtime::createOutDataNode ( const std::string &  kind,
const std::string &  name 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 185 of file Runtime.cxx.

Referenced by YACS::outnodetypeParser< T >::create().

186 {
187  throw Exception("OutDataNode factory not implemented");
188 }
OutputDataStreamPort * Runtime::createOutputDataStreamPort ( const std::string &  name,
Node node,
TypeCode type 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 269 of file Runtime.cxx.

Referenced by YACS::ENGINE::ElementaryNode::createOutputDataStreamPort().

270 {
271  return new OutputDataStreamPort(name,node,type);
272 }
virtual OutputPort* YACS::ENGINE::Runtime::createOutputPort ( const std::string &  name,
const std::string &  impl,
Node node,
TypeCode type 
)
pure virtual
Proc * Runtime::createProc ( const std::string &  name)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 226 of file Runtime.cxx.

Referenced by YACS::proctypeParser< T >::pre().

227 {
228  return new Proc(name);
229 }
ServiceNode * Runtime::createRefNode ( const std::string &  kind,
const std::string &  name 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 200 of file Runtime.cxx.

Referenced by YACS::servicetypeParser< T >::ref().

201 {
202  throw Exception("RefNode factory not implemented");
203 }
InlineNode * Runtime::createScriptNode ( const std::string &  kind,
const std::string &  name 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 195 of file Runtime.cxx.

Referenced by YACS::remotetypeParser< T >::script(), and YACS::inlinetypeParser< T >::script().

196 {
197  throw Exception("ScriptNode factory not implemented");
198 }
TypeCode * Runtime::createSequenceTc ( const std::string &  id,
const std::string &  name,
TypeCode content 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 168 of file Runtime.cxx.

References YACS::ENGINE::TypeCode::sequenceTc().

Referenced by YACS::ENGINE::SessionCataLoader::loadTypes().

171 {
172  return TypeCode::sequenceTc(id.c_str(),name.c_str(),content);
173 };
ServiceInlineNode * Runtime::createSInlineNode ( const std::string &  kind,
const std::string &  name 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 210 of file Runtime.cxx.

Referenced by YACS::inlinetypeParser< T >::function().

211 {
212  throw Exception("SInlineNode factory not implemented");
213 }
TypeCodeStruct * Runtime::createStructTc ( const std::string &  id,
const std::string &  name 
)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 175 of file Runtime.cxx.

References YACS::ENGINE::TypeCode::structTc().

Referenced by YACS::ENGINE::SessionCataLoader::loadTypes().

176 {
177  return (TypeCodeStruct *)TypeCode::structTc(id.c_str(),name.c_str());
178 }
Switch * Runtime::createSwitch ( const std::string &  name)
virtual

Definition at line 236 of file Runtime.cxx.

Referenced by YACS::switchtypeParser::name().

237 {
238  return new Switch(name);
239 }
WhileLoop * Runtime::createWhileLoop ( const std::string &  name)
virtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 241 of file Runtime.cxx.

Referenced by YACS::whilelooptypeParser< T >::name().

242 {
243  return new WhileLoop(name);
244 }
virtual void YACS::ENGINE::Runtime::fini ( )
inlinevirtual

Reimplemented in YACS::ENGINE::RuntimeSALOME.

Definition at line 72 of file Runtime.hxx.

Referenced by main().

72 { }
Catalog * Runtime::getBuiltinCatalog ( )
TypeCode * Runtime::getTypeCode ( const std::string &  name)
virtual

Get a typecode by its name from runtime catalogs.

Returns
the typecode if it exists or NULL

Definition at line 328 of file Runtime.cxx.

Referenced by YACS::objtypeParser::base(), YACS::seqtypeParser::content(), YACS::ENGINE::Proc::getTypeCode(), YACS::inlinetypeParser< T >::inport(), YACS::servertypeParser< T >::instream(), YACS::servicetypeParser< T >::instream(), YACS::structtypeParser::member(), YACS::inlinetypeParser< T >::outport(), YACS::servertypeParser< T >::outstream(), YACS::servicetypeParser< T >::outstream(), YACS::outnodetypeParser< T >::parameter(), YACS::presettypeParser< T >::parameter(), and YACS::foreachlooptypeParser< T >::postAttr().

329 {
330  if (_builtinCatalog->_typeMap.count(name) != 0)
331  return _builtinCatalog->_typeMap[name];
332  for(std::vector<Catalog *>::const_iterator it=_catalogs.begin();it !=_catalogs.end();it++)
333  {
334  if ((*it)->_typeMap.count(name) != 0)
335  return (*it)->_typeMap[name];
336  }
337  return 0;
338 }
virtual void YACS::ENGINE::Runtime::init ( )
inlinevirtual

Definition at line 71 of file Runtime.hxx.

71 { }
Catalog * Runtime::loadCatalog ( const std::string &  sourceKind,
const std::string &  path 
)
virtual

Load a catalog of calculation to use as factory.

Parameters
sourceKind,:the kind of catalog source. It depends on runtime. It could be a file, a server, a directory
path,:the path to the catalog.
Returns
the loaded Catalog

Definition at line 280 of file Runtime.cxx.

References YACS::ENGINE::CatalogLoader::load().

Referenced by YACS::HMI::CatalogWidget::addCatalogFromFile(), YACS::HMI::GenericGui::GenericGui(), and main().

281 {
282  if (_catalogLoaderFactoryMap.find(sourceKind) == _catalogLoaderFactoryMap.end())
283  {
284  throw Exception("This type of catalog loader does not exist: " + sourceKind);
285  }
286  else
287  {
288  Catalog* cata=new Catalog(path);
289  CatalogLoader* proto=_catalogLoaderFactoryMap[sourceKind];
290  proto->load(cata,path);
291  return cata;
292  }
293 }
void Runtime::removeRuntime ( )
virtual

Definition at line 138 of file Runtime.cxx.

139 {
140  delete this;
141 }
void Runtime::setCatalogLoaderFactory ( const std::string &  name,
CatalogLoader factory 
)
virtual

Add a catalog loader factory to the map _catalogLoaderFactoryMap under the name name.

Parameters
name,:name under which the factory is registered
factory,:the factory

Definition at line 300 of file Runtime.cxx.

Referenced by YACS::YACSLoader::registerProcCataLoader().

301 {
302  _catalogLoaderFactoryMap[name]=factory;
303 }

Friends And Related Function Documentation

Runtime* getRuntime ( ) throw (Exception)
friend

Member Data Documentation

Catalog* YACS::ENGINE::Runtime::_builtinCatalog
protected

Definition at line 151 of file Runtime.hxx.

std::map<std::string,CatalogLoader*> YACS::ENGINE::Runtime::_catalogLoaderFactoryMap

Definition at line 142 of file Runtime.hxx.

std::vector<Catalog*> YACS::ENGINE::Runtime::_catalogs
protected

Definition at line 152 of file Runtime.hxx.

std::set<std::string> YACS::ENGINE::Runtime::_setOfImplementation
protected

Definition at line 150 of file Runtime.hxx.

Runtime * Runtime::_singleton = 0
staticprotected
TypeCode * Runtime::_tc_file = 0
static
TypeCode * Runtime::_tc_propvec = 0
static

Definition at line 140 of file Runtime.hxx.

Referenced by YACS::ENGINE::Node::Node(), and Runtime().

TypeCode * Runtime::_tc_stringpair = 0
static

Definition at line 139 of file Runtime.hxx.

Referenced by Runtime().

const char Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME ="Neutral"
static

The documentation for this class was generated from the following files: