summaryrefslogtreecommitdiff
path: root/quellcode/versuch4/multithreading/ReceiverDual.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'quellcode/versuch4/multithreading/ReceiverDual.cpp')
-rwxr-xr-xquellcode/versuch4/multithreading/ReceiverDual.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/quellcode/versuch4/multithreading/ReceiverDual.cpp b/quellcode/versuch4/multithreading/ReceiverDual.cpp
new file mode 100755
index 0000000..91f02f2
--- /dev/null
+++ b/quellcode/versuch4/multithreading/ReceiverDual.cpp
@@ -0,0 +1,123 @@
+#include <iostream>
+#include <stdio.h>
+
+
+//#include <asm/irq.h>
+
+#include "benchI.h"
+
+#include "orbsvcs/CosNamingC.h"
+#include <tao/RTCORBA/RTCORBA.h>
+
+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"<<std::endl;
+
+ // access RT Extensions
+ CORBA::Object_var rtorb = orb->resolve_initial_references("RTORB");
+ RTCORBA::RTORB_var rtORB = RTCORBA::RTORB::_narrow(rtorb);
+ std::cout<<"RT Extensions 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, 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"<<std::endl;
+
+ // create high Priority Policy
+ CORBA::PolicyList benchPolicy(2);
+ benchPolicy.length(2);
+ benchPolicy[0] = rtORB->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"<<std::endl;
+
+ // create 2nd ObjectAdapter, assign low priority Policy
+ PortableServer::POA_var benchLowPOA = rootPOA->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"<<std::endl;
+
+ // NameService
+ CORBA::Object_var namingObject = orb->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"<<std::endl;
+ name[0].id = CORBA::string_dup("LowReceiver");
+ namingContext->bind(name, lowBenchObj.in());
+ std::cout<<"Bound LowReceiver to NameService"<<std::endl;
+
+ // start ORB
+ orb->run();
+ std::cout<<"ORB ready"<<std::endl;
+
+ //destroy
+ rootPOA->destroy(1,1);
+ orb->destroy();
+ //enable_irq(18);
+ }catch(CORBA::Exception &any){
+ std::cout<<"Exception: "<<any<<std::endl;
+ //enable_irq(18);
+ }
+ return 0;
+}
+