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
25#include <core/threading/thread.h>
26#include <netcomm/fawkes/client.h>
27#include <utils/system/argparser.h>
28#include <utils/system/signal.h>
29
30#include <cstdio>
31#include <cstdlib>
32#include <string>
33
34using namespace fawkes;
35
36int
37main(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
46 Thread::init_main();
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);
63 SignalManager::register_handler(SIGINT, pt);
64 pt->run();
65 SignalManager::finalize();
66 delete pt;
67
68 c->disconnect();
69 delete c;
70
71 Thread::destroy_main();
72
73 return 0;
74}
Program to communicate with plugin manager via Fawkes network.
Definition: plugin_tool.h:36
void run()
Run opmode as requested determined by the arguments.
static void print_usage(const char *program_name)
Print usage.
Definition: plugin_tool.cpp:98
Parse command line arguments.
Definition: argparser.h:64
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual const char * what_no_backtrace() const noexcept
Get primary string (does not implicitly print the back trace).
Definition: exception.cpp:663
Simple Fawkes network client.
Definition: client.h:52
void connect()
Connect to remote.
Definition: client.cpp:424
void disconnect()
Disconnect socket.
Definition: client.cpp:539
Fawkes library namespace.