1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>main.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="main.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center>
<hr><h1>main.cc</h1><a href="a00105.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// Package : omniEvents</font>
00002 <font class="comment">// main.cc Created : 2004/08/01</font>
00003 <font class="comment">// Author : Alex Tingle.</font>
00004 <font class="comment">//</font>
00005 <font class="comment">// Copyright (C) 1998 Paul Nader, 2004 Alex Tingle.</font>
00006 <font class="comment">//</font>
00007 <font class="comment">// This file is part of the omniEvents application.</font>
00008 <font class="comment">//</font>
00009 <font class="comment">// omniEvents is free software; you can redistribute it and/or</font>
00010 <font class="comment">// modify it under the terms of the GNU Lesser General Public</font>
00011 <font class="comment">// License as published by the Free Software Foundation; either</font>
00012 <font class="comment">// version 2.1 of the License, or (at your option) any later version.</font>
00013 <font class="comment">//</font>
00014 <font class="comment">// omniEvents is distributed in the hope that it will be useful,</font>
00015 <font class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00016 <font class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00017 <font class="comment">// Lesser General Public License for more details.</font>
00018 <font class="comment">//</font>
00019 <font class="comment">// You should have received a copy of the GNU Lesser General Public</font>
00020 <font class="comment">// License along with this library; if not, write to the Free Software</font>
00021 <font class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font>
00022 <font class="comment">//</font>
00023 <font class="comment">// Description:</font>
00024 <font class="comment">// Event Services Channel Factory implementation. The factory registers</font>
00025 <font class="comment">// itself with the naming service. Clients wishing to create event</font>
00026 <font class="comment">// channels can either use the factory by resolving its name with the</font>
00027 <font class="comment">// naming service or create in-process channels.</font>
00028 <font class="comment">//</font>
00029
00030 <font class="preprocessor">#ifdef HAVE_CONFIG_H</font>
00031 <font class="preprocessor"></font><font class="preprocessor"># include "<a class="code" href="a00082.html">config.h</a>"</font>
00032 <font class="preprocessor">#endif</font>
00033 <font class="preprocessor"></font>
00034 <font class="preprocessor">#ifdef HAVE_GETOPT</font>
00035 <font class="preprocessor"></font><font class="preprocessor"># include <unistd.h></font>
00036 <font class="keyword">extern</font> <font class="keywordtype">char</font>* optarg;
00037 <font class="keyword">extern</font> <font class="keywordtype">int</font> optind;
00038 <font class="preprocessor">#else</font>
00039 <font class="preprocessor"></font><font class="preprocessor"># include "<a class="code" href="a00104.html">getopt.h</a>"</font>
00040 <font class="preprocessor">#endif</font>
00041 <font class="preprocessor"></font>
00042 <font class="preprocessor">#include "<a class="code" href="a00106.html">main.h</a>"</font>
00043 <font class="preprocessor">#include "<a class="code" href="a00111.html">omniEvents.h</a>"</font>
00044 <font class="preprocessor">#include "<a class="code" href="a00109.html">naming.h</a>"</font>
00045 <font class="preprocessor">#include "<a class="code" href="a00113.html">omniEventsLog.h</a>"</font>
00046 <font class="preprocessor">#include "<a class="code" href="a00095.html">EventChannelFactory.h</a>"</font>
00047 <font class="preprocessor">#include "<a class="code" href="a00115.html">Orb.h</a>"</font>
00048 <font class="preprocessor">#include "<a class="code" href="a00085.html">daemon.h</a>"</font>
00049
00050 <font class="preprocessor">#if defined(HAVE_SIGNAL_H) && defined(HAVE_SIGSET)</font>
00051 <font class="preprocessor"></font><font class="preprocessor"># include <signal.h></font>
00052 <font class="preprocessor"># define SIGSET(sig,func) ::sigset(sig,func)</font>
00053 <font class="preprocessor"></font><font class="preprocessor">#elif defined(HAVE_SIGNAL_H)</font>
00054 <font class="preprocessor"></font><font class="preprocessor"># include <signal.h></font>
00055 <font class="preprocessor"># define SIGSET(sig,func) ::signal(sig,func)</font>
00056 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00057 <font class="preprocessor"></font>
00058 <font class="preprocessor">#ifdef HAVE_OMNIORB4</font>
00059 <font class="preprocessor"></font><font class="preprocessor"># include <omniORB4/internal/orbOptions.h></font>
00060 <font class="preprocessor">#endif</font>
00061 <font class="preprocessor"></font>
00062 <font class="preprocessor">#include <stdio.h></font> <font class="comment">// for sprintf</font>
00063
<a name="l00064"></a><a class="code" href="a00105.html#a0">00064</a> <font class="keywordtype">int</font> <a class="code" href="a00131.html#a1">main</a>(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font>** argv)
00065 {
00066 <a class="code" href="a00044.html">OmniEvents::Daemon</a> <a class="code" href="a00138.html#a0">daemon</a>(argc,argv);
00067
00068 <font class="preprocessor">#ifdef HAVE_OMNIORB4</font>
00069 <font class="preprocessor"></font> <font class="keywordflow">try</font>
00070 {
00071 <font class="comment">// Duplicate argv & argc.</font>
00072 <font class="keywordtype">int</font> originalArgc =argc;
00073 <font class="keywordtype">char</font>** originalArgv =<font class="keyword">new</font> <font class="keywordtype">char</font>*[originalArgc];
00074 <font class="keywordflow">for</font>(<font class="keywordtype">int</font> i=0; i<originalArgc; ++i)
00075 originalArgv[i]=strdup(argv[i]);
00076
00077 <font class="comment">// Remove ORB arguments from argc & argv.</font>
00078 <font class="keywordflow">try</font> {
00079 omni::orbOptions::singleton().extractInitOptions(argc,argv);
00080 }
00081 <font class="keywordflow">catch</font>(...) {
00082 argc=originalArgc;
00083 argv=originalArgv;
00084 }
00085 <font class="preprocessor">#endif</font>
00086 <font class="preprocessor"></font>
00087 <font class="keyword">using</font> <font class="keyword">namespace </font>OmniEvents;
00088
00089 <font class="comment">//</font>
00090 <font class="comment">// Process Options</font>
00091 <font class="keyword">const</font> <font class="keywordtype">char</font>* endPointNoListen =NULL;
00092 <font class="keywordtype">int</font> port =0;
00093 <font class="keyword">const</font> <font class="keywordtype">char</font>* logDir =NULL;
00094 <font class="keyword">const</font> <font class="keywordtype">char</font>* factoryName =<font class="stringliteral">"EventChannelFactory"</font>;
00095 <font class="keywordtype">bool</font> verbose =<font class="keyword">false</font>;
00096
00097 <font class="keywordtype">int</font> c;
00098 <font class="keywordflow">while</font> ((c = <a class="code" href="a00103.html#a5">getopt</a>(argc,argv,<font class="stringliteral">"O:a:p:l:P:N:dft:vVh"</font>)) != EOF)
00099 {
00100 <font class="keywordflow">switch</font> (c)
00101 {
00102 <font class="keywordflow">case</font> <font class="charliteral">'O'</font>: <font class="keywordflow">break</font>; <font class="comment">// Helps protect us from -ORB arguments.</font>
00103
00104 <font class="comment">// Initialisation options (only useful on first run)</font>
00105 <font class="keywordflow">case</font> <font class="charliteral">'a'</font>: endPointNoListen=optarg;
00106 <font class="keywordflow">break</font>;
00107
00108 <font class="keywordflow">case</font> <font class="charliteral">'p'</font>: port=atoi(optarg);
00109 <font class="keywordflow">if</font> (port <= 0)
00110 {
00111 cerr<<<font class="stringliteral">"\nError: port must be a positive integer"</font><<endl;
00112 <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00113 }
00114 <font class="keywordflow">break</font>;
00115
00116 <font class="comment">// Other options</font>
00117 <font class="keywordflow">case</font> <font class="charliteral">'l'</font>: logDir=optarg;
00118 <font class="keywordflow">break</font>;
00119
00120 <font class="keywordflow">case</font> <font class="charliteral">'P'</font>: daemon.<a class="code" href="a00044.html#a3">pidfile</a>(optarg);
00121 <font class="keywordflow">break</font>;
00122
00123 <font class="keywordflow">case</font> <font class="charliteral">'N'</font>: factoryName=optarg;
00124 <font class="keywordflow">break</font>;
00125
00126 <font class="keywordflow">case</font> <font class="charliteral">'d'</font>: cerr<<<font class="stringliteral">"Option '-d' is deprecated. Use '-f' instead."</font><<endl;
00127 daemon.<a class="code" href="a00044.html#a4">foreground</a>(<font class="keyword">true</font>);
00128 <font class="keywordflow">break</font>;
00129
00130 <font class="keywordflow">case</font> <font class="charliteral">'f'</font>: daemon.<a class="code" href="a00044.html#a4">foreground</a>(<font class="keyword">true</font>);
00131 <font class="keywordflow">break</font>;
00132
00133 <font class="comment">// Informational options</font>
00134 <font class="keywordflow">case</font> <font class="charliteral">'t'</font>: daemon.<a class="code" href="a00044.html#a2">tracefile</a>(optarg);
00135 <font class="keywordflow">break</font>;
00136
00137 <font class="keywordflow">case</font> <font class="charliteral">'v'</font>: verbose=<font class="keyword">true</font>;
00138 <font class="keywordflow">break</font>;
00139
00140 <font class="keywordflow">case</font> <font class="charliteral">'V'</font>: <a class="code" href="a00138.html#a6">OmniEvents::version</a>();
00141 <font class="keywordflow">break</font>;
00142
00143 <font class="keywordflow">case</font> <font class="charliteral">'h'</font>:
00144 <font class="keywordflow">default</font> : <a class="code" href="a00131.html#a0">usage</a>(argc,argv);
00145 <font class="keywordflow">break</font>;
00146 }
00147 }
00148
00149 <font class="comment">//</font>
00150 <font class="comment">// Create database instance.</font>
00151 omniEventsLog logfile(logDir);
00152 PersistNode* initialState =NULL;
00153 <font class="keywordflow">if</font>(logfile.fileExists(logfile.activeFilename()))
00154 {
00155 <font class="comment">// Read library file.</font>
00156 initialState=logfile.parse();
00157 <font class="comment">// Check for incompatibilities between options and the file.</font>
00158 <font class="keywordflow">if</font>(port && port!=initialState->child(<font class="stringliteral">"ecf"</font>)->attrLong(<font class="stringliteral">"port"</font>))
00159 {
00160 cerr<<
00161 <font class="stringliteral">"Error: Option '-p "</font><<port<<<font class="stringliteral">"' conflicts with value '"</font><<
00162 initialState->child(<font class="stringliteral">"ecf"</font>)->attrLong(<font class="stringliteral">"port"</font>)<<<font class="stringliteral">"'\n stored in"</font>
00163 <font class="stringliteral">" database file '"</font><<logfile.activeFilename()<<<font class="stringliteral">"'.\n"</font>
00164 <font class="stringliteral">" Either delete the file to clear the database, or do not use the"</font>
00165 <font class="stringliteral">" '-p' option."</font><<endl;
00166 exit(1);
00167 }
00168 <font class="keywordflow">if</font>(endPointNoListen && string(endPointNoListen)!=
00169 initialState->child(<font class="stringliteral">"ecf"</font>)->attrString(<font class="stringliteral">"endPointNoListen"</font>))
00170 {
00171 cerr<<
00172 <font class="stringliteral">"Error: Option '-a "</font><<endPointNoListen<<<font class="stringliteral">"' conflicts with value '"</font><<
00173 initialState->child(<font class="stringliteral">"ecf"</font>)->attrString(<font class="stringliteral">"endPointNoListen"</font>)<<<font class="stringliteral">"'\n"</font>
00174 <font class="stringliteral">" stored in database file '"</font><<logfile.activeFilename()<<<font class="stringliteral">"'.\n"</font>
00175 <font class="stringliteral">" Either delete the file to clear the database, or do not use the"</font>
00176 <font class="stringliteral">" '-a' option."</font><<endl;
00177 exit(1);
00178 }
00179 }
00180 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(logfile.fileExists(logfile.backupFilename()))
00181 {
00182 <font class="comment">// Quit with an error.</font>
00183 cerr <<
00184 <font class="stringliteral">"Error: backup file '"</font> << logfile.backupFilename() << <font class="stringliteral">"' exists.\n"</font>
00185 <font class="stringliteral">" Rename it to '"</font> << logfile.activeFilename() << <font class="stringliteral">"'\n"</font>
00186 <font class="stringliteral">" to recover the server's state, or delete it to create a new\n"</font>
00187 <font class="stringliteral">" database file."</font> << endl;
00188 exit(1);
00189 }
00190 <font class="keywordflow">else</font>
00191 {
00192 <font class="comment">// Create initial state without a library file.</font>
00193 initialState=logfile.bootstrap(port?port:11169,endPointNoListen);
00194 }
00195 port=initialState->child(<font class="stringliteral">"ecf"</font>)->attrLong(<font class="stringliteral">"port"</font>,port);
00196 string endPoint2=initialState->child(<font class="stringliteral">"ecf"</font>)->attrString(<font class="stringliteral">"endPointNoListen"</font>);
00197
00198 <font class="comment">//</font>
00199 <font class="comment">// Daemonise</font>
00200 daemon.<a class="code" href="a00044.html#a5">daemonize</a>();
00201
00202 <font class="comment">//</font>
00203 <font class="comment">// Initialise orb & POAs.</font>
00204 <font class="preprocessor">#ifdef HAVE_OMNIORB4</font>
00205 <font class="preprocessor"></font> <font class="keywordtype">char</font> endPoint[64];
00206 sprintf(endPoint,<font class="stringliteral">"giop:::%d"</font>,port);
00207 <font class="keywordflow">if</font>(endPoint2.empty())
00208 {
00209 <font class="keyword">const</font> <font class="keywordtype">char</font>* opts[][2] ={ {<font class="stringliteral">"endPoint"</font>,endPoint}, {0,0} };
00210 Orb::inst()._orb=CORBA::ORB_init(originalArgc,originalArgv,<font class="stringliteral">"omniORB4"</font>,opts);
00211 }
00212 <font class="keywordflow">else</font>
00213 {
00214 <font class="keyword">const</font> <font class="keywordtype">char</font>* opts[][2] ={
00215 {<font class="stringliteral">"endPoint"</font>,endPoint},
00216 {<font class="stringliteral">"endPointNoListen"</font>,endPoint2.c_str()},
00217 {0,0} };
00218 Orb::inst()._orb=CORBA::ORB_init(originalArgc,originalArgv,<font class="stringliteral">"omniORB4"</font>,opts);
00219 }
00220 <font class="preprocessor">#else</font>
00221 <font class="preprocessor"></font> <a class="code" href="a00138.html#a7">insertArgs</a>(argc, argv, 1, 2);
00222 argv[1] = strdup(<font class="stringliteral">"-ORBpoa_iiop_port"</font>);
00223 argv[2] = <font class="keyword">new</font> <font class="keywordtype">char</font>[32 + 1];
00224 sprintf(argv[2], <font class="stringliteral">"%d"</font>, port);
00225 Orb::inst()._orb=CORBA::ORB_init(argc,argv);
00226 <font class="preprocessor">#endif</font>
00227 <font class="preprocessor"></font> Orb::inst().resolveInitialReferences();
00228 {
00229 PortableServer::POAManager_var pman;
00230 pman=Orb::inst()._RootPOA->the_POAManager();
00231 pman->activate();
00232 pman=Orb::inst()._omniINSPOA->the_POAManager();
00233 pman->activate();
00234 }
00235
00236 <font class="comment">//</font>
00237 <font class="comment">// If omniEvents is restarting then the omniEventsLog object</font>
00238 <font class="comment">// will take care of creating the factory and any subordinate</font>
00239 <font class="comment">// event channels, proxies, etc under it.</font>
00240 logfile.incarnateFactory(initialState);
00241 <font class="keyword">delete</font> initialState; <font class="comment">// Tidy up.</font>
00242 initialState=NULL;
00243
00244 <font class="comment">//</font>
00245 <font class="comment">// Register factory with the Naming Service.</font>
00246 <a class="code" href="a00108.html#a2">bindName2Object</a>(
00247 Orb::inst()._NameService.in(),
00248 <a class="code" href="a00108.html#a1">str2name</a>(factoryName),
00249 logfile.factory()->_this()
00250 );
00251
00252 <font class="comment">//</font>
00253 <font class="comment">// Print the factory IOR.</font>
00254 <font class="keywordflow">if</font>(verbose)
00255 {
00256 <a class="code" href="a00115.html#a2">DB</a>(1,<font class="stringliteral">"Starting omniEvents on port "</font><<port)
00257 <font class="keywordflow">if</font>(!endPoint2.empty())
00258 <a class="code" href="a00115.html#a2">DB</a>(1,<font class="stringliteral">"Alternate endPoint "</font><<endPoint2.c_str())
00259 CORBA::String_var iorstr =
00260 Orb::inst()._orb->object_to_string(logfile.factory()->_this());
00261 <a class="code" href="a00115.html#a2">DB</a>(1,iorstr.in())
00262 }
00263
00264 <font class="preprocessor">#ifdef HAVE_SIGNAL_H</font>
00265 <font class="preprocessor"></font> SIGSET(SIGINT , ::<a class="code" href="a00105.html#a1">OmniEvents_Orb_shutdown</a>);
00266 SIGSET(SIGTERM, ::<a class="code" href="a00105.html#a1">OmniEvents_Orb_shutdown</a>);
00267 <font class="preprocessor"># ifdef SIGUSR1</font>
00268 <font class="preprocessor"></font> SIGSET(SIGUSR1, ::<a class="code" href="a00105.html#a2">OmniEvents_Orb_bumpTraceLevel</a>);
00269 <font class="preprocessor"># endif</font>
00270 <font class="preprocessor"></font><font class="preprocessor"># ifdef SIGPIPE</font>
00271 <font class="preprocessor"></font> SIGSET(SIGPIPE, SIG_IGN); <font class="comment">// Ignore broken pipes</font>
00272 <font class="preprocessor"># endif</font>
00273 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00274 <font class="preprocessor"></font>
00275 daemon.<a class="code" href="a00044.html#a6">runningOk</a>();
00276
00277 <font class="comment">//</font>
00278 <font class="comment">// Start the background tasks.</font>
00279 logfile.runWorker(); <font class="comment">// Logfile's worker thread.</font>
00280 Orb::inst().run(); <font class="comment">// Use the main thread to collect orphaned responses.</font>
00281
00282 <a class="code" href="a00115.html#a2">DB</a>(1,<font class="stringliteral">"Shutdown requested."</font>)
00283 Orb::inst()._orb->shutdown(1); <font class="comment">// Synchronous shutdown</font>
00284 Orb::inst()._orb->destroy(); <font class="comment">// clean up</font>
00285
00286 <font class="keywordflow">return</font> 0; <font class="comment">// Delete any pidfile & exit.</font>
00287
00288 <font class="preprocessor">#ifdef HAVE_OMNIORB4</font>
00289 <font class="preprocessor"></font> }
00290 <font class="keywordflow">catch</font> (CORBA::SystemException& ex) {
00291 <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"System exception: "</font><<ex._name()<<<font class="stringliteral">" ("</font><<<a class="code" href="a00115.html#a3">NP_MINORSTRING</a>(ex)<<<font class="stringliteral">")"</font>)
00292 }
00293 <font class="keywordflow">catch</font> (CORBA::Exception& ex) {
00294 <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"CORBA exception: "</font><<ex._name())
00295 }
00296 <font class="keywordflow">return</font> 1;
00297 <font class="preprocessor">#endif</font>
00298 <font class="preprocessor"></font>} <font class="comment">// end main()</font>
00299
00300
00301 <font class="comment">//</font>
00302 <font class="comment">// Signal handlers.</font>
00303 <font class="comment">//</font>
00304
00305 <font class="keyword">extern</font> <font class="stringliteral">"C"</font>
00306 {
<a name="l00307"></a><a class="code" href="a00105.html#a1">00307</a> <font class="keywordtype">void</font> <a class="code" href="a00105.html#a1">OmniEvents_Orb_shutdown</a>(<font class="keywordtype">int</font> signum)
00308 {
00309 <a class="code" href="a00059.html#d0">OmniEvents::Orb::inst</a>().shutdown(signum);
00310 }
00311
<a name="l00312"></a><a class="code" href="a00105.html#a2">00312</a> <font class="keywordtype">void</font> <a class="code" href="a00105.html#a2">OmniEvents_Orb_bumpTraceLevel</a>(<font class="keywordtype">int</font> signum)
00313 {
00314 omniORB::traceLevel=(omniORB::traceLevel+5)%45;
00315 <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"TRACE LEVEL BUMPED TO "</font><<omniORB::traceLevel<<<font class="stringliteral">" BY SIGNAL "</font><<signum)
00316 }
00317 }
</pre></div><hr><address align="right"><small>Generated on Fri Nov 19 17:42:20 2004 for OmniEvents by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>
|