webservice/module.cpp
Go to the documentation of this file.
00001 /*************************************************************************** 00002 file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/tags/0.9.1/modules/webservice/module.cpp $ 00003 version : $LastChangedRevision: 1656 $ $LastChangedBy: jdetaeye $ 00004 date : $LastChangedDate: 2012-03-27 19:05:34 +0200 (Tue, 27 Mar 2012) $ 00005 ***************************************************************************/ 00006 00007 /*************************************************************************** 00008 * * 00009 * Copyright (C) 2007-2012 by Johan De Taeye, frePPLe bvba * 00010 * * 00011 * This library is free software; you can redistribute it and/or modify it * 00012 * under the terms of the GNU Lesser General Public License as published * 00013 * by the Free Software Foundation; either version 2.1 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00019 * General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * 00024 * USA * 00025 * * 00026 ***************************************************************************/ 00027 00028 #include "module.h" 00029 00030 00031 namespace module_webservice 00032 { 00033 00034 unsigned int CommandWebservice::port = 6262; 00035 unsigned int CommandWebservice::threads = 10; 00036 00037 00038 MODULE_EXPORT const char* initialize(const Environment::ParameterList& z) 00039 { 00040 // Initialize only once 00041 static bool init = false; 00042 static const char* name = "webservice"; 00043 if (init) 00044 { 00045 logger << "Warning: Initializing module webservice more than once." << endl; 00046 return name; 00047 } 00048 init = true; 00049 00050 try 00051 { 00052 // Process the module parameters 00053 for (Environment::ParameterList::const_iterator x = z.begin(); 00054 x != z.end(); ++x) 00055 { 00056 if (x->first == "port") 00057 CommandWebservice::setPort(x->second.getInt()); 00058 else if (x->first == "threads") 00059 CommandWebservice::setThreads(x->second.getInt()); 00060 else 00061 logger << "Warning: Unrecognized parameter '" << x->first << "'" << endl; 00062 } 00063 00064 // Initialize the Python extension. 00065 PyGILState_STATE state = PyGILState_Ensure(); 00066 try 00067 { 00068 // Register new Python data types 00069 PythonInterpreter::registerGlobalMethod( 00070 "webservice", CommandWebservice::pythonService, METH_NOARGS, 00071 "Starts the webservice to listen for HTTP requests"); 00072 PyGILState_Release(state); 00073 } 00074 catch (const exception &e) 00075 { 00076 PyGILState_Release(state); 00077 logger << "Error: " << e.what() << endl; 00078 } 00079 catch (...) 00080 { 00081 PyGILState_Release(state); 00082 logger << "Error: unknown exception" << endl; 00083 } 00084 00085 // Return the name of the module 00086 return name; 00087 } 00088 00089 00090 } // end namespace