APIServer.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 #ifndef _APISERVER_H_
00039 #define _APISERVER_H_
00040 
00041 #include <oasys/debug/Log.h>
00042 #include <oasys/thread/Thread.h>
00043 #include <oasys/io/TCPClient.h>
00044 #include <oasys/io/TCPServer.h>
00045 
00046 #include "dtn_api.h"
00047 #include "dtn_ipc.h"
00048 #include "dtn_types.h"
00049 
00050 namespace dtn {
00051 
00052 class APIRegistration;
00053 class APIRegistrationList;
00054 
00059 class APIServer : public oasys::TCPServerThread {
00060 public:
00066     APIServer();
00067 
00068     // Virtual from TCPServerThread
00069     void accepted(int fd, in_addr_t addr, u_int16_t port);
00070     
00071     in_addr_t  local_addr() const { return local_addr_; }
00072     in_addr_t* local_addr_ptr() { return &local_addr_; }
00073     
00074     u_int16_t  local_port() const { return local_port_; }
00075     u_int16_t* local_port_ptr() { return &local_port_; }
00076     
00077 private:
00078     in_addr_t local_addr_;    
00079     u_int16_t local_port_;    
00080 };
00081 
00085 class APIClient : public oasys::Thread, public oasys::TCPClient {
00086 public:
00087     APIClient(int fd, in_addr_t remote_host, u_int16_t remote_port);
00088     virtual ~APIClient();
00089     virtual void run();
00090 
00091     void close_session();
00092     
00093 protected:
00094     int handle_handshake();
00095     int handle_local_eid();
00096     int handle_register();
00097     int handle_unregister();
00098     int handle_find_registration();
00099     int handle_bind();
00100     int handle_unbind();
00101     int handle_send();
00102     int handle_recv();
00103     int handle_begin_poll();
00104     int handle_cancel_poll();
00105     int handle_close();
00106 
00107     // wait for a bundle arrival on any bound registration, or for
00108     // traffic on the api socket.
00109     //
00110     // returns the oasys IO error code if there was a timeout or an
00111     // internal error. returns 0 if there is a bundle waiting or
00112     // socket data on the channel, and assigns the reg or sock_ready
00113     // pointers appropriately
00114     int wait_for_bundle(const char* operation, dtn_timeval_t timeout,
00115                         APIRegistration** reg, bool* sock_ready);
00116 
00117     int send_response(int ret);
00118 
00119     bool is_bound(u_int32_t regid);
00120     
00121     char buf_[DTN_MAX_API_MSG];
00122     XDR xdr_encode_;
00123     XDR xdr_decode_;
00124     APIRegistrationList* bindings_;
00125     oasys::Notifier notifier_;
00126 };
00127 
00128 } // namespace dtn
00129 
00130 #endif /* _APISERVER_H_ */

Generated on Fri Dec 22 14:47:57 2006 for DTN Reference Implementation by  doxygen 1.5.1