Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / ORB_Local_Config / Two_DLL_ORB / ORB_DLL.cpp
blobfd1da26caebb993979fea497401ad29573e91e72
1 // -*- C++ -*-
2 #include "ORB_DLL.h"
3 #include "ace/Service_Config.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/OS_NS_strings.h"
7 #include "ace/Arg_Shifter.h"
8 #include "ace/Log_Msg.h"
10 Abstract_Worker::Abstract_Worker (const ACE_TCHAR *s)
11 : ior_file_ (s)
16 Abstract_Worker::~Abstract_Worker ()
21 Service_Config_ORB_DLL::Service_Config_ORB_DLL ()
22 : is_server_ (-1)
23 , worker_ (nullptr)
24 , argv_ (nullptr)
29 Service_Config_ORB_DLL::~Service_Config_ORB_DLL ()
34 int
35 Service_Config_ORB_DLL::init (int argc, ACE_TCHAR *argv[])
37 ACE_Arg_Shifter arg_shifter (argc, argv);
39 while (arg_shifter.is_anything_left ())
41 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-c")) == 0)
43 this->is_server_ = 0;
44 arg_shifter.consume_arg();
46 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-s")) == 0)
48 this->is_server_ = 1;
49 arg_shifter.consume_arg();
51 else
52 arg_shifter.ignore_arg();
55 if (this->is_server_ < 0)
56 ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) You must specify -c(lient) or -s(erver) argument. Aborting."), -1);
58 ACE_TCHAR **temp_argv = new ACE_TCHAR*[argc+1];
59 for (int i = 0; i < argc; i++)
61 temp_argv[i] = new ACE_TCHAR[ACE_OS::strlen(argv[i])+1];
62 ACE_OS::strcpy (temp_argv[i],argv[i]);
64 temp_argv[argc] = 0;
66 ACE_ARGV* tmp = 0;
67 ACE_NEW_RETURN (tmp, ACE_ARGV (temp_argv), -1);
68 this->argv_.reset (tmp);
69 for (int i = 0; i < argc; i++)
70 delete [] temp_argv[i];
71 delete [] temp_argv;
73 Abstract_Worker* worker = 0;
74 if (this->is_server_)
76 ACE_NEW_RETURN (worker, Server_Worker, -1);
78 else
80 ACE_NEW_RETURN (worker, Client_Worker, -1);
82 this->worker_.reset (worker);
84 #if defined (ACE_HAS_THREADS)
85 ACE_DEBUG ((LM_DEBUG,
86 ACE_TEXT ("(%P|%t) About to activate %s, argv[%d]=\'%s\' ...\n"),
87 this->worker_->kind (),
88 this->argv_->argc (),
89 this->argv_->buf ()));
91 // Become an Active Object if more than one argument passed.
92 // Two arguments indicate two "test objects" to be dynamically
93 // loaded.
94 return this->activate ();
95 #else
96 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) Threading support is required for this test. Aborting.")), -1);
97 #endif /* ACE_HAS_THREADS */
101 Service_Config_ORB_DLL::svc ()
103 ACE_ASSERT (this->worker_.get () != 0);
104 ACE_ASSERT (this->argv_.get () != 0);
108 ACE_DEBUG ((LM_DEBUG,
109 ACE_TEXT ("(%P|%t) %@ %s is active, argv[%d]=\'%s\'\n"),
110 this,
111 this->worker_->kind (),
112 this->argv_->argc (),
113 this->argv_->buf ()));
115 int ret = this->worker_->test_main (this->argv_->argc (),
116 this->argv_->argv ());
118 ACE_DEBUG ((LM_DEBUG,
119 ACE_TEXT ("(%P|%t) %@ %s bows out - so long, cruel world! (%d)\n"),
120 this,
121 this->worker_->kind (),
122 ret));
123 return ret;
125 catch (const CORBA::Exception& ex)
127 ex._tao_print_exception (ACE_TEXT("Failure:"));
128 ACE_ERROR_RETURN ((LM_ERROR,
129 ACE_TEXT ("(%P|%t) Aborting.\n")),
130 -1);
134 // Define our service for using with the Service Configurator
135 ACE_FACTORY_DEFINE (Service_Config_ORB_DLL, Service_Config_ORB_DLL)