Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / FT_App / FT_ReplicationManagerController.cpp
blobcb90f1cdc6e94aff46e37a13d15b94539bf308cd
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 /////////////////////////////
13 // Public interface.
14 public:
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[]);
20 int run ();
22 /////////////////////////////
23 // Forbidden.
24 private:
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.
32 private:
33 void usage (FILE* out) const;
35 /////////////////////////////
36 // Data members.
37 private:
38 CORBA::ORB_var orb_;
39 FT::ReplicationManager_var replication_manager_;
40 const ACE_TCHAR *rm_ior_;
41 int shutdown_;
45 TAO_FT_ReplicationManagerController::TAO_FT_ReplicationManagerController ()
46 : orb_ (CORBA::ORB::_nil())
47 , replication_manager_ (FT::ReplicationManager::_nil())
48 , rm_ior_ (0)
49 , shutdown_ (0)
53 TAO_FT_ReplicationManagerController::~TAO_FT_ReplicationManagerController ()
57 int TAO_FT_ReplicationManagerController::init (int &argc, ACE_TCHAR *argv[])
59 int result = 0;
61 try
63 // Initialize the ORB.
64 this->orb_ = CORBA::ORB_init (argc, argv);
66 // Parse arguments.
67 result = this->parse_args (argc, argv);
68 if (result == 0)
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_));
76 else
78 obj = this->orb_->resolve_initial_references (
79 "ReplicationManager");
81 this->replication_manager_ = FT::ReplicationManager::_narrow (
82 obj.in());
83 if (CORBA::is_nil (this->replication_manager_.in()))
85 ACE_ERROR ((LM_ERROR,
86 ACE_TEXT ("TAO_FT_ReplicationManagerController::init: ")
87 ACE_TEXT ("Could not get Replication Manager's IOR.\n")
88 ));
89 result = -1;
93 catch (const CORBA::Exception& ex)
95 ex._tao_print_exception (
96 ACE_TEXT (
97 "TAO_FT_ReplicationManagerController::init:\n"));
98 result = -1;
101 return result;
105 int TAO_FT_ReplicationManagerController::parse_args (int &argc, ACE_TCHAR *argv[])
107 int result = 0;
109 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:x"));
110 int c;
112 while (result == 0 && (c = get_opts ()) != -1)
114 switch (c)
116 case 'k':
118 this->rm_ior_ = get_opts.opt_arg ();
119 break;
122 case 'x':
124 this->shutdown_ = 1;
125 break;
128 default:
129 ACE_OS::fprintf (stderr, "%s: Unknown argument - %c\n",
130 ACE_TEXT_ALWAYS_CHAR (argv[0]), c);
131 this->usage(stderr);
132 result = -1;
133 break;
135 case '?':
136 this->usage(stderr);
137 result = -1;
141 return result;
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 ()
153 int result = 0;
157 if (this->shutdown_ == 1)
159 this->replication_manager_->shutdown ();
160 ACE_Time_Value tv (0, 500000);
161 ACE_OS::sleep (tv);
164 catch (const CORBA::Exception& ex)
166 ex._tao_print_exception (
167 ACE_TEXT ("TAO_FT_ReplicationManagerController::run:\n"));
168 result = -1;
171 return result;
174 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
176 int result = 0;
177 TAO_FT_ReplicationManagerController rmctrl;
178 result = rmctrl.init (argc, argv);
179 if (result == 0)
181 result = rmctrl.run ();
183 return result;