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> 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;
85 char *host = (
char *)
"localhost";
86 unsigned short int port = 1910;
91 if ( free_host ) free(host);
93 c->register_handler(
this, FAWKES_CID_SKILLER_PLUGIN);
100 printf(
"Finalizing\n");
103 sif->msgq_enqueue(rcm);
111 c->deregister_handler(FAWKES_CID_SKILLER_PLUGIN);
119 if ( c->connected() ) {
120 if ( just_connected ) {
121 just_connected =
false;
126 sif->msgq_enqueue(aqm);
134 if ( argp->num_items() > 0 ) {
135 std::string sks =
"";
136 const std::vector< const char * > & items = argp->items();
138 std::vector< const char * >::const_iterator i = items.begin();
141 for (; i != items.end(); ++i) {
147 sif->msgq_enqueue(esm);
154 line = readline(prompt);
156 if (strcmp(line,
"") != 0) {
158 if (strcmp(line,
"stop") == 0 ) {
159 printf(
"Stopping skill execution\n");
161 sif->msgq_enqueue(sm);
163 printf(
"Executing: %s\n", line);
165 sif->msgq_enqueue(esm);
171 if ( ! connection_died_recently ) {
177 if ( connection_died_recently ) {
178 connection_died_recently =
false;
179 printf(
"Connection died\n");
199 unsigned int id)
throw()
213 connection_died_recently =
true;
223 printf(
"Connection established\n");
224 just_connected =
true;
236 bool connection_died_recently;
245 main(
int argc,
char **argv)
250 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.
Fawkes library namespace.
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.
void join()
Join the thread.
SkillerInterface Fawkes BlackBoard Interface.
bool has_arg(const char *argn)
Check if argument has been supplied.
The BlackBoard abstract class.
~SkillShellThread()
Destructor.
virtual void inbound_received(FawkesNetworkMessage *m, unsigned int id)
Called for incoming messages.
void start(bool wait=true)
Call this method to start the thread.