1 / 7

Efficient Messaging and Banking Interface Implementation with CORBA

This document describes the implementation of a messaging service and a banking example using CORBA (Common Object Request Broker Architecture). The Messenger interface allows users to send messages with a specified subject and username. The banking module includes an account management system that supports depositing funds and writing checks while handling exceptions for bad checks. The implementation follows the IDL (Interface Definition Language) with specific methods for message transmission and banking operations, showcasing both client and server interactions.

lea
Télécharger la présentation

Efficient Messaging and Banking Interface Implementation with CORBA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. // messenger.idl interface Messenger { boolean send_message ( in string user_name, in string subject, inout string message ); };

  2. module BankExample { interface Account { exception BadCheck { float fee; }; float deposit(in float amount); float writeCheck(in float amount) raises (BadCheck); }; interface AccountManager { Account openAccount(in string name); }; };

  3. IDL File Client Object Implementation (Servant) IDL Stub IDL Skeleton Request Object Request Broker CORBA Diagram (c) 2001 A. David McKinnon, used with permission

  4. #include <Messenger_skel.h> class Messenger_impl : public POA_Messenger, public PortableServer::RefCountServantBase { public: virtual bool send_message (const char* user_name, const char* subject, char*& message) throw(CORBA::SystemException); };

  5. int main(int argc, char *argv[]) { int status = EXIT_SUCCESS; CORBA::ORB_var orb; try { orb = CORBA::ORB_init(argc,argv); status = run(orb); } catch(const CORBA::Exception&) { status = EXIT_FAILURE; } if (!CORBA::is_nil(orb)) { try { orb->destroy(); } catch(const CORBA::Exception&) { status = EXIT_FAILURE; } } return status; }

  6. int run(CORBA::ORB_ptr orb) { const char* refFile = "Messenger.ref"; ifstream in(refFile); char s [2048]; in >> s; in.close(); CORBA::Object_var obj = orb->string_to_object(s); CORBA::String_var message = CORBA::string_dup("Howdy!"); Messenger_var messenger = Messenger::_narrow(obj); if (messenger->send_message("hauser", "Test message", message.inout())) { cout << "server ok" << endl; cout << "Return message from server: " << message << endl; } else { cout << "server returned false" << endl; cout << "Return message from server: " << message << endl; } return 0; }

  7. int run(CORBA::ORB_ptr orb) { CORBA::Object_var poaObj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var rootPoa = PortableServer::POA::_narrow(poaObj); PortableServer::POAManager_var manager = rootPoa->the_POAManager(); Messenger_impl* messengerImpl = new Messenger_impl(); PortableServer::ServantBase_var servant = messengerImpl; Messenger_var messenger = messengerImpl -> _this(); CORBA::String_var s = orb -> object_to_string(messenger); const char* refFile = "Messenger.ref"; ofstream out(refFile); out << s << endl; out.close(); manager -> activate(); orb->run(); return EXIT_SUCCESS; }

More Related