📄 main.cpp
字号:
// main.cpp,v 1.9 2002/01/29 20:20:56 okellogg Exp
// ========================================================================
//
// = FILE
// Program to test the property services.
//
// = DESCRIPTION
// Here all the objects are at one address space. See the
// client.cpp and server.cpp to see property calls on remote
// objects.
//
// = AUTHOR
// Alexander Babu Arulanthu <alex@cs.wustl.edu>
//
// ========================================================================
#include "orbsvcs/CosPropertyServiceS.h"
#include "orbsvcs/Property/CosPropertyService_i.h"
ACE_RCSID(CosPropertyService, main, "main.cpp,v 1.9 2002/01/29 20:20:56 okellogg Exp")
class TAO_PropertySet_Tester
{
// = TITLE
// The testing code for the PropertySet interface are grouped
// under the functions of this class.
//
// = DESCRIPTION
// Go thru the functions to understand the usage of the various
// methods of the PropertySet interaface.
public:
friend class TAO_PropertyNamesIterator_Tester;
// He has to instantiate TAO_NamesIterator class using the instance
// of TAO_PropertySet.
TAO_PropertySet_Tester (void);
// Constructor.
~TAO_PropertySet_Tester (void);
// Destructor.
int test_define_property (ACE_ENV_SINGLE_ARG_DECL);
// Defines a char,a short, a long, a float and a string property.
int test_get_number_of_properties (ACE_ENV_SINGLE_ARG_DECL);
// Gets the number of properties currently defined in the PropertySet.
int test_delete_property (const char *property_name
ACE_ENV_ARG_DECL);
// Delete a given property.
int test_is_property_defined (ACE_ENV_SINGLE_ARG_DECL);
// Check the following properties are defined or
// no. "char_property", "short_property" and a "string_property".
int test_get_property_value (ACE_ENV_SINGLE_ARG_DECL);
// Get the "float_property" and "string_property" and print them
// out.
int test_delete_properties (ACE_ENV_SINGLE_ARG_DECL);
// Delete char, short,long, and string properties.
int test_delete_all_properties (ACE_ENV_SINGLE_ARG_DECL);
// Delete all the properties.
int test_define_properties (ACE_ENV_SINGLE_ARG_DECL);
// Define a sequence of properties. a char, a short, a long, a float
// and a string.
private:
TAO_PropertySet property_set_;
// The PropertySet.
};
class TAO_PropertyNamesIterator_Tester
{
// = TITLE
// The testing code for the PropertyNamesIterator interface are grouped
// under the functions of this class.
//
// = DESCRIPTION
// Go thru the functions to understand the usage of the various
// methods of the PropertyNamesIterator interaface.
public:
TAO_PropertyNamesIterator_Tester (TAO_PropertySet_Tester &propertyset_tester);
// Constructor. To make names iterator from the property set object.
~TAO_PropertyNamesIterator_Tester (void);
// Destructor.
int test_next_one (ACE_ENV_SINGLE_ARG_DECL);
// Test next one method. Iterate thru all the names in the
// PropertySet and print them out.
int test_reset (ACE_ENV_SINGLE_ARG_DECL);
// Test the reset method.
int test_next_n (size_t n ACE_ENV_ARG_DECL);
// Test the next_n method.
private:
TAO_PropertyNamesIterator iterator_;
// Our names iterator.
};
// Constructor.
TAO_PropertySet_Tester::TAO_PropertySet_Tester (void)
{
}
// Destructor.
TAO_PropertySet_Tester::~TAO_PropertySet_Tester (void)
{
}
// Defines a char, a short, a long, a float and a string.
int
TAO_PropertySet_Tester::test_define_property (ACE_ENV_SINGLE_ARG_DECL)
{
ACE_DEBUG ((LM_DEBUG,
"\nChecking define_property\n"));
CORBA::Any anyval;
// Prepare a char and "define" that in the PropertySet.
CORBA::Char ch = '#';
anyval <<= from_char (ch);
ch = '*';
anyval >>= to_char (ch);
ACE_DEBUG ((LM_DEBUG,
"Main : Char ch = %c\n",
ch));
property_set_.define_property ("char_property",
anyval
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN ( 1);
// Prepare a Short and "define" that in the PropertySet.
CORBA::Short s = 3;
anyval <<= s;
s = 7;
anyval >>= s;
ACE_DEBUG ((LM_DEBUG,
"Main : Short s = %d\n",
s));
property_set_.define_property ("short_property",
anyval
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN ( 1);
// Prepare a Long and "define" that in the PropertySet.
CORBA::Long l = 931232;
anyval <<= l;
l = 931233;
anyval >>= l;
ACE_DEBUG ((LM_DEBUG,
"Main : Long l = %d\n",
l));
CORBA::Any newany(anyval);
property_set_.define_property ("long_property",
anyval
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN ( 1);
// Prepare a Float and "define" that in the PropertySet.
CORBA::Float f = 3.14;
anyval <<= f;
f = 4.14;
anyval >>= f;
ACE_DEBUG ((LM_DEBUG,
"Main : Float f = %f\n",
f));
property_set_.define_property ("float_property",
anyval
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN ( 1);
// Prepare a String and "define" that in the PropertySet.
ACE_DEBUG ((LM_DEBUG,
"Main: Any holding String\n"));
CORBA::String_var strvar (CORBA::string_dup ("Test_String"));
anyval <<= strvar.in ();
CORBA::String newstr;
anyval >>= newstr;
ACE_DEBUG ((LM_DEBUG,
"Main: String : %s, From any : %s\n",
strvar.in (),
newstr));
property_set_.define_property ("string_property",
anyval
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN ( 1);
return 0;
}
// Testing, get_number_of_properties.
int
TAO_PropertySet_Tester::test_get_number_of_properties (ACE_ENV_SINGLE_ARG_DECL)
{
ACE_DEBUG ((LM_DEBUG,
"Main : Number of props : %d\n",
property_set_.get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER)));
ACE_CHECK_RETURN ( 1);
return 0;
}
// Testing the delete_property. Delets property, with the given name,
// if that exsists.
int
TAO_PropertySet_Tester::test_delete_property (const char *property_name
ACE_ENV_ARG_DECL)
{
ACE_DEBUG ((LM_DEBUG, "\nChecking delete_property\n"));
property_set_.delete_property (property_name
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN ( 1);
return 0;
}
// Gets the value of "short_property" and "string_property".
int
TAO_PropertySet_Tester::test_get_property_value (ACE_ENV_SINGLE_ARG_DECL)
{
ACE_DEBUG ((LM_DEBUG,
"\nChecking get_property_value\n"));
CORBA::Any_ptr anyptr = property_set_.get_property_value ("short_property"
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN ( 1);
// Get the short value.
if (anyptr != 0)
{
CORBA::Short s;
*anyptr >>= s;
ACE_DEBUG ((LM_DEBUG,
"Short %d\n",
s));
}
else
ACE_DEBUG ((LM_DEBUG,
"Short property not found\n"));
// Get the string.
anyptr = property_set_.get_property_value ("string_property"
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN ( 1);
if (anyptr != 0)
{
CORBA::String str;
*anyptr >>= str;
ACE_DEBUG ((LM_DEBUG,
"Str %s\n", str));
}
else
ACE_DEBUG ((LM_DEBUG,
"string_property not found\n"));
return 0;
}
// Check the following properties are defined or no. "short_property",
// "string_property" and "char_property".
int
TAO_PropertySet_Tester::test_is_property_defined (ACE_ENV_SINGLE_ARG_DECL)
{
ACE_DEBUG ((LM_DEBUG,
"\nChecking is_property_defined ()\n"));
if (property_set_.is_property_defined ("short_property"
ACE_ENV_ARG_PARAMETER) == 0)
ACE_DEBUG ((LM_DEBUG,
"short_property not defined\n"));
else
ACE_DEBUG ((LM_DEBUG,
"short_property defined\n"));
ACE_CHECK_RETURN ( 1);
if (property_set_.is_property_defined ("string_property"
ACE_ENV_ARG_PARAMETER) == 0)
ACE_DEBUG ((LM_DEBUG,
"string_property not defined\n"));
else
ACE_DEBUG ((LM_DEBUG,
"string_property defined\n"));
ACE_CHECK_RETURN ( 1);
if (property_set_.is_property_defined ("char_property"
ACE_ENV_ARG_PARAMETER) == 0)
ACE_DEBUG ((LM_DEBUG,
"char_property not defined\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -