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
|
// $Id$
#include "ace/Get_Opt.h"
#include "ace/SString.h"
#include "ace/OS_NS_stdio.h"
#include "orbsvcs/FtRtEvent/Utils/FTEC_Gateway.h"
#include "orbsvcs/FtRtEvent/Utils/resolve_init.h"
/// include this file to statically linked with FT ORB
#include "orbsvcs/FaultTolerance/FT_ClientService_Activate.h"
/// include this file to statically linked with Transaction Depth
#include "orbsvcs/FtRtEvent/ClientORB/FTRT_ClientORB_Loader.h"
ACE_RCSID (Gateway_Service,
FTRTEC_Gateway_Service,
"$Id$")
namespace {
CORBA::ORB_var orb;
FtRtecEventChannelAdmin::EventChannel_var ftec;
ACE_CString ior_file_name;
}
int parse_args(int argc, ACE_TCHAR** argv)
{
try{
ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("i:n:o:"));
int opt;
CosNaming::Name name(1);
name.length(1);
name[0].id = CORBA::string_dup("FT_EventService");
while ((opt = get_opt ()) != EOF)
{
switch (opt)
{
case 'i':
{
CORBA::Object_var obj = orb->string_to_object(get_opt.opt_arg ());
ftec = FtRtecEventChannelAdmin::EventChannel::_narrow(obj.in());
}
break;
case 'n':
name[0].id = CORBA::string_dup(get_opt.opt_arg ());
break;
case 'o':
ior_file_name = get_opt.opt_arg ();
break;
}
}
if (CORBA::is_nil(ftec.in())) {
/// we should get the ftec from Naming Service
CosNaming::NamingContext_var naming_context =
resolve_init<CosNaming::NamingContext>(orb.in(), "NameService");
ftec = resolve<FtRtecEventChannelAdmin::EventChannel>(naming_context.in(),
name);
if (CORBA::is_nil(ftec.in()))
ACE_ERROR_RETURN((LM_ERROR, "Cannot Find FT_EventService\n"), -1);
}
}
catch (const CORBA::Exception&){
ACE_ERROR_RETURN((LM_ERROR, "Cannot Find FT_EventService\n"), -1);
}
return 0;
}
int main(int argc, ACE_TCHAR** argv)
{
try
{
orb = CORBA::ORB_init (argc, argv);
if (parse_args(argc, argv)==-1)
return 1;
PortableServer::POA_var
root_poa = resolve_init<PortableServer::POA>(orb.in(), "RootPOA");
// create POAManager
PortableServer::POAManager_var
mgr = root_poa->the_POAManager();
mgr->activate();
TAO_FTRTEC::FTEC_Gateway gateway_servant(orb.in(), ftec.in());
RtecEventChannelAdmin::EventChannel_var gateway =
gateway_servant.activate(root_poa.in());
if (ior_file_name.length())
{
CORBA::String_var str = orb->object_to_string(gateway.in());
FILE *output_file=
ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR(ior_file_name.c_str()),
ACE_TEXT("w"));
if (output_file == 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Cannot open output file for writing IOR: %s",
ior_file_name.c_str()),
1);
ACE_OS::fprintf (output_file, "%s", str.in ());
ACE_OS::fclose (output_file);
}
orb->run();
}
catch (const CORBA::Exception&){
return 1;
}
return 0;
}
|