-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.h
147 lines (104 loc) · 3.65 KB
/
log.h
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
// -*- Mode: C++; -*-
// Package : omniNames
// log.h Author : Tristan Richardson (tjr)
//
// Copyright (C) 2003-2013 Apasphere Ltd
// Copyright (C) 1997-1999 AT&T Laboratories Cambridge
//
// This file is part of omniNames.
//
// omniNames is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
//
#ifndef _log_h_
#define _log_h_
#include <omniORB4/CORBA.h>
#ifdef HAVE_STD
# include <fstream>
using namespace std;
#else
# include <fstream.h>
#endif
#ifndef DATADIR_ENV_VAR
# define DATADIR_ENV_VAR "OMNINAMES_DATADIR"
#endif
#ifndef LOGDIR_ENV_VAR
# define LOGDIR_ENV_VAR "OMNINAMES_LOGDIR"
#endif
// Tracing/logging
#define LOG(level, msg) \
do { \
if (omniORB::trace(level)) { \
omniORB::logger _log("omniNames: "); \
_log << msg << '\n'; \
} \
} while(0)
class omniNameslog {
CORBA::ORB_ptr orb;
PortableServer::POA_ptr poa;
PortableServer::POA_ptr ins_poa;
CORBA::String_var active;
CORBA::String_var backup;
CORBA::String_var checkpt;
CORBA::String_var active_new;
CORBA::String_var active_old;
ofstream logf;
int port;
PortableServer::ObjectId persistentId;
int startingUp; // true while reading log file initially.
int firstTime; // true if running for the first time
int checkpointNeeded; // true if changes have been made since last checkpoint
int line; // current line number when reading log file initially.
//
// functions to write to a file
//
void putPort(int port, ostream& file);
void putPersistent(const PortableServer::ObjectId& id, ostream& file);
void putCreate(const PortableServer::ObjectId& id, ostream& file);
void putDestroy(CosNaming::NamingContext_ptr nc, ostream& file);
void putBind(CosNaming::NamingContext_ptr nc,
const CosNaming::Name& n, CORBA::Object_ptr obj,
CosNaming::BindingType t, ostream& file);
void putUnbind(CosNaming::NamingContext_ptr nc, const CosNaming::Name& n,
ostream& file);
void putKey(const PortableServer::ObjectId& id, ostream& file);
void putString(const char* str, ostream& file);
//
// functions to read from a file
//
void getPort(istream& file);
void getPersistent(istream& file);
void getCreate(istream& file);
void getDestroy(istream& file);
void getBind(istream& file);
void getUnbind(istream& file);
void getKey(PortableServer::ObjectId& id, istream& file);
void getFinalString(char*& buf, istream& file);
void getNonfinalString(char*& buf, istream& file);
int getString(char*& buf, istream& file);
public:
class IOError {};
class ParseError {};
omniNameslog(int& port, const char* logdir, int nohostname, int always);
void init(CORBA::ORB_ptr o,
PortableServer::POA_ptr p,
PortableServer::POA_ptr ip);
void create(const PortableServer::ObjectId& id);
void destroy(CosNaming::NamingContext_ptr nc);
void bind(CosNaming::NamingContext_ptr nc,
const CosNaming::Name& n, CORBA::Object_ptr obj,
CosNaming::BindingType t);
void unbind(CosNaming::NamingContext_ptr nc, const CosNaming::Name& n);
void checkpoint();
};
#endif