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
)
16 Abstract_Worker::~Abstract_Worker ()
21 Service_Config_ORB_DLL::Service_Config_ORB_DLL ()
29 Service_Config_ORB_DLL::~Service_Config_ORB_DLL ()
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)
44 arg_shifter
.consume_arg();
46 else if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT ("-s")) == 0)
49 arg_shifter
.consume_arg();
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
]);
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
];
73 Abstract_Worker
* worker
= 0;
76 ACE_NEW_RETURN (worker
, Server_Worker
, -1);
80 ACE_NEW_RETURN (worker
, Client_Worker
, -1);
82 this->worker_
.reset (worker
);
84 #if defined (ACE_HAS_THREADS)
86 ACE_TEXT ("(%P|%t) About to activate %s, argv[%d]=\'%s\' ...\n"),
87 this->worker_
->kind (),
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
94 return this->activate ();
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"),
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"),
121 this->worker_
->kind (),
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")),
134 // Define our service for using with the Service Configurator
135 ACE_FACTORY_DEFINE (Service_Config_ORB_DLL
, Service_Config_ORB_DLL
)