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
|
//=============================================================================
/**
* @file ior_corbaname_client_i.cpp
*
* This example implements a simple client which sends a corbaname:
* style url to the server and gets a response from the
* server to indicate that the server has received the request.
*
* @author Priyanka Gontla <pgontla@ece.uci.edu>
*/
//=============================================================================
#include "ior_corbaname_client_i.h"
#include "ace/Get_Opt.h"
#include "ace/Read_Buffer.h"
#include "ace/SString.h"
// Constructor
IOR_corbaname_Client_i::IOR_corbaname_Client_i (void)
{
}
// Destructor
IOR_corbaname_Client_i::~IOR_corbaname_Client_i (void)
{
}
int
IOR_corbaname_Client_i::run (void)
{
try
{
CosNaming::Name name (1);
name.length (1);
name[0].id = CORBA::string_dup ("STATUS");
// The corbaname URL contains the host at which an NamingContext
// Object can be found and also the stringified form of an entry
// in the Naming Service separated by '#'. For simplicity,
// in this example, we are specifying the stringified form of
// the binding directly without using <to_string> method on
// <name>. "#" refers to the seperator between the host and the
// entry.
ACE_CString corbaname_url (ACE_TEXT_ALWAYS_CHAR (this->argv_[1]), 0, 1);
// Append the seperator '#' to the host.
corbaname_url += "#";
// Append the stringified name to the resultant.
corbaname_url += "STATUS";
// Resolve the stringified name.
CORBA::Object_var factory_object =
this->orb_->string_to_object (corbaname_url.c_str ());
// Narrow
corbaname::Status_var factory =
corbaname::Status::_narrow (factory_object.in ());
if (CORBA::is_nil (factory.in ()))
{
ACE_ERROR_RETURN ((LM_ERROR,
"Object reference <%s> is nil\n",
this->argv_[1]),
1);
}
// Invoke a request on the server
CORBA::Boolean const ret_value = factory->print_status ();
if (!ret_value)
{
ACE_DEBUG ((LM_DEBUG,
"The server has been successfully contacted.\n",
0));
}
}
catch (const CosNaming::NamingContext::NotFound& ex)
{
ex._tao_print_exception ("CosNaming::NamingContext::NotFound");
}
catch (const CORBA::SystemException& ex)
{
ex._tao_print_exception ("A system exception on client side");
return -1;
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("client");
return -1;
}
return 0;
}
int
IOR_corbaname_Client_i::init (int argc, ACE_TCHAR **argv)
{
this->argc_ = argc;
this->argv_ = argv;
try
{
// First initialize the ORB, that will remove some arguments...
this->orb_ = CORBA::ORB_init (this->argc_, this->argv_);
// There must be at least one argument, the file that has to be
// retrieved
if (this->argc_ < 2)
ACE_ERROR_RETURN ((LM_ERROR,
"%s: Address of naming context not specified\n",
this->argv_[0]),
-1);
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("client");
return 1;
}
return 0;
}
|