hpp-corbaserver  4.9.0
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 // This file is part of the hpp-corbaserver.
5 //
6 // hpp-corbaserver is free software: you can redistribute
7 // it and/or modify it under the terms of the GNU Lesser General
8 // Public License as published by the Free Software Foundation, either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // hpp-corbaserver is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with hpp-corbaserver. If not, see
18 // <http://www.gnu.org/licenses/>.
19 
20 #ifndef HPP_CORBASERVER_BASIC_SERVER_HH
21 # define HPP_CORBASERVER_BASIC_SERVER_HH
22 
23 # include <stdexcept>
24 
25 # include <hpp/util/exception.hh>
26 
29 
30 # include "robot.impl.hh"
31 # include "obstacle.impl.hh"
32 # include "problem.impl.hh"
33 
34 namespace hpp {
35  namespace corbaServer {
36  namespace impl {
37  class Obstacle;
38  class Problem;
39  class Robot;
40  }
41 
42  class HPP_CORBASERVER_LOCAL BasicServer: public ServerPlugin
43  {
44  public:
45  BasicServer (Server* parent);
46 
47  ~BasicServer ();
48 
50  void startCorbaServer (const std::string& contextId,
51  const std::string& contextKind);
52 
53  ::CORBA::Object_ptr servant (const std::string& name) const;
54 
55  std::string name() const;
56 
57  private:
58  corba::Server <impl::Obstacle>* obstacleImpl_;
59  corba::Server <impl::Problem >* problemImpl_;
60  corba::Server <impl::Robot >* robotImpl_;
61  }; // class ServerPlugin
62 
64  : ServerPlugin (parent)
65  , obstacleImpl_ (NULL)
66  , problemImpl_ (NULL)
67  , robotImpl_ (NULL)
68  {
69  }
70 
72  {
73  if (obstacleImpl_) delete obstacleImpl_;
74  if (problemImpl_ ) delete problemImpl_;
75  if (robotImpl_ ) delete robotImpl_;
76  }
77 
78  std::string BasicServer::name () const
79  {
80  return "basic";
81  }
82 
85  const std::string& contextId,
86  const std::string& contextKind)
87  {
88  initializeTplServer(obstacleImpl_, contextId, contextKind, name(), "obstacle");
89  initializeTplServer(problemImpl_ , contextId, contextKind, name(), "problem");
90  initializeTplServer(robotImpl_ , contextId, contextKind, name(), "robot");
91 
92  obstacleImpl_->implementation ().setServer (this);
93  problemImpl_ ->implementation ().setServer (this);
94  robotImpl_ ->implementation ().setServer (this);
95  }
96 
97  ::CORBA::Object_ptr BasicServer::servant(const std::string& name) const
98  {
99  if (name == "obstacle") return obstacleImpl_->implementation()._this();
100  if (name == "problem" ) return problemImpl_ ->implementation()._this();
101  if (name == "robot" ) return robotImpl_ ->implementation()._this();
102  throw std::invalid_argument ("No servant " + name);
103  }
104  } // namespace corbaserver
105 } // namespace hpp
106 
107 #endif // HPP_CORBASERVER_SERVER_PLUGIN_HH
Definition: server-plugin.hh:44
~BasicServer()
Definition: basic-server.hh:71
Implement CORBA interface ``Obstacle&#39;&#39;.
::CORBA::Object_ptr servant(const std::string &name) const
Definition: basic-server.hh:97
BasicServer(Server *parent)
Definition: basic-server.hh:63
std::string name(const LieGroupGenericTpl< LieGroupCollection > &lg)
virtual std::string name() const =0
Definition: basic-server.hh:78
ProblemServant< POA_hpp::core_idl::Problem, core::ProblemPtr_t > Problem
Definition: problem.hh:116
Implementation of Hpp module Corba server.
Definition: server.hh:54
virtual void startCorbaServer(const std::string &contextId, const std::string &contextKind)=0
Start corba server.
Definition: basic-server.hh:84
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:85