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
|
//$Id$
#include "Bank_Client_i.h"
#include "ace/Get_Opt.h"
#include "ace/Read_Buffer.h"
// This is the interface program that accesses the remote object
// Constructor.
Bank_Client_i::Bank_Client_i (void)
{
//no-op
}
//Destructor.
Bank_Client_i::~Bank_Client_i (void)
{
//no-op
}
int
Bank_Client_i::run (const char *name,
int argc,
char *argv[])
{
// Initialize the client.
if (client.init (name,argc, argv) == -1)
return -1;
ACE_TRY_NEW_ENV
{
this->check_accounts ();
if (client.shutdown () == 1)
client->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
ACE_DEBUG ((LM_DEBUG,
"\nException caught in run\n"));
}
ACE_ENDTRY;
return 0;
}
int
Bank_Client_i::check_accounts (void )
{
ACE_TRY_NEW_ENV
{
ACE_DEBUG ((LM_DEBUG,
"\nTests for account with same name\n"));
this->test_for_same_name (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG,
"\nTests for account with different names\n"));
this->test_for_different_name (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG,
"\nTests for overdrafts\n"));
this->test_for_overdraft (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
ACE_DEBUG ((LM_DEBUG,
"From Bank_Client_i::check_accounts()"));
}
ACE_ENDTRY;
return 0;
}
// This method tests whether an account with a
// a same name can be opened
void
Bank_Client_i::test_for_same_name (ACE_ENV_SINGLE_ARG_DECL)
{
const char *name = "Name";
CORBA::Float initial_bal = 0.00;
Bank::Account_var acct_id1 = client->open (name,
initial_bal
ACE_ENV_ARG_PARAMETER);
Bank::Account_var acct_id2 = client->open (name,
initial_bal
ACE_ENV_ARG_PARAMETER);
ACE_ASSERT (acct_id1->_is_equivalent ((CORBA::Object *) acct_id2.in ()) != 0);
client->close (acct_id1.in ()
ACE_ENV_ARG_PARAMETER);
client->close (acct_id2.in ()
ACE_ENV_ARG_PARAMETER);
}
// This method tests whether an account with different names can be opened
void
Bank_Client_i::test_for_different_name (ACE_ENV_SINGLE_ARG_DECL)
{
const char *name1 = "Name1";
const char *name2 = "Name2";
CORBA::Float initial_bal = 0.0;
Bank::Account_var acct_id1 = client->open (name1,
initial_bal
ACE_ENV_ARG_PARAMETER);
Bank::Account_var acct_id2 = client->open (name2,
initial_bal
ACE_ENV_ARG_PARAMETER);
ACE_ASSERT (acct_id1->_is_equivalent ((CORBA::Object *)acct_id2.in ()) == 0);
client->close (acct_id1.in ()
ACE_ENV_ARG_PARAMETER);
client->close (acct_id2.in ()
ACE_ENV_ARG_PARAMETER);
}
// This method tests the Overdraft exception.
void
Bank_Client_i::test_for_overdraft (ACE_ENV_SINGLE_ARG_DECL)
{
CORBA::Float initial_bal = 100.0;
const char *name = "Name";
Bank::Account_var acct_id = client->open (name, initial_bal ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
acct_id->deposit (100.00 ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
CORBA::Float bal = acct_id->balance (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
acct_id->withdraw (bal + 20);
client->close (acct_id.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class Client<Bank::AccountManager,Bank::AccountManager_var>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate Client<Bank,Bank_var>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|