Sophie

Sophie

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

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: dtnd.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>dtnd.cc</h1><a href="dtnd_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 &lt;errno.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;oasys/debug/Log.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;oasys/io/NetUtils.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;oasys/tclcmd/ConsoleCommand.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;oasys/tclcmd/TclCommand.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;oasys/thread/Timer.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;oasys/util/App.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;oasys/util/Getopt.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;oasys/util/StringBuffer.h&gt;</span>
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="APIServer_8h.html">applib/APIServer.h</a>"</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="TestCommand_8h.html">cmd/TestCommand.h</a>"</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include "<a class="code" href="DTNServer_8h.html">servlib/DTNServer.h</a>"</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include "<a class="code" href="DTNStorageConfig_8h.html">storage/DTNStorageConfig.h</a>"</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include "<a class="code" href="BundleDaemon_8h.html">bundling/BundleDaemon.h</a>"</span>
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="keyword">extern</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="dtnd_8cc.html#ae46a12fba1b20fe0278beb099ae28ee">dtn_version</a>;
<a name="l00041"></a>00041 
<a name="l00045"></a>00045 <span class="keyword">namespace </span>dtn {
<a name="l00046"></a>00046 
<a name="l00050"></a><a class="code" href="classdtn_1_1DTND.html">00050</a> <span class="keyword">class </span><a class="code" href="classdtn_1_1DTND.html" title="Thin class that implements the daemon itself.">DTND</a> : <span class="keyword">public</span> oasys::App {
<a name="l00051"></a>00051 <span class="keyword">public</span>:
<a name="l00052"></a>00052     <a class="code" href="classdtn_1_1DTND.html#b486fe7e513a6d3a070426bc6ff53b04">DTND</a>();
<a name="l00053"></a>00053     <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1DTND.html#0d2d5f40e1d7528106de58d6aeb32c23">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[]);
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 <span class="keyword">protected</span>:
<a name="l00056"></a><a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">00056</a>     <a class="code" href="classdtn_1_1TestCommand.html" title="CommandModule for the &amp;quot;test&amp;quot; command.">TestCommand</a>*          <a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">testcmd_</a>;
<a name="l00057"></a><a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">00057</a>     oasys::ConsoleCommand* <a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>;
<a name="l00058"></a><a class="code" href="classdtn_1_1DTND.html#bd94035d07586caa48da4a56d663af4c">00058</a>     <a class="code" href="classdtn_1_1DTNStorageConfig.html" title="Subclass of the basic oasys storage config to add dtn-specific configuration variables...">DTNStorageConfig</a>      <a class="code" href="classdtn_1_1DTND.html#bd94035d07586caa48da4a56d663af4c">storage_config_</a>;
<a name="l00059"></a>00059     
<a name="l00060"></a>00060     <span class="comment">// virtual from oasys::App</span>
<a name="l00061"></a>00061     <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1DTND.html#6903b364b2c8690a74fc2bde16ba25c9">fill_options</a>();
<a name="l00062"></a>00062     
<a name="l00063"></a>00063     <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1DTND.html#77dbb35cd956983967fda8fb2ce180c4">init_testcmd</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[]);
<a name="l00064"></a>00064     <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1DTND.html#fdd902a6d8cadfad21a2f126431c02bd">run_console</a>();
<a name="l00065"></a>00065 };
<a name="l00066"></a>00066 
<a name="l00067"></a>00067 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00068"></a><a class="code" href="classdtn_1_1DTND.html#b486fe7e513a6d3a070426bc6ff53b04">00068</a> <a class="code" href="classdtn_1_1DTND.html#b486fe7e513a6d3a070426bc6ff53b04">DTND::DTND</a>()
<a name="l00069"></a>00069     : App(<span class="stringliteral">"DTND"</span>, <span class="stringliteral">"dtnd"</span>, <a class="code" href="dtnd_8cc.html#ae46a12fba1b20fe0278beb099ae28ee">dtn_version</a>),
<a name="l00070"></a>00070       testcmd_(NULL),
<a name="l00071"></a>00071       consolecmd_(NULL),
<a name="l00072"></a>00072       storage_config_(<span class="stringliteral">"storage"</span>,                        <span class="comment">// command name</span>
<a name="l00073"></a>00073                       <span class="stringliteral">"berkeleydb"</span>,                     <span class="comment">// storage type</span>
<a name="l00074"></a>00074                       <span class="stringliteral">"DTN"</span>,                            <span class="comment">// DB name</span>
<a name="l00075"></a>00075                       <a class="code" href="dtn-config_8h.html#c76b2b56e37c056971de289cac9841fa">INSTALL_LOCALSTATEDIR</a> <span class="stringliteral">"/dtn/db"</span>)  <span class="comment">// DB directory</span>
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077     <span class="comment">// override default logging settings</span>
<a name="l00078"></a>00078     loglevel_ = oasys::LOG_NOTICE;
<a name="l00079"></a>00079     debugpath_ = <span class="stringliteral">"~/.dtndebug"</span>;
<a name="l00080"></a>00080     
<a name="l00081"></a>00081     <span class="comment">// override defaults from oasys storage config</span>
<a name="l00082"></a>00082     <a class="code" href="classdtn_1_1DTND.html#bd94035d07586caa48da4a56d663af4c">storage_config_</a>.db_max_tx_ = 1000;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084     <a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">testcmd_</a>    = <span class="keyword">new</span> <a class="code" href="classdtn_1_1TestCommand.html" title="CommandModule for the &amp;quot;test&amp;quot; command.">TestCommand</a>();
<a name="l00085"></a>00085     <a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a> = <span class="keyword">new</span> oasys::ConsoleCommand(<span class="stringliteral">"dtn% "</span>);
<a name="l00086"></a>00086 }
<a name="l00087"></a>00087 
<a name="l00088"></a>00088 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00089"></a>00089 <span class="keywordtype">void</span>
<a name="l00090"></a><a class="code" href="classdtn_1_1DTND.html#6903b364b2c8690a74fc2bde16ba25c9">00090</a> <a class="code" href="classdtn_1_1DTND.html#6903b364b2c8690a74fc2bde16ba25c9">DTND::fill_options</a>()
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092     fill_default_options(DAEMONIZE_OPT | CONF_FILE_OPT);
<a name="l00093"></a>00093     
<a name="l00094"></a>00094     opts_.addopt(
<a name="l00095"></a>00095         <span class="keyword">new</span> oasys::BoolOpt(<span class="charliteral">'t'</span>, <span class="stringliteral">"tidy"</span>, &amp;<a class="code" href="classdtn_1_1DTND.html#bd94035d07586caa48da4a56d663af4c">storage_config_</a>.tidy_,
<a name="l00096"></a>00096                            <span class="stringliteral">"clear database and initialize tables on startup"</span>));
<a name="l00097"></a>00097 
<a name="l00098"></a>00098     opts_.addopt(
<a name="l00099"></a>00099         <span class="keyword">new</span> oasys::BoolOpt(0, <span class="stringliteral">"init-db"</span>, &amp;<a class="code" href="classdtn_1_1DTND.html#bd94035d07586caa48da4a56d663af4c">storage_config_</a>.init_,
<a name="l00100"></a>00100                            <span class="stringliteral">"initialize database on startup"</span>));
<a name="l00101"></a>00101 
<a name="l00102"></a>00102     opts_.addopt(
<a name="l00103"></a>00103         <span class="keyword">new</span> oasys::InAddrOpt(0, <span class="stringliteral">"console-addr"</span>, &amp;<a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;addr_, <span class="stringliteral">"&lt;addr&gt;"</span>,
<a name="l00104"></a>00104                              <span class="stringliteral">"set the console listening addr (default off)"</span>));
<a name="l00105"></a>00105     
<a name="l00106"></a>00106     opts_.addopt(
<a name="l00107"></a>00107         <span class="keyword">new</span> oasys::UInt16Opt(0, <span class="stringliteral">"console-port"</span>, &amp;<a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;port_, <span class="stringliteral">"&lt;port&gt;"</span>,
<a name="l00108"></a>00108                              <span class="stringliteral">"set the console listening port (default off)"</span>));
<a name="l00109"></a>00109     
<a name="l00110"></a>00110     opts_.addopt(
<a name="l00111"></a>00111         <span class="keyword">new</span> oasys::IntOpt(<span class="charliteral">'i'</span>, 0, &amp;<a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">testcmd_</a>-&gt;<a class="code" href="classdtn_1_1TestCommand.html#10c96b8c63976960caa21c676be044bc" title="sets the test node id">id_</a>, <span class="stringliteral">"&lt;id&gt;"</span>,
<a name="l00112"></a>00112                           <span class="stringliteral">"set the test id"</span>));
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114 
<a name="l00115"></a>00115 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00116"></a>00116 <span class="keywordtype">void</span>
<a name="l00117"></a><a class="code" href="classdtn_1_1DTND.html#77dbb35cd956983967fda8fb2ce180c4">00117</a> <a class="code" href="classdtn_1_1DTND.html#77dbb35cd956983967fda8fb2ce180c4">DTND::init_testcmd</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])
<a name="l00118"></a>00118 {
<a name="l00119"></a>00119     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; argc; ++i) {
<a name="l00120"></a>00120         <a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">testcmd_</a>-&gt;<a class="code" href="classdtn_1_1TestCommand.html#73146361b043bf8f7a8c9645ee7a9332" title="&amp;quot;list&amp;quot; of space-separated args">argv_</a>.append(argv[i]);
<a name="l00121"></a>00121         <a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">testcmd_</a>-&gt;<a class="code" href="classdtn_1_1TestCommand.html#73146361b043bf8f7a8c9645ee7a9332" title="&amp;quot;list&amp;quot; of space-separated args">argv_</a>.append(<span class="stringliteral">" "</span>);
<a name="l00122"></a>00122     }
<a name="l00123"></a>00123 
<a name="l00124"></a>00124     <a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">testcmd_</a>-&gt;<a class="code" href="classdtn_1_1TestCommand.html#de12e12e9844cab954b0e6848b9fe280" title="Binding function.">bind_vars</a>();
<a name="l00125"></a>00125     oasys::TclCommandInterp::instance()-&gt;reg(<a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">testcmd_</a>);
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127 
<a name="l00128"></a>00128 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00129"></a>00129 <span class="keywordtype">void</span>
<a name="l00130"></a><a class="code" href="classdtn_1_1DTND.html#fdd902a6d8cadfad21a2f126431c02bd">00130</a> <a class="code" href="classdtn_1_1DTND.html#fdd902a6d8cadfad21a2f126431c02bd">DTND::run_console</a>()
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132     <span class="comment">// launch the console server</span>
<a name="l00133"></a>00133     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;port_ != 0) {
<a name="l00134"></a>00134         log_info_p(<span class="stringliteral">"/dtnd"</span>, <span class="stringliteral">"starting console on %s:%d"</span>,
<a name="l00135"></a>00135                    intoa(<a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;addr_), <a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;port_);
<a name="l00136"></a>00136         
<a name="l00137"></a>00137         oasys::TclCommandInterp::instance()-&gt;
<a name="l00138"></a>00138             command_server(<a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;prompt_.c_str(),
<a name="l00139"></a>00139                            <a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;addr_, <a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;port_);
<a name="l00140"></a>00140     }
<a name="l00141"></a>00141     
<a name="l00142"></a>00142     <span class="keywordflow">if</span> (daemonize_ || (<a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;stdio_ == <span class="keyword">false</span>)) {
<a name="l00143"></a>00143         oasys::TclCommandInterp::instance()-&gt;event_loop();
<a name="l00144"></a>00144     } <span class="keywordflow">else</span> {
<a name="l00145"></a>00145         oasys::TclCommandInterp::instance()-&gt;
<a name="l00146"></a>00146             command_loop(<a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>-&gt;prompt_.c_str());
<a name="l00147"></a>00147     }
<a name="l00148"></a>00148 }
<a name="l00149"></a>00149 
<a name="l00150"></a>00150 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00151"></a>00151 <span class="keywordtype">int</span>
<a name="l00152"></a><a class="code" href="classdtn_1_1DTND.html#0d2d5f40e1d7528106de58d6aeb32c23">00152</a> <a class="code" href="classdtn_1_1DTND.html#0d2d5f40e1d7528106de58d6aeb32c23">DTND::main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])
<a name="l00153"></a>00153 {
<a name="l00154"></a>00154     init_app(argc, argv);
<a name="l00155"></a>00155 
<a name="l00156"></a>00156     log_notice_p(<span class="stringliteral">"/dtnd"</span>, <span class="stringliteral">"DTN daemon starting up... (pid %d)"</span>, getpid());
<a name="l00157"></a>00157 
<a name="l00158"></a>00158     <span class="keywordflow">if</span> (oasys::TclCommandInterp::init(argv[0], <span class="stringliteral">"/dtn/tclcmd"</span>) != 0)
<a name="l00159"></a>00159     {
<a name="l00160"></a>00160         log_crit_p(<span class="stringliteral">"/dtnd"</span>, <span class="stringliteral">"Can't init TCL"</span>);
<a name="l00161"></a>00161         notify_and_exit(1);
<a name="l00162"></a>00162     }
<a name="l00163"></a>00163 
<a name="l00164"></a>00164     <span class="comment">// stop thread creation b/c of initialization dependencies</span>
<a name="l00165"></a>00165     oasys::Thread::activate_start_barrier();
<a name="l00166"></a>00166 
<a name="l00167"></a>00167     <a class="code" href="classdtn_1_1DTNServer.html">DTNServer</a>* dtnserver = <span class="keyword">new</span> <a class="code" href="classdtn_1_1DTNServer.html">DTNServer</a>(<span class="stringliteral">"/dtnd"</span>, &amp;<a class="code" href="classdtn_1_1DTND.html#bd94035d07586caa48da4a56d663af4c">storage_config_</a>);
<a name="l00168"></a>00168     <a class="code" href="classdtn_1_1APIServer.html" title="Class that implements the main server side handling of the DTN application IPC.">APIServer</a>* apiserver = <span class="keyword">new</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>();
<a name="l00169"></a>00169 
<a name="l00170"></a>00170     dtnserver-&gt;<a class="code" href="classdtn_1_1DTNServer.html#25004a24eda88d80df382931bcae1aaa">init</a>();
<a name="l00171"></a>00171 
<a name="l00172"></a>00172     oasys::TclCommandInterp::instance()-&gt;reg(<a class="code" href="classdtn_1_1DTND.html#764522b2c6bf1baccc0ead6442b1a27a">consolecmd_</a>);
<a name="l00173"></a>00173     <a class="code" href="classdtn_1_1DTND.html#77dbb35cd956983967fda8fb2ce180c4">init_testcmd</a>(argc, argv);
<a name="l00174"></a>00174 
<a name="l00175"></a>00175     <span class="keywordflow">if</span> (! dtnserver-&gt;<a class="code" href="classdtn_1_1DTNServer.html#93f18438079f9ddbe2afdc994d8bd25f" title="Parse the conf file.">parse_conf_file</a>(conf_file_, conf_file_set_)) {
<a name="l00176"></a>00176         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<span class="stringliteral">"/dtnd"</span>, <span class="stringliteral">"error in configuration file, exiting..."</span>);
<a name="l00177"></a>00177         notify_and_exit(1);
<a name="l00178"></a>00178     }
<a name="l00179"></a>00179 
<a name="l00180"></a>00180     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1DTND.html#bd94035d07586caa48da4a56d663af4c">storage_config_</a>.init_)
<a name="l00181"></a>00181     {
<a name="l00182"></a>00182         log_notice_p(<span class="stringliteral">"/dtnd"</span>, <span class="stringliteral">"initializing persistent data store"</span>);
<a name="l00183"></a>00183     }
<a name="l00184"></a>00184 
<a name="l00185"></a>00185     <span class="keywordflow">if</span> (! dtnserver-&gt;<a class="code" href="classdtn_1_1DTNServer.html#90e55dea605a029a958bb9d53a4e7b52" title="Initialize the datastore.">init_datastore</a>()) {
<a name="l00186"></a>00186         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<span class="stringliteral">"/dtnd"</span>, <span class="stringliteral">"error initializing data store, exiting..."</span>);
<a name="l00187"></a>00187         notify_and_exit(1);
<a name="l00188"></a>00188     }
<a name="l00189"></a>00189     
<a name="l00190"></a>00190     <span class="comment">// If we're running as --init-db, make an empty database and exit</span>
<a name="l00191"></a>00191     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1DTND.html#bd94035d07586caa48da4a56d663af4c">storage_config_</a>.init_ &amp;&amp; !<a class="code" href="classdtn_1_1DTND.html#bd94035d07586caa48da4a56d663af4c">storage_config_</a>.tidy_)
<a name="l00192"></a>00192     {
<a name="l00193"></a>00193         dtnserver-&gt;<a class="code" href="classdtn_1_1DTNServer.html#6c43a61f37a218e5e105258a6835372e" title="Close and sync the data store.">close_datastore</a>();
<a name="l00194"></a>00194         log_info_p(<span class="stringliteral">"/dtnd"</span>, <span class="stringliteral">"database initialization complete."</span>);
<a name="l00195"></a>00195         notify_and_exit(0);
<a name="l00196"></a>00196     }
<a name="l00197"></a>00197     
<a name="l00198"></a>00198     <span class="keywordflow">if</span> (BundleDaemon::instance()-&gt;local_eid().equals(<a class="code" href="classdtn_1_1EndpointID.html#31bd1844cae5e71cc2393a139c9bec4c" title="Return the special endpoint id used for the null endpoint, namely &amp;quot;dtn:none&amp;quot;...">EndpointID::NULL_EID</a>()))
<a name="l00199"></a>00199     {
<a name="l00200"></a>00200         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<span class="stringliteral">"/dtnd"</span>, <span class="stringliteral">"no local eid specified; use the 'route local_eid' command"</span>);
<a name="l00201"></a>00201         notify_and_exit(1);
<a name="l00202"></a>00202     }
<a name="l00203"></a>00203 
<a name="l00204"></a>00204     <span class="comment">// if we've daemonized, now is the time to notify our parent</span>
<a name="l00205"></a>00205     <span class="comment">// process that we've successfully initialized</span>
<a name="l00206"></a>00206     <span class="keywordflow">if</span> (daemonize_) {
<a name="l00207"></a>00207         daemonizer_.notify_parent(0);
<a name="l00208"></a>00208     }
<a name="l00209"></a>00209     
<a name="l00210"></a>00210     dtnserver-&gt;<a class="code" href="classdtn_1_1DTNServer.html#91378d308617a0ec3b6688e445bdd85d" title="Start DTN daemon.">start</a>();
<a name="l00211"></a>00211     <span class="keywordflow">if</span> (apiserver-&gt;<a class="code" href="classdtn_1_1APIServer.html#9da09c603ffa6a92b523633dec148a36">enabled</a>()) {
<a name="l00212"></a>00212         apiserver-&gt;bind_listen_start(apiserver-&gt;<a class="code" href="classdtn_1_1APIServer.html#8057e873307e2c0fa3bfcda6b9a1146d">local_addr</a>(), 
<a name="l00213"></a>00213                                      apiserver-&gt;<a class="code" href="classdtn_1_1APIServer.html#2c377b4c3ea52f788d41fdf905591882">local_port</a>());
<a name="l00214"></a>00214     }
<a name="l00215"></a>00215     oasys::Thread::release_start_barrier(); <span class="comment">// run blocked threads</span>
<a name="l00216"></a>00216 
<a name="l00217"></a>00217     <span class="comment">// if the test script specified something to run for the test,</span>
<a name="l00218"></a>00218     <span class="comment">// then execute it now</span>
<a name="l00219"></a>00219     <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">testcmd_</a>-&gt;<a class="code" href="classdtn_1_1TestCommand.html#b409b7ec6a35ff40edd57ecccab93431" title="tcl script to run at init">initscript_</a>.length() != 0) {
<a name="l00220"></a>00220         oasys::TclCommandInterp::instance()-&gt;
<a name="l00221"></a>00221             exec_command(<a class="code" href="classdtn_1_1DTND.html#057a3e959965ce7f63bfe61d268f28bb">testcmd_</a>-&gt;<a class="code" href="classdtn_1_1TestCommand.html#b409b7ec6a35ff40edd57ecccab93431" title="tcl script to run at init">initscript_</a>.c_str());
<a name="l00222"></a>00222     }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224     <span class="comment">// allow startup messages to be flushed to standard-out before</span>
<a name="l00225"></a>00225     <span class="comment">// the prompt is displayed</span>
<a name="l00226"></a>00226     oasys::Thread::yield();
<a name="l00227"></a>00227     usleep(500000);
<a name="l00228"></a>00228     
<a name="l00229"></a>00229     <a class="code" href="classdtn_1_1DTND.html#fdd902a6d8cadfad21a2f126431c02bd">run_console</a>();
<a name="l00230"></a>00230 
<a name="l00231"></a>00231     log_notice_p(<span class="stringliteral">"/dtnd"</span>, <span class="stringliteral">"command loop exited... shutting down daemon"</span>);
<a name="l00232"></a>00232 
<a name="l00233"></a>00233     apiserver-&gt;stop();
<a name="l00234"></a>00234     
<a name="l00235"></a>00235     oasys::TclCommandInterp::shutdown();
<a name="l00236"></a>00236     dtnserver-&gt;<a class="code" href="classdtn_1_1DTNServer.html#99decfe3bc07be267f449c230ab34174" title="Shut down the server.">shutdown</a>();
<a name="l00237"></a>00237     
<a name="l00238"></a>00238     <span class="comment">// close out servers</span>
<a name="l00239"></a>00239     <span class="keyword">delete</span> dtnserver;
<a name="l00240"></a>00240     <span class="comment">// don't delete apiserver; keep it around so slow APIClients can finish</span>
<a name="l00241"></a>00241     
<a name="l00242"></a>00242     <span class="comment">// give other threads (like logging) a moment to catch up before exit</span>
<a name="l00243"></a>00243     oasys::Thread::yield();
<a name="l00244"></a>00244     sleep(1);
<a name="l00245"></a>00245     
<a name="l00246"></a>00246     <span class="comment">// kill logging</span>
<a name="l00247"></a>00247     oasys::Log::shutdown();
<a name="l00248"></a>00248     
<a name="l00249"></a>00249     <span class="keywordflow">return</span> 0;
<a name="l00250"></a>00250 }
<a name="l00251"></a>00251 
<a name="l00252"></a>00252 } <span class="comment">// namespace dtn</span>
<a name="l00253"></a>00253 
<a name="l00254"></a>00254 <span class="keywordtype">int</span>
<a name="l00255"></a><a class="code" href="dtnd_8cc.html#0ddf1224851353fc92bfbff6f499fa97">00255</a> <a class="code" href="dtncat_8c.html#3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])
<a name="l00256"></a>00256 {
<a name="l00257"></a>00257     <a class="code" href="classdtn_1_1DTND.html" title="Thin class that implements the daemon itself.">dtn::DTND</a> dtnd;
<a name="l00258"></a>00258     dtnd.<a class="code" href="classdtn_1_1DTND.html#0d2d5f40e1d7528106de58d6aeb32c23">main</a>(argc, argv);
<a name="l00259"></a>00259 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:55 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>