diff options
author | msmit <msmit@remedy.nl> | 2009-08-27 16:45:41 +0000 |
---|---|---|
committer | msmit <msmit@remedy.nl> | 2009-08-27 16:45:41 +0000 |
commit | f521852e9b83de9ccf30c8fbc92c5bdf3dde4cdd (patch) | |
tree | fb99326744936342bf53200cdeffa70ea2a9ea9c | |
parent | 8c1ae7a1294162be25140f933f26a967f2c3d691 (diff) | |
download | ATCD-f521852e9b83de9ccf30c8fbc92c5bdf3dde4cdd.tar.gz |
Thu Aug 27 16:47:53 UTC 2009 Marcel Smit <msmit@remedy.nl>
* connectors/AMI_CCM/AMI/AMI.mpc:
* connectors/AMI_CCM/AMI/AMI_MyFoo_i.h:
* connectors/AMI_CCM/AMI/AMI_MyFoo_i.cpp:
* connectors/AMI_CCM/AMI/AMI_MyInterface_i.h:
* connectors/AMI_CCM/AMI/AMI_MyInterface_i.cpp:
* connectors/AMI_CCM/AMI/AMI_exec.h:
* connectors/AMI_CCM/AMI/AMI_exec.cpp:
* connectors/AMI_CCM/Hello_Base/Hello_Base.idl:
* connectors/AMI_CCM/Sender/Hello_Sender_exec.h:
* connectors/AMI_CCM/Sender/Hello_Sender_exec.cpp:
* connectors/AMI_CCM/descriptors/run_test.pl:
Refactored code. Also expanded this
example with another interface.
* connectors/AMI_CCM/AMI/AMI_internal_i.h:
* connectors/AMI_CCM/AMI/AMI_internal_i.cpp:
* connectors/AMI_CCM/AMI/AMI_perform_work.h:
* connectors/AMI_CCM/AMI/AMI_perform_work.cpp:
* connectors/AMI_CCM/AMI/AMI_server.h:
* connectors/AMI_CCM/AMI/AMI_server.cpp:
Removed these files.
18 files changed, 726 insertions, 425 deletions
diff --git a/modules/CIAO/ChangeLog b/modules/CIAO/ChangeLog index 734a046c84f..9cecc99a92f 100644 --- a/modules/CIAO/ChangeLog +++ b/modules/CIAO/ChangeLog @@ -1,3 +1,28 @@ +Thu Aug 27 16:47:53 UTC 2009 Marcel Smit <msmit@remedy.nl> + + * connectors/AMI_CCM/AMI/AMI.mpc: + * connectors/AMI_CCM/AMI/AMI_MyFoo_i.h: + * connectors/AMI_CCM/AMI/AMI_MyFoo_i.cpp: + * connectors/AMI_CCM/AMI/AMI_MyInterface_i.h: + * connectors/AMI_CCM/AMI/AMI_MyInterface_i.cpp: + * connectors/AMI_CCM/AMI/AMI_exec.h: + * connectors/AMI_CCM/AMI/AMI_exec.cpp: + * connectors/AMI_CCM/Hello_Base/Hello_Base.idl: + * connectors/AMI_CCM/Sender/Hello_Sender_exec.h: + * connectors/AMI_CCM/Sender/Hello_Sender_exec.cpp: + * connectors/AMI_CCM/descriptors/run_test.pl: + Refactored code. Also expanded this + example with another interface. + + * connectors/AMI_CCM/AMI/AMI_internal_i.h: + * connectors/AMI_CCM/AMI/AMI_internal_i.cpp: + * connectors/AMI_CCM/AMI/AMI_perform_work.h: + * connectors/AMI_CCM/AMI/AMI_perform_work.cpp: + * connectors/AMI_CCM/AMI/AMI_server.h: + * connectors/AMI_CCM/AMI/AMI_server.cpp: + + Removed these files. + Wed Aug 26 18:42:49 UTC 2009 Marcel Smit <msmit@remedy.nl> * connectors/AMI_CCM/AMI/AMI.idl: @@ -13,7 +38,7 @@ Wed Aug 26 18:42:49 UTC 2009 Marcel Smit <msmit@remedy.nl> * connectors/AMI_CCM/Sender/Hello_Sender_exec.cpp: * connectors/AMI_CCM/descriptors/Plan.cdp: Set up (empty) framework in order to test one reply handler - per request. + per request. Wed Aug 26 13:04:12 UTC 2009 Marcel Smit <msmit@remedy.nl> diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI.mpc b/modules/CIAO/connectors/AMI_CCM/AMI/AMI.mpc index 76c76a9d8e6..b3f6fe7c6a3 100644 --- a/modules/CIAO/connectors/AMI_CCM/AMI/AMI.mpc +++ b/modules/CIAO/connectors/AMI_CCM/AMI/AMI.mpc @@ -90,16 +90,14 @@ project(Hello_Base_AMI_exec) : ciao_executor, ami { Source_Files { AMI_exec.cpp - AMI_server.cpp - AMI_perform_work.cpp - AMI_internal_i.cpp + AMI_MyFoo_i.cpp + AMI_MyInterface_i.cpp } Header_Files { AMI_exec.h - AMI_server.h - AMI_perform_work.h - AMI_internal_i.h + AMI_MyFoo_i.h + AMI_MyInterface_i.h AMI_exec_export.h } diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyFoo_i.cpp b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyFoo_i.cpp new file mode 100644 index 00000000000..c9e4875615e --- /dev/null +++ b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyFoo_i.cpp @@ -0,0 +1,169 @@ +// $Id$ + +#include "AMI_MyFoo_i.h" + +namespace CCM_CORBA_AMI_MyFoo_Impl +{ + //============================================================ + // Implementation of the AMI CORBA FOO reply handler + //============================================================ + AMI_MyFoo_reply_handler::AMI_MyFoo_reply_handler (::CCM_AMI::AMI_MyFoo_callback_ptr foo_callback) + : foo_callback_ (::CCM_AMI::AMI_MyFoo_callback::_duplicate (foo_callback)) + { + } + + AMI_MyFoo_reply_handler::~AMI_MyFoo_reply_handler () + { + } + + void + AMI_MyFoo_reply_handler::foo ( + CORBA::Long result, + const char * out_str) + { + printf ("AMI CORBA (FOO) :\tMyFoo Reply Handler::foo\n"); + foo_callback_->foo_callback_handler (result, CORBA::string_dup (out_str)); + //this->_remove_ref (); + } + + void + AMI_MyFoo_reply_handler::foo_excep ( + ::Messaging::ExceptionHolder * excep_holder) + { + printf ("AMI CORBA (FOO) :\tMyFoo Reply Handler::foo_excep\n"); + + try + { + excep_holder->raise_exception (); + } + catch (const CCM_AMI::InternalError& ex) + { + printf ("AMI CORBA (FOO) :\tCaught the correct exception type (CCM_AMI::InternalError) <%d> <%s>\n", + ex.ex.id, ex.ex.error_string.in ()); + + foo_callback_->foo_callback_excep (ex.ex); + + if (ex.ex.id != 42) + { + printf ("ERROR (FOO):\tReceived unexpected ID received in exception handler\n"); + } + if (ACE_OS::strcmp (ex.ex.error_string.in (), "Hello world") != 0) + { + printf ("ERROR (FOO):\tReceived unexpected error string received in exception handler\n"); + } + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("ERROR (FOO) :\tCaught the WRONG exception:"); + } + //this->_remove_ref (); + }; + + //============================================================ + // Implementation of the AMI CORBA FOO interface + //============================================================ + AMI_MyFoo_i::AMI_MyFoo_i (CORBA::ORB_ptr orb, ::CCM_AMI::MyFoo_ptr foo_receiver) + : orb_ (CORBA::ORB::_duplicate (orb)), + foo_receiver_ (::CCM_AMI::MyFoo::_duplicate (foo_receiver)) + { + } + + CORBA::Long + AMI_MyFoo_i::foo (const char * in_str, + CORBA::String_out out_str) + { + try + { + printf ("AMI CORBA (FOO) :\tReceived string <%s>. Try passing it to the Receiver component\n", in_str); + CORBA::Long result = foo_receiver_->foo (CORBA::string_dup (in_str), out_str); + return result; + } + catch (CCM_AMI::InternalError& ex) + { + printf ("AMI CORBA (FOO) :\tCORRECT EXCEPTION -> re-throwing\n"); + CCM_AMI::InternalException excep; + excep.id = ex.ex.id; + excep.error_string = CORBA::string_dup (ex.ex.error_string); + throw CCM_AMI::InternalError (excep); + } + catch (...) + { + printf ("AMI CORBA (FOO) :\t!!!!!UNKNOWN EXCEPTION!!!!!\n"); + CCM_AMI::InternalException excep; + excep.id = 43; + excep.error_string = CORBA::string_dup ("UNKNOWN"); + throw CCM_AMI::InternalError (excep); + } + } + + //============================================================ + // Worker thread to service the AMI CORBA FOO interface + //============================================================ + CORBA_MyFoo_server::CORBA_MyFoo_server (::CCM_AMI::MyFoo_ptr foo_receiver) + : foo_receiver_ (::CCM_AMI::MyFoo::_duplicate (foo_receiver)) + { + } + + int CORBA_MyFoo_server::svc () + { + try + { + int argc = 2; + ACE_TCHAR **argv = new ACE_TCHAR *[argc]; + argv[0] = ACE::strnew (ACE_TEXT ("")); + argv[1] = ACE::strnew (ACE_TEXT ("")); + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, ACE_TEXT ("CORBA_MyFoo_server")); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + if (CORBA::is_nil (poa_object.in ())) + { + printf ("Server :\tERROR creating POA \n"); + return 1; + } + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + AMI_MyFoo_i AMI_MyFoo_i (orb.in (), foo_receiver_); + + PortableServer::ObjectId_var id = + root_poa->activate_object (&AMI_MyFoo_i); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + CCM_AMI::MyFoo_var ami_foo_var = + CCM_AMI::MyFoo::_narrow (object.in ()); + + CORBA::String_var ior = + orb->object_to_string (ami_foo_var.in ()); + + // If the ior_output_file exists, output the ior to it + FILE *output_file= ACE_OS::fopen ("foo.ior", "w"); + if (output_file == 0) + { + printf ("Cannot open output file for writing IOR: server.ior\n"); + return 1; + } + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + printf ("AMI CORBA (FOO) :\tFOO Server is activated\n"); + + orb->run (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Caught exception:"); + return 1; + } + + return 0; + } +} diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyFoo_i.h b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyFoo_i.h new file mode 100644 index 00000000000..c71867cacb2 --- /dev/null +++ b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyFoo_i.h @@ -0,0 +1,63 @@ +// $Id$ + +#ifndef AMI_MyFoo_i_H +#define AMI_MyFoo_i_H + +#include "AMIS.h" +#include "ace/Task.h" + +namespace CCM_CORBA_AMI_MyFoo_Impl +{ + //============================================================ + // Implementation of the AMI CORBA FOO reply handler + //============================================================ + class AMI_MyFoo_reply_handler : public POA_CCM_AMI::AMI_MyFooHandler + { + public: + AMI_MyFoo_reply_handler ( + ::CCM_AMI::AMI_MyFoo_callback_ptr foo_callback); + ~AMI_MyFoo_reply_handler (void); + + void + foo ( + CORBA::Long result, + const char * out_str); + + void + foo_excep ( + ::Messaging::ExceptionHolder * excep_holder); + + private: + ::CCM_AMI::AMI_MyFoo_callback_var foo_callback_; + }; + + class AMI_MyFoo_i : public POA_CCM_AMI::MyFoo + { + public: + /// ctor + AMI_MyFoo_i ( + CORBA::ORB_ptr orb, + ::CCM_AMI::MyFoo_ptr foo_receiver); + + // The AMI methods. + CORBA::Long foo (const char * in_str, + CORBA::String_out out_str); + private: + CORBA::ORB_var orb_; + ::CCM_AMI::MyFoo_var foo_receiver_; + }; + + // CORBA server which delivers the MyFoo interface + class CORBA_MyFoo_server : public ACE_Task_Base + { + public: + CORBA_MyFoo_server ( + ::CCM_AMI::MyFoo_ptr foo_receiver); + virtual int svc (void); + + private: + ::CCM_AMI::MyFoo_var foo_receiver_; + }; +}; +#endif /* AMI_MyFoo_i_H */ + diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyInterface_i.cpp b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyInterface_i.cpp new file mode 100644 index 00000000000..a0fa16bab6f --- /dev/null +++ b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyInterface_i.cpp @@ -0,0 +1,168 @@ +// $Id$ + +#include "AMI_MyInterface_i.h" + +namespace CCM_CORBA_AMI_MyInterface_Impl +{ + //============================================================ + // Implementation of the AMI CORBA INTERFACE reply handler + //============================================================ + AMI_MyInterface_reply_handler::AMI_MyInterface_reply_handler ( + ::CCM_AMI::AMI_MyInterface_callback_ptr interface_callback) + : interface_callback_ (::CCM_AMI::AMI_MyInterface_callback::_duplicate (interface_callback)) + { + } + + AMI_MyInterface_reply_handler::~AMI_MyInterface_reply_handler () + { + } + + void + AMI_MyInterface_reply_handler::do_something_with_something ( + CORBA::Float result) + { + printf ("AMI CORBA :\tMyInterface Reply Handler::do_something_with_something\n"); + interface_callback_->do_something_with_something_callback_handler (result); + //this->_remove_ref (); + } + + void + AMI_MyInterface_reply_handler::do_something_with_something_excep ( + ::Messaging::ExceptionHolder * excep_holder) + { + printf ("AMI CORBA :\tMyInterface Reply Handler::do_something_with_something_excep\n"); + + try + { + excep_holder->raise_exception (); + } + catch (const CCM_AMI::InternalError& ex) + { + printf ("AMI CORBA (INTERFACE) :\tCaught the correct exception type (CCM_AMI::InternalError) <%d> <%s>\n", + ex.ex.id, ex.ex.error_string.in ()); + + interface_callback_->do_something_with_something_callback_excep (ex.ex); + + if (ex.ex.id != 42) + { + printf ("ERROR (INTERFACE) :\tReceived unexpected ID received in exception handler\n"); + } + if (ACE_OS::strcmp (ex.ex.error_string.in (), "Hello world") != 0) + { + printf ("ERROR (INTERFACE) :\tReceived unexpected error string received in exception handler\n"); + } + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("ERROR (FOO) :\tCaught the WRONG exception:"); + } + //this->_remove_ref (); + } + + //============================================================ + // Implementation of the AMI CORBA FOO interface + //============================================================ + AMI_MyInterface_i::AMI_MyInterface_i (CORBA::ORB_ptr orb, ::CCM_AMI::MyInterface_ptr interface_receiver) + : orb_ (CORBA::ORB::_duplicate (orb)), + interface_receiver_ (::CCM_AMI::MyInterface::_duplicate (interface_receiver)) + { + } + + CORBA::Float + AMI_MyInterface_i::do_something_with_something (CORBA::Short something) + { + try + { + printf ("AMI CORBA (INTERFACE) :\tReceived short <%d>. Try passing it to the Receiver component\n", something); + CORBA::Float result = interface_receiver_->do_something_with_something (something); + return result; + } + catch (CCM_AMI::InternalError& ex) + { + printf ("AMI CORBA (INTERFACE) :\tCORRECT EXCEPTION -> re-throwing\n"); + CCM_AMI::InternalException excep; + excep.id = ex.ex.id; + excep.error_string = CORBA::string_dup (ex.ex.error_string); + throw CCM_AMI::InternalError (excep); + } + catch (...) + { + printf ("AMI CORBA (INTERFACE) :\t!!!!!UNKNOWN EXCEPTION!!!!!\n"); + CCM_AMI::InternalException excep; + excep.id = 43; + excep.error_string = CORBA::string_dup ("UNKNOWN"); + throw CCM_AMI::InternalError (excep); + } + } + + //============================================================ + // Worker thread to service the AMI CORBA FOO interface + //============================================================ + CORBA_MyInterface_server::CORBA_MyInterface_server (::CCM_AMI::MyInterface_ptr interface_receiver) + : interface_receiver_ (::CCM_AMI::MyInterface::_duplicate (interface_receiver)) + { + } + + int CORBA_MyInterface_server::svc () + { + try + { + int argc = 2; + ACE_TCHAR **argv = new ACE_TCHAR *[argc]; + argv[0] = ACE::strnew (ACE_TEXT ("")); + argv[1] = ACE::strnew (ACE_TEXT ("")); + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, ACE_TEXT ("CORBA_MyInterface_server")); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + if (CORBA::is_nil (poa_object.in ())) + { + printf ("Server :\tERROR creating POA \n"); + return 1; + } + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + AMI_MyInterface_i AMI_MyInterface_i (orb.in (), interface_receiver_); + + PortableServer::ObjectId_var id = + root_poa->activate_object (&AMI_MyInterface_i); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + CCM_AMI::MyInterface_var ami_interface_var = + CCM_AMI::MyInterface::_narrow (object.in ()); + + CORBA::String_var ior = + orb->object_to_string (ami_interface_var.in ()); + + // If the ior_output_file exists, output the ior to it + FILE *output_file= ACE_OS::fopen ("interface.ior", "w"); + if (output_file == 0) + { + printf ("Cannot open output file for writing IOR: interface.ior\n"); + return 1; + } + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + printf ("AMI CORBA (INTERFACE) :\tServer is activated\n"); + + orb->run (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Caught exception:"); + return 1; + } + + return 0; + } +} diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyInterface_i.h b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyInterface_i.h new file mode 100644 index 00000000000..3eb2b2d04f8 --- /dev/null +++ b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_MyInterface_i.h @@ -0,0 +1,63 @@ +// $Id$ + +#ifndef AMI_MyInterface_i_H +#define AMI_MyInterface_i_H + +#include "AMIS.h" +#include "ace/Task.h" + +namespace CCM_CORBA_AMI_MyInterface_Impl +{ + //============================================================ + // Implementation of the AMI CORBA INTERFACE reply handler + //============================================================ + class AMI_MyInterface_reply_handler : public POA_CCM_AMI::AMI_MyInterfaceHandler + { + public: + AMI_MyInterface_reply_handler ( + ::CCM_AMI::AMI_MyInterface_callback_ptr interface_callback); + ~AMI_MyInterface_reply_handler (void); + + void + do_something_with_something ( + CORBA::Float result); + + void + do_something_with_something_excep ( + ::Messaging::ExceptionHolder * excep_holder); + + private: + ::CCM_AMI::AMI_MyInterface_callback_var interface_callback_; + }; + + class AMI_MyInterface_i : public POA_CCM_AMI::MyInterface + { + public: + /// ctor + AMI_MyInterface_i ( + CORBA::ORB_ptr orb, + ::CCM_AMI::MyInterface_ptr interface_receiver); + + CORBA::Float + do_something_with_something ( + CORBA::Short something); + + private: + CORBA::ORB_var orb_; + ::CCM_AMI::MyInterface_var interface_receiver_; + }; + + // CORBA server which delivers the MyInterface interface + class CORBA_MyInterface_server : public ACE_Task_Base + { + public: + CORBA_MyInterface_server ( + ::CCM_AMI::MyInterface_ptr interface_receiver); + virtual int svc (void); + + private: + ::CCM_AMI::MyInterface_var interface_receiver_; + }; +}; +#endif /* AMI_MyInterface_i_H */ + diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_exec.cpp b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_exec.cpp index d36d4198e99..90fb7134705 100644 --- a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_exec.cpp +++ b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_exec.cpp @@ -29,130 +29,46 @@ // be/be_codegen.cpp:1278 #include "AMI_exec.h" -#include "AMI_perform_work.h" #include "ciao/CIAO_common.h" -#include "AMI_server.h" +#include "AMI_MyFoo_i.h" +#include "AMI_MyInterface_i.h" namespace CIAO_Hello_AMI_AMI_Impl { //============================================================ - // Implementation of the AMI CORBA FOO reply handler + // Worker thread to call "perform_work" //============================================================ - class AMI_MyFoo_reply_handler : public POA_CCM_AMI::AMI_MyFooHandler + AMI_perform_work::AMI_perform_work (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) { - public: - AMI_MyFoo_reply_handler (::CCM_AMI::AMI_MyFoo_callback_ptr foo_callback) - : foo_callback_ (::CCM_AMI::AMI_MyFoo_callback::_duplicate (foo_callback)) - { - }; - - void foo (CORBA::Long result, - const char * out_str) - { - printf ("AMI CORBA (FOO) :\tMyFoo Reply Handler::foo\n"); - foo_callback_->foo_callback_handler (result, CORBA::string_dup (out_str)); - this->_remove_ref (); - }; - - void foo_excep (::Messaging::ExceptionHolder * excep_holder) - { - printf ("AMI CORBA (FOO) :\tMyFoo Reply Handler::foo_excep\n"); - - try - { - excep_holder->raise_exception (); - } - catch (const CCM_AMI::InternalError& ex) - { - printf ("AMI CORBA (FOO) :\tCaught the correct exception type (CCM_AMI::InternalError) <%d> <%s>\n", - ex.ex.id, ex.ex.error_string.in ()); - - foo_callback_->foo_callback_excep (ex.ex); - - if (ex.ex.id != 42) - { - printf ("ERROR (FOO):\tReceived unexpected ID received in exception handler\n"); - } - if (ACE_OS::strcmp (ex.ex.error_string.in (), "Hello world") != 0) - { - printf ("ERROR (FOO):\tReceived unexpected error string received in exception handler\n"); - } - } - catch (const CORBA::Exception& ex) - { - ex._tao_print_exception ("ERROR (FOO) :\tCaught the WRONG exception:"); - } - this->_remove_ref (); - }; - - ~AMI_MyFoo_reply_handler (void) - { - }; - private: - ::CCM_AMI::AMI_MyFoo_callback_var foo_callback_; - }; + } - - //============================================================ - // Implementation of the AMI CORBA INTERFACE reply handler - //============================================================ - class AMI_MyInterface_reply_handler : public POA_CCM_AMI::AMI_MyInterfaceHandler + int AMI_perform_work::svc () { - public: - AMI_MyInterface_reply_handler (::CCM_AMI::AMI_MyInterface_callback_ptr interface_callback) - : interface_callback_ (::CCM_AMI::AMI_MyInterface_callback::_duplicate (interface_callback)) - { - }; - - void do_something_with_something (CORBA::Float /*result*/) + try { - printf ("AMI CORBA :\tMyInterface Reply Handler::do_something_with_something\n"); - //foo_callback_->foo_callback_handler (result, CORBA::string_dup (out_str)); - this->_remove_ref (); - }; - - void do_something_with_something_excep (::Messaging::ExceptionHolder * excep_holder) - { - printf ("AMI CORBA :\tMyInterface Reply Handler::do_something_with_something_excep\n"); - - try - { - excep_holder->raise_exception (); - } - catch (const CCM_AMI::InternalError& ex) - { - printf ("AMI CORBA (INTERFACE) :\tCaught the correct exception type (CCM_AMI::InternalError) <%d> <%s>\n", - ex.ex.id, ex.ex.error_string.in ()); - - //foo_callback_->foo_callback_excep (ex.ex); - - if (ex.ex.id != 42) - { - printf ("ERROR (INTERFACE) :\tReceived unexpected ID received in exception handler\n"); - } - if (ACE_OS::strcmp (ex.ex.error_string.in (), "Hello world") != 0) + printf ("AMI :\tPerform work started\n"); + while (1) { - printf ("ERROR (INTERFACE) :\tReceived unexpected error string received in exception handler\n"); + if (orb_->work_pending()) + orb_->perform_work(); + ACE_Time_Value tv (0, 1000); + ACE_OS::sleep (tv); } - } - catch (const CORBA::Exception& ex) - { - ex._tao_print_exception ("ERROR (FOO) :\tCaught the WRONG exception:"); - } - this->_remove_ref (); - }; - - ~AMI_MyInterface_reply_handler (void) + } + catch (const CORBA::Exception& ex) { - }; - private: - ::CCM_AMI::AMI_MyInterface_callback_var interface_callback_; - }; + ex._tao_print_exception ("Caught exception:"); + return 1; + } + printf ("AMI :\t Exiting perform work"); + return 0; + } + //============================================================ // Facet Executor Implementation Class: AMI_MyFoo_exec_i //============================================================ - AMI_MyFoo_exec_i::AMI_MyFoo_exec_i ( ::CCM_AMI::AMI_MyFoo_callback_ptr foo_callback) : foo_callback_ (::CCM_AMI::AMI_MyFoo_callback::_duplicate (foo_callback)) @@ -163,13 +79,13 @@ namespace CIAO_Hello_AMI_AMI_Impl argv[0] = ACE::strnew (ACE_TEXT ("-ORBAMICollocation")); argv[1] = ACE::strnew (ACE_TEXT ("0")); CORBA::ORB_var orb = - CORBA::ORB_init (argc, argv, ACE_TEXT ("AMI client")); + CORBA::ORB_init (argc, argv, ACE_TEXT ("AMI_foo_client")); CORBA::Object_var object = - orb->string_to_object ("file://server.ior"); - ami_foo_var_ = CCM_AMI::MyFoo::_narrow (object.in ()); + orb->string_to_object ("file://foo.ior"); + ami_foo_server_ = CCM_AMI::MyFoo::_narrow (object.in ()); - if (CORBA::is_nil (ami_foo_var_.in ())) + if (CORBA::is_nil (ami_foo_server_.in ())) { printf ("Server is NIL\n"); } @@ -199,14 +115,16 @@ namespace CIAO_Hello_AMI_AMI_Impl void AMI_MyFoo_exec_i::sendc_foo ( + ::CCM_AMI::AMI_MyFoo_callback_ptr /*cb_handler */, const char * in_str) { - printf ("AMI :\tsendc_foo <%s>\n", in_str); - AMI_MyFoo_reply_handler* handler = new AMI_MyFoo_reply_handler (foo_callback_); + printf ("AMI (FOO) :\tsendc_foo <%s>\n", in_str); + ::CCM_CORBA_AMI_MyFoo_Impl::AMI_MyFoo_reply_handler* handler = + new ::CCM_CORBA_AMI_MyFoo_Impl::AMI_MyFoo_reply_handler (foo_callback_); CCM_AMI::AMI_MyFooHandler_var the_handler_var = handler->_this (); - printf ("AMI :\tSending string <%s> to AMI CORBA server\n", in_str); - ami_foo_var_->sendc_foo (the_handler_var.in (), in_str); - printf ("AMI : \tInvoked sendc_foo\n"); + printf ("AMI (FOO) :\tSending string <%s> to AMI CORBA server\n", in_str); + ami_foo_server_->sendc_foo (the_handler_var.in (), in_str); + printf ("AMI (FOO) : \tInvoked sendc_foo\n"); } //============================================================ @@ -217,6 +135,38 @@ namespace CIAO_Hello_AMI_AMI_Impl ::CCM_AMI::AMI_MyInterface_callback_ptr interface_callback) : interface_callback_ (::CCM_AMI::AMI_MyInterface_callback::_duplicate (interface_callback)) { + //initialize AMI client + int argc = 2; + ACE_TCHAR **argv = new ACE_TCHAR *[argc]; + argv[0] = ACE::strnew (ACE_TEXT ("-ORBAMICollocation")); + argv[1] = ACE::strnew (ACE_TEXT ("0")); + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, ACE_TEXT ("AMI_Interface_client")); + + CORBA::Object_var object = + orb->string_to_object ("file://interface.ior"); + ami_interface_server_ = CCM_AMI::MyInterface::_narrow (object.in ()); + + if (CORBA::is_nil (ami_interface_server_.in ())) + { + printf ("Server is NIL\n"); + } + // Activate POA to handle the call back. + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + if (CORBA::is_nil (poa_object.in ())) + printf ("POA is NIL!\n"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + poa_manager->activate (); + AMI_perform_work *pw = new AMI_perform_work (orb.in ()); + pw->activate (); } AMI_MyInterface_exec_i::~AMI_MyInterface_exec_i (void) @@ -227,8 +177,16 @@ namespace CIAO_Hello_AMI_AMI_Impl void AMI_MyInterface_exec_i::sendc_do_something_with_something ( - CORBA::Short /*something*/) + ::CCM_AMI::AMI_MyInterface_callback_ptr /* cb_handler */, + CORBA::Short something) { + printf ("AMI (INTERFACE) :\tsendc_do_something_with_something <%d>\n", something); + ::CCM_CORBA_AMI_MyInterface_Impl::AMI_MyInterface_reply_handler* handler = + new ::CCM_CORBA_AMI_MyInterface_Impl::AMI_MyInterface_reply_handler (interface_callback_); + CCM_AMI::AMI_MyInterfaceHandler_var the_handler_var = handler->_this (); + printf ("AMI (INTERFACE) :\tSending short <%d> to AMI CORBA server\n", something); + ami_interface_server_->sendc_do_something_with_something (the_handler_var.in (), something); + printf ("AMI (INTERFACE) : \tInvoked sendc_do_something_with_something\n"); } //============================================================ @@ -291,9 +249,17 @@ namespace CIAO_Hello_AMI_AMI_Impl { ::CCM_AMI::MyFoo_var receiver_foo = this->context_->get_connection_my_foo_receiver (); - AMI_server* srv = new AMI_server (receiver_foo.in ()); - printf ("AMI :\tStarting server thread.\n"); - srv->activate (); + ::CCM_CORBA_AMI_MyFoo_Impl::CORBA_MyFoo_server* foo_srv = + new ::CCM_CORBA_AMI_MyFoo_Impl::CORBA_MyFoo_server (receiver_foo.in ()); + printf ("AMI :\tStarting MyFoo CORBA server thread.\n"); + foo_srv->activate (); + + ::CCM_AMI::MyInterface_var receiver_interface = + this->context_->get_connection_my_interface_receiver (); + ::CCM_CORBA_AMI_MyInterface_Impl::CORBA_MyInterface_server* interface_srv = + new ::CCM_CORBA_AMI_MyInterface_Impl::CORBA_MyInterface_server (receiver_interface.in ()); + printf ("AMI :\tStarting MyInterface CORBA server thread.\n"); + interface_srv->activate (); } void diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_exec.h b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_exec.h index 93aa0dffe09..66f373adece 100644 --- a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_exec.h +++ b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_exec.h @@ -44,6 +44,16 @@ namespace CIAO_Hello_AMI_AMI_Impl { + class AMI_perform_work : public ACE_Task_Base + { + public: + AMI_perform_work (CORBA::ORB_ptr orb); + virtual int svc (void); + + private: + CORBA::ORB_var orb_; + }; + class AMI_MyFoo_exec_i : public virtual ::CCM_AMI::CCM_AMI_MyFoo, public virtual ::CORBA::LocalObject @@ -52,17 +62,13 @@ namespace CIAO_Hello_AMI_AMI_Impl AMI_MyFoo_exec_i (::CCM_AMI::AMI_MyFoo_callback_ptr foo_callback); virtual ~AMI_MyFoo_exec_i (void); - - // Operations and attributes from ::CCM_AMI::AMI_ami_foo - - // TAO_IDL - Generated from - // be/be_visitor_operation/operation_ch.cpp:46 - virtual void sendc_foo ( + ::CCM_AMI::AMI_MyFoo_callback_ptr cb_handler, const char * in_str); + private: - CCM_AMI::MyFoo_var ami_foo_var_; + CCM_AMI::MyFoo_var ami_foo_server_; ::CCM_AMI::AMI_MyFoo_callback_var foo_callback_; }; @@ -74,17 +80,14 @@ namespace CIAO_Hello_AMI_AMI_Impl AMI_MyInterface_exec_i (::CCM_AMI::AMI_MyInterface_callback_ptr foo_callback); virtual ~AMI_MyInterface_exec_i (void); - - // Operations and attributes from ::CCM_AMI::AMI_ami_foo - - // TAO_IDL - Generated from - // be/be_visitor_operation/operation_ch.cpp:46 - + virtual void sendc_do_something_with_something ( + ::CCM_AMI::AMI_MyInterface_callback_ptr cb_handler, CORBA::Short something); + private: - CCM_AMI::MyFoo_var ami_foo_var_; + CCM_AMI::MyInterface_var ami_interface_server_; ::CCM_AMI::AMI_MyInterface_callback_var interface_callback_; }; diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_internal_i.cpp b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_internal_i.cpp deleted file mode 100644 index 74b13c97078..00000000000 --- a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_internal_i.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// $Id$ - -#include "AMI_internal_i.h" - -AMI_internal_i::AMI_internal_i (CORBA::ORB_ptr orb, ::CCM_AMI::MyFoo_ptr foo_receiver) - : orb_ (CORBA::ORB::_duplicate (orb)), - foo_receiver_ (::CCM_AMI::MyFoo::_duplicate (foo_receiver)) -{ -} - -CORBA::Long -AMI_internal_i::foo (const char * in_str, - CORBA::String_out out_str) -{ - try - { - printf ("AMI CORBA :\tReceived string <%s>. Try passing it to the Receiver component\n", in_str); - CORBA::Long result = foo_receiver_->foo (CORBA::string_dup (in_str), out_str); - return result; - } - catch (CCM_AMI::InternalError& ex) - { - printf ("AMI CORBA :\tCORRECT EXCEPTION -> re-throwing\n"); - CCM_AMI::InternalException excep; - excep.id = ex.ex.id; - excep.error_string = CORBA::string_dup (ex.ex.error_string); - throw CCM_AMI::InternalError (excep); - } - catch (...) - { - printf ("AMI CORBA :\t!!!!!UNKNOWN EXCEPTION!!!!!\n"); - CCM_AMI::InternalException excep; - excep.id = 43; - excep.error_string = CORBA::string_dup ("UNKNOWN"); - throw CCM_AMI::InternalError (excep); - } -} - -void -AMI_internal_i::shutdown (void) -{ - printf ("AMI CORBA :\tShutting down\n"); - this->orb_->shutdown (0); -} diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_internal_i.h b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_internal_i.h deleted file mode 100644 index 236b27218b1..00000000000 --- a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_internal_i.h +++ /dev/null @@ -1,29 +0,0 @@ -// $Id$ - -#ifndef AMI_INTERNAL_I_H -#define AMI_INTERNAL_I_H - -#include "AMIS.h" -#include "AMI_exec.h" - -class AMI_internal_i : public POA_CCM_AMI::MyFoo -{ -public: - /// ctor - AMI_internal_i ( - CORBA::ORB_ptr orb, - ::CCM_AMI::MyFoo_ptr foo_receiver); - - // The AMI methods. - CORBA::Long foo (const char * in_str, - CORBA::String_out out_str); - - void shutdown (void); - -private: - CORBA::ORB_var orb_; - ::CCM_AMI::MyFoo_var foo_receiver_; -}; - -#endif /* AMI_INTERNAL_I_H */ - diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_perform_work.cpp b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_perform_work.cpp deleted file mode 100644 index b4f4d00b71b..00000000000 --- a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_perform_work.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// $Id$ - -#include "AMI_perform_work.h" -#include "ace/OS_NS_unistd.h" - -AMI_perform_work::AMI_perform_work (CORBA::ORB_ptr orb) - : orb_ (CORBA::ORB::_duplicate (orb)) -{ -} - -int AMI_perform_work::svc () -{ - try - { - printf ("AMI :\tPerform work started\n"); - while (1) - { - if (orb_->work_pending()) - { - orb_->perform_work(); - } - ACE_Time_Value tv (0, 1000); - ACE_OS::sleep (tv); - } - } - catch (const CORBA::Exception& ex) - { - ex._tao_print_exception ("Caught exception:"); - return 1; - } - printf ("AMI :\t Exiting perform work"); - return 0; -} diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_perform_work.h b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_perform_work.h deleted file mode 100644 index f1698426a7e..00000000000 --- a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_perform_work.h +++ /dev/null @@ -1,20 +0,0 @@ - -#ifndef AMI_PERFORM_WORK_H -#define AMI_PERFORM_WORK_H - -#include "ace/Task.h" -#include "AMIC.h" - -class AMI_perform_work : public ACE_Task_Base -{ -public: - /// ctor - AMI_perform_work (CORBA::ORB_ptr orb); - virtual int svc (void); - -private: - CORBA::ORB_var orb_; -}; - -#endif /* AMI_PERFORM_WORK_H */ - diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_server.cpp b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_server.cpp deleted file mode 100644 index 6494bc38047..00000000000 --- a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_server.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// $Id$ - -#include "AMI_server.h" - -AMI_server::AMI_server (::CCM_AMI::MyFoo_ptr foo_receiver) - : foo_receiver_ (::CCM_AMI::MyFoo::_duplicate (foo_receiver)) -{ -} - -int AMI_server::svc () -{ - try - { - int argc = 2; - ACE_TCHAR **argv = new ACE_TCHAR *[argc]; - argv[0] = ACE::strnew (ACE_TEXT ("")); - argv[1] = ACE::strnew (ACE_TEXT ("")); - CORBA::ORB_var orb = - CORBA::ORB_init (argc, argv, ACE_TEXT ("AMI_server")); - - CORBA::Object_var poa_object = - orb->resolve_initial_references("RootPOA"); - - if (CORBA::is_nil (poa_object.in ())) - { - printf ("Server :\tERROR creating POA \n"); - return 1; - } - PortableServer::POA_var root_poa = - PortableServer::POA::_narrow (poa_object.in ()); - - PortableServer::POAManager_var poa_manager = - root_poa->the_POAManager (); - - AMI_internal_i ami_internal_i (orb.in (), foo_receiver_); - - PortableServer::ObjectId_var id = - root_poa->activate_object (&ami_internal_i); - - CORBA::Object_var object = root_poa->id_to_reference (id.in ()); - - CCM_AMI::MyFoo_var ami_foo_var = - CCM_AMI::MyFoo::_narrow (object.in ()); - - CORBA::String_var ior = - orb->object_to_string (ami_foo_var.in ()); - - // If the ior_output_file exists, output the ior to it - FILE *output_file= ACE_OS::fopen ("server.ior", "w"); - if (output_file == 0) - { - printf ("Cannot open output file for writing IOR: server.ior\n"); - return 1; - } - ACE_OS::fprintf (output_file, "%s", ior.in ()); - ACE_OS::fclose (output_file); - - poa_manager->activate (); - - printf ("AMI CORBA :\tServer is activated\n"); - - orb->run (); - } - catch (const CORBA::Exception& ex) - { - ex._tao_print_exception ("Caught exception:"); - return 1; - } - - return 0; -} diff --git a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_server.h b/modules/CIAO/connectors/AMI_CCM/AMI/AMI_server.h deleted file mode 100644 index 8d1cce6e7da..00000000000 --- a/modules/CIAO/connectors/AMI_CCM/AMI/AMI_server.h +++ /dev/null @@ -1,21 +0,0 @@ -// $Id$ - -#ifndef AMI_SERVER_H -#define AMI_SERVER_H - -#include "ace/Task.h" -#include "AMI_internal_i.h" - -class AMI_server : public ACE_Task_Base -{ -public: - AMI_server ( - ::CCM_AMI::MyFoo_ptr foo_receiver); - virtual int svc (void); - -private: - ::CCM_AMI::MyFoo_var foo_receiver_; -}; - -#endif /* AMI_SERVER_H */ - diff --git a/modules/CIAO/connectors/AMI_CCM/Hello_Base/Hello_Base.idl b/modules/CIAO/connectors/AMI_CCM/Hello_Base/Hello_Base.idl index fac219cfd4f..f425d6f0c9c 100644 --- a/modules/CIAO/connectors/AMI_CCM/Hello_Base/Hello_Base.idl +++ b/modules/CIAO/connectors/AMI_CCM/Hello_Base/Hello_Base.idl @@ -4,12 +4,6 @@ module CCM_AMI { - // AMI component. Sender calls AMI-component and AMI-component calls Receiver - // using the AMI_foo interface. - interface AMI_MyFoo - { - void sendc_foo (in string in_str); - }; // callback interface from AMI-component to Sender component interface AMI_MyFoo_callback @@ -18,15 +12,22 @@ module CCM_AMI void foo_callback_excep (in CCM_AMI::InternalException exception_holder); }; - interface AMI_MyInterface + // AMI component. Sender calls AMI-component and AMI-component calls Receiver + // using the AMI_foo interface. + interface AMI_MyFoo { - void sendc_do_something_with_something (in short something); + void sendc_foo (in AMI_MyFoo_callback cb_handler, in string in_str); }; - + // callback interface from AMI-component to Sender component interface AMI_MyInterface_callback { void do_something_with_something_callback_handler (in float result); void do_something_with_something_callback_excep (in CCM_AMI::InternalException exception_holder); }; + + interface AMI_MyInterface + { + void sendc_do_something_with_something (in AMI_MyInterface_callback cb_handler, in short something); + }; }; diff --git a/modules/CIAO/connectors/AMI_CCM/Sender/Hello_Sender_exec.cpp b/modules/CIAO/connectors/AMI_CCM/Sender/Hello_Sender_exec.cpp index 4010dd5d81f..200d7aa267e 100644 --- a/modules/CIAO/connectors/AMI_CCM/Sender/Hello_Sender_exec.cpp +++ b/modules/CIAO/connectors/AMI_CCM/Sender/Hello_Sender_exec.cpp @@ -46,25 +46,28 @@ namespace CIAO_Hello_AMI_Sender_Impl { } + //============================================================ // Operations from ::CCM_AMI::MyFoo_callback - + //============================================================ void MyFoo_callback_exec_i::foo_callback_handler ( ::CORBA::Long result, const char * answer) { - printf ("Sender :\tCallback from AMI : result <%d> answer <%s>\n", result, answer); + printf ("Sender (FOO) :\tCallback from AMI : result <%d> answer <%s>\n", result, answer); } void MyFoo_callback_exec_i::foo_callback_excep ( const ::CCM_AMI::InternalException & exception_holder) { - //printf ("Sender :\tCallback EXCEPTION from AMI : cookie <%d> error <%s>\n", ck, exception_holder.error_string); - printf ("Sender :\tCallback EXCEPTION from AMI : exception id : <%d> exception error : <%s>\n", + printf ("Sender (FOO) :\tCallback EXCEPTION from AMI : exception id : <%d> exception error : <%s>\n", exception_holder.id, exception_holder.error_string.in ()); } - + + //============================================================ + // Operations from ::CCM_AMI::MyInterface_callback + //============================================================ MyInterface_callback_exec_i::MyInterface_callback_exec_i () { } @@ -77,87 +80,115 @@ namespace CIAO_Hello_AMI_Sender_Impl MyInterface_callback_exec_i::do_something_with_something_callback_handler ( ::CORBA::Float result) { + printf ("Sender (INTERFACE) :\tCallback from AMI : result <%f>\n", result); } void MyInterface_callback_exec_i::do_something_with_something_callback_excep ( const ::CCM_AMI::InternalException & exception_holder) { + printf ("Sender (INTERFACE) :\tCallback EXCEPTION from AMI : exception id : <%d> exception error : <%s>\n", + exception_holder.id, exception_holder.error_string.in ()); } //============================================================ - // Worker thread for asynchronous invocations + // Worker thread for asynchronous invocations for MyFoo //============================================================ - asynch_generator::asynch_generator (::CCM_AMI::AMI_MyFoo_ptr foo_ami) - : foo_ami_ (::CCM_AMI::AMI_MyFoo::_duplicate (foo_ami)) + asynch_foo_generator::asynch_foo_generator (::CCM_AMI::AMI_MyFoo_ptr my_foo_ami) + : my_foo_ami_ (::CCM_AMI::AMI_MyFoo::_duplicate (my_foo_ami)) { } - int asynch_generator::svc () + int asynch_foo_generator::svc () { ACE_OS::sleep (3); for (int i = 0; i < 5; ++i) { - if (CORBA::is_nil (foo_ami_)) + if (CORBA::is_nil (my_foo_ami_)) { - printf ("Sender (SYNCH) :\tfoo_receiver is NIL !!!\n"); + printf ("Sender (ASYNCH) :\tfoo_ami is NIL !!!\n"); return 1; } else { - foo_ami_->sendc_foo ("Do something asynchronous"); - printf ("Sender (SYNCH) :\tInvoked Asynchronous call\n"); + my_foo_ami_->sendc_foo (0, "Do something asynchronous"); + printf ("Sender (ASYNCH) :\tInvoked Asynchronous call\n"); } } - /* - printf ("GLOBAL REPLY HANDLER\n"); - for (int i = 0; i < 5; ++i) - { - foo_ami_->sendc_foo (0, "Do something asynchronous"); - printf ("Sender (SYNCH) :\tInvoked Asynchronous call\n"); - } -*/ - printf ("Sender (SYNCH) :\tInvoke Asynchronous call to test EXCEPTION HANDLING\n"); - foo_ami_->sendc_foo (""); - printf ("Sender (SYNCH) :\tInvoked Asynchronous call.\n"); + printf ("Sender (ASYNCH) :\tInvoke Asynchronous call to test EXCEPTION HANDLING\n"); + my_foo_ami_->sendc_foo (0, ""); + printf ("Sender (ASYNCH) :\tInvoked Asynchronous call.\n"); return 0; } //============================================================ - // Worker thread for synchronous invocations + // Worker thread for synchronous invocations for MyFoo //============================================================ - synch_generator::synch_generator (::CCM_AMI::MyFoo_ptr foo_ami) - : foo_ami_ (::CCM_AMI::MyFoo::_duplicate (foo_ami)) + synch_foo_generator::synch_foo_generator (::CCM_AMI::MyFoo_ptr my_foo_ami) + : my_foo_ami_ (::CCM_AMI::MyFoo::_duplicate (my_foo_ami)) { } - int synch_generator::svc () + int synch_foo_generator::svc () { ACE_OS::sleep (3); //run synch calls char * out_str; for (int i = 0; i < 5; ++i) - { - CORBA::Long result = foo_ami_->foo ("Do something synchronous", out_str); - printf ("Sender (SYNCH):\tInvoked synchronous call result <%d> answer <%s>\n", result, out_str); - } + { + CORBA::Long result = my_foo_ami_->foo ("Do something synchronous", out_str); + printf ("Sender (SYNCH):\tInvoked synchronous call result <%d> answer <%s>\n", result, out_str); + } try - { - CORBA::Long result = foo_ami_->foo ("", out_str); - printf ("Sender (SYNCH) :\tInvoked synchronous call result <%d> answer <%s>\n", result, out_str); - } + { + CORBA::Long result = my_foo_ami_->foo ("", out_str); + printf ("Sender (SYNCH) :\tInvoked synchronous call result <%d> answer <%s>\n", result, out_str); + } catch (CCM_AMI::InternalError& ex) + { + printf ("Sender (SYNCH) :\tExpected Exception caught : <%d> <%s>\n", ex.ex.id, ex.ex.error_string.in ()); + } + return 0; + } + + //============================================================ + // Worker thread for asynchronous invocations for MyInterface + //============================================================ + asynch_interface_generator::asynch_interface_generator (::CCM_AMI::AMI_MyInterface_ptr my_interface_ami) + : my_interface_ami_ (::CCM_AMI::AMI_MyInterface::_duplicate (my_interface_ami)) + { + } + + int asynch_interface_generator::svc () + { + ACE_OS::sleep (3); + for (int i = 1; i < 15; ++i) { - printf ("Sender (SYNCH) :\tExpected Exception caught : <%d> <%s>\n", ex.ex.id, ex.ex.error_string.in ()); + if (CORBA::is_nil (my_interface_ami_)) + { + printf ("Sender (INTERFACE) :\tinterface_ami is NIL !!!\n"); + return 1; + } + else + { + printf ("Sender (INTERFACE) :\tInvoke Asynchronous call\n"); + //MyInterface_callback_exec_i* cb = new MyInterface_callback_exec_i (); + my_interface_ami_->sendc_do_something_with_something (0, i); + printf ("Sender (INTERFACE) :\tInvoked Asynchronous call\n"); + } } + printf ("Sender (INTERFACE) :\tInvoke Asynchronous call to test EXCEPTION HANDLING\n"); + my_interface_ami_->sendc_do_something_with_something (0, 0); + printf ("Sender (INTERFACE) :\tInvoked Asynchronous call.\n"); return 0; } - + //============================================================ // Component Executor Implementation Class: Sender_exec_i //============================================================ - Sender_exec_i::Sender_exec_i (void) + : global_foo_callback_ (0), + global_interface_callback_ (0) { } @@ -174,13 +205,23 @@ namespace CIAO_Hello_AMI_Sender_Impl ::CCM_AMI::CCM_AMI_MyFoo_callback_ptr Sender_exec_i::get_the_my_foo_callback () { - return new MyFoo_callback_exec_i (); + if (CORBA::is_nil (global_foo_callback_)) + { + global_foo_callback_ = new MyFoo_callback_exec_i (); + } + + return global_foo_callback_; } ::CCM_AMI::CCM_AMI_MyInterface_callback_ptr Sender_exec_i::get_the_my_interface_callback () { - return new MyInterface_callback_exec_i (); + if (CORBA::is_nil (global_foo_callback_)) + { + global_interface_callback_ = new MyInterface_callback_exec_i (); + } + + return global_interface_callback_; } // Operations from Components::SessionComponent. @@ -206,16 +247,25 @@ namespace CIAO_Hello_AMI_Sender_Impl void Sender_exec_i::ccm_activate (void) { + ::CCM_AMI::AMI_MyFoo_var asynch_foo = - this->context_->get_connection_run_asynch_my_foo(); + this->context_->get_connection_run_asynch_my_foo(); + asynch_foo_generator* asynch_foo_gen = + new asynch_foo_generator (asynch_foo); + asynch_foo_gen->activate (THR_NEW_LWP | THR_JOINABLE, 1); + ::CCM_AMI::MyFoo_var synch_foo = this->context_->get_connection_run_my_foo (); + synch_foo_generator* synch_foo_gen = + new synch_foo_generator (synch_foo); + synch_foo_gen->activate (THR_NEW_LWP | THR_JOINABLE, 1); - asynch_generator* asynch = new asynch_generator (asynch_foo); - asynch->activate (THR_NEW_LWP | THR_JOINABLE, 1); - - synch_generator* synch = new synch_generator (synch_foo); - synch->activate (THR_NEW_LWP | THR_JOINABLE, 1); + ::CCM_AMI::AMI_MyInterface_var asynch_interface = + this->context_->get_connection_run_asynch_my_interface(); + asynch_interface_generator* asynch_interface_gen = + new asynch_interface_generator (asynch_interface); + asynch_interface_gen->activate (THR_NEW_LWP | THR_JOINABLE, 1); + } void diff --git a/modules/CIAO/connectors/AMI_CCM/Sender/Hello_Sender_exec.h b/modules/CIAO/connectors/AMI_CCM/Sender/Hello_Sender_exec.h index 4b91971643e..5204060dcc6 100644 --- a/modules/CIAO/connectors/AMI_CCM/Sender/Hello_Sender_exec.h +++ b/modules/CIAO/connectors/AMI_CCM/Sender/Hello_Sender_exec.h @@ -46,27 +46,39 @@ namespace CIAO_Hello_AMI_Sender_Impl { // Worker thread for asynchronous invocations - class asynch_generator : public virtual ACE_Task_Base + class asynch_foo_generator : public virtual ACE_Task_Base { public: - asynch_generator (::CCM_AMI::AMI_MyFoo_ptr foo_ami); + asynch_foo_generator (::CCM_AMI::AMI_MyFoo_ptr my_foo_ami); virtual int svc (void); private: - ::CCM_AMI::AMI_MyFoo_var foo_ami_; + ::CCM_AMI::AMI_MyFoo_var my_foo_ami_; }; // Worker thread for synchronous invocations - class synch_generator : public virtual ACE_Task_Base + class synch_foo_generator : public virtual ACE_Task_Base { public: - synch_generator (::CCM_AMI::MyFoo_ptr foo_ami); + synch_foo_generator (::CCM_AMI::MyFoo_ptr my_foo_ami); virtual int svc (void); private: - ::CCM_AMI::MyFoo_var foo_ami_; + ::CCM_AMI::MyFoo_var my_foo_ami_; + }; + + // Worker thread for synchronous invocations + class asynch_interface_generator : public virtual ACE_Task_Base + { + public: + asynch_interface_generator (::CCM_AMI::AMI_MyInterface_ptr my_interface_ami); + + virtual int svc (void); + + private: + ::CCM_AMI::AMI_MyInterface_ptr my_interface_ami_; }; class MyInterface_callback_exec_i @@ -94,7 +106,6 @@ namespace CIAO_Hello_AMI_Sender_Impl const ::CCM_AMI::InternalException & exception_holder); }; - class MyFoo_callback_exec_i : public virtual ::CCM_AMI::CCM_AMI_MyFoo_callback, public virtual ::CORBA::LocalObject @@ -155,6 +166,8 @@ namespace CIAO_Hello_AMI_Sender_Impl private: ::Hello_AMI::CCM_Sender_Context_var context_; + MyFoo_callback_exec_i* global_foo_callback_; + MyInterface_callback_exec_i* global_interface_callback_; }; extern "C" HELLO_SENDER_EXEC_Export ::Components::EnterpriseComponent_ptr diff --git a/modules/CIAO/connectors/AMI_CCM/descriptors/run_test.pl b/modules/CIAO/connectors/AMI_CCM/descriptors/run_test.pl index 17b95666450..fbfa5743e5b 100755 --- a/modules/CIAO/connectors/AMI_CCM/descriptors/run_test.pl +++ b/modules/CIAO/connectors/AMI_CCM/descriptors/run_test.pl @@ -43,7 +43,7 @@ sub delete_ior_files { unlink PerlACE::LocalFile ("EM.ior"); unlink PerlACE::LocalFile ("Receiver.ior"); unlink PerlACE::LocalFile ("Sender.ior"); - unlink PerlACE::LocalFile ("Server.ior"); + unlink PerlACE::LocalFile ("foo.ior"); unlink PerlACE::LocalFile ("AMI.ior"); unlink PerlACE::LocalFile ("ns.ior"); } @@ -185,8 +185,8 @@ if (PerlACE::waitforfile_timed ("AMI.ior", exit 1; } -print "Sleeping 20 seconds to allow task to complete\n"; -sleep (20); +print "Sleeping 30 seconds to allow task to complete\n"; +sleep (30); # Invoke executor - stop the application -. print "Invoking executor - stop the application -\n"; |