diff options
Diffstat (limited to 'quellcode/versuch5/Server.cpp')
| -rwxr-xr-x | quellcode/versuch5/Server.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/quellcode/versuch5/Server.cpp b/quellcode/versuch5/Server.cpp new file mode 100755 index 0000000..94afb5c --- /dev/null +++ b/quellcode/versuch5/Server.cpp @@ -0,0 +1,143 @@ +#include <iostream> + +#include "bench_i.h" + +#include "orbsvcs/CosNamingC.h" +#include <tao/RTCORBA/RTCORBA.h> +#include "tao/RTCORBA/Network_Priority_Mapping_Manager.h" +#include "tao/RTCORBA/Network_Priority_Mapping.h" +#include "Custom_Network_Priority_Mapping.h" + +RTCORBA::Priority corbaPriority = RTCORBA::minPriority; + +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; + + // Network priority mapping + CORBA::Object_var netmapper = orb->resolve_initial_references("NetworkPriorityMappingManager"); + RTCORBA::NetworkPriorityMappingManager_var mappingManager = RTCORBA::NetworkPriorityMappingManager::_narrow( netmapper.in() ); + + Custom_Network_Priority_Mapping *cnpm; + cnpm = new Custom_Network_Priority_Mapping(); + + cnpm->corba_priority(corbaPriority); + mappingManager->mapping(cnpm); + + // 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; + + // Set transport protocol properties + RTCORBA::TCPProtocolProperties_var tcpProperties = rtORB->create_tcp_protocol_properties (ACE_DEFAULT_MAX_SOCKET_BUFSIZ, ACE_DEFAULT_MAX_SOCKET_BUFSIZ, 1, 0, 1, 1 /*enable netw. priority*/); + + RTCORBA::ProtocolList protocols; + protocols.length (1); + protocols[0].protocol_type = 0; + protocols[0].transport_protocol_properties = RTCORBA::ProtocolProperties::_duplicate (tcpProperties.in ()); + protocols[0].orb_protocol_properties = RTCORBA::ProtocolProperties::_nil (); + + // obtain rootPOA + CORBA::Object_var poa = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poa.in()); + + // NameService + CORBA::Object_var namingObject = orb->resolve_initial_references("NameService"); + CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingObject.in()); + + // activate POA Manager + PortableServer::POAManager_var poaManager = rootPOA->the_POAManager(); + poaManager->activate(); + std::cout<<"rootPOA OK"<<std::endl; + + // create 2 lanes (message and port) + CORBA::ULong TOTAL_LANES = 2; + RTCORBA::ThreadpoolLanes lanes(TOTAL_LANES); + lanes.length(TOTAL_LANES); + + // message lane + lanes[0].static_threads = 1; + lanes[0].dynamic_threads = 1; + lanes[0].lane_priority = 0; + + // port lane + lanes[1].static_threads = 1; + lanes[1].dynamic_threads = 1; + lanes[1].lane_priority = RTCORBA::maxPriority; + + // create threadpool + RTCORBA::ThreadpoolId threadpool_id = rtORB->create_threadpool_with_lanes(0 /*Stacksize*/, lanes, 0 /*borrowing*/, 0 /*buffering*/, 0 /*maxBuf*/, 0 /*maxBufSize*/); + + // create Policy + CORBA::PolicyList benchPolicy(3); + benchPolicy.length(3); + benchPolicy[0] = rtORB->create_priority_model_policy(RTCORBA::CLIENT_PROPAGATED, 0 /*default priority*/); + benchPolicy[1] = rtORB->create_threadpool_policy(threadpool_id); + benchPolicy[2] = rtORB->create_server_protocol_policy (protocols); + + // create ObjectAdapters, assign Policy + PortableServer::POA_var msgAndPort1POA = rootPOA->create_POA("msgAndPort1POA", poaManager.in(), benchPolicy); + PortableServer::POA_var msgAndPort2POA = rootPOA->create_POA("msgAndPort2POA", poaManager.in(), benchPolicy); + PortableServer::POA_var msgOnlyPOA = rootPOA->create_POA("msgOnlyPOA", poaManager.in(), benchPolicy); + + // benchPolicy[0] = rtORB->create_priority_model_policy(RTCORBA::CLIENT_PROPAGATED, 0 /*default priority*/); + + PortableServer::POA_var portOnlyPOA = rootPOA->create_POA("portOnlyPOA", poaManager.in(), benchPolicy); + std::cout<<"POAs created, Policies assigned"<<std::endl; + + // create the servants + benchmark_msgAndPort1_i msgAndPort1_i(orb); + benchmark_msgAndPort2_i msgAndPort2_i(orb); + benchmark_msgOnly_i msgOnly_i(orb); + benchmark_setPortsOnly_i portOnly_i(orb); + + // activate servants + CosNaming::Name name(1); + name.length(1); + + PortableServer::ObjectId_var objectID = msgAndPort1POA->activate_object(&msgAndPort1_i); + CORBA::Object_var benchObj = msgAndPort1POA->id_to_reference(objectID.in()); + name[0].id = CORBA::string_dup("msgAndPort1"); + namingContext->bind(name, benchObj.in()); + + objectID = msgAndPort2POA->activate_object(&msgAndPort2_i); + benchObj = msgAndPort2POA->id_to_reference(objectID.in()); + name[0].id = CORBA::string_dup("msgAndPort2"); + namingContext->bind(name, benchObj.in()); + + objectID = msgOnlyPOA->activate_object(&msgOnly_i); + benchObj = msgOnlyPOA->id_to_reference(objectID.in()); + name[0].id = CORBA::string_dup("msgOnly"); + namingContext->bind(name, benchObj.in()); + + objectID = portOnlyPOA->activate_object(&portOnly_i); + benchObj = portOnlyPOA->id_to_reference(objectID.in()); + name[0].id = CORBA::string_dup("portOnly"); + namingContext->bind(name, benchObj.in()); + + std::cout<<"Servants activated"<<std::endl; + + // start ORB + orb->run(); + std::cout<<"ORB ready"<<std::endl; + + //destroy + rootPOA->destroy(1,1); + orb->destroy(); + }catch(CORBA::Exception &any){ + std::cout<<"Exception: "<<any<<std::endl; + } + return 0; +} + |
