7 #ifndef _QI_TYPE_DETAIL_OBJECT_HXX_
8 #define _QI_TYPE_DETAIL_OBJECT_HXX_
11 #include <boost/mpl/if.hpp>
28 #include <type_traits>
33 static const unsigned int nullObjectId = 0;
67 return go()->
metaCall(method, params, callType, returnSignature);
75 return go()->
metaCall(nameWithOptionalSignature, params, callType, returnSignature);
79 return go()->
metaPost(event, params);
83 return go()->
metaPost(nameWithOptionalSignature, in);
85 template <
typename... Args>
86 inline void post(
const std::string& eventName, Args&&... args)
const
88 return go()->
post(eventName, std::forward<Args>(args)...);
90 template <
typename FUNCTOR_TYPE>
94 return go()->
connect(eventName, callback, threadingModel);
98 return go()->
connect(name, functor);
102 return go()->
connect(signal, subscriber);
113 return go()->template property<T>(
name);
142 return go()->
stats();
160 template <
typename R,
typename... Args>
163 return go()->template async<R>(methodName, std::forward<Args>(args)...);
165 template <
typename R,
typename... Args>
166 R
call(
const std::string& methodName, Args&&... args)
const
168 return go()->template call<R>(methodName, std::forward<Args>(args)...);
174 GenericObject* g =
static_cast<const O*
>(
this)->asGenericObject();
176 throw std::runtime_error(
"This object is null");
181 template <
typename T>
189 template <
typename T,
typename... Args>
193 return boost::make_shared<typename detail::InterfaceImplTraits<T>::ImplType>(std::forward<Args>(args)...);
195 template <
typename T,
typename... Args>
199 return Object<T>(
new T(std::forward<Args>(args)...));
211 #define QI_REGISTER_IMPLEMENTATION_H(interface, impl)\
217 struct InterfaceImplTraits<interface>\
219 using Defined = std::true_type;\
220 using InterfaceType = interface;\
221 using ImplType = impl;\
222 using AsyncType = interface##LocalAsync<boost::shared_ptr<ImplType>>;\
223 using SyncType = interface##LocalSync<boost::shared_ptr<ImplType>>;\
227 struct InterfaceImplTraits<impl>:\
228 public InterfaceImplTraits<interface>\
276 Object(T* ptr, boost::function<
void(T*)> deleter);
281 template<
typename U>
Object(boost::shared_ptr<U> other);
283 explicit operator bool()
const;
288 friend KA_GENERATE_REGULAR_OP_LESS_OR_EQUAL(
Object)
289 friend KA_GENERATE_REGULAR_OP_GREATER_OR_EQUAL(
Object)
321 deleter((T*)obj->
value);
340 qiLogDebug(
"qi.object") <<
"deleteObject " << obj <<
" "
359 boost::weak_ptr<GenericObject>
_ptr;
368 std::stringstream err;
369 err <<
"Object<T> can only be used on registered object types. ("
371 throw std::runtime_error(err.str());
438 _obj->_internal_accept_owner(&other, go);
446 boost::shared_ptr<T> other,
447 const boost::optional<ObjectUid>& maybeUid =
boost::none)
458 template<
typename From>
461 boost::shared_ptr<From>& other,
468 template<
typename From>
471 boost::shared_ptr<From>& other,
478 template<
typename ToSameAsFrom>
481 boost::shared_ptr<ToSameAsFrom>& other,
488 template<
typename To,
typename From>
491 boost::shared_ptr<From>& other,
495 std::is_base_of<
typename std::decay<To>::type,
typename std::decay<From>::type>::value,
496 "Cannot construct object from instance, because it is not a direct base or an associated implementation");
497 auto asDestinationType = boost::static_pointer_cast<To>(other);
502 template<
typename To,
typename From>
505 boost::shared_ptr<From>& other,
510 const auto realImplUid =
os::ptrUid(other.get());
511 auto localProxy = boost::make_shared<SyncProxyType>(other);
554 return boost::shared_ptr<T>(&asT(),
boost::bind(&keepManagedObjectPtr, _obj));
560 if (!boost::is_same<T, Empty>::value && obj)
570 template<
typename T,
typename U>
577 template<
typename T,
typename U>
586 QI_ASSERT(a.asGenericObject() && b.asGenericObject());
587 return a.asGenericObject()->uid < b.asGenericObject()->uid;
593 return _obj && _obj->type;
606 if (boost::is_same<T, Empty>::value || !_obj)
609 const auto isMatchingType = [&] {
610 return _obj->type->info() == typeOf<T>()->info()
614 if (!isMatchingType())
617 detail::ProxyGeneratorMap::iterator it = map.find(typeOf<T>()->info());
620 qiLogDebug(
"qitype.anyobject") <<
"Upgrading Object to specialized proxy.";
627 throw std::runtime_error(std::string() +
"Object does not have interface " + typeOf<T>()->infoString());
638 return *
static_cast<T*
>(_obj->value);
650 return _obj.unique();
666 return go()->
connect(signal, target, slot);
678 public TypeImpl<boost::shared_ptr<GenericObject>>
696 struct hash<qi::Object<T>>
706 #endif // _QITYPE_DETAIL_OBJECT_HXX_
boost::shared_ptr< GenericObject > ManagedObjectPtr
boost::shared_ptr< T > asSharedPtr()
GenericObject * asGenericObject() const
static void noDeleteT(T *)
ObjectUid uid
Uid of "value".
boost::enable_if< typename detail::InterfaceImplTraits< T >::Defined, qi::Object< T > >::type constructObject(Args...args)
boost::weak_ptr< GenericObject > _ptr
qi::Future< AnyReference > metaCall(const std::string &nameWithOptionalSignature, const GenericFunctionParameters ¶ms, MetaCallType callType=MetaCallType_Auto, Signature returnSignature=Signature()) const
qi::FutureSync< void > setProperty(const std::string &name, const T &val) const
qi::FutureSync< void > disconnect(SignalLink linkId) const
qi::FutureSync< SignalLink > connect(const std::string &eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel=MetaCallType_Direct)
qi::FutureSync< AnyValue > property(unsigned int id) const
void enableStats(bool enable)
Set statistics gathering status.
int findMethod(const std::string &name, const GenericFunctionParameters ¶meters) const
std::size_t operator()(const qi::Object< T > &o) const
void enableStats(bool enable) const
std::map< unsigned int, MethodStatistics > ObjectStatistics
void checkT()
Check tha value actually has the T interface.
qi::FutureSync< SignalLink > connect(unsigned int signal, const SignalSubscriber &subscriber) const
Honor the default behavior.
qi::FutureSync< T > property(const std::string &name) const
#define QI_ASSERT(expr__)
const ValueType & value(int msecs=FutureTimeout_Infinite) const
qi::FutureSync< SignalLink > connect(const std::string &eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel=MetaCallType_Auto) const
void enableTrace(bool enable)
bool isStatsEnabled() const
int findMethod(const std::string &name, const GenericFunctionParameters ¶meters)
Find method named name callable with arguments parameters.
void post(const std::string &eventName, Args &&...args) const
friend KA_GENERATE_REGULAR_OP_GREATER(Object) friend KA_GENERATE_REGULAR_OP_LESS_OR_EQUAL(Object) friend KA_GENERATE_REGULAR_OP_GREATER_OR_EQUAL(Object) ObjectUid uid() const
static void deleteGenericObjectOnly(GenericObject *obj)
R call(const std::string &methodName, Args &&...args) const
unsigned use_count() const
void destroy()
Deletes storage.
static const auto INHERITS_FAILED
WeakObject(const Object< U > &o)
ProxyGeneratorMap & proxyGeneratorMap()
void forceExecutionContext(boost::shared_ptr< qi::ExecutionContext > ec)
T to() const
Convert to anything or throw trying.
qi::FutureSync< void > disconnect(SignalLink linkId)
Disconnect an event link. Returns if disconnection was successful.
Object< T > & operator=(const Object< U > &o)
detail::ManagedObjectPtr managedObjectPtr()
bool operator==(const Signature &lhs, const Signature &rhs)
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
std::map< TypeInfo, boost::function< AnyReference(AnyObject)>> ProxyGeneratorMap
const MetaObject & metaObject() const
qi::FutureSync< void > setProperty(const std::string &name, const T &val)
void metaPost(unsigned int event, const GenericFunctionParameters ¶ms) const
bool isStatsEnabled() const
ObjectTypeInterface * type
void post(const std::string &eventName, qi::AutoAnyReference p1=qi::AutoAnyReference(), qi::AutoAnyReference p2=qi::AutoAnyReference(), qi::AutoAnyReference p3=qi::AutoAnyReference(), qi::AutoAnyReference p4=qi::AutoAnyReference(), qi::AutoAnyReference p5=qi::AutoAnyReference(), qi::AutoAnyReference p6=qi::AutoAnyReference(), qi::AutoAnyReference p7=qi::AutoAnyReference(), qi::AutoAnyReference p8=qi::AutoAnyReference())
void metaPost(unsigned int event, const GenericFunctionParameters ¶ms)
virtual void destroy(void *)=0
Free all resources of a storage.
void enableTrace(bool enable)
qi::FutureSync< void > setProperty(unsigned int id, const AnyValue &val) const
qi::FutureSync< T > property(const std::string &name)
const char * infoString()
static ObjectTypeInterface * interface()
typename boost::mpl::if_< typename boost::is_same< Empty, Empty >::type, None, Object< Empty >>::type MaybeAnyObject
ManagedObjectPtr managedObjectFromSharedPtr(ObjectTypeInterface *oit, boost::shared_ptr< T > other, const boost::optional< ObjectUid > &maybeUid=boost::none)
qi::FutureSync< SignalLink > connect(const std::string &name, const SignalSubscriber &functor) const
qi::Future< R > async(const std::string &methodName, Args &&...args) const
boost::shared_ptr< ExecutionContext > executionContext() const
const MetaObject & metaObject()
Object< Empty > AnyObject
bool isTraceEnabled() const
static void noDelete(GenericObject *)
ObjectStatistics stats() const
PtrUid ptrUid(void *address)
const ValueType & value(int msecs=FutureTimeout_Infinite) const
Return the value associated to a Future.
qi::Future< AnyReference > metaCall(unsigned int method, const GenericFunctionParameters ¶ms, MetaCallType callType=MetaCallType_Auto, Signature returnSignature=Signature()) const
void forceExecutionContext(boost::shared_ptr< ExecutionContext > eventLoop)
Override all ThreadingModel and force dispatch to given event loop.
bool isTraceEnabled() const
void clearStats()
Reset all statistical data.
static void keepManagedObjectPtr(detail::ManagedObjectPtr)
qi::Future< AnyReference > metaCall(const std::string &nameWithOptionalSignature, const GenericFunctionParameters ¶ms, MetaCallType callType=MetaCallType_Auto, Signature returnSignature=Signature())
bool operator!=(const Signature &lhs, const Signature &rhs)
ObjectStatistics stats() const
void init(qi::LogLevel verb=qi::LogLevel_Info, qi::LogContext context=qi::LogContextAttr_ShortVerbosity|qi::LogContextAttr_Tid|qi::LogContextAttr_Category, bool synchronous=true)
Initialization of the logging system Creates and registers the default log handler according to QI_DE...
std::enable_if< std::is_function< RF >::value, boost::function< RF > >::type bind(AF &&fun, Arg0 &&arg0, Args &&...args)
void metaPost(const std::string &nameWithOptionalSignature, const GenericFunctionParameters &in) const
static void deleteCustomDeleter(GenericObject *obj, boost::function< void(T *)> deleter)
ExecutionContext * executionContext() const