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
|
#include <iostream.h>
// @(#)Logger.cpp 1.1 10/18/96
#include "Logger.h"
Logger::~Logger (void)
{
// Release and free up the object reference.
this->logref_->_release ();
// Must use free since we used strdup(3C).
ACE_OS::free (ACE_MALLOC_T (this->server_));
}
// Constructor takes the name of the host where the server
// is located. If server == 0, then use the locator service.
Logger::Logger (char *server, size_t max_message_size)
: server_ (server == 0 ? 0 : ACE_OS::strdup (server)),
ip_ (0),
pid_ (ACE_OS::getpid ())
{
struct utsname name;
#if 0
// Could also use sysinfo(2)...
ACE_OS::sysinfo (SI_HOSTNAME, clienthost, MAXHOSTNAMELEN);
#endif
ACE_OS::uname (&name);
hostent *hp = ACE_OS::gethostbyname (name.nodename);
if (hp != 0)
memcpy ((void *) &this->ip_, (void *) hp->h_addr, hp->h_length);
TRY {
// First bind to the logger object.
// argv[1] has the hostname (if any) of the target logger object;
// The default is the local host:
this->logref_ = profile_logger::_bind ("", this->server_, IT_X);
} CATCHANY {
// an error occurred while trying to bind to the logger object.
cerr << "Bind to object failed" << endl;
cerr << "Unexpected exception " << IT_X << endl;
} ENDTRY;
// Pre-assign certain values that don't change.
this->log_msg_.app_id = this->pid_;
this->log_msg_.host_addr = this->ip_;
this->log_msg_.msg_data._maximum = max_message_size;
}
// Transmit the message to the logging server.
int
Logger::log (logger::Log_Priority priority, char message[], int length)
{
// The following values change with every logging operation.
this->log_msg_.type = priority;
this->log_msg_.time = ACE_OS::time (0);
this->log_msg_.msg_data._length = length;
this->log_msg_.msg_data._buffer = message;
TRY {
// Try to log a message.
this->logref_->log (this->log_msg_, IT_X);
} CATCHANY {
// an error occurred while trying to read the height and width:
cerr << "call to log failed" << endl;
cerr << "Unexpected exception " << IT_X << endl;
return -1;
} ENDTRY;
// success.
return 0;
}
// Get the value of verbose.
int
Logger::verbose (void)
{
int verbosity = 0;
TRY {
verbosity = this->logref_->verbose ();
} CATCHANY {
return -1;
} ENDTRY;
return verbosity;
}
// Set the value of verbose.
int
Logger::verbose (int value)
{
int verbosity = 0;
TRY {
this->logref_->verbose (value);
} CATCHANY {
return -1;
} ENDTRY;
return 0;
}
// Activate the timer.
int
Logger::start_timer (void)
{
TRY {
this->logref_->start_timer ();
} CATCHANY {
return -1;
} ENDTRY;
return 0;
}
// Deactivate the timer and return the elapsed time.
int
Logger::stop_timer (profile_logger::Elapsed_Time &et)
{
TRY {
this->logref_->stop_timer (et);
} CATCHANY {
return -1;
} ENDTRY;
return 0;
}
|