Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Alt_Mapping / options.cpp
blobfc146142491adcca316a45c1d9ba39575ebdb4bd
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file options.cpp
7 * Options for the Param_Test application
9 * @author Jeff Parsonss
11 //=============================================================================
14 #include "options.h"
15 #include "tao/debug.h"
16 #include "ace/Read_Buffer.h"
17 #include "ace/Get_Opt.h"
18 #include "ace/OS_NS_string.h"
19 #include "ace/OS_NS_fcntl.h"
20 #include "ace/Log_Msg.h"
22 // Constructor.p
23 Options::Options (void)
24 : ior_ (CORBA::string_dup ("file://test.ior")),
25 test_type_ (Options::NO_TEST),
26 invoke_type_ (Options::SII),
27 loop_count_ (1),
28 debug_ (0),
29 shutdown_ (0)
33 Options::~Options (void)
37 // Parses the command line arguments and returns an error status.
39 int
40 Options::parse_args (int argc, ACE_TCHAR **argv)
42 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xdn:f:i:t:k:"));
43 int c;
44 int result;
46 while ((c = get_opts ()) != -1)
47 switch (c)
49 case 'd': // debug flag
50 TAO_debug_level++;
51 this->debug_ = 1;
52 break;
54 case 'x':
55 this->shutdown_ = 1;
56 break;
58 case 'n': // loop count
59 this->loop_count_ = (CORBA::ULong) ACE_OS::atoi (get_opts.opt_arg ());
60 break;
62 case 'f':
63 result = this->read_ior (get_opts.opt_arg ());
65 if (result < 0)
66 ACE_ERROR_RETURN ((LM_ERROR,
67 "Unable to read ior from %s : %p\n",
68 get_opts.opt_arg ()),
69 -1);
71 break;
73 case 'k':
74 this->ior_ = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ()));
75 break;
77 case 'i': // invocation
78 if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("dii")))
79 this->invoke_type_ = Options::DII;
80 break;
82 case 't': // data type
83 if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ubstring")))
84 this->test_type_ = Options::TEST_UB_STRING;
85 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ub_struct_seq")))
86 this->test_type_ = Options::TEST_UB_STRUCT_SEQUENCE;
87 break;
89 case '?':
90 default:
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "usage: %s"
93 " [-d]"
94 " [-n loopcount]"
95 " [-f servant-IOR-file]"
96 " [-i invocation (sii/dii)]"
97 " [-t data type]"
98 "\n",
99 argv [0]),
100 -1);
103 // Indicates successful parsing of command line.
104 return 0;
107 // Get the factory IOR from the file created by the server.
109 Options::read_ior (ACE_TCHAR *filename)
111 // Open the file for reading.
112 ACE_HANDLE f_handle = ACE_OS::open (filename, 0);
114 if (f_handle == ACE_INVALID_HANDLE)
115 ACE_ERROR_RETURN ((LM_ERROR,
116 "Unable to open %s for writing: %p\n",
117 filename),
118 -1);
119 ACE_Read_Buffer ior_buffer (f_handle, true);
120 this->ior_ = ior_buffer.read ();
122 if (this->ior_.in () == 0)
123 ACE_ERROR_RETURN ((LM_ERROR,
124 "Unable to allocate memory to read ior: %p\n"),
125 -1);
126 return 0;
129 char const *
130 Options::param_test_ior (void) const
132 return this->ior_.in ();
135 Options::TEST_TYPE
136 Options::test_type (void)
138 return this->test_type_;
141 Options::INVOKE_TYPE
142 Options::invoke_type (void)
144 return this->invoke_type_;
147 CORBA::ULong
148 Options::loop_count (void)
150 return this->loop_count_;
153 CORBA::Boolean
154 Options::debug (void) const
156 return this->debug_;
159 CORBA::Boolean
160 Options::shutdown (void) const
162 return this->shutdown_;
165 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton, Options, ACE_Recursive_Thread_Mutex);