23 #include <netcomm/fawkes/client.h>
24 #include <blackboard/remote.h>
25 #include <utils/system/argparser.h>
26 #include <utils/system/signal.h>
27 #include <core/threading/thread.h>
28 #include <netcomm/fawkes/client_handler.h>
37 #include <readline/readline.h>
38 #include <readline/history.h>
40 #include <interfaces/SkillerInterface.h>
42 using namespace fawkes;
45 print_usage(
const char *program_name)
47 printf(
"Usage: %s [-h] [-r host[:port]]\n"
48 " -h This help message\n"
49 " -r host[:port] Remote host (and optionally port) to connect to\n",
77 just_connected =
true;
78 connection_died_recently =
false;
83 rl_event_hook = event_hook;
87 char *host = (
char *)
"localhost";
88 unsigned short int port = 1910;
93 if ( free_host ) free(host);
95 c->register_handler(
this, FAWKES_CID_SKILLER_PLUGIN);
102 printf(
"Finalizing\n");
105 sif->msgq_enqueue(rcm);
113 c->deregister_handler(FAWKES_CID_SKILLER_PLUGIN);
121 if ( c->connected() ) {
122 if ( just_connected ) {
123 just_connected =
false;
128 sif->msgq_enqueue(aqm);
136 if ( argp->num_items() > 0 ) {
137 std::string sks =
"";
138 const std::vector< const char * > & items = argp->items();
140 std::vector< const char * >::const_iterator i = items.begin();
143 for (; i != items.end(); ++i) {
149 sif->msgq_enqueue(esm);
156 line = readline(prompt);
158 if (strcmp(line,
"") != 0) {
160 if ( strcmp(line,
"cont") == 0 ) {
161 printf(
"Switching to continuous skill execution mode\n");
163 }
else if (strcmp(line,
"oneshot") == 0 ) {
164 printf(
"Switching to one-shot skill execution mode\n");
166 }
else if (strcmp(line,
"stop") == 0 ) {
167 printf(
"Stopping continuous skill execution\n");
169 sif->msgq_enqueue(sm);
171 printf(
"Executing: %s\n", line);
174 sif->msgq_enqueue(escm);
177 sif->msgq_enqueue(esm);
184 if ( ! connection_died_recently ) {
190 if ( connection_died_recently ) {
191 connection_died_recently =
false;
192 printf(
"Connection died\n");
206 virtual void deregistered(
unsigned int id)
throw()
212 unsigned int id)
throw()
217 virtual void connection_died(
unsigned int id)
throw()
226 connection_died_recently =
true;
234 virtual void connection_established(
unsigned int id)
throw()
236 printf(
"Connection established\n");
237 just_connected =
true;
249 bool connection_died_recently;
260 main(
int argc,
char **argv)
264 if ( argp.has_arg(
"h") ) {
265 print_usage(argv[0]);