corba_ipc_server.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jun 26 13:26:02 CEST 2006  generictask_test.cpp
00003 
00004                         generictask_test.cpp -  description
00005                            -------------------
00006     begin                : Mon June 26 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@fmtc.be
00009 
00010  ***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 
00020 // need access to all TLSF functions embedded in RTT
00021 // this call must occur before ALL RTT include's!!
00022 #define ORO_MEMORY_POOL
00023 #include <rtt/os/tlsf/tlsf.h>
00024 
00025 #include <iostream>
00026 #include <rtt/OperationCaller.hpp>
00027 #include <rtt/Service.hpp>
00028 #include <transports/corba/DataFlowI.h>
00029 #include <rtt/transports/corba/RemotePorts.hpp>
00030 #include <transports/corba/ServiceC.h>
00031 #include <transports/corba/corba.h>
00032 #include <rtt/InputPort.hpp>
00033 #include <rtt/OutputPort.hpp>
00034 #include <rtt/TaskContext.hpp>
00035 #include <rtt/plugin/PluginLoader.hpp>
00036 #include <transports/corba/TaskContextServer.hpp>
00037 #include <transports/corba/TaskContextProxy.hpp>
00038 #include <string>
00039 #include <os/main.h>
00040 #include "operations_fixture.hpp"
00041 #include <fstream>
00042 
00043 using namespace RTT;
00044 using namespace RTT::detail;
00045 using namespace std;
00046 
00047 class TheServer : public TaskContext, public OperationsFixture
00048 {
00049 public:
00050     // Ports
00051     InputPort<double>  mi1;
00052     OutputPort<double> mo1;
00053     bool is_calling, is_sending;
00054     int cbcount;
00055 
00056     TheServer(string name) : TaskContext(name), mi1("mi"), mo1("mo"), is_calling(false), is_sending(false), cbcount(0) {
00057         ports()->addEventPort( mi1 );
00058         ports()->addPort( mo1 );
00059         this->createOperationCallerFactories( this );
00060         ts = corba::TaskContextServer::Create( this, true ); //use-naming
00061         this->start();
00062         addOperation("callBackPeer", &TheServer::callBackPeer, this,ClientThread);
00063         addOperation("callBackPeerOwn", &TheServer::callBackPeer, this,OwnThread);
00064     }
00065     ~TheServer() {
00066         this->stop();
00067     }
00068 
00069     void updateHook(){
00070         double d = 123456.789;
00071         mi1.read(d);
00072         mo1.write(d);
00073     }
00074 
00075     corba::TaskContextServer* ts;
00076 
00077     void callBackPeer(TaskContext* peer, string const& opname) {
00078         int count = ++cbcount;
00079         log(Info) << "Server executes callBackPeer():"<< count <<endlog();
00080         OperationCaller<void(TaskContext*, string const&)> op1 (peer->getOperation(opname), this->engine());
00081                 if (!is_calling) {
00082                         is_calling = true;
00083                         log(Info) << "Server calls back peer:" << count << endlog();
00084                         op1(this, "callBackPeerOwn");
00085                         log(Info) << "Server finishes call back peer:" << count << endlog();
00086                 }
00087 
00088                 if (!is_sending) {
00089                         is_sending = true;
00090                         log(Info) << "Server sends back peer:" << count << endlog();
00091                         SendHandle<void(TaskContext*, string const&)> handle = op1.send(
00092                                         this, "callBackPeer");
00093                         log(Info) << "Server finishes send back peer:" << count << endlog();
00094                 }
00095                 log(Info) << "Server finishes callBackPeer():" << count << endlog();
00096     }
00097 
00098 };
00099 
00100 int ORO_main(int argc, char** argv)
00101 {
00102 #ifdef OR_RT_MALLOC
00103         void*   rtMem=0;
00104         size_t  freeMem=0;
00105 
00107         rtMem           = malloc(BUILD_TEST_RT_MEM_POOL_SIZE);  // don't calloc() as is first thing TLSF does.
00108         assert(0 != rtMem);
00109         freeMem         = init_memory_pool(BUILD_TEST_RT_MEM_POOL_SIZE, rtMem);
00110         assert((size_t)-1 != freeMem); // increase MEMORY_SIZE above most likely, as TLSF has a several kilobyte overhead
00111 #endif
00112     corba::TaskContextProxy::InitOrb(argc,argv);
00113 
00114     PluginLoader::Instance()->loadTypekits("../rtt");
00115 
00116 #ifndef WIN32
00117     pid_t pid = getpid();
00118     std::ofstream pidfile("corba-ipc-server.pid");
00119     pidfile << pid << endl;
00120     pidfile.close();
00121 #endif
00122     {
00123         TheServer ctest1("peerRMC");
00124         TheServer ctest2("peerRM");
00125         TheServer ctest3("peerAM");
00126         TheServer ctest4("peerDFI");
00127         TheServer ctest5("peerPC");
00128         TheServer ctest6("peerPP");
00129         TheServer ctest7("peerDH");
00130         TheServer ctest8("peerBH");
00131         TheServer ctest9("peerRMCb");
00132 
00133         // wait for shutdown.
00134         corba::TaskContextServer::RunOrb();
00135     }
00136 
00137     corba::TaskContextProxy::DestroyOrb();
00138 
00139     return 0;
00140 }


rtt
Author(s): RTT Developers
autogenerated on Mon Oct 6 2014 03:13:34