main.cpp

00001 
00002 /***************************************************************************
00003  *  main.cpp - Fawkes plugin tool main
00004  *
00005  *  Created: Tue Nov 22 00:25:26 2006
00006  *  Copyright  2006  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include "plugin_tool.h"
00024 #include <netcomm/fawkes/client.h>
00025 
00026 #include <core/threading/thread.h>
00027 #include <utils/system/argparser.h>
00028 #include <utils/system/signal.h>
00029 
00030 #include <string>
00031 #include <cstdlib>
00032 #include <cstdio>
00033 
00034 using namespace fawkes;
00035 
00036 int
00037 main(int argc, char **argv)
00038 {
00039   ArgumentParser argp(argc, argv, "hl:u:R:waLr:");
00040 
00041   if ( argp.has_arg("h") ) {
00042     PluginTool::print_usage(argp.program_name());
00043     exit(0);
00044   }
00045 
00046   Thread::init_main();
00047 
00048   std::string host = "localhost";
00049   unsigned short int port = 1910;
00050   if ( argp.has_arg("r") ) {
00051     argp.parse_hostport("r", host, port);
00052   }
00053 
00054   FawkesNetworkClient *c = new FawkesNetworkClient(host.c_str(), port);
00055   try {
00056     c->connect();
00057   } catch( Exception &e ) {
00058     printf("Could not connect to host: %s\n", host.c_str());
00059     exit(1);
00060   }
00061 
00062   PluginTool *pt = new PluginTool(&argp, c);
00063   SignalManager::register_handler(SIGINT, pt);
00064   pt->run();
00065   SignalManager::finalize();
00066   delete pt;
00067 
00068   c->disconnect();
00069   delete c;
00070 
00071   Thread::destroy_main();
00072 
00073   return 0;
00074 }

Generated on Tue Feb 22 13:32:17 2011 for Fawkes API by  doxygen 1.4.7