Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > d9faa203c2b0b6fbb179d93daaea81b7 > files > 498

libdtn-devel-2.6.0-1mdv2009.0.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: ProphetNodeList.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<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>
<h1>ProphetNodeList.cc</h1><a href="ProphetNodeList_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 2007 Baylor University</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><span class="preprocessor">#include "<a class="code" href="ProphetNodeList_8h.html">ProphetNodeList.h</a>"</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="keyword">namespace </span>dtn
<a name="l00023"></a>00023 {
<a name="l00024"></a>00024 
<a name="l00025"></a><a class="code" href="classdtn_1_1ProphetNodeList.html#e2e83fff7f23a878473a7871e4f3d0be">00025</a> <a class="code" href="classdtn_1_1ProphetNodeList.html#e2e83fff7f23a878473a7871e4f3d0be" title="Constructor.">ProphetNodeList::ProphetNodeList</a>()
<a name="l00026"></a>00026 {
<a name="l00027"></a>00027 }
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="classdtn_1_1ProphetNodeList.html#45d7de5e274e24f9085d9bcdca495627">00029</a> ProphetNodeList::~ProphetNodeList()
<a name="l00030"></a>00030 {
<a name="l00031"></a>00031     <a class="code" href="classdtn_1_1ProphetNodeList.html#2dad0fc20c9645013f92585c77e17b03" title="Clean up memory associated with this list (leaving permanent store untouched).">clear</a>();
<a name="l00032"></a>00032 }
<a name="l00033"></a>00033     
<a name="l00034"></a>00034 <span class="keywordtype">void</span>
<a name="l00035"></a><a class="code" href="classdtn_1_1ProphetNodeList.html#afbd8e532b00c349d5a1027573f5e67b">00035</a> <a class="code" href="classdtn_1_1ProphetNodeList.html#afbd8e532b00c349d5a1027573f5e67b" title="Deserialize from storage.">ProphetNodeList::load</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Node.html" title="Node represents a route to another Prophet node, and as such, tracks destination...">prophet::Node</a>* n)
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037     log_debug_p(<span class="stringliteral">"/dtn/route/nodelist"</span>,<span class="stringliteral">"load"</span>);
<a name="l00038"></a>00038     <a class="code" href="classdtn_1_1ProphetNodeList.html#06bb25a1b90b07056fe183fc33aa5a62">iterator</a> i;
<a name="l00039"></a>00039     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(n != NULL);
<a name="l00040"></a>00040     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(! <a class="code" href="classdtn_1_1ProphetNodeList.html#413a090a92022c78c1cc751bdb7b447d" title="Retrieve node from permanent store; returns NULL if not found.">find</a>(n-&gt;<a class="code" href="classprophet_1_1Node.html#4c423ba83a417f43615a087bf52127e9" title="Accessors.">dest_id</a>(), i));
<a name="l00041"></a>00041 
<a name="l00042"></a>00042     log_debug_p(<span class="stringliteral">"/dtn/route/nodelist"</span>,
<a name="l00043"></a>00043             <span class="stringliteral">"add new node for %s (age %u pv %.2f flags %s%s%s)"</span>,
<a name="l00044"></a>00044             n-&gt;<a class="code" href="classprophet_1_1Node.html#4c423ba83a417f43615a087bf52127e9" title="Accessors.">dest_id</a>(),
<a name="l00045"></a>00045             n-&gt;<a class="code" href="classprophet_1_1Node.html#203a4a3557ffec82595fe2ddce4fd9ab" title="Accessors.">age</a>(),
<a name="l00046"></a>00046             n-&gt;<a class="code" href="classprophet_1_1Node.html#97b1dbf4d60d48b5ffc8d7022a3708b7" title="Accessors.">p_value</a>(),
<a name="l00047"></a>00047             n-&gt;<a class="code" href="classprophet_1_1Node.html#0c4ef32bed5fa9595df25d24d4090ffc" title="Accessors.">relay</a>() ? <span class="stringliteral">"R"</span> : <span class="stringliteral">"-"</span>,
<a name="l00048"></a>00048             n-&gt;<a class="code" href="classprophet_1_1Node.html#30c2f606e0860b283bea16d79e1d5747" title="Accessors.">custody</a>() ? <span class="stringliteral">"C"</span> : <span class="stringliteral">"-"</span>,
<a name="l00049"></a>00049             n-&gt;<a class="code" href="classprophet_1_1Node.html#f960607d5799557a90155780683e5be3" title="Accessors.">internet_gw</a>() ? <span class="stringliteral">"I"</span> : <span class="stringliteral">"-"</span>);
<a name="l00050"></a>00050     <span class="comment">// create and insert new object</span>
<a name="l00051"></a>00051     <a class="code" href="classdtn_1_1ProphetNode.html" title="ProphetNode stores state for a remote node as identified by remote_eid.">ProphetNode</a>* a = <span class="keyword">new</span> <a class="code" href="classdtn_1_1ProphetNode.html" title="ProphetNode stores state for a remote node as identified by remote_eid.">ProphetNode</a>(*n);
<a name="l00052"></a>00052     <span class="comment">// internally and in ProphetStorage</span>
<a name="l00053"></a>00053     <a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.insert(i,a);
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 <span class="keywordtype">void</span>
<a name="l00057"></a><a class="code" href="classdtn_1_1ProphetNodeList.html#4e137701492aabe741b4fcab1e0762ba">00057</a> <a class="code" href="classdtn_1_1ProphetNodeList.html#4e137701492aabe741b4fcab1e0762ba" title="Update (or add new) node in permanent store.">ProphetNodeList::update</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Node.html" title="Node represents a route to another Prophet node, and as such, tracks destination...">prophet::Node</a>* n)
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059     log_debug_p(<span class="stringliteral">"/dtn/route/nodelist"</span>,<span class="stringliteral">"update"</span>);
<a name="l00060"></a>00060     <a class="code" href="classdtn_1_1ProphetNodeList.html#06bb25a1b90b07056fe183fc33aa5a62">iterator</a> i;
<a name="l00061"></a>00061     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(n != NULL);
<a name="l00062"></a>00062     <span class="keywordflow">if</span> (! <a class="code" href="classdtn_1_1ProphetNodeList.html#413a090a92022c78c1cc751bdb7b447d" title="Retrieve node from permanent store; returns NULL if not found.">find</a>(n-&gt;<a class="code" href="classprophet_1_1Node.html#4c423ba83a417f43615a087bf52127e9" title="Accessors.">dest_id</a>(), i))
<a name="l00063"></a>00063     {
<a name="l00064"></a>00064         log_debug_p(<span class="stringliteral">"/dtn/route/nodelist"</span>,
<a name="l00065"></a>00065                 <span class="stringliteral">"add new node for %s"</span>,n-&gt;<a class="code" href="classprophet_1_1Node.html#4c423ba83a417f43615a087bf52127e9" title="Accessors.">dest_id</a>());
<a name="l00066"></a>00066         <span class="comment">// create and insert new object</span>
<a name="l00067"></a>00067         <a class="code" href="classdtn_1_1ProphetNode.html" title="ProphetNode stores state for a remote node as identified by remote_eid.">ProphetNode</a>* a = <span class="keyword">new</span> <a class="code" href="classdtn_1_1ProphetNode.html" title="ProphetNode stores state for a remote node as identified by remote_eid.">ProphetNode</a>(*n);
<a name="l00068"></a>00068         <span class="comment">// internally and in ProphetStorage</span>
<a name="l00069"></a>00069         <a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.insert(i,a);
<a name="l00070"></a>00070         ProphetStore::instance()-&gt;add(a);
<a name="l00071"></a>00071     }
<a name="l00072"></a>00072     <span class="keywordflow">else</span>
<a name="l00073"></a>00073     {
<a name="l00074"></a>00074         log_debug_p(<span class="stringliteral">"/dtn/route/nodelist"</span>,
<a name="l00075"></a>00075                 <span class="stringliteral">"update existing node for %s"</span>,n-&gt;<a class="code" href="classprophet_1_1Node.html#4c423ba83a417f43615a087bf52127e9" title="Accessors.">dest_id</a>());
<a name="l00076"></a>00076         <span class="comment">// update existing</span>
<a name="l00077"></a>00077         <a class="code" href="classdtn_1_1ProphetNode.html" title="ProphetNode stores state for a remote node as identified by remote_eid.">ProphetNode</a>* a = <span class="keyword">static_cast&lt;</span><a class="code" href="classdtn_1_1ProphetNode.html" title="ProphetNode stores state for a remote node as identified by remote_eid.">ProphetNode</a>*<span class="keyword">&gt;</span>(*i);
<a name="l00078"></a>00078         a-&gt;set_pvalue( n-&gt;<a class="code" href="classprophet_1_1Node.html#97b1dbf4d60d48b5ffc8d7022a3708b7" title="Accessors.">p_value</a>() );
<a name="l00079"></a>00079         ProphetStore::instance()-&gt;update(a);
<a name="l00080"></a>00080     }
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082 
<a name="l00083"></a>00083 <span class="keywordtype">void</span>
<a name="l00084"></a><a class="code" href="classdtn_1_1ProphetNodeList.html#bc02c29e504d40da397a066842a5d63b">00084</a> <a class="code" href="classdtn_1_1ProphetNodeList.html#bc02c29e504d40da397a066842a5d63b" title="Remove node from permanent store.">ProphetNodeList::del</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Node.html" title="Node represents a route to another Prophet node, and as such, tracks destination...">prophet::Node</a>* n)
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086     <a class="code" href="classdtn_1_1ProphetNodeList.html#06bb25a1b90b07056fe183fc33aa5a62">iterator</a> i;
<a name="l00087"></a>00087     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(n != NULL);
<a name="l00088"></a>00088     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1ProphetNodeList.html#413a090a92022c78c1cc751bdb7b447d" title="Retrieve node from permanent store; returns NULL if not found.">find</a>(n-&gt;<a class="code" href="classprophet_1_1Node.html#4c423ba83a417f43615a087bf52127e9" title="Accessors.">dest_id</a>(), i))
<a name="l00089"></a>00089     {
<a name="l00090"></a>00090         <span class="comment">// remove from list and from ProphetStorage</span>
<a name="l00091"></a>00091         <a class="code" href="classdtn_1_1ProphetNode.html" title="ProphetNode stores state for a remote node as identified by remote_eid.">ProphetNode</a>* a = <span class="keyword">static_cast&lt;</span><a class="code" href="classdtn_1_1ProphetNode.html" title="ProphetNode stores state for a remote node as identified by remote_eid.">ProphetNode</a>*<span class="keyword">&gt;</span>(*i);
<a name="l00092"></a>00092         <a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.erase(i);
<a name="l00093"></a>00093         ProphetStore::instance()-&gt;del(a);
<a name="l00094"></a>00094         <span class="keyword">delete</span> a;
<a name="l00095"></a>00095     }
<a name="l00096"></a>00096 }
<a name="l00097"></a>00097 
<a name="l00098"></a>00098 <span class="keyword">const</span> <a class="code" href="classprophet_1_1Node.html" title="Node represents a route to another Prophet node, and as such, tracks destination...">prophet::Node</a>*
<a name="l00099"></a><a class="code" href="classdtn_1_1ProphetNodeList.html#413a090a92022c78c1cc751bdb7b447d">00099</a> <a class="code" href="classdtn_1_1ProphetNodeList.html#413a090a92022c78c1cc751bdb7b447d" title="Retrieve node from permanent store; returns NULL if not found.">ProphetNodeList::find</a>(<span class="keyword">const</span> std::string&amp; dest_id)<span class="keyword"> const</span>
<a name="l00100"></a>00100 <span class="keyword"></span>{
<a name="l00101"></a>00101     <a class="code" href="classdtn_1_1ProphetNodeList.html#06bb25a1b90b07056fe183fc33aa5a62">iterator</a> i;
<a name="l00102"></a>00102     <a class="code" href="classdtn_1_1ProphetNodeList.html" title="Maintain a one-to-one mapping of objects in memory to objects in permanent store...">ProphetNodeList</a>* me = <span class="keyword">const_cast&lt;</span><a class="code" href="classdtn_1_1ProphetNodeList.html" title="Maintain a one-to-one mapping of objects in memory to objects in permanent store...">ProphetNodeList</a>*<span class="keyword">&gt;</span>(<span class="keyword">this</span>);
<a name="l00103"></a>00103     <span class="keywordflow">if</span> (me == NULL) <span class="keywordflow">return</span> NULL;
<a name="l00104"></a>00104     <span class="keywordflow">if</span> (me-&gt;<a class="code" href="classdtn_1_1ProphetNodeList.html#413a090a92022c78c1cc751bdb7b447d" title="Retrieve node from permanent store; returns NULL if not found.">find</a>(dest_id,i))
<a name="l00105"></a>00105         <span class="keywordflow">return</span> *i;
<a name="l00106"></a>00106     <span class="keywordflow">return</span> NULL;
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 <span class="keywordtype">void</span>
<a name="l00110"></a><a class="code" href="classdtn_1_1ProphetNodeList.html#641fd92c8528bad7a7d36a17d9dd875b">00110</a> <a class="code" href="classdtn_1_1ProphetNodeList.html#641fd92c8528bad7a7d36a17d9dd875b" title="Copy list of nodes from permanent store into prophet::Table.">ProphetNodeList::clone</a>(<a class="code" href="classprophet_1_1Table.html" title="Container for Prophet nodes (routes and predictability values).">prophet::Table</a>* nodes,
<a name="l00111"></a>00111                        <span class="keyword">const</span> <a class="code" href="structprophet_1_1NodeParams.html" title="Tunable parameter struct for setting global default values for Prophet node algorithms...">prophet::NodeParams</a>* params)
<a name="l00112"></a>00112 {
<a name="l00113"></a>00113     <span class="keywordflow">if</span> (nodes == NULL || params == NULL) <span class="keywordflow">return</span>;
<a name="l00114"></a>00114 
<a name="l00115"></a>00115     std::list&lt;const prophet::Node*&gt; list(<a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.begin(),<a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.end());
<a name="l00116"></a>00116     nodes-&gt;<a class="code" href="classprophet_1_1Table.html#d771f3abdf649a941a4c8fbfbe7a0f42" title="Update Table from peer&amp;#39;s RIB.">assign</a>(list,params);
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118 
<a name="l00119"></a>00119 <span class="keywordtype">void</span>
<a name="l00120"></a><a class="code" href="classdtn_1_1ProphetNodeList.html#2dad0fc20c9645013f92585c77e17b03">00120</a> <a class="code" href="classdtn_1_1ProphetNodeList.html#2dad0fc20c9645013f92585c77e17b03" title="Clean up memory associated with this list (leaving permanent store untouched).">ProphetNodeList::clear</a>()
<a name="l00121"></a>00121 {
<a name="l00122"></a>00122     <span class="keywordflow">while</span> (!<a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.empty())
<a name="l00123"></a>00123     {
<a name="l00124"></a>00124         <span class="keyword">delete</span> <a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.front();
<a name="l00125"></a>00125         <a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.pop_front();
<a name="l00126"></a>00126     }
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 
<a name="l00129"></a>00129 <span class="keywordtype">bool</span>
<a name="l00130"></a><a class="code" href="classdtn_1_1ProphetNodeList.html#cc4e4e5ee2ffa2989824ca8db80ab108">00130</a> <a class="code" href="classdtn_1_1ProphetNodeList.html#413a090a92022c78c1cc751bdb7b447d" title="Retrieve node from permanent store; returns NULL if not found.">ProphetNodeList::find</a>(<span class="keyword">const</span> std::string&amp; dest_id, <a class="code" href="classdtn_1_1ProphetNodeList.html#06bb25a1b90b07056fe183fc33aa5a62">iterator</a>&amp; i)
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132     i = <a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.begin();
<a name="l00133"></a>00133     <span class="keywordflow">while</span> (i != <a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.end() &amp;&amp; (*i)-&gt;dest_id() &lt; dest_id)
<a name="l00134"></a>00134         i++;
<a name="l00135"></a>00135     <span class="keywordflow">return</span> (i != <a class="code" href="classdtn_1_1ProphetNodeList.html#6980210a7d6690d745dea9ed96bf2a44" title="collection of prophet::Node&amp;#39;s">list_</a>.end() &amp;&amp; (*i)-&gt;dest_id() == dest_id);
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137 
<a name="l00138"></a>00138 }; <span class="comment">// namespace dtn</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:46 2008 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.6 </small></address>
</body>
</html>