xmlrpc_thread.cpp

00001 
00002 /***************************************************************************
00003  *  xmlrpc_thread.cpp - Thread that handles xml-rpc requests
00004  *
00005  *  Created: Sun Aug 30 12:49:26 2009
00006  *  Copyright  2006-2009  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 "xmlrpc_thread.h"
00024 #include "xmlrpc_processor.h"
00025 #include "methods/plugin.h"
00026 #include "methods/log.h"
00027 
00028 #include <core/version.h>
00029 #include <webview/server.h>
00030 #include <webview/request_dispatcher.h>
00031 
00032 using namespace fawkes;
00033 
00034 
00035 /** @class XmlRpcThread "xmlrpc_thread.h"
00036  * XML-RPC Thread.
00037  * This thread runs the HTTP server and handles XML-RPC calls.
00038  * @author Tim Niemueller
00039  */
00040 
00041 
00042 /** Constructor. */
00043 XmlRpcThread::XmlRpcThread()
00044   : Thread("XmlRpcThread", Thread::OPMODE_CONTINUOUS),
00045     LoggerAspect(&__cache_logger)
00046 {
00047   set_prepfin_conc_loop(true);
00048   
00049 }
00050 
00051 
00052 XmlRpcThread::~XmlRpcThread()
00053 {
00054 }
00055 
00056 void
00057 XmlRpcThread::init()
00058 {
00059   __cfg_port = config->get_uint("/xmlrpc/port");
00060 
00061   __cache_logger.clear();
00062 
00063   __dispatcher = new WebRequestDispatcher();
00064   __webserver  = new WebServer(__cfg_port, __dispatcher);
00065 
00066   __processor  = new XmlRpcRequestProcessor(logger);
00067 
00068   xmlrpc_c::registry *registry = __processor->registry();
00069   __plugin_methods = new XmlRpcPluginMethods(registry, plugin_manager, logger);
00070   __log_methods    = new XmlRpcLogMethods(registry, &__cache_logger, logger);
00071 
00072   __dispatcher->add_processor("/", __processor);
00073 
00074   logger->log_info("XmlRpcThread", "Listening for HTTP connections on port %u", __cfg_port);
00075 
00076 
00077   __xmlrpc_service = new NetworkService(nnresolver, "Fawkes XML-RPC on %h",
00078                                         "_http._tcp", __cfg_port);
00079   __xmlrpc_service->add_txt("fawkesver=%u.%u.%u", FAWKES_VERSION_MAJOR,
00080                             FAWKES_VERSION_MINOR, FAWKES_VERSION_MICRO);
00081   service_publisher->publish_service(__xmlrpc_service);
00082 
00083 
00084 }
00085 
00086 void
00087 XmlRpcThread::finalize()
00088 {
00089   service_publisher->unpublish_service(__xmlrpc_service);
00090   delete __xmlrpc_service;
00091 
00092   delete __webserver;
00093   delete __plugin_methods;
00094   delete __dispatcher;
00095   delete __processor;
00096 }
00097 
00098 
00099 void
00100 XmlRpcThread::loop()
00101 {
00102   __webserver->process();
00103 }

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