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
|
/* -*- C++ -*- */
// $Id$
#include "Options.h"
#include "ImR_Activator_i.h"
#include "NT_Service.h"
int
run_standalone (void)
{
ImR_Activator_i server;
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
// Initialize the ImR_Activator_i server.
int status = server.init (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
if (status == -1)
{
return 1;
}
else
{
// Run the server if it is initialized correctly.
server.run (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// End the server after its work is done.
status = server.fini (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
if (status == -1)
return 1;
}
}
ACE_CATCH (CORBA::SystemException, sysex)
{
ACE_PRINT_EXCEPTION (sysex, "System Exception");
return 1;
}
ACE_CATCH (CORBA::UserException, userex)
{
ACE_PRINT_EXCEPTION (userex, "User Exception");
return 1;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Unknown Exception");
return 1;
}
ACE_ENDTRY;
return 0;
}
#if defined (ACE_WIN32)
ACE_NT_SERVICE_DEFINE (service, ImR_NT_Service, IMR_SERVICE_NAME);
#endif /* ACE_WIN32 */
int
run_service (void)
{
#if defined (ACE_WIN32)
// @todo: Update me
// If we get here, we either run the app in debug mode (-d) or are
// being called from the service manager to start the service.
ACE_NT_SERVICE_RUN (service, SERVICE::instance (), ret);
if (ret == 0)
ACE_ERROR ((LM_ERROR, "%p\n", "Couldn't start service"));
return ret;
#else /* ACE_WIN32 */
return 1;
#endif /* ACE_WIN32 */
}
int
main (int argc, char *argv[])
{
int result = OPTIONS::instance ()->init (argc, argv);
if (result < 0)
return 1; // Error parsing args
else if (result > 0)
return 0; // No error, but we should exit anyway.
if (OPTIONS::instance ()->service () == 1)
return run_service ();
return run_standalone ();
}
|