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
|
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <Ice/Application.h>
#ifndef _WIN32
# include <csignal>
#endif
using namespace std;
using namespace Ice;
const char* Application::_appName;
CommunicatorPtr Application::_communicator;
Ice::Application::Application()
{
}
Ice::Application::~Application()
{
}
int
Ice::Application::main(int argc, char* argv[], const char* configFile)
{
if(_communicator)
{
cerr << argv[0] << ": only one instance of the Application class can be used" << endl;
return EXIT_FAILURE;
}
_appName = argv[0];
int status;
try
{
if(configFile)
{
PropertiesPtr properties = createProperties(argc, argv);
properties->load(configFile);
_communicator = initializeWithProperties(argc, argv, properties);
}
else
{
_communicator = initialize(argc, argv);
}
status = run(argc, argv);
}
catch(const Exception& ex)
{
cerr << _appName << ": " << ex << endl;
status = EXIT_FAILURE;
}
catch(...)
{
cerr << _appName << ": unknown exception" << endl;
status = EXIT_FAILURE;
}
if(_communicator)
{
try
{
_communicator->destroy();
}
catch(const Exception& ex)
{
cerr << _appName << ": " << ex << endl;
status = EXIT_FAILURE;
}
catch(...)
{
cerr << _appName << ": unknown exception" << endl;
status = EXIT_FAILURE;
}
_communicator = 0;
}
return status;
}
const char*
Ice::Application::appName()
{
return _appName;
}
CommunicatorPtr
Ice::Application::communicator()
{
return _communicator;
}
#ifdef _WIN32
static BOOL WINAPI
interruptHandler(DWORD)
{
assert(Application::communicator());
Application::communicator()->shutdown();
return TRUE;
}
void
Ice::Application::shutdownOnInterrupt()
{
SetConsoleCtrlHandler(NULL, FALSE);
SetConsoleCtrlHandler(interruptHandler, TRUE);
}
void
Ice::Application::ignoreInterrupt()
{
SetConsoleCtrlHandler(interruptHandler, FALSE);
SetConsoleCtrlHandler(NULL, TRUE);
}
void
Ice::Application::defaultInterrupt()
{
SetConsoleCtrlHandler(interruptHandler, FALSE);
SetConsoleCtrlHandler(NULL, FALSE);
}
#else
static void
interruptHandler(int)
{
assert(Application::communicator());
Application::communicator()->shutdown();
}
void
Ice::Application::shutdownOnInterrupt()
{
struct sigaction action;
action.sa_handler = interruptHandler;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGHUP);
sigaddset(&action.sa_mask, SIGINT);
sigaddset(&action.sa_mask, SIGTERM);
action.sa_flags = 0;
sigaction(SIGHUP, &action, 0);
sigaction(SIGINT, &action, 0);
sigaction(SIGTERM, &action, 0);
}
void
Ice::Application::ignoreInterrupt()
{
struct sigaction action;
action.sa_handler = SIG_IGN;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
sigaction(SIGHUP, &action, 0);
sigaction(SIGINT, &action, 0);
sigaction(SIGTERM, &action, 0);
}
void
Ice::Application::defaultInterrupt()
{
struct sigaction action;
action.sa_handler = SIG_DFL;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
sigaction(SIGHUP, &action, 0);
sigaction(SIGINT, &action, 0);
sigaction(SIGTERM, &action, 0);
}
#endif
|