webservice/module.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   file : $URL: http://svn.code.sf.net/p/frepple/code/trunk/modules/webservice/module.cpp $
00003   version : $LastChangedRevision: 1713 $  $LastChangedBy: jdetaeye $
00004   date : $LastChangedDate: 2012-07-18 11:46:01 +0200 (Wed, 18 Jul 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 Affero General Public License as published   *
00013  * by the Free Software Foundation; either version 3 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            *
00019  * GNU Affero General Public License for more details.                     *
00020  *                                                                         *
00021  * You should have received a copy of the GNU Affero General Public        *
00022  * License along with this program.                                        *
00023  * If not, see <http://www.gnu.org/licenses/>.                             *
00024  *                                                                         *
00025  ***************************************************************************/
00026 
00027 #include "module.h"
00028 
00029 
00030 namespace module_webservice
00031 {
00032 
00033 unsigned int CommandWebservice::port = 6262;
00034 unsigned int CommandWebservice::threads = 10;
00035 
00036 
00037 MODULE_EXPORT const char* initialize(const Environment::ParameterList& z)
00038 {
00039   // Initialize only once
00040   static bool init = false;
00041   static const char* name = "webservice";
00042   if (init)
00043   {
00044     logger << "Warning: Initializing module webservice more than once." << endl;
00045     return name;
00046   }
00047   init = true;
00048 
00049   try
00050   {
00051     // Process the module parameters
00052     for (Environment::ParameterList::const_iterator x = z.begin();
00053         x != z.end(); ++x)
00054     {
00055       if (x->first == "port")
00056         CommandWebservice::setPort(x->second.getInt());
00057       else if (x->first == "threads")
00058         CommandWebservice::setThreads(x->second.getInt());
00059       else
00060         logger << "Warning: Unrecognized parameter '" << x->first << "'" << endl;
00061     }
00062 
00063     // Initialize the Python extension.
00064     PyGILState_STATE state = PyGILState_Ensure();
00065     try
00066     {
00067       // Register new Python data types
00068       PythonInterpreter::registerGlobalMethod(
00069         "webservice", CommandWebservice::pythonService, METH_NOARGS,
00070         "Starts the webservice to listen for HTTP requests");
00071       PyGILState_Release(state);
00072     }
00073     catch (const exception &e)
00074     {
00075       PyGILState_Release(state);
00076       logger << "Error: " << e.what() << endl;
00077     }
00078     catch (...)
00079     {
00080       PyGILState_Release(state);
00081       logger << "Error: unknown exception" << endl;
00082     }
00083 
00084     // Return the name of the module
00085     return name;
00086   }
00087 
00088 
00089 }       // end namespace

Documentation generated for frePPLe by  doxygen