diff options
Diffstat (limited to 'quellcode/versuch3/multithreading/SupplierLow.cpp')
| -rwxr-xr-x | quellcode/versuch3/multithreading/SupplierLow.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/quellcode/versuch3/multithreading/SupplierLow.cpp b/quellcode/versuch3/multithreading/SupplierLow.cpp new file mode 100755 index 0000000..47ae343 --- /dev/null +++ b/quellcode/versuch3/multithreading/SupplierLow.cpp @@ -0,0 +1,126 @@ +#include <iostream> +#include "benchC.h" +#include "orbsvcs/CosNamingC.h" +#include <tao/RTCORBA/RTCORBA.h> +#include <unistd.h> + +#include "cpx.h" + +//benchmark::Put_var put; +benchmark::PutLow_var lowPut; +CPX cpx; + +void sigproc(int signo) +{ signal(SIGRTMIN+29, sigproc); +// int i1 = cpx.get(1); +// int i2 /*= cpx.get(2)*/; +// int i3 /*= cpx.get(3)*/; +// put->allPorts(i1, i2, i3); + lowPut->onePort(3, cpx.get(1)); +// put->allPorts(cpx.get(1), -1, -1); +// put->onePort(3, cpx.get(3)); +} + + +int main(int argc, char* argv[]){ + + 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{ + // 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 rtORB = RTCORBA::RTORB::_narrow(rtorb.in()); + std::cout<<"RTORB ok"<<std::endl; + + // Network Settings + CORBA::Long sendBufferSize = 0; + CORBA::Long recvBufferSize = 0; + CORBA::Boolean keepAlive = 1; + CORBA::Boolean dontRoute = 1; + CORBA::Boolean noDelay = 1; + + RTCORBA::TCPProtocolProperties_var tcpProperties = rtORB->create_tcp_protocol_properties( + sendBufferSize, recvBufferSize, keepAlive, dontRoute, noDelay, RTCORBA::maxPriority /*network priority*/); + + tcpProperties->enable_network_priority(1); + + RTCORBA::ProtocolList protocols; + protocols.length(1); + protocols[0].protocol_type = 0; //TAO_TAG_IIOP_PROFILE; + protocols[0].transport_protocol_properties = RTCORBA::ProtocolProperties::_duplicate(tcpProperties.in()); + + // NamingService + CORBA::Object_var namingObject = orb->resolve_initial_references("NameService"); + CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingObject.in()); + std::cout<<"NamingService ok"<<std::endl; + + // receive Objects + CosNaming::Name name(1); + name.length(1); + +// name[0].id = CORBA::string_dup("Receiver"); +// CORBA::Object_var benchObj = namingContext->resolve(name); +// put = benchmark::Put::_narrow(benchObj.in()); + + name[0].id = CORBA::string_dup("LowReceiver"); + CORBA::Object_var lowBenchObj = namingContext->resolve(name); + lowPut = benchmark::PutLow::_narrow(lowBenchObj.in()); + + std::cout<<"TransferOjekt ok"<<std::endl; + + // Private Connection Policy + CORBA::PolicyList pcPolicy(2); + pcPolicy.length(2); + pcPolicy[0] = rtORB->create_private_connection_policy(); + pcPolicy[1] = rtORB->create_client_protocol_policy(protocols); + + CORBA::Object_var newTran = lowPut->_set_policy_overrides(pcPolicy, CORBA::SET_OVERRIDE); + lowPut = benchmark::PutLow::_narrow(newTran.in()); + lowPut = benchmark::PutLow::_narrow(newTran.in()); + std::cout<<"PrivateConnection, RTProtocol ok"<<std::endl; + + // rtCurrent set priority + //CORBA::Object_var rtCurrentObj = orb->resolve_initial_references("RTCurrent"); + //RTCORBA::Current_var rtCurrent = RTCORBA::Current::_narrow(rtCurrentObj.in()); + //rtCurrent->the_priority(RTCORBA::maxPriority); + //std::cout<<"PriorityChange ok"<<std::endl; + + // explicitly bind connection to server + //CORBA::PolicyList_var inconsistentPolicies; + //CORBA::Boolean status = transfer->_validate_connection(inconsistentPolicies.out()); + //std::cout<<"explicit bind ok"<<std::endl; + + // Input auf Interface schreiben + // ... + lowPut->connect(); + //lowPut->connect(); + lowPut->allPorts(0, 0, 0); + sleep(1); + lowPut->onePort(1, 255); + sleep(1); + lowPut->allPorts(0, 0, 0); + + // 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; +} |
