diff options
author | pradeep <pradeep@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-09-16 00:33:14 +0000 |
---|---|---|
committer | pradeep <pradeep@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-09-16 00:33:14 +0000 |
commit | 6c5aa686d4ad5f060f765c517c3bb3439e121c36 (patch) | |
tree | 030b6eb83cb91d7ed737ed508d975e821c466a9b /TAO/tests | |
parent | 133dbfce2165db1767e518a626787a6d36d206e0 (diff) | |
download | ATCD-6c5aa686d4ad5f060f765c517c3bb3439e121c36.tar.gz |
*** empty log message ***
Diffstat (limited to 'TAO/tests')
-rw-r--r-- | TAO/tests/Simple/chat/Broadcaster.idl | 10 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/Broadcaster_i.cpp | 124 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/Broadcaster_i.h | 57 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/Receiver.idl | 4 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/Receiver_i.cpp | 12 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/Receiver_i.h | 21 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/client.cpp | 34 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/client_i.cpp | 202 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/client_i.h | 81 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/server.cpp | 52 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/server_i.cpp | 83 | ||||
-rw-r--r-- | TAO/tests/Simple/chat/server_i.h | 65 |
12 files changed, 668 insertions, 77 deletions
diff --git a/TAO/tests/Simple/chat/Broadcaster.idl b/TAO/tests/Simple/chat/Broadcaster.idl index 6398929e592..ccfce9e1686 100644 --- a/TAO/tests/Simple/chat/Broadcaster.idl +++ b/TAO/tests/Simple/chat/Broadcaster.idl @@ -6,10 +6,10 @@ interface Broadcaster { // = TITLE // This interface is to be implemented by the simple chat server. - // It broadcasts messages received from one registered client to all - // its registered clients. + // It broadcasts messages received from one registered client to + // all its registered clients. - exception CannotAdd + exception CannotAdd { string reason_; }; @@ -19,7 +19,7 @@ interface Broadcaster string reason_; }; - void add (in Receiver receiver) + void add (in Receiver receiver, in string nickname) raises (CannotAdd); // Registers a Receiver with the chat server. A registered client // must call un_register before it goes away. @@ -28,6 +28,6 @@ interface Broadcaster raises (CannotRemove); // Unregisters a Receiver. - void say (in string text); + void say (in Receiver receiver, in string text); // Say something to all registered clients. }; diff --git a/TAO/tests/Simple/chat/Broadcaster_i.cpp b/TAO/tests/Simple/chat/Broadcaster_i.cpp index 543a0781346..fc98e0d93b6 100644 --- a/TAO/tests/Simple/chat/Broadcaster_i.cpp +++ b/TAO/tests/Simple/chat/Broadcaster_i.cpp @@ -19,6 +19,17 @@ #include "Broadcaster_i.h" +int +Broadcaster_i::Receiver_Data::operator == (const Receiver_Data &receiver_data) const +{ + // The <_is_equivalent> function checks if the _var and _ptr objects + // are the same. NOTE: this call might not behave well on other + // ORBs since <_is_equivalent> isn't guaranteed to differentiate + // object references. + return this->receiver_.in()->_is_equivalent (receiver_data.receiver_) + && this->nickname_ == receiver_data.nickname_; +} + Broadcaster_i::Broadcaster_i (void) { } @@ -29,46 +40,121 @@ Broadcaster_i::~Broadcaster_i (void) void Broadcaster_i::add (Receiver_ptr receiver, + const char *nickname, CORBA::Environment &environment) { - // store the client information. - Receiver_var receiver = Receiver::_duplicate (receiver); - - // insert the Receiver reference to the set - if (receiver_set_.insert (receiver) == -1) - { - // Raise exception - environment.exception (new Broadcaster::CannotAdd (/* reason */)); - } + // @@ Please check and make sure that you fully qualify the + // Receiver_Data class with Broadcaster_i. + Broadcaster_i::Receiver_Data receiver_data; + + // Store the client information. + receiver_data.receiver_ = Receiver::_duplicate (receiver); + receiver_data.nickname_ = nickname; + + // Insert the Receiver reference to the set + if (receiver_set_.insert (receiver_data) == -1) + // Raise exception + environment.exception (new Broadcaster::CannotAdd + ("failed to add to the receiver set\n")); + // Tell everyone which person just joined the chat. + ACE_CString broadcast_string = + ACE_CString ("**** ") + + ACE_CString (nickname) + + ACE_CString (" has joined the chat ****\n"); + + this->broadcast (broadcast_string.fast_rep (), + environment); } void Broadcaster_i::remove (Receiver_ptr receiver, CORBA::Environment &environment) { - + Receiver_Data receiver_data_to_remove; + + for (RECEIVER_SET_ITERATOR iter = this->receiver_set_.begin (); + iter != this->receiver_set_.end (); + iter++) + { + // @@ Please put the comment about "non-portability" here, as + // well! + if ((*iter).receiver_.in ()->_is_equivalent (receiver) == 1) + { + receiver_data_to_remove = *iter; + break; + } + } + + // Remove the reference from our list. + + if (this->receiver_set_.remove (receiver_data_to_remove) == -1) + // Raise exception. + environment.exception(new Broadcaster::CannotRemove + ("failed to remove from receiver set\n")); + + // Tell everyone, which person left the chat. + ACE_CString broadcast_string = "**** " + + receiver_data_to_remove.nickname_ + + " left the chat" + + " ****\n"; + + this->broadcast (broadcast_string.fast_rep (), + environment); } -void -Broadcaster_i::say (const char *text, - CORBA::Environment &environment) +void +Broadcaster_i::say (Receiver_ptr receiver, + const char *text, + CORBA::Environment &TAO_TRY_ENV) { - CORBA::Environment TAO_TRY_ENV; - TAO_TRY { - // Broadcast the message to all registered clients + ACE_CString sender_nickname ("Sender Unknown"); + + // Find the nickname for this receiver. + for (RECEIVER_SET_ITERATOR iter = this->receiver_set_.begin (); - iter != this->receiver_set_.done (); + iter != this->receiver_set_.end (); iter++) { - (*iter)->message (msg, TAO_TRY_ENV); + // @@ Please add comment here.... + if ((*iter).receiver_.in ()->_is_equivalent (receiver) == 1) + { + sender_nickname = (*iter).nickname_; + } } + + // Broadcast the message to all registered clients + ACE_CString broadcast_string ("[" + sender_nickname + "] " + text); + + // @@ Please be consistent in your use of env vs. environment. + // In fact, I recommend you use the TAO macro TAO_TRY_ENV. + this->broadcast (broadcast_string.fast_rep (), + env); } TAO_CATCHANY { TAO_TRY_ENV.print_exception ("Broadcaster_i::say\t\n"); } - TAO_ENDTRY; } + +void +Broadcaster_i::broadcast (const char *text, + CORBA::Environment &_tao_environment) +{ + // Broadcast the message to all registered clients. + + for (RECEIVER_SET_ITERATOR iter = this->receiver_set_.begin (); + iter != this->receiver_set_.end (); + iter++) + { + // @@ You need to put in an exception handling check here for the + // case where something fails. I'm not sure what you should do, + // but you should probably print a message indicating which + // exception occurred and then keep processing the other + // receivers. + (*iter).receiver_->message (text, + _tao_environment); + } +} diff --git a/TAO/tests/Simple/chat/Broadcaster_i.h b/TAO/tests/Simple/chat/Broadcaster_i.h index 4b09a343265..1ee3ff96656 100644 --- a/TAO/tests/Simple/chat/Broadcaster_i.h +++ b/TAO/tests/Simple/chat/Broadcaster_i.h @@ -1,3 +1,4 @@ +/* -*- C++ -*- */ // $Id$ // =========================================================== @@ -28,45 +29,63 @@ class Broadcaster_i : public POA_Broadcaster { // = TITLE - // The implementation of the Broadcaster class which is the servant - // object for the chat server. - + // The implementation of the Broadcaster class, which is the + // servant object for the chat server. public: + // = Initialization and termination methods. Broadcaster_i (void); // Constructor ~Broadcaster_i (void); // Destructor - virtual CORBA::Long add (Receiver_ptr receiver, - const char * nickname, - CORBA::Environment &_tao_environment); - // saves receiver references in a list. + virtual void add (Receiver_ptr receiver, + const char *nickname, + CORBA::Environment &_tao_environment); + // Saves receiver references in a list. - virtual CORBA::Long remove (Receiver_ptr receiver, - CORBA::Environment &_tao_environment); - // removes receiver references from the list. + virtual void remove (Receiver_ptr receiver, + CORBA::Environment &_tao_environment); + // Removes receiver references from the list. - virtual void say (const char * text, + virtual void say (Receiver_ptr receiver, + const char *text, CORBA::Environment &_tao_environment); - // called by Broadcaster clients to send messages. + // Called by Broadcaster clients to send messages. private: TAO_ORB_Manager orb_manager_; - // the ORB manager. + // The ORB manager. + + void broadcast (const char* text, + CORBA::Environment &_tao_environment); + // Broadcasts the text to all registered clients. - struct Receiver_Data + class Receiver_Data { + // = TITLE + // Per-client info. + // + // = DESCRIPTION + // Saves the Receiver_var and user nickname. + public: + int operator == (const Receiver_Data &receiver_data) const; + // The == op required by the ACE_Unbounded set. + Receiver_var receiver_; - ACE_CString nick_; + // Stores the receiver reference. + + ACE_CString nickname_; + // Stores the client nickname. }; - // per client info - typedef ACE_Unbounded_Set<Receiver_Data> RECEIVER_SET; - typedef ACE_Unbounded_Set_Iterator<Receiver_Data> RECEIVER_SET_ITERATOR; + typedef ACE_Unbounded_Set<Receiver_Data> + RECEIVER_SET; + typedef ACE_Unbounded_Set_Iterator<Receiver_Data> + RECEIVER_SET_ITERATOR; RECEIVER_SET receiver_set_; - // set of registered clients. + // Set of registered clients. }; #endif /* BROADCASTER_I_H */ diff --git a/TAO/tests/Simple/chat/Receiver.idl b/TAO/tests/Simple/chat/Receiver.idl index 3a8ae47b3a7..04a8a77c390 100644 --- a/TAO/tests/Simple/chat/Receiver.idl +++ b/TAO/tests/Simple/chat/Receiver.idl @@ -7,8 +7,8 @@ interface Receiver // clients.The interface functions are called by the chat server. void message (in string msg); - // displays the message in the client application. + // Displays the message in the client application. oneway void shutdown (); - // called by the chat server before it goes away. + // Called by the chat server before it goes away. }; diff --git a/TAO/tests/Simple/chat/Receiver_i.cpp b/TAO/tests/Simple/chat/Receiver_i.cpp index 2797dfa7098..baebf861cc1 100644 --- a/TAO/tests/Simple/chat/Receiver_i.cpp +++ b/TAO/tests/Simple/chat/Receiver_i.cpp @@ -18,29 +18,27 @@ #include "Receiver_i.h" -Receiver_i::Receiver_i (void) +Receiver_i::Receiver_i (void) : orb_ (0) { } - Receiver_i::~Receiver_i (void) { } void -Receiver_i::message (const char *msg, +Receiver_i::message (const char *msg, CORBA::Environment &) { - ACE_DEBUG ((LM_DEBUG, ": %s\n", msg)); + ACE_DEBUG ((LM_DEBUG, + ": %s\n", + msg)); } void Receiver_i::shutdown (CORBA::Environment &) { - ACE_DEBUG ((LM_DEBUG, - "Receiver_i is shutting down\n")); - // Instruct the ORB to shutdown. this->orb_->shutdown (); } diff --git a/TAO/tests/Simple/chat/Receiver_i.h b/TAO/tests/Simple/chat/Receiver_i.h index 5dc74c82336..40499f0f3c1 100644 --- a/TAO/tests/Simple/chat/Receiver_i.h +++ b/TAO/tests/Simple/chat/Receiver_i.h @@ -1,3 +1,4 @@ +/* -*- C++ -*- */ // $Id$ // =========================================================== @@ -9,7 +10,7 @@ // Receiver_i.h // // = DESCRIPTION -// Defines the implementation header for the Receiver interface +// Defines the implementation header for the Receiver interface. // // = AUTHOR // Pradeep Gore <pradeep@cs.wustl.edu> @@ -27,25 +28,23 @@ class Receiver_i : public POA_Receiver // Receiver object implementation // // = DESCRIPTION - // This class has methods which are called by the chat server. - // - + // This class has methods that are called by the chat server. public: // = Initialization and termination methods. - Receiver_i (void); - // Constructor + // Constructor. ~Receiver_i (void); - // Destructor + // Destructor. - virtual void message (const char *msg, + virtual void message (const char *msg, CORBA::Environment &_tao_environment); - // receives a message string + // Receives a message string. virtual void shutdown (CORBA::Environment &_tao_environment); - // called when the chat server is going away. - // the client implementation should shutdown the chat client in response to this. + // Called when the chat server is going away. The client + // implementation should shutdown the chat client in response to + // this. void orb (CORBA::ORB_ptr o); // Set the ORB pointer. diff --git a/TAO/tests/Simple/chat/client.cpp b/TAO/tests/Simple/chat/client.cpp index 356c65aa1ad..8b78e9de11f 100644 --- a/TAO/tests/Simple/chat/client.cpp +++ b/TAO/tests/Simple/chat/client.cpp @@ -2,12 +2,11 @@ // =========================================================== // -// // = LIBRARY // TAO/tests/Simple/chat // // = FILENAME -// Chat.cpp +// client.cpp // // = DESCRIPTION // The Chat client program entry point. @@ -17,32 +16,39 @@ // // =========================================================== -#include "Chat_i.h" +#include "client_i.h" int -main(int argc, char* argv[]) +main (int argc, char *argv[]) { - printf("\n============= Simple Chat ===========\n"); - - char *nick = "chat client"; + char *nick; if (argc >= 2) nick = argv[1]; else - printf("\n usage: Chat <nickname>\n"); + ACE_ERROR_RETURN ((LM_ERROR, + "\n usage: client <nickname>\n"), + -1); TAO_TRY { - Chat_i chat_i ("chat.ior", nick); + ACE_DEBUG ((LM_DEBUG, + "\n============= Simple Chat ===========\n")); + + ACE_DEBUG ((LM_DEBUG, + "\n============= type 'quit' to exit ===========\n")); + + // @@ Please make the "chat.ior" an option or something you can + // override as a user. + Client_i client_i ("chat.ior", nick); - if (chat_i.init (argc, argv) == -1 || chat_i.run () == -1) - { - return -1; - } + if (client_i.init (argc, argv) == -1 + || client_i.run () == -1) + return -1; } TAO_CATCHANY { - TAO_TRY_ENV.print_exception ("chat::main\t\n"); + TAO_TRY_ENV.print_exception ("client::main\t\n"); return -1; } TAO_ENDTRY; diff --git a/TAO/tests/Simple/chat/client_i.cpp b/TAO/tests/Simple/chat/client_i.cpp new file mode 100644 index 00000000000..ba219c3ab0b --- /dev/null +++ b/TAO/tests/Simple/chat/client_i.cpp @@ -0,0 +1,202 @@ +// $Id$ + +// =========================================================== +// +// +// = LIBRARY +// TAO/tests/Simple/chat +// +// = FILENAME +// client_i.cpp +// +// = DESCRIPTION +// Implementation of the Client_i class. +// +// = AUTHOR +// Pradeep Gore <pradeep@cs.wustl.edu> +// +// =========================================================== + +#include "client_i.h" +#include "ace/Read_Buffer.h" +#include "tao/ORB.h" + +Client_i::Client_i (char *ior_file_name, + char *nick) + : ior_file_name_ (ior_file_name), + nickname_ (nickname) +{ +} + +Client_i::~Client_i (void) +{ + // Make sure to cleanup the STDIN handler. + if (ACE_Event_Handler::remove_stdin_handler + (TAO_ORB_Core_instance ()->reactor (), + TAO_ORB_Core_instance ()->thr_mgr ()) == -1) + ACE_ERROR ((LM_ERROR, + "%p\n", + "remove_stdin_handler")); +} + +int +Client_i::init (int argc, char *argv[]) +{ + CORBA::Environment TAO_TRY_ENV; + + TAO_TRY + { + // Retrieve the ORB. + this->orb_ = CORBA::ORB_init (argc, + argv, + 0, + TAO_TRY_ENV); + TAO_CHECK_ENV; + + // set the orb in the receiver_i_ object. + this->receiver_i_.orb (this->orb_); + + // read the ior from file + if (this->read_ior (this->ior_file_name_) != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "could not read the ior from the file: <%s>\n", + this->ior_file_name_), + -1); + + CORBA::Object_var server_object = + this->orb_->string_to_object (this->ior_, + TAO_TRY_ENV); + TAO_CHECK_ENV; + + if (CORBA::is_nil (server_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "invalid ior <%s>\n", + this->ior_), + -1); + + this->server_ = Broadcaster::_narrow (server_object.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("client_i::init\n"); + return -1; + } + TAO_ENDTRY; + + // Register our <Input_Handler> to handle STDIN events, which will + // trigger the <handle_input> method to process these events. + + if (ACE_Event_Handler::register_stdin_handler + (this, + TAO_ORB_Core_instance ()->reactor (), + TAO_ORB_Core_instance ()->thr_mgr ()) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "register_stdin_handler"), + -1); + return 0; +} + +int +Client_i::run (void) +{ + CORBA::Environment TAO_TRY_ENV; + + TAO_TRY + { + this->receiver_var_ = + this->receiver_i_._this (TAO_TRY_ENV); + TAO_CHECK_ENV; + + // Register ourselves with the server. + server_->add (this->receiver_var_.in (), + this->nick_, + TAO_TRY_ENV); + TAO_CHECK_ENV; + + // Run the ORB + this->orb_->run (); + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("Client_i::run ()"); + return -1; + } + TAO_ENDTRY; + + return 0; +} + +int +Client_i::handle_input (ACE_HANDLE) +{ + char buf[BUFSIZ]; + + if (ACE_OS::fgets (buf, BUFSIZ, stdin) == 0) + return 0; + + CORBA::Environment TAO_TRY_ENV; + + TAO_TRY + { + // Check if the user wants to quit. + if (ACE_OS::strncmp (buf, + QUIT_STRING, + ACE_OS::strlen (QUIT_STRING)) == 0) + { + // Remove ourselves from the server. + this->server_->remove (this->receiver_var_.in ()); + this->receiver_i_.shutdown (TAO_TRY_ENV); + return 0; + } + + // Call the server function <say> to pass the string typed by + // the server. + this->server_->say (this->receiver_var_.in (), + buf, + TAO_TRY_ENV); + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("Input_Handler::init"); + return -1; + } + TAO_ENDTRY; + return 0; +} + +int +Client_i::read_ior (const char *filename) +{ + // Open the file for reading. + ACE_HANDLE f_handle = ACE_OS::open (filename, 0); + + if (f_handle == ACE_INVALID_HANDLE) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to open %s for writing: %p\n", + filename, + "invalid handle"), + -1); + + ACE_Read_Buffer ior_buffer (f_handle); + char *data = ior_buffer.read (); + + if (data == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to read ior: %p\n"), + -1); + + this->ior_ = ACE_OS::strdup (data); + ior_buffer.alloc ()->free (data); + + ACE_OS::close (f_handle); + + if (this->ior_ == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "failed to read ior from file\n", + ""), + -1); + return 0; +} diff --git a/TAO/tests/Simple/chat/client_i.h b/TAO/tests/Simple/chat/client_i.h new file mode 100644 index 00000000000..3cbfe558063 --- /dev/null +++ b/TAO/tests/Simple/chat/client_i.h @@ -0,0 +1,81 @@ +// $Id$ + +// =========================================================== +// +// +// = LIBRARY +// TAO/tests/Simple/chat +// +// = FILENAME +// client_i.h +// +// = DESCRIPTION +// Definition of the Chat Client class, Client_i. +// +// = AUTHOR +// Pradeep Gore <pradeep@cs.wustl.edu> +// +// =========================================================== + +#if !defined (CLIENT_I_H) +#define CLIENT_I_H + +#include "Receiver_i.h" +#include "BroadcasterC.h" +#include "ace/Read_Buffer.h" +#include "tao/TAO.h" + +class Client_i : public ACE_Event_Handler +{ + // = TITLE + // Chat Client class. + // + // = DESCRIPTION + // Connects to the Chat server and registers the Receiver_i + // object with the chat server. It also takes in user chat + // messages and sends them to the server. +public: + // = Initialization and termination methods. + Client_i (char *ior_file_name, + char* nickname); + // Constructor. + + ~Client_i (void); + // Destructor. + + int init (int argc, char *argv[]); + // Initialize the client communication with the server. + + int run (void); + // Start the ORB object. + + virtual int handle_input (ACE_HANDLE); + // Handle the user input. + + private: + int read_ior (const char *filename); + // Function to read the server ior from a file. + + char *ior_; + // IOR of the obj ref of the server. + + const char* ior_file_name_; + // The filename that stores the ior of the server + + const char* nickname_; + // Nickname of the user chatting. + + Broadcaster_var server_; + // Server object ptr. + + CORBA::ORB_var orb_; + // Our orb. + + Receiver_i receiver_i_; + // The receiver object. + + Receiver_var receiver_var_; + // Pointer to the receiver object registered with the ORB. +}; + +#endif /* CLIENT_I_H */ diff --git a/TAO/tests/Simple/chat/server.cpp b/TAO/tests/Simple/chat/server.cpp new file mode 100644 index 00000000000..4166fcc41a2 --- /dev/null +++ b/TAO/tests/Simple/chat/server.cpp @@ -0,0 +1,52 @@ +// $Id$ + +// =========================================================== +// +// +// = LIBRARY +// TAO/tests/Simple/chat +// +// = FILENAME +// Server.cpp +// +// = DESCRIPTION +// Entry point for the chat server. +// +// = AUTHOR +// Pradeep Gore <pradeep@cs.wustl.edu> +// +// =========================================================== + +#include "server_i.h" + +int +main (int argc, char *argv[]) +{ + // @@ Please make the "chat.ior" be something that can be overridden + // by a user. + + Server_i server_i ("chat.ior"); + + CORBA::Environment TAO_TRY_ENV; + + TAO_TRY + { + ACE_DEBUG ((LM_DEBUG, + "Running chat server...\n")); + + if (server_i.init (argc, argv, TAO_TRY_ENV) != 0 + || server_i.run (TAO_TRY_ENV) != 0) + { + ACE_DEBUG((LM_DEBUG, "\n error in init or run.\n")); + return 1; + } + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("server::main\t\n"); + return 1; + } + TAO_ENDTRY; + + return 0; +} diff --git a/TAO/tests/Simple/chat/server_i.cpp b/TAO/tests/Simple/chat/server_i.cpp new file mode 100644 index 00000000000..8b5654d4a2b --- /dev/null +++ b/TAO/tests/Simple/chat/server_i.cpp @@ -0,0 +1,83 @@ +// $Id$ + +// =========================================================== +// +// +// = LIBRARY +// TAO/tests/Simple/chat +// +// = FILENAME +// Server_i.cpp +// +// = DESCRIPTION +// Implementation of the Chat Server_i class. +// +// = AUTHOR +// Pradeep Gore <pradeep@cs.wustl.edu> +// +// =========================================================== + +#include "server_i.h" + +Server_i::Server_i (char *ior_file_name) + : ior_file_name_ (ior_file_name) +{ +} + +Server_i::~Server_i (void) +{ +} + +int +Server_i::init (int argc, + char *argv[], + CORBA::Environment &env) +{ + if (this->orb_manager_.init (argc, + argv, + env) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "init_child_poa"), + -1); + + TAO_CHECK_ENV_RETURN (env, -1); + + CORBA::ORB_var orb = this->orb_manager_.orb (); + + // Activate the servant in its own child POA. + + CORBA::String_var str = + this->orb_manager_.activate (&(this->broadcaster_i_), + env); + this->writeIOR (str.in()); + return 0; +} + +int +Server_i::run (CORBA::Environment &env) +{ + // Run the main event loop for the ORB. + if (this->orb_manager_.run (env) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Server_i::run"), + -1); + return 0; +} + +int +Server_i::writeIOR(const char* ior) +{ + FILE* ior_output_file_ = + ACE_OS::fopen (this->ior_file_name_, "w"); + + if (ior_output_file_) + { + ACE_OS::fprintf (ior_output_file_, + "%s", + ior); + ACE_OS::fclose (ior_output_file_); + } + + return 0; +} diff --git a/TAO/tests/Simple/chat/server_i.h b/TAO/tests/Simple/chat/server_i.h new file mode 100644 index 00000000000..0871f1fb296 --- /dev/null +++ b/TAO/tests/Simple/chat/server_i.h @@ -0,0 +1,65 @@ +/* -*- C++ -*- */ +// $Id$ + +// =========================================================== +// +// +// = LIBRARY +// TAO/tests/Simple/chat +// +// = FILENAME +// Server_i.h +// +// = DESCRIPTION +// Definition of the Chat Server_i class. +// +// = AUTHOR +// Pradeep Gore <pradeep@cs.wustl.edu> +// +// =========================================================== + +#if !defined (SERVER_I_H) +#define SERVER_I_H + +#include "Broadcaster_i.h" +#include "tao/TAO.h" + +class Server_i +{ + // = TITLE + // The class defines the server for the chat. It sets up the Orb + // manager and registers the Broadcaster servant object. + +public: + // = Initialization and termination methods. + Server_i (char *ior_file_name); + // Constructor. + + ~Server_i (void); + // Destructor. + + int init (int argc, + char *argv[], + CORBA::Environment &env); + // Initialize the server. + + int run (CORBA::Environment &env); + // Run the ORB. + +private: + // @@ Please rename this to write_IOR. + int writeIOR(const char* ior); + // Writes the server ior to a file, for the clients to pick up + // later. + + char *ior_file_name_; + // The file name to save the ior to. + + TAO_ORB_Manager orb_manager_; + // The tao orb manager object. + + Broadcaster_i broadcaster_i_; + // The servant object registered with the orb. +}; + +#endif /* SERVER_I_H */ |