11 #ifndef HPP_CORBASERVER_SERVANT_BASE_HH 12 # define HPP_CORBASERVER_SERVANT_BASE_HH 14 # include <boost/type.hpp> 16 # include <hpp/common-idl.hh> 54 #define SERVANT_BASE_TYPEDEFS(idlObj, hppObj) \ 56 using AbstractServantBase<hppObj>::server_; \ 59 typedef _Storage Storage; \ 60 typedef idlObj Object; \ 61 typedef idlObj ## _ptr Object_ptr; \ 62 typedef idlObj ## _var Object_var; \ 63 typedef ServantBase<hppObj, _Storage> _ServantBase; \ 64 using _ServantBase::get; \ 65 using _ServantBase::getT; \ 66 using _ServantBase::getS 87 virtual TShPtr_t
get()
const = 0;
111 virtual TShPtr_t
get ()
const 113 TWkPtr_t wk ((StorageElementWkPtr_t) s);
121 StorageElementShPtr_t
getT ()
const 123 StorageElementWkPtr_t wk ((StorageElementWkPtr_t) s);
139 if (persistant) p_ =
get();
151 persistantStorage(
false);
154 PortableServer::Servant servant =
dynamic_cast<PortableServer::Servant
>(
this);
156 throw Error (
"The object was deleted. I could not delete the servant.");
157 this->server_->removeServant (servant);
159 PortableServer::ObjectId_var objectId
160 = this->server_->poa()->servant_to_id(servant);
161 this->server_->poa()->deactivate_object(objectId.in());
168 persistantStorage (
true);
174 void objectExpired ()
const 177 PortableServer::Servant servant =
dynamic_cast<PortableServer::Servant
>(
const_cast<ServantBase*
>(
this));
179 throw Error (
"The object was deleted. I could not delete the servant.");
180 this->server_->removeServant (servant);
182 PortableServer::ObjectId_var objectId
183 = this->server_->poa()->servant_to_id(servant);
184 this->server_->poa()->deactivate_object(objectId.in());
185 throw Error (
"The object has been deleted. I delete the servant.");
214 operator boost::shared_ptr<T > ()
const {
return element.lock(); }
215 operator boost::weak_ptr <T > ()
const {
return element; }
220 operator bool ()
const {
return use_count()>0; }
227 PortableServer::Servant s = server->
poa()->reference_to_servant(p);
228 if (s == NULL)
throw Error (
"The servant is not located here");
229 return dynamic_cast<S*
> (s);
234 ServantBase_var s = server->
poa()->reference_to_servant(p);
235 if (s.in() == NULL)
throw Error (
"The servant is not located here");
250 S* servant =
dynamic_cast<S*
> (server->
getServant (servantKey));
251 if (servant != NULL) {
253 return servant->_this();
256 PortableServer::Servant_var<S>
d (s);
258 PortableServer::ObjectId_var servantId = server->
poa()->activate_object(d);
269 template <
typename U,
typename V,
template<
typename>
class StorageTpl>
270 struct storage_cast_impl {
271 static StorageTpl<U> run (
const StorageTpl<V>&
o) {
272 return o.template cast<U>();
277 template <
typename U,
typename V>
278 struct storage_cast_impl<U, V, boost::shared_ptr> {
279 static boost::shared_ptr<U> run (
const boost::shared_ptr<V>&
o) {
280 return boost::dynamic_pointer_cast<U>(
o);
285 template <
typename U,
typename V>
286 struct storage_cast_impl<U, V, boost::weak_ptr> {
287 static boost::weak_ptr<U> run (
const boost::weak_ptr<V>&
o) {
288 return boost::dynamic_pointer_cast<U>(o.lock());
295 template <
typename U,
typename V,
template<
typename>
class StorageTpl>
296 static StorageTpl<U> storage_cast(
const StorageTpl<V>&
o)
298 return details::storage_cast_impl<U, V, StorageTpl>::run (o);
304 template <
typename ServantBaseType>
308 typedef typename ServantBaseType::Storage
Storage;
313 virtual Object_var servant (
Server* server,
const Storage& obj) = 0;
326 template <
typename ServantBaseType,
typename ServantType>
337 typedef typename ServantType::Storage
Storage;
338 Storage u = storage_cast<
typename Storage::element_type>(
o);
340 if (u.use_count()>0) ret = makeServant <Object_var> (s,
new ServantType (s, u));
345 template <
typename ServantBaseType>
346 std::vector< ServantFactoryBase<ServantBaseType>* >&
objectDowncasts ();
348 template <
typename ServantBaseType>
351 typedef std::vector< ServantFactoryBase<ServantBaseType>* >
vector_t;
352 typedef typename vector_t::iterator iterator;
354 vector_t& vec = objectDowncasts<ServantBaseType>();
356 for (iterator _obj = vec.begin(); _obj != vec.end(); ++_obj) {
357 if (d >= (*_obj)->depth()) {
358 vec.insert(_obj,
object);
362 vec.push_back(
object);
367 template <
typename ServantBaseType,
typename ReturnType>
370 typedef typename ServantBaseType::Object_var BaseObject_var;
371 typedef typename ReturnType::Object_var Object_var;
372 BaseObject_var servant;
373 assert (CORBA::Object_Helper::is_nil(servant.in()));
375 typedef std::vector< ServantFactoryBase<ServantBaseType>* >
vector_t;
376 typedef typename vector_t::iterator iterator;
378 vector_t& vec = objectDowncasts<ServantBaseType>();
379 for (iterator _obj = vec.begin(); _obj != vec.end(); ++_obj) {
380 servant = (*_obj)->servant(server, t);
381 if (!CORBA::Object_Helper::is_nil(servant.in())) {
383 return Object_var (ReturnType::Object::_narrow (servant._retn()));
389 template <
typename ServantBaseType>
394 typedef typename ServantBaseType::Object_var Object_var;
396 assert (CORBA::Object_Helper::is_nil(servant.in()));
398 typedef std::vector< ServantFactoryBase<ServantBaseType>* >
vector_t;
399 typedef typename vector_t::iterator iterator;
401 vector_t& vec = objectDowncasts<ServantBaseType>();
402 for (iterator _obj = vec.begin(); _obj != vec.end(); ++_obj) {
403 servant = (*_obj)->servant(server, t);
404 if (!CORBA::Object_Helper::is_nil(servant.in()))
break;
410 template <
typename OutType,
typename InnerBaseType,
typename InnerType = InnerBaseType>
417 template <
typename InContainer>
418 inline OutType* operator() (
const InContainer& input)
421 OutType* seq =
new OutType ();
422 seq->length ((CORBA::ULong) len);
425 typename InContainer::const_iterator it = input.begin();
426 while (it != input.end()) {
427 (*seq)[i] = makeServantDownCast<InnerBaseType, InnerType> (s, *it)._retn();
447 #define HPP_CORBASERVER_ADD_DOWNCAST_OBJECT(ServantType, BaseServantType, depth) \ 448 struct HPP_CORE_DLLAPI __InitializerClass_##ServantType { \ 449 __InitializerClass_##ServantType () { \ 450 ::hpp::corbaServer::addDowncastObjects<BaseServantType> \ 451 ( new ::hpp::corbaServer::ServantFactory<BaseServantType, ServantType> (depth)); \ 454 HPP_CORBASERVER_DLLLOCAL __InitializerClass_##ServantType __instance_##ServantType; 456 #endif // HPP_CORBASERVER_SERVANT_BASE_HH Definition: servant-base.hh:100
PortableServer::Servant_var< PortableServer::ServantBase > ServantBase_var
Definition: servant-base.hh:223
boost::shared_ptr< T > TShPtr_t
Definition: servant-base.hh:84
std::vector< ServantFactoryBase< ServantBaseType > *> & objectDowncasts()
ServantFactory(const size_type &depth)
Definition: servant-base.hh:332
boost::shared_ptr< typename Storage::element_type > StorageElementShPtr_t
Definition: servant-base.hh:107
Definition: servant-base.hh:327
ServantBaseType::Object_var Object_var
Definition: servant-base.hh:309
Implement CORBA interface ``Obstacle''.
AbstractServantBase(Server *server)
Definition: servant-base.hh:95
AbstractServantBase< T > * reference_to_servant_base(Server *server, const P &p)
Definition: servant-base.hh:232
unsigned long long size_t
Definition: paths.idl:18
boost::weak_ptr< T > ptr_t
Definition: servant-base.hh:209
T element_type
Definition: servant-base.hh:219
ptr_t element
Definition: servant-base.hh:211
size_type depth() const
Definition: servant-base.hh:318
Abstract class used to avoid duplication of the servants.
Definition: servant-base.hh:69
PortableServer::Servant_var< S > reference_to_servant(Server *server, const P &p)
Definition: servant-base.hh:225
void addServantKeyAndServant(ServantKey servantKey, PortableServer::Servant servant)
boost::weak_ptr< typename Storage::element_type > StorageElementWkPtr_t
Definition: servant-base.hh:106
Server * server_
Definition: servant-base.hh:97
Corba exception travelling through the Corba channel.
Definition: common.idl:24
Definition: servant-base.hh:206
bool persistantStorage() const
See persistantStorage(bool)
Definition: servant-base.hh:144
Definition: servant-base.hh:305
void addDowncastObjects(ServantFactoryBase< ServantBaseType > *const object)
Definition: servant-base.hh:349
virtual Server::ServantKey getServantKey() const =0
pinocchio::vector_t vector_t
Definition: fwd.hh:83
const Storage & getS() const
Definition: servant-base.hh:131
ReturnType::Object_var makeServantDownCast(Server *server, const typename ServantBaseType::Storage &t)
Definition: servant-base.hh:368
assert(d.lhs()._blocks()==d.rhs()._blocks())
PortableServer::POA_var poa()
Definition: server.hh:88
ServantBase(Server *server, const Storage &_s)
Definition: servant-base.hh:165
P makeServant(Server *server, S *s)
Definition: servant-base.hh:247
Storage s
Definition: servant-base.hh:171
AbstractStorage(const ptr_t &_element)
Definition: servant-base.hh:213
ServantBaseType::Object_var Object_var
Definition: servant-base.hh:329
virtual ~ServantBase()
Definition: servant-base.hh:109
vectorToSeqServant(Server *_s)
Definition: servant-base.hh:415
Definition: servant-base.hh:411
virtual Object_var servant(Server *s, const StorageBase &o)
Definition: servant-base.hh:335
ServantBaseType::Storage StorageBase
Definition: servant-base.hh:330
Implementation of Hpp module Corba server.
Definition: server.hh:54
virtual Server::ServantKey getServantKey() const
Definition: servant-base.hh:89
PortableServer::Servant getServant(ServantKey servantKey) const
Definition: servant-base.hh:79
void persistantStorage(bool persistant)
Set to true if the servant should take ownership of this object.
Definition: servant-base.hh:137
void * ServantKey
Definition: server.hh:146
boost::weak_ptr< T > TWkPtr_t
Definition: servant-base.hh:85
_Storage Storage
Definition: servant-base.hh:103
Server * s
Definition: servant-base.hh:413
StorageElementShPtr_t getT() const
Definition: servant-base.hh:121
void deleteThis()
Definition: servant-base.hh:149
ServantBaseType::Storage Storage
Definition: servant-base.hh:308
long use_count() const
Definition: servant-base.hh:216
pinocchio::size_type size_type
Definition: fwd.hh:86
FCL_REAL distance(const KDOP< N > &other, Vec3f *P=NULL, Vec3f *Q=NULL) const
virtual ~AbstractServantBase()
Definition: servant-base.hh:82
ServantFactoryBase(const size_type &depth)
Definition: servant-base.hh:311