1 Module name: Shard Script
3 Associated modules: None
4 Requires: Naming Service
13 ****************************************************************************************************
14 * The following block is a possible better implementation of the core of the script system
15 ****************************************************************************************************
19 //-------------------------------------------------------------------------------------------------
21 //-------------------------------------------------------------------------------------------------
23 class IScriptLine: public NLMISC::CRefCount
26 virtual ~IScriptLine() {}
27 virtual void execute()=0;
29 typedef NLMISC::CSmartPtr<IScriptLine> TScriptLinePtr;
32 //-------------------------------------------------------------------------------------------------
33 // class CScriptLineCmd
34 //-------------------------------------------------------------------------------------------------
36 class CScriptLineCmd: public IScriptLine
39 CScriptLineCmd(uint32 delay,const NLMISC::CSString& service,const NLMISC::CSString& cmdLine);
41 static CScriptLineCmd* buildNew(const NLMISC::CSString& txt);
42 virtual void execute();
45 NLMISC::CSString _Service;
46 NLMISC::CSString _CmdLine;
49 CScriptLineCmd::CScriptLineCmd(uint32 delay,const NLMISC::CSString& service,const NLMISC::CSString& cmdLine)
56 CScriptLineCmd* CScriptLineCmd::buildNew(const NLMISC::CSString& txt)
58 todo(" convert command line to components");
59 return new CScriptLineCmd(0,txt,txt);
62 void CScriptLineCmd::execute()
64 CCommandExecutor::getInstance()->addCommand(_Delay,_Service,_CmdLine);
68 //-------------------------------------------------------------------------------------------------
69 // class CScriptLineSetVar
70 //-------------------------------------------------------------------------------------------------
72 class CScriptLineSetVar: public IScriptLine
75 CScriptLineSetVar(const NLMISC::CSString& keyVarName,const NLMISC::CSString& keyValue,const NLMISC::CSString& targetVarName);
77 static CScriptLineSetVar* buildNew(const NLMISC::CSString& txt);
78 virtual void execute();
80 NLMISC::CSString _KeyVarName;
81 NLMISC::CSString _KeyValue;
82 NLMISC::CSString _TargetVarName;
85 CScriptLineSetVar::CScriptLineSetVar(const NLMISC::CSString& keyVarName,const NLMISC::CSString& keyValue,const NLMISC::CSString& targetVarName)
87 _KeyVarName= keyVarName;
89 _TargetVarName= targetVarName;
92 CScriptLineSetVar* CScriptLineSetVar::buildNew(const NLMISC::CSString& txt)
94 todo("split up the call into its components");
95 return new CScriptLineSetVar(txt,txt,txt);
98 void CScriptLineSetVar::execute()
104 //-------------------------------------------------------------------------------------------------
105 // class CScriptLineCall
106 //-------------------------------------------------------------------------------------------------
108 class CScriptLineCall: public IScriptLine
111 CScriptLineCall(const NLMISC::CSString& scriptName);
113 static CScriptLineCall* buildNew(const NLMISC::CSString& txt);
114 virtual void execute();
116 NLMISC::CSString _ScriptName;
119 CScriptLineCall::CScriptLineCall(const NLMISC::CSString& scriptName)
121 _ScriptName= scriptName;
124 CScriptLineCall* CScriptLineCall::buildNew(const NLMISC::CSString& txt)
126 if (txt.countWords()!=1)
128 nlwarning("the following is not a valid routine name: %s",txt.c_str());
131 return new CScriptLineCall(txt);
134 void CScriptLineCall::execute()
136 CScriptManager::getInstance()->runScript(_ScriptName);
140 //-------------------------------------------------------------------------------------------------
141 // IScriptLine factory: buildScriptLine()
142 //-------------------------------------------------------------------------------------------------
144 static TScriptLinePtr buildScriptLine(const NLMISC::CSString& txt)
146 NLMISC::CSString keyword= txt.firstWordConst().strip();
147 NLMISC::CSString rawArgs= txt.tailFromFirstWord().strip();
149 if (keyword=="cmd") return CScriptLineCmd::buildNew(rawArgs);
150 if (keyword=="setVar") return CScriptLineSetVar::buildNew(rawArgs);
151 if (keyword=="runScript") return CScriptLineCall::buildNew(rawArgs);