1 / 15

Intro to TAO Programming

Intro to TAO Programming. Study the Hello example in ACE_wrappers/TAO/tests Show IDL definition, servant, server, and client code Show some IDL compiler generated code Show how to compile and run the test

tremain
Download Presentation

Intro to TAO Programming

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. Intro to TAO Programming • Study the Hello example in ACE_wrappers/TAO/tests • Show IDL definition, servant, server, and client code • Show some IDL compiler generated code • Show how to compile and run the test • Number of examples available under ACE_wrappers/TAO/tests and ACE_wrappers/TAO/examples • Understand the IDL->C++ Mapping for memory management issues Vanderbilt University, Spring 2003

  2. IDL definition module Test { /// A very simple interface interface Hello { /// Return a simple string string get_string (); /// A method to shutdown the ORB /// This method is used to simplify shutdown process oneway void shutdown (); }; }; Vanderbilt University, Spring 2003

  3. IDL Compiler-generated Skeleton Header /* ONLY RELEVANT DETAILS SHOWN */ // module becomes namespace namespace POA_Test { // interface becomes a class class Hello: public PortableServer::ServantBase { public: // returns an object reference. Used for implicit activation ::Test::Hello*_this (); // servant implements this operation virtual char * get_string () throw ((CORBA::SystemException)) = 0; }; Vanderbilt University, Spring 2003

  4. IDL Compiler-generated Stub Header File /* ONLY RELEVANT DETAILS SHOWN */ // module becomes namespace namespace Test { /* note how this is different */ // declare a smart pointer class Hello_var { /* details not shown */ }; // interface becomes a class class Hello: public virtual CORBA::Object { public: typedef Hello_ptr _ptr_type; typedef Hello_var _var_type; // The static operations. static Hello_ptr _duplicate (Hello_ptr obj); static Hello_ptr _narrow (CORBA::Object_ptr obj); Vanderbilt University, Spring 2003

  5. IDL Compiler-generated Stub header file (contd) static Hello_ptr _nil (void) { return (Hello_ptr)0; } // is_a virtual CORBA::Boolean _is_a (const char *type_id); // operation virtual char * get_string() throw ((CORBA::SystemException)); }; // end of class }; // end of namespace Vanderbilt University, Spring 2003

  6. Servant Header (Hello.h) // include the skeleton header #include “TestS.h“ // our implementation class Hello: public POA_Hello::Test { public: // ctor Hello (); virtual char * get_string () throw ((CORBA::SystemException)); }; Vanderbilt University, Spring 2003

  7. Servant Impl (Hello.cpp) #include “Hello.h" // operation Char * Hello::get_string() throw ((CORBA::SystemException)) { return CORBA::string_dup (“Hello There”); } Vanderbilt University, Spring 2003

  8. Server Code (server.cpp) #include “Hello.h" int main (int argc, char* argv[]) { try { // initialize the ORB CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "" /* the ORB name, it can be anything! */ ); // Get a reference to the RootPOA CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA“); Vanderbilt University, Spring 2003

  9. Server Code contd // narrow down to the correct reference PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in ()); // Set a POA Manager PortableServer::POAManager_var poa_manager = poa->the_POAManager (); // Activate the POA Manager (recall the state transition // diagram for POA Manager. By activating we are telling // the POA manager to start accepting requests poa_manager->activate (); Vanderbilt University, Spring 2003

  10. Server Code contd // Create the servant Hello hello; // This is not the best way, but for the sake // of simplicity lets have it that way. // Activate it and obtain the object reference Test::Hello_var h = hello._this (); CORBA::String_var ior = orb->object_to_string (h.in ()); // Write the IOR to a file. More sophisticated methods available Vanderbilt University, Spring 2003

  11. Server Code contd poa_manager->activate (); // Run the orb orb->run (); // Destroy the POA, waiting until the destruction terminates poa->destroy (1, 1); orb->destroy (); } // catch any exceptions beyond this } Vanderbilt University, Spring 2003

  12. Client code (client.cpp) int main (int argc, char *argv[]) { try { // initialize the ORB CORBA::ORB_var orb = CORBA::init (argc, argv, “”); // Make a CORBA object CORBA::Object_var tmp = orb->string_to_object(ior); // Create an Invocation Object Test::Hello_var hello = Test::Hello::_narrow(tmp.in ()); // Error checking if (CORBA::is_nil (hello.in ())) Vanderbilt University, Spring 2003

  13. Client code contd // now invoke a request CORBA::String_var the_string = hello->get_string (); // check return value and print it // Shutdown the server hello->shutdown (); } // put catch clauses here } // end of main Vanderbilt University, Spring 2003

  14. Makefile IDL_FILES = Test IDL_SRC = TestC.cpp TestS.cpp BIN = client server SRC = $(addsuffix .cpp, $(BIN) Hello) $(IDL_SRC) CLIENT_OBJS = client.o TestC.o SERVER_OBJS = server.o Hello.o $(IDL_SRC:.cpp=.o) TAO_IDLFLAGS += -Ge 1 server: $(addprefix $(VDIR),$(SERVER_OBJS)) $(LINK.cc) $(LDFLAGS) -o $@ $^ $(TAO_SRVR_LIBS) $(POSTLINK) client: $(addprefix $(VDIR),$(CLIENT_OBJS)) $(LINK.cc) $(LDFLAGS) -o $@ $^ $(TAO_CLNT_LIBS) $(POSTLINK) Vanderbilt University, Spring 2003

  15. Makefile (Contd.) server: $(addprefix (VDIR),$(SERVER_OBJS)) $(LINK.cc) $(LDFLAGS) -o $@ $^ $(TAO_SRVR_LIBS) $(POSTLINK) client: $(addprefix $(VDIR),$(CLIENT_OBJS)) $(LINK.cc) $(LDFLAGS) -o $@ $^ $(TAO_CLNT_LIBS) $(POSTLINK) Vanderbilt University, Spring 2003

More Related