20 #include <coil/UUID.h> 21 #include <coil/Guard.h> 22 #include <coil/stringutil.h> 60 : m_rtobj(rtobj), m_allConsumerEnabled(true),
61 rtclog(
"SdoServiceAdmin")
63 RTC_TRACE((
"SdoServiceAdmin::SdoServiceAdmin(%s)",
72 RTC_DEBUG((
"sdo.service.provider.enabled_services: %s",
73 prop[
"sdo.service.provider.enabled_services"].c_str()));
77 prop[
"sdo.service.provider.available_services"]
79 RTC_DEBUG((
"sdo.service.provider.available_services: %s",
80 prop[
"sdo.service.provider.available_services"].c_str()));
85 for (
size_t i(0); i < enabledProviderTypes.size(); ++i)
87 std::string tmp(enabledProviderTypes[i]);
91 activeProviderTypes = availableProviderTypes;
92 RTC_DEBUG((
"sdo.service.provider.enabled_services: ALL"));
95 for (
size_t j(0); j < availableProviderTypes.size(); ++j)
97 if (availableProviderTypes[j] == enabledProviderTypes[i])
99 activeProviderTypes.push_back(availableProviderTypes[j]);
105 for (
size_t i(0); i < activeProviderTypes.size(); ++i)
110 SDOPackage::ServiceProfile prof;
111 prof.id = CORBA::string_dup(activeProviderTypes[i].c_str());
112 prof.interface_type = CORBA::string_dup(activeProviderTypes[i].c_str());
113 prof.service = svc->_this();
114 std::string propkey =
ifrToKey(activeProviderTypes[i]);
116 prop.getNode(propkey.c_str()));
118 svc->
init(rtobj, prof);
126 ::std::string constypes =
prop[
"sdo.service.consumer.enabled_services"];
128 RTC_DEBUG((
"sdo.service.consumer.enabled_services: %s", constypes.c_str()));
130 prop[
"sdo.service.consumer.available_services"]
132 RTC_DEBUG((
"sdo.service.consumer.available_services: %s",
133 prop[
"sdo.service.consumer.available_services"].c_str()));
143 RTC_DEBUG((
"sdo.service.consumer.enabled_services: ALL"));
181 SDOPackage::ServiceProfileList_var prof
182 =
new SDOPackage::ServiceProfileList();
199 SDOPackage::ServiceProfile*
202 std::string idstr(
id);
206 if (idstr == static_cast<const char*>(
m_providers[i]->getProfile().
id))
208 return new SDOPackage::ServiceProfile(
m_providers[i]->getProfile());
211 throw new SDOPackage::InvalidParameter();
212 return new SDOPackage::ServiceProfile();
224 SDOPackage::ServiceProfile_var prof;
226 SDOPackage::SDOService_var sdo
227 = SDOPackage::SDOService::_duplicate(prof->service);
242 RTC_TRACE((
"SdoServiceAdmin::addSdoServiceProvider(if=%s)",
243 static_cast<const char*>(prof.interface_type)));
246 std::string
id(static_cast<const char*>(prof.id));
249 if (
id == static_cast<const char*>(
m_providers[i]->getProfile().
id))
251 RTC_ERROR((
"SDO service(id=%s, ifr=%s) already exists",
252 static_cast<const char*>(prof.id),
253 static_cast<const char*>(prof.interface_type)));
270 RTC_TRACE((
"removeSdoServiceProvider(%d)",
id));
273 std::string strid(
id);
274 std::vector<SdoServiceProviderBase*>::iterator it =
m_providers.begin();
275 std::vector<SdoServiceProviderBase*>::iterator it_end =
m_providers.end();
278 if (strid == static_cast<const char*>((*it)->getProfile().id))
285 RTC_INFO((
"SDO service provider has been deleted: %s",
id));
290 RTC_WARN((
"Specified SDO service provider not found: %s",
id));
305 RTC_TRACE((
"addSdoServiceConsumer(IFR = %s)",
306 static_cast<const char*>(sProfile.interface_type)));
311 RTC_DEBUG((
"Valid SDO service required"));
312 if (strncmp(sProfile.id,
"", 1) == 0)
314 RTC_WARN((
"No id specified. It should be given by clients."));
319 std::string
id(sProfile.id);
322 if (
id == static_cast<const char*>(
m_consumers[i]->getProfile().
id))
324 RTC_INFO((
"Existing consumer is reinitilized."));
331 RTC_DEBUG((
"SDO service properly initialized."));
336 const char* ctype =
static_cast<const char*
>(sProfile.interface_type);
337 if (ctype == NULL) {
return false; }
339 if (consumer == NULL)
341 RTC_ERROR((
"Hmm... consumer must be created."));
344 RTC_DEBUG((
"An SDO service consumer created."));
347 if (!consumer->init(
m_rtobj, sProfile))
349 RTC_WARN((
"SDO service initialization was failed."));
350 RTC_DEBUG((
"id: %s", static_cast<const char*>(sProfile.id)));
352 static_cast<const char*>(sProfile.interface_type)));
356 RTC_INFO((
"SDO consumer was deleted by initialization failure"));
359 RTC_DEBUG((
"An SDO service consumer initialized."));
360 RTC_DEBUG((
"id: %s", static_cast<const char*>(sProfile.id)));
362 static_cast<const char*>(sProfile.interface_type)));
382 if (
id == NULL ||
id[0] ==
'\0')
384 RTC_ERROR((
"removeSdoServiceConsumer(): id is invalid."));
387 RTC_TRACE((
"removeSdoServiceConsumer(id = %s)",
id));
389 std::string strid(
id);
390 std::vector<SdoServiceConsumerBase*>::iterator it =
m_consumers.begin();
391 std::vector<SdoServiceConsumerBase*>::iterator it_end =
m_consumers.end();
394 if (strid == static_cast<const char*>((*it)->getProfile().id))
401 RTC_INFO((
"SDO service has been deleted: %s",
id));
406 RTC_WARN((
"Specified SDO consumer not found: %s",
id));
429 static_cast<const char*>(sProfile.interface_type))
431 RTC_DEBUG((
"%s is supported SDO service.",
432 static_cast<const char*>(sProfile.interface_type)));
436 RTC_WARN((
"Consumer type is not supported: %s",
437 static_cast<const char*>(sProfile.interface_type)));
454 for (
size_t i(0); i < consumerTypes.size(); ++i)
456 if (consumerTypes[i] ==
457 static_cast<const char*>(sProfile.interface_type))
459 RTC_DEBUG((
"%s exists in the SDO service factory.",
460 static_cast<const char*>(sProfile.interface_type)));
461 RTC_PARANOID((
"Available SDO serices in the factory: %s",
466 RTC_WARN((
"No available SDO service in the factory: %s",
467 static_cast<const char*>(sProfile.interface_type)));
477 return (
const char*)
uuid->to_string();
#define RTC_ERROR(fmt)
Error log output macro.
virtual bool init(RTObject_impl &rtobj, const SDOPackage::ServiceProfile &profile)=0
Initialization function of the consumer class.
Functor for ServiceProfile.
bool operator()(const SDOPackage::ServiceProfile &s)
const std::string getUUID() const
void init()
Initialization.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
bool removeSdoServiceProvider(const char *id)
Remove a SDO service provider.
SDOPackage::SDOService_ptr getServiceProvider(const char *id)
Get ServiceProfile of an SDO Service.
coil::Properties & getProperties()
[local interface] Get RTC property
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
GlobalFactory template class.
bool isEnabledConsumerType(const SDOPackage::ServiceProfile &sProfile)
If it is enabled service type.
#define RTC_WARN(fmt)
Warning log output macro.
bool m_allConsumerEnabled
SDO service provider base class and its factory.
SDO service administration class.
#define RTC_PARANOID(fmt)
Paranoid level log output macro.
std::vector< Identifier > getIdentifiers()
Get factory ID list.
std::vector< std::string > vstring
SdoServiceAdmin(::RTC::RTObject_impl &rtobj)
Constructor.
coil::UUID * generateUUID(ACE_UINT16 version=0x0001, u_char variant=0x80)
#define RTC_DEBUG(fmt)
Debug level log output macro.
std::string flatten(vstring sv)
Create CSV file from the given string list.
std::string toString(const SDOPackage::NVList &nv, const char *name)
Get NVList of specifid name as string.
coil::Guard< coil::Mutex > Guard
coil::vstring m_consumerTypes
void deleteObject(const Identifier &id, AbstractClass *&obj)
Delete factory object.
std::string ifrToKey(std::string &ifr)
CORBA sequence utility template functions.
AbstractClass * createObject(const Identifier &id)
Create factory object.
unsigned int replaceString(std::string &str, const std::string from, const std::string to)
Replace string.
bool addSdoServiceProvider(const SDOPackage::ServiceProfile &prof, SdoServiceProviderBase *provider)
Set a SDO service provider.
prop
Organization::get_organization_property ();.
service_id(const char *id)
void toLower(std::string &str)
Lowercase String Transformation.
Class represents a set of properties.
bool addSdoServiceConsumer(const SDOPackage::ServiceProfile &sProfile)
Add Service Consumer.
SDOPackage::ServiceProfile * getServiceProviderProfile(const char *id)
Get ServiceProfile of an SDO Service Provider.
#define RTC_INFO(fmt)
Information level log output macro.
RTC::RTObject_impl & m_rtobj
void copyFromProperties(SDOPackage::NVList &nv, const coil::Properties &prop)
Copy the properties to NVList.
SDOPackage::ServiceProfileList * getServiceProviderProfiles()
Get ServiceProfileList of SDO Service Provider.
coil::Mutex m_consumer_mutex
coil::Mutex m_provider_mutex
bool isExistingConsumerType(const SDOPackage::ServiceProfile &sProfile)
If it is existing service type.
SDO service consumer base class and its factory.
virtual ~SdoServiceAdmin()
Virtual destractor.
bool removeSdoServiceConsumer(const char *id)
Remove Service Consumer.
std::vector< SdoServiceConsumerBase * > m_consumers
SDO ServiceProfileList with mutex lock.
std::vector< SdoServiceProviderBase * > m_providers
SDO ServiceProfileList with mutex lock.