orb_init.cpp

来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 133 行

CPP
133
字号
// ORB_init.cpp,v 1.8 2003/11/01 11:15:11 dhinton Exp

#include "tao/RTCORBA/RTCORBA.h"
#include "tao/ORB.h"
#include "ace/Get_Opt.h"
#include "ace/OS_NS_stdio.h"

int
test_multiple_orbs (const char *test_name,
                    int argc,
                    char *argv[],
                    int iterations,
                    int rt_orb,
                    int destroy)
{
  CORBA::ORB_var *orbs =
    new CORBA::ORB_var[iterations];

  RTCORBA::RTORB_var *rt_orbs =
    new RTCORBA::RTORB_var[iterations];

  ACE_TRY_NEW_ENV
    {
      for (int i = 0;
           i < iterations;
           ++i)
        {
          char name[100];
          ACE_OS::sprintf (name, "%s %d", test_name, i);

          orbs[i] =
            CORBA::ORB_init (argc,
                             argv,
                             name
                             ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          if (rt_orb)
            {
              CORBA::Object_var object =
                orbs[i]->resolve_initial_references ("RTORB"
                                                     ACE_ENV_ARG_PARAMETER);
              ACE_TRY_CHECK;

              rt_orbs[i] =
                RTCORBA::RTORB::_narrow (object.in ()
                                         ACE_ENV_ARG_PARAMETER);
              ACE_TRY_CHECK;

              ACE_ASSERT (rt_orbs[i].in () != RTCORBA::RTORB::_nil ());
            }
        }

      if (destroy)
        {
          for (int i = 0;
               i < iterations;
               ++i)
            {
              orbs[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
              ACE_TRY_CHECK;
            }
        }
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Unexpected exception caught in ORB_init");
      return -1;
    }
  ACE_ENDTRY;

  delete[] rt_orbs;
  delete[] orbs;

  return 0;
}

int
main (int argc, char *argv[])
{
  int iterations = 5;
  int rt_orb = 0;
  int destroy = 0;

  int result =
    test_multiple_orbs ("non-RT ORBs, disable destroy",
                        argc,
                        argv,
                        iterations,
                        rt_orb,
                        destroy);
  ACE_ASSERT (result == 0);

  destroy = 1;
  rt_orb = 0;

  result =
    test_multiple_orbs ("non-RT ORBs, enable destroy",
                        argc,
                        argv,
                        iterations,
                        rt_orb,
                        destroy);
  ACE_ASSERT (result == 0);

  destroy = 0;
  rt_orb = 1;

  result =
    test_multiple_orbs ("RT ORBs, disable destroy",
                        argc,
                        argv,
                        iterations,
                        rt_orb,
                        destroy);
  ACE_ASSERT (result == 0);

  destroy = 1;
  rt_orb = 1;

  result =
    test_multiple_orbs ("RT ORBs, enable destroy",
                        argc,
                        argv,
                        iterations,
                        rt_orb,
                        destroy);
  ACE_ASSERT (result == 0);

  return result;
}

⌨️ 快捷键说明

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