⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// client.cpp,v 1.30 2002/10/25 00:40:19 bala Exp

// ============================================================================
//
// = LIBRARY
//    TAO/orbsvcs/tests/Property
//
// = FILENAME
//    client.cpp
//
// = DESCRIPTION
//    Test client for the Property Service.
//
// = AUTHORS
//    Alexander Babu Arulanthu <alex@cs.wustl.edu>
//
// ============================================================================

#include "client.h"
#include "tao/debug.h"

ACE_RCSID(CosPropertyService, client, "client.cpp,v 1.30 2002/10/25 00:40:19 bala Exp")

  Client::Client (void)
{
}

int
Client::init (int argc,
              char *argv[]
              ACE_ENV_ARG_DECL)
{
  // Init the ORB.
  manager_.init (argc,
                 argv
                 ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Initialize the naming services
  if (my_name_client_.init (manager_.orb()) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       " (%P|%t) Unable to initialize "
                       "the TAO_Naming_Client. \n"),
                      -1);

  // Bind PropertySetDef Object.

  CosNaming::Name propsetdef_name (1);
  propsetdef_name.length (1);
  propsetdef_name [0].id = CORBA::string_dup ("PropertySetDef");
  CORBA::Object_var propsetdef_obj = my_name_client_->resolve (propsetdef_name
                                                               ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  this->propsetdef_ = CosPropertyService::PropertySetDef::_narrow (propsetdef_obj.in ()
                                                                   ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  if (CORBA::is_nil (this->propsetdef_.in ()))
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Couldnot resolve propsetdef in Naming server"),
                      -1);

  return 0;
}

// Testing the methods of the property service.

int
Client::property_tester (ACE_ENV_SINGLE_ARG_DECL)
{
  // = Testing PropertySet & Iterators.

  // Testing define_property () of PropertySet interface.
  this->test_define_property (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Test the number of properties.
  this->test_get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Testing get_all_property_names.
  this->test_get_all_property_names (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Test get_property_value.
  this->test_get_property_value (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Testing delete property.
  this->test_delete_property ("no_property" ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Testing get_properties.
  this->test_get_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Testing delete_properties.
  this->test_delete_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Test the number of properties.
  this->test_get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Testing define_properties.
  this->test_define_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Test the number of properties.
  this->test_get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Testing get_all_property_names.
  this->test_get_all_property_names (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Testing get_all_properties.
  this->test_get_all_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // = Testing PropertySetDef & Iterators.

  // Testing define_property_with_mode.
  this->test_define_property_with_mode (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  return 0;
}

// Testing define_property.

int
Client::test_define_property (ACE_ENV_SINGLE_ARG_DECL)
{
  CORBA::Any anyval;

  // Prepare a char and "define" that in the PropertySet.
  CORBA::Char ch = '#';
  anyval <<= CORBA::Any::from_char (ch);
  ch = '*';
  anyval >>= CORBA::Any::to_char (ch);

  this->propsetdef_->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;

  propsetdef_->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;
  CORBA::Any newany(anyval);
  propsetdef_->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.14F;
  anyval <<= f;
  f = 4.14F;
  anyval >>= f;

  propsetdef_->define_property ("float_property",
                                anyval
                                ACE_ENV_ARG_PARAMETER);

  ACE_CHECK_RETURN (-1);

  // Prepare a String and "define" that in the PropertySet.
  CORBA::String_var strvar (CORBA::string_dup ("Test_String"));
  anyval <<= strvar.in ();
  const char * newstr;
  anyval >>= newstr;
  propsetdef_->define_property ("string_property",
                                anyval
                                ACE_ENV_ARG_PARAMETER);

  ACE_CHECK_RETURN (-1);

  return 0;
}

// Testing get_all_property_names of the PropertySet.

int
Client::test_get_all_property_names (ACE_ENV_SINGLE_ARG_DECL)
{
  // Get the size.
  CORBA::ULong num_of_properties =
    propsetdef_->get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Get half on the names and half of on the iterator.
  CORBA::ULong how_many = num_of_properties / 2;

  // The extra ptr's and out's required to avoind SunnCC's warning
  // when foo.out () is passed to a funtion.
  CosPropertyService::PropertyNames_var names_var;
  CosPropertyService::PropertyNames     *names_ptr = 0;
  CosPropertyService::PropertyNames_out names_out (names_ptr);

  CosPropertyService::PropertyNamesIterator_var iterator_var;
  CosPropertyService::PropertyNamesIterator_ptr iterator_ptr;
  CosPropertyService::PropertyNamesIterator_out iterator_out (iterator_ptr);

  propsetdef_->get_all_property_names (how_many,
                                       names_out,
                                       iterator_out
                                       ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Get the values back to var.
  names_var = names_out.ptr ();
  iterator_var = iterator_out.ptr ();

  // Print out the names in the names-sequence.
  if (TAO_debug_level > 0)
    {
      if (names_var.ptr () != 0)
        {
          CORBA::ULong len = names_var->length ();

          for (CORBA::ULong ni = 0; ni < len; ni++)
            ACE_DEBUG ((LM_DEBUG,
                        "%s\n",
                        (const char *) names_var [ni]));
        }

      // Iterate thru and print out the names in the iterator, if any.
      if (iterator_var.ptr () != 0)
        {
          // Helper variables to stop the SunCC warnings on on foo.out
          // ().
          CosPropertyService::PropertyName  name_ptr = 0;
          CosPropertyService::PropertyName_out name_out (name_ptr);

          // Call the function.
          CORBA::Boolean next_one_result = iterator_var->next_one (name_out ACE_ENV_ARG_PARAMETER);
          ACE_CHECK_RETURN (-1);

          // Get the values back on a _var variable.
          CosPropertyService::PropertyName_var name_var = name_out.ptr ();

          while (next_one_result == 1)
            {
              ACE_DEBUG ((LM_DEBUG, "%s\n", name_var.in ()));

              // Call the function to iterate again.
              next_one_result = iterator_var->next_one (name_out ACE_ENV_ARG_PARAMETER);
              ACE_CHECK_RETURN (-1);

              // Get the values back on a _var variable.
              name_var = name_out.ptr ();
            }

          ACE_CHECK_RETURN (-1);
        }
    }
  return 0;
}

// Test get_properties. Give a sequence of names and get all their
// properties.

int
Client::test_get_properties (ACE_ENV_SINGLE_ARG_DECL)
{
  // Get float_property, string_property and no_property. If return
  // value is false and type is tc_void then that name is not there in
  // the PropertySet.
  CosPropertyService::PropertyNames_var names;
  CosPropertyService::PropertyNames     *names_ptr;

  ACE_NEW_RETURN (names_ptr,
                  CosPropertyService::PropertyNames,
                  -1);
  names = names_ptr;

  names->length (3);
  names [0u] = CORBA::string_dup ("float_property");
  //names [1] = CORBA::string_dup ("string_property");
  names [1u] = CORBA::string_dup ("long_property");
  names [2u] = CORBA::string_dup ("char_property");
  //names [2] = CORBA::string_dup ("no_property");


  CosPropertyService::Properties *properties_ptr = 0;
  CosPropertyService::Properties_out properties_out (properties_ptr);

  // Get the properties.
  CORBA::Boolean return_val = propsetdef_->get_properties (names.in (),
                                                           properties_out
                                                           ACE_ENV_ARG_PARAMETER);
  ACE_UNUSED_ARG (return_val);
  ACE_CHECK_RETURN (-1);


  if (TAO_debug_level > 0)
    {
      // Get the value to the _var.
      CosPropertyService::Properties_var properties = properties_out.ptr ();

      if (properties.ptr () != 0)
        {
          // Go thru the properties and print them out, if they are not
          // _tc_void typed values.
          CORBA::ULong len = properties->length ();

          for (CORBA::ULong pi = 0; pi < len; pi++)
            {
              // Print the name.
              ACE_DEBUG ((LM_DEBUG,
                          "%s : ",
                          (const char *) properties [pi].property_name.in ()));

              // Print the value.
              CORBA::Char    char_val;
              CORBA::Long    long_val;
              CORBA::ULong  ulong_val;
              CORBA::Float  float_val;
              CORBA::Double double_val;
              const char *  string_val;

              if (properties [pi].property_value >>=
                  CORBA::Any::to_char (char_val))
                {
                  ACE_DEBUG ((LM_DEBUG, "%c\n", char_val));
                }
              else if (properties [pi].property_value >>= long_val)
                {
                  ACE_DEBUG ((LM_DEBUG, "%d\n", long_val));
                }
              else if (properties [pi].property_value >>= ulong_val)
                {
                  ACE_DEBUG ((LM_DEBUG, "%ld\n", ulong_val));
                }
              else if (properties [pi].property_value >>= float_val)
                {
                  ACE_DEBUG ((LM_DEBUG, "%f\n", long_val));
                }
              else if (properties [pi].property_value >>= double_val)
                {
                  ACE_DEBUG ((LM_DEBUG, "%f\n", double_val));
                }
              else if (properties [pi].property_value >>= string_val)
                {
                  ACE_DEBUG ((LM_DEBUG, "%s\n", string_val));
                }
            }
        }
    }
  return 0;
}

// Testing, get_number_of_properties.

int
Client::test_get_number_of_properties (ACE_ENV_SINGLE_ARG_DECL)
{
  CORBA::ULong nproperties = this->propsetdef_->get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  if (TAO_debug_level > 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "\nNumber of props : %d\n",
                  nproperties));
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -