Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / FT_App / FT_ReplicationManagerController.cpp
blob987f3814c900ab6a3197dfee6fd1e5425f2f87ec
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_;
44 TAO_FT_ReplicationManagerController::TAO_FT_ReplicationManagerController ()
45 : orb_ (CORBA::ORB::_nil())
46 , replication_manager_ (FT::ReplicationManager::_nil())
47 , rm_ior_ (0)
48 , shutdown_ (0)
52 TAO_FT_ReplicationManagerController::~TAO_FT_ReplicationManagerController ()
56 int TAO_FT_ReplicationManagerController::init (int &argc, ACE_TCHAR *argv[])
58 int result = 0;
60 try
62 // Initialize the ORB.
63 this->orb_ = CORBA::ORB_init (argc, argv);
65 // Parse arguments.
66 result = this->parse_args (argc, argv);
67 if (result == 0)
69 CORBA::Object_var obj = CORBA::Object::_nil ();
70 if (this->rm_ior_ != 0)
72 obj = this->orb_->string_to_object (
73 ACE_TEXT_ALWAYS_CHAR (this->rm_ior_));
75 else
77 obj = this->orb_->resolve_initial_references (
78 "ReplicationManager");
80 this->replication_manager_ = FT::ReplicationManager::_narrow (
81 obj.in());
82 if (CORBA::is_nil (this->replication_manager_.in()))
84 ACE_ERROR ((LM_ERROR,
85 ACE_TEXT ("TAO_FT_ReplicationManagerController::init: ")
86 ACE_TEXT ("Could not get Replication Manager's IOR.\n")
87 ));
88 result = -1;
92 catch (const CORBA::Exception& ex)
94 ex._tao_print_exception (
95 ACE_TEXT (
96 "TAO_FT_ReplicationManagerController::init:\n"));
97 result = -1;
100 return result;
104 int TAO_FT_ReplicationManagerController::parse_args (int &argc, ACE_TCHAR *argv[])
106 int result = 0;
108 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:x"));
109 int c;
111 while (result == 0 && (c = get_opts ()) != -1)
113 switch (c)
115 case 'k':
117 this->rm_ior_ = get_opts.opt_arg ();
118 break;
121 case 'x':
123 this->shutdown_ = 1;
124 break;
127 default:
128 ACE_OS::fprintf (stderr, "%s: Unknown argument - %c\n",
129 ACE_TEXT_ALWAYS_CHAR (argv[0]), c);
130 this->usage(stderr);
131 result = -1;
132 break;
134 case '?':
135 this->usage(stderr);
136 result = -1;
140 return result;
143 void TAO_FT_ReplicationManagerController::usage (FILE* out) const
145 ACE_OS::fprintf (out, "usage"
146 " -k <replication manager ior file>"
147 " -x (shutdown the Replication Manager)\n");
150 int TAO_FT_ReplicationManagerController::run ()
152 int result = 0;
156 if (this->shutdown_ == 1)
158 this->replication_manager_->shutdown ();
159 ACE_Time_Value tv (0, 500000);
160 ACE_OS::sleep (tv);
163 catch (const CORBA::Exception& ex)
165 ex._tao_print_exception (
166 ACE_TEXT ("TAO_FT_ReplicationManagerController::run:\n"));
167 result = -1;
170 return result;
173 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
175 int result = 0;
176 TAO_FT_ReplicationManagerController rmctrl;
177 result = rmctrl.init (argc, argv);
178 if (result == 0)
180 result = rmctrl.run ();
182 return result;