corba_ipc_server.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.cpp
3 
4  generictask_test.cpp - description
5  -------------------
6  begin : Mon June 26 2006
7  copyright : (C) 2006 Peter Soetens
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 // need access to all TLSF functions embedded in RTT
21 // this call must occur before ALL RTT include's!!
22 #define ORO_MEMORY_POOL
23 #include <rtt/os/tlsf/tlsf.h>
24 
25 #include <iostream>
26 #include <rtt/OperationCaller.hpp>
27 #include <rtt/Service.hpp>
30 #include <transports/corba/ServiceC.h>
31 #include <transports/corba/corba.h>
32 #include <rtt/InputPort.hpp>
33 #include <rtt/OutputPort.hpp>
34 #include <rtt/TaskContext.hpp>
38 #include <string>
39 #include <os/main.h>
40 #include "operations_fixture.hpp"
41 #include <fstream>
42 
43 using namespace RTT;
44 using namespace RTT::detail;
45 using namespace std;
46 
47 class TheServer : public TaskContext, public OperationsFixture
48 {
49 public:
50  // Ports
53  enum { INITIAL, CALL, SEND, FINAL } callBackPeer_step;
55 
56  TheServer(string name) : TaskContext(name), mi1("mi"), mo1("mo"), callBackPeer_step(INITIAL), callBackPeer_count(0) {
57  ports()->addEventPort( mi1 );
58  ports()->addPort( mo1 );
59  this->createOperationCallerFactories( this );
60  ts = corba::TaskContextServer::Create( this, /* use_naming = */ true );
61  this->start();
62  addOperation("callBackPeer", &TheServer::callBackPeer, this,ClientThread);
63  addOperation("callBackPeerOwn", &TheServer::callBackPeer, this,OwnThread);
64  addOperation("resetCallBackPeer", &TheServer::resetCallBackPeer, this,OwnThread);
65  }
67  this->stop();
68  }
69 
70  void updateHook(){
71  double d = 123456.789;
72  FlowStatus fs = NoData;
73  while( (fs = mi1.read(d, false)) == NewData ) {
74  mo1.write(d);
75  }
76  }
77 
79 
80  void callBackPeer(TaskContext* peer, string const& opname) {
81  OperationCaller<void(TaskContext*, string const&)> op1(peer->getOperation(opname), this->engine());
82  int count = ++callBackPeer_count;
83 
84  if (callBackPeer_step == INITIAL) callBackPeer_step = CALL;
85 
86  log(Info) << "Server executes callBackPeer():"<< count <<endlog();
87  if (callBackPeer_step == CALL) {
88  callBackPeer_step = SEND;
89  log(Info) << "Server calls back peer:" << count << endlog();
90  op1(this, "callBackPeerOwn");
91  log(Info) << "Server finishes call back peer:" << count << endlog();
92  }
93  else if (callBackPeer_step == SEND) {
94  callBackPeer_step = FINAL;
95  log(Info) << "Server sends back peer:" << count << endlog();
97  this, "callBackPeer");
98  log(Info) << "Server finishes send back peer:" << count << endlog();
99  }
100  log(Info) << "Server finishes callBackPeer():" << count << endlog();
101  }
102 
104  log(Info) << "Server resets callBackPeer state." <<endlog();
105  callBackPeer_count = 0;
106  callBackPeer_step = INITIAL;
107  }
108 
109 };
110 
111 int ORO_main(int argc, char** argv)
112 {
113 #ifdef OS_RT_MALLOC
114  void* rtMem=0;
115  size_t freeMem=0;
116 
118  rtMem = malloc(BUILD_TEST_RT_MEM_POOL_SIZE); // don't calloc() as is first thing TLSF does.
119  assert(0 != rtMem);
120  freeMem = init_memory_pool(BUILD_TEST_RT_MEM_POOL_SIZE, rtMem);
121  assert((size_t)-1 != freeMem); // increase MEMORY_SIZE above most likely, as TLSF has a several kilobyte overhead
122  (void)freeMem; // avoid compiler warning
123 #endif
125 
126  PluginLoader::Instance()->loadTypekits("../rtt");
127 
128 #ifndef WIN32
129  pid_t pid = getpid();
130  std::ofstream pidfile("corba-ipc-server.pid");
131  pidfile << pid << endl;
132  pidfile.close();
133 #endif
134  {
135  TheServer ctest1("peerRMC");
136  TheServer ctest2("peerRM");
137  TheServer ctest3("peerAM");
138  TheServer ctest4("peerDFI");
139  TheServer ctest5("peerPC");
140  TheServer ctest6("peerPP");
141  TheServer ctest7("peerDH");
142  TheServer ctest8("peerBH");
143  TheServer ctest9("peerRMCb");
144 
145  // wait for shutdown.
147  }
148 
150 
151  return 0;
152 }
InputPort< double > mi1
void resetCallBackPeer()
FlowStatus
Definition: FlowStatus.hpp:56
Definition: mystd.hpp:163
size_t init_memory_pool(size_t mem_pool_size, void *mem_pool)
Definition: tlsf.c:498
OutputPort< double > mo1
FlowStatus read(base::DataSourceBase::shared_ptr source)
Definition: InputPort.hpp:97
void callBackPeer(TaskContext *peer, string const &opname)
static RTT_CORBA_API bool InitOrb(int argc, char *argv[], Seconds orb_timeout=0)
TheServer(string name)
static TaskContextServer * Create(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
WriteStatus write(const T &sample)
Definition: OutputPort.hpp:243
basic_ostreams & endl(basic_ostreams &s)
Definition: rtstreams.cpp:110
OperationInterfacePart * getOperation(std::string name)
static boost::shared_ptr< PluginLoader > Instance()
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
int ORO_main(int argc, char **argv)
static Logger & log()
Definition: Logger.hpp:350
corba::TaskContextServer * ts
static Logger::LogFunction endlog()
Definition: Logger.hpp:362


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:32