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

📄 client.cpp

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

// Test delete_property.

int
Client::test_delete_property (const char *property_name
                              ACE_ENV_ARG_DECL)
{
  ACE_TRY
    {
      CORBA::String_var property_name_var (property_name);

      this->propsetdef_->delete_property (property_name_var.in ()
                                          ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
    }
  ACE_CATCH (CORBA::UserException, ex)
    {
      // For no property, it is ok to get the user exception.
      return 0;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ex, "Not an user exception");
      return -1;
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (-1);

  return 0;
}

// Test delete_properties.
// Make a sequence of property names and delete them from the
// PropertySet.  Deleting char, short, long, float and string
// properties.

int
Client::test_delete_properties (ACE_ENV_SINGLE_ARG_DECL)
{
  CosPropertyService::PropertyNames prop_names;
  prop_names.length (3);
  prop_names [0] = CORBA::string_dup ("char_property");
  prop_names [1] = CORBA::string_dup ("short_property");
  prop_names [2] = CORBA::string_dup ("long_property");
  // prop_names [3] = CORBA::string_dup ("no_property");
  this->propsetdef_->delete_properties (prop_names
                                        ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN ( 0);

  return 0;
}

// Defines a sequnce of properties containing, char, short, long,
// float in the property set.

int
Client::test_define_properties (ACE_ENV_SINGLE_ARG_DECL)
{
  CosPropertyService::Properties nproperties;
  nproperties.length (4);
  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);
  nproperties[0].property_name  = CORBA::string_dup ("char_property");
  nproperties[0].property_value <<= CORBA::Any::from_char (ch);

  // Prepare a Short and "define" that in the PropertySet.
  CORBA::Short s = 3;
  anyval <<= s;
  s = 7;
  anyval >>= s;
  nproperties[1].property_name  = CORBA::string_dup ("short_property");
  nproperties[1].property_value <<= s;

  // Prepare a Long and "define" that in the PropertySet.
  CORBA::Long l = 931232;
  anyval <<= l;
  l = 931233;
  anyval >>= l;
  nproperties[2].property_name  = CORBA::string_dup ("long_property");
  nproperties[2].property_value <<= l;

  // Prepare a Float and "define" that in the PropertySet.
  CORBA::Float f = 3.14F;
  anyval <<= f;
  f = 4.14F;
  anyval >>= f;
  nproperties[3].property_name  = CORBA::string_dup ("float_property");
  nproperties[3].property_value <<= f;

  // Define this sequence of properties now.
  this->propsetdef_->define_properties (nproperties ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN ( -1);

  return 0;
}

// Test get_all_properties.

int
Client::test_get_all_properties (ACE_ENV_SINGLE_ARG_DECL)
{
  // Get the number of current properties.
  CORBA::ULong num_of_properties =
    this->propsetdef_->get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN ( -1);
  ACE_UNUSED_ARG (num_of_properties);

  // Get half on the properties and half of on the iterator.
  CORBA::ULong how_many = 1;

  // Helper variables to avoid SunCC warnings.
  CosPropertyService::Properties *properties_ptr = 0;
  CosPropertyService::Properties_out properties_out (properties_ptr);
  CosPropertyService::PropertiesIterator_ptr iterator_ptr = 0;
  CosPropertyService::PropertiesIterator_out iterator_out (iterator_ptr);

  propsetdef_->get_all_properties (how_many,
                                   properties_out,
                                   iterator_out
                                   ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN ( -1);

  // Get these values to the _var's.
  CosPropertyService::Properties_var properties = properties_out.ptr ();
  CosPropertyService::PropertiesIterator_var iterator = iterator_out.ptr ();

  // Print out the properties now.
  if (TAO_debug_level > 0)
    {
      if (properties.ptr () != 0)
        {
          CORBA::ULong len = properties->length ();

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

              // Print the value if type is not tk_void.
              if (properties [pi].property_value.type () == CORBA::_tc_void)
                ACE_DEBUG ((LM_DEBUG,"Void\n"));

              if (properties [pi].property_value.type () == CORBA::_tc_float)
                {
                  CORBA::Float f;
                  properties [pi].property_value >>= f;
                  ACE_DEBUG ((LM_DEBUG,"%f\n", f));
                }

              if (properties [pi].property_value.type () == CORBA::_tc_string)
                {
                  const char* str;
                  properties [pi].property_value >>= str;
                  ACE_DEBUG ((LM_DEBUG,"%s\n", str));
                }

              if (properties [pi].property_value.type () == CORBA::_tc_long)
                {
                  CORBA::Long l;
                  properties [pi].property_value >>= l;
                  ACE_DEBUG ((LM_DEBUG,"%d\n", l));
                }
            }
        }

      // Pass thru the iterator.
      if (iterator.ptr () != 0)
        {
          // Helper variables to avoid warnings with .out () in SunCC.
          CosPropertyService::Property* property_ptr = 0;
          CosPropertyService::Property_out property_out (property_ptr);

          // Call the funtion.
          CORBA::Boolean next_one_result = iterator->next_one (property_out
                                                               ACE_ENV_ARG_PARAMETER);

          // Get the value to the _var variable.
          CosPropertyService::Property_var property = property_out.ptr ();

          while (next_one_result != 0)
            {
              ACE_CHECK_RETURN ( -1);
              ACE_DEBUG ((LM_DEBUG,
                          "%s : ",
                          property->property_name.in ()));

              // Print the property_value.
              if (property->property_value.type () == CORBA::_tc_char)
                {
                  CORBA::Char c;
                  property->property_value >>= CORBA::Any::to_char (c);
                  ACE_DEBUG ((LM_DEBUG,"%c\n", c));
                }

              if (property->property_value.type () == CORBA::_tc_short)
                {
                  CORBA::Short s;
                  property->property_value >>= s;
                  ACE_DEBUG ((LM_DEBUG,"%d\n", s));
                }

              if (property->property_value.type () == CORBA::_tc_float)
                {
                  CORBA::Float f;
                  property->property_value >>= f;
                  ACE_DEBUG ((LM_DEBUG,"%f\n", f));
                }

              if (property->property_value.type () == CORBA::_tc_string)
                {
                  const char* str;
                  property->property_value >>= str;
                  ACE_DEBUG ((LM_DEBUG,"%s\n", str));
                }

              if (property->property_value.type () == CORBA::_tc_long)
                {
                  CORBA::Long l;
                  property->property_value >>= l;
                  ACE_DEBUG ((LM_DEBUG,"%d\n", l));
                }

              // Call the function for the next iteraton.
              next_one_result = iterator->next_one (property_out
                                                    ACE_ENV_ARG_PARAMETER);

              // Get the value to the _var variable.
              property = property_out.ptr ();
            }
          ACE_CHECK_RETURN ( -1);
        }
    }
  return 0;
}

// Testing define property with mode.
// Defines char, short, long and float properties with different modes.
int
Client::test_define_property_with_mode (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_with_mode ("char_property",
                                                anyval,
                                                CosPropertyService::normal
                                                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_with_mode ("short_property",
                                          anyval,
                                          CosPropertyService::read_only
                                          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_with_mode ("long_property",
                                          anyval,
                                          CosPropertyService::fixed_normal
                                          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_with_mode ("float_property",
                                          anyval,
                                          CosPropertyService::fixed_readonly
                                          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;
}

int
Client::test_get_property_value (ACE_ENV_SINGLE_ARG_DECL)
{
  ACE_TRY
    {
      // Get the ior property.
      CORBA::Any_ptr any_ptr = this->propsetdef_->get_property_value ("PropertySetDef_IOR"
                                                                      ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Check whether the IOR is fine.
      CORBA::Object_var propsetdef_object;
      (*any_ptr) >>= CORBA::Any::to_object (propsetdef_object.out ());

      CosPropertyService::PropertySetDef_var propsetdef =
        CosPropertyService::PropertySetDef::_narrow (propsetdef_object.in ()
                                                     ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (CORBA::is_nil (propsetdef.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "invalid object reference\n"),
                          -1);
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "get_property_value");
      return -1;
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (-1);
  return 0;
}

int
main (int argc, char **argv)
{
  ACE_DECLARE_NEW_CORBA_ENV;

  ACE_TRY
    {
      Client client;

      if (client.init (argc,
                       argv
                       ACE_ENV_ARG_PARAMETER) == -1)
        return 1;
      ACE_TRY_CHECK;

      //  client.run (ACE_ENV_SINGLE_ARG_PARAMETER);
      int ret = client.property_tester (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;
      if (ret != 0)
        ACE_DEBUG ((LM_DEBUG, "Test failed\n"));
      else
        ACE_DEBUG ((LM_DEBUG, "Test succeeded\n"));
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "PropertyService Test : client");
      return -1;
    }
 ACE_ENDTRY;
 ACE_CHECK_RETURN (-1);

  return 0;
}

⌨️ 快捷键说明

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