Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions utils/openrtmNames/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if(POLICY CMP0144)
endif()

set(target openrtmNames)
set(targetDLL OpenrtmNamesPlugin)
project (${target}
VERSION ${RTM_VERSION}
LANGUAGES CXX)
Expand All @@ -20,14 +21,22 @@ if(WIN32)
add_definitions(-DRTM_SKEL_IMPORT_SYMBOL)
endif()

add_executable(${target} openrtmNames.cpp NamingContext.h NamingContext.cpp
BindingIterator.h BindingIterator.cpp ObjectBinding.h ObjectBinding.cpp
RTObjectBinding.h RTObjectBinding.cpp ManagerBinding.h ManagerBinding.cpp)
set(OPENRTMNAMES_FILES NamingContext.h NamingContext.cpp
BindingIterator.h BindingIterator.cpp ObjectBinding.h ObjectBinding.cpp
RTObjectBinding.h RTObjectBinding.cpp ManagerBinding.h ManagerBinding.cpp)

add_executable(${target} openrtmNames.cpp ${OPENRTMNAMES_FILES})
openrtm_common_set_compile_props(${target})
openrtm_set_link_props_shared(${target})
openrtm_include_rtm(${target})

add_library(${targetDLL} SHARED OpenrtmNamesPlugin.cpp OpenrtmNamesPlugin.h ${OPENRTMNAMES_FILES})
set_target_properties(${targetDLL} PROPERTIES PREFIX "")
openrtm_common_set_compile_props(${targetDLL})
openrtm_set_link_props_shared(${targetDLL})
openrtm_include_rtm(${targetDLL})


set(libs ${RTM_PROJECT_NAME} ${ORB_LIBRARIES} ${DATATYPE_FACTORIES})
if(CORBA STREQUAL "TAO")
if(VXWORKS)
Expand Down Expand Up @@ -59,6 +68,8 @@ endif(SSL_ENABLE)

target_link_libraries(${target} ${libs} ${RTM_LINKER_OPTION})

target_link_libraries(${targetDLL} ${libs} ${RTM_LINKER_OPTION})



if(VXWORKS)
Expand All @@ -74,11 +85,20 @@ if(WIN32)
ARCHIVE DESTINATION ${INSTALL_RTM_LIB_DIR}
RUNTIME DESTINATION ${INSTALL_RTM_LIB_DIR}
COMPONENT utils)
install(TARGETS ${targetDLL} LIBRARY DESTINATION ${INSTALL_RTM_EXT_DIR}/naming
ARCHIVE DESTINATION ${INSTALL_RTM_EXT_DIR}/naming
RUNTIME DESTINATION ${INSTALL_RTM_EXT_DIR}/naming
COMPONENT utils)
else(WIN32)
install(TARGETS ${target} LIBRARY DESTINATION ${INSTALL_RTM_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_RTM_LIB_DIR}
RUNTIME DESTINATION ${INSTALL_RTM_BIN_DIR}
COMPONENT utils)

install(TARGETS ${targetDLL} LIBRARY DESTINATION ${INSTALL_RTM_EXT_DIR}/naming
ARCHIVE DESTINATION ${INSTALL_RTM_EXT_DIR}/naming
RUNTIME DESTINATION ${INSTALL_RTM_EXT_DIR}/naming
COMPONENT utils)
endif(WIN32)

if(SSL_ENABLE)
Expand Down
142 changes: 142 additions & 0 deletions utils/openrtmNames/OpenrtmNamesPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// -*- C++ -*-
/*!
* @file OpenrtmNamesPlugin.cpp
* @brief OpenrtmNamesPlugin class
* @date $Date: 2025-10-17 03:08:03 $
* @author Nobuhiko Miyamoto <n-miyamoto@aist.go.jp>
*
* Copyright (C) 2025
* Nobuhiko Miyamoto
* Intelligent Systems Research Institute,
* National Institute of
* Advanced Industrial Science and Technology (AIST), Japan
*
* All rights reserved.
*
*
*/

#include "OpenrtmNamesPlugin.h"
#include <rtm/ManagerConfig.h>
#include <coil/stringutil.h>
#include <iostream>

