summaryrefslogtreecommitdiff
path: root/quellcode/versuch5/Client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'quellcode/versuch5/Client.cpp')
-rwxr-xr-xquellcode/versuch5/Client.cpp248
1 files changed, 248 insertions, 0 deletions
diff --git a/quellcode/versuch5/Client.cpp b/quellcode/versuch5/Client.cpp
new file mode 100755
index 0000000..e740be3
--- /dev/null
+++ b/quellcode/versuch5/Client.cpp
@@ -0,0 +1,248 @@
+#include <iostream>
+#include <fstream>
+#include "benchC.h"
+#include "orbsvcs/CosNamingC.h"
+#include <tao/RTCORBA/RTCORBA.h>
+#include <unistd.h>
+
+#include "Custom_Network_Priority_Mapping.h"
+#include "cpx.h"
+
+CPX cpx;
+
+benchmark::msg_var message = new benchmark::msg;
+
+benchmark::msgAndPort1_var msgAndPort1;
+benchmark::msgAndPort2_var msgAndPort2;
+benchmark::msgOnly_var msgOnly;
+benchmark::setPortsOnly_var portOnly;
+
+RTCORBA::Current_var current;
+
+int mode;
+std::string strData;
+
+void sigproc(int signo)
+{
+ signal(SIGRTMIN+29, sigproc);
+ switch(mode){
+ case 1:
+ current->the_priority( RTCORBA::maxPriority /* Priority Definition */ );
+ msgAndPort1->setPorts(cpx.get(1), cpx.get(2), cpx.get(3));
+ current->the_priority( RTCORBA::minPriority /* Priority Definition */ );
+ msgAndPort1->sendMsg(message);
+ break;
+ case 2:
+ current->the_priority( RTCORBA::maxPriority /* Priority Definition */ );
+ msgAndPort2->setPortsSendMsg(cpx.get(1), cpx.get(2), cpx.get(3), message);
+ break;
+ case 3:
+ current->the_priority( RTCORBA::minPriority /* Priority Definition */ );
+ std::cout<<"msgOnly mode and DI signal? ..strange"<<std::endl;
+ break;
+ case 4:
+ current->the_priority( RTCORBA::maxPriority /* Priority Definition */ );
+ portOnly->setPorts(cpx.get(1), cpx.get(2), cpx.get(3));
+ current->the_priority( RTCORBA::minPriority /* Priority Definition */ );
+ msgOnly->sendMsg(message);
+ break;
+ default:
+ std::cout<<"this is impossible :-)"<<std::endl;
+ }
+}
+
+
+int main(int argc, char* argv[]){
+
+ if (argc < 2){
+ std::cout<<"enter filename as param1\n";
+ return 0;
+ }
+
+ mode = 0;
+
+ // Mode selection
+ std::cout<<"Which Interface?\n\n1) msgAndPort1\n2) msgAndPort2\n3) msgOnly\n4) 2 Interfaces\n\nNumber: ";
+ std::cin>>mode;
+
+ if ( (mode < 1) || (mode > 4) ) {
+ std::cout<<"Fehlerhafte Eingabe\nBenutze 4)"<<std::endl;
+ mode = 4;
+ }
+
+ 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);
+ }
+
+ std::string line;
+ std::ifstream infile (argv[1], std::ios_base::in);
+ while (getline(infile, line, '\n'))
+ {
+ strData += line;
+ }
+
+ message->sender = CORBA::string_alloc(sizeof(argv[1]));
+ message->sender = CORBA::string_dup((const char*)argv[1]);
+
+ message->message = CORBA::string_alloc(sizeof(strData));
+ message->message = CORBA::string_dup((const char*)strData.c_str());
+
+ 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;
+
+ // Set the tcp protocol protperties
+ RTCORBA::TCPProtocolProperties_var tcp_properties = 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 (tcp_properties.in ());
+ protocols[0].orb_protocol_properties = RTCORBA::ProtocolProperties::_nil ();
+
+
+ // 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;
+
+ CosNaming::Name name(1);
+ name.length(1);
+
+ // Policies
+ CORBA::PolicyList pcPolicy(2);
+ pcPolicy.length(2);
+ pcPolicy[0] = rtORB->create_private_connection_policy();
+ pcPolicy[1] = rtORB->create_client_protocol_policy(protocols);
+
+ CORBA::Policy_var policy;
+ RTCORBA::PriorityModelPolicy_var rtpolicy;
+ RTCORBA::PriorityModel priomod;
+
+ CORBA::Object_var curobj;
+
+ CORBA::Object_var newTran;
+ CORBA::Object_var benchObj;
+
+ curobj = orb->resolve_initial_references("RTCurrent");
+ current = RTCORBA::Current::_narrow (curobj.in());
+
+ // Retrive apropriate objects
+ switch(mode) {
+ case 1:
+ name[0].id = CORBA::string_dup("msgAndPort1");
+ benchObj = namingContext->resolve(name);
+ msgAndPort1 = benchmark::msgAndPort1::_narrow(benchObj.in());
+ newTran = msgAndPort1->_set_policy_overrides(pcPolicy, CORBA::SET_OVERRIDE);
+ msgAndPort1 = benchmark::msgAndPort1::_narrow(newTran.in());
+
+ current->the_priority( 99 /* Priority Definition */ );
+
+ // network priority
+ benchObj = msgAndPort1->_set_policy_overrides (pcPolicy, CORBA::SET_OVERRIDE);
+ msgAndPort1 = benchmark::msgAndPort1::_narrow( benchObj.in() );
+
+ msgAndPort1->connect();
+ msgAndPort1->setPorts(0,0,0);
+ sleep(1);
+ msgAndPort1->setPorts(255,255,255);
+ sleep(1);
+ msgAndPort1->setPorts(0,0,0);
+
+ break;
+ case 2:
+ name[0].id = CORBA::string_dup("msgAndPort2");
+ benchObj = namingContext->resolve(name);
+ msgAndPort2 = benchmark::msgAndPort2::_narrow(benchObj.in());
+ newTran = msgAndPort2->_set_policy_overrides(pcPolicy, CORBA::SET_OVERRIDE);
+ msgAndPort2 = benchmark::msgAndPort2::_narrow(newTran.in());
+
+ current->the_priority( 99 /* Priority Definition */ );
+
+ benchObj = msgAndPort2->_set_policy_overrides (pcPolicy, CORBA::SET_OVERRIDE);
+ msgAndPort2 = benchmark::msgAndPort2::_narrow( benchObj.in() );
+
+ msgAndPort2->connect();
+ msgAndPort2->setPortsSendMsg(0,0,0, message);
+ sleep(1);
+ msgAndPort2->setPortsSendMsg(255,255,255, message);
+ sleep(1);
+ msgAndPort2->setPortsSendMsg(0,0,0, message);
+
+ break;
+ case 3:
+ name[0].id = CORBA::string_dup("msgOnly");
+ benchObj = namingContext->resolve(name);
+ msgOnly = benchmark::msgOnly::_narrow(benchObj.in());
+ newTran = msgOnly->_set_policy_overrides(pcPolicy, CORBA::SET_OVERRIDE);
+ msgOnly = benchmark::msgOnly::_narrow(newTran.in());
+
+ current->the_priority( RTCORBA::minPriority /* Priority Definition */ );
+
+ benchObj = msgOnly->_set_policy_overrides (pcPolicy, CORBA::SET_OVERRIDE);
+ msgOnly = benchmark::msgOnly::_narrow( benchObj.in() );
+
+ while(true){
+ if(!msgOnly->sendMsg(message)){
+ std::cout<<"error occured -> exit"<<std::endl;
+ return 0;
+ }
+ }
+ break;
+
+ case 4:
+ name[0].id = CORBA::string_dup("portOnly");
+ benchObj = namingContext->resolve(name);
+ portOnly = benchmark::setPortsOnly::_narrow(benchObj.in());
+ newTran = portOnly->_set_policy_overrides(pcPolicy, CORBA::SET_OVERRIDE);
+ portOnly = benchmark::setPortsOnly::_narrow(newTran.in());
+
+ benchObj = portOnly->_set_policy_overrides (pcPolicy, CORBA::SET_OVERRIDE);
+ portOnly = benchmark::setPortsOnly::_narrow( benchObj.in() );
+
+ name[0].id = CORBA::string_dup("msgOnly");
+ benchObj = namingContext->resolve(name);
+ msgOnly = benchmark::msgOnly::_narrow(benchObj.in());
+ newTran = msgOnly->_set_policy_overrides(pcPolicy, CORBA::SET_OVERRIDE);
+ msgOnly = benchmark::msgOnly::_narrow(newTran.in());
+
+ current->the_priority( 99 /* Priority Definition */ );
+
+ benchObj = msgOnly->_set_policy_overrides (pcPolicy, CORBA::SET_OVERRIDE);
+ msgOnly = benchmark::msgOnly::_narrow( benchObj.in() );
+
+ portOnly->connect();
+ portOnly->setPorts(0,0,0);
+ sleep(1);
+ portOnly->setPorts(255,255,255);
+ sleep(1);
+ portOnly->setPorts(0,0,0);
+ break;
+ default:
+ std::cout<<"this never happens ;-)"<<std::endl;
+ }
+
+ // 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;
+}