23 #include "usServiceReferenceBasePrivate.h"
24 #include "usServiceRegistrationBasePrivate.h"
27 #include "usModulePrivate.h"
33 ServiceReferenceBase::ServiceReferenceBase()
34 : d(new ServiceReferenceBasePrivate(0))
45 ServiceReferenceBase::ServiceReferenceBase(ServiceRegistrationBasePrivate* reg)
46 : d(new ServiceReferenceBasePrivate(reg))
50 void ServiceReferenceBase::SetInterfaceId(
const std::string& interfaceId)
56 d =
new ServiceReferenceBasePrivate(d->registration);
58 d->interfaceId = interfaceId;
61 ServiceReferenceBase::operator bool_type()
const
63 return GetModule() != 0 ? &ServiceReferenceBase::d : NULL;
72 d =
new ServiceReferenceBasePrivate(0);
85 MutexLock lock(d->registration->propsLock);
87 return d->registration->properties.Value(key);
92 MutexLock lock(d->registration->propsLock);
94 const std::vector<std::string>& ks = d->registration->properties.Keys();
95 keys.assign(ks.begin(), ks.end());
100 if (d->registration == 0 || d->registration->module == 0)
105 return d->registration->module->q;
110 MutexLock lock(d->registration->propsLock);
112 ServiceRegistrationBasePrivate::ModuleToRefsMap::const_iterator end = d->registration->dependents.end();
113 for (ServiceRegistrationBasePrivate::ModuleToRefsMap::const_iterator iter = d->registration->dependents.begin();
116 modules.push_back(iter->first);
134 assert(anyR1.
Empty() || anyR1.
Type() ==
typeid(int));
135 assert(anyR2.
Empty() || anyR2.
Type() ==
typeid(int));
148 assert(anyId1.
Type() ==
typeid(
long int));
149 assert(anyId2.
Type() ==
typeid(
long int));
150 const long int id1 = *
any_cast<
long int>(&anyId1);
151 const long int id2 = *
any_cast<
long int>(&anyId2);
161 return d->registration == reference.d->registration;
166 ServiceReferenceBasePrivate* curr_d = d;
170 if (!curr_d->ref.Deref())
178 return d->IsConvertibleTo(interfaceId);
183 return d->interfaceId;
186 std::size_t ServiceReferenceBase::Hash()
const
188 using namespace US_HASH_FUNCTION_NAMESPACE;
196 std::ostream&
operator<<(std::ostream& os,
const ServiceReferenceBase& serviceRef)
200 assert(serviceRef.GetModule() != NULL);
202 os <<
"Reference for service object registered from "
203 << serviceRef.GetModule()->GetName() <<
" " << serviceRef.GetModule()->GetVersion()
205 std::vector<std::string> keys;
206 serviceRef.GetPropertyKeys(keys);
207 size_t keySize = keys.size();
208 for(
size_t i = 0; i < keySize; ++i)
210 os << keys[i] <<
"=" << serviceRef.GetProperty(keys[i]).ToString();
211 if (i < keySize-1) os <<
",";
217 os <<
"Invalid service reference";
Module * GetModule() const
const std::type_info & Type() const
US_Core_EXPORT const std::string & SERVICE_RANKING()
bool operator==(const ServiceReferenceBase &reference) const
ValueType * any_cast(Any *operand)
void GetUsingModules(std::vector< Module * > &modules) const
bool operator<(const ServiceReferenceBase &reference) const
friend class ServiceRegistrationBasePrivate
US_Core_EXPORT std::ostream & operator<<(std::ostream &os, ModuleEvent::Type eventType)
Any GetProperty(const std::string &key) const
std::string GetInterfaceId() const
ServiceReferenceBase & operator=(int null)
void GetPropertyKeys(std::vector< std::string > &keys) const
bool IsConvertibleTo(const std::string &interfaceid) const
US_Core_EXPORT const std::string & SERVICE_ID()
US_MSVC_POP_WARNING US_HASH_FUNCTION_NAMESPACE_BEGIN return US_HASH_FUNCTION(us::ServiceRegistrationBasePrivate *, arg.d)