Critical Link MityCam SoC Firmware  1.0
Critical Link MityCam SoC Firmware
tcCommandExecutiveBase.h
Go to the documentation of this file.
1 
2 #ifndef tcCommandExecutiveBase_H_
3 #define tcCommandExecutiveBase_H_
4 
5 #include <stdint.h>
6 #include <string>
7 #include <vector>
8 #include <list>
9 #include "Thread.h"
10 
11 class tcUIThread;
12 
13 
18 #define MENU_FUNCTION_DECL(name) \
19  static void name (void* me) { ((tcCommandExecutiveBase*)me)-> name (); } \
20  void name ();
21 
22 
37 {
38 friend class tcUIThread;
39 
40 protected:
43  typedef void (*tpVoidFunc)(void*);
44 
45 public:
46  tcCommandExecutiveBase (const char *appname);
47 
50  void start();
51 
52 protected:
53  void add_cmnd (const char *cmnd, tpVoidFunc func, const char *desc);
54  void add_seperator ();
55 
56  MENU_FUNCTION_DECL (process_help);
57  // the camera app doesn't have a clean shutdown...
58  // MENU_FUNCTION_DECL (process_quit);
59 
60 protected:
61  void conditionalRead (unsigned int anTabs, const char* apMessage);
62 
63  bool ask_on_off (const char *prompt, bool allowempty = false, bool dflt = false);
64  bool ask_yes_no (const char *prompt, bool allowempty = false, bool dflt = false);
65  double ask_double (const char *prompt, bool allowempty = false, double dflt = 0);
66  float ask_float (const char *prompt, bool allowempty = false, float dflt = 0);
67  uint32_t ask_uint (const char *prompt, bool allowempty = false, uint32_t dflt = 0);
68  int32_t ask_int (const char *prompt, bool allowempty = false, int32_t dflt = 0);
69  std::string ask_string (const char *prompt, bool allowempty = false, const char *dflt = "");
70 
71  void ReadUserInput ();
72  void UserInputLoop ();
73 
74  typedef struct
75  {
76  std::string m_cmnd;
78  std::string m_help;
79  } tsCmndFunc;
80  std::vector<tsCmndFunc> m_cmnd_func_list;
81  tpVoidFunc get_func (const char *cmnd);
82  tsCmndFunc *get_cmndfunc (const char *cmnd);
83 
85  bool m_continue;
86  std::list<std::string> m_cmnd_list;
87  std::string m_appname;
88 
89 
90  void printHelp (const char *cmnd);
91  void printHelpGeneric (const tsCmndFunc *tcf) const;
92  void printHelpAll () const;
93 };
94 
95 #undef MENU_FUNCTION_DECL // We don't need this anymore
96 
97 
101 class tcUIThread : public tcThread
102 {
103 public:
106 protected:
108 };
109 
110 
111 #endif // tcCommandExecutiveBase_H_
112 
tcCommandExecutiveBase::m_ConsoleListenerThread
tcUIThread * m_ConsoleListenerThread
Thread handle for User Input.
Definition: tcCommandExecutiveBase.h:84
tcCommandExecutiveBase::ask_int
int32_t ask_int(const char *prompt, bool allowempty=false, int32_t dflt=0)
Definition: tcCommandExecutiveBase.cpp:182
tcUIThread::tcUIThread
tcUIThread(tcCommandExecutiveBase *exec)
Definition: tcCommandExecutiveBase.h:104
tcCommandExecutiveBase::m_appname
std::string m_appname
Definition: tcCommandExecutiveBase.h:87
tcCommandExecutiveBase::conditionalRead
void conditionalRead(unsigned int anTabs, const char *apMessage)
Definition: tcCommandExecutiveBase.cpp:281
tcCommandExecutiveBase::tsCmndFunc::m_cmnd
std::string m_cmnd
Definition: tcCommandExecutiveBase.h:76
tcCommandExecutiveBase::printHelpAll
void printHelpAll() const
Definition: tcCommandExecutiveBase.cpp:368
tcCommandExecutiveBase::get_cmndfunc
tsCmndFunc * get_cmndfunc(const char *cmnd)
Definition: tcCommandExecutiveBase.cpp:58
tcUIThread
This class forms the user input thread for the menu.
Definition: tcCommandExecutiveBase.h:101
tcCommandExecutiveBase::ask_yes_no
bool ask_yes_no(const char *prompt, bool allowempty=false, bool dflt=false)
Generic "yes/no" asker.
Definition: tcCommandExecutiveBase.cpp:238
tcCommandExecutiveBase::start
void start()
Definition: tcCommandExecutiveBase.cpp:88
tcThread::NORMAL_PRIORITY
static const int NORMAL_PRIORITY
Definition: Thread.h:12
tcCommandExecutiveBase
Definition: tcCommandExecutiveBase.h:36
tcCommandExecutiveBase::tsCmndFunc::m_func
tpVoidFunc m_func
Definition: tcCommandExecutiveBase.h:77
tcCommandExecutiveBase::ask_float
float ask_float(const char *prompt, bool allowempty=false, float dflt=0)
Definition: tcCommandExecutiveBase.cpp:147
tcThread
Definition: Thread.h:6
tcCommandExecutiveBase::tsCmndFunc
Definition: tcCommandExecutiveBase.h:74
tcCommandExecutiveBase::m_continue
bool m_continue
Tells the UI thread when QUIT command has been given.
Definition: tcCommandExecutiveBase.h:85
Thread.h
tcCommandExecutiveBase::ask_string
std::string ask_string(const char *prompt, bool allowempty=false, const char *dflt="")
Definition: tcCommandExecutiveBase.cpp:199
tcCommandExecutiveBase::ask_on_off
bool ask_on_off(const char *prompt, bool allowempty=false, bool dflt=false)
Generic "on/off" asker.
Definition: tcCommandExecutiveBase.cpp:216
tcCommandExecutiveBase::tpVoidFunc
void(* tpVoidFunc)(void *)
Definition: tcCommandExecutiveBase.h:43
tcCommandExecutiveBase::UserInputLoop
void UserInputLoop()
Definition: tcCommandExecutiveBase.cpp:296
tcCommandExecutiveBase::add_seperator
void add_seperator()
Definition: tcCommandExecutiveBase.cpp:52
tcThread::setPriority
void setPriority(int anRelativePriority)
Definition: Thread.cpp:35
tcUIThread::m_exec
tcCommandExecutiveBase * m_exec
Definition: tcCommandExecutiveBase.h:107
tcCommandExecutiveBase::m_cmnd_list
std::list< std::string > m_cmnd_list
Definition: tcCommandExecutiveBase.h:86
tcCommandExecutiveBase::ask_double
double ask_double(const char *prompt, bool allowempty=false, double dflt=0)
Definition: tcCommandExecutiveBase.cpp:130
tcCommandExecutiveBase::tcCommandExecutiveBase
tcCommandExecutiveBase(const char *appname)
Constructor, Create an input thread and then populate the menu and the help menu.
Definition: tcCommandExecutiveBase.cpp:13
tcCommandExecutiveBase::printHelp
void printHelp(const char *cmnd)
Prints either a single command, all commands, or an error, depending on the help string.
Definition: tcCommandExecutiveBase.cpp:335
tcCommandExecutiveBase::m_cmnd_func_list
std::vector< tsCmndFunc > m_cmnd_func_list
Definition: tcCommandExecutiveBase.h:80
tcCommandExecutiveBase::get_func
tpVoidFunc get_func(const char *cmnd)
Definition: tcCommandExecutiveBase.cpp:74
tcCommandExecutiveBase::ask_uint
uint32_t ask_uint(const char *prompt, bool allowempty=false, uint32_t dflt=0)
Definition: tcCommandExecutiveBase.cpp:164
tcCommandExecutiveBase::ReadUserInput
void ReadUserInput()
Definition: tcCommandExecutiveBase.cpp:260
tcUIThread::run
void * run()
Definition: tcCommandExecutiveBase.h:105
tcCommandExecutiveBase::printHelpGeneric
void printHelpGeneric(const tsCmndFunc *tcf) const
Prints generic formatted help for the specfied command and info.
Definition: tcCommandExecutiveBase.cpp:358
tcCommandExecutiveBase::add_cmnd
void add_cmnd(const char *cmnd, tpVoidFunc func, const char *desc)
Definition: tcCommandExecutiveBase.cpp:37
tcCommandExecutiveBase::MENU_FUNCTION_DECL
MENU_FUNCTION_DECL(process_help)
tcCommandExecutiveBase::tsCmndFunc::m_help
std::string m_help
Definition: tcCommandExecutiveBase.h:78