<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>DTN Reference Implementation: APIServer.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.8 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <h1>APIServer.h</h1><a href="APIServer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * Copyright 2004-2006 Intel Corporation</span> <a name="l00003"></a>00003 <span class="comment"> * </span> <a name="l00004"></a>00004 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span> <a name="l00005"></a>00005 <span class="comment"> * you may not use this file except in compliance with the License.</span> <a name="l00006"></a>00006 <span class="comment"> * You may obtain a copy of the License at</span> <a name="l00007"></a>00007 <span class="comment"> * </span> <a name="l00008"></a>00008 <span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span> <a name="l00009"></a>00009 <span class="comment"> * </span> <a name="l00010"></a>00010 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span> <a name="l00011"></a>00011 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span> <a name="l00012"></a>00012 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> <a name="l00013"></a>00013 <span class="comment"> * See the License for the specific language governing permissions and</span> <a name="l00014"></a>00014 <span class="comment"> * limitations under the License.</span> <a name="l00015"></a>00015 <span class="comment"> */</span> <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#ifndef _APISERVER_H_</span> <a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#define _APISERVER_H_</span> <a name="l00019"></a>00019 <span class="preprocessor"></span> <a name="l00020"></a>00020 <span class="preprocessor">#include <list></span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#include <oasys/compat/rpc.h></span> <a name="l00023"></a>00023 <span class="preprocessor">#include <oasys/debug/Log.h></span> <a name="l00024"></a>00024 <span class="preprocessor">#include <oasys/thread/Thread.h></span> <a name="l00025"></a>00025 <span class="preprocessor">#include <oasys/thread/SpinLock.h></span> <a name="l00026"></a>00026 <span class="preprocessor">#include <oasys/io/TCPClient.h></span> <a name="l00027"></a>00027 <span class="preprocessor">#include <oasys/io/TCPServer.h></span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="dtn__api_8h.html">dtn_api.h</a>"</span> <a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="dtn__ipc_8h.html">dtn_ipc.h</a>"</span> <a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="dtn__types_8h.html">dtn_types.h</a>"</span> <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="keyword">namespace </span>dtn { <a name="l00034"></a>00034 <a name="l00035"></a>00035 <span class="keyword">class </span>APIClient; <a name="l00036"></a>00036 <span class="keyword">class </span>APIRegistration; <a name="l00037"></a>00037 <span class="keyword">class </span>APIRegistrationList; <a name="l00038"></a>00038 <a name="l00043"></a><a class="code" href="classdtn_1_1APIServer.html">00043</a> <span class="keyword">class </span><a class="code" href="classdtn_1_1APIServer.html" title="Class that implements the main server side handling of the DTN application IPC.">APIServer</a> : <span class="keyword">public</span> oasys::TCPServerThread { <a name="l00044"></a>00044 <span class="keyword">public</span>: <a name="l00050"></a>00050 <a class="code" href="classdtn_1_1APIServer.html#964a720028d4513d9de05f4c88689917" title="The constructor checks for environment variable overrides of the address / port.">APIServer</a>(); <a name="l00051"></a>00051 <a name="l00052"></a>00052 <span class="comment">// shutdown hook, clean up clients</span> <a name="l00053"></a>00053 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1APIServer.html#9799799151cc98f5e84b3deb6b68b33e">shutdown_hook</a>(); <a name="l00054"></a>00054 <a name="l00055"></a>00055 <span class="comment">// Virtual from TCPServerThread</span> <a name="l00056"></a>00056 <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1APIServer.html#9e4edfeba6a6b7b05e489f346f79b125">accepted</a>(<span class="keywordtype">int</span> <a class="code" href="dtnperf-client_8c.html#6f8059414f0228f0256115e024eeed4b">fd</a>, in_addr_t addr, u_int16_t port); <a name="l00057"></a>00057 <a name="l00058"></a><a class="code" href="classdtn_1_1APIServer.html#9da09c603ffa6a92b523633dec148a36">00058</a> <span class="keywordtype">bool</span> <a class="code" href="classdtn_1_1APIServer.html#9da09c603ffa6a92b523633dec148a36">enabled</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1APIServer.html#52bb7c6b0365b5a1f324d9f9d90f1c5a" title="whether or not to enable it">enabled_</a>; } <a name="l00059"></a><a class="code" href="classdtn_1_1APIServer.html#fe04d3fdcc74b5b6d44e0f8b2044234f">00059</a> <span class="keywordtype">bool</span>* <a class="code" href="classdtn_1_1APIServer.html#fe04d3fdcc74b5b6d44e0f8b2044234f">enabled_ptr</a>() { <span class="keywordflow">return</span> &<a class="code" href="classdtn_1_1APIServer.html#52bb7c6b0365b5a1f324d9f9d90f1c5a" title="whether or not to enable it">enabled_</a>; } <a name="l00060"></a>00060 <a name="l00061"></a><a class="code" href="classdtn_1_1APIServer.html#8057e873307e2c0fa3bfcda6b9a1146d">00061</a> in_addr_t <a class="code" href="classdtn_1_1APIServer.html#8057e873307e2c0fa3bfcda6b9a1146d">local_addr</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1APIServer.html#e19acdd68aa4c9f0c6c308493328f5c6" title="local address to bind to">local_addr_</a>; } <a name="l00062"></a><a class="code" href="classdtn_1_1APIServer.html#d043609acb0f35ea29fd1d75730be1c3">00062</a> in_addr_t* <a class="code" href="classdtn_1_1APIServer.html#d043609acb0f35ea29fd1d75730be1c3">local_addr_ptr</a>() { <span class="keywordflow">return</span> &<a class="code" href="classdtn_1_1APIServer.html#e19acdd68aa4c9f0c6c308493328f5c6" title="local address to bind to">local_addr_</a>; } <a name="l00063"></a>00063 <a name="l00064"></a><a class="code" href="classdtn_1_1APIServer.html#2c377b4c3ea52f788d41fdf905591882">00064</a> u_int16_t <a class="code" href="classdtn_1_1APIServer.html#2c377b4c3ea52f788d41fdf905591882">local_port</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1APIServer.html#72c56ebd73a38bf0caa78a16036740c6" title="local port to use for api">local_port_</a>; } <a name="l00065"></a><a class="code" href="classdtn_1_1APIServer.html#db95eebd60b603b8f04885ee7140c043">00065</a> u_int16_t* <a class="code" href="classdtn_1_1APIServer.html#db95eebd60b603b8f04885ee7140c043">local_port_ptr</a>() { <span class="keywordflow">return</span> &<a class="code" href="classdtn_1_1APIServer.html#72c56ebd73a38bf0caa78a16036740c6" title="local port to use for api">local_port_</a>; } <a name="l00066"></a>00066 <a name="l00067"></a>00067 <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1APIServer.html#a59a177fa443ca1be6a9da71e3495973">register_client</a>(<a class="code" href="classdtn_1_1APIClient.html" title="Class that implements the API session.">APIClient</a> *); <a name="l00068"></a>00068 <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1APIServer.html#fd9f7a445d44dfac0805db7846296f8e">unregister_client</a>(<a class="code" href="classdtn_1_1APIClient.html" title="Class that implements the API session.">APIClient</a> *); <a name="l00069"></a>00069 <a name="l00070"></a>00070 <span class="keyword">protected</span>: <a name="l00071"></a><a class="code" href="classdtn_1_1APIServer.html#52bb7c6b0365b5a1f324d9f9d90f1c5a">00071</a> <span class="keywordtype">bool</span> <a class="code" href="classdtn_1_1APIServer.html#52bb7c6b0365b5a1f324d9f9d90f1c5a" title="whether or not to enable it">enabled_</a>; <a name="l00072"></a><a class="code" href="classdtn_1_1APIServer.html#e19acdd68aa4c9f0c6c308493328f5c6">00072</a> in_addr_t <a class="code" href="classdtn_1_1APIServer.html#e19acdd68aa4c9f0c6c308493328f5c6" title="local address to bind to">local_addr_</a>; <a name="l00073"></a><a class="code" href="classdtn_1_1APIServer.html#72c56ebd73a38bf0caa78a16036740c6">00073</a> u_int16_t <a class="code" href="classdtn_1_1APIServer.html#72c56ebd73a38bf0caa78a16036740c6" title="local port to use for api">local_port_</a>; <a name="l00074"></a>00074 <a name="l00075"></a><a class="code" href="classdtn_1_1APIServer.html#ce510dee43b8d52dc6b2ffec93aa5ded">00075</a> std::list<APIClient *> <a class="code" href="classdtn_1_1APIServer.html#ce510dee43b8d52dc6b2ffec93aa5ded" title="active clients">client_list</a>; <a name="l00076"></a><a class="code" href="classdtn_1_1APIServer.html#ad197c6739024b73b03c6287206bd6df">00076</a> oasys::SpinLock <a class="code" href="classdtn_1_1APIServer.html#ad197c6739024b73b03c6287206bd6df" title="synchronizer">client_list_lock</a>; <a name="l00077"></a>00077 }; <a name="l00078"></a>00078 <a name="l00082"></a><a class="code" href="classdtn_1_1APIClient.html">00082</a> <span class="keyword">class </span><a class="code" href="classdtn_1_1APIClient.html" title="Class that implements the API session.">APIClient</a> : <span class="keyword">public</span> oasys::Thread, <span class="keyword">public</span> oasys::TCPClient { <a name="l00083"></a>00083 <span class="keyword">public</span>: <a name="l00084"></a>00084 <a class="code" href="classdtn_1_1APIClient.html#0a3ca236759a37189d2ff7bf19f4b977">APIClient</a>(<span class="keywordtype">int</span> <a class="code" href="dtnperf-client_8c.html#6f8059414f0228f0256115e024eeed4b">fd</a>, in_addr_t remote_host, u_int16_t remote_port, <a name="l00085"></a>00085 <a class="code" href="classdtn_1_1APIServer.html" title="Class that implements the main server side handling of the DTN application IPC.">APIServer</a> *parent); <a name="l00086"></a>00086 <span class="keyword">virtual</span> <a class="code" href="classdtn_1_1APIClient.html#b492c133ba9f0c9b22c69f067900be8a">~APIClient</a>(); <a name="l00087"></a>00087 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1APIClient.html#1f9b4788d77129db1a3f8a6fb0f1da61">run</a>(); <a name="l00088"></a>00088 <a name="l00089"></a>00089 <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1APIClient.html#6681a2fe127ddcfc2880004d21f06b19">close_client</a>(); <a name="l00090"></a>00090 <a name="l00091"></a>00091 <span class="keyword">protected</span>: <a name="l00092"></a>00092 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#8ccf701f5461adce95be8ee1e4781ebf">handle_handshake</a>(); <a name="l00093"></a>00093 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#84d763e96acc0b07d425f4cf003ba257">handle_local_eid</a>(); <a name="l00094"></a>00094 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#56bb3d82073d910564ece376b710fee4">handle_register</a>(); <a name="l00095"></a>00095 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#3ace90f9a37789ba35368c9f2f7d5489">handle_unregister</a>(); <a name="l00096"></a>00096 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#262746ba8158df642ab53a2083c51e77">handle_find_registration</a>(); <a name="l00097"></a>00097 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#98e793d1feb9e5254578bdbc357f7489">handle_bind</a>(); <a name="l00098"></a>00098 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#fa8cf363d0568517bf082ef60a485938">handle_unbind</a>(); <a name="l00099"></a>00099 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#6961c3dcfe571414d3da893554ec7176">handle_send</a>(); <a name="l00100"></a>00100 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#55108097eb6498f788eebadd3311725f">handle_cancel</a>(); <a name="l00101"></a>00101 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#62bed4eeeb10a011c0dca071d32b1aff">handle_recv</a>(); <a name="l00102"></a>00102 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#e082ab699cdd974eff4be0b3622342e4">handle_begin_poll</a>(); <a name="l00103"></a>00103 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#67898f3771df3d7780d7dd7f3baf0f14">handle_cancel_poll</a>(); <a name="l00104"></a>00104 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#ba38760ce21e619d3296059842f56928">handle_close</a>(); <a name="l00105"></a>00105 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#f19b929f413fea3504c794202068c4d7">handle_session_update</a>(); <a name="l00106"></a>00106 <a name="l00107"></a>00107 <span class="comment">// block the calling thread, waiting for bundle arrival on a bound</span> <a name="l00108"></a>00108 <span class="comment">// registration, notification that a subscriber has arrived for a</span> <a name="l00109"></a>00109 <span class="comment">// custody session, or for traffic on the api socket.</span> <a name="l00110"></a>00110 <span class="comment">//</span> <a name="l00111"></a>00111 <span class="comment">// returns the oasys IO error code if there was a timeout or an</span> <a name="l00112"></a>00112 <span class="comment">// internal error. returns 0 if there is a bundle waiting or</span> <a name="l00113"></a>00113 <span class="comment">// socket data on the channel, and assigns the reg or sock_ready</span> <a name="l00114"></a>00114 <span class="comment">// pointers appropriately</span> <a name="l00115"></a>00115 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#684680789390fa8e03f98a0abd5cb518">wait_for_notify</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* operation, <a name="l00116"></a>00116 <a class="code" href="dtn__types_8h.html#8865a20f2e713bb38e35736e32e1653c" title="DTN timeouts are specified in seconds.">dtn_timeval_t</a> timeout, <a name="l00117"></a>00117 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>** recv_ready_reg, <a name="l00118"></a>00118 <a class="code" href="classdtn_1_1APIRegistration.html" title="Registration class to represent an actual attached application over the client api...">APIRegistration</a>** session_ready_reg, <a name="l00119"></a>00119 <span class="keywordtype">bool</span>* sock_ready); <a name="l00120"></a>00120 <a name="l00121"></a>00121 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#bfb85bb3e353ab67949514ea0aa72059">handle_unexpected_data</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* operation); <a name="l00122"></a>00122 <a name="l00123"></a>00123 <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1APIClient.html#476beb5eb7b7073738e3a9c18de1ab5f">send_response</a>(<span class="keywordtype">int</span> ret); <a name="l00124"></a>00124 <a name="l00125"></a>00125 <span class="keywordtype">bool</span> <a class="code" href="classdtn_1_1APIClient.html#02902ee6c5e3a406c7c579ed21bcf205">is_bound</a>(u_int32_t <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>); <a name="l00126"></a>00126 <a name="l00127"></a><a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">00127</a> <span class="keywordtype">char</span> <a class="code" href="classdtn_1_1APIClient.html#3d1129c8e4961bb050af83f927f57546">buf_</a>[<a class="code" href="dtn__ipc_8h.html#51d06f90137293f017ba7e9019d6602f" title="The maximum IPC message size (in bytes).">DTN_MAX_API_MSG</a>]; <a name="l00128"></a><a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">00128</a> XDR <a class="code" href="classdtn_1_1APIClient.html#913a8a0ef9793ca0ad9742be58aaa5e9">xdr_encode_</a>; <a name="l00129"></a><a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">00129</a> XDR <a class="code" href="classdtn_1_1APIClient.html#ace73b2d7a0e5c748ee9c1bf741c5b41">xdr_decode_</a>; <a name="l00130"></a><a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">00130</a> <a class="code" href="classdtn_1_1APIRegistrationList.html" title="Typedef for a list of APIRegistrations.">APIRegistrationList</a>* <a class="code" href="classdtn_1_1APIClient.html#500f1a606af3ed2fe3fe7a3030d2af42">bindings_</a>; <a name="l00131"></a><a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">00131</a> <a class="code" href="classdtn_1_1APIRegistrationList.html" title="Typedef for a list of APIRegistrations.">APIRegistrationList</a>* <a class="code" href="classdtn_1_1APIClient.html#5448e687c48be53a1df5d5246b0f7e3f">sessions_</a>; <a name="l00132"></a><a class="code" href="classdtn_1_1APIClient.html#0a59d9aaa708622f03224ba11e27c43f">00132</a> oasys::Notifier <a class="code" href="classdtn_1_1APIClient.html#0a59d9aaa708622f03224ba11e27c43f">notifier_</a>; <a name="l00133"></a><a class="code" href="classdtn_1_1APIClient.html#f3458aa411cf077c6d7196433aec8db2">00133</a> <a class="code" href="classdtn_1_1APIServer.html" title="Class that implements the main server side handling of the DTN application IPC.">APIServer</a>* <a class="code" href="classdtn_1_1APIClient.html#f3458aa411cf077c6d7196433aec8db2">parent_</a>; <a name="l00134"></a><a class="code" href="classdtn_1_1APIClient.html#98a37692381356296c960cd1713ab9e8">00134</a> <span class="keywordtype">size_t</span> <a class="code" href="classdtn_1_1APIClient.html#98a37692381356296c960cd1713ab9e8">total_sent_</a>; <a name="l00135"></a><a class="code" href="classdtn_1_1APIClient.html#64c975c94dafb44c3d761065498aa62f">00135</a> <span class="keywordtype">size_t</span> <a class="code" href="classdtn_1_1APIClient.html#64c975c94dafb44c3d761065498aa62f">total_rcvd_</a>; <a name="l00136"></a>00136 }; <a name="l00137"></a>00137 <a name="l00138"></a>00138 } <span class="comment">// namespace dtn</span> <a name="l00139"></a>00139 <a name="l00140"></a>00140 <span class="preprocessor">#endif </span><span class="comment">/* _APISERVER_H_ */</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:52 2009 for DTN Reference Implementation by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> </body> </html>