module.h
Go to the documentation of this file.
00001 /***************************************************************************
00002   file : $URL: http://svn.code.sf.net/p/frepple/code/trunk/modules/webservice/module.h $
00003   version : $LastChangedRevision: 1715 $  $LastChangedBy: jdetaeye $
00004   date : $LastChangedDate: 2012-07-19 21:37:46 +0200 (Thu, 19 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 /** @file module.h
00028   * @brief Header file for the module webservice.
00029   *
00030   * @namespace module_webservice
00031   * @brief A SOAP webservice to publish frePPLe data as a service.
00032   *
00033   * The gSOAP toolkit is used to create a SOAP service for frePPLe.
00034   *
00035   * A new Python extension is added to run a multi-threaded SOAP webservice
00036   * server.
00037   */
00038 
00039 #include "frepple.h"
00040 #include "freppleinterface.h"
00041 using namespace frepple;
00042 
00043 #include "soapH.h"
00044 
00045 
00046 // Settings specific to gsoap
00047 #define BACKLOG (100) // Max. number of backlog requests
00048 #define MAX_QUEUE (1000) // Max. size of request queue
00049 
00050 
00051 namespace module_webservice
00052 {
00053 
00054 
00055 /** Initialization routine for the library. */
00056 MODULE_EXPORT const char* initialize(const Environment::ParameterList& z);
00057 
00058 
00059 /** @brief This command runs a multi-threaded SOAP webservice server.
00060   *
00061   */
00062 class CommandWebservice : public Command
00063 {
00064   private:
00065     /** Port number for the server. */
00066     static unsigned int port;
00067 
00068     /** Number of threads to handle requests. */
00069     static unsigned int threads;
00070 
00071     /** Worker function for the threads. */
00072     static void *process_queue(void*);
00073 
00074     /** Put a new connection in the queue. */
00075     int enqueue(SOAP_SOCKET);
00076 
00077     /** Pick a connection from the queue. */
00078     SOAP_SOCKET dequeue();
00079 
00080     struct thread_data
00081     {
00082       public:
00083         CommandWebservice* master;
00084         struct soap *soap_thr; // each thread needs a soap runtime environment
00085         pthread_t tid;
00086         unsigned int index;
00087     };
00088 
00089 
00090     SOAP_SOCKET queue[MAX_QUEUE]; // The global request queue of sockets
00091     int head;
00092     int tail; // Queue head and tail
00093     pthread_mutex_t queue_cs;
00094     pthread_cond_t queue_cv;
00095 
00096   public:
00097     /** Python interface for the webservice server. */
00098     static PyObject* pythonService(PyObject*, PyObject*);
00099 
00100     /** Runs the webservice server. */
00101     void commit();
00102 
00103     /** Returns a descriptive string. */
00104     string getDescription() const {return "frePPLe webservice";}
00105 
00106     /** Default constructor. */
00107     explicit CommandWebservice() : head(0), tail(0) {}
00108 
00109     /** Destructor. */
00110     virtual ~CommandWebservice() {}
00111 
00112     /** Returns the port number. */
00113     static unsigned int getPort() {return port;}
00114 
00115     /** Updates the port number. */
00116     static void setPort(int i)
00117     {
00118       if (i <= 0 || i>65535)
00119         throw DataException("Invalid port number: valid range is 1 - 65535");
00120       port = i;
00121     }
00122 
00123     /** Returns the number of threads for the server. */
00124     static unsigned int getThreads() {return threads;}
00125 
00126     /** Updates the number of threads for the server. */
00127     static void setThreads(int i)
00128     {
00129       if (i <= 0 || i>100)
00130         throw DataException("Invalid number of threads: valid range is 1 - 100");
00131       threads = i;
00132     }
00133 };
00134 
00135 
00136 }
00137 

Documentation generated for frePPLe by  doxygen