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");
212 unsigned int id)
throw()
226 connection_died_recently =
true;
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]);
Message handler for FawkesNetworkClient.
SkillShellThread(ArgumentParser *argp)
Constructor.
virtual void deregistered(unsigned int id)
This handler has been deregistered.
bool parse_hostport(const char *argn, char **host, unsigned short int *port)
Parse host:port string.
Simple Fawkes network client.
StopExecMessage Fawkes BlackBoard Interface Message.
Representation of a message that is sent over the network.
Parse command line arguments.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
Thread class encapsulation of pthreads.
AcquireControlMessage Fawkes BlackBoard Interface Message.
Base class for exceptions in Fawkes.
ExecSkillMessage Fawkes BlackBoard Interface Message.
virtual void connection_established(unsigned int id)
Client has established a connection.
void print_trace()
Prints trace to stderr.
virtual void loop()
Code to execute in the thread.
virtual void connection_died(unsigned int id)
Client connection died.
SkillerInterface Fawkes BlackBoard Interface.
The BlackBoard abstract class.
~SkillShellThread()
Destructor.
ExecSkillContinuousMessage Fawkes BlackBoard Interface Message.
virtual void inbound_received(FawkesNetworkMessage *m, unsigned int id)
Called for incoming messages.