GCC Code Coverage Report


Directory: ./
File: include/hpp/corba/template/server.hxx
Date: 2025-03-26 15:03:21
Exec Total Coverage
Lines: 16 19 84.2%
Branches: 13 38 34.2%

Line Branch Exec Source
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 1 Server<T>::Server(int argc, const char* argv[], const char* orb_identifier,
59 const char* options[][2])
60
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 : ServerBase(argc, argv, orb_identifier, options), impl_(NULL) {}
61
62 /// \brief Shutdown CORBA server
63 template <class T>
64 2 Server<T>::~Server() {
65 2 deactivateAndDestroyServers();
66 }
67
68 template <class T>
69 T& Server<T>::implementation() {
70 return *impl_;
71 }
72
73 template <class T>
74 1 bool Server<T>::initRootPOA(bool inMultiThread) {
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!ServerBase::initRootPOA(inMultiThread)) return false;
76
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (impl_ != NULL) return true;
78
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 poa_ = main_poa();
79
80 // create implementation
81 try {
82
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 impl_ = new T();
83
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 setServant(impl_->_this());
84 }
85 HPP_CORBA_CATCH("failed to create the server implementation", false);
86
87 // activate implementation
88 try {
89
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 servantId_ = poa_->activate_object(impl_);
90 }
91 HPP_CORBA_CATCH("failed to activate the server implementation", false);
92
93 1 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 1 void Server<T>::deactivateAndDestroyServers() {
121
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (impl_) {
122 try {
123
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 poa_->deactivate_object(servantId_);
124 } catch (const CORBA::OBJECT_NOT_EXIST& exc) {
125 // Servant was already deactivated and deleted.
126 }
127 }
128 1 }
129
130 } // end of namespace corba.
131 } // end of namespace hpp.
132
133 #endif // HPP_CORBA_TEMPLATE_SERVER_HXX
134