diff options
Diffstat (limited to 'quellcode/versuch3/Supplier.cpp')
| -rwxr-xr-x | quellcode/versuch3/Supplier.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
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 <iostream> +#include "benchC.h" +#include "orbsvcs/CosNamingC.h" +#include <tao/RTCORBA/RTCORBA.h> +#include <unistd.h> + +#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 <class T> 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 <corba-args>\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<PutHigh>("HighReceiver", argc, argv); + else lowPut = bindService<PutLow>("LowReceiver", argc, argv); + + // signal handling + signal(SIGRTMIN+29, sigproc); + + while(true) pause(); + + // destroy ORB + orb->destroy(); + + }catch(CORBA::Exception &any){ + std::cout<<"Exception occured: "<<any<<std::endl; + } + return 0; +} |
