📄 client_test.cpp
字号:
// Client_Test.cpp,v 4.21 2005/12/21 19:16:00 jwillemsen Exp#define ACE_BUILD_SVC_DLL#include "ace/Service_Config.h"#include "ace/Naming_Context.h"#include "ace/Dynamic_Service.h"#include "ace/Thread_Manager.h"#include "Client_Test.h"#include "ace/Reactor.h"#include "ace/os_include/os_ctype.h"#include "ace/OS_NS_signal.h"#include "ace/OS_NS_stdio.h"#include "ace/OS_NS_string.h"#include "ace/OS_NS_unistd.h"#include "ace/os_include/os_assert.h"ACE_RCSID (Client, Client_Test, "Client_Test.cpp,v 4.21 2005/12/21 19:16:00 jwillemsen Exp")class ACE_Svc_Export Client_Test : public ACE_Service_Object{public: Client_Test (void); int open (void); // Cache reactor and then register self with reactor int close (void); // Close things down and free up resources. virtual int handle_input (ACE_HANDLE handle); // Handle user entered commands virtual int init (int argc, ACE_TCHAR *argv[]); // Initialize name options and naming context when dynamically // linked. virtual int fini (void); // Close down the test when dynamically unlinked. void list_options (void); // Print name options int bind (const char *key, const char *value, const char *type = ""); // Bind a key to a value int unbind (const char *key); // Unbind a name binding int rebind (const char *key, const char *value, const char *type = ""); // Rebind a name binding int find (const char *key); // Find the value associated with a key int list_names (const char *pattern); // Find all names that match pattern int list_values (const char *pattern); // Find all values that match pattern int list_types (const char *pattern); // Find all types that match pattern int list_name_entries (const char *pattern); // Find all names that match pattern int list_value_entries (const char *pattern); // Find all values that match pattern int list_type_entries (const char *pattern); // Find all types that match patternprivate: ACE_Name_Options *name_options_; // Name Options associated with the Naming Context void display_menu (void); // Display user menu int set_proc_local (void); // Set options to use PROC_LOCAL naming context int set_node_local (void); // Set options to use NODE_LOCAL naming context int set_host (const char *hostname, int port); // Set options to use NET_LOCAL naming context specifying host name // and port number int quit (void); // Gracefully exit};// The following Factory is used by the ACE_Service_Config and// svc.conf file to dynamically initialize the state of the client// test.ACE_SVC_FACTORY_DEFINE (Client_Test)// Get the instance of Name_Service using Dynamic_Service//inline Name_Service *//NAME_SERVICE (void)inline ACE_Naming_Context *NAMING_CONTEXT (void){ return ACE_Dynamic_Service<ACE_Naming_Context>::instance ("ACE_Naming_Context");}Client_Test::Client_Test (void){ ACE_DEBUG ((LM_DEBUG, "Client_Test::Client_Test\n"));}intClient_Test::init (int /* argc */, ACE_TCHAR * /* argv */ []){ ACE_DEBUG ((LM_DEBUG, "Client_Test::init\n")); // Cache the name options. this->name_options_ = NAMING_CONTEXT ()->name_options (); return this->open ();}intClient_Test::open (void){ this->display_menu (); if (ACE_Event_Handler::register_stdin_handler (this, ACE_Reactor::instance (), ACE_Thread_Manager::instance ()) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "register_stdin_handler"), -1); return 0;}intClient_Test::close (void){ // Deregister this handler with the ACE_Reactor. return ACE_Reactor::instance ()->remove_handler (ACE_STDIN, ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::READ_MASK);}intClient_Test::fini (void){ ACE_DEBUG ((LM_DEBUG, "Client_Test::fini\n")); return this->close ();}intClient_Test::handle_input (ACE_HANDLE){ char option[BUFSIZ]; char buf1[BUFSIZ]; char buf2[BUFSIZ]; char buf3[BUFSIZ]; char *temp_buf; int port; char input[1024]; if (::scanf ("%s", option) <= 0) ACE_ERROR_RETURN ((LM_ERROR, "%p Try again!\n", "Client_Test::handle_input"), 0); int result = -1; switch (isupper (option[0]) ? tolower (option[0]) : option[0]) { case 'p' : result = this->set_proc_local (); break; case 'n' : result = this->set_node_local (); break; case 'h' : if (::scanf ("%s %d", buf1, &port) <= 0) break; result = this->set_host (buf1, port); break; case 'b' : // get the input from stdin ACE_OS::fgets (input, sizeof input, stdin); // get the key if ((temp_buf = ACE_OS::strtok (input, " "))) { ACE_OS::strcpy (buf1, temp_buf); temp_buf = ACE_OS::strtok (0, " "); // get the value if (temp_buf) { ACE_OS::strcpy (buf2, temp_buf); temp_buf = ACE_OS::strtok (0, " "); // get the type (if entered). if (temp_buf) { ACE_OS::strcpy (buf3, temp_buf); result = this->bind (buf1, buf2, buf3); } else result = this->bind (buf1, buf2); } else ACE_ERROR ((LM_ERROR, "Bind Failed! Value not entered.\n")); } else ACE_ERROR ((LM_ERROR, "Bind Failed! Key and Value not entered.\n")); break; case 'u' : if (::scanf ("%s", buf1) <= 0) break; result = this->unbind (buf1); break; case 'r' : // get the input from stdin ACE_OS::fgets (input, sizeof input, stdin); temp_buf = ACE_OS::strtok (input, " "); // get the key if (temp_buf) { ACE_OS::strcpy (buf1, temp_buf); temp_buf = ACE_OS::strtok (0, " "); // get the value if (temp_buf) { ACE_OS::strcpy (buf2, temp_buf); temp_buf = ACE_OS::strtok (0, " "); // get the type (if entered) if (temp_buf) { ACE_OS::strcpy (buf3, temp_buf); result = this->rebind (buf1, buf2, buf3); } else result = this->rebind (buf1, buf2); } else ACE_ERROR ((LM_ERROR, "Rebind Failed! Value not entered.\n")); } else ACE_ERROR ((LM_ERROR, "Reind Failed! Key and value not entered.\n")); break; case 'f' : if (::scanf ("%s", buf1) <= 0) break; result = this->find (buf1); break; case 'j' : if (::scanf ("%s", buf1) <= 0) break; else result = this->list_names (buf1); break; case 'k' : if (::scanf ("%s", buf1) <= 0) break; else result = this->list_values (buf1); break; case 'l' : if (::scanf ("%s", buf1) <= 0) break; else result = this->list_types (buf1); break; case 'c' : if (::scanf ("%s", buf1) <= 0) break; else result = this->list_name_entries (buf1); break; case 'd' : if (::scanf ("%s", buf1) <= 0) break; else result = this->list_value_entries (buf1); break; case 'e' : if (::scanf ("%s", buf1) <= 0) break; else result = this->list_type_entries (buf1); break; case 'q' : result = this->quit (); break; default : ACE_DEBUG ((LM_DEBUG, "Unrecognized command.\n")); } this->display_menu (); return result;}voidClient_Test::display_menu (void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -