-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcorba_ipc_server.cpp
140 lines (120 loc) · 4.62 KB
/
corba_ipc_server.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/***************************************************************************
tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.cpp
generictask_test.cpp - description
-------------------
begin : Mon June 26 2006
copyright : (C) 2006 Peter Soetens
email : [email protected]
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// need access to all TLSF functions embedded in RTT
// this call must occur before ALL RTT include's!!
#define ORO_MEMORY_POOL
#include <rtt/os/tlsf/tlsf.h>
#include <iostream>
#include <rtt/OperationCaller.hpp>
#include <rtt/Service.hpp>
#include <transports/corba/DataFlowI.h>
#include <rtt/transports/corba/RemotePorts.hpp>
#include <transports/corba/ServiceC.h>
#include <transports/corba/corba.h>
#include <rtt/InputPort.hpp>
#include <rtt/OutputPort.hpp>
#include <rtt/TaskContext.hpp>
#include <rtt/plugin/PluginLoader.hpp>
#include <transports/corba/TaskContextServer.hpp>
#include <transports/corba/TaskContextProxy.hpp>
#include <string>
#include <os/main.h>
#include "operations_fixture.hpp"
#include <fstream>
using namespace RTT;
using namespace RTT::detail;
using namespace std;
class TheServer : public TaskContext, public OperationsFixture
{
public:
// Ports
InputPort<double> mi1;
OutputPort<double> mo1;
bool is_calling, is_sending;
int cbcount;
TheServer(string name) : TaskContext(name), mi1("mi"), mo1("mo"), is_calling(false), is_sending(false), cbcount(0) {
ports()->addEventPort( mi1 );
ports()->addPort( mo1 );
this->createOperationCallerFactories( this );
ts = corba::TaskContextServer::Create( this, true ); //use-naming
this->start();
addOperation("callBackPeer", &TheServer::callBackPeer, this,ClientThread);
addOperation("callBackPeerOwn", &TheServer::callBackPeer, this,OwnThread);
}
~TheServer() {
this->stop();
}
void updateHook(){
double d = 123456.789;
mi1.read(d);
mo1.write(d);
}
corba::TaskContextServer* ts;
void callBackPeer(TaskContext* peer, string const& opname) {
int count = ++cbcount;
log(Info) << "Server executes callBackPeer():"<< count <<endlog();
OperationCaller<void(TaskContext*, string const&)> op1 (peer->getOperation(opname), this->engine());
if (!is_calling) {
is_calling = true;
log(Info) << "Server calls back peer:" << count << endlog();
op1(this, "callBackPeerOwn");
log(Info) << "Server finishes call back peer:" << count << endlog();
}
if (!is_sending) {
is_sending = true;
log(Info) << "Server sends back peer:" << count << endlog();
SendHandle<void(TaskContext*, string const&)> handle = op1.send(
this, "callBackPeer");
log(Info) << "Server finishes send back peer:" << count << endlog();
}
log(Info) << "Server finishes callBackPeer():" << count << endlog();
}
};
int ORO_main(int argc, char** argv)
{
#ifdef OR_RT_MALLOC
void* rtMem=0;
size_t freeMem=0;
/// setup real-time memory allocation
rtMem = malloc(BUILD_TEST_RT_MEM_POOL_SIZE); // don't calloc() as is first thing TLSF does.
assert(0 != rtMem);
freeMem = init_memory_pool(BUILD_TEST_RT_MEM_POOL_SIZE, rtMem);
assert((size_t)-1 != freeMem); // increase MEMORY_SIZE above most likely, as TLSF has a several kilobyte overhead
#endif
corba::TaskContextProxy::InitOrb(argc,argv);
PluginLoader::Instance()->loadTypekits("../rtt");
#ifndef WIN32
pid_t pid = getpid();
std::ofstream pidfile("corba-ipc-server.pid");
pidfile << pid << endl;
pidfile.close();
#endif
{
TheServer ctest1("peerRMC");
TheServer ctest2("peerRM");
TheServer ctest3("peerAM");
TheServer ctest4("peerDFI");
TheServer ctest5("peerPC");
TheServer ctest6("peerPP");
TheServer ctest7("peerDH");
TheServer ctest8("peerBH");
TheServer ctest9("peerRMCb");
// wait for shutdown.
corba::TaskContextServer::RunOrb();
}
corba::TaskContextProxy::DestroyOrb();
return 0;
}