1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#include <iostream>
#include "benchC.h"
#include "orbsvcs/CosNamingC.h"
#include <tao/RTCORBA/RTCORBA.h>
#include <unistd.h>
#include "cpx.h"
static benchmark::PutHigh_var highPut;
static benchmark::PutLow_var lowPut;
static bool high;
static CPX cpx;
static CORBA::ORB_ptr orb;
static RTCORBA::RTORB_var rtORB;
extern CosNaming::NamingContext_ptr nameContext;
template <class T> typename T::_ptr_type bindService (const char *n, int argc, char *argv[]) {
CORBA::Object_var obj;
if (CORBA::is_nil (nameContext)) { //first call
// get ORB
orb = CORBA::ORB_init (argc, argv, 0);
// get RTORB
obj = orb->resolve_initial_references("RTORB");
rtORB = RTCORBA::RTORB::_narrow(obj.in());
// get NamingService
obj = orb->resolve_initial_references ("NameService");
nameContext = CosNaming::NamingContext::_narrow (obj);
if (CORBA::is_nil (name_context)) return 0;
}
CosNaming::Name svcName;
svcName.length (1);
svcName[0].id = n;
// retrieve reference
obj = nameContext->resolve(svcName);
// cast to T
return T::_narrow (obj);
}
void sigproc(int signo) {
signal(SIGRTMIN+29, sigproc);
if (high) highPut->onePort(1, cpx.get(1));
else lowPut->onePort(3, cpx.get(1));
}
void argError(){
std::cout<<"./Supplier high|low <corba-args>\n";
}
int main(int argc, char* argv[]){
if (argc < 1) {
argError();
return 0;
}
if (argv[1] == "high") high = true;
else if (argv[1] == "low") high = false;
else {
argError();
return 0;
}
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{
// receive Objects
if (high) highPut = bindService<PutHigh>("HighReceiver", argc, argv);
else lowPut = bindService<PutLow>("LowReceiver", argc, argv);
// 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;
}
|