webservice.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002   file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/tags/0.8.0/modules/webservice/webservice.cpp $
00003   version : $LastChangedRevision: 1108 $  $LastChangedBy: jdetaeye $
00004   date : $LastChangedDate: 2009-12-06 18:54:18 +0100 (Sun, 06 Dec 2009) $
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  * Copyright (C) 2007 by Johan De Taeye                                    *
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     CommandReadXMLString(data, true, false).execute();
00062   }
00063   catch (DataException e)
00064     {return soap_sender_fault(soap, "Data Exception", e.what());}
00065   catch (LogicException e)
00066     {return soap_sender_fault(soap, "Logic Exception", e.what());}
00067   catch (RuntimeException e)
00068     {return soap_sender_fault(soap, "Runtime Exception", e.what());}
00069   catch (...)
00070     {return soap_sender_fault(soap, "Exception", "Unidentified");}
00071   result._return = 11;
00072   return SOAP_OK;
00073 }
00074 
00075