namespace OpenRTMNames
{
ManagerActionListener::ManagerActionListener(RTC::Manager* manager)
{
m_manager = manager;
PortableServer::POA_var root_poa = manager->getPOA();
CORBA::ORB_var orb = manager->getORB();
#ifndef ORB_IS_TAO
PortableServer::POA_var ins_poa;
#else
IORTable::Table_var adapter;
#endif
try {
m_nameservice = new RTM::NamingContext(root_poa);
CosNaming::NamingContextExt_var nameserviceref = m_nameservice->_this();
CORBA::String_var sior(orb->object_to_string(nameserviceref));
std::cout << sior << std::endl;

#ifndef ORB_IS_TAO
CORBA::Object_var ins_obj = orb->resolve_initial_references("omniINSPOA");

ins_poa = PortableServer::POA::_narrow(ins_obj);
ins_poa->the_POAManager()->activate();

PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId("NameService");
ins_poa->activate_object_with_id(id.in(), m_nameservice);
#else
CORBA::Object_var obj = orb->resolve_initial_references("IORTable");
adapter = IORTable::Table::_narrow(obj.in());

CORBA::String_var ior = orb->object_to_string(nameservice->_this());
adapter->bind("NameService", ior.in());
#endif
}
catch (const CORBA::INITIALIZE& ex) {
#ifdef ORB_IS_OMNIORB
std::cerr << "Failed to initialise: " << ex.NP_minorString() << std::endl;
#elif defined(ORB_IS_TAO)
std::cerr << "Failed to initialise: " << ex.minor() << std::endl;
#endif
return;
}
catch (CORBA::SystemException& ex) {
std::cerr << "Caught CORBA::" << ex._name() << std::endl;
return;
}
catch (CORBA::Exception& ex) {
std::cerr << "Caught CORBA::Exception: " << ex._name() << std::endl;
return;
}


}
ManagerActionListener::~ManagerActionListener()
{

}
void ManagerActionListener::preShutdown()
{
m_nameservice->destroy();
PortableServer::POA_var root_poa = m_manager->getPOA();


PortableServer::ObjectId_var oid = root_poa->servant_to_id(m_nameservice);
root_poa->deactivate_object(oid);


#ifndef ORB_IS_TAO
CORBA::Object_var obj = m_manager->theORB()->resolve_initial_references("omniINSPOA");

PortableServer::POA_var ins_poa = PortableServer::POA::_narrow(obj);
PortableServer::ObjectId_var id;
id = ins_poa->servant_to_id(m_nameservice);

ins_poa->deactivate_object(id.in());
#else
CORBA::Object_var obj = m_manager.theORB()->resolve_initial_references("IORTable");
IORTable::Table_var adapter = IORTable::Table::_narrow(obj.in());


coil::Properties config(m_manager.getConfig());

adapter->unbind("NameService");
#endif

}
void ManagerActionListener::postShutdown()
{
}
void ManagerActionListener::postReinit()
{

}

void ManagerActionListener::preReinit()
{

}

}

extern "C"
{
/*!
* @if jp
* @brief モジュール初期化関数
* @else
* @brief Module initialization
* @endif
*/
void OpenrtmNamesPluginInit(RTC::Manager* manager)
{
OpenRTMNames::ManagerActionListener* listener = new OpenRTMNames::ManagerActionListener(manager);
manager->addManagerActionListener(listener);
}

}


62 changes: 62 additions & 0 deletions utils/openrtmNames/OpenrtmNamesPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// -*- C++ -*-
/*!
* @file OpenrtmNamesPlugin.h
* @brief OpenrtmNamesPlugin class
* @date $Date: 2025-10-17 03:08:03 $
* @author Nobuhiko Miyamoto <n-miyamoto@aist.go.jp>
*
* Copyright (C) 2018
* Nobuhiko Miyamoto
* Intelligent Systems Research Institute,
* National Institute of
* Advanced Industrial Science and Technology (AIST), Japan
*
* All rights reserved.
*
*
*/

#ifndef RTC_OPENRTMNAMESPLUGIN_H
#define RTC_OPENRTMNAMESPLUGIN_H

#include <rtm/RTC.h>
#include <rtm/Manager.h>
#include "NamingContext.h"

namespace OpenRTMNames
{
class ManagerActionListener : public RTM::ManagerActionListener
{
public:
ManagerActionListener(RTC::Manager* manager);
~ManagerActionListener() override;
void preShutdown() override;
void postShutdown() override;
void postReinit() override;
void preReinit() override;
private:
PortableServer::Servant_var<RTM::NamingContext> m_nameservice;
RTC::Manager* m_manager;
};
}

extern "C"
{
/*!
* @if jp
* @brief モジュール初期化関数
*
* ネーミングサービスの初期化関数。
*
* @else
* @brief Module initialization
*
*
*
* @endif
*/
DLL_EXPORT void OpenrtmNamesPluginInit(RTC::Manager* manager);
}

#endif // RTC_OPENRTMNAMESPLUGIN_H

Loading