File: a00172.html

package info (click to toggle)
omnievents 2.6.1-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,228 kB
  • ctags: 2,538
  • sloc: cpp: 7,346; sh: 2,568; python: 2,171; xml: 2,057; java: 1,407; makefile: 304; ansic: 9
file content (726 lines) | stat: -rw-r--r-- 52,781 bytes parent folder | download
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
<!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>omniEventsLog.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> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>omniEventsLog.cc</h1><a href="a00112.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// -*- Mode: C++; -*-</font>
00002 <font class="comment">//                            Package   : omniEvents</font>
00003 <font class="comment">//  omniEventsLog.cc          Created   : 1/10/99</font>
00004 <font class="comment">//                            Author    : Paul Nader (pwn)</font>
00005 <font class="comment">//</font>
00006 <font class="comment">//    Copyright (C) 1998 Paul Nader.</font>
00007 <font class="comment">//</font>
00008 <font class="comment">//    This file is part of the omniEvents application.</font>
00009 <font class="comment">//</font>
00010 <font class="comment">//    omniEvents is free software; you can redistribute it and/or</font>
00011 <font class="comment">//    modify it under the terms of the GNU Lesser General Public</font>
00012 <font class="comment">//    License as published by the Free Software Foundation; either</font>
00013 <font class="comment">//    version 2.1 of the License, or (at your option) any later version.</font>
00014 <font class="comment">//</font>
00015 <font class="comment">//    omniEvents is distributed in the hope that it will be useful,</font>
00016 <font class="comment">//    but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment">//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</font>
00018 <font class="comment">//    Lesser General Public License for more details.</font>
00019 <font class="comment">//</font>
00020 <font class="comment">//    You should have received a copy of the GNU Lesser General Public</font>
00021 <font class="comment">//    License along with this library; if not, write to the Free Software</font>
00022 <font class="comment">//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</font>
00023 <font class="comment">//</font>
00024 <font class="comment">// Description:</font>
00025 <font class="comment">//      </font>
00026 
00027 <font class="comment">/*</font>
00028 <font class="comment">  $Log: omniEventsLog.cc,v $</font>
00029 <font class="comment">  Revision 1.20.2.1  2004/11/16 21:46:11  alextingle</font>
00030 <font class="comment">  Made several methods virtual to allow users of libomniEvents to override</font>
00031 <font class="comment">  the default persistency behaviour. (Dirk O. Siebnich)</font>
00032 <font class="comment"></font>
00033 <font class="comment">  Revision 1.20  2004/09/25 23:12:28  alextingle</font>
00034 <font class="comment">  New method: Orb::reportObjectFailure() - flags unexpected failures at a higher</font>
00035 <font class="comment">  priority than normal non-fatal exceptions.</font>
00036 <font class="comment"></font>
00037 <font class="comment">  New macro: NP_MINORSTRING() - a safe interface to</font>
00038 <font class="comment">  CORBA::SystemException::NP_minorString() that returns "??" when there is no</font>
00039 <font class="comment">  mapping for the exception's minor code.</font>
00040 <font class="comment"></font>
00041 <font class="comment">  Revision 1.19  2004/07/26 16:27:08  alextingle</font>
00042 <font class="comment">  Support for NT service on windows: main() moved into daemon.cc.</font>
00043 <font class="comment">  New (laxer) start up syntax. Port is now set with -p (not -s). There is no</font>
00044 <font class="comment">  special cold start mode.</font>
00045 <font class="comment">  More flexible naming service name option -N. (No more -K option).</font>
00046 <font class="comment"></font>
00047 <font class="comment">  Revision 1.18  2004/07/16 08:45:46  alextingle</font>
00048 <font class="comment">  New macro: IF_OMNIORB4(). Fixes warnings on AIX xlC_r.</font>
00049 <font class="comment"></font>
00050 <font class="comment">  Revision 1.17  2004/07/15 16:18:45  alextingle</font>
00051 <font class="comment">  Fixed casting warnings on Tru64.</font>
00052 <font class="comment"></font>
00053 <font class="comment">  Revision 1.16  2004/07/06 12:46:34  alextingle</font>
00054 <font class="comment">  Moved default macros into defaults.h</font>
00055 <font class="comment"></font>
00056 <font class="comment">  Revision 1.15  2004/07/06 10:59:39  alextingle</font>
00057 <font class="comment">  Tightened privileges on created files.</font>
00058 <font class="comment"></font>
00059 <font class="comment">  Revision 1.14  2004/07/05 13:52:37  alextingle</font>
00060 <font class="comment">  Improved iostream portability (again).</font>
00061 <font class="comment"></font>
00062 <font class="comment">  Revision 1.13  2004/07/02 15:20:39  alextingle</font>
00063 <font class="comment">  Added daemonization, syslog &amp; pidfile support on Unix.</font>
00064 <font class="comment">  Corrected trace levels for consistency with omniORB.</font>
00065 <font class="comment"></font>
00066 <font class="comment">  Revision 1.12  2004/05/14 14:44:48  alextingle</font>
00067 <font class="comment">  Explicitly cast 'flags' to type ios::openmode for platforms where this type is an enum.</font>
00068 <font class="comment"></font>
00069 <font class="comment">  Revision 1.11  2004/04/20 20:23:03  alextingle</font>
00070 <font class="comment">  Cross-platform friendly use of std:ifstream.</font>
00071 <font class="comment"></font>
00072 <font class="comment">  Revision 1.10  2004/04/20 17:16:16  alextingle</font>
00073 <font class="comment">  Corrected openOfstream() arg name/comments.</font>
00074 <font class="comment"></font>
00075 <font class="comment">  Revision 1.9  2004/03/30 17:31:00  alextingle</font>
00076 <font class="comment">  Added exception handlers to thread methods.</font>
00077 <font class="comment"></font>
00078 <font class="comment">  Revision 1.8  2004/03/28 01:03:58  alextingle</font>
00079 <font class="comment">  Refactored class omniEventsLog to allow for more EventChannelFactory parameters.\nNew omniEvents params: -v, -a (alternate endPoint).</font>
00080 <font class="comment"></font>
00081 <font class="comment">  Revision 1.7  2004/03/23 13:29:34  alextingle</font>
00082 <font class="comment">  Fixed bizarre compilation errors on Sun's CC.</font>
00083 <font class="comment"></font>
00084 <font class="comment">  Revision 1.6  2004/01/11 16:57:26  alextingle</font>
00085 <font class="comment">  New persistancy log file format, implemented by PersistNode.h/cc. The new format enables new nodes to be added and old ones erased by appending a single line to the file, rather than by re-persisting the whole application. This is much more efficient when lots of proxies are being created all at once. It's also a much simpler solution, with far fewer lines of code.</font>
00086 <font class="comment"></font>
00087 <font class="comment">  Revision 1.5  2003/12/21 16:17:19  alextingle</font>
00088 <font class="comment">  Added OmniEvents namespace. Now uses POA implementations.</font>
00089 <font class="comment"></font>
00090 <font class="comment">  Revision 1.4  2003/11/14 14:05:21  alextingle</font>
00091 <font class="comment">  New output() members functions. Eliminates the need for friend ostream</font>
00092 <font class="comment">  functions that are problematic on earlier versions of Microsoft</font>
00093 <font class="comment">  VisualC++. Improved helpfulness of usage and error messages.</font>
00094 <font class="comment"></font>
00095 <font class="comment">  Revision 1.3  2003/11/03 22:41:00  alextingle</font>
00096 <font class="comment">  Oops! Removed excess log comments.</font>
00097 <font class="comment"></font>
00098 <font class="comment">  Revision 1.2  2003/11/03 22:38:39  alextingle</font>
00099 <font class="comment">  Removed many platform specific switches, alas many remain. Now uses</font>
00100 <font class="comment">    autoconf,config.h wherever possible.</font>
00101 <font class="comment">  Removed local definition of strdup() - omniEvents.cc manages to get</font>
00102 <font class="comment">    along without it, so it can't be needed here.</font>
00103 <font class="comment">  Moved convoluted code to obtain hostname into its own header file:</font>
00104 <font class="comment">    gethostname.h</font>
00105 <font class="comment">  Moved code that constructs logfile names into its own private method,</font>
00106 <font class="comment">    omniEventsLog::initializeFileNames()</font>
00107 <font class="comment">  Added explicit initialisation for all `class omniEventsLog' members.</font>
00108 <font class="comment">  Moved code that opens file stream into its own private method,</font>
00109 <font class="comment">    omniEventsLog::openOfstream()</font>
00110 <font class="comment"></font>
00111 <font class="comment">  Revision 1.1.1.1  2002/09/25 19:00:35  shamus13</font>
00112 <font class="comment">  Import of OmniEvents source tree from release 2.1.1</font>
00113 <font class="comment"></font>
00114 <font class="comment">  Revision 1.8  2000/09/26 09:20:26  naderp</font>
00115 <font class="comment">  STL Default parameters rework.</font>
00116 <font class="comment">  Configurable checkpoint period.</font>
00117 <font class="comment"></font>
00118 <font class="comment">  Revision 1.7  2000/09/04 05:05:22  naderp</font>
00119 <font class="comment">  Fixed problem with triggering multiple checkpoints.</font>
00120 <font class="comment"></font>
00121 <font class="comment">  Revision 1.6  2000/08/30 04:38:24  naderp</font>
00122 <font class="comment">  Fix to prevent recorder thread from terminating.</font>
00123 <font class="comment"></font>
00124 <font class="comment">  Revision 1.5  2000/08/30 00:57:29  naderp</font>
00125 <font class="comment">  Fixed broken persist method exiting after first checkpoint.</font>
00126 <font class="comment"></font>
00127 <font class="comment">  Revision 1.4  2000/03/06 13:19:58  naderp</font>
00128 <font class="comment">  Moved port from global to factory persistency data.</font>
00129 <font class="comment"></font>
00130 <font class="comment">  Revision 1.3  2000/03/06 04:15:09  naderp</font>
00131 <font class="comment">  Removed internal dependency between factory and Naming Service.</font>
00132 <font class="comment"></font>
00133 <font class="comment">  Revision 1.2  2000/03/02 04:20:09  naderp</font>
00134 <font class="comment">  Initialising factory refernce in init().</font>
00135 <font class="comment"></font>
00136 <font class="comment">  Revision 1.1  2000/03/02 02:00:25  naderp</font>
00137 <font class="comment">  Re-open active logfile during re-start.</font>
00138 <font class="comment"></font>
00139 <font class="comment">  Revision 1.0  1999/11/01 17:04:08  naderp</font>
00140 <font class="comment">  Initial revision</font>
00141 <font class="comment"></font>
00142 <font class="comment">*/</font>
00143 
00144 <font class="preprocessor">#include "<a class="code" href="a00113.html">omniEventsLog.h</a>"</font>
00145 
00146 <font class="preprocessor">#ifdef HAVE_CONFIG_H</font>
00147 <font class="preprocessor"></font><font class="preprocessor">#  include "<a class="code" href="a00082.html">config.h</a>"</font>
00148 <font class="preprocessor">#endif</font>
00149 <font class="preprocessor"></font>
00150 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00151 
00152 <font class="preprocessor">#ifdef HAVE_STDLIB_H</font>
00153 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;stdlib.h&gt;</font>
00154 <font class="preprocessor">#endif</font>
00155 <font class="preprocessor"></font>
00156 <font class="preprocessor">#ifdef HAVE_SYS_TYPES_H</font>
00157 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;sys/types.h&gt;</font>
00158 <font class="preprocessor">#endif</font>
00159 <font class="preprocessor"></font>
00160 <font class="preprocessor">#ifdef HAVE_SYS_STAT_H</font>
00161 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;sys/stat.h&gt;</font>
00162 <font class="preprocessor">#endif</font>
00163 <font class="preprocessor"></font>
00164 <font class="preprocessor">#ifdef HAVE_FCNTL_H</font>
00165 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;fcntl.h&gt;</font>
00166 <font class="preprocessor">#endif</font>
00167 <font class="preprocessor"></font>
00168 <font class="preprocessor">#if defined(__VMS) &amp;&amp; __CRTL_VER &lt; 70000000</font>
00169 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;omniVMS/unlink.hxx&gt;</font>
00170 <font class="preprocessor">#endif</font>
00171 <font class="preprocessor"></font>
00172 <font class="preprocessor">#ifdef __WIN32__</font>
00173 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;io.h&gt;</font>
00174 <font class="preprocessor">#  include &lt;winbase.h&gt;</font>
00175 <font class="preprocessor">#  define stat(x,y) _stat(x,y)</font>
00176 <font class="preprocessor"></font><font class="preprocessor">#  define unlink(x) _unlink(x)</font>
00177 <font class="preprocessor"></font><font class="preprocessor">#  define STRUCT_STAT struct _stat</font>
00178 <font class="preprocessor"></font><font class="preprocessor">#else</font>
<a name="l00179"></a><a class="code" href="a00112.html#a0">00179</a> <font class="preprocessor"></font><font class="preprocessor">#  define STRUCT_STAT struct stat</font>
00180 <font class="preprocessor"></font><font class="preprocessor">#endif // __WIN32__</font>
00181 <font class="preprocessor"></font>
00182 <font class="preprocessor">#ifdef HAVE_UNISTD_H</font>
00183 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;unistd.h&gt;</font>
00184 <font class="preprocessor">#endif</font>
00185 <font class="preprocessor"></font>
00186 <font class="preprocessor">#ifdef HAVE_LIBC_H</font>
00187 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;libc.h&gt;</font>
00188 <font class="preprocessor">#endif</font>
00189 <font class="preprocessor"></font>
00190 <font class="preprocessor">#ifdef HAVE_SYS_PARAM_H</font>
00191 <font class="preprocessor"></font><font class="preprocessor">#  include &lt;sys/param.h&gt;</font>
00192 <font class="preprocessor">#endif</font>
00193 <font class="preprocessor"></font>
00194 <font class="preprocessor">#include &lt;errno.h&gt;</font>
00195 <font class="preprocessor">#include &lt;time.h&gt;</font>
00196 <font class="preprocessor">#include &lt;assert.h&gt;</font>
00197 <font class="preprocessor">#include "<a class="code" href="a00102.html">gethostname.h</a>"</font>
00198 
00199 <font class="preprocessor">#include "<a class="code" href="a00095.html">EventChannelFactory.h</a>"</font>
00200 <font class="preprocessor">#include "<a class="code" href="a00115.html">Orb.h</a>"</font>
00201 <font class="preprocessor">#include "<a class="code" href="a00090.html">defaults.h</a>"</font>
00202 
00203 <font class="comment">//</font>
00204 <font class="comment">// Set flags for use in calls to omniEventsLog::openOfstream()</font>
00205 <font class="comment">//</font>
00206 
00207 <font class="preprocessor">#if defined(HAVE_FSTREAM_OPEN)</font>
00208 <font class="preprocessor"></font><font class="preprocessor">#  define FLAG_TRUNCATE ios::trunc</font>
00209 <font class="preprocessor"></font><font class="preprocessor">#  define FLAG_APPEND   ios::app</font>
00210 <font class="preprocessor"></font><font class="preprocessor">#  define FLAG_SYNC     0</font>
00211 <font class="preprocessor"></font><font class="preprocessor">#elif defined(HAVE_FSTREAM_ATTACH)</font>
00212 <font class="preprocessor"></font><font class="preprocessor">#  if defined(__WIN32__)</font>
00213 <font class="preprocessor"></font><font class="preprocessor">#    define FLAG_SYNC 0</font>
00214 <font class="preprocessor"></font><font class="preprocessor">#  elif defined(O_SYNC)</font>
00215 <font class="preprocessor"></font><font class="preprocessor">#    define FLAG_SYNC O_SYNC</font>
00216 <font class="preprocessor"></font><font class="preprocessor">#  else</font>
00217 <font class="preprocessor"></font><font class="preprocessor">#    define FLAG_SYNC O_FSYNC // FreeBSD 3.2 does not have O_SYNC???</font>
00218 <font class="preprocessor"></font><font class="preprocessor">#  endif</font>
00219 <font class="preprocessor"></font><font class="preprocessor">#  define FLAG_TRUNCATE O_CREAT|O_TRUNC</font>
00220 <font class="preprocessor"></font><font class="preprocessor">#  define FLAG_APPEND   O_APPEND</font>
00221 <font class="preprocessor"></font><font class="preprocessor">#else</font>
00222 <font class="preprocessor"></font><font class="preprocessor">#  error "Can't open a file without ofstream::open() or ofstream::attach()"</font>
00223 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00224 <font class="preprocessor"></font>
00225 <font class="comment">//</font>
00226 <font class="comment">// Append ';' to VMS filenames to force the latest version.</font>
00227 <font class="comment">//</font>
00228 
00229 <font class="preprocessor">#ifdef __VMS</font>
00230 <font class="preprocessor"></font><font class="preprocessor">#  define VMS_SEMICOLON ";"</font>
00231 <font class="preprocessor"></font><font class="preprocessor">#else</font>
<a name="l00232"></a><a class="code" href="a00112.html#a1">00232</a> <font class="preprocessor"></font><font class="preprocessor">#  define VMS_SEMICOLON</font>
00233 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00234 <font class="preprocessor"></font>
00235 <font class="keyword">extern</font> <font class="keywordtype">int</font> <a class="code" href="a00112.html#a4">yyparse</a>();
<a name="l00236"></a><a class="code" href="a00112.html#a2">00236</a> <font class="keyword">extern</font> <font class="keywordtype">int</font> <a class="code" href="a00112.html#a2">yydebug</a>;
<a name="l00237"></a><a class="code" href="a00112.html#a3">00237</a> <font class="keyword">extern</font> FILE *<a class="code" href="a00112.html#a3">yyin</a>;
00238 
00239 <font class="keyword">namespace </font>OmniEvents {
00240 
<a name="l00246"></a><a class="code" href="a00078.html">00246</a> <font class="keyword">class </font><a class="code" href="a00078.html">timestamp</a>
00247 {
<a name="l00248"></a><a class="code" href="a00078.html#o0">00248</a>   <font class="keywordtype">char</font> <a class="code" href="a00078.html#o0">str</a>[29];
00249 <font class="keyword">public</font>:
<a name="l00250"></a><a class="code" href="a00078.html#a0">00250</a>   <a class="code" href="a00078.html#a0">timestamp</a>(<font class="keywordtype">void</font>)
00251   {
00252     <a class="code" href="a00078.html#o0">str</a>[0] = <font class="charliteral">'['</font>;
00253     <a class="code" href="a00078.html#o0">str</a>[1] = <a class="code" href="a00078.html#o0">str</a>[28] = <font class="charliteral">'\0'</font>;
00254   }
<a name="l00255"></a><a class="code" href="a00078.html#a1">00255</a>   <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="a00078.html#a1">t</a>(<font class="keywordtype">void</font>)
00256   {
00257     time_t <a class="code" href="a00078.html#a1">t</a> =time(NULL);
00258     <font class="keywordtype">char</font>*  p =ctime(&amp;<a class="code" href="a00078.html#a1">t</a>);
00259     <font class="keywordflow">if</font>(strncmp(p, &amp;<a class="code" href="a00078.html#o0">str</a>[1], 24) == 0)
00260         <font class="keywordflow">return</font> <font class="stringliteral">""</font>;
00261     strncpy(&amp;<a class="code" href="a00078.html#o0">str</a>[1], p, 24);
00262     <a class="code" href="a00078.html#o0">str</a>[25] = <font class="charliteral">']'</font>;
00263     <a class="code" href="a00078.html#o0">str</a>[26] = <font class="charliteral">' '</font>;
00264     <a class="code" href="a00078.html#o0">str</a>[27] = <font class="charliteral">' '</font>;
00265     <font class="keywordflow">return</font> <a class="code" href="a00078.html#o0">str</a>;
00266   }
00267 };
00268 
<a name="l00269"></a><a class="code" href="a00138.html#a2">00269</a> <a class="code" href="a00078.html">timestamp</a> <a class="code" href="a00138.html#a2">ts</a>;
00270 
00271 <font class="comment">//------------------------------------------------------------------------</font>
00272 <font class="comment">//           omniEvents Log Implementation</font>
00273 <font class="comment">//------------------------------------------------------------------------</font>
00274 
<a name="l00275"></a><a class="code" href="a00056.html#r0">00275</a> <a class="code" href="a00056.html">omniEventsLog</a> *omniEventsLog::theLog = NULL;
00276 
<a name="l00277"></a><a class="code" href="a00056.html#a0">00277</a> omniEventsLog::omniEventsLog(<font class="keyword">const</font> <font class="keywordtype">char</font>* logdir) :
00278   _logstream(),
00279   _activeFilename(NULL),
00280   _backupFilename(NULL),
00281   _checkpointFilename(NULL),
00282   _workerThread(NULL),
00283   _factory(NULL),
00284   _checkpointNeeded(true),
00285   _lock()
00286 {
00287   omniEventsLog::theLog = <font class="keyword">this</font>;
00288   <a class="code" href="a00056.html#b0">initializeFileNames</a>(logdir);
00289 }
00290 
00291 
<a name="l00292"></a><a class="code" href="a00056.html#a1">00292</a> omniEventsLog::~omniEventsLog()
00293 {
00294   omniEventsLog::theLog = NULL;
00295 }
00296 
00297 
<a name="l00298"></a><a class="code" href="a00056.html#a2">00298</a> <font class="keywordtype">bool</font> omniEventsLog::fileExists(<font class="keyword">const</font> <font class="keywordtype">char</font>* filename)<font class="keyword"> const</font>
00299 <font class="keyword"></font>{
00300   <a class="code" href="a00112.html#a0">STRUCT_STAT</a> sb;
00301   <font class="keywordflow">return</font>(::stat(filename,&amp;sb) == 0);
00302 }
00303 
00304 
<a name="l00305"></a><a class="code" href="a00056.html#a5">00305</a> <a class="code" href="a00060.html">PersistNode</a>* omniEventsLog::bootstrap(<font class="keywordtype">int</font> port, <font class="keyword">const</font> <font class="keywordtype">char</font>* endPointNoListen)
00306 {
00307   <font class="comment">//</font>
00308   <font class="comment">// Construct a new initialState, from the arguments.</font>
00309   <a class="code" href="a00060.html">PersistNode</a>* initialState=<font class="keyword">new</font> <a class="code" href="a00060.html">PersistNode</a>();
00310   PersistNode* ecf =initialState-&gt;<a class="code" href="a00060.html#a6">addnode</a>(<font class="stringliteral">"ecf"</font>);
00311   ecf-&gt;<a class="code" href="a00060.html#a8">addattr</a>(<font class="stringliteral">"port"</font>,port);
00312   <font class="keywordflow">if</font>(endPointNoListen &amp;&amp; endPointNoListen[0])
00313       ecf-&gt;<a class="code" href="a00060.html#a8">addattr</a>(string(<font class="stringliteral">"endPointNoListen="</font>)+endPointNoListen);
00314   <font class="keywordflow">return</font> initialState;
00315 } <font class="comment">// bootstrap()</font>
00316 
00317 
<a name="l00318"></a><a class="code" href="a00056.html#a6">00318</a> <a class="code" href="a00060.html">PersistNode</a>* omniEventsLog::parse()
00319 {
00320   <font class="comment">//</font>
00321   <font class="comment">// Restart - parse log file.</font>
00322   ifstream persiststream(<a class="code" href="a00056.html#o1">_activeFilename</a>);
00323   <font class="keywordflow">if</font>(!persiststream)
00324   {
00325     cerr &lt;&lt; <font class="stringliteral">"Error: cannot read database file '"</font>
00326          &lt;&lt; <a class="code" href="a00056.html#o1">_activeFilename</a> &lt;&lt; <font class="stringliteral">"'."</font> &lt;&lt; endl;
00327     <font class="keywordflow">if</font>( <a class="code" href="a00056.html#a2">fileExists</a>(<a class="code" href="a00056.html#o2">_backupFilename</a>) ) 
00328     {
00329       cerr &lt;&lt;
00330         <font class="stringliteral">" Backup file '"</font> &lt;&lt; <a class="code" href="a00056.html#o2">_backupFilename</a> &lt;&lt; <font class="stringliteral">"' exists.\n"</font>
00331         <font class="stringliteral">" Either rename it to '"</font> &lt;&lt; <a class="code" href="a00056.html#o1">_activeFilename</a> &lt;&lt; <font class="stringliteral">"' to\n"</font>
00332         <font class="stringliteral">" to recover the server's state, or delete it to create a new\n"</font>
00333         <font class="stringliteral">" database file."</font> &lt;&lt; endl;
00334     }
00335     exit(1);
00336   }
00337   <a class="code" href="a00060.html">PersistNode</a>* initialState=<font class="keyword">new</font> <a class="code" href="a00060.html">PersistNode</a>(persiststream);
00338   persiststream.close();
00339   
00340   <font class="comment">//</font>
00341   <font class="comment">// Check that the file contains a valid EventChannelFactory.</font>
00342   <font class="keyword">const</font> <font class="keywordtype">char</font>* errorStr =NULL;
00343   PersistNode* ecf=initialState-&gt;<a class="code" href="a00060.html#a13">child</a>(<font class="stringliteral">"ecf"</font>);
00344   <font class="keywordflow">if</font>(!ecf)
00345       errorStr=<font class="stringliteral">"Can't find EventChannelFactory."</font>;
00346   <font class="keywordflow">else</font> <font class="keywordflow">if</font>(ecf-&gt;<a class="code" href="a00060.html#a12">attrLong</a>(<font class="stringliteral">"port"</font>,-1)&lt;=0)
00347       errorStr=<font class="stringliteral">"EventChannelFactory is not assigned a valid port."</font>;
00348 
00349   <font class="keywordflow">if</font>(errorStr)
00350   {
00351     cerr&lt;&lt;<font class="stringliteral">"Error parsing database '"</font>&lt;&lt;<a class="code" href="a00056.html#o1">_activeFilename</a>&lt;&lt;<font class="stringliteral">"'.\n"</font>
00352         &lt;&lt;errorStr&lt;&lt;<font class="stringliteral">" Try deleting the file (and any backup)."</font>&lt;&lt;endl;
00353     exit(1);
00354   }
00355 
00356   <font class="keywordflow">return</font> initialState;
00357 } <font class="comment">// parse()</font>
00358 
00359 
<a name="l00360"></a><a class="code" href="a00056.html#a7">00360</a> <font class="keywordtype">void</font> omniEventsLog::incarnateFactory(<a class="code" href="a00060.html">PersistNode</a>* initialState)
00361 {
00362   assert(initialState!=NULL);
00363 
00364   <font class="comment">//</font>
00365   <font class="comment">// Open the logstream (The EventChannelFactory might want to write to it).</font>
00366   <font class="keywordflow">try</font>
00367   {
00368     <a class="code" href="a00056.html#b2">openOfstream</a>(<a class="code" href="a00056.html#o0">_logstream</a>,<a class="code" href="a00056.html#o1">_activeFilename</a>,FLAG_APPEND);
00369   }
00370   <font class="keywordflow">catch</font> (<a class="code" href="a00057.html">IOError</a>&amp; ex)
00371   {
00372     cerr &lt;&lt; <font class="stringliteral">"Error: cannot "</font>
00373          &lt;&lt; (<a class="code" href="a00056.html#a2">fileExists</a>(<a class="code" href="a00056.html#o1">_activeFilename</a>)?<font class="stringliteral">"write to"</font>:<font class="stringliteral">"create new"</font>)
00374          &lt;&lt; <font class="stringliteral">" database file '"</font> &lt;&lt; <a class="code" href="a00056.html#o1">_activeFilename</a>
00375          &lt;&lt; <font class="stringliteral">"': "</font> &lt;&lt; strerror(errno) &lt;&lt; endl;
00376     cerr &lt;&lt; <font class="stringliteral">"\nUse option '-l' or set the environment variable "</font>
00377          &lt;&lt; OMNIEVENTS_LOGDIR_ENV_VAR
00378          &lt;&lt; <font class="stringliteral">"\nto specify the directory where the files are kept.\n"</font>
00379          &lt;&lt; endl;
00380     <a class="code" href="a00056.html#o0">_logstream</a>.close();
00381     unlink(<a class="code" href="a00056.html#o1">_activeFilename</a>);
00382     exit(1);
00383   }
00384 
00385   <font class="comment">//</font>
00386   <font class="comment">// Recreate the persisted factory.</font>
00387   <a class="code" href="a00060.html">PersistNode</a>* ecf=initialState-&gt;<a class="code" href="a00060.html#a13">child</a>(<font class="stringliteral">"ecf"</font>);
00388   assert(ecf!=NULL);
00389   <a class="code" href="a00056.html#o5">_factory</a> =<font class="keyword">new</font> <a class="code" href="a00047.html">EventChannelFactory_i</a>(*ecf);
00390   assert(!CORBA::is_nil(<a class="code" href="a00056.html#o5">_factory</a>-&gt;_this()));
00391 } <font class="comment">// incarnateFactory</font>
00392 
00393 
<a name="l00394"></a><a class="code" href="a00056.html#a8">00394</a> <font class="keywordtype">void</font> omniEventsLog::runWorker()
00395 {
00396   assert(<a class="code" href="a00056.html#o5">_factory</a>!=NULL);
00397 
00398   <a class="code" href="a00056.html#o4">_workerThread</a>=<font class="keyword">new</font> <a class="code" href="a00058.html">omniEventsLogWorker</a>(
00399       <font class="keyword">this</font>,
00400       &amp;omniEventsLog::checkpoint, <font class="comment">// member function pointer</font>
00401       omni_thread::PRIORITY_NORMAL
00402     );
00403 }
00404 
00405 
<a name="l00406"></a><a class="code" href="a00056.html#a11">00406</a> <font class="keywordtype">void</font> omniEventsLog::output(ostream&amp; os)
00407 {
00408   <a class="code" href="a00056.html#o5">_factory</a>-&gt;<a class="code" href="a00047.html#a8">output</a>(os);
00409   os&lt;&lt;endl;
00410 }
00411 
00412 
<a name="l00413"></a><a class="code" href="a00056.html#a10">00413</a> <font class="keywordtype">void</font> omniEventsLog::checkpoint(<font class="keywordtype">void</font>)
00414 {
00415   <font class="keywordtype">int</font> idle_time_btw_chkpt;
00416   <font class="keyword">static</font> <font class="keywordtype">int</font> firstCheckPoint = 1;
00417   <font class="keywordtype">char</font> *itbc = getenv(<font class="stringliteral">"OMNIEVENTS_ITBC"</font>);
00418   <font class="keywordflow">if</font> (itbc == NULL || sscanf(itbc,<font class="stringliteral">"%d"</font>,&amp;idle_time_btw_chkpt) != 1)
00419   {
00420     idle_time_btw_chkpt=<a class="code" href="a00090.html#a6">OMNIEVENTS_LOG_CHECKPOINT_PERIOD</a>;
00421   }
00422 
00423   omni_mutex mutex;
00424   omni_condition cond(&amp;mutex);
00425 
00426   mutex.lock();
00427   <font class="keywordflow">while</font> (1) {
00428 
00429     <font class="comment">// Take an initial checkpoint the first time. All subsequent</font>
00430     <font class="comment">// checkpoints are conditionally tested on whether they are</font>
00431     <font class="comment">// needed or not.</font>
00432 
00433     <font class="keywordflow">if</font> (! firstCheckPoint)
00434     {
00435        <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> s, n;
00436        omni_thread::get_time(&amp;s, &amp;n, idle_time_btw_chkpt);
00437        cond.timedwait(s,n);
00438 
00439        <a class="code" href="a00056.html#o7">_lock</a>.lock();
00440        <font class="keywordflow">if</font>(!<a class="code" href="a00056.html#o6">_checkpointNeeded</a>)
00441        {
00442           <a class="code" href="a00056.html#o7">_lock</a>.unlock();
00443           <font class="keywordflow">continue</font>;
00444        }
00445     }
00446     <font class="keywordflow">else</font>
00447     {
00448        <a class="code" href="a00056.html#o7">_lock</a>.lock();
00449        firstCheckPoint = 0;
00450     }
00451   
00452     <a class="code" href="a00115.html#a2">DB</a>(1,ts.<a class="code" href="a00078.html#a1">t</a>() &lt;&lt; <font class="stringliteral">"Checkpointing Phase 1: Prepare."</font>)
00453   
00454     ofstream ckpf;
00455     <font class="keywordtype">int</font> fd = -1;
00456   
00457     <font class="keywordflow">try</font>
00458     {
00459       <font class="keywordflow">try</font>
00460       {
00461         <a class="code" href="a00056.html#b2">openOfstream</a>(ckpf,<a class="code" href="a00056.html#o3">_checkpointFilename</a>,FLAG_TRUNCATE|FLAG_SYNC,&amp;fd);
00462       }
00463       <font class="keywordflow">catch</font>(<a class="code" href="a00057.html">IOError</a>&amp; ex)
00464       {
00465         <a class="code" href="a00115.html#a2">DB</a>(0,ts.<a class="code" href="a00078.html#a1">t</a>() &lt;&lt; <font class="stringliteral">"Error: cannot open checkpoint file '"</font>
00466              &lt;&lt; <a class="code" href="a00056.html#o3">_checkpointFilename</a> &lt;&lt; <font class="stringliteral">"' for writing."</font>)
00467         <font class="keywordflow">throw</font>;
00468       }
00469   
00470       <a class="code" href="a00056.html#a11">output</a>(ckpf);
00471   
00472       ckpf.close();
00473       <font class="keywordflow">if</font>(!ckpf)
00474           <font class="keywordflow">throw</font> <a class="code" href="a00057.html">IOError</a>();
00475   
00476   <font class="comment">// a bug in sparcworks C++ means that the fd doesn't get closed.</font>
00477 <font class="preprocessor">#if defined(__sunos__) &amp;&amp; defined(__SUNPRO_CC) &amp;&amp; __SUNPRO_CC &lt; 0x500</font>
00478 <font class="preprocessor"></font>      <font class="keywordflow">if</font>(close(fd) &lt; 0)
00479           <font class="keywordflow">throw</font> <a class="code" href="a00057.html">IOError</a>();
00480 <font class="preprocessor">#endif</font>
00481 <font class="preprocessor"></font>  
00482     }
00483     <font class="keywordflow">catch</font>(<a class="code" href="a00057.html">IOError</a>&amp; ex)
00484     {
00485       <a class="code" href="a00115.html#a2">DB</a>(0,ts.<a class="code" href="a00078.html#a1">t</a>()&lt;&lt;<font class="stringliteral">"I/O error writing checkpoint file: "</font>&lt;&lt;strerror(errno)
00486            &lt;&lt;<font class="stringliteral">"\nAbandoning checkpoint"</font>)
00487       ckpf.close();
00488   <font class="comment">// a bug in sparcworks C++ means that the fd doesn't get closed.</font>
00489 <font class="preprocessor">#if defined(__sunos__) &amp;&amp; defined(__SUNPRO_CC) &amp;&amp; __SUNPRO_CC &lt; 0x500</font>
00490 <font class="preprocessor"></font>      close(fd);
00491 <font class="preprocessor">#endif</font>
00492 <font class="preprocessor"></font>      unlink(<a class="code" href="a00056.html#o3">_checkpointFilename</a>);
00493       <a class="code" href="a00056.html#o7">_lock</a>.unlock();
00494       <font class="keywordflow">continue</font>;
00495     }
00496   
00497     <font class="comment">//</font>
00498     <font class="comment">// Now commit the checkpoint to become the active log.</font>
00499     <font class="comment">//</font>
00500   
00501     <a class="code" href="a00115.html#a2">DB</a>(1,ts.<a class="code" href="a00078.html#a1">t</a>() &lt;&lt; <font class="stringliteral">"Checkpointing Phase 2: Commit."</font>)
00502 
00503   <font class="comment">// a bug in sparcworks C++ means that the fd doesn't get closed.</font>
00504 <font class="preprocessor">#if defined(__sunos__) &amp;&amp; defined(__SUNPRO_CC) &amp;&amp; __SUNPRO_CC &lt; 0x500</font>
00505 <font class="preprocessor"></font>    close(<a class="code" href="a00056.html#o0">_logstream</a>.rdbuf()-&gt;fd());
00506 <font class="preprocessor">#endif</font>
00507 <font class="preprocessor"></font>  
00508     <a class="code" href="a00056.html#o0">_logstream</a>.close();
00509   
00510     unlink(<a class="code" href="a00056.html#o2">_backupFilename</a>);
00511   
00512 <font class="preprocessor">#if defined(__WIN32__)</font>
00513 <font class="preprocessor"></font>    <font class="keywordflow">if</font>(rename(<a class="code" href="a00056.html#o1">_activeFilename</a>, <a class="code" href="a00056.html#o2">_backupFilename</a>) != 0)
00514 <font class="preprocessor">#elif defined(__VMS)</font>
00515 <font class="preprocessor"></font>    <font class="keywordflow">if</font>(rename(<a class="code" href="a00056.html#o1">_activeFilename</a>, <a class="code" href="a00056.html#o2">_backupFilename</a>) &lt; 0)
00516 <font class="preprocessor">#else</font>
00517 <font class="preprocessor"></font>    <font class="keywordflow">if</font>(link(<a class="code" href="a00056.html#o1">_activeFilename</a>,<a class="code" href="a00056.html#o2">_backupFilename</a>) &lt; 0)
00518 <font class="preprocessor">#endif</font>
00519 <font class="preprocessor"></font>    {
00520       <font class="comment">// Failure here leaves old active and checkpoint file.</font>
00521       <a class="code" href="a00115.html#a2">DB</a>(0,ts.<a class="code" href="a00078.html#a1">t</a>() &lt;&lt; <font class="stringliteral">"Error: failed to link backup file '"</font>
00522            &lt;&lt; <a class="code" href="a00056.html#o2">_backupFilename</a> &lt;&lt; <font class="stringliteral">"' to old log file '"</font>
00523            &lt;&lt; <a class="code" href="a00056.html#o1">_activeFilename</a> &lt;&lt; <font class="stringliteral">"'."</font>)
00524       exit(1);
00525     }
00526   
00527 <font class="preprocessor">#if !defined( __VMS) &amp;&amp; !defined(__WIN32__)</font>
00528 <font class="preprocessor"></font>    <font class="keywordflow">if</font>(unlink(<a class="code" href="a00056.html#o1">_activeFilename</a>) &lt; 0)
00529     {
00530       <font class="comment">// Failure here leaves active and backup pointing to the same (old) file.</font>
00531       <a class="code" href="a00115.html#a2">DB</a>(0,ts.<a class="code" href="a00078.html#a1">t</a>() &lt;&lt; <font class="stringliteral">"Error: failed to unlink old log file '"</font>
00532            &lt;&lt; <a class="code" href="a00056.html#o1">_activeFilename</a> &lt;&lt; <font class="stringliteral">"': "</font> &lt;&lt; strerror(errno))
00533       exit(1);
00534     }
00535 <font class="preprocessor">#endif</font>
00536 <font class="preprocessor"></font>  
00537 <font class="preprocessor">#if defined(__WIN32__)</font>
00538 <font class="preprocessor"></font>    <font class="keywordflow">if</font>(rename(<a class="code" href="a00056.html#o3">_checkpointFilename</a>,<a class="code" href="a00056.html#o1">_activeFilename</a>) != 0)
00539 <font class="preprocessor">#elif defined(__VMS)</font>
00540 <font class="preprocessor"></font>    <font class="keywordflow">if</font>(rename(<a class="code" href="a00056.html#o3">_checkpointFilename</a>,<a class="code" href="a00056.html#o1">_activeFilename</a>) &lt; 0)
00541 <font class="preprocessor">#else</font>
00542 <font class="preprocessor"></font>    <font class="keywordflow">if</font>(link(<a class="code" href="a00056.html#o3">_checkpointFilename</a>,<a class="code" href="a00056.html#o1">_activeFilename</a>) &lt; 0)
00543 <font class="preprocessor">#endif</font>
00544 <font class="preprocessor"></font>    {
00545       <font class="comment">// Failure here leaves no active but backup points to the old file.</font>
00546       <a class="code" href="a00115.html#a2">DB</a>(0,ts.<a class="code" href="a00078.html#a1">t</a>() &lt;&lt; <font class="stringliteral">"Error: failed to link log file '"</font> &lt;&lt; <a class="code" href="a00056.html#o1">_activeFilename</a>
00547            &lt;&lt; <font class="stringliteral">"' to checkpoint file '"</font> &lt;&lt; <a class="code" href="a00056.html#o3">_checkpointFilename</a> &lt;&lt; <font class="stringliteral">"'."</font>)
00548       exit(1);
00549     }
00550   
00551 <font class="preprocessor">#if !defined( __VMS) &amp;&amp; !defined(__WIN32__)</font>
00552 <font class="preprocessor"></font>    <font class="keywordflow">if</font> (unlink(<a class="code" href="a00056.html#o3">_checkpointFilename</a>) &lt; 0)
00553     {
00554       <font class="comment">// Failure here leaves active and checkpoint pointing to the same file.</font>
00555       <a class="code" href="a00115.html#a2">DB</a>(0,ts.<a class="code" href="a00078.html#a1">t</a>() &lt;&lt; <font class="stringliteral">"Error: failed to unlink checkpoint file '"</font>
00556            &lt;&lt; <a class="code" href="a00056.html#o3">_checkpointFilename</a> &lt;&lt; <font class="stringliteral">"'."</font>)
00557       exit(1);
00558     }
00559 <font class="preprocessor">#endif</font>
00560 <font class="preprocessor"></font>  
00561     <font class="keywordflow">try</font>
00562     {
00563       <a class="code" href="a00056.html#b2">openOfstream</a>(<a class="code" href="a00056.html#o0">_logstream</a>,<a class="code" href="a00056.html#o1">_activeFilename</a>,FLAG_APPEND|FLAG_SYNC,&amp;fd);
00564     }
00565     <font class="keywordflow">catch</font> (<a class="code" href="a00057.html">IOError</a>&amp; ex)
00566     {
00567       <a class="code" href="a00115.html#a2">DB</a>(0,ts.<a class="code" href="a00078.html#a1">t</a>() &lt;&lt; <font class="stringliteral">"Error: cannot open new log file '"</font> &lt;&lt; <a class="code" href="a00056.html#o1">_activeFilename</a>
00568            &lt;&lt; <font class="stringliteral">"' for writing."</font>)
00569       exit(1);
00570     }
00571   
00572     <a class="code" href="a00115.html#a2">DB</a>(1,ts.<a class="code" href="a00078.html#a1">t</a>() &lt;&lt; <font class="stringliteral">"Checkpointing completed."</font>)
00573   
00574     <a class="code" href="a00056.html#o6">_checkpointNeeded</a>=<font class="keyword">false</font>;
00575     <a class="code" href="a00056.html#o7">_lock</a>.unlock();
00576   }
00577   mutex.unlock();
00578 } <font class="comment">// checkpoint</font>
00579 
00580 
<a name="l00591"></a><a class="code" href="a00056.html#b0">00591</a> <font class="keywordtype">void</font> omniEventsLog::initializeFileNames(<font class="keyword">const</font> <font class="keywordtype">char</font>* logdir)
00592 {
00593   <font class="keywordflow">if</font>(!logdir)
00594       logdir=getenv(OMNIEVENTS_LOGDIR_ENV_VAR);
00595   <font class="keywordflow">if</font>(!logdir)
00596       logdir=<a class="code" href="a00090.html#a4">OMNIEVENTS_LOG_DEFAULT_LOCATION</a>;
00597 
00598   <font class="keyword">const</font> <font class="keywordtype">char</font>* logname =<font class="stringliteral">"omnievents-"</font>;
00599   <font class="keywordtype">char</font> hostname[<a class="code" href="a00102.html#a0">MAXHOSTNAMELEN</a>];
00600   <font class="keywordflow">if</font> (0!=<a class="code" href="a00102.html#a1">gethostname</a>(hostname,<a class="code" href="a00102.html#a0">MAXHOSTNAMELEN</a>))
00601   {
00602     cerr &lt;&lt; <font class="stringliteral">"Error: cannot get the name of this host."</font> &lt;&lt; endl;
00603     exit(1);
00604   }
00605   <font class="keyword">const</font> <font class="keywordtype">char</font>* sep =<font class="stringliteral">""</font>;
00606 
00607 <font class="preprocessor">#if defined(__WIN32__)</font>
00608 <font class="preprocessor"></font>  sep=<font class="stringliteral">"\\"</font>;
00609 <font class="preprocessor">#elif defined(__VMS)</font>
00610 <font class="preprocessor"></font>  <font class="keywordtype">char</font> last( logdir[strlen(logdir)-1] );
00611   <font class="keywordflow">if</font> (last != <font class="charliteral">':'</font> &amp;&amp; last != <font class="charliteral">']'</font>)
00612   {
00613     cerr &lt;&lt; <font class="stringliteral">"Error: "</font> &lt;&lt; OMNIEVENTS_LOGDIR_ENV_VAR &lt;&lt; <font class="stringliteral">" ("</font> &lt;&lt; logdir
00614          &lt;&lt; <font class="stringliteral">") is not a directory name."</font> &lt;&lt; endl;
00615     exit(1);
00616   }
00617 <font class="preprocessor">#else // Unix</font>
00618 <font class="preprocessor"></font>  <font class="keywordflow">if</font> (logdir[0] != <font class="charliteral">'/'</font>)
00619   {
00620     cerr &lt;&lt; <font class="stringliteral">"Error: "</font> &lt;&lt; OMNIEVENTS_LOGDIR_ENV_VAR &lt;&lt; <font class="stringliteral">" ("</font> &lt;&lt; logdir
00621          &lt;&lt; <font class="stringliteral">") is not an absolute path name."</font> &lt;&lt; endl;
00622     exit(1);
00623   }
00624   <font class="keywordflow">if</font> (logdir[strlen(logdir)-1] != <font class="charliteral">'/'</font>)
00625       sep=<font class="stringliteral">"/"</font>;
00626 <font class="preprocessor">#endif</font>
00627 <font class="preprocessor"></font>
00628   <font class="comment">// VMS_SEMICOLON specifies latest version of the file on VMS</font>
00629   <font class="comment">// (essentially, we're saying we don't want to use VMS file versioning).</font>
00630 
00631   <a class="code" href="a00056.html#b1">setFilename</a>(<a class="code" href="a00056.html#o1">_activeFilename</a>,logdir,sep,logname,hostname,<font class="stringliteral">".log"</font> <a class="code" href="a00112.html#a1">VMS_SEMICOLON</a>);
00632   <a class="code" href="a00056.html#b1">setFilename</a>(<a class="code" href="a00056.html#o2">_backupFilename</a>,logdir,sep,logname,hostname,<font class="stringliteral">".bak"</font> <a class="code" href="a00112.html#a1">VMS_SEMICOLON</a>);
00633   <a class="code" href="a00056.html#b1">setFilename</a>(
00634           <a class="code" href="a00056.html#o3">_checkpointFilename</a>,logdir,sep,logname,hostname,<font class="stringliteral">".ckp"</font> <a class="code" href="a00112.html#a1">VMS_SEMICOLON</a>);
00635 }
00636 
00637 
<a name="l00641"></a><a class="code" href="a00056.html#b1">00641</a> <font class="keywordtype">void</font> omniEventsLog::setFilename(
00642   <font class="keywordtype">char</font>*&amp; filename,     <font class="keyword">const</font> <font class="keywordtype">char</font>* logdir,   <font class="keyword">const</font> <font class="keywordtype">char</font>* sep,
00643   <font class="keyword">const</font> <font class="keywordtype">char</font>* logname, <font class="keyword">const</font> <font class="keywordtype">char</font>* hostname, <font class="keyword">const</font> <font class="keywordtype">char</font>* ext)
00644 {
00645   size_t len=1+
00646     strlen(logdir)+strlen(sep)+strlen(logname)+strlen(hostname)+strlen(ext);
00647   filename=<font class="keyword">new</font> <font class="keywordtype">char</font>[len];
00648   sprintf(filename,<font class="stringliteral">"%s%s%s%s%s"</font>,logdir,sep,logname,hostname,ext);
00649 }
00650 
00651 
<a name="l00665"></a><a class="code" href="a00056.html#b2">00665</a> <font class="keywordtype">void</font> omniEventsLog::openOfstream(
00666   ofstream&amp; s, <font class="keyword">const</font> <font class="keywordtype">char</font>* filename, <font class="keywordtype">int</font> flags, <font class="keywordtype">int</font>* fd)
00667 {
00668 <font class="preprocessor">#if defined(HAVE_FSTREAM_OPEN)</font>
00669 <font class="preprocessor"></font><font class="preprocessor">#  ifdef HAVE_STD_IOSTREAM</font>
00670 <font class="preprocessor"></font>      ios::openmode openmodeflags =ios::out|ios::openmode(flags);
00671 <font class="preprocessor">#  else</font>
00672 <font class="preprocessor"></font>      <font class="keywordtype">int</font>           openmodeflags =ios::out|flags;
00673 <font class="preprocessor">#  endif</font>
00674 <font class="preprocessor"></font>
00675 <font class="preprocessor">#  ifdef FSTREAM_OPEN_PROT</font>
00676 <font class="preprocessor"></font>      s.open(filename,openmodeflags,0644);
00677 <font class="preprocessor">#  else</font>
00678 <font class="preprocessor"></font>      s.open(filename,openmodeflags);
00679 <font class="preprocessor">#  endif</font>
00680 <font class="preprocessor"></font>      <font class="keywordflow">if</font> (!s)
00681           <font class="keywordflow">throw</font> <a class="code" href="a00057.html">IOError</a>();
00682 
00683 <font class="preprocessor">#elif defined(HAVE_FSTREAM_ATTACH)</font>
00684 <font class="preprocessor"></font><font class="preprocessor">#  ifdef __WIN32__</font>
00685 <font class="preprocessor"></font>      <font class="keywordtype">int</font> localFd = _open(filename, O_WRONLY | flags, _S_IWRITE);
00686 <font class="preprocessor">#  else</font>
00687 <font class="preprocessor"></font>      <font class="keywordtype">int</font> localFd = open(filename, O_WRONLY | flags, 0644);
00688 <font class="preprocessor">#  endif </font><font class="comment">/* __WIN32__ */</font>
00689       <font class="keywordflow">if</font> (localFd &lt; 0)
00690           <font class="keywordflow">throw</font> <a class="code" href="a00057.html">IOError</a>();
00691       <font class="keywordflow">if</font>(fd)
00692           (*fd)=localFd;
00693       s.attach(localFd);
00694 <font class="preprocessor">#endif</font>
00695 <font class="preprocessor"></font>}
00696 
00697 
00698 <font class="comment">//------------------------------------------------------------------------</font>
00699 <font class="comment">//           OmniEvents Log Worker Implementation</font>
00700 <font class="comment">//------------------------------------------------------------------------</font>
<a name="l00701"></a><a class="code" href="a00058.html#a0">00701</a> omniEventsLogWorker::omniEventsLogWorker(
00702   <a class="code" href="a00056.html">omniEventsLog</a>* object,
00703   Method         method,
00704   priority_t     priority
00705 ):omni_thread(NULL,priority)
00706 {
00707   <a class="code" href="a00115.html#a2">DB</a>(15, <font class="stringliteral">"omniEventsLogWorker::omniEventsLogWorker()"</font>);
00708 
00709   <a class="code" href="a00058.html#o1">_method</a>=method;
00710   <a class="code" href="a00058.html#o0">_object</a>=object;
00711 
00712   start_undetached();
00713 }
00714 
00715 
<a name="l00716"></a><a class="code" href="a00058.html#a1">00716</a> <font class="keywordtype">void</font>* omniEventsLogWorker::run_undetached(<font class="keywordtype">void</font> *)
00717 {
00718   <font class="keywordflow">try</font> {
00719     <a class="code" href="a00115.html#a2">DB</a>(15, <font class="stringliteral">"omniEventsLogWorker : run_undetached Start"</font>);
00720     (<a class="code" href="a00058.html#o0">_object</a>-&gt;*<a class="code" href="a00058.html#o1">_method</a>)();
00721     <a class="code" href="a00115.html#a2">DB</a>(15, <font class="stringliteral">"omniEventsLogWorker : run_undetached End"</font>);
00722   }
00723   <font class="keywordflow">catch</font> (CORBA::SystemException&amp; ex) {
00724     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"omniEventsLogWorker killed by CORBA system exception"</font>
00725        <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<font class="stringliteral">": "</font>&lt;&lt;ex._name()&lt;&lt;<font class="stringliteral">" ("</font>&lt;&lt;<a class="code" href="a00115.html#a3">NP_MINORSTRING</a>(ex)&lt;&lt;<font class="stringliteral">")"</font>) <font class="stringliteral">"."</font>)
00726   }
00727   <font class="keywordflow">catch</font> (CORBA::Exception&amp; ex) {
00728     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"omniEventsLogWorker killed by CORBA exception"</font>
00729        <a class="code" href="a00115.html#a1">IF_OMNIORB4</a>(<font class="stringliteral">": "</font>&lt;&lt;ex._name()&lt;&lt;) <font class="stringliteral">"."</font>)
00730   }
00731   <font class="keywordflow">catch</font>(...) {
00732     <a class="code" href="a00115.html#a2">DB</a>(0,<font class="stringliteral">"omniEventsLogWorker killed by unknown exception."</font>)
00733   }
00734   <font class="keywordflow">return</font> NULL;
00735 }
00736 
<a name="l00737"></a><a class="code" href="a00058.html#a2">00737</a> omniEventsLogWorker::~omniEventsLogWorker()
00738 {
00739   <a class="code" href="a00115.html#a2">DB</a>(20, <font class="stringliteral">"omniEventsLogWorker::~omniEventsLogWorker()"</font>);
00740 }
00741 
00742 
00743 }; <font class="comment">// end namespace OmniEvents</font>
</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>