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/multithreading/ReceiverDual.cpp | 123 ++++++++++++++++++ quellcode/versuch3/multithreading/SupplierHigh.cpp | 126 +++++++++++++++++++ quellcode/versuch3/multithreading/SupplierLow.cpp | 126 +++++++++++++++++++ quellcode/versuch3/multithreading/benchDual.mpc | 35 ++++++ quellcode/versuch3/multithreading/benchI.cpp | 137 +++++++++++++++++++++ quellcode/versuch3/multithreading/benchI.h | 130 +++++++++++++++++++ quellcode/versuch3/multithreading/cpx.cpp | 85 +++++++++++++ quellcode/versuch3/multithreading/cpx.h | 73 +++++++++++ quellcode/versuch3/multithreading/svc.conf | 2 + 9 files changed, 837 insertions(+) create mode 100755 quellcode/versuch3/multithreading/ReceiverDual.cpp create mode 100755 quellcode/versuch3/multithreading/SupplierHigh.cpp create mode 100755 quellcode/versuch3/multithreading/SupplierLow.cpp create mode 100755 quellcode/versuch3/multithreading/benchDual.mpc create mode 100755 quellcode/versuch3/multithreading/benchI.cpp create mode 100755 quellcode/versuch3/multithreading/benchI.h create mode 100755 quellcode/versuch3/multithreading/cpx.cpp create mode 100755 quellcode/versuch3/multithreading/cpx.h create mode 100755 quellcode/versuch3/multithreading/svc.conf (limited to 'quellcode/versuch3/multithreading') diff --git a/quellcode/versuch3/multithreading/ReceiverDual.cpp b/quellcode/versuch3/multithreading/ReceiverDual.cpp new file mode 100755 index 0000000..91f02f2 --- /dev/null +++ b/quellcode/versuch3/multithreading/ReceiverDual.cpp @@ -0,0 +1,123 @@ +#include +#include + + +//#include + +#include "benchI.h" + +#include "orbsvcs/CosNamingC.h" +#include + +COBA::ULong static_threads = 2; +long nap_time = 1000; + +int registerServant(CORBA::Policy_ptr threadpoolPolicy, const char* poaName, PortableServer::POAManager_ptr poaManager, PortableServer::POA_ptr rootPOA, CORBA::ORB_ptr orb, RTCORBA::RTORB rtORB) { + return 0; +} + +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, "ServerORB"); + std::cout<<"ORB initialized"<resolve_initial_references("RTORB"); + RTCORBA::RTORB_var rtORB = RTCORBA::RTORB::_narrow(rtorb); + std::cout<<"RT Extensions OK"<create_tcp_protocol_properties( + sendBufferSize, recvBufferSize, keepAlive, dontRoute, noDelay, 1 /*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()); + + // obtain rootPOA + CORBA::Object_var poa = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poa.in()); + + // activate POA Manager + PortableServer::POAManager_var poaManager = rootPOA->the_POAManager(); + poaManager->activate(); + std::cout<<"rootPOA OK"<create_priority_model_policy(RTCORBA::CLIENT_PROPAGATED, RTCORBA::maxPriority); + benchPolicy[1] = rtORB->create_server_protocol_policy(protocols); + + //// create low Priority Policy + CORBA::PolicyList benchLowPolicy(2); + benchLowPolicy.length(2); + benchLowPolicy[0] = rtORB->create_priority_model_policy(RTCORBA::CLIENT_PROPAGATED, RTCORBA::minPriority); + benchLowPolicy[1] = rtORB->create_server_protocol_policy(protocols); + + // create ObjectAdapter, assign Policy + PortableServer::POA_var benchPOA = rootPOA->create_POA("benchPOA", poaManager.in(), benchPolicy); + std::cout<<"Policy assigned"<create_POA("benchLowPOA", poaManager.in(), benchLowPolicy); + + // create the servant + benchmark_PutHigh_i bench_i; + benchmark_PutLow_i lowBench_i; + + // activate servant + PortableServer::ObjectId_var objectID = benchPOA->activate_object(&bench_i); + CORBA::Object_var benchObj = benchPOA->id_to_reference(objectID.in()); + CORBA::String_var ior = orb->object_to_string(benchObj.in()); + + PortableServer::ObjectId_var objectLowID = benchLowPOA->activate_object(&lowBench_i); + CORBA::Object_var lowBenchObj = benchLowPOA->id_to_reference(objectLowID.in()); + CORBA::String_var ior2 = orb->object_to_string(lowBenchObj.in()); + std::cout<<"Servant activated"<resolve_initial_references("NameService"); + CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingObject.in()); + CosNaming::Name name(1); + name.length(1); + name[0].id = CORBA::string_dup("HighReceiver"); + namingContext->bind(name, benchObj.in()); + std::cout<<"Bound Receiver to NameService"<bind(name, lowBenchObj.in()); + std::cout<<"Bound LowReceiver to NameService"<run(); + std::cout<<"ORB ready"<destroy(1,1); + orb->destroy(); + //enable_irq(18); + }catch(CORBA::Exception &any){ + std::cout<<"Exception: "< +#include "benchC.h" +#include "orbsvcs/CosNamingC.h" +#include +#include + +#include "cpx.h" + +//benchmark::Put_var put; +benchmark::PutHigh_var highPut; +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); + highPut->onePort(1, 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, "Client2ORB"); + std::cout<<"ORB ok"<resolve_initial_references("RTORB"); + RTCORBA::RTORB_var rtORB = RTCORBA::RTORB::_narrow(rtorb.in()); + std::cout<<"RTORB ok"<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"<resolve(name); +// put = benchmark::Put::_narrow(benchObj.in()); + + name[0].id = CORBA::string_dup("HighReceiver"); + CORBA::Object_var lowBenchObj = namingContext->resolve(name); + highPut = benchmark::PutHigh::_narrow(lowBenchObj.in()); + + std::cout<<"TransferOjekt ok"<create_private_connection_policy(); + pcPolicy[1] = rtORB->create_client_protocol_policy(protocols); + + CORBA::Object_var newTran = highPut->_set_policy_overrides(pcPolicy, CORBA::SET_OVERRIDE); + highPut = benchmark::PutHigh::_narrow(newTran.in()); + highPut = benchmark::PutHigh::_narrow(newTran.in()); + std::cout<<"PrivateConnection, RTProtocol ok"<resolve_initial_references("RTCurrent"); + //RTCORBA::Current_var rtCurrent = RTCORBA::Current::_narrow(rtCurrentObj.in()); + //rtCurrent->the_priority(RTCORBA::maxPriority); + //std::cout<<"PriorityChange ok"<_validate_connection(inconsistentPolicies.out()); + //std::cout<<"explicit bind ok"<connect(); + //lowPut->connect(); + highPut->allPorts(0, 0, 0); + sleep(1); + highPut->onePort(1, 255); + sleep(1); + highPut->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: "< +#include "benchC.h" +#include "orbsvcs/CosNamingC.h" +#include +#include + +#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"<resolve_initial_references("RTORB"); + RTCORBA::RTORB_var rtORB = RTCORBA::RTORB::_narrow(rtorb.in()); + std::cout<<"RTORB ok"<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"<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"<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"<resolve_initial_references("RTCurrent"); + //RTCORBA::Current_var rtCurrent = RTCORBA::Current::_narrow(rtCurrentObj.in()); + //rtCurrent->the_priority(RTCORBA::maxPriority); + //std::cout<<"PriorityChange ok"<_validate_connection(inconsistentPolicies.out()); + //std::cout<<"explicit bind ok"<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: "<set(portNo, value); +} + +void benchmark_PutLow_i::allPorts ( + ::CORBA::Short valPort1, + ::CORBA::Short valPort2, + ::CORBA::Short valPort3 + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )) +{ + // Add your implementation here + if(valPort1>=0) cpx->set(1, valPort1); + if(valPort2>=0) cpx->set(2, valPort2); + if(valPort3>=0) cpx->set(3, valPort3); +} + +// Implementation skeleton constructor +benchmark_PutHigh_i::benchmark_PutHigh_i (void) +{ +} + +// Implementation skeleton destructor +benchmark_PutHigh_i::~benchmark_PutHigh_i (void) +{ +} + +void benchmark_PutHigh_i::connect ( + + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )) +{ + // Add your implementation here + cpx = new CPX(); +} + +void benchmark_PutHigh_i::onePort ( + ::CORBA::Short portNo, + ::CORBA::Short value + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )) +{ + // Add your implementation here + cpx->set(portNo, value); +} + +void benchmark_PutHigh_i::allPorts ( + ::CORBA::Short valPort1, + ::CORBA::Short valPort2, + ::CORBA::Short valPort3 + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )) +{ + // Add your implementation here + if(valPort1>=0) cpx->set(1, valPort1); + if(valPort2>=0) cpx->set(2, valPort2); + if(valPort3>=0) cpx->set(3, valPort3); +} + + diff --git a/quellcode/versuch3/multithreading/benchI.h b/quellcode/versuch3/multithreading/benchI.h new file mode 100755 index 0000000..fb33928 --- /dev/null +++ b/quellcode/versuch3/multithreading/benchI.h @@ -0,0 +1,130 @@ +// -*- C++ -*- +// +// $Id$ + +// **** Code generated by the The ACE ORB (TAO) IDL Compiler **** +// 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:1001 + +#ifndef BENCHI_H_ +#define BENCHI_H_ + +#include "benchS.h" +#include "cpx.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +class benchmark_PutLow_i + : public virtual POA_benchmark::PutLow +{ +private: + CPX* cpx; +public: + // Constructor + benchmark_PutLow_i (void); + + // Destructor + virtual ~benchmark_PutLow_i (void); + + virtual + void connect ( + + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )); + + virtual + void onePort ( + ::CORBA::Short portNo, + ::CORBA::Short value + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )); + + virtual + void allPorts ( + ::CORBA::Short valPort1, + ::CORBA::Short valPort2, + ::CORBA::Short valPort3 + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )); +}; + +class benchmark_PutHigh_i + : public virtual POA_benchmark::PutHigh +{ + +private: + CPX* cpx; +public: + // Constructor + benchmark_PutHigh_i (void); + + // Destructor + virtual ~benchmark_PutHigh_i (void); + + virtual + void connect ( + + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )); + + virtual + void onePort ( + ::CORBA::Short portNo, + ::CORBA::Short value + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )); + + virtual + void allPorts ( + ::CORBA::Short valPort1, + ::CORBA::Short valPort2, + ::CORBA::Short valPort3 + ) + ACE_THROW_SPEC (( + ::CORBA::SystemException, + ::benchmark::invalidRequest + )); +}; + + +#endif /* BENCHI_H_ */ + diff --git a/quellcode/versuch3/multithreading/cpx.cpp b/quellcode/versuch3/multithreading/cpx.cpp new file mode 100755 index 0000000..eebdc65 --- /dev/null +++ b/quellcode/versuch3/multithreading/cpx.cpp @@ -0,0 +1,85 @@ +/** + * + * \file cpx.cpp + * \brief read and write DIO + * + * \author Manuel Traut + * \version 2006-10-06 + * + */ + +#include "cpx.h" + +CPX::CPX(){ + init(); + std::cout<<"\n\n init ok\n\n"; +} + +int CPX::init(){ + + int fd_out = open(CPX_Input, O_RDWR | O_SYNC); + if (fd_out == -1){ + std::cout<<"PBCIO: open failed"< + +#include +#include +#include +#include + +#define CPX_Input "/dev/iio2" +#define CPX_Input_1 "/dev/iio2_in" +#define CPX_Output_1 "/dev/iio2_out" + +#define PORT1_OUT 0x2c00 +#define PORT2_OUT 0x3c00 +#define PORT3_OUT 0x4c00 + +#define PORT1_IN 0x5c00 +#define PORT2_IN 0x6c00 +#define PORT3_IN 0x7c00 + +# ifndef PROT_READ +# define PROT_READ 0x01 +# endif +# ifndef PROT_WRITE +# define PROT_WRITE 0x02 +# endif +# ifndef MAP_SHARED +# define MAP_SHARED 0x01 +# endif +# ifndef MAP_PRIVATE +# define MAP_PRIVATE 0x02 +# endif + +// ioctl (file descriptor, CPX_DIO_IOCTL_SET_SIGNAL, irq_send_signal_param*) +// enable sending signal on interrupt +// cpx_dio_set_signal_param.signal = signal to be sent to process +#define CPX_DIO_IOCTL_BASE 0xCD + +typedef struct{ + int signal; /* IN parameter: LINUX signal to be sent */ + int pid; /* IN parameter: process id where signal should be sent to */ +}cpx_dio_set_signal_param; + +#define CPX_DIO_IOCTL_ADD_SIG _IOW(CPX_DIO_IOCTL_BASE, 3, cpx_dio_set_signal_param) +#define CPX_DIO_IOCTL_DEL_SIG _IOW(CPX_DIO_IOCTL_BASE, 4, cpx_dio_set_signal_param) + +class CPX{ + public: + CPX(); + void set(short port, short value); + short get(short port); + private: + int init(); + unsigned char *mapped_in; + unsigned char *mapped_out; + volatile u_char *DOUT; + volatile u_char *DIN; + cpx_dio_set_signal_param param; +}; + +#endif diff --git a/quellcode/versuch3/multithreading/svc.conf b/quellcode/versuch3/multithreading/svc.conf new file mode 100755 index 0000000..ab151ce --- /dev/null +++ b/quellcode/versuch3/multithreading/svc.conf @@ -0,0 +1,2 @@ +static Resource_Factory "-ORBResources global -ORBReactorType select_mt" +static Server_Strategy_Factory "-ORBConcurrency thread-per-connection" -- cgit v1.2.3