Skip to content

Commit f65cad6

Browse files
authored
Merge pull request #12 from jmirabel/devel
Use plugin mechanism of hpp-corbaserver.
2 parents b9a1b9a + e057cd6 commit f65cad6

File tree

7 files changed

+58
-66
lines changed

7 files changed

+58
-66
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ SET(CUSTOM_HEADER_DIR hpp/corbaserver/affordance)
3232

3333
SETUP_HPP_PROJECT ()
3434

35+
LIST(APPEND PKG_CONFIG_ADDITIONAL_VARIABLES cmake_plugin)
36+
3537
# Dependencies
3638
HPP_FINDPYTHON()
3739
ADD_REQUIRED_DEPENDENCY("hpp-core >= 3")

include/hpp/corbaserver/affordance/server.hh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# define HPP_AFFORDANCE_CORBA_SERVER_HH
1313

1414
# include <hpp/corba/template/server.hh>
15+
# include <hpp/corbaserver/server-plugin.hh>
1516
# include <hpp/corbaserver/affordance/fwd.hh>
1617
# include <hpp/corbaserver/affordance/config.hh>
1718
# include "hpp/corbaserver/problem-solver-map.hh"
@@ -25,21 +26,18 @@ namespace hpp
2526
class Afford;
2627
} // namespace impl
2728

28-
class HPP_AFFORDANCE_CORBA_DLLAPI Server
29+
class HPP_AFFORDANCE_CORBA_DLLAPI Server : public corbaServer::ServerPlugin
2930
{
3031
public:
31-
Server (int argc, const char* argv[], bool multiThread = false,
32-
const std::string& poaName = "child");
32+
Server (corbaServer::Server* parent);
3333

3434
/// \brief Shutdown CORBA server
3535
~Server ();
36-
/// Set planner that will be controlled by server
37-
void setProblemSolverMap (hpp::corbaServer::ProblemSolverMapPtr_t psMap);
3836

3937
void startCorbaServer(const std::string& contextId,
40-
const std::string& contextKind,
41-
const std::string& objectId,
42-
const std::string& objectKind);
38+
const std::string& contextKind);
39+
40+
std::string name () const;
4341

4442
private:
4543
corba::Server <impl::Afford>* impl_;

src/CMakeLists.txt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ SET(IDL_SOURCES
2020
affordance
2121
)
2222

23+
INCLUDE(${HPP_CORBASERVER_CMAKE_PLUGIN})
2324
OMNIIDL_INCLUDE_DIRECTORIES(
2425
${HPP_CORBASERVER_DATAROOTDIR}/idl
2526
${CMAKE_SOURCE_DIR}/idl
@@ -51,24 +52,17 @@ INSTALL(
5152
ADD_CUSTOM_TARGET(generate_idl_cpp DEPENDS ${ALL_IDL_CPP_STUBS})
5253
ADD_CUSTOM_TARGET(generate_idl_python DEPENDS ${ALL_IDL_PYTHON_STUBS})
5354

54-
ADD_LIBRARY(${LIBRARY_NAME}
55-
SHARED
55+
HPP_ADD_SERVER_PLUGIN(affordance-corba
56+
SOURCES
5657
${ALL_IDL_CPP_STUBS}
5758
affordance.impl.hh
5859
affordance.impl.cc
5960
server.cc
61+
PKG_CONFIG_DEPENDENCIES omniORB4 hpp-corbaserver hpp-affordance hpp-template-corba hpp-util
6062
)
6163

62-
ADD_DEPENDENCIES (${LIBRARY_NAME} generate_idl_cpp)
63-
ADD_DEPENDENCIES (${LIBRARY_NAME} generate_idl_python)
64-
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} hpp-affordance)
65-
66-
PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} hpp-corbaserver)
67-
PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} hpp-affordance)
68-
PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} hpp-template-corba)
69-
PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} hpp-util)
70-
71-
INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
64+
ADD_DEPENDENCIES (affordance-corba generate_idl_cpp)
65+
ADD_DEPENDENCIES (affordance-corba generate_idl_python)
7266

7367
PYTHON_INSTALL_ON_SITE(
7468
hpp/corbaserver/affordance corba.py ${PYTHON_SITELIB}
@@ -123,7 +117,6 @@ ENDFOREACH()
123117

124118
# Standalone corba server
125119
ADD_EXECUTABLE (hpp-affordance-server hpp-affordance-corba.cc)
126-
TARGET_LINK_LIBRARIES (hpp-affordance-server ${LIBRARY_NAME} hpp-affordance)
127120

128121
PKG_CONFIG_USE_DEPENDENCY(hpp-affordance-server hpp-corbaserver)
129122
PKG_CONFIG_USE_DEPENDENCY(hpp-affordance-server hpp-template-corba)

src/affordance.impl.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ namespace hpp
3737

3838
Afford::Afford (const core::ProblemSolverPtr_t& /*problemSolver*/) {}
3939

40-
void Afford::setProblemSolverMap
41-
(hpp::corbaServer::ProblemSolverMapPtr_t psMap)
42-
{
43-
psMap_ = psMap;
44-
resetAffordanceConfig ();
45-
}
46-
4740
void Afford::resetAffordanceConfig() throw (hpp::Error)
4841
{
4942
problemSolver()->affordanceConfigs.add("Support", vector3_t (0.3,0.3,0.05));

src/affordance.impl.hh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# include "hpp/core/problem-solver.hh"
1616
# include "hpp/corbaserver/problem-solver-map.hh"
1717
# include "hpp/corbaserver/affordance/fwd.hh"
18+
# include "hpp/corbaserver/affordance/server.hh"
1819

1920
# include "affordance-idl.hh"
2021

@@ -31,9 +32,12 @@ namespace hpp
3132

3233
Afford ();
3334

34-
Afford (const core::ProblemSolverPtr_t& problemSolver);
35+
void setServer (Server* server)
36+
{
37+
server_ = server;
38+
}
3539

36-
void setProblemSolverMap (hpp::corbaServer::ProblemSolverMapPtr_t psMap);
40+
Afford (const core::ProblemSolverPtr_t& problemSolver);
3741

3842
void resetAffordanceConfig() throw (hpp::Error);
3943

@@ -85,10 +89,10 @@ namespace hpp
8589
hpp::Names_t* getAffordanceConfigTypes () throw (hpp::Error);
8690

8791
private:
88-
corbaServer::ProblemSolverMapPtr_t psMap_;
92+
Server* server_;
8993
core::ProblemSolverPtr_t problemSolver()
9094
{
91-
return psMap_->selected();
95+
return server_->problemSolver();
9296
}
9397
}; // class Afford
9498
} // namespace impl

