Directory: | ./ |
---|---|
File: | include/hpp/corbaserver/server-plugin.hh |
Date: | 2024-12-13 15:50:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 16 | 18 | 88.9% |
Branches: | 3 | 24 | 12.5% |
Line | Branch | Exec | Source |
---|---|---|---|
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> | ||
33 | #include <hpp/corbaserver/config.hh> | ||
34 | #include <hpp/corbaserver/fwd.hh> | ||
35 | #include <hpp/corbaserver/problem-solver-map.hh> | ||
36 | #include <hpp/corbaserver/server.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 { | ||
50 | class HPP_CORBASERVER_DLLAPI ServerPlugin { | ||
51 | public: | ||
52 | 16 | virtual ~ServerPlugin() {} | |
53 | |||
54 | /// Start corba server | ||
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 | 58 | Server* parent() { return parent_; } | |
63 | |||
64 | 106 | core::ProblemSolverPtr_t problemSolver() const { | |
65 | 106 | return problemSolverMap_->selected(); | |
66 | } | ||
67 | |||
68 | ✗ | ProblemSolverMapPtr_t problemSolverMap() const { return problemSolverMap_; } | |
69 | |||
70 | /// Set planner that will be controlled by server | ||
71 | 8 | void setProblemSolverMap(ProblemSolverMapPtr_t psMap) { | |
72 | 8 | problemSolverMap_ = psMap; | |
73 | 8 | } | |
74 | |||
75 | protected: | ||
76 | 8 | ServerPlugin(Server* parent) : parent_(parent) {} | |
77 | |||
78 | Server* parent_; | ||
79 | ProblemSolverMapPtr_t problemSolverMap_; | ||
80 | |||
81 | template <typename T> | ||
82 | 48 | 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 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
48 | server = new corba::Server<T>(0, NULL); |
88 | 48 | server->initRootPOA(parent()->multiThread()); | |
89 | |||
90 | 48 | int ret = parent()->nameService() | |
91 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
48 | ? server->startCorbaServer(contextId, contextKind, objectId, |
92 | objectKind) | ||
93 | 48 | : server->startCorbaServer(); | |
94 | |||
95 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
48 | if (ret != 0) { |
96 | ✗ | throw std::runtime_error("Failed to start corba " + contextId + '.' + | |
97 | contextKind + '/' + objectId + '.' + objectKind + | ||
98 | " server."); | ||
99 | } | ||
100 | 48 | } | |
101 | }; // class ServerPlugin | ||
102 | } // namespace corbaServer | ||
103 | } // namespace hpp | ||
104 | |||
105 | #endif // HPP_CORBASERVER_SERVER_PLUGIN_HH | ||
106 |