XmlRpcInterface.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2007 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #ifndef _XMLRPCINTERFACE_H__
00025 #define _XMLRPCINTERFACE_H__
00026 
00027 #include <omnetpp.h>
00028 #include <CommonMessages_m.h>
00029 #include <DHTMessage_m.h>
00030 #include <BaseOverlay.h>
00031 #include <BaseApp.h>
00032 #include <tunoutscheduler.h>
00033 #include <realtimescheduler.h>
00034 #include <XmlRpc.h>
00035 
00036 const int XMLRPC_TIMEOUT=30;
00037 
00038 
00042 class XmlRpcInterface : public BaseApp, public XmlRpc::XmlRpcServer
00043 {
00044 protected:
00045     unsigned int mtu;
00046 
00047     cMessage* packetNotification; // used by TunOutScheduler to notify about new packets
00048     RealtimeScheduler::PacketBuffer packetBuffer; // received packets are stored here
00049     RealtimeScheduler* scheduler;
00050 
00052     bool readHeader(char *buf, uint32_t length);
00053 
00055     bool readRequest(char *buf, uint32_t length);
00056 
00058     bool writeResponse();
00059 
00061     enum ServerConnectionState { READ_HEADER, READ_REQUEST, EXECUTE_REQUEST,
00062                              WRITE_RESPONSE };
00063 
00064     struct XmlRpcConnectionState {
00066         ServerConnectionState _connectionState;
00067 
00069         std::string _header;
00070 
00072         int _contentLength;
00073 
00075         std::string _request;
00076 
00078         std::string _response;
00079 
00081         int _bytesWritten;
00082 
00084         bool _keepAlive;
00085 
00087         SOCKET appFd;
00088 
00090         bool localhost;
00091 
00093         uint32_t pendingRpc;
00094     };
00095 
00096     std::map<int, XmlRpcConnectionState> state;
00097     SOCKET curAppFd;
00098     bool limitAccess;
00099 
00100     XmlRpc::XmlRpcServerMethod* _localLookup;
00101     XmlRpc::XmlRpcServerMethod* _lookup;
00102     XmlRpc::XmlRpcServerMethod* _register;
00103     XmlRpc::XmlRpcServerMethod* _resolve;
00104     XmlRpc::XmlRpcServerMethod* _put;
00105     XmlRpc::XmlRpcServerMethod* _get;
00106     XmlRpc::XmlRpcServerMethod* _dumpDht;
00107     XmlRpc::XmlRpcServerMethod* _joinOverlay;
00108 
00116     bool isPrivileged();
00117 
00118     void handleRealworldPacket(char *buf, uint32_t len);
00119     void handleCommonAPIPacket(cMessage *msg);
00120     void handleRpcResponse(BaseResponseMessage* msg,
00121                            cPolymorphic* context,
00122                            int rpcId,
00123                            simtime_t rtt);
00128     void resetConnectionState();
00129 
00130     void closeConnection();
00131     void sendInternalRpcWithTimeout(CompType destComp, BaseCallMessage *call);
00132 
00133 
00134 public:
00135     XmlRpcInterface();
00136     ~XmlRpcInterface();
00137 
00138     virtual void initializeApp(int stage);
00139 
00144     virtual void handleMessage(cMessage *msg);
00145 
00146     // see BaseRpc.cc
00147     void handleRpcTimeout(BaseCallMessage* msg,
00148                           const TransportAddress& dest,
00149                           cPolymorphic* context, int rpcId,
00150                           const OverlayKey&);
00151 
00152     void localLookup(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00153     void lookup(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00154     void p2pnsRegister(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00155     void p2pnsResolve(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00156     void put(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00157     void get(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00158     void dumpDht(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00159     void joinOverlay(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00160 };
00161 
00162 #endif

Generated on Wed Mar 25 16:32:50 2009 for OverSim by  doxygen 1.5.5