src/hpp-affordance-corba.cc

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,21 @@
1111
#include <iostream>
1212
#include <hpp/util/debug.hh>
1313
#include "hpp/corbaserver/server.hh"
14-
#include <hpp/corbaserver/affordance/server.hh>
1514
#include <hpp/corbaserver/problem-solver-map.hh>
1615
#include <hpp/core/problem-solver.hh>
17-
typedef hpp::affordanceCorba::Server AffordanceServer;
16+
1817
typedef hpp::corbaServer::Server CorbaServer;
19-
typedef hpp::affordanceCorba::ProblemSolverPtr_t ProblemSolverPtr_t;
20-
typedef hpp::affordanceCorba::ProblemSolver ProblemSolver;
18+
typedef hpp::core::ProblemSolverPtr_t ProblemSolverPtr_t;
19+
typedef hpp::core::ProblemSolver ProblemSolver;
2120

2221
int
2322
main (int argc, const char* argv[])
2423
{
2524
ProblemSolverPtr_t problemSolver = ProblemSolver::create ();
2625
CorbaServer corbaServer (problemSolver, argc,
2726
const_cast<const char**> (argv), true);
28-
AffordanceServer affServer (argc, argv, true);
29-
affServer.setProblemSolverMap (corbaServer.problemSolverMap());
30-
31-
try {
32-
corbaServer.startCorbaServer ();
33-
hppDout (info, "successfully started hpp-corbaserver");
34-
} catch (const std::exception& exc) {
35-
hppDout (error, "Failed to start hpp-corbaserver");
36-
}
37-
try {
38-
affServer.startCorbaServer ("hpp", "corbaserver",
39-
"affordanceCorba", "affordance");
4027

41-
hppDout (info, "Successfully started corba server for affordance");
42-
} catch (const std::exception& exc) {
43-
hppDout (error, "failed to start corba server for affordance");
44-
}
28+
corbaServer.startCorbaServer ();
29+
corbaServer.loadPlugin (corbaServer.mainContextId(), "affordance-corba.so");
4530
corbaServer.processRequest(true);
4631
}

src/server.cc

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,52 @@
88
//
99
// See the COPYING file for more information.
1010

11+
#include "hpp/corbaserver/affordance/server.hh"
12+
1113
#include <hpp/util/exception.hh>
1214
#include <hpp/util/debug.hh>
13-
#include "hpp/corbaserver/affordance/server.hh"
15+
#include <hpp/corbaserver/server.hh>
1416
#include "affordance.impl.hh"
1517

1618
namespace hpp
1719
{
1820
namespace affordanceCorba
1921
{
20-
Server::Server (int argc, const char* argv[], bool multiThread,
21-
const std::string& poaName) :
22-
impl_ (new corba::Server <impl::Afford>
23-
(argc, argv, multiThread, poaName)) {}
24-
Server::~Server () { delete impl_;}
25-
void Server::setProblemSolverMap (hpp::corbaServer::ProblemSolverMapPtr_t psMap)
22+
Server::Server (corbaServer::Server* server)
23+
: corbaServer::ServerPlugin (server),
24+
impl_ (NULL)
25+
{}
26+
27+
Server::~Server ()
2628
{
27-
impl_->implementation ().setProblemSolverMap (psMap);
29+
if (impl_) delete impl_;
30+
}
31+
32+
std::string Server::name () const
33+
{
34+
return "affordance";
2835
}
2936

3037
/// Start corba server
3138
void Server::startCorbaServer(const std::string& contextId,
32-
const std::string& contextKind,
33-
const std::string& objectId,
34-
const std::string& objectKind)
39+
const std::string& contextKind)
3540
{
36-
if (impl_->startCorbaServer(contextId, contextKind, objectId, objectKind)
37-
!= 0) {
38-
HPP_THROW_EXCEPTION (hpp::Exception, "Failed to start corba server.");
41+
bool mThd = parent()->multiThread();
42+
impl_ = new corba::Server <impl::Afford> (0, NULL, mThd, "child");
43+
44+
impl_->implementation ().setServer (this);
45+
46+
if (impl_->startCorbaServer(contextId, contextKind,
47+
"affordanceCorba", "affordance") != 0) {
48+
HPP_THROW_EXCEPTION (hpp::Exception, "Failed to start affordance corba server.");
3949
}
50+
51+
// TODO this a very fragile. It works because startCorbaServer is called
52+
// after setProblemSolverMap in hpp::corbaServer::Server::getContext
53+
// implementation (file hpp-corbaserver/src/server.cc)
54+
impl_->implementation().resetAffordanceConfig();
4055
}
4156
} // namespace affordanceCorba
4257
} // namespace hpp
58+
59+
HPP_CORBASERVER_DEFINE_PLUGIN(hpp::affordanceCorba::Server)

0 commit comments

Comments
 (0)