diff options
Diffstat (limited to 'modules/CIAO/connectors/ami4ccm/examples/AMI')
8 files changed, 1249 insertions, 0 deletions
diff --git a/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI.idl b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI.idl new file mode 100644 index 00000000000..57478b6d997 --- /dev/null +++ b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI.idl @@ -0,0 +1,33 @@ +// $Id$ + +#ifndef AMI_IDL +#define AMI_IDL + +#include <Components.idl> + +#include "../Hello_Base/Hello_Base.idl" + +module Hello_AMI +{ + component AMI + { + //provides the interface for Sender + provides CCM_AMI::AMI_MyFoo perform_asynch_my_foo; + provides CCM_AMI::AMI_MyInterface perform_asynch_my_interface; + + //uses the interface of the Receiver ('server') + uses CCM_AMI::MyFoo my_foo_receiver; + uses CCM_AMI::MyInterface my_interface_receiver; + + //uses the callback interface of the sender + uses CCM_AMI::AMI_MyFoo_callback callback_my_foo; + uses CCM_AMI::AMI_MyInterface_callback callback_my_interface; + }; + + home AMIHome manages AMI + { + }; +}; + + +#endif diff --git a/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI.mpc b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI.mpc new file mode 100644 index 00000000000..b3f6fe7c6a3 --- /dev/null +++ b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI.mpc @@ -0,0 +1,138 @@ +// $Id$ +// This file is generated with "generate_component_mpc.pl -p Hello_Base AMI" + +project(Hello_Base_AMI_idl_gen) : componentidldefaults { + custom_only = 1 + idlflags += -Wb,stub_export_macro=AMI_STUB_Export \ + -Wb,stub_export_include=AMI_stub_export.h \ + -Wb,skel_export_macro=AMI_SVNT_Export \ + -Wb,skel_export_include=AMI_svnt_export.h \ + -Wb,exec_export_macro=AMI_EXEC_Export \ + -Wb,exec_export_include=AMI_exec_export.h + + IDL_Files { + AMI.idl + } +} + +project(Hello_Base_AMI_lem_gen) : ciaoidldefaults { + after += Hello_Base_AMI_idl_gen + custom_only = 1 + idlflags += -Wb,stub_export_macro=AMI_LEM_STUB_Export \ + -Wb,stub_export_include=AMI_lem_stub_export.h \ + -SS -Gxhst + + IDL_Files { + AMIE.idl + } +} + +project(Hello_Base_AMI_lem_stub) : ccm_svnt, ami { + after += Hello_Base_AMI_lem_gen Hello_Base_AMI_stub Hello_Base_stub + libs += Hello_Base_stub AMI_stub + libpaths += ../lib + libout = ../lib + sharedname = AMI_lem_stub + dynamicflags = AMI_LEM_STUB_BUILD_DLL + + IDL_Files { + } + + Source_Files { + AMIEC.cpp + } + + Header_Files { + AMIEC.h + AMI_lem_stub_export.h + } + + Inline_Files { + AMIEC.inl + } +} + +project(Hello_Base_AMI_stub) : ccm_stub, ami { + after += Hello_Base_AMI_idl_gen Hello_Base_stub + libs += Hello_Base_stub + libpaths += ../lib + libout = ../lib + sharedname = AMI_stub + dynamicflags = AMI_STUB_BUILD_DLL + + IDL_Files { + } + + Source_Files { + AMIC.cpp + } + + Header_Files { + AMIC.h + AMI_stub_export.h + } + + Inline_Files { + AMIC.inl + } +} + +project(Hello_Base_AMI_exec) : ciao_executor, ami { + after += Hello_Base_AMI_lem_stub Hello_Base_AMI_stub + sharedname = AMI_exec + libs += AMI_stub AMI_lem_stub Hello_Base_stub Hello_Base_skel + libpaths += ../lib + libout = ../lib + dynamicflags = AMI_EXEC_BUILD_DLL + + IDL_Files { + } + + Source_Files { + AMI_exec.cpp + AMI_MyFoo_i.cpp + AMI_MyInterface_i.cpp + } + + Header_Files { + AMI_exec.h + AMI_MyFoo_i.h + AMI_MyInterface_i.h + AMI_exec_export.h + } + + Inline_Files { + } +} + + +project(Hello_Base_AMI_svnt) : ciao_servant, ami { + after += Hello_Base_skel Hello_Base_AMI_lem_stub + sharedname = AMI_svnt + libs += AMI_stub AMI_lem_stub \ + Hello_Base_skel \ + Hello_Base_stub + libpaths += ../lib + libout = ../lib + dynamicflags = AMI_SVNT_BUILD_DLL + + IDL_Files { + } + + Source_Files { + AMIS.cpp + AMI_svnt.cpp + } + + Header_Files { + AMIS.h + AMI_svnt.h + AMI_svnt_export.h + } + + Inline_Files { + AMIS.inl + } +} + + diff --git a/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_MyFoo_i.cpp b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_MyFoo_i.cpp new file mode 100644 index 00000000000..5bab675fbfd --- /dev/null +++ b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_MyFoo_i.cpp @@ -0,0 +1,239 @@ +// $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 () + { + } + + // FOO methods + void + AMI_MyFoo_reply_handler::foo ( + CORBA::Long result, + const char * out_str) + { + printf ("AMI CORBA (FOO) :\tMyFoo Foo 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 Foo 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 (); + } + + // HELLO methods + void + AMI_MyFoo_reply_handler::hello ( + CORBA::Long answer) + { + printf ("AMI CORBA (FOO) :\tMyFoo Hello Reply Handler::foo\n"); + foo_callback_->hello_callback_handler (answer); + this->_remove_ref (); + } + + void + AMI_MyFoo_reply_handler::hello_excep ( + ::Messaging::ExceptionHolder * excep_holder) + { + printf ("AMI CORBA (FOO) :\tMyFoo Hello 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_->hello_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); + } + } + + void + AMI_MyFoo_i::hello (CORBA::Long_out answer) + { + try + { + printf ("AMI CORBA (FOO) :\tHello. Try calling the Receiver component\n"); + foo_receiver_->hello (answer); + } + 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/ami4ccm/examples/AMI/AMI_MyFoo_i.h b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_MyFoo_i.h new file mode 100644 index 00000000000..377e8b02bbc --- /dev/null +++ b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_MyFoo_i.h @@ -0,0 +1,78 @@ +// $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); + + void + hello ( + CORBA::Long answer); + + void + hello_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); + + void + hello ( + CORBA::Long_out answer); + + 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/ami4ccm/examples/AMI/AMI_MyInterface_i.cpp b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_MyInterface_i.cpp new file mode 100644 index 00000000000..b4cf296368f --- /dev/null +++ b/modules/CIAO/connectors/ami4ccm/examples/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/ami4ccm/examples/AMI/AMI_MyInterface_i.h b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_MyInterface_i.h new file mode 100644 index 00000000000..3eb2b2d04f8 --- /dev/null +++ b/modules/CIAO/connectors/ami4ccm/examples/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/ami4ccm/examples/AMI/AMI_exec.cpp b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_exec.cpp new file mode 100644 index 00000000000..f84da8ceeb3 --- /dev/null +++ b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_exec.cpp @@ -0,0 +1,365 @@ +// -*- C++ -*- +// +// $Id$ + +// **** Code generated by the The ACE ORB (TAO) IDL Compiler v1.7.1 **** +// TAO and the TAO IDL Compiler have been developed by: +// Center for Distributed Object Computing +// Washington University +// St. Louis, MO +// USA +// http://www.cs.wustl.edu/~schmidt/doc-center.html +// and +// Distributed Object Computing Laboratory +// University of California at Irvine +// Irvine, CA +// USA +// http://doc.ece.uci.edu/ +// and +// Institute for Software Integrated Systems +// Vanderbilt Universityaaa +// Nashville, TN +// USA +// http://www.isis.vanderbilt.edu/ +// +// Information about TAO is available at: +// http://www.cs.wustl.edu/~schmidt/TAO.html + +// TAO_IDL - Generated from +// be/be_codegen.cpp:1278 + +#include "AMI_exec.h" +#include "ciao/CIAO_common.h" +#include "AMI_MyFoo_i.h" +#include "AMI_MyInterface_i.h" +#include "ace/OS_NS_unistd.h" + +namespace CIAO_Hello_AMI_AMI_Impl +{ + //============================================================ + // Worker thread to call "perform_work" + //============================================================ + 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; + } + + + //============================================================ + // 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)) + { + //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_foo_client")); + + CORBA::Object_var object = + orb->string_to_object ("file://foo.ior"); + ami_foo_server_ = CCM_AMI::MyFoo::_narrow (object.in ()); + + if (CORBA::is_nil (ami_foo_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_MyFoo_exec_i::~AMI_MyFoo_exec_i (void) + { + } + + // Operations from ::CCM_AMI::AMI_ami_foo + + void + AMI_MyFoo_exec_i::sendc_foo ( + const char * in_str) + { + 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 (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"); + } + + void + AMI_MyFoo_exec_i::sendc_hello () + { + printf ("AMI (FOO) :\tsendc_hello\n"); + + ::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 (FOO) :\tCalling AMI CORBA server\n"); + ami_foo_server_->sendc_hello (the_handler_var.in ()); + printf ("AMI (FOO) : \tInvoked sendc_foo\n"); + } + + //============================================================ + // Facet Executor Implementation Class: AMI_MyFoo_exec_i + //============================================================ + + AMI_MyInterface_exec_i::AMI_MyInterface_exec_i ( + ::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) + { + } + + // Operations from ::CCM_AMI::AMI_ami_foo + + void + AMI_MyInterface_exec_i::sendc_do_something_with_something ( + ::CCM_AMI::AMI_MyInterface_callback_ptr cb_handler, + CORBA::Short something) + { + printf ("AMI (INTERFACE) :\tsendc_do_something_with_something <%d>\n", something); + if (CORBA::is_nil (cb_handler)) + { //treat it as an oneway CORBA invocation + printf ("AMI (INTERFACE) :\tONE WAY INVOCATION. Sending short <%d> to AMI CORBA server\n", something); + ami_interface_server_->sendc_do_something_with_something (0, something); + printf ("AMI (INTERFACE) : \tInvoked sendc_do_something_with_something\n"); + } + else + { + ::CCM_CORBA_AMI_MyInterface_Impl::AMI_MyInterface_reply_handler* handler = + new ::CCM_CORBA_AMI_MyInterface_Impl::AMI_MyInterface_reply_handler (cb_handler); + 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"); + } + } + + //============================================================ + // Component Executor Implementation Class: AMI_exec_i + //============================================================ + + AMI_exec_i::AMI_exec_i (void) + { + } + + AMI_exec_i::~AMI_exec_i (void) + { + } + + // Supported operations and attributes. + + // Component attributes. + + // Port operations. + + ::CCM_AMI::CCM_AMI_MyFoo_ptr + AMI_exec_i::get_perform_asynch_my_foo (void) + { + ::CCM_AMI::AMI_MyFoo_callback_var foo_callback = + this->context_->get_connection_callback_my_foo (); + return new AMI_MyFoo_exec_i (foo_callback.in ()); + } + + ::CCM_AMI::CCM_AMI_MyInterface_ptr + AMI_exec_i::get_perform_asynch_my_interface () + { + ::CCM_AMI::AMI_MyInterface_callback_var interface_callback = + this->context_->get_connection_callback_my_interface (); + return new AMI_MyInterface_exec_i (interface_callback.in ()); + } + + // Operations from Components::SessionComponent. + + void + AMI_exec_i::set_session_context ( + ::Components::SessionContext_ptr ctx) + { + this->context_ = + ::Hello_AMI::CCM_AMI_Context::_narrow (ctx); + + if ( ::CORBA::is_nil (this->context_.in ())) + { + throw ::CORBA::INTERNAL (); + } + } + + void + AMI_exec_i::configuration_complete (void) + { + /* Your code here. */ + } + + void + AMI_exec_i::ccm_activate (void) + { + ::CCM_AMI::MyFoo_var receiver_foo = + this->context_->get_connection_my_foo_receiver (); + ::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 + AMI_exec_i::ccm_passivate (void) + { + /* Your code here. */ + } + + void + AMI_exec_i::ccm_remove (void) + { + /* Your code here. */ + } + + extern "C" ::Components::EnterpriseComponent_ptr + create_Hello_AMI_AMI_Impl (void) + { + ::Components::EnterpriseComponent_ptr retval = + ::Components::EnterpriseComponent::_nil (); + + ACE_NEW_RETURN ( + retval, + AMI_exec_i, + ::Components::EnterpriseComponent::_nil ()); + + return retval; + } +} + +namespace CIAO_Hello_AMI_AMI_Impl +{ + //============================================================ + // Home Executor Implementation Class: AMIHome_exec_i + //============================================================ + + AMIHome_exec_i::AMIHome_exec_i (void) + { + } + + AMIHome_exec_i::~AMIHome_exec_i (void) + { + } + + // All operations and attributes. + + // Factory operations. + + // Finder operations. + + // Implicit operations. + + ::Components::EnterpriseComponent_ptr + AMIHome_exec_i::create (void) + { + ::Components::EnterpriseComponent_ptr retval = + ::Components::EnterpriseComponent::_nil (); + + ACE_NEW_THROW_EX ( + retval, + AMI_exec_i, + ::CORBA::NO_MEMORY ()); + + return retval; + } + + extern "C" ::Components::HomeExecutorBase_ptr + create_Hello_AMI_AMIHome_Impl (void) + { + ::Components::HomeExecutorBase_ptr retval = + ::Components::HomeExecutorBase::_nil (); + + ACE_NEW_RETURN ( + retval, + AMIHome_exec_i, + ::Components::HomeExecutorBase::_nil ()); + + return retval; + } +} + diff --git a/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_exec.h b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_exec.h new file mode 100644 index 00000000000..716a2d033ad --- /dev/null +++ b/modules/CIAO/connectors/ami4ccm/examples/AMI/AMI_exec.h @@ -0,0 +1,165 @@ +// -*- C++ -*- +// +// $Id$ + +// **** Code generated by the The ACE ORB (TAO) IDL Compiler v1.7.1 **** +// TAO and the TAO IDL Compiler have been developed by: +// Center for Distributed Object Computing +// Washington University +// St. Louis, MO +// USA +// http://www.cs.wustl.edu/~schmidt/doc-center.html +// and +// Distributed Object Computing Laboratory +// University of California at Irvine +// Irvine, CA +// USA +// http://doc.ece.uci.edu/ +// and +// Institute for Software Integrated Systems +// Vanderbilt University +// Nashville, TN +// USA +// http://www.isis.vanderbilt.edu/ +// +// Information about TAO is available at: +// http://www.cs.wustl.edu/~schmidt/TAO.html + +// TAO_IDL - Generated from +// be/be_codegen.cpp:1217 + +#ifndef CIAO_AMI_EXEC_H_ +#define CIAO_AMI_EXEC_H_ + + +#include "AMIEC.h" +#include "AMI_exec_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/LocalObject.h" +#include "ace/Task.h" + +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 + { + public: + AMI_MyFoo_exec_i (::CCM_AMI::AMI_MyFoo_callback_ptr foo_callback); + + virtual ~AMI_MyFoo_exec_i (void); + virtual void + sendc_foo ( + const char * in_str); + + virtual void + sendc_hello (); + + private: + CCM_AMI::MyFoo_var ami_foo_server_; + ::CCM_AMI::AMI_MyFoo_callback_var foo_callback_; + }; + + class AMI_MyInterface_exec_i + : public virtual ::CCM_AMI::CCM_AMI_MyInterface, + public virtual ::CORBA::LocalObject + { + public: + AMI_MyInterface_exec_i (::CCM_AMI::AMI_MyInterface_callback_ptr foo_callback); + + virtual ~AMI_MyInterface_exec_i (void); + + virtual void + sendc_do_something_with_something ( + ::CCM_AMI::AMI_MyInterface_callback_ptr cb_handler, + CORBA::Short something); + + private: + CCM_AMI::MyInterface_var ami_interface_server_; + ::CCM_AMI::AMI_MyInterface_callback_var interface_callback_; + }; + + class AMI_exec_i + : public virtual AMI_Exec, + public virtual ::CORBA::LocalObject + { + public: + AMI_exec_i (void); + virtual ~AMI_exec_i (void); + + // Supported operations and attributes. + + // Component attributes. + + // Port operations. + + virtual ::CCM_AMI::CCM_AMI_MyFoo_ptr + get_perform_asynch_my_foo (void); + + virtual ::CCM_AMI::CCM_AMI_MyInterface_ptr + get_perform_asynch_my_interface (void); + + // Operations from Components::SessionComponent. + + virtual void + set_session_context ( + ::Components::SessionContext_ptr ctx); + + virtual void configuration_complete (void); + + virtual void ccm_activate (void); + virtual void ccm_passivate (void); + virtual void ccm_remove (void); + + private: + ::Hello_AMI::CCM_AMI_Context_var context_; + ::CCM_AMI::AMI_MyFoo_callback_var callback_foo_; + }; + + extern "C" AMI_EXEC_Export ::Components::EnterpriseComponent_ptr + create_Hello_AMI_AMI_Impl (void); +} + +namespace CIAO_Hello_AMI_AMI_Impl +{ + class AMIHome_exec_i + : public virtual AMIHome_Exec, + public virtual ::CORBA::LocalObject + { + public: + AMIHome_exec_i (void); + + virtual ~AMIHome_exec_i (void); + + // All operations and attributes. + + // Factory operations. + + // Finder operations. + + // Implicit operations. + + virtual ::Components::EnterpriseComponent_ptr + create (void); + }; + + extern "C" AMI_EXEC_Export ::Components::HomeExecutorBase_ptr + create_Hello_AMI_AMIHome_Impl (void); +} + +#endif /* ifndef */ + |