61 #include "rnr/rnrconfig.h" 76 #define SH_C_COMMENT '#' 98 bool operator()(
const char*
const &lhs,
const char*
const &rhs)
const 100 return strcmp(lhs, rhs) < 0;
107 typedef map<const char *, ShCmdNode, ShCmdNodeKeyCmp>
ShCmdMap;
125 enum NodeType { NodeTypeNull, NodeTypeCmd, NodeTypeMap };
133 m_eType = NodeTypeNull;
144 m_eType = NodeTypeCmd;
155 m_eType = NodeTypeMap;
173 m_eType = NodeTypeCmd;
187 m_eType = NodeTypeMap;
198 return m_eType == NodeTypeCmd? m_obj.m_pCmd: NULL;
208 return m_eType == NodeTypeMap? m_obj.m_pMap: NULL;
218 return m_strMapBrief;
226 void SetMapBrief(
const string &strBrief)
228 m_strMapBrief = strBrief;
236 bool IsNull() {
return m_eType == NodeTypeNull; }
243 bool IsCmd() {
return m_eType == NodeTypeCmd; }
250 bool IsMap() {
return m_eType == NodeTypeMap; }
281 m_sScriptFile =
NEWSTR(sScriptFile);
291 if( m_fpScript != NULL )
305 return m_sScriptFile;
353 static const int m_nMaxScriptDepth = 5;
368 void PublishMap(
const char *sParent,
const string &strBrief);
369 void PublishCommand(
const char *sParent,
DynaShellCmd *pNewCmd);
370 void DeleteCommands(
ShCmdMap &cmdMap);
385 if( m_pRecording == NULL )
389 m_pRecording->
Init(nSamplePeriod, sDate);
399 if( m_pRecording != NULL )
403 m_pRecording = pNewRecording;
406 void ScriptPush(
const char *sScriptFile, FILE *fp);
409 void ScriptTrace(
const char *sLine);
418 return m_vecScripts.empty()?
false:
true;
433 void Response(
const char *sFmt, ...);
434 void Warning(
const char *sFmt, ...);
435 void Error(
int rc,
const char *sFmt, ...);
436 void Error(
int nServoId, uint_t uAlarms);
437 void Error(
const char *sFmt, ...);
451 char *CmdListGenerator(
int nUid,
455 const char *sContext);
457 char *CmdSpecGenerator(
int nUid,
461 const char *sContext);
464 typedef map<int,DynaShellCmd*> MapTabCompleteGen;
479 char *GetInputLine();
494 return (sLine!=NULL) && (*sLine!=0) && (*sLine!=SH_C_COMMENT)?
true:
false;
497 static char *CmdListGeneratorWrap(
int nUid,
501 const char *sContext,
504 static char *CmdSpecGeneratorWrap(
int nUid,
508 const char *sContext,
511 void AddToHistory(
char *sLine);
520 return !m_vecScripts.empty()? m_vecScripts.back()->GetFp(): stdin;
529 if( !m_vecScripts.empty() )
531 m_vecScripts.back()->BumpLineNum();
542 return feof(InputFp())?
true:
false;
547 #endif // _DYNASHELL_H ShCmdNode()
Default constructor.
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
ShCmdMap * GetMap()
Get map object.
FILE * GetFp()
Get file pointer.
#define NEWSTR(s)
Allocate a new duplicated string convenience macro.
void ScriptBumpLineNum()
Bump the line number of the current executing script, if any, by one.
Shell command node map key compare helper class.
FILE * InputFp()
Get the current input file pointer.
bool IsRunningScript()
Test if executing a script.
const char * m_sPS2
secondary user prompt
Dynamixel shell utilities.
int m_nLineNum
current line number
const char * GetScriptName() const
Get script file name.
DynaShellCmd * GetCmd()
Get command object.
DynaComm * m_pDynaComm
dynamixel bus communication
void RecordingReplace(DynaRecording *pNewRecording)
Replace recording.
ShCmdMap m_mapCmds
map of published commnds
MapTabCompleteGen m_mapTabGen
command tab-completion generators map
RoadNarrows Dynamixel Servo Chain Container Base Class Interface.
bool IsExecStmt(const char *sLine)
Test if line is a potential executable statement.
Dynamixel shell command abstract base class.
string m_strMapBrief
map brief description
bool IsNull()
Test if node type is null.
DynaRecording * m_pRecording
dynamixel recording
Dynamixel background thread class declarations.
vector< ShScript * > m_vecScripts
script stack
ShScript(const char *sScriptFile, FILE *fp)
Initialization constructor.
map< const char *, ShCmdNode, ShCmdNodeKeyCmp > ShCmdMap
Shell command map type.
bool m_bIsInteractive
[not] user interactive
ShCmdNode(DynaShellCmd *pCmd)
Shell command initialization constructor.
virtual void Ok()
Print standard ok success response.
DynaShellCmd * m_pCmd
pointer to allocated shell command
bool m_bXTrace
do [not] trace script
const char * m_sPS1
primary user prompt
void BumpLineNum()
Bump line number by one.
The Dynamixel Recording Class.
ReadLine m_ReadLine
readline object
bool operator()(const char *const &lhs, const char *const &rhs) const
Compare operator required by <map>.
ShCmdMap * m_pMap
pointer to allocated map of commands
bool IsMap()
Test if node type is map of commands.
Dynamixel Chain Container Base Class.
ShCmdNode & operator=(ShCmdMap *rhs)
Shell map assignment operator.
bool IsEOF()
Test if input is at End Of File condition.
FILE * m_fpScript
open file pointer
~ShScript()
Default destructor.
virtual void Init(int nSamplePeriod, const char *sDate=NULL)
(Re)Initialize recording.
DynaBgThread * m_pDynaBgThread
dynamixel chain
NodeType m_eType
node type
ReadLine class provides a c++ wrapper around the readline c library.
bool m_bSilent
do [not] silence non-error responses
The Dynamixel Shell ReadLine Class.
RoadNarrows Dynamixel Top-Level Package Header File.
ShCmdNode(ShCmdMap *pMap)
Map of commands initialization constructor.
#define DELSTR(s)
Delete an allocated string convenience macro.
const int GetLineNum() const
Get current line number.
~ShCmdNode()
Default destructor.
bool m_bRun
do [not] run shell
DynaChain * m_pDynaChain
dynamixel chain
Shell command node class.
int m_rc
last command executed return code
ShCmdNode & operator=(DynaShellCmd *rhs)
Shell command assignment operator.
char * m_sScriptFile
script file name
bool IsCmd()
Test if node type is shell command.
void RecordingInit(int nSamplePeriod, const char *sDate=NULL)
(Re)Initialize recording.
const char * m_sShellName
shell name
bool m_bNoExec
parse only, no execution
char * m_sInputLine
working, allocated line of input
Dynamixel Bus Communications Abstract Base Class.