#include"account.h" #include #include using namespace std; class Account_impl : virtual public POA_Account{ private: CORBA::Long _balance; public: Account_impl(){ _balance = 0; } void deposit(CORBA::Long amount){ cout << "Server: deposit. Amount = " << amount << endl; if(amount>0){ _balance = _balance + amount; }else{ cout << "Server: Erro ao depositar. Amount = " << amount << endl; } } void withdraw(CORBA::Long amount){ cout << "Server: withdraw. Amount = " << amount << endl; if(_balance > amount){ _balance = _balance - amount; }else{ cout << "Server: Erro ao retirar. Amount = " << amount << endl; } } CORBA::Long balance(){ cout << "Server: balance. _balance = " << _balance << endl; return _balance; } }; int main(int argc, char* argv[]){ //INICIALIZANDO O ORB CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); //OBTENDO REFERENCIA DO RootPOA e do Manager CORBA::Object_var poaobj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poaobj); PortableServer::POAManager_var mgr = poa->the_POAManager(); //CRIANDO UMA ACCOUNT PortableServer::Servant account_servant = new Account_impl; //ATIVANDO UMA ACCOUNT CORBA::Object_var the_account = account_servant->_this(); //ESCREVENDO OS OBJETOS IOR NUM ARQUIVO CHAMADO "account.ior" CORBA::String_var ior = orb->object_to_string (the_account); ofstream of ("account.ior"); of << ior; of.close (); //Activate the POA and start serving requests cout << "Running." << endl; mgr->activate (); orb->run(); //Shutdown(never reached) poa->destroy(TRUE, TRUE); delete account_servant; return 0; }