| 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_SERVER_HH | ||
| 12 | #define HPP_CORBA_SERVER_HH | ||
| 13 | |||
| 14 | #include <omniORB4/CORBA.h> | ||
| 15 | |||
| 16 | #include <string> | ||
| 17 | |||
| 18 | namespace hpp { | ||
| 19 | namespace corba { | ||
| 20 | class ServerBase { | ||
| 21 | public: | ||
| 22 | /** | ||
| 23 | \brief Constructor | ||
| 24 | \param argc, argv parameter to feed ORB initialization. | ||
| 25 | |||
| 26 | \note It is recommended to configure your Corba implementation through | ||
| 27 | environment variables and to set argc to 1 and argv to any string. | ||
| 28 | */ | ||
| 29 | ServerBase(int argc, const char* argv[], const char* orb_identifier = "", | ||
| 30 | const char* options[][2] = 0); | ||
| 31 | |||
| 32 | /** | ||
| 33 | \name CORBA server initialization | ||
| 34 | \{ | ||
| 35 | */ | ||
| 36 | /** Initialize ORB. | ||
| 37 | * This is called by the constructor of this class and should not be | ||
| 38 | * called manually. | ||
| 39 | */ | ||
| 40 | bool initORB(int argc, const char* argv[], const char* orb_identifier, | ||
| 41 | const char* options[][2]); | ||
| 42 | bool initRootPOA(bool inMultiThread); | ||
| 43 | bool initOmniINSPOA(); | ||
| 44 | /** | ||
| 45 | \} | ||
| 46 | */ | ||
| 47 | |||
| 48 | /// \brief Shutdown CORBA server | ||
| 49 | virtual ~ServerBase(); | ||
| 50 | |||
| 51 | /// \brief Initialize CORBA server to process requests from clients and | ||
| 52 | /// declare it to the NameService (DNS for CORBA) | ||
| 53 | /// \param contextId first part of context name | ||
| 54 | /// \param contextKind second part of context name | ||
| 55 | /// \param objectId first part of CORBA server name | ||
| 56 | /// \param objectKind second part of CORBA server name | ||
| 57 | /// \return 0 if success, -1 if failure. | ||
| 58 | /// | ||
| 59 | /// The CORBA server is referenced in the name server by context and | ||
| 60 | /// name: contextId.contextKind/objectId.objectKind. | ||
| 61 | /// The context can be seen as a directory and the object as a filename. | ||
| 62 | int startCorbaServer(const std::string& contextId, | ||
| 63 | const std::string& contextKind, | ||
| 64 | const std::string& objectId, | ||
| 65 | const std::string& objectKind); | ||
| 66 | |||
| 67 | /// \brief Initialize CORBA server to process requests from clients and | ||
| 68 | /// declare it to the NameService (DNS for CORBA) | ||
| 69 | /// \param contextId first part of context name | ||
| 70 | /// \param contextKind second part of context name | ||
| 71 | /// \return 0 if success, -1 if failure. | ||
| 72 | /// | ||
| 73 | /// The CORBA server is referenced in the name server by context and | ||
| 74 | /// name: contextId.contextKind. | ||
| 75 | int startCorbaServer(const std::string& contextId, | ||
| 76 | const std::string& contextKind); | ||
| 77 | |||
| 78 | /// \brief Initialize CORBA server to process requests from clients | ||
| 79 | int startCorbaServer(); | ||
| 80 | |||
| 81 | /// \brief If ORB work is pending, process it | ||
| 82 | /// \param loop if true, the function never returns; if false, the function | ||
| 83 | /// processes pending requests and returns. | ||
| 84 | int processRequest(bool loop); | ||
| 85 | |||
| 86 | 1 | PortableServer::POA_var main_poa() { return main_poa_; } | |
| 87 | |||
| 88 | /// The Portable Object Adapter used to active the server | ||
| 89 | 1 | PortableServer::POA_var poa() { return poa_; } | |
| 90 | |||
| 91 | CORBA::ORB_var orb() { return orb_; } | ||
| 92 | |||
| 93 | protected: | ||
| 94 | CORBA::ORB_var orb_; | ||
| 95 | PortableServer::POA_var poa_, main_poa_, ins_poa_; | ||
| 96 | |||
| 97 | /// \brief Corba context. | ||
| 98 | CosNaming::NamingContext_var hppContext_; | ||
| 99 | |||
| 100 | void setServant(CORBA::Object_ptr obj); | ||
| 101 | |||
| 102 | private: | ||
| 103 | /// \brief Implementation of object | ||
| 104 | CORBA::Object_var servant_; | ||
| 105 | |||
| 106 | /// \brief Create context. | ||
| 107 | bool createHppContext(const std::string& id, const std::string kind); | ||
| 108 | |||
| 109 | /// \brief Store objects in Corba name service. | ||
| 110 | bool bindObjectToName(CORBA::Object_ptr objref, CosNaming::Name objectName); | ||
| 111 | |||
| 112 | /// \brief Store objects in Corba name service. | ||
| 113 | bool bindObjectToName(CosNaming::NamingContext_ptr context, | ||
| 114 | CORBA::Object_ptr objref, CosNaming::Name objectName); | ||
| 115 | }; | ||
| 116 | |||
| 117 | /** | ||
| 118 | \brief Template CORBA server | ||
| 119 | |||
| 120 | For information on how to use see the \ref hpp_template_corba_sec_how_to | ||
| 121 | section of the main documentation page | ||
| 122 | */ | ||
| 123 | template <class T> | ||
| 124 | class Server : public ServerBase { | ||
| 125 | public: | ||
| 126 | /** | ||
| 127 | \brief Constructor | ||
| 128 | \param argc, argv parameter to feed ORB initialization. | ||
| 129 | |||
| 130 | \note It is recommended to configure your Corba implementation through | ||
| 131 | environment variables and to set argc to 1 and argv to any string. | ||
| 132 | */ | ||
| 133 | Server(int argc, const char* argv[], const char* orb_identifier = "", | ||
| 134 | const char* options[][2] = 0); | ||
| 135 | |||
| 136 | /** | ||
| 137 | \name CORBA server initialization | ||
| 138 | \{ | ||
| 139 | */ | ||
| 140 | /** Initialize a root POA | ||
| 141 | * This is suitable for multithreading and for using a name service. | ||
| 142 | * \param inMultiThread whether the server may process request using | ||
| 143 | * multithread policy. | ||
| 144 | */ | ||
| 145 | bool initRootPOA(bool inMultiThread); | ||
| 146 | /** Initialize a root POA | ||
| 147 | * This cannot be multithreaded. It is suitable to serve an object at a | ||
| 148 | * fixed address. The address can be set using the ORB endPoint option. | ||
| 149 | * \param object_id the object name, use in the address | ||
| 150 | * (corbaloc:iiop:host:port/object_id) | ||
| 151 | */ | ||
| 152 | bool initOmniINSPOA(const char* object_id); | ||
| 153 | /** | ||
| 154 | \} | ||
| 155 | */ | ||
| 156 | |||
| 157 | /// \brief Shutdown CORBA server | ||
| 158 | ~Server(); | ||
| 159 | |||
| 160 | /// \brief Return a reference to the implementation | ||
| 161 | T& implementation(); | ||
| 162 | |||
| 163 | private: | ||
| 164 | T* impl_; | ||
| 165 | |||
| 166 | /// \brief It seems that we need to store this object to | ||
| 167 | /// deactivate the server. | ||
| 168 | PortableServer::ObjectId_var servantId_; | ||
| 169 | |||
| 170 | /// \brief Corba context. | ||
| 171 | CosNaming::NamingContext_var hppContext_; | ||
| 172 | |||
| 173 | /// \brief Create context. | ||
| 174 | bool createHppContext(const std::string& id, const std::string kind); | ||
| 175 | |||
| 176 | /// \brief Store objects in Corba name service. | ||
| 177 | bool bindObjectToName(CORBA::Object_ptr objref, CosNaming::Name objectName); | ||
| 178 | |||
| 179 | /// \brief Store objects in Corba name service. | ||
| 180 | bool bindObjectToName(CosNaming::NamingContext_ptr context, | ||
| 181 | CORBA::Object_ptr objref, CosNaming::Name objectName); | ||
| 182 | |||
| 183 | /// \brief Deactivate and destroy servers | ||
| 184 | /// | ||
| 185 | /// Destroying active servers raises a Corba exception. | ||
| 186 | void deactivateAndDestroyServers(); | ||
| 187 | }; | ||
| 188 | |||
| 189 | } // end of namespace corba. | ||
| 190 | } // end of namespace hpp. | ||
| 191 | |||
| 192 | #include "hpp/corba/template/server.hxx" | ||
| 193 | #endif | ||
| 194 |