hpp-corbaserver  6.0.0
Corba server for Humanoid Path Planner applications
server-plugin.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_SERVER_PLUGIN_HH
30 #define HPP_CORBASERVER_SERVER_PLUGIN_HH
31 
32 #include <hpp/corba/template/server.hh>
34 #include <hpp/corbaserver/fwd.hh>
37 #include <hpp/util/exception.hh>
38 #include <stdexcept>
39 
40 #define HPP_CORBASERVER_DEFINE_PLUGIN(PluginClassName) \
41  extern "C" { \
42  ::hpp::corbaServer::ServerPlugin* createServerPlugin( \
43  ::hpp::corbaServer::Server* server) { \
44  return new PluginClassName(server); \
45  } \
46  }
47 
48 namespace hpp {
49 namespace corbaServer {
51  public:
52  virtual ~ServerPlugin() {}
53 
55  virtual void startCorbaServer(const std::string& contextId,
56  const std::string& contextKind) = 0;
57 
58  virtual std::string name() const = 0;
59 
60  virtual ::CORBA::Object_ptr servant(const std::string& name) const = 0;
61 
62  Server* parent() { return parent_; }
63 
64  core::ProblemSolverPtr_t problemSolver() const {
65  return problemSolverMap_->selected();
66  }
67 
68  ProblemSolverMapPtr_t problemSolverMap() const { return problemSolverMap_; }
69 
72  problemSolverMap_ = psMap;
73  }
74 
75  protected:
76  ServerPlugin(Server* parent) : parent_(parent) {}
77 
80 
81  template <typename T>
82  void initializeTplServer(corba::Server<T>*& server,
83  const std::string& contextId,
84  const std::string& contextKind,
85  const std::string& objectId,
86  const std::string& objectKind) {
87  server = new corba::Server<T>(0, NULL);
88  server->initRootPOA(parent()->multiThread());
89 
90  int ret = parent()->nameService()
91  ? server->startCorbaServer(contextId, contextKind, objectId,
92  objectKind)
93  : server->startCorbaServer();
94 
95  if (ret != 0) {
96  throw std::runtime_error("Failed to start corba " + contextId + '.' +
97  contextKind + '/' + objectId + '.' + objectKind +
98  " server.");
99  }
100  }
101 }; // class ServerPlugin
102 } // namespace corbaServer
103 } // namespace hpp
104 
105 #endif // HPP_CORBASERVER_SERVER_PLUGIN_HH
Definition: server-plugin.hh:50
ProblemSolverMapPtr_t problemSolverMap_
Definition: server-plugin.hh:79
ProblemSolverMapPtr_t problemSolverMap() const
Definition: server-plugin.hh:68
Server * parent()
Definition: server-plugin.hh:62
void setProblemSolverMap(ProblemSolverMapPtr_t psMap)
Set planner that will be controlled by server.
Definition: server-plugin.hh:71
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
ServerPlugin(Server *parent)
Definition: server-plugin.hh:76
core::ProblemSolverPtr_t problemSolver() const
Definition: server-plugin.hh:64
virtual ~ServerPlugin()
Definition: server-plugin.hh:52
virtual ::CORBA::Object_ptr servant(const std::string &name) const =0
Server * parent_
Definition: server-plugin.hh:78
virtual void startCorbaServer(const std::string &contextId, const std::string &contextKind)=0
Start corba server.
virtual std::string name() const =0
Implementation of Hpp module Corba server.
Definition: server.hh:78
#define HPP_CORBASERVER_DLLAPI
Definition: config.hh:88
shared_ptr< ProblemSolverMap > ProblemSolverMapPtr_t
Definition: fwd.hh:57
Implement CORBA interface `‘Obstacle’'.
Definition: client.hh:46