hpp-template-corba
9.0.2
Template corba server
Toggle main menu visibility
Loading...
Searching...
No Matches
server.hxx
Go to the documentation of this file.
1
// Copyright (C) 2009, 2010 by Florent Lamiraux, Thomas Moulard, JRL.
2
//
3
// This file is part of hpp-template-corba
4
//
5
// This software is provided "as is" without warranty of any kind,
6
// either expressed or implied, including but not limited to the
7
// implied warranties of fitness for a particular purpose.
8
//
9
// See the COPYING file for more information.
10
11
#ifndef HPP_CORBA_TEMPLATE_SERVER_HXX
12
#define HPP_CORBA_TEMPLATE_SERVER_HXX
13
14
#include <errno.h>
15
#include <pthread.h>
16
17
#include <
hpp/corba/template/debug.hh
>
18
#include <iostream>
19
20
// FIXME: remove me.
21
#define HPP_CORBA_CATCH(msg, ret) \
22
catch (CORBA::UserException & exc) { \
23
hppCorbaDout(error, \
24
"CORBA::UserException: " << msg << " " << exc._name()); \
25
return ret; \
26
} \
27
catch (CORBA::SystemException&) { \
28
hppCorbaDout(error, "CORBA::SystemException: " << msg); \
29
return ret; \
30
} \
31
catch (CORBA::Exception&) { \
32
hppCorbaDout(error, "CORBA::Exception: " << msg); \
33
return ret; \
34
} \
35
catch (omniORB::fatalException & fe) { \
36
hppCorbaDout(error, "CORBA::fatalException: " << msg); \
37
return ret; \
38
} \
39
catch (...) { \
40
hppCorbaDout(error, "CORBA: unknown exception: " << msg); \
41
return ret; \
42
}
43
44
namespace
hpp
{
45
namespace
corba {
46
using
CORBA::COMM_FAILURE;
47
using
CORBA::Exception;
48
using
CORBA::Object_ptr;
49
using
CORBA::Object_var;
50
using
CORBA::ORB_init;
51
using
CORBA::PolicyList;
52
using
CORBA::SystemException;
53
using
omniORB::fatalException;
54
55
typedef
CORBA::ORB::InvalidName
InvalidName
;
56
57
template
<
class
T>
58
Server<T>::Server
(
int
argc,
const
char
* argv[],
const
char
* orb_identifier,
59
const
char
* options[][2])
60
:
ServerBase
(argc, argv, orb_identifier, options), impl_(NULL) {}
61
63
template
<
class
T>
64
Server<T>::~Server
() {
65
deactivateAndDestroyServers();
66
}
67
68
template
<
class
T>
69
T&
Server<T>::implementation
() {
70
return
*impl_;
71
}
72
73
template
<
class
T>
74
bool
Server<T>::initRootPOA
(
bool
inMultiThread) {
75
if
(!
ServerBase::initRootPOA
(inMultiThread))
return
false
;
76
77
if
(impl_ != NULL)
return
true
;
78
poa_
=
main_poa
();
79
80
// create implementation
81
try
{
82
impl_ =
new
T();
83
setServant
(impl_->_this());
84
}
85
HPP_CORBA_CATCH
(
"failed to create the server implementation"
,
false
);
86
87
// activate implementation
88
try
{
89
servantId_ =
poa_
->activate_object(impl_);
90
}
91
HPP_CORBA_CATCH
(
"failed to activate the server implementation"
,
false
);
92
93
return
true
;
94
}
95
96
template
<
class
T>
97
bool
Server<T>::initOmniINSPOA
(
const
char
* object_id) {
98
if
(!
ServerBase::initOmniINSPOA
())
return
false
;
99
100
if
(impl_ != NULL)
return
true
;
101
poa_
=
ins_poa_
;
102
103
// create implementation
104
try
{
105
impl_ =
new
T();
106
setServant
(impl_->_this());
107
}
108
HPP_CORBA_CATCH
(
"failed to create the server implementation"
,
false
);
109
110
try
{
111
servantId_ = PortableServer::string_to_ObjectId(object_id);
112
poa_
->activate_object_with_id(servantId_, impl_);
113
}
114
HPP_CORBA_CATCH
(
"failed to activate the server implementation"
,
false
);
115
116
return
true
;
117
}
118
119
template
<
class
T>
120
void
Server<T>::deactivateAndDestroyServers() {
121
if
(impl_) {
122
try
{
123
poa_->deactivate_object(servantId_);
124
}
catch
(
const
CORBA::OBJECT_NOT_EXIST& exc) {
125
// Servant was already deactivated and deleted.
126
}
127
}
128
}
129
130
}
// end of namespace corba.
131
}
// end of namespace hpp.
132
133
#endif
// HPP_CORBA_TEMPLATE_SERVER_HXX
hpp::corba::ServerBase::poa_
PortableServer::POA_var poa_
Definition
server.hh:95
hpp::corba::ServerBase::main_poa
PortableServer::POA_var main_poa()
Definition
server.hh:86
hpp::corba::ServerBase::ins_poa_
PortableServer::POA_var ins_poa_
Definition
server.hh:95
hpp::corba::ServerBase::initOmniINSPOA
bool initOmniINSPOA()
hpp::corba::ServerBase::setServant
void setServant(CORBA::Object_ptr obj)
hpp::corba::ServerBase::initRootPOA
bool initRootPOA(bool inMultiThread)
hpp::corba::ServerBase::ServerBase
ServerBase(int argc, const char *argv[], const char *orb_identifier="", const char *options[][2]=0)
Constructor.
hpp::corba::Server::Server
Server(int argc, const char *argv[], const char *orb_identifier="", const char *options[][2]=0)
Constructor.
Definition
server.hxx:58
hpp::corba::Server::initRootPOA
bool initRootPOA(bool inMultiThread)
Definition
server.hxx:74
hpp::corba::Server::implementation
T & implementation()
Return a reference to the implementation.
Definition
server.hxx:69
hpp::corba::Server::~Server
~Server()
Shutdown CORBA server.
Definition
server.hxx:64
debug.hh
hpp::corba::InvalidName
CORBA::ORB::InvalidName InvalidName
Definition
server.hxx:55
hpp
Definition
server.hh:18
HPP_CORBA_CATCH
#define HPP_CORBA_CATCH(msg, ret)
Definition
server.hxx:21
include
hpp
corba
template
server.hxx
Generated by
1.17.0