Fawkes API  Fawkes Development Version
main.cpp
1 
2 /***************************************************************************
3  * main.cpp - Fawkes plugin tool main
4  *
5  * Created: Tue Nov 22 00:25:26 2006
6  * Copyright 2006 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "plugin_tool.h"
24 #include <netcomm/fawkes/client.h>
25 
26 #include <core/threading/thread.h>
27 #include <utils/system/argparser.h>
28 #include <utils/system/signal.h>
29 
30 #include <string>
31 #include <cstdlib>
32 #include <cstdio>
33 
34 using namespace fawkes;
35 
36 int
37 main(int argc, char **argv)
38 {
39  ArgumentParser argp(argc, argv, "hl:u:R:waLr:");
40 
41  if ( argp.has_arg("h") ) {
42  PluginTool::print_usage(argp.program_name());
43  exit(0);
44  }
45 
47 
48  std::string host = "localhost";
49  unsigned short int port = 1910;
50  if ( argp.has_arg("r") ) {
51  argp.parse_hostport("r", host, port);
52  }
53 
54  FawkesNetworkClient *c = new FawkesNetworkClient(host.c_str(), port);
55  try {
56  c->connect();
57  } catch( Exception &e ) {
58  printf("Could not connect to host: %s (%s)\n", host.c_str(), e.what_no_backtrace());
59  exit(1);
60  }
61 
62  PluginTool *pt = new PluginTool(&argp, c);
64  pt->run();
66  delete pt;
67 
68  c->disconnect();
69  delete c;
70 
72 
73  return 0;
74 }
static void finalize()
Finalize (and free) the SignalManager instance, this does NOT implicitly delete the signal handlers...
Definition: signal.cpp:98
Simple Fawkes network client.
Definition: client.h:52
Fawkes library namespace.
void disconnect()
Disconnect socket.
Definition: client.cpp:529
void connect()
Connect to remote.
Definition: client.cpp:417
Parse command line arguments.
Definition: argparser.h:66
static void init_main()
Initialize Thread wrapper instance for main thread.
Definition: thread.cpp:1271
static void print_usage(const char *program_name)
Print usage.
void run()
Run opmode as requested determined by the arguments.
Base class for exceptions in Fawkes.
Definition: exception.h:36
Program to communicate with plugin manager via Fawkes network.
Definition: plugin_tool.h:35
static void destroy_main()
Destroy main thread wrapper instance.
Definition: thread.cpp:1285
static SignalHandler * register_handler(int signum, SignalHandler *handler)
Register a SignalHandler for a signal.
Definition: signal.cpp:116
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
Definition: exception.cpp:686