Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 29c369053a983cc5d8c880dc6e0a2237 > files > 368

libdtn-devel-2.6.0-2mdv2009.1.i586.rpm

<!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: InterfaceTable.cc 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&nbsp;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&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>InterfaceTable.cc</h1><a href="InterfaceTable_8cc.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">#ifdef HAVE_CONFIG_H</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;<a class="code" href="dtn-config_8h.html">dtn-config.h</a>&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#endif</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include "<a class="code" href="InterfaceTable_8h.html">InterfaceTable.h</a>"</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="ConvergenceLayer_8h.html">conv_layers/ConvergenceLayer.h</a>"</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include "oasys/util/StringBuffer.h"</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="keyword">namespace </span>dtn {
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 InterfaceTable* <a class="code" href="classdtn_1_1InterfaceTable.html#8b25363add8b0219adfcb95ec6ee6bda">InterfaceTable::instance_</a> = NULL;
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="classdtn_1_1InterfaceTable.html#7e25241c33b23cfdb9f89d08a8c95d59">00029</a> <a class="code" href="classdtn_1_1InterfaceTable.html#7e25241c33b23cfdb9f89d08a8c95d59" title="Constructor.">InterfaceTable::InterfaceTable</a>()
<a name="l00030"></a>00030     : <a class="code" href="classoasys_1_1Logger.html">Logger</a>(<span class="stringliteral">"InterfaceTable"</span>, <span class="stringliteral">"/dtn/interface/table"</span>)
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032 }
<a name="l00033"></a>00033 
<a name="l00034"></a><a class="code" href="classdtn_1_1InterfaceTable.html#7f12f79af5bab5d6c3c63cd55e494a82">00034</a> <a class="code" href="classdtn_1_1InterfaceTable.html#7f12f79af5bab5d6c3c63cd55e494a82" title="Destructor.">InterfaceTable::~InterfaceTable</a>()
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036     NOTREACHED;
<a name="l00037"></a>00037 }
<a name="l00038"></a>00038 
<a name="l00043"></a>00043 <span class="keywordtype">bool</span>
<a name="l00044"></a><a class="code" href="classdtn_1_1InterfaceTable.html#7a25701997d76b8325ea8f0f2d72dfaa">00044</a> <a class="code" href="classdtn_1_1InterfaceTable.html#7a25701997d76b8325ea8f0f2d72dfaa" title="Internal method to find the location of the given interface in the list.">InterfaceTable::find</a>(<span class="keyword">const</span> std::string&amp; name,
<a name="l00045"></a>00045                      InterfaceList::iterator* iter)
<a name="l00046"></a>00046 {
<a name="l00047"></a>00047     <a class="code" href="classdtn_1_1Interface.html" title="Abstraction of a local dtn interface.">Interface</a>* iface;
<a name="l00048"></a>00048     <span class="keywordflow">for</span> (*iter = <a class="code" href="classdtn_1_1InterfaceTable.html#ae6cb65182e415b91cf9ff7f770ce1c1" title="All interfaces are tabled in-memory in a flat list.">iflist_</a>.begin(); *iter != <a class="code" href="classdtn_1_1InterfaceTable.html#ae6cb65182e415b91cf9ff7f770ce1c1" title="All interfaces are tabled in-memory in a flat list.">iflist_</a>.end(); ++(*iter)) {
<a name="l00049"></a>00049         iface = **iter;
<a name="l00050"></a>00050         
<a name="l00051"></a>00051         <span class="keywordflow">if</span> (iface-&gt;<a class="code" href="classdtn_1_1Interface.html#dc2636c7e82f1fc234679eb3983be95a">name</a>() == name) {
<a name="l00052"></a>00052             <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00053"></a>00053         }
<a name="l00054"></a>00054     }        
<a name="l00055"></a>00055     
<a name="l00056"></a>00056     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00057"></a>00057 }
<a name="l00058"></a>00058 
<a name="l00064"></a>00064 <span class="keywordtype">bool</span>
<a name="l00065"></a><a class="code" href="classdtn_1_1InterfaceTable.html#98e3f88c67062ccf02f8fb52c1a5d70d">00065</a> <a class="code" href="classdtn_1_1InterfaceTable.html#98e3f88c67062ccf02f8fb52c1a5d70d" title="Add a new interface to the table.">InterfaceTable::add</a>(<span class="keyword">const</span> std::string&amp; name,
<a name="l00066"></a>00066                     <a class="code" href="classdtn_1_1ConvergenceLayer.html" title="The abstract interface for a convergence layer.">ConvergenceLayer</a>* cl,
<a name="l00067"></a>00067                     <span class="keyword">const</span> <span class="keywordtype">char</span>* proto,
<a name="l00068"></a>00068                     <span class="keywordtype">int</span> argc, <span class="keyword">const</span> <span class="keywordtype">char</span>* argv[])
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070     InterfaceList::iterator iter;
<a name="l00071"></a>00071     
<a name="l00072"></a>00072     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1InterfaceTable.html#7a25701997d76b8325ea8f0f2d72dfaa" title="Internal method to find the location of the given interface in the list.">find</a>(name, &amp;iter)) {
<a name="l00073"></a>00073         log_err(<span class="stringliteral">"interface %s already exists"</span>, name.c_str());
<a name="l00074"></a>00074         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00075"></a>00075     }
<a name="l00076"></a>00076     
<a name="l00077"></a>00077     log_info(<span class="stringliteral">"adding interface %s (%s)"</span>, name.c_str(), proto);
<a name="l00078"></a>00078 
<a name="l00079"></a>00079     <a class="code" href="classdtn_1_1Interface.html" title="Abstraction of a local dtn interface.">Interface</a>* iface = <span class="keyword">new</span> <a class="code" href="classdtn_1_1Interface.html" title="Abstraction of a local dtn interface.">Interface</a>(name, proto, cl);
<a name="l00080"></a>00080     <span class="keywordflow">if</span> (! cl-&gt;<a class="code" href="classdtn_1_1ConvergenceLayer.html#0d8005ac771a2200d8b9a1fc46a42c29" title="Bring up a new interface.">interface_up</a>(iface, argc, argv)) {
<a name="l00081"></a>00081         log_err(<span class="stringliteral">"convergence layer error adding interface %s"</span>, name.c_str());
<a name="l00082"></a>00082         <span class="keyword">delete</span> iface;
<a name="l00083"></a>00083         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00084"></a>00084     }
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     <a class="code" href="classdtn_1_1InterfaceTable.html#ae6cb65182e415b91cf9ff7f770ce1c1" title="All interfaces are tabled in-memory in a flat list.">iflist_</a>.push_back(iface);
<a name="l00087"></a>00087 
<a name="l00088"></a>00088     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00089"></a>00089 }
<a name="l00090"></a>00090 
<a name="l00094"></a>00094 <span class="keywordtype">bool</span>
<a name="l00095"></a><a class="code" href="classdtn_1_1InterfaceTable.html#16a1079a0de9a8bf7101d9416dc50542">00095</a> <a class="code" href="classdtn_1_1InterfaceTable.html#16a1079a0de9a8bf7101d9416dc50542" title="Remove the specified interface.">InterfaceTable::del</a>(<span class="keyword">const</span> std::string&amp; name)
<a name="l00096"></a>00096 {
<a name="l00097"></a>00097     InterfaceList::iterator iter;
<a name="l00098"></a>00098     <a class="code" href="classdtn_1_1Interface.html" title="Abstraction of a local dtn interface.">Interface</a>* iface;
<a name="l00099"></a>00099     <span class="keywordtype">bool</span> retval = <span class="keyword">false</span>;
<a name="l00100"></a>00100     
<a name="l00101"></a>00101     log_info(<span class="stringliteral">"removing interface %s"</span>, name.c_str());
<a name="l00102"></a>00102 
<a name="l00103"></a>00103     <span class="keywordflow">if</span> (! <a class="code" href="classdtn_1_1InterfaceTable.html#7a25701997d76b8325ea8f0f2d72dfaa" title="Internal method to find the location of the given interface in the list.">find</a>(name, &amp;iter)) {
<a name="l00104"></a>00104         log_err(<span class="stringliteral">"error removing interface %s: no such interface"</span>,
<a name="l00105"></a>00105                 name.c_str());
<a name="l00106"></a>00106         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00107"></a>00107     }
<a name="l00108"></a>00108 
<a name="l00109"></a>00109     iface = *iter;
<a name="l00110"></a>00110     <a class="code" href="classdtn_1_1InterfaceTable.html#ae6cb65182e415b91cf9ff7f770ce1c1" title="All interfaces are tabled in-memory in a flat list.">iflist_</a>.erase(iter);
<a name="l00111"></a>00111 
<a name="l00112"></a>00112     <span class="keywordflow">if</span> (iface-&gt;<a class="code" href="classdtn_1_1Interface.html#a66e0906d6d60bca99d8d31049db7f85">clayer</a>()-&gt;<a class="code" href="classdtn_1_1ConvergenceLayer.html#1f92c4c8c0fe58e20caa3ed72142f953" title="Bring down the interface.">interface_down</a>(iface)) {
<a name="l00113"></a>00113         retval = <span class="keyword">true</span>;
<a name="l00114"></a>00114     } <span class="keywordflow">else</span> {
<a name="l00115"></a>00115         log_err(<span class="stringliteral">"error deleting interface %s from the convergence layer."</span>,
<a name="l00116"></a>00116                 name.c_str());
<a name="l00117"></a>00117         retval = <span class="keyword">false</span>;
<a name="l00118"></a>00118     }
<a name="l00119"></a>00119 
<a name="l00120"></a>00120     <span class="keyword">delete</span> iface;
<a name="l00121"></a>00121     <span class="keywordflow">return</span> retval;
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123 
<a name="l00127"></a>00127 <span class="keywordtype">void</span>
<a name="l00128"></a><a class="code" href="classdtn_1_1InterfaceTable.html#129d7bde09a2db027b3a082c6a2b88ff">00128</a> <a class="code" href="classdtn_1_1InterfaceTable.html#129d7bde09a2db027b3a082c6a2b88ff" title="List the current interfaces.">InterfaceTable::list</a>(oasys::StringBuffer *<a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>)
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130     InterfaceList::iterator iter;
<a name="l00131"></a>00131     <a class="code" href="classdtn_1_1Interface.html" title="Abstraction of a local dtn interface.">Interface</a>* iface;
<a name="l00132"></a>00132 
<a name="l00133"></a>00133     <span class="keywordflow">for</span> (iter = <a class="code" href="classdtn_1_1InterfaceTable.html#ae6cb65182e415b91cf9ff7f770ce1c1" title="All interfaces are tabled in-memory in a flat list.">iflist_</a>.begin(); iter != <a class="code" href="classdtn_1_1InterfaceTable.html#ae6cb65182e415b91cf9ff7f770ce1c1" title="All interfaces are tabled in-memory in a flat list.">iflist_</a>.end(); ++(iter)) {
<a name="l00134"></a>00134         iface = *iter;
<a name="l00135"></a>00135         buf-&gt;appendf(<span class="stringliteral">"%s: Convergence Layer: %s\n"</span>,
<a name="l00136"></a>00136                      iface-&gt;<a class="code" href="classdtn_1_1Interface.html#dc2636c7e82f1fc234679eb3983be95a">name</a>().c_str(), iface-&gt;<a class="code" href="classdtn_1_1Interface.html#7635e91472a03d7882b3f144e71b7f3a">proto</a>().c_str());
<a name="l00137"></a>00137         iface-&gt;<a class="code" href="classdtn_1_1Interface.html#a66e0906d6d60bca99d8d31049db7f85">clayer</a>()-&gt;<a class="code" href="classdtn_1_1ConvergenceLayer.html#b7e42424ed95b560edcc28d6b45ecf04" title="Dump out CL specific interface information.">dump_interface</a>(iface, buf);
<a name="l00138"></a>00138         buf-&gt;append(<span class="stringliteral">"\n"</span>);
<a name="l00139"></a>00139     }
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 
<a name="l00142"></a>00142 } <span class="comment">// namespace dtn</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:57 2009 for DTN Reference Implementation by&nbsp;
<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>