hpp-corbaserver: src/basic-server.hh Source File

hpp-corbaserver 9.0.2 Corba server for Humanoid Path Planner applications

basic-server.hh
Go to the documentation of this file.
1 // Copyright (C) 2019 CNRS-LAAS
2 // Author: Joseph Mirabel
3 //
4
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28
29 #ifndef HPP_CORBASERVER_BASIC_SERVER_HH
30 #define HPP_CORBASERVER_BASIC_SERVER_HH
31
32 #include <hpp/corba/template/server.hh>
33 #include <hpp/corbaserver/server-plugin.hh>
34 #include <hpp/util/exception.hh>
35 #include <stdexcept>
36
37 #include "obstacle.impl.hh"
38 #include "problem.impl.hh"
39 #include "robot.impl.hh"
40
41 namespace hpp {
42 namespace corbaServer {
43 namespace impl {
44 class Obstacle;
45 class Problem;
46 class Robot;
47 } // namespace impl
48
49 class HPP_CORBASERVER_LOCAL BasicServer : public ServerPlugin {
50 public:
51 BasicServer(Server* parent);
52
53 ~BasicServer();
54
56 void startCorbaServer(const std::string& contextId,
57 const std::string& contextKind);
58
59 ::CORBA::Object_ptr servant(const std::string& name) const;
60
61 std::string name() const;
62
63 private:
64 corba::Server<impl::Obstacle>* obstacleImpl_;
65 corba::Server<impl::Problem>* problemImpl_;
66 corba::Server<impl::Robot>* robotImpl_;
67 }; // class ServerPlugin
68
69 BasicServer::BasicServer(Server* parent)
70 : ServerPlugin(parent),
71 obstacleImpl_(NULL),
72 problemImpl_(NULL),
73 robotImpl_(NULL) {}
74
75 BasicServer::~BasicServer() {
76 if (obstacleImpl_) delete obstacleImpl_;
77 if (problemImpl_) delete problemImpl_;
78 if (robotImpl_) delete robotImpl_;
79 }
80
81 std::string BasicServer::name() const { return "basic"; }
82
84 void BasicServer::startCorbaServer(const std::string& contextId,
85 const std::string& contextKind) {
86 initializeTplServer(obstacleImpl_, contextId, contextKind, name(),
87 "obstacle");
88 initializeTplServer(problemImpl_, contextId, contextKind, name(), "problem");
89 initializeTplServer(robotImpl_, contextId, contextKind, name(), "robot");
90
91 obstacleImpl_->implementation().setServer(this);
92 problemImpl_->implementation().setServer(this);
93 robotImpl_->implementation().setServer(this);
94 }
95
96 ::CORBA::Object_ptr BasicServer::servant(const std::string& name) const {
97 if (name == "obstacle") return obstacleImpl_->implementation()._this();
98 if (name == "problem") return problemImpl_->implementation()._this();
99 if (name == "robot") return robotImpl_->implementation()._this();
100 throw std::invalid_argument("No servant " + name);
101 }
102 } // namespace corbaServer
103 } // namespace hpp
104
105 #endif // HPP_CORBASERVER_SERVER_PLUGIN_HH
Obstacle
Definition: obstacle-idl.hh:94
Problem
Definition: problem-idl.hh:138
Robot
Definition: robot-idl.hh:98
hpp::corbaServer::BasicServer
Definition: basic-server.hh:49
hpp::corbaServer::BasicServer::startCorbaServer
void startCorbaServer(const std::string &contextId, const std::string &contextKind)
Start corba server.
Definition: basic-server.hh:84
hpp::corbaServer::BasicServer::name
std::string name() const
Definition: basic-server.hh:81
hpp::corbaServer::BasicServer::~BasicServer
~BasicServer()
Definition: basic-server.hh:75
hpp::corbaServer::BasicServer::servant
::CORBA::Object_ptr servant(const std::string &name) const
Definition: basic-server.hh:96
hpp::corbaServer::BasicServer::BasicServer
BasicServer(Server *parent)
Definition: basic-server.hh:69
hpp::corbaServer::ServerPlugin
Definition: server-plugin.hh:50
hpp::corbaServer::ServerPlugin::initializeTplServer
void initializeTplServer(corba::Server< T > *&server, const std::string &contextId, const std::string &contextKind, const std::string &objectId, const std::string &objectKind)
Definition: server-plugin.hh:82
hpp::corbaServer::Server
Implementation of Hpp module Corba server.
Definition: server.hh:78
hpp::corba::Server
HPP_CORBASERVER_LOCAL
#define HPP_CORBASERVER_LOCAL
Definition: config.hh:92
exception.hh
hpp
Implement CORBA interface `‘Obstacle’'.
obstacle.impl.hh
problem.impl.hh
robot.impl.hh
server-plugin.hh
server.hh