CorbaConsumer.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef RTC_CORBACONSUMER_H
00021 #define RTC_CORBACONSUMER_H
00022 
00023 #include <iostream>
00024 #ifdef ORB_IS_MICO
00025 #include <CORBA.h>
00026 #endif
00027 #ifdef ORB_IS_OMNIORB
00028 #ifdef WIN32
00029 #pragma warning( disable : 4267 )
00030 #pragma warning( disable : 4290 )
00031 #pragma warning( disable : 4311 )
00032 #pragma warning( disable : 4312 )
00033 #endif // WIN32
00034 #include <omniORB4/CORBA.h>
00035 #ifdef WIN32
00036 #pragma warning( default : 4267 )
00037 #pragma warning( default : 4290 )
00038 #pragma warning( default : 4311 )
00039 #pragma warning( default : 4312 )
00040 #endif // WIN32
00041 #endif
00042 #ifdef ORB_IS_ORBACUS
00043 #include <OB/CORBA.h>
00044 #endif
00045 #ifdef ORB_IS_ORBIT2
00046 #include <orbitcpp/orb-cpp/orbitcpp.h>
00047 #endif
00048 #ifdef ORB_IS_ORBIX
00049 #include <CORBA.h>
00050 #endif
00051 #ifdef ORB_IS_TAO
00052 #include <tao/corba.h>
00053 #endif
00054 
00069 namespace RTC
00070 {
00094   class CorbaConsumerBase
00095   {
00096   public:
00108     CorbaConsumerBase(){};
00109     
00125     CorbaConsumerBase(const CorbaConsumerBase& x)
00126       : m_objref(CORBA::Object::_duplicate(x.m_objref))
00127     {
00128     }
00129     
00149     CorbaConsumerBase& operator=(const CorbaConsumerBase& x)
00150     {
00151       CorbaConsumerBase tmp(x);
00152       tmp.swap(*this);
00153       return *this;
00154     }
00155 
00171     void swap(CorbaConsumerBase& x)
00172     {
00173       CORBA::Object_var tmpref = x.m_objref;
00174       x.m_objref = this->m_objref;
00175       this->m_objref = tmpref;
00176     }
00177     
00189     virtual ~CorbaConsumerBase(void)
00190     {
00191       releaseObject();
00192     };
00193     
00221     virtual bool setObject(CORBA::Object_ptr obj)
00222     {
00223       if (CORBA::is_nil(obj))
00224         {
00225           return false;
00226         }
00227       m_objref = CORBA::Object::_duplicate(obj);
00228       return true;
00229     }
00230     
00254     virtual CORBA::Object_ptr getObject()
00255     {
00256       return m_objref;
00257     }
00258     
00276     virtual void releaseObject()
00277     {
00278       m_objref = CORBA::Object::_nil();
00279     }
00280     
00281   protected:
00289     CORBA::Object_var m_objref;
00290   };
00291   
00335   template <class ObjectType,
00336             typename ObjectTypePtr = typename ObjectType::_ptr_type,
00337             typename ObjectTypeVar = typename ObjectType::_var_type>
00338   class CorbaConsumer
00339     : public CorbaConsumerBase
00340   {
00341   public:
00353     CorbaConsumer(){};
00354     
00370     CorbaConsumer(const CorbaConsumer& x)
00371       : m_var(ObjectType::_duplicate(x.m_var))
00372     {
00373     }
00374     
00394     CorbaConsumer& operator=(const CorbaConsumer& x)
00395     {
00396       CorbaConsumer tmp(x);
00397       tmp.swap(*this);
00398       return *this;
00399     }
00400 
00401     void swap(CorbaConsumer& x)
00402     {
00403       CorbaConsumerBase::swap(x);
00404       ObjectTypeVar tmpref = x.m_var;
00405       x.m_var = this->m_var;
00406       this->m_var = tmpref;
00407       
00408     }
00409     
00421     virtual ~CorbaConsumer(void)
00422     {
00423       releaseObject();
00424     };
00425     
00454     virtual bool setObject(CORBA::Object_ptr obj)
00455     {
00456       if (!CorbaConsumerBase::setObject(obj))
00457         {
00458           releaseObject();
00459           return false; // object is nil
00460         }
00461 
00462       ObjectTypeVar var = ObjectType::_narrow(m_objref);
00463  
00464       if (CORBA::is_nil(var))
00465         {
00466           releaseObject();
00467           return false;
00468         }
00469 
00470       m_var = var;
00471       return true;
00472     }
00473 
00498     inline ObjectTypePtr _ptr()
00499     {
00500       return m_var.inout();
00501     }
00502     
00527     inline ObjectTypePtr operator->()
00528     {
00529       return m_var.inout();
00530     }
00531     
00549     virtual void releaseObject()
00550     {
00551       CorbaConsumerBase::releaseObject();
00552       m_var = ObjectType::_nil();
00553     }
00554     
00555   protected:
00563     ObjectTypeVar m_var;
00564   };
00565 }; // namespace RTC
00566 #endif // RTC_CORBACONSUMER_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:03