GCC Code Coverage Report


Directory: ./
File: include/hpp/corbaserver/server.hh
Date: 2024-09-11 11:37:19
Exec Total Coverage
Lines: 5 5 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // Copyright (C) 2009, 2010 by Florent Lamiraux, Thomas Moulard, Joseph Mirabel,
2 // JRL.
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 // This software is provided "as is" without warranty of any kind,
30 // either expressed or implied, including but not limited to the
31 // implied warranties of fitness for a particular purpose.
32 //
33 // See the COPYING file for more information.
34
35 #ifndef HPP_CORBASERVER_SERVER_HH
36 #define HPP_CORBASERVER_SERVER_HH
37
38 #include <omniORB4/CORBA.h>
39
40 #include <hpp/corba/template/server.hh>
41 #include <hpp/corbaserver/config.hh>
42 #include <hpp/corbaserver/fwd.hh>
43 #include <hpp/corbaserver/problem-solver-map.hh>
44 #include <hpp/corbaserver/read-write-lock.hh>
45
46 namespace hpp {
47 namespace corbaServer {
48 /// Implementation of Hpp module Corba server.
49
50 /// This class initializes the Corba server and starts the following Corba
51 /// interface implementations. \li hpp::corbaserver::Robot: to build a
52 /// hpp::model::Device and to insert it in a hpp::core::ProblemSolver object,
53 /// \li hpp::corbaserver::Obstacle: to build obstacles and insert them in a
54 /// hpp::core::ProblemSolver object, \li hpp::corbaserver::Problem: to define a
55 /// path planning problem and solve it.
56
57 /// To use this object, call the constructor
58
59 /// \code
60 /// int argc=1;
61 /// char *argv[1] = {"program"};
62 /// core::ProblemSolverPtr_t problemSolver = new core::ProblemSolver;
63 /// Server server(problemSolver, argc, argv, isMultiThread);
64 /// \endcode
65 /// where \c isMultiThread specifies whether the server should process
66 /// requests using multi-thread policy of not.
67
68 /// After starting a name server and configuring your Corba implementation,
69 /// start the servers.
70 /// \code
71 /// server.startCorbaServer();
72 /// \endcode
73 /// Then, enter in the loop that handle the Corba requests
74 /// \code
75 /// server.processRequest(true);
76 /// \endcode
77 /// You can then send request to the servers.
78 class HPP_CORBASERVER_DLLAPI Server {
79 public:
80 /// Constructor
81 /// \param problemSolver the object that will handle Corba requests.
82 /// \param argc, argv parameter to feed ORB initialization.
83 /// \param multiThread whether the server may process request using
84 /// multithred policy.
85 /// \note It is recommended to configure your Corba implementation
86 /// through environment variables and to set argc to 1 and argv to
87 /// any string.
88 /// \note It is highly recommended not to enable multi-thread policy in
89 /// CORBA request processing if this library is run from an openGL
90 /// based GUI, since OpenGL does not support multithreading.
91 Server(core::ProblemSolverPtr_t problemSolver, int argc, const char* argv[],
92 bool multiThread = false);
93
94 /// Constructor
95 /// \param problemSolver the object that will handle Corba requests.
96 /// \param multiThread whether the server may process request using
97 /// multithred policy.
98 Server(core::ProblemSolverPtr_t problemSolver, bool multiThread = false);
99
100 ///\name CORBA server initialization
101 /// \{
102
103 /// Configure using command line argument
104 bool parseArguments(int argc, const char* argv[]);
105
106 /// Initialize ORB and CORBA servers.
107 void initialize();
108
109 /// \}
110
111 /// \brief Shutdown CORBA server
112 ~Server();
113
114 14 PortableServer::POA_var poa() { return tools_->main_poa(); }
115
116 9 CORBA::ORB_var orb() { return tools_->orb(); }
117
118 /// \brief Initialize CORBA server to process requests from clients
119 /// \return 0 if success, -1 if failure.
120 void startCorbaServer();
121
122 /// Get main context ID
123 8 const std::string& mainContextId() const { return mainContextId_; }
124
125 24 const bool& multiThread() const { return multiThread_; }
126
127 24 const bool& nameService() const { return nameService_; }
128
129 /// \brief If ORB work is pending, process it
130 /// \param loop if true, the function never returns,
131 /// if false, the function processes pending requests and
132 /// returns.
133 int processRequest(bool loop);
134
135 /// Request a shutdown
136 /// \param wait if true, the method waits for the server to be shut down.
137 /// \warning From a servant method, set wait to false. Otherwise the
138 /// application will be deadlocked.
139 void requestShutdown(bool wait);
140
141 bool createContext(const std::string& contextName);
142
143 std::vector<std::string> getContexts() const;
144
145 bool deleteContext(const std::string& contextName);
146
147 CORBA::Object_ptr getServer(const std::string& contextName,
148 const std::string& pluginName,
149 const std::string& objectName);
150
151 /// Load a plugin if not already loaded.
152 /// \return true if the plugin is correctly loaded, false otherwise (which
153 /// includes the case where the plugin was already loaded).
154 bool loadPlugin(const std::string& contextName,
155 const std::string& libFilename);
156
157 ProblemSolverMapPtr_t problemSolverMap();
158
159 core::ProblemSolverPtr_t problemSolver();
160
161 typedef void* ServantKey;
162
163 PortableServer::Servant getServant(ServantKey servantKey) const;
164
165 void addServantKeyAndServant(ServantKey servantKey,
166 PortableServer::Servant servant);
167
168 void removeServant(PortableServer::Servant servant);
169
170 void clearServantsMap();
171
172 std::vector<std::string> getAllObjectIds();
173
174 private:
175 corba::Server<Tools>* tools_;
176
177 std::string ORBendPoint;
178 std::string mainContextId_;
179
180 bool multiThread_, nameService_;
181
182 /// pointer to core::ProblemSolver Object.
183 ///
184 /// At initialization, the constructor creates a core::ProblemSolver
185 /// object and keeps a pointer to this object. All Corba requests are
186 /// processed by this object. Notice that this pointer is passed
187 /// to each constructor of implementation classes of the server
188 /// Corba interface.
189 ProblemSolverMapPtr_t problemSolverMap_;
190
191 typedef shared_ptr<ServerPlugin> ServerPluginPtr_t;
192 typedef std::map<std::string, ServerPluginPtr_t> ServerPluginMap_t;
193 struct Context {
194 ServerPluginPtr_t main;
195 ServerPluginMap_t plugins;
196 };
197 std::map<std::string, Context> contexts_;
198
199 Context& getContext(const std::string& name);
200
201 typedef std::map<ServantKey, PortableServer::Servant>
202 ServantKeyToServantMap_t;
203 typedef std::map<PortableServer::Servant, ServantKey>
204 ServantToServantKeyMap_t;
205 ServantKeyToServantMap_t servantKeyToServantMap_;
206 ServantToServantKeyMap_t servantToServantKeyMap_;
207 // Mutex for accessing servant / servant key maps.
208 ReadWriteLock lock_;
209 };
210 } // end of namespace corbaServer.
211 } // end of namespace hpp.
212 #endif
213