1 #include "orbsvcs/FT_ReplicationManagerC.h"
2 #include <ace/Get_Opt.h>
3 // FUZZ: disable check_for_streams_include
4 #include "ace/streams.h"
5 #include "ace/OS_NS_unistd.h"
6 #include "ace/OS_NS_stdio.h"
8 // A simple class for building a client that "controls' the
9 // Replication Manager (right now it just shuts it down).
10 class TAO_FT_ReplicationManagerController
12 /////////////////////////////
15 TAO_FT_ReplicationManagerController ();
16 virtual ~TAO_FT_ReplicationManagerController ();
18 int init (int &argc
, ACE_TCHAR
*argv
[]);
19 int parse_args (int &argc
, ACE_TCHAR
*argv
[]);
22 /////////////////////////////
25 TAO_FT_ReplicationManagerController (
26 const TAO_FT_ReplicationManagerController
& rhs
);
27 TAO_FT_ReplicationManagerController
& operator = (
28 const TAO_FT_ReplicationManagerController
& rhs
);
30 /////////////////////////////
31 // Private implementation.
33 void usage (FILE* out
) const;
35 /////////////////////////////
39 FT::ReplicationManager_var replication_manager_
;
40 const ACE_TCHAR
*rm_ior_
;
45 TAO_FT_ReplicationManagerController::TAO_FT_ReplicationManagerController ()
46 : orb_ (CORBA::ORB::_nil())
47 , replication_manager_ (FT::ReplicationManager::_nil())
53 TAO_FT_ReplicationManagerController::~TAO_FT_ReplicationManagerController ()
57 int TAO_FT_ReplicationManagerController::init (int &argc
, ACE_TCHAR
*argv
[])
63 // Initialize the ORB.
64 this->orb_
= CORBA::ORB_init (argc
, argv
);
67 result
= this->parse_args (argc
, argv
);
70 CORBA::Object_var obj
= CORBA::Object::_nil ();
71 if (this->rm_ior_
!= 0)
73 obj
= this->orb_
->string_to_object (
74 ACE_TEXT_ALWAYS_CHAR (this->rm_ior_
));
78 obj
= this->orb_
->resolve_initial_references (
79 "ReplicationManager");
81 this->replication_manager_
= FT::ReplicationManager::_narrow (
83 if (CORBA::is_nil (this->replication_manager_
.in()))
86 ACE_TEXT ("TAO_FT_ReplicationManagerController::init: ")
87 ACE_TEXT ("Could not get Replication Manager's IOR.\n")
93 catch (const CORBA::Exception
& ex
)
95 ex
._tao_print_exception (
97 "TAO_FT_ReplicationManagerController::init:\n"));
105 int TAO_FT_ReplicationManagerController::parse_args (int &argc
, ACE_TCHAR
*argv
[])
109 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:x"));
112 while (result
== 0 && (c
= get_opts ()) != -1)
118 this->rm_ior_
= get_opts
.opt_arg ();
129 ACE_OS::fprintf (stderr
, "%s: Unknown argument - %c\n",
130 ACE_TEXT_ALWAYS_CHAR (argv
[0]), c
);
144 void TAO_FT_ReplicationManagerController::usage (FILE* out
) const
146 ACE_OS::fprintf (out
, "usage"
147 " -k <replication manager ior file>"
148 " -x (shutdown the Replication Manager)\n");
151 int TAO_FT_ReplicationManagerController::run ()
157 if (this->shutdown_
== 1)
159 this->replication_manager_
->shutdown ();
160 ACE_Time_Value
tv (0, 500000);
164 catch (const CORBA::Exception
& ex
)
166 ex
._tao_print_exception (
167 ACE_TEXT ("TAO_FT_ReplicationManagerController::run:\n"));
174 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
177 TAO_FT_ReplicationManagerController rmctrl
;
178 result
= rmctrl
.init (argc
, argv
);
181 result
= rmctrl
.run ();