SdoOrganization.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #include <coil/UUID.h> 
00021 #include <rtm/SdoOrganization.h>
00022 #include <rtm/CORBA_SeqUtil.h>
00023 #include <memory>
00024 #include <iostream>
00025 
00026 namespace SDOPackage
00027 {
00028   /* @if jp
00029    * @brief コンストラクタ
00030    * @else
00031    * @brief Constructor
00032    * @endif
00033    */
00034 #ifdef ORB_IS_RTORB
00035   Organization_impl::Organization_impl(RTC::RTObject_ptr sdo)
00036     : rtclog("organization")
00037   {
00038     m_varOwner = sdo.in();
00039 
00040     coil::UUID_Generator uugen;
00041     uugen.init();
00042     std::auto_ptr<coil::UUID> uuid(uugen.generateUUID(2,0x01));
00043     m_pId = uuid->to_string();
00044 #ifdef WIN32
00045     uuid->~UUID();
00046 #endif // WIN32
00047     m_dependency = OWN;
00048     m_objref = this->_this();
00049   }
00050 #endif // ORB_IS_RTORB
00051 
00052   Organization_impl::Organization_impl(SDOSystemElement_ptr sdo)
00053     : rtclog("organization"), m_varOwner(SDOSystemElement::_duplicate(sdo))
00054   {
00055     coil::UUID_Generator uugen;
00056     uugen.init();
00057     std::auto_ptr<coil::UUID> uuid(uugen.generateUUID(2,0x01));
00058     m_pId = uuid->to_string();
00059 #ifdef WIN32
00060     uuid->~UUID();
00061 #endif // WIN32
00062     m_dependency = OWN;
00063     m_objref = this->_this();
00064   }
00065   
00066   /* @if jp
00067    * @brief 仮想デストラクタ
00068    * @else
00069    * @brief Virtual destructor
00070    * @endif
00071    */
00072   Organization_impl::~Organization_impl()
00073   {
00074   }
00075   
00083   char* Organization_impl::get_organization_id()
00084     throw (CORBA::SystemException,
00085            InvalidParameter, NotAvailable, InternalError)
00086   {
00087     RTC_TRACE(("get_organization_id() = %s", m_pId.c_str()));
00088     return CORBA::string_dup(m_pId.c_str());
00089   }
00090   
00098   OrganizationProperty* Organization_impl::get_organization_property()
00099     throw (CORBA::SystemException,
00100            NotAvailable, InternalError)
00101   {
00102     RTC_TRACE(("get_organization_property()"));
00103     Guard guard(m_org_mutex);
00104     OrganizationProperty_var prop;
00105     prop = new OrganizationProperty(m_orgProperty);
00106     return prop._retn();
00107   }
00108   
00116   CORBA::Any*
00117   Organization_impl::get_organization_property_value(const char* name)
00118     throw (CORBA::SystemException,
00119            InvalidParameter, NotAvailable, InternalError)
00120   {
00121     RTC_TRACE(("get_organization_property_value(%s)", name));
00122     if (std::string(name).empty())
00123       throw InvalidParameter("Empty name.");
00124     
00125     CORBA::Long index;
00126     index = CORBA_SeqUtil::find(m_orgProperty.properties, nv_name(name));
00127     
00128     if (index < 0)
00129       throw InvalidParameter("Not found.");
00130     
00131     try
00132       {
00133         CORBA::Any_var value;
00134         value = new CORBA::Any(m_orgProperty.properties[index].value);
00135         return value._retn();
00136       }
00137     catch (...)
00138       {
00139         throw InternalError("get_organization_property_value()");
00140       }
00141     // never reach here
00142     return new CORBA::Any();
00143   }
00144   
00152   CORBA::Boolean
00153   Organization_impl::
00154   add_organization_property(const OrganizationProperty& organization_property)
00155     throw (CORBA::SystemException,
00156            InvalidParameter, NotAvailable, InternalError)
00157   {
00158     RTC_TRACE(("add_organization_property()"));
00159     try
00160       {
00161         Guard guard(m_org_mutex);
00162         m_orgProperty = organization_property;
00163         return true;
00164       }
00165     catch (...)
00166       {
00167         throw InternalError("set_organization_property()");
00168       }
00169     return false;
00170   }
00171   
00179   CORBA::Boolean
00180   Organization_impl::set_organization_property_value(const char* name,
00181                                                      const CORBA::Any& value)
00182     throw (CORBA::SystemException,
00183            InvalidParameter, NotAvailable, InternalError)
00184   {
00185     RTC_TRACE(("set_organization_property_value(name=%s)", name));
00186     if (std::string(name).empty())
00187       {
00188         throw InvalidParameter("set_organization_property_value(): Enpty name.");
00189       }
00190     
00191     CORBA::Long index;
00192     index = CORBA_SeqUtil::find(m_orgProperty.properties,nv_name(name));
00193     if (index < 0)
00194       {
00195         NameValue nv;
00196         nv.name = CORBA::string_dup(name);
00197         nv.value = value;
00198         CORBA_SeqUtil::push_back(m_orgProperty.properties, nv);
00199       }
00200     else
00201       {
00202         m_orgProperty.properties[index].value = value;
00203       }
00204     return true;
00205   }
00206   
00214   CORBA::Boolean
00215   Organization_impl::remove_organization_property(const char* name)
00216     throw (CORBA::SystemException,
00217            InvalidParameter, NotAvailable, InternalError)
00218   {
00219     RTC_TRACE(("remove_organization_property(%s)", name));
00220     if (std::string(name).empty())
00221       throw InvalidParameter("remove_organization_property(): Enpty name.");
00222     
00223     CORBA::Long index;
00224     index = CORBA_SeqUtil::find(m_orgProperty.properties,nv_name(name));
00225     if (index < 0)
00226       throw InvalidParameter("remove_organization_property(): Not found.");
00227     
00228     try
00229       {
00230         CORBA_SeqUtil::erase(m_orgProperty.properties, index);
00231         return true;
00232       }
00233     catch (...)
00234       {
00235         throw InternalError("remove_organization_property()");
00236       }
00237     return false;
00238   }
00239   
00247   SDOSystemElement_ptr Organization_impl::get_owner()
00248     throw (CORBA::SystemException,
00249            NotAvailable, InternalError)
00250   {
00251     RTC_TRACE(("get_owner()"));
00252     return m_varOwner._retn();
00253   }
00254   
00262   CORBA::Boolean Organization_impl::set_owner(SDOSystemElement_ptr sdo)
00263     throw (CORBA::SystemException,
00264            InvalidParameter, NotAvailable, InternalError)
00265   {
00266     RTC_TRACE(("set_owner()"));
00267     if (CORBA::is_nil(sdo))
00268       throw InvalidParameter("set_owner()");
00269     try
00270       {
00271         m_varOwner = SDOSystemElement::_duplicate(sdo);
00272         return true;
00273       }
00274     catch (...)
00275       {
00276         throw InternalError("set_owner()");
00277       }
00278     return true;
00279   }
00280   
00288   SDOList* Organization_impl::get_members()
00289     throw (CORBA::SystemException,
00290            NotAvailable, InternalError)
00291   {
00292     RTC_TRACE(("get_members()"));
00293     try
00294       {
00295         SDOList_var sdos;
00296         sdos = new SDOList(m_memberList);
00297         return sdos._retn();
00298       }
00299     catch (...)
00300       {
00301         throw InternalError("get_members()");
00302       }
00303   }
00304   
00312   CORBA::Boolean Organization_impl::set_members(const SDOList& sdos)
00313     throw (CORBA::SystemException,
00314            InvalidParameter, NotAvailable, InternalError)
00315   {
00316     RTC_TRACE(("set_members()"));
00317     if (sdos.length() < 0)
00318       throw InvalidParameter("set_members(): number of SDOList is invalid.");
00319     try
00320       {
00321         m_memberList = sdos;
00322         return true;
00323       }
00324     catch (...)
00325       {
00326         throw InternalError("set_members()");
00327       }
00328     return true;
00329   }
00330   
00338   CORBA::Boolean Organization_impl::add_members(const SDOList& sdo_list)
00339     throw (CORBA::SystemException,
00340            InvalidParameter, NotAvailable, InternalError)
00341   {
00342     RTC_TRACE(("add_members()"));
00343     if (sdo_list.length() < 0)
00344       throw InvalidParameter("set_members(): number of SDOList is invalid.");
00345     try
00346       {
00347         if (sdo_list.length() == 0) return true;
00348         CORBA_SeqUtil::push_back_list(m_memberList, sdo_list);
00349         return true;
00350       }
00351     catch (...)
00352       {
00353         throw InternalError("add_members()");
00354       }
00355     return false;       
00356   }
00357   
00365   CORBA::Boolean Organization_impl::remove_member(const char* id)
00366     throw (CORBA::SystemException,
00367            InvalidParameter, NotAvailable, InternalError)
00368   {
00369     RTC_TRACE(("remove_member(%s)", id));
00370 
00371     if (std::string(id).empty())
00372       {
00373         RTC_ERROR(("remove_member(): Enpty name."));
00374         throw InvalidParameter("remove_member(): Enpty name.");
00375       }
00376     
00377     CORBA::Long index;
00378     index = CORBA_SeqUtil::find(m_memberList, sdo_id(id));
00379     
00380     if (index < 0)
00381       {
00382         RTC_ERROR(("remove_member(): Not found."));
00383         throw InvalidParameter("remove_member(): Not found.");
00384       }
00385     
00386     try
00387       {
00388         CORBA_SeqUtil::erase(m_memberList, index);
00389         return true;
00390       }
00391     catch (...)
00392       {
00393         RTC_ERROR(("unknown exception"));
00394         throw InternalError("remove_member(): Not found.");
00395       }
00396     return false;
00397   }
00398   
00406   DependencyType Organization_impl::get_dependency()
00407     throw (CORBA::SystemException,
00408            NotAvailable, InternalError)
00409   {
00410     RTC_TRACE(("get_dependency()"));
00411     return m_dependency;
00412   }
00413   
00421   CORBA::Boolean Organization_impl::set_dependency(DependencyType dependency)
00422     throw (CORBA::SystemException,
00423            NotAvailable, InternalError)
00424   {
00425     RTC_TRACE(("set_dependency()"));
00426     try
00427       {
00428         m_dependency = dependency;
00429         return true;
00430       }
00431     catch (...)
00432       {
00433         throw InternalError("set_dependency(): Unknown.");
00434       }
00435     return false;
00436   }
00437 };


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:39