ProxyFactory.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00019 #ifndef DOIL_PROXYFACTORY_H
00020 #define DOIL_PROXYFACTORY_H
00021 
00022 #include <doil/ProxyBase.h>
00023 #include <doil/corba/CORBA.h>
00024 
00025 namespace doil
00026 {
00027   // Servant 生成・削除関数のtypedef
00028 //  typedef ImplBase* (*ProxyNewFunc)(::CORBA::Object_ptr obj);
00029 //  typedef void (*ProxyDeleteFunc)(ImplBase*);
00030   typedef ProxyBase* (*ProxyNewFunc)(::CORBA::Object_ptr obj);
00031   typedef void (*ProxyDeleteFunc)(ProxyBase*);
00032 
00033   // Servant 生成のためのテンプレート関数
00034   template <class Proxy>
00035   ProxyBase* New(::CORBA::Object_ptr obj)
00036   {
00037     return new Proxy(obj);
00038   }
00039 
00040   // Servant 削除のためのテンプレート関数
00041   template <class Proxy>
00042 //  void Delete(ImplBase* impl)
00043   void Delete(ProxyBase* impl)
00044   {
00045     if (impl != NULL)
00046       {
00047         delete impl;
00048         impl = NULL;
00049       }
00050   }
00051 
00052   class ProxyFactoryBase
00053   {
00054   public:
00055     virtual ~ProxyFactoryBase(){}
00056     virtual const char* name() = 0;
00057     virtual ProxyBase* create() = 0;
00058 //    virtual void destroy(ImplBase* impl) = 0;
00059     virtual void destroy(ProxyBase* impl) = 0;
00060   };
00061 
00062 
00063   class ProxyFactory
00064   //    : public ServantFactoryBase
00065   {
00066   public:
00067     ProxyFactory(const char* id, 
00068                    ProxyNewFunc new_func,
00069                    ProxyDeleteFunc delete_func)
00070       : m_id(id), m_new(new_func), m_delete(delete_func)
00071     {
00072     }
00073 
00074     /*
00075     ServantFactory(const ServantFactory& sf)
00076     {
00077       m_name   = sf.m_name;
00078       m_new    = sf.m_new;
00079       m_delete = sf.m_delete;
00080     }
00081 
00082     ServantFactory& operator=(ServantFactory& sf)
00083     {
00084       ServantFactory tmp(sf);
00085       std::swap(*this, tmp);
00086       return *this;
00087     }
00088     */
00089     virtual ~ProxyFactory(){};
00090 
00091     virtual const char* id()
00092     {
00093       return m_id.c_str();
00094     }
00095     virtual ProxyBase* create(::CORBA::Object_ptr obj)
00096     {
00097       return m_new(obj);
00098     }
00099 //    virtual void destroy(ImplBase* impl)
00100     virtual void destroy(ProxyBase* impl)
00101     {
00102       m_delete(impl);
00103     }
00104   private:
00105     std::string m_id;
00106     ProxyNewFunc m_new;
00107     ProxyDeleteFunc m_delete;
00108   };
00109 
00110 
00111 };
00112 #endif // DOIL_SERVANTFACTORY_H
00113 


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