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; }
int synch_foo_generator::svc () { ::AsynchT::MyFoo_var my_foo_ami_ = context_->get_connection_run_my_foo (); ACE_OS::sleep(1); CORBA::Boolean wait = false; for (int i = 0; i < 3; ++i) { // Run some synch calls, answer has to come before the next step. CORBA::String_var answer; try { if( wait==true) { ACE_ERROR ((LM_ERROR, "ERROR: NOT RECEIVED SYNCHRONOUS answer.\n")); } wait = true; ACE_DEBUG ((LM_DEBUG, "OK: SEND SYNCHRONOUS CALL foo.\n")); CORBA::Long result = my_foo_ami_->foo ("Do something synchronous", 2 , answer.out ()); if ( result == 2) { ACE_DEBUG ((LM_DEBUG, "OK: RECEIVED SYNCHRONOUS answer <%C>\n", answer.in ())); wait = false; } if ( wait==true) { ACE_ERROR ((LM_ERROR, "ERROR: NOT RECEIVED SYNCHRONOUS answer.\n")); } wait = true; CORBA::Long l_cmd = 0; ACE_DEBUG ((LM_DEBUG, "OK: SEND SYNCHRONOUS CALL bar.\n")); my_foo_ami_->bar (2,l_cmd); if ( l_cmd == 2) { ACE_DEBUG ((LM_DEBUG, "OK: RECEIVED SYNCHRONOUS answer <%C>\n", answer.in ())); wait = false; } } catch (const AsynchT::InternalError&) { ACE_ERROR ((LM_ERROR, "ERROR: synch_foo_generator::foo: " "Unexpected exception.\n")); } } return 0; }
CORBA::Boolean DynExceptImpl::validate_name() throw(CORBA::SystemException) { try { CORBA::String_var str; _next_value->read_string(str.out()); return (!strcmp(str, _base_type->id())); } catch(CORBA::TypeCode::BadKind) { throw CORBA::BAD_TYPECODE(); } }
char * Object_Group_i::resolve_with_id (const char * id) { CORBA::String_var ior; if (this->members_->find (const_cast<char *> (id), ior.out (), this->allocator_) == -1) throw Load_Balancer::no_such_member (); char *retn_ptr = CORBA::string_dup (ior.in ()); return retn_ptr; }
int synch_foo_generator::svc () { ::UsesMulti::Sender::run_my_um_oneConnections_var my_one_ami_ = context_->get_connections_run_my_um_one (); for(CORBA::ULong i = 0; i < my_one_ami_->length(); ++i) { CORBA::String_var test; switch (i) { case 0: test = CORBA::string_dup ("Synch. call 0."); break; case 1: test = CORBA::string_dup ("Synch. call 1"); break; case 2: test = CORBA::string_dup ("Synch. call 2"); break; default: break; } ACE_DEBUG ((LM_DEBUG,"Sender (SYNCH) : send <%C> !\n", test.in ())); CORBA::String_var answer; CORBA::ULong result = my_one_ami_[i].objref->foo( test, i, answer.out ()); if (result != i) { ACE_ERROR ((LM_ERROR, "ERROR Sender (SYNCH) : CLASS One foo !\n")); } else { ++this->nr_of_received_; ACE_DEBUG ((LM_DEBUG, "Sender (SYNCH) : received answer = <%C> !\n", answer.in ())); } } return 0; }
int synch_foo_generator::svc () { ::ThreeComp::Sender::run_my_fooConnections_var my_foo_ami_ = context_->get_connections_run_my_foo (); CORBA::Boolean wait = false; for(CORBA::ULong i = 0; i < my_foo_ami_->length(); ++i) { CORBA::String_var answer; try { if ( wait==true) { ACE_ERROR ((LM_ERROR, "ERROR: Sender didn't receive SYNCHRONOUS answer" " from Receiver.\n")); } wait = true; ACE_DEBUG ((LM_DEBUG, "OK Sender send SYNCHRONOUS CALL to Receiver.\n")); CORBA::ULong result = my_foo_ami_[i].objref->foo( 20, answer.out ()); if (result == 2) { ACE_DEBUG ((LM_DEBUG, "OK Sender received SYNCHRONOUS answer " "from Receiver <%C>\n", answer.in ())); ++this->nr_of_rec_; wait = false; } } catch (const ThreeComp::InternalError&) { ACE_ERROR ((LM_ERROR, "ERROR: synch_foo_generator::foo: " "Unexpected exception.\n")); } } return 0; }
int synch_foo_generator::svc () { ACE_OS::sleep (3); ::DelReplyH::MyFoo_var my_foo_ami_ = this->context_->get_connection_run_my_foo (); //run some synch calls try { CORBA::String_var answer; my_foo_ami_->foo("synchronous call", answer.out ()); ACE_DEBUG ((LM_DEBUG, "OK: SYNCH foo returns <%C>.\n", answer.in ())); } catch (const DelReplyH::InternalError& ) { ACE_ERROR ((LM_ERROR, "ERROR: SYNCH foo(): " "Unexpected return.\n")); } return 0; }
int synch_foo_generator::svc () { ACE_OS::sleep(3); ::OneProcess::MyFoo_var my_foo_ami_ = this->context_->get_connection_run_my_foo (); CORBA::Boolean wait = false; for (int i = 0; i < 3; ++i) { //run some synch calls try { CORBA::String_var answer; if( wait==true) { ACE_ERROR ((LM_ERROR, "ERROR: NOT RECEIVED SYNCHRONOUS answer.\n")); } wait = true; CORBA::Long result = my_foo_ami_->foo ("Do something synchronous", 2 , answer.out ()); if ( result == 2) { ACE_DEBUG ((LM_DEBUG, "OK: RECEIVED SYNCHRONOUS answer <%C>\n", answer.in ())); wait = false; } } catch (const OneProcess::InternalError&) { ACE_ERROR ((LM_ERROR, "ERROR: synch_foo_generator::foo: " "Unexpected exception.\n")); } ACE_OS::sleep(1); } return 0; }
int synch_state_generator::svc () { ::ThreeComp::State_var my_state_ami_ = context_->get_connection_run_my_state (); ACE_OS::sleep(1); CORBA::Boolean wait = false; for (int i = 0; i < 3; ++i) { // Run some synch calls, answer has to come before the next step. CORBA::String_var answer; ::CORBA::Long ret = 0; try { if ( wait==true) { ACE_ERROR ((LM_ERROR, "ERROR: NOT RECEIVED SYNCHRONOUS answer.\n")); } wait = true; ACE_DEBUG ((LM_DEBUG, "OK: Master send SYNCHRONOUS call to Sender.\n")); ret = my_state_ami_->bar (2,answer.out()); if (ret == 2) { ACE_DEBUG ((LM_DEBUG, "OK: Master received SYNCHRONOUS answer from Sender <%C>\n", answer.in ())); wait = false; } } catch (const ThreeComp::InternalError&) { ACE_ERROR ((LM_ERROR, "ERROR: synch_state_generator::state: " "Unexpected exception.\n")); } } return 0; }
int Service::call_are_you_there (Test::Callback_ptr callback) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Service, calling are_you_there\n")); const int iterations = 10; int exception_count = 0; for (int i = 0; i != iterations; ++i) { CORBA::String_var outstr; CORBA::String_out out_str (outstr.out ()); try { (void) callback->are_you_there (out_str); } catch (const CORBA::Exception&) { exception_count++; } ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Service, answer = %C\n", outstr.in ())); } return exception_count; }
int Identity_Client::run (void) { // Contact the <Object_Group_Factory> to obtain an <Object_Group>. CORBA::ORB_var orb = orb_manager_.orb (); CORBA::Object_var obj = orb->string_to_object (this->group_factory_ior_); if (obj.in () == 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%N|%l) <ERROR> [Identity_Client::run]\n") ACE_TEXT ("factory_resolve\n")), -1); Load_Balancer::Object_Group_Factory_var factory = Load_Balancer::Object_Group_Factory::_narrow (obj.in ()); if (CORBA::is_nil (factory.in ())) ACE_ERROR_RETURN ((LM_ERROR, "Identity_Client: problems using the factory ior\n"), -1); const char *group_name; if (this->use_random_) group_name = "Random group"; else group_name = "Round Robin group"; Load_Balancer::Object_Group_var object_group; // We have this for the measurement that was done. #if defined (DOORS_MEASURE_STATS) // Performance measurements start here ACE_High_Res_Timer::calibrate (); ACE_hrtime_t throughput_base = ACE_OS::gethrtime (); ACE_Throughput_Stats throughput; ACE_High_Res_Timer::global_scale_factor_type gsf = ACE_High_Res_Timer::global_scale_factor (); for (int i = 0; i < this->iterations_; i++) { // Record current time. ACE_hrtime_t latency_base = ACE_OS::gethrtime (); #endif /*TAO_MEASURE_STATS*/ // Remote call object_group = factory->resolve (group_name); CORBA::String_var iorstring = orb->object_to_string (object_group.in ()); ACE_DEBUG ((LM_DEBUG, "The ior string is %s\n", iorstring.in ())); #if defined (DOORS_MEASURE_STATS) // Grab timestamp again. ACE_hrtime_t now = ACE_OS::gethrtime (); // Record statistics. throughput.sample (now - throughput_base, now - latency_base); } ACE_OS::printf ("*=*=*=*=Aggregated result *=*=*=*=*=\n"); throughput.dump_results (ACE_TEXT("Aggregated"), gsf); #endif /*TAO_MEASURE_STATS */ if (CORBA::is_nil (object_group.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "(%l|%d)The narrowed object is NUL:"), -1); } // List <Object_Group>'s id. CORBA::String_var id = object_group->id (); ACE_DEBUG ((LM_DEBUG, "Object Group's id is: %s\n\n", id.in ())); // List all <Object_Group>s members. Load_Balancer::Member_ID_List_var id_list = object_group->members (); ACE_DEBUG ((LM_DEBUG, "The group contains %d members:\n", id_list->length ())); for (CORBA::ULong i = 0; i < id_list->length (); ++i) ACE_DEBUG ((LM_DEBUG, "%s\n", static_cast<char const*>(id_list[i]))); // Perform <number_of_invocations_> method calls on <Identity> // objects, which are members of the <Object_Group>. Before each // invocations, we get an <Identity> reference to use for that // invocation from our <Object_Group>. Identity_var identity_object; CORBA::String_var identity; CORBA::String_var objref; for (size_t ind = 0; ind < this->number_of_invocations_; ++ind) { objref = object_group->resolve (); obj = orb->string_to_object (objref.in ()); identity_object = Identity::_narrow (obj.in ()); if (CORBA::is_nil (identity_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, "Identity_Client: cannot narrow an object received from" "<Object_Group::resolve> to <Identity>\n"), -1); identity_object->get_name (identity.out ()); ACE_DEBUG ((LM_DEBUG, "Invocation %s\n", identity.in ())); } return 0; }