hpp-template-corba 5.0.0
Template corba server
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
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
44namespace hpp {
45namespace corba {
46using CORBA::COMM_FAILURE;
47using CORBA::Exception;
48using CORBA::Object_ptr;
49using CORBA::Object_var;
50using CORBA::ORB_init;
51using CORBA::PolicyList;
52using CORBA::SystemException;
53using omniORB::fatalException;
54
55typedef CORBA::ORB::InvalidName InvalidName;
56
57template <class T>
58Server<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
63template <class T>
65 deactivateAndDestroyServers();
66}
67
68template <class T>
70 return *impl_;
71}
72
73template <class T>
74bool 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
96template <class T>
97bool 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
119template <class T>
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
Definition: server.hh:20
bool initRootPOA(bool inMultiThread)
Template CORBA server.
Definition: server.hh:124
Server(int argc, const char *argv[], const char *orb_identifier="", const char *options[][2]=0)
Constructor.
Definition: server.hxx:58
bool initRootPOA(bool inMultiThread)
Definition: server.hxx:74
T & implementation()
Return a reference to the implementation.
Definition: server.hxx:69
~Server()
Shutdown CORBA server.
Definition: server.hxx:64
CORBA::ORB::InvalidName InvalidName
Definition: server.hxx:55
Definition: server.hh:18
#define HPP_CORBA_CATCH(msg, ret)
Definition: server.hxx:21