OverSim
XmlRpcInterface.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef _XMLRPCINTERFACE_H__
25 #define _XMLRPCINTERFACE_H__
26 
27 #include <tunoutscheduler.h>
28 #include <realtimescheduler.h>
29 #include <omnetpp.h>
30 #include <CommonMessages_m.h>
31 #include <DHTMessage_m.h>
32 #include <BaseOverlay.h>
33 #include <BaseApp.h>
34 #include <XmlRpc.h>
35 
36 class P2pns;
37 
38 const int XMLRPC_TIMEOUT=30;
39 
40 
45 {
46 protected:
47  unsigned int mtu;
48 
49  cMessage* packetNotification; // used by TunOutScheduler to notify about new packets
50  PacketBuffer packetBuffer; // received packets are stored here
52 
54  bool readHeader(char *buf, uint32_t length);
55 
57  bool readRequest(char *buf, uint32_t length);
58 
60  bool writeResponse();
61 
65 
69 
71  std::string _header;
72 
75 
77  std::string _request;
78 
80  std::string _response;
81 
84 
86  bool _keepAlive;
87 
89  SOCKET appFd;
90 
92  bool localhost;
93 
95  uint32_t pendingRpc;
96  };
97 
98  std::map<int, XmlRpcConnectionState> state;
99  SOCKET curAppFd;
101 
110 
111  // SODESSON interface
120 
128  bool isPrivileged();
129 
130  void handleAppTunPacket(char *buf, uint32_t len);
131  void handleRealworldPacket(char *buf, uint32_t len);
132  void handleCommonAPIPacket(cMessage *msg);
134  cPolymorphic* context,
135  int rpcId,
136  simtime_t rtt);
141  void resetConnectionState();
142 
143  void closeConnection();
145  virtual void handleReadyMessage(CompReadyMessage* msg);
146 
147  SOCKET appTunFd;
150 public:
151  XmlRpcInterface();
153 
154  virtual void initializeApp(int stage);
155 
160  virtual void handleMessage(cMessage *msg);
161 
162  // see BaseRpc.cc
164  const TransportAddress& dest,
165  cPolymorphic* context, int rpcId,
166  const OverlayKey&);
167 
168  void deliverTunneledMessage(const BinaryValue& payload);
169 
170  void localLookup(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
171  void lookup(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
174  void put(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
175  void get(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
176  void dumpDht(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
177  void joinOverlay(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
178 
179 };
180 
181 #endif