webservice.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/webservice.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 #include "frepple.nsmap"
00030 
00031 
00032 /** Implementation of the webservice method to return demand information. */
00033 SOAP_FMAC5 int SOAP_FMAC6 frepple__demand(struct soap* soap, char *name, struct frepple__DemandInfoResponse &result)
00034 {
00035   // Search for the demand
00036   if (!name)
00037     return soap_sender_fault(soap, "Missing demand name", "NULL demand name passed");
00038   Demand* i = Demand::find(name);
00039   if (!i)
00040   {
00041     ostringstream msg;
00042     msg << "The demand with name '" << name << "' couldn't be found";
00043     return soap_sender_fault(soap, "Demand not found", msg.str().c_str());
00044   }
00045 
00046   // Retrieve demand data
00047   result._return.name = const_cast<char*>(i->getName().c_str());
00048   if (i->getItem())
00049     result._return.item = const_cast<char*>(i->getItem()->getName().c_str());
00050   result._return.priority = i->getPriority();
00051   result._return.quantity = i->getQuantity();
00052   result._return.due = i->getDue().getTicks();
00053   return SOAP_OK;
00054 }
00055 
00056 
00057 /** Implementation of the webservice method to post XML data. */
00058 SOAP_FMAC5 int SOAP_FMAC6 frepple__post(struct soap* soap, char *data, struct frepple__PostResponse &result)
00059 {
00060   try
00061   {
00062     CommandReadXMLString(data, true, false).commit();
00063   }
00064   catch (const DataException& e)
00065   {return soap_sender_fault(soap, "Data Exception", e.what());}
00066   catch (const LogicException& e)
00067   {return soap_sender_fault(soap, "Logic Exception", e.what());}
00068   catch (const RuntimeException& e)
00069   {return soap_sender_fault(soap, "Runtime Exception", e.what());}
00070   catch (...)
00071   {return soap_sender_fault(soap, "Exception", "Unidentified");}
00072   result._return = 11;
00073   return SOAP_OK;
00074 }
00075 
00076 

Documentation generated for frePPLe by  doxygen