00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _APISERVER_H_
00018 #define _APISERVER_H_
00019
00020 #include <list>
00021
00022 #include <oasys/compat/rpc.h>
00023 #include <oasys/debug/Log.h>
00024 #include <oasys/thread/Thread.h>
00025 #include <oasys/thread/SpinLock.h>
00026 #include <oasys/io/TCPClient.h>
00027 #include <oasys/io/TCPServer.h>
00028
00029 #include "dtn_api.h"
00030 #include "dtn_ipc.h"
00031 #include "dtn_types.h"
00032
00033 namespace dtn {
00034
00035 class APIClient;
00036 class APIRegistration;
00037 class APIRegistrationList;
00038
00043 class APIServer : public oasys::TCPServerThread {
00044 public:
00050 APIServer();
00051
00052
00053 virtual void shutdown_hook();
00054
00055
00056 void accepted(int fd, in_addr_t addr, u_int16_t port);
00057
00058 bool enabled() const { return enabled_; }
00059 bool* enabled_ptr() { return &enabled_; }
00060
00061 in_addr_t local_addr() const { return local_addr_; }
00062 in_addr_t* local_addr_ptr() { return &local_addr_; }
00063
00064 u_int16_t local_port() const { return local_port_; }
00065 u_int16_t* local_port_ptr() { return &local_port_; }
00066
00067 void register_client(APIClient *);
00068 void unregister_client(APIClient *);
00069
00070 protected:
00071 bool enabled_;
00072 in_addr_t local_addr_;
00073 u_int16_t local_port_;
00074
00075 std::list<APIClient *> client_list;
00076 oasys::SpinLock client_list_lock;
00077 };
00078
00082 class APIClient : public oasys::Thread, public oasys::TCPClient {
00083 public:
00084 APIClient(int fd, in_addr_t remote_host, u_int16_t remote_port,
00085 APIServer *parent);
00086 virtual ~APIClient();
00087 virtual void run();
00088
00089 void close_client();
00090
00091 protected:
00092 int handle_handshake();
00093 int handle_local_eid();
00094 int handle_register();
00095 int handle_unregister();
00096 int handle_find_registration();
00097 int handle_bind();
00098 int handle_unbind();
00099 int handle_send();
00100 int handle_cancel();
00101 int handle_recv();
00102 int handle_begin_poll();
00103 int handle_cancel_poll();
00104 int handle_close();
00105 int handle_session_update();
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 int wait_for_notify(const char* operation,
00116 dtn_timeval_t timeout,
00117 APIRegistration** recv_ready_reg,
00118 APIRegistration** session_ready_reg,
00119 bool* sock_ready);
00120
00121 int handle_unexpected_data(const char* operation);
00122
00123 int send_response(int ret);
00124
00125 bool is_bound(u_int32_t regid);
00126
00127 char buf_[DTN_MAX_API_MSG];
00128 XDR xdr_encode_;
00129 XDR xdr_decode_;
00130 APIRegistrationList* bindings_;
00131 APIRegistrationList* sessions_;
00132 oasys::Notifier notifier_;
00133 APIServer* parent_;
00134 size_t total_sent_;
00135 size_t total_rcvd_;
00136 };
00137
00138 }
00139
00140 #endif