From 1adba473e6917b227e1b0a1118148101dca202e7 Mon Sep 17 00:00:00 2001 From: Manuel Traut Date: Mon, 31 Mar 2014 16:53:55 +0200 Subject: add quellcode Signed-off-by: Manuel Traut --- quellcode/versuch3/Supplier.cpp | 89 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 quellcode/versuch3/Supplier.cpp (limited to 'quellcode/versuch3/Supplier.cpp') diff --git a/quellcode/versuch3/Supplier.cpp b/quellcode/versuch3/Supplier.cpp new file mode 100755 index 0000000..0476e69 --- /dev/null +++ b/quellcode/versuch3/Supplier.cpp @@ -0,0 +1,89 @@ +#include +#include "benchC.h" +#include "orbsvcs/CosNamingC.h" +#include +#include + +#include "cpx.h" + +static benchmark::PutHigh_var highPut; +static benchmark::PutLow_var lowPut; +static bool high; +static CPX cpx; + +static CORBA::ORB_ptr orb; +static RTCORBA::RTORB_var rtORB; +extern CosNaming::NamingContext_ptr nameContext; + +template typename T::_ptr_type bindService (const char *n, int argc, char *argv[]) { + CORBA::Object_var obj; + if (CORBA::is_nil (nameContext)) { //first call + // get ORB + orb = CORBA::ORB_init (argc, argv, 0); + // get RTORB + obj = orb->resolve_initial_references("RTORB"); + rtORB = RTCORBA::RTORB::_narrow(obj.in()); + // get NamingService + obj = orb->resolve_initial_references ("NameService"); + nameContext = CosNaming::NamingContext::_narrow (obj); + if (CORBA::is_nil (name_context)) return 0; + } + CosNaming::Name svcName; + svcName.length (1); + svcName[0].id = n; + // retrieve reference + obj = nameContext->resolve(svcName); + // cast to T + return T::_narrow (obj); +} + + +void sigproc(int signo) { + signal(SIGRTMIN+29, sigproc); + if (high) highPut->onePort(1, cpx.get(1)); + else lowPut->onePort(3, cpx.get(1)); +} + +void argError(){ + std::cout<<"./Supplier high|low \n"; +} + +int main(int argc, char* argv[]){ + + if (argc < 1) { + argError(); + return 0; + } + if (argv[1] == "high") high = true; + else if (argv[1] == "low") high = false; + else { + argError(); + return 0; + } + + struct sched_param schedparam; + schedparam.sched_priority = 99; + + if (sched_setscheduler(0, SCHED_FIFO, &schedparam) != 0) { + fprintf(stderr, "%s: PID %d: sched_setscheduler() failed errno = %d\n", __FUNCTION__, getpid(), errno); + } + + try{ + + // receive Objects + if (high) highPut = bindService("HighReceiver", argc, argv); + else lowPut = bindService("LowReceiver", argc, argv); + + // signal handling + signal(SIGRTMIN+29, sigproc); + + while(true) pause(); + + // destroy ORB + orb->destroy(); + + }catch(CORBA::Exception &any){ + std::cout<<"Exception occured: "<