Download presentation
Presentation is loading. Please wait.
Published byDoreen Weaver Modified over 9 years ago
1
1 Aniruddha Gokhale Vanderbilt University, Spring 2003 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
2
2 Aniruddha Gokhale Vanderbilt University, Spring 2003 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 (); };
3
3 Aniruddha Gokhale Vanderbilt University, Spring 2003 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; };
4
4 Aniruddha Gokhale Vanderbilt University, Spring 2003 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);
5
5 Aniruddha Gokhale Vanderbilt University, Spring 2003 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
6
6 Aniruddha Gokhale Vanderbilt University, Spring 2003 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)); };
7
7 Aniruddha Gokhale Vanderbilt University, Spring 2003 Servant Impl (Hello.cpp) #include “Hello.h" // operation Char * Hello::get_string() throw ((CORBA::SystemException)) { return CORBA::string_dup (“Hello There”); }
8
8 Aniruddha Gokhale Vanderbilt University, Spring 2003 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“);
9
9 Aniruddha Gokhale Vanderbilt University, Spring 2003 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 ();
10
10 Aniruddha Gokhale Vanderbilt University, Spring 2003 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
11
11 Aniruddha Gokhale Vanderbilt University, Spring 2003 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 }
12
12 Aniruddha Gokhale Vanderbilt University, Spring 2003 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 ()))
13
13 Aniruddha Gokhale Vanderbilt University, Spring 2003 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
14
14 Aniruddha Gokhale Vanderbilt University, Spring 2003 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)
15
15 Aniruddha Gokhale Vanderbilt University, Spring 2003 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)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.