Exemplo n.º 1
1
int runTests(CORBA::ORB_var orb, First::IHello_ptr hello)
{
	result = 0;

	try
	{
		std::cout << "  AddValue: ";
		check(5 == hello->AddValue(2, 3));
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  SayHello: ";
		check(std::wstring(L"Hello, Andy. It's Bob.") == (wchar_t*)CORBA::WString_var(hello->SayHello(L"Andy")));
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  SayHello2: ";
		CORBA::String_var greeting;
		hello->SayHello2("Andy", greeting.out());
		check(std::string("Hello, Andy. It's Bob.") == (char*)greeting);
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Message: ";
		CORBA::String_var message = "Hello, Bob";
		hello->Message(message.inout());
		check(std::string("Hello, Andy.") == (char*)message);
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  MulComplex: ";
		First::MyComplexNumber x, y;
		x.re = 2, x.im = 3;
		y.re = 5, y.im = 6;
		First::MyComplexNumber expected;
		expected.re = x.re * y.re - x.im * y.im;
		expected.im = x.re * y.im + x.im - y.re;

		First::MyComplexNumber result = hello->MulComplex(x, y);
		check(equal(result, expected) && equal(result, y));
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  MulComplexAsAny: ";
		First::MyComplexNumber x, y;
		x.re = 2, x.im = 3;
		y.re = 5, y.im = 6;
		First::MyComplexNumber expected;
		expected.re = x.re * y.re - x.im * y.im;
		expected.im = x.re * y.im + x.im - y.re;

		CORBA::Any _x, _y;
		_x <<= x;
		_y <<= y;

		CORBA::Any_var _result;
		bool success = hello->MulComplexAsAny(_x, _y, _result.out());

		First::MyComplexNumber* result;
		_result >>= result;

		check(success && result && equal(*result, expected));
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  DataTimeTransfer: ";
		SYSTEMTIME initial_systemtime = {};
		initial_systemtime.wMilliseconds = 0;
		initial_systemtime.wSecond = 0;
		initial_systemtime.wMinute = 0;
		initial_systemtime.wHour = 0;
		initial_systemtime.wDay = 8;
		initial_systemtime.wDayOfWeek = 1;
		initial_systemtime.wMonth = 2;
		initial_systemtime.wYear = 2016;

		FILETIME initial_filetime;
		SystemTimeToFileTime(&initial_systemtime, &initial_filetime);
		__int64 val = SysytemTimeToInt64(initial_systemtime);

		hello->DataTimeTransfer(val);

		FILETIME return_filetime;
		Int64ToFileTime(&val, &return_filetime);

		check(CompareFileTime(&initial_filetime, &return_filetime) == 0);
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Install exceptions hadlers: ";
		omniORB::installTransientExceptionHandler(hello, 0, transientExceptionHandler);
		omniORB::installSystemExceptionHandler(hello, 0, systemExceptionHandler);
		check(true);
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Catch NO_IMPLEMENT: ";
		expectedExceptionType = SYSTEM_EXCEPTION_TYPE;
		exceptionProperlyHandled = false;
		hello->ThrowExceptions(0);
	}
	catch (CORBA::NO_IMPLEMENT& se)
	{
		check(exceptionProperlyHandled && 1 == se.minor());
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Catch TRANSIENT: ";
		expectedExceptionType = TRANSIENT_EXCEPTION_TYPE;
		exceptionProperlyHandled = false;
		hello->ThrowExceptions(3);
	}
	catch (CORBA::TRANSIENT& se)
	{
		std::string ex_neame = se._name();
		check(exceptionProperlyHandled && ex_neame.compare("TRANSIENT") == 0);
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Catch plain user exception: ";
		hello->ThrowExceptions(1);
	}
	catch (First::IHello::UserExceptionS& ue)
	{
		check(std::string("UserExceptionS") == ue._name());
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Catch user exception with members: ";
		hello->ThrowExceptions(2);
	}
	catch (First::IHello::UserExceptionExt& ue)
	{
		check((std::string("EXCEPTIONS_WORKS") == (char*)ue.reason) && (254 == ue.codeError));
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Catch unknown exception: ";
		hello->ThrowExceptions(4);
	}
	catch (CORBA::UNKNOWN& se)
	{
		check(std::string("UNKNOWN") == (char*)se._name());
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Sequence reversed: ";

		int row[] = { 1, 3, 5, 7, 10 };
		int length = sizeof(row) / sizeof(row[0]);

		First::SequenceLong_var sequence(new First::SequenceLong());
		sequence->length(length);
		for (int i = 0; i < length; ++i)
		{
			sequence[i] = row[i];
		}

		First::SequenceLong_var reversed = hello->Reverse(sequence.in());

		if (5 == reversed->length())
		{
			check((reversed[0] == row[4]) && (reversed[1] == row[3]) && (reversed[2] == row[2]) && (reversed[3] == row[1]) && (reversed[4] == row[0]));
		}
		else
			check(false);
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Callback: ";

		PortableServer::POA_var poa = createBidirectionalPOA(orb);

		TestCallBackImpl* pCallback = new TestCallBackImpl();
		PortableServer::ObjectId_var oid = poa->activate_object(pCallback);
		First::ITestCallBack_var callback(pCallback->_this());
		pCallback->_remove_ref();

		check(hello->CallMe(callback) && pCallback->Greeting() == "Hello from Server");
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Pass single dimensional array: ";

		First::Vector4_var x = First::Vector4_alloc();
		x[0] = 1.0; x[1] = 2.0; x[2] = 3; x[3] = -4.0;

		First::Vector4_var y = First::Vector4_alloc();
		y[0] = -1.0; y[1] = 12.0; y[2] = 4.1; y[3] = 0;

		double expected[] = {
			x[0] + y[0],
			x[1] + y[1],
			x[2] + y[2],
			x[3] + y[3]
		};

		First::Vector4_slice* result = hello->AddVectors(x, y);
		bool equal = result[0] == expected[0] && result[1] == expected[1] && result[2] == expected[2] && result[3] == expected[3];
		
		First::Vector4_free(result);

		check(equal);
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Pass multi dimensional array: ";

		First::Matrix3x4_var x = First::Matrix3x4_alloc();
		x[0][0] =  1.0; x[0][1] = -2.0; x[0][2] =  3; x[0][3] = 4.1;
		x[1][0] =  2.0; x[1][1] =  4.0; x[1][2] = -6; x[1][3] = 8.1;
		x[2][0] = -3.0; x[2][1] = -5.0; x[2][2] =  7; x[2][3] =  -1;

		First::Matrix3x4_var y = First::Matrix3x4_alloc();
		y[0][0] =  3.0; y[0][1] = -2.4; y[0][2] =  3; y[0][3] =  -0;
		y[1][0] =  6.0; y[1][1] =  2.0; y[1][2] = -7; y[1][3] = 8.9;
		y[2][0] = -7.0; y[2][1] = -1.0; y[2][2] =  7; y[2][3] =   1;

		double expected[3][4] = {
			{ x[0][0] + y[0][0], x[0][1] + y[0][1], x[0][2] + y[0][2], x[0][3] + y[0][3] },
			{ x[1][0] + y[1][0], x[1][1] + y[1][1], x[1][2] + y[1][2], x[1][3] + y[1][3] },
			{ x[2][0] + y[2][0], x[2][1] + y[2][1], x[2][2] + y[2][2], x[2][3] + y[2][3] }
		};

		First::Matrix3x4_slice* result = hello->AddMatrixes(x, y);

		//check selectively
		bool equal = result[0][0] == expected[0][0] && result[1][3] == expected[1][3] && result[2][0] == expected[2][0] && result[2][3] == expected[2][3];

		First::Matrix3x4_free(result);

		check(equal);
	}
	catch (...)
	{
		check(false);
	}

	try
	{
		std::cout << "  Shutdown: ";
		hello->Shutdown();
		check(true);
	}
	catch (...)
	{
		check(false);
	}

	return result;
}
Exemplo n.º 2
0
  int svc ()
  {
    CORBA::String_var str = CORBA::string_alloc (200*2000 + 1);
    if (str.in () == 0) return 1;
    str.inout ()[0] = CORBA::Char ('\0');
    for (int i=0; i < 2000; ++i)
      {
        ACE_OS::strcat (str.inout (), twohundredbytes);
      }

    while (1)
      {
        try
          {
            CORBA::String_var ret = srv_->test_method (str.in ());
            if (0 != ACE_OS::strcmp (str.in (), ret.in ())) return 1;
          }
        catch (const CORBA::Exception& ex)
          {
            ACE_DEBUG ((LM_ERROR,
                        ACE_TEXT ("(%P|%t) Exception caught: \n%C\n"),
                        ex._info ().c_str ()));
            return 1;
          }
      }
    return 0;
  }
Exemplo n.º 3
0
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
    try
    {
        // Initialize orb
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

        CORBA::Object_var rootObj =
            orb->resolve_initial_references("NameService");

        CosNaming::NamingContext_var rootContext =
            CosNaming::NamingContext::_narrow(rootObj.in());

        CosNaming::Name name;
        name.length (1);
        name[0].id = CORBA::string_dup ("MessengerService");

        CORBA::Object_var messengerObj = rootContext->resolve(name);

        if (CORBA::is_nil(messengerObj.in())) {
            std::cerr << "Nil Messenger reference" << std::endl;
            return 1;
        }

        // Narrow
        Messenger_var messenger = Messenger::_narrow(messengerObj.in());
        if (CORBA::is_nil(messenger.in ())) {
            std::cerr << "Argument is not a Messenger reference" << std::endl;
            return 1;
        }

        CORBA::String_var message = CORBA::string_dup(
                                        "We are experiencing network problems.");
        messenger->send_message ("*****@*****.**",
                                 "urgent",
                                 message.inout());

        message = CORBA::string_dup("Where can I get TAO?");
        messenger->send_message ("*****@*****.**",
                                 "OCI's Distribution of TAO",
                                 message.inout());

        message = CORBA::string_dup(
                      "Please contact [email protected] regarding your request.");
        messenger->send_message ("*****@*****.**",
                                 "OCI's Distribution of TAO",
                                 message.inout());

    }
    catch(const CORBA::Exception& ex) {
        std::cerr << "Caught a CORBA exception: " << ex << std::endl;
        return 1;
    }

    std::cout << "MessengerClient: success" << std::endl;
    return 0;
}
Exemplo n.º 4
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{

  // Detection of closed on read currently not working certain platforms.
#if defined (sun) || defined (AIX) || defined (__FreeBSD_version)
  return 2;
#endif

  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    // Destringify ior
    CORBA::Object_var obj = orb->string_to_object( ior );
    if (CORBA::is_nil(obj.in())) {
      std::cerr << "Nil Messenger reference" << std::endl;
      return 1;
    }

    // Narrow
    Messenger_var messenger = Messenger::_narrow( obj.in() );
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Argument is not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup( "Hello!" );

    messenger->send_message( "TAO User", "Test 1", message.inout() );

    // Force server to abort to verify it will be brought
    // back up when send_message() is called.
    messenger->abort(2);
    ACE_OS::sleep(seconds_between_requests);

    ACE_DEBUG ((LM_INFO,
                "(%P|%t) - Sending another message after abort of server\n"));

    messenger->send_message( "TAO User", "Test 2", message.inout() );

    std::cout << "messages were sent" << std::endl;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Client main() Caught CORBA::Exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemplo n.º 5
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) {
  try {
    if (argc <= 1) {
      std::cerr << "Error: Must specify the name of an IOR file." << std::endl;
      return 1;
    }
    ACE_TString ior = ACE_TEXT("file://");
    ior += argv[1];

    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    CORBA::Object_var obj = orb->string_to_object(ior.c_str());

    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Unable to get a Messenger reference." << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup("Hello!");
    messenger->send_message("TAO User", "TAO Test", message.inout());
    std::cout << "message was sent" << std::endl;
    std::cout << "Reply was : " << message.in() << std::endl;

    return 0;
  } catch(const CORBA::Exception& ex) {
    std::cerr << "Client main() Caught Exception: " << ex << std::endl;
  }
  return 1;
}
Exemplo n.º 6
0
//--------------------------------------------------------------------------
// activateObject:
//--------------------------------------------------------------------------
int activateObject (ClientData clientData, 
                    Tcl_Interp *interp,
                    int argc,
                    const char *argv[])
{
  if (argc < 2)
    {
      sprintf (interp->result, 
               "Usage: %s serviceId ?objectId?",
               ACTIVATE_OBJECT_CMD);
      return TCL_ERROR;
    }

  const char *serviceId = argv[1];
  const char *objectId = (argc > 2) ? argv[2] : 0;
  
  try 
    {
      CORBA::String_var strObjectReference = 
        ServiceManager::instance()->activateObject (serviceId, objectId);
      Tcl_SetResult (interp, strObjectReference.inout (), TCL_VOLATILE);
      return TCL_OK;
      
    }
  catch (Exception &exp)
    {
      error ("%s:%d %s", exp.getFile (), exp.getLine (), exp.getMessage ());
      interp->result = exp.getMessage ();
      return TCL_ERROR;
    }
}
Exemplo n.º 7
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    // Find the Naming Service
    CORBA::Object_var naming_obj = orb->resolve_initial_references("NameService");
    CosNaming::NamingContextExt_var root =
      CosNaming::NamingContextExt::_narrow(naming_obj.in());
    if (CORBA::is_nil(root.in())) {
      std::cerr << "Nil Naming Context reference" << std::endl;
      return 1;
    }

    // Resolve the Messenger object
    CosNaming::Name name;
    name.length( 2 );
    name[0].id = CORBA::string_dup( "example" );
    name[1].id = CORBA::string_dup( "Messenger" );
    CORBA::Object_var obj = CORBA::Object::_nil();
    while (CORBA::is_nil(obj.in())) {
      try {
        obj = root->resolve_str("example/Messenger");
      } catch (const CosNaming::NamingContext::NotFound&) {
        // Sleep for a second and try again
        ACE_OS::sleep(1);
      }
    }

    // Narrow the Messenger object reference
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup("Hello!");

    // Send a message
    messenger->send_message("TAO User", "TAO Test", message.inout());

    std::cout << "Message was sent" << std::endl;

    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Caught a CORBA exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemplo n.º 8
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    // Find the Naming Service  & the Message Server name in it
    CORBA::Object_var obj = orb->string_to_object(ior_input_file);

    // Narrow
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup("Hello!");
    messenger->send_message( "TAO User", "TAO Test", message.inout());

    std::cout << "Message was sent" << std::endl;

    std::cout << "Now try the same thing with the simple name." << std::endl;
    obj = orb->resolve_initial_references("NameService");
    CosNaming::NamingContextExt_var root =
      CosNaming::NamingContextExt::_narrow(obj.in());
    obj = root->resolve_str("Simple/Messenger");
    messenger = Messenger::_narrow(obj.in());
    messenger->send_message( "ACE User", "TAO Test", message.inout());

    std::cout << "Message was sent" << std::endl;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Caught a CORBA::Exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemplo n.º 9
0
  int synch_foo_generator::svc ()
   {
     ACE_OS::sleep (3);

     //run some synch calls
     ::InterInOutT::MyFoo_var my_foo_ami_ =
          context_->get_connection_run_my_foo ();
     CORBA::String_var answer = CORBA::string_dup("Hi from sender");
     CORBA::Long l_cmd = 1;
     try
       {
         CORBA::Long result = my_foo_ami_->foo ("Do something synchronous",
                                                 l_cmd ,
                                                 answer.inout ());
         if ((result == (update_val + cmd_synch_ok)) &&
             (ACE_OS::strcmp (answer.in(), "Hi from receiver") == 0))
           {
             ++this->nr_of_received_;
           }
       }
     catch (const InterInOutT::InternalError&)
       {
         ACE_ERROR ((LM_ERROR, "ERROR: synch_foo_generator::foo: "
                               "Unexpected exception.\n"));
       }
     try
       {
         l_cmd = 2;
         answer = CORBA::string_dup("Hi from sender");
         my_foo_ami_->foo ("",l_cmd, answer.inout());
       }
     catch (const InterInOutT::InternalError& ex)
       {
           HandleException (ex.id, (update_val + cmd_synch_nok),
                            ex.error_string.in(),
                            "synch foo");
       }
     return 0;
   }
Exemplo n.º 10
0
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
  try {
    // Initialize the ORB
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    if (parse_args (argc, argv) != 0)
      return 1;

    // Create a smart proxy factory.  It will register itself with the
    // smart proxy factory adapter so it can be used to create
    // Messenger proxies.  It must be created on the heap, but is
    // otherwise unused here.
    new Smart_Messenger_Proxy_Factory(orb.in());

    // Convert the contents of the Messenger.ior file to an object reference.
    CORBA::Object_var obj = orb->string_to_object(ior);
    if (CORBA::is_nil(obj.in())) {
      std::cerr << "Nil Messenger reference" << std::endl;
      return 1;
    }

    // Narrow the object reference to a Messenger object reference.
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Not a Messenger object reference" << std::endl;
      return 1;
    }

    // Create a message and send it to the Messenger.
    CORBA::String_var message = CORBA::string_dup("Hello!");
    messenger->send_message ("TAO User", "TAO Test", message.inout());
    std::cout << "Message was sent" << std::endl;

    // Release resources.
    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Caught a CORBA exception: " << ex << std::endl;
    return 1;
  }
  catch(...) {
    std::cerr << "Caught an unknown exception type" << std::endl;
    return 1;
  }

  return 0;
}
Exemplo n.º 11
0
int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
  try {
    // Initialize the ORB.
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args(argc, argv) != 0) {
      return 1;
    }

    // Read and destringify the Messenger object's IOR.
    CORBA::Object_var obj = orb->string_to_object(ior.c_str());
    if( CORBA::is_nil( obj.in() ) ) {
      std::cerr << "Could not get Messenger IOR." << std::endl;
      return 1;
    }

    // Narrow the IOR to a Messenger object reference.
    DevGuide::Messenger_var messenger =
      DevGuide::Messenger::_narrow( obj.in() );
    if( CORBA::is_nil( messenger.in() ) ) {
      std::cerr << "IOR was not a Messenger object reference." << std::endl;
      return 1;
    }

    // Send a message the the Messenger object.
    CORBA::String_var msg = CORBA::string_dup( "Hello!" );
    messenger->send_message( "TAO User", "TAO Test", msg.inout() );

    // Print the Messenger's reply.
    std::cout << "Reply: " << msg.in() << std::endl;

    orb->destroy();

    return 0;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "CORBA exception: " << ex << std::endl;
  }

  return 1;
}
Exemplo n.º 12
0
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
  try
  {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    if (parse_args (argc, argv) != 0)
      return 1;

    CORBA::Object_var obj = orb->string_to_object( ior );
    if (CORBA::is_nil(obj.in())) {
      std::cerr << "Nil Messenger reference" << std::endl;
      return 1;
    }

    // Narrow
    Messenger_var messenger = Messenger::_narrow( obj.in() );
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Argument is not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup(
      "Where can I get TAO?");
    for (int i=0; i<3; i++) {
      messenger->send_message ("*****@*****.**",
                               "OCI's Distribution of TAO",
                               message.inout());
    }
  }
  catch(const CORBA::Exception& ex)
  {
    std::cerr << "Caught exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemplo n.º 13
0
int ACE_TMAIN (int, ACE_TCHAR **)
{
  try {
    // Construct a Messenger object and use it "as if" it's a corba object.
    // Put it into CORBA object reference
    // comparable to activation, narrow, etc.
    Messenger_var messenger(new Messenger_i);

    // Send a message the the Messenger object.
    CORBA::String_var message = CORBA::string_dup ("Hello!");
    messenger->send_message("TAO User", "TAO Test", message.inout());

    // Print the Messenger's reply.
    std::cout << "Reply: " << message.in() << std::endl;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Caught CORBA::Exception : " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemplo n.º 14
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
  {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    CORBA::Object_var obj =
      orb->string_to_object (ior);

    // Narrow the Messenger object reference
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      ACE_ERROR((LM_ERROR, " ERROR: Client cannot get a Messenger reference\n"));
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup("Hello!");

    // Send a message
    messenger->send_message("user", "TAO Test", message.inout());

    ACE_DEBUG((LM_DEBUG, "CLIENT: Message was sent\n"));

    orb->destroy();
  }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return 1;
    }

  return 0;
}
Exemplo n.º 15
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  try {
    // Initialize the ORB
    CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

    if (parse_args (argc, argv) != 0)
        return 1;

    // Converts the contents of the file to an object reference
    CORBA::Object_var obj = orb->string_to_object (ior);
    if (CORBA::is_nil (obj.in())) {
      std::cerr << "Nill Messenger reference" << std::endl;
      return 1;
    }

    // Narrow the object reference to a Messenger object reference
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil (messenger.in())) {
      std::cerr << "Not a Messenger object reference" << std::endl;
      return 1;
    }

    // Create a message and send it to the Messenger
    CORBA::String_var message = CORBA::string_dup("Hello!");
    messenger->send_message ("TAO User", "TAO Test", message.inout());

    orb->destroy();
    std::cout << "Message was sent" << std::endl;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Client Caught a CORBA exception: " << ex << std::endl;
    return 1;
  }
  std::cout << "Message was sent" << std::endl;
  return 0;
}
Exemplo n.º 16
0
    void
    ImR_Client_Adapter_Impl::imr_notify_startup (TAO_Root_POA* poa )
    {
      CORBA::Object_var imr = poa->orb_core ().implrepo_service ();

      if (CORBA::is_nil (imr.in ()))
        {
          if (TAO_debug_level > 0)
            {
              TAOLIB_ERROR ((LM_ERROR,
                          ACE_TEXT ("TAO_ImR_Client (%P|%t) - ERROR: No usable IMR initial reference ")
                          ACE_TEXT ("available but use IMR has been specified.\n")));
            }
          throw ::CORBA::TRANSIENT (
              CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
              CORBA::COMPLETED_NO);
        }

      if (TAO_debug_level > 0)
        {
          if (TAO_debug_level > 1)
            {
              CORBA::ORB_ptr orb = poa->orb_core ().orb ();
              CORBA::String_var ior = orb->object_to_string (imr.in ());
              TAOLIB_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("TAO_ImR_Client (%P|%t) - Notifying ImR of startup IMR IOR <%C>\n"),
                            ior.in ()));
            }
        }

      ImplementationRepository::Administration_var imr_locator;

      {
        // ATTENTION: Trick locking here, see class header for details
        TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa);
        ACE_UNUSED_ARG (non_servant_upcall);

        imr_locator =
          ImplementationRepository::Administration::_narrow (imr.in ());
      }

      if (CORBA::is_nil (imr_locator.in ()))
        {
          if (TAO_debug_level > 0)
            {
              TAOLIB_ERROR ((LM_ERROR,
                          ACE_TEXT ("TAO_ImR_Client (%P|%t) - ERROR: Narrowed IMR initial reference ")
                          ACE_TEXT ("is nil but use IMR has been specified.\n")));
            }

          throw ::CORBA::TRANSIENT (
              CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
              CORBA::COMPLETED_NO);
        }

      TAO_Root_POA *root_poa = poa->object_adapter ().root_poa ();
      ACE_NEW_THROW_EX (this->server_object_,
                        ServerObject_i (poa->orb_core ().orb (),
                                        root_poa),
                        CORBA::NO_MEMORY ());

      PortableServer::ServantBase_var safe_servant (this->server_object_);
      ACE_UNUSED_ARG (safe_servant);

      // Since this method is called from the POA constructor, there
      // shouldn't be any waiting required.  Therefore,
      // <wait_occurred_restart_call_ignored> can be ignored.
      bool wait_occurred_restart_call_ignored = false;

      // Activate the servant in the root poa.
      PortableServer::ObjectId_var id =
        root_poa->activate_object_i (this->server_object_,
                                     poa->server_priority (),
                                     wait_occurred_restart_call_ignored);

      CORBA::Object_var obj = root_poa->id_to_reference_i (id.in (), false);

      ImplementationRepository::ServerObject_var svr
        = ImplementationRepository::ServerObject::_narrow (obj.in ());

      if (!svr->_stubobj () || !svr->_stubobj ()->profile_in_use ())
        {
          if (TAO_debug_level > 0)
            {
              TAOLIB_ERROR ((LM_ERROR, "TAO_ImR_Client (%P|%t) - Invalid ImR ServerObject, bailing out.\n"));
            }
          return;
        }
      CORBA::ORB_var orb = root_poa->_get_orb ();
      CORBA::String_var full_ior = orb->object_to_string (obj.in ());
      TAO_Profile& profile = *(svr->_stubobj ()->profile_in_use ());
      CORBA::String_var ior = profile.to_string();
      if (TAO_debug_level > 0)
        {
          TAOLIB_DEBUG((LM_INFO,
                        "TAO_ImR_Client (%P|%t) - full_ior <%C>\nior <%C>\n",
                        full_ior.in(),
                        ior.in()));
        }
      char* const pos = find_delimiter (ior.inout (),
                                        profile.object_key_delimiter ());

      const ACE_CString partial_ior (ior.in (), (pos - ior.in ()) + 1);

      if (TAO_debug_level > 0)
      {
        CORBA::String_var poaname = poa->the_name ();
        TAOLIB_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO_ImR_Client (%P|%t) - Informing IMR that <%C> is running at <%C>\n"),
                    poaname.in(), partial_ior.c_str ()));
      }

      try
        {
          // ATTENTION: Trick locking here, see class header for details
          TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa);
          ACE_UNUSED_ARG (non_servant_upcall);

          ACE_CString const serverId = poa->orb_core ().server_id ();
          ACE_CString name;
          if (serverId.empty ())
            {
              name = poa->name ();
            }
          else
            {
              name = serverId + ":" + poa->name ();
            }

          imr_locator->server_is_running (name.c_str (),
                                          partial_ior.c_str (),
                                          svr.in ());
        }
      catch (const ::CORBA::SystemException&)
        {
          throw;
        }
      catch (const ::CORBA::Exception&)
        {
          throw ::CORBA::TRANSIENT (
              CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
              CORBA::COMPLETED_NO);
        }

      if (TAO_debug_level > 0)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                         ACE_TEXT ("TAO_ImR_Client (%P|%t) - Successfully notified ImR of Startup\n")));
        }
    }
Exemplo n.º 17
0
void
do_primary_test (CORBA::ORB_var &orb, Simple_Server_var &server)
{
	try
	{
		CORBA::Object_var nilobj = CORBA::Object::_nil();

		CORBA::Object_var object =
			orb->string_to_object (ior);

		server =
			Simple_Server::_narrow (object.in ());

		if (CORBA::is_nil (server.in ()))
		{
			ACE_ERROR ((LM_ERROR,
				    "Object reference <%s> is nil\n",
				    ior));
			return;
		}

		CORBA::Short x = server->s();
		ACE_ERROR ((LM_ERROR,"Server->s() returned %d\n", x));
		server->s(510);
		Structure the_in_structure;
		the_in_structure.i = x;
		the_in_structure.seq.length (10);
		the_in_structure.obj = CORBA::Object::_duplicate(server.in());
		Structure_var out_struct;
		CORBA::String_var name = CORBA::string_dup ("test");
		server->struct_test (12345,
				     the_in_structure,
				     out_struct.out(),
				     name.inout());
		CORBA::String_var outior =
			orb->object_to_string(out_struct->obj);
		ACE_DEBUG ((LM_DEBUG,"Got outior:\n%s\n", outior.in()));

		if (test_user_exception == 1)
		{
			server->raise_user_exception ();
		}
		else if (test_system_exception == 1)
		{
			server->raise_system_exception ();
		}
		if (test_user_exception != 0 ||
		    test_system_exception != 0)
		{
			ACE_DEBUG ((LM_DEBUG,"Expected exception not caught!\n"));
			return;
		}

		ACE_DEBUG ((LM_DEBUG,"Sending main ref\n"));
		CORBA::Object_var echo = server->echo_object (server.in());
		ACE_DEBUG ((LM_DEBUG,"Sending nil ref\n"));
		echo = server->echo_object (nilobj.in());

		CORBA::Any a;
		a <<= "String through Any";
		CORBA::Boolean success = server->any_test (a);
		ACE_DEBUG ((LM_DEBUG,"any_test(string) returned %d\n",success));

		a <<= server.in();
		success = server->any_test (a);
		ACE_DEBUG ((LM_DEBUG,"any_test(objref) returned %d\n",success));

		for (int i = 0; i != niterations; ++i)
		{
			the_in_structure.i = i;
			CORBA::String_var name = CORBA::string_dup ("the name");

			Structure_var the_out_structure;

			CORBA::Long r =
				server->struct_test (i,
						     the_in_structure,
						     the_out_structure.out (),
						     name.inout ());

			ACE_DEBUG ((LM_DEBUG,
				    "DSI_Simpler_Server ====\n"
				    "    x = %d\n"
				    "    i = %d\n"
				    "    length = %d\n"
				    "    name = <%s>\n",
				    r,
				    the_out_structure->i,
				    the_out_structure->seq.length (),
				    name.in ()));

			if (r != i)
			{
				ACE_DEBUG ((LM_DEBUG,
					    "(%P|%t) unexpected result = %d for %d",
					    r, i));
			}
		}
	}
	catch (const test_exception& ex)
	{
		ex._tao_print_exception ("Client: exception caught - ");

		ACE_DEBUG ((LM_DEBUG,
			    "error code: %d\n"
			    "error info: %s\n"
			    "status: %s\n",
			    ex.error_code,
			    ex.error_message.in (),
			    ex.status_message.in ()));
	}
	catch (const CORBA::NO_PERMISSION& ex)
	{
		ex._tao_print_exception ("Client: exception caught - ");
	}
	catch (const CORBA::SystemException& sysEx)
	{
		sysEx._tao_print_system_exception ();
	}
	catch (const CORBA::Exception& ex)
	{
		ex._tao_print_exception ("Client: exception caught - ");
	}
}
Exemplo n.º 18
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      ClientInitializer* temp_initializer = new ClientInitializer;

      PortableInterceptor::ORBInitializer_var orb_initializer =
        temp_initializer;

      PortableInterceptor::register_orb_initializer (orb_initializer.in ());

      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Client ORB");

      // Now that the ORB is initialized (and subsequently the
      // PICurrent), we can set the slot data on the PICurrent for our
      // interceptor initializer.
      temp_initializer->set_slot_data ();

      CORBA::Object_var naming_obj =
        orb->resolve_initial_references( "NameService" );
      CosNaming::NamingContext_var root =
        CosNaming::NamingContext::_narrow( naming_obj.in() );
      if ( CORBA::is_nil(root.in() ) ) {
        std::cerr << "Couldn't find Naming Service." << std::endl;
        return 1;
      }

      // get Messenger
      CosNaming::Name name;
      name.length(1);
      name[0].id = CORBA::string_dup( "Messenger" );

      CORBA::Object_var obj = CORBA::Object::_nil();
      while ( CORBA::is_nil( obj.in() ) ) {
        try {
          obj = root->resolve( name );
        } catch (const CosNaming::NamingContext::NotFound&) {
          // Sleep for a second and try again
          ACE_OS::sleep(1);
        }
      }

      Messenger_var messenger = Messenger::_narrow( obj.in() );
      if( CORBA::is_nil( messenger.in() ) ) {
        std::cerr << "Not a Messenger reference" << std::endl;
        return 1;
      }

      CORBA::String_var message = CORBA::string_dup( "Hello!" );
      messenger->send_message( "TAO User", "TAO Test", message.inout() );

    }

  catch(const CORBA::Exception& ex)
    {
      std::cerr << "Caught CORBA exception: " << ex << std::endl;
      return 1;
    }

  return 0;
}
Exemplo n.º 19
0
  Invocation_Status
  DII_Invocation::handle_user_exception (TAO_InputCDR &cdr)
  {
    Reply_Guard mon (this, TAO_INVOKE_FAILURE);

    if (TAO_debug_level > 3)
      {
        TAOLIB_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) - DII_Invocation::"
                    "handle_user_exception\n"));
      }

    // Match the exception interface repository id with the
    // exception in the exception list.
    // This is important to decode the exception.
    CORBA::String_var buf;

    TAO_InputCDR tmp_stream (cdr,
                             cdr.start ()->length (),
                             0);

    // Pull the exception ID out of the marshaling buffer.
    if (tmp_stream.read_string (buf.inout ()) == 0)
      {
        throw ::CORBA::MARSHAL (TAO::VMCID, CORBA::COMPLETED_YES);
      }

    for (CORBA::ULong i = 0;
         this->excp_list_ != 0 && i < this->excp_list_->count ();
         i++)
      {
          CORBA::TypeCode_var tc = this->excp_list_->item (i);

          const char *xid = tc->id ();

          if (ACE_OS::strcmp (buf.in (), xid) != 0)
            {
              continue;
            }

          CORBA::Any any;
          TAO::Unknown_IDL_Type *unk = 0;
          ACE_NEW_RETURN (unk,
                          TAO::Unknown_IDL_Type (
                              tc.in (),
                              cdr
                            ),
                          TAO_INVOKE_FAILURE);

          any.replace (unk);

          mon.set_status (TAO_INVOKE_USER_EXCEPTION);

          throw ::CORBA::UnknownUserException (any);
        }

    // If we couldn't find the right exception, report it as
    // CORBA::UNKNOWN.

    // But first, save the user exception in case we
    // are being used in a TAO gateway.
    this->host_->raw_user_exception (cdr);

    mon.set_status (TAO_INVOKE_USER_EXCEPTION);

    // @@ It would seem that if the remote exception is a
    //    UserException we can assume that the request was
    //    completed.
    throw ::CORBA::UNKNOWN (TAO::VMCID, CORBA::COMPLETED_YES);

  }
Exemplo n.º 20
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) != 0)
        {
          return 1;
        }

      CORBA::Object_var object =
        orb->string_to_object (ior);

      Simple_Server_var server =
        Simple_Server::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil.\n",
                             ior),
                            1);
        }

      Structure the_in_structure;
      the_in_structure.seq.length (10);

      if (test_user_exception == 1)
        {
          server->raise_user_exception ();
        }
      else if (test_system_exception == 1)
        {
          server->raise_system_exception ();
        }
      else
        {
          for (int i = 0; i != niterations; ++i)
            {
              CORBA::Long const tv = i + 100;
              server->test_val(tv);
              CORBA::Long const rtv = server->test_val ();

              if (TAO_debug_level > 0)
                {
                   ACE_DEBUG ((LM_DEBUG,
                               "DSI_Simpler_Server ==== Expected result = %d for %d\n",
                               rtv, tv));
                }

              if (rtv != tv)
                {
                   ACE_ERROR ((LM_ERROR,
                             "(%P|%t) ERROR: unexpected result = %d for %d\n",
                             rtv, tv));
               }

             the_in_structure.i = i;
             CORBA::String_var name = CORBA::string_dup ("the name");

             Structure_var the_out_structure;

             CORBA::Long const r =
                server->test_method (i,
                                     the_in_structure,
                                     the_out_structure.out (),
                                     name.inout ());

              if (TAO_debug_level > 0)
                {
                  ACE_DEBUG ((LM_DEBUG,
                              "DSI_Simpler_Server ====\n"
                              "    x = %d\n"
                              "    i = %d\n"
                              "    length = %d\n"
                              "    name = <%C>\n",
                              r,
                              the_out_structure->i,
                              the_out_structure->seq.length (),
                              name.in ()));
                }

              if (r != i)
                {
                  ACE_ERROR ((LM_ERROR,
                              "(%P|%t) ERROR: unexpected result = %d for %d",
                              r, i));
                }
            }
        }

      if (do_shutdown)
        {
          server->shutdown ();
        }
    }
  catch (const test_exception& ex)
    {
      if (test_user_exception == 1)
        ACE_DEBUG ((LM_DEBUG,
                    "Client: caught expected user exception: %C\n",
                    ex._name()));
      else
        ex._tao_print_exception ("Client: exception caught - ");

      ACE_DEBUG ((LM_DEBUG,
                  "error code: %d\n"
                  "error info: %C\n"
                  "status: %C\n",
                  ex.error_code,
                  ex.error_message.in (),
                  ex.status_message.in ()));

      return test_user_exception == 1 ? 0 : 1;
    }
  catch (const CORBA::NO_PERMISSION& ex)
    {
      if (test_system_exception == 1)
        ACE_DEBUG ((LM_DEBUG,
                    "Client: caught expected system exception: %C\n",
                    ex._name()));
      else
        ex._tao_print_exception ("Client: exception caught - ");
      return test_system_exception == 1 ? 0 : 1;
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Client: exception caught - ");
      return 1;
    }

  return 0;
}
Exemplo n.º 21
0
  int asynch_foo_generator::svc ()
  {
    ACE_OS::sleep (3);
    ::InterInOutT::AMI4CCM_MyFoo_var my_foo_ami_  =
       context_->get_connection_sendc_run_my_foo();
    if (CORBA::is_nil (my_foo_ami_))
      {
        ACE_ERROR ((LM_ERROR, "ERROR Sender (ASYNCH) :\tfoo_ami is NIL !\n"));
       return 1;
      }
    else
      {
        ::InterInOutT::AMI4CCM_MyFooReplyHandler_var cb =
          new AMI4CCM_MyFooReplyHandler_run_my_foo_i (
          this->nr_of_received_);

        CORBA::Long l_cmd = 3;
        CORBA::String_var answer = CORBA::string_dup("Hi from sender");
        //Invoke Asynchronous calls to test
        my_foo_ami_->sendc_foo ( cb.in (),
          "Do something synchronous", l_cmd, answer.inout());

        //this should invoke a exception
        l_cmd = 4;
        my_foo_ami_->sendc_foo (  cb.in (),
          "", l_cmd, answer.inout());
        my_foo_ami_->sendc_var_ins(  cb.in (),
                                   "Here a double for you.", 1.6);

        InterInOutT::TestTopic test_topic;
        test_topic.key = "aaa";
        test_topic.x = 10;
        InterInOutT::TopicString topic_str;
        topic_str.key = "bbb";
        topic_str.x_str = "ccc";
        InterInOutT::TestArray topic_arr;
        for ( CORBA::UShort i = 0; i < 5; i ++)
          {
            topic_arr[i].key = CORBA::string_dup("ddd");
            for (CORBA::UShort y = 0; y < 5; y ++)
              {
                topic_arr[i].x_array[y] = i * 100 + y ;
              }
          }
        my_foo_ami_->sendc_var_div_ins ( cb.in (),
                                        test_topic,topic_str,topic_arr, answer);

        InterInOutT::X_Union topic_union;
        topic_union.x_long(11);
        InterInOutT::test ttt;
        ttt.x_test = 12;
        ttt.x_teststr = "fff" ;
        InterInOutT::test_seq seq;
        seq.length(2);
        seq[0] = ttt;

        my_foo_ami_->sendc_var_div2_ins ( cb.in (),
                                         topic_union, seq);
        InterInOutT::test_enum in_test;
        in_test = ::InterInOutT::ONE;
        my_foo_ami_->sendc_enum_in( cb.in (),
                                          in_test);
      }
    return 0;
  }
Exemplo n.º 22
0
bool
Foo_B_ClientEngine::execute(void)
{
  // Make sure the connection is established before making
  // remote invocations.
  if (AppHelper::validate_connection (this->obj_.in ()) == false)
    {
      ACE_ERROR((LM_ERROR, "(%P|%t)Foo_A_ClientEngine::execute  " \
                          "client %d connect failed.\n", this->client_id_));
      return false;
    }

  // Verify the return values and return the results.
  bool check_validity = true;

  this->obj_->op1();

  this->obj_->op2(this->client_id_);

  CORBA::Long value = this->obj_->op3(this->client_id_);

  if (value != static_cast<CORBA::Long>(this->client_id_))
    {
      check_validity = false;
    }

  for (CORBA::ULong j = 1; j <= 5; j++)
    {
      this->obj_->op4(495 + (this->client_id_ * 5) + j);
    }

  bool caught_exception = false;

  try
  {
    this->obj_->op5();
  }
  catch (const FooException& )
  {
    // Expected
    caught_exception = true;
  }

  if (! caught_exception)
    {
      check_validity = false;
    }

  TimeOfDay t;
  t.hour = 12;
  t.minute = 30;
  t.second = 10;

  char test_str [20];
  ACE_OS::sprintf (test_str, "%d %s", this->client_id_, ONEWAY_ARG_TEST_STR);

  char buffer [20];

  // Two-Way calls with "inout" and fixed size "in" arguments.
  CORBA::String_var message = CORBA::string_dup(test_str);

  CORBA::Boolean result = this->obj_->op6( t, message.inout());

  ACE_UNUSED_ARG(result);

  ACE_OS::sprintf (buffer, "%d %s %d:%d:%d", this->client_id_, ONEWAY_ARG_TEST_STR,
    t.hour, t.minute, t.second);

  if (ACE_OS::strncmp (message.in (), buffer, ACE_OS::strlen (buffer)) != 0)
    {
      check_validity = false;
    }

  // Callback test.
  this->obj_->op7 (this->callback_.in ());

  // One-Way calls with various arguments.
  CORBA::String_var ub_string = CORBA::string_dup( test_str );
  this->obj_->test_unbounded_string_arg (ub_string.in ());

  CORBA::String_var bd_string = CORBA::string_dup( test_str );
  this->obj_->test_bounded_string_arg (bd_string.in ());

  Fixed_Array fixed_array;

  for (CORBA::ULong m = 0 ; m < 20; m ++)
  {
     fixed_array[m] = this->client_id_ + m;
  }

  this->obj_->test_fixed_array_arg (fixed_array);

  Var_Array var_array;

  for (CORBA::ULong k = 0; k < 3; k++)
    {
      ACE_OS::sprintf (buffer, "%d %s %d",
                       this->client_id_, ONEWAY_ARG_TEST_STR, k);
      var_array[k] = CORBA::string_dup(buffer);
    }

  this->obj_->test_var_array_arg (var_array);

  Bounded_Var_Size_var bd_var_size_string = new Bounded_Var_Size();

  bd_var_size_string->replace (ACE_OS::strlen (test_str) + 1,
                               test_str);
  this->obj_->test_bounded_var_size_arg (bd_var_size_string.in ());

  Unbounded_Var_Size_var ub_var_size_string = new Unbounded_Var_Size(100);
  ub_var_size_string->replace (ub_var_size_string->maximum (),
                               ACE_OS::strlen (test_str) + 1,
                               test_str);
  this->obj_->test_unbounded_var_size_arg (ub_var_size_string.in ());

  this->obj_->test_fixed_size_arg (t);

  this->obj_->test_special_basic_arg (this->client_id_ % 2,
                                      this->client_id_);

  this->obj_->test_objref_arg (this->callback_.in ());

  // Sleep for 5 seconds before invoking done().
  // This is a workaround with the problem that some oneway requests lost
  // when the server has multiple orb threads.
  ACE_OS::sleep (5);
  this->obj_->done();

  return check_validity;
}
Exemplo n.º 23
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {

    CORBA::ORB_var orb =
      CORBA::ORB_init( argc, argv );

      if (parse_args (argc, argv) != 0)
        return 1;

    CORBA::Object_var obj =
      orb->string_to_object( ior );

    Messenger_var messenger =
      Messenger::_narrow( obj.in() );

    CORBA::String_var message =
      CORBA::string_dup( "Terminating messenger service!" );

    messenger->send_message( "Chief of Security",
                             "New Directive",
                             message.inout() );

    messenger->shutdown("Chief of Security");

    Security::QOP qop =
      Security::SecQOPIntegrityAndConfidentiality;

    CORBA::Any want_protection;
    want_protection <<= qop;

    CORBA::Policy_var policy =
      orb->create_policy (Security::SecQOPPolicy,
                          want_protection);

    Security::EstablishTrust establish_trust;
    establish_trust.trust_in_client = 0;
    establish_trust.trust_in_target = 1;

    CORBA::Any want_trust;
    want_trust <<= establish_trust;

    CORBA::Policy_var policy2 =
      orb->create_policy (Security::SecEstablishTrustPolicy,
                          want_trust);


    CORBA::PolicyList policy_list (2);
    policy_list.length (1);
    policy_list[0] =
      CORBA::Policy::_duplicate (policy.in ());
    policy_list.length (2);
    policy_list[1] =
      CORBA::Policy::_duplicate (policy2.in ());


    CORBA::Object_var object =
      obj->_set_policy_overrides (policy_list,
                                  CORBA::SET_OVERRIDE);

    Messenger_var messenger2 =
      Messenger::_narrow( object.in() );

    message =
      CORBA::string_dup( "Terminating messenger service!" );

    messenger2->send_message( "Chief of Security",
                             "New Directive",
                             message.inout() );

    messenger2->shutdown("Chief of Security");

    orb->destroy();
  }
  catch(const CORBA::Exception& ex)
  {
    ex._tao_print_exception("Client: main block");
    return 1;
  }

  return 0;
}
Exemplo n.º 24
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  // Detection of closed on read currently not working certain platforms.
#if defined (sun) || defined (AIX) || defined (__FreeBSD_version)
  return 2;
#endif

  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    // Destringify ior
    CORBA::Object_var obj = orb->string_to_object( ior );
    if (CORBA::is_nil(obj.in())) {
      std::cerr << "Nil Messenger reference" << std::endl;
      return 1;
    }

    // Narrow
    Messenger_var messenger = Messenger::_narrow( obj.in() );
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Argument is not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup( "Hello!" );

    int try_count = 0;
    int succeeded = 0;
    for (; try_count < number_of_tries; ++try_count)
    {
      ACE_DEBUG ((LM_INFO,
                  "(%P|%t) - Sending message <%d> to server\n", try_count));

      try {
        messenger->send_message( "TAO User", "Test 1", message.inout() );

        ACE_DEBUG ((LM_INFO,
            "(%P|%t) - Successfully received response for message <%d> to server\n", try_count));
        ++succeeded;

        // Force server to abort to verify it will be brought
        // back up when send_message() is called.
        messenger->abort(2);
        ACE_OS::sleep(seconds_between_requests);
      }
      catch (const CORBA::Exception&)
      {
        // Swallow
      }
    }

    if (succeeded == number_of_succeed)
    {
      ACE_DEBUG ((LM_INFO,
            "(%P|%t) - <%d> Messages where send to the server, <%d> succeeded\n", try_count, succeeded));
    }
    else
    {
      ACE_ERROR ((LM_INFO,
            "(%P|%t) - ERROR: <%d> Messages where send to the server, <%d> succeeded, should be <%d>\n", try_count, succeeded, number_of_succeed));
    }

    orb->destroy ();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Client main() Caught CORBA::Exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}