1 #include "AccountManager_i.h"
4 #include "tao/Utils/ORB_Manager.h"
7 AccountManager_i::AccountManager_i () :
13 AccountManager_i::~AccountManager_i ()
17 // Set the ORB pointer
19 AccountManager_i::orb (CORBA::ORB_ptr o
)
21 this->orb_
= CORBA::ORB::_duplicate (o
);
25 AccountManager_i::poa (PortableServer::POA_ptr poa
)
27 this->poa_
= PortableServer::POA::_duplicate (poa
);
31 AccountManager_i::set_orb_manager (TAO_ORB_Manager
*orb_manager
)
33 this->orb_manager_
= orb_manager
;
36 // Open an account for the given name.
39 AccountManager_i::open (const char *name
,
40 CORBA::Float initial_balance
)
42 // If name is already in the map, <find> will assign <result> to the
45 if (hash_map_
.find (name
, result
) != 0)
48 ACE_TEXT ("[SERVER] Process/Thread Id : (%P/%t) Opening Account (%C,%8.2f)\n"),
53 ACE_NEW_THROW_EX (tmp
,
59 // Enter the new Account in the hash map. If the <bind> fails
60 // throw an UNKNOWN exception. <result> may be valid but since
61 // it is not properly bound, it's behaviour may be off, so
62 // delete it to be safe.
64 if (hash_map_
.bind (name
, result
) == -1)
66 throw CORBA::UNKNOWN ();
70 if (TAO_debug_level
> 0)
72 ACE_TEXT ("[SERVER] Process/Thread Id : (%P/%t) Account already exists for %C\n"),
74 // Generate an IOR for the result object and register it with the
75 // POA. In case the object already exists then the previously
76 // generated IOR is returned.
78 return result
->_this ();
83 AccountManager_i::close (Bank::Account_ptr account
)
87 CORBA::String_var name
= account
->name ();
90 ACE_TEXT ("[SERVER] Process/Thread Id : (%P/%t) Closing Account for %C\n"),
93 Account_i_var account
;
94 if (hash_map_
.unbind (name
.in (), account
) == -1)
96 if (TAO_debug_level
> 0)
98 ACE_TEXT ("Unable to close account\n")));
101 if (!account
.is_nil ())
103 PortableServer::POA_var poa
= account
->_default_POA ();
105 PortableServer::ObjectId_var id
= poa
->servant_to_id (account
.in ());
107 poa
->deactivate_object (id
.in ());
110 catch (const CORBA::Exception
& ex
)
112 ex
._tao_print_exception ("Unable to close Account\n");
117 AccountManager_i::shutdown ()
119 ACE_DEBUG ((LM_DEBUG
,
120 ACE_TEXT ("\n[SERVER] Process/Thread Id : (%P/%t) AccountManager_i is shutting down\n")));
122 // Instruct the ORB to shutdown.
123 this->orb_
->shutdown ();