diff options
| author | Manuel Traut <manut@linutronix.de> | 2009-06-23 23:43:56 +0100 |
|---|---|---|
| committer | Manuel Traut <manut@linutronix.de> | 2009-06-23 23:43:56 +0100 |
| commit | 950b78b4cd58c90f1c19769994ee37c7286b9804 (patch) | |
| tree | e026c43a2523195bec68cea619f2abefcbaeac60 /frameworks/middleware/examples | |
| parent | 46f636afe5ad22567351391155da76f8a2e00bc6 (diff) | |
middleware: added corba example
Signed-off-by: Manuel Traut <manut@linutronix.de>
Diffstat (limited to 'frameworks/middleware/examples')
| -rwxr-xr-x | frameworks/middleware/examples/corba/Receiver.cpp | 85 | ||||
| -rwxr-xr-x | frameworks/middleware/examples/corba/Supplier.cpp | 86 | ||||
| -rwxr-xr-x | frameworks/middleware/examples/corba/ping.idl | 15 | ||||
| -rwxr-xr-x | frameworks/middleware/examples/corba/ping.mpc | 15 | ||||
| -rw-r--r-- | frameworks/middleware/examples/corba/ping_I.cpp | 24 |
5 files changed, 225 insertions, 0 deletions
diff --git a/frameworks/middleware/examples/corba/Receiver.cpp b/frameworks/middleware/examples/corba/Receiver.cpp new file mode 100755 index 0000000..45ac9dc --- /dev/null +++ b/frameworks/middleware/examples/corba/Receiver.cpp @@ -0,0 +1,85 @@ +/** + * \file Receiver.cpp + * \brief RTCORBA Server, holding one Object for receiving ping calls + * + * \author Manuel Traut + * \version 2009-06-23 + */ + +#include <iostream> + +#include "pingI.h" + +#include "orbsvcs/CosNamingC.h" +#include <tao/RTCORBA/RTCORBA.h> + +int main(int argc, char* argv[]){ + try{ + // initialize ORB + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "ServerORB"); + std::cout<<"ORB initialized"<<std::endl; + + // access RT Extensions + CORBA::Object_var rtorb = orb->resolve_initial_references("RTORB"); + RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow(rtorb); + std::cout<<"RT Extensions OK"<<std::endl; + + // obtain root_poa + CORBA::Object_var poa = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa.in()); + + // activate POA Manager + PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); + poa_manager->activate(); + std::cout<<"root_poa OK"<<std::endl; + + // create Policy + CORBA::PolicyList ping_policy(1); + ping_policy.length(1); + ping_policy[0] = rt_orb->create_priority_model_policy( + RTCORBA::CLIENT_PROPAGATED, RTCORBA::maxPriority); + + // create ObjectAdapter, assign Policy + PortableServer::POA_var ping_poa = + root_poa->create_POA("ping_poa", poa_manager.in(), ping_policy); + + std::cout<<"Policy assigned"<<std::endl; + + // create the servant + Linutronix_Ping_i ping_i; + + // activate servant + PortableServer::ObjectId_var object_id = ping_poa->activate_object(&ping_i); + CORBA::Object_var ping_obj = ping_poa->id_to_reference(object_id.in()); + CORBA::String_var ior = orb->object_to_string(ping_obj.in()); + std::cout<<"Servant activated"<<std::endl; + + // NameService + CORBA::Object_var naming_obj = + orb->resolve_initial_references("NameService"); + + std::cout<<"bind\n"; + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + CosNaming::Name name(1); + name.length(1); + name[0].id = CORBA::string_dup("Receiver"); + + naming_context->rebind(name, ping_obj.in()); + std::cout<<"Bound Receiver to NameService"<<std::endl; + + // start ORB + orb->run(); + std::cout<<"ORB ready"<<std::endl; + + //destroy + root_poa->destroy(1,1); + orb->destroy(); + + } catch(CORBA::Exception &any) { + std::cout<<"Exception: "<<any<<std::endl; + } + return 0; +} diff --git a/frameworks/middleware/examples/corba/Supplier.cpp b/frameworks/middleware/examples/corba/Supplier.cpp new file mode 100755 index 0000000..8d6f413 --- /dev/null +++ b/frameworks/middleware/examples/corba/Supplier.cpp @@ -0,0 +1,86 @@ +/** + * \file Supplier.cpp + * \brief RTCORBA Client, sends ping commands to Receiver + * + * \author Manuel Traut + * \version 2009-06-23 + * + */ + +#include <iostream> +#include <string> +#include <unistd.h> +#include <orbsvcs/CosNamingC.h> +#include <tao/RTCORBA/RTCORBA.h> + +#include "pingC.h" + +static Linutronix::Ping_var ping; +static std::string str; + +int main(int argc, char* argv[]) +{ + if (argc > 1) + str = argv[1]; + else + str = "no argument given"; + + try{ + // initialize ORB + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "ClientORB"); + std::cout<<"ORB ok"<<std::endl; + + // get RTORB + CORBA::Object_var rtorb = orb->resolve_initial_references("RTORB"); + RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow(rtorb.in()); + std::cout<<"RTORB ok"<<std::endl; + + // NamingService + CORBA::Object_var naming_obj = + orb->resolve_initial_references("NameService"); + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + std::cout<<"NamingService ok"<<std::endl; + + CosNaming::Name name(1); + name.length(1); + name[0].id = CORBA::string_dup("Receiver"); + + // receive Object + CORBA::Object_var ping_obj = naming_context->resolve(name); + ping = Linutronix::Ping::_narrow(ping_obj.in()); + std::cout<<"TransferOjekt ok"<<std::endl; + + // Private Connection Policy + CORBA::PolicyList pc_policy(1); + pc_policy.length(1); + pc_policy[0] = rt_orb->create_private_connection_policy(); + + CORBA::Object_var new_tran = + ping->_set_policy_overrides(pc_policy, CORBA::SET_OVERRIDE); + + ping = Linutronix::Ping::_narrow(new_tran.in()); + std::cout<<"PrivateConnection ok"<<std::endl; + + struct timespec time_tx; + struct timespec time_done; + + for(unsigned int i = 0; i < 100; i++) + { + clock_gettime(CLOCK_MONOTONIC, &time_tx); + ping->send((const char*)str.c_str()); + clock_gettime(CLOCK_MONOTONIC, &time_done); + std::cout<<time_tx.tv_sec<<":"<<time_tx.tv_nsec/1000<<"\n"; + std::cout<<time_done.tv_sec<<":"<<time_done.tv_nsec/1000<<"\n\n"; + } + + // destroy ORB + orb->destroy(); + + } catch(CORBA::Exception &any) { + std::cout<<"Exception occured: "<<any<<std::endl; + } + return 0; +} diff --git a/frameworks/middleware/examples/corba/ping.idl b/frameworks/middleware/examples/corba/ping.idl new file mode 100755 index 0000000..f41fb07 --- /dev/null +++ b/frameworks/middleware/examples/corba/ping.idl @@ -0,0 +1,15 @@ +/** + * + * \file ping.idl + * \brief Interfacedefinition for ping performance test + * + * \author Manuel Traut + * \version 2009-06-23 + * + */ + +module Linutronix{ + interface Ping{ + oneway void send(in string payload); + }; +}; diff --git a/frameworks/middleware/examples/corba/ping.mpc b/frameworks/middleware/examples/corba/ping.mpc new file mode 100755 index 0000000..f90790e --- /dev/null +++ b/frameworks/middleware/examples/corba/ping.mpc @@ -0,0 +1,15 @@ +project(*Receiver): rt_server, naming { + requires += exceptions + Source_Files { + ping_I.cpp + Receiver.cpp + } +} + +project(*Supplier): rt_client, naming { + requires += exceptions + Source_Files { + pingC.cpp + Supplier.cpp + } +} diff --git a/frameworks/middleware/examples/corba/ping_I.cpp b/frameworks/middleware/examples/corba/ping_I.cpp new file mode 100644 index 0000000..309d1e8 --- /dev/null +++ b/frameworks/middleware/examples/corba/ping_I.cpp @@ -0,0 +1,24 @@ +#include <time.h> +#include <iostream> + +#include "pingI.h" + +// Implementation skeleton constructor +Linutronix_Ping_i::Linutronix_Ping_i (void) +{ +} + +// Implementation skeleton destructor +Linutronix_Ping_i::~Linutronix_Ping_i (void) +{ +} + +void Linutronix_Ping_i::send ( + const char * payload) +{ + // Add your implementation here + struct timespec time_rx; + clock_gettime(CLOCK_MONOTONIC, &time_rx); + std::cout<<time_rx.tv_sec<<":"<<time_rx.tv_nsec/1000<<": "<<payload<<"\n"; +} + |
