Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / examples / Simple / bank / AccountManager_i.cpp
blob7cd2405208e84b1ddb006d008225ca19b508fe24
1 #include "AccountManager_i.h"
2 #include "Account_i.h"
3 #include "tao/debug.h"
4 #include "tao/Utils/ORB_Manager.h"
6 // Constructor
7 AccountManager_i::AccountManager_i () :
8 orb_manager_ (0)
12 // Destructor
13 AccountManager_i::~AccountManager_i ()
17 // Set the ORB pointer
18 void
19 AccountManager_i::orb (CORBA::ORB_ptr o)
21 this->orb_ = CORBA::ORB::_duplicate (o);
24 void
25 AccountManager_i::poa (PortableServer::POA_ptr poa)
27 this->poa_ = PortableServer::POA::_duplicate (poa);
30 void
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.
38 Bank::Account_ptr
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
43 // appropriate value.
44 Account_i_var result;
45 if (hash_map_.find (name, result) != 0)
47 ACE_DEBUG ((LM_DEBUG,
48 ACE_TEXT ("[SERVER] Process/Thread Id : (%P/%t) Opening Account (%C,%8.2f)\n"),
49 name,
50 initial_balance));
52 Account_i *tmp = 0;
53 ACE_NEW_THROW_EX (tmp,
54 Account_i (name,
55 initial_balance),
56 CORBA::NO_MEMORY ());
57 result = 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)
71 ACE_DEBUG ((LM_DEBUG,
72 ACE_TEXT ("[SERVER] Process/Thread Id : (%P/%t) Account already exists for %C\n"),
73 name));
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 ();
81 // Shutdown.
82 void
83 AccountManager_i::close (Bank::Account_ptr account)
85 try
87 CORBA::String_var name = account->name ();
89 ACE_DEBUG((LM_DEBUG,
90 ACE_TEXT ("[SERVER] Process/Thread Id : (%P/%t) Closing Account for %C\n"),
91 name.in ()));
93 Account_i_var account;
94 if (hash_map_.unbind (name.in (), account) == -1)
96 if (TAO_debug_level > 0)
97 ACE_DEBUG((LM_DEBUG,
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");
116 void
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 ();