7 #ifndef _QI_TYPE_DETAIL_OBJECT_HXX_
8 #define _QI_TYPE_DETAIL_OBJECT_HXX_
10 #include <boost/mpl/if.hpp>
60 return go()->
metaCall(method, params, callType, returnSignature);
68 return go()->
metaCall(nameWithOptionalSignature, params, callType, returnSignature);
72 return go()->
metaPost(event, params);
76 return go()->
metaPost(nameWithOptionalSignature, in);
78 template <
typename... Args>
79 inline void post(
const std::string& eventName, Args&&... args)
const
81 return go()->
post(eventName, std::forward<Args>(args)...);
83 template <
typename FUNCTOR_TYPE>
87 return go()->
connect(eventName, callback, threadingModel);
91 return go()->
connect(name, functor);
95 return go()->
connect(signal, subscriber);
106 return go()->template property<T>(name);
135 return go()->
stats();
153 template <
typename R,
typename... Args>
156 return go()->template async<R>(methodName, std::forward<Args>(args)...);
158 template <
typename R,
typename... Args>
159 R
call(
const std::string& methodName, Args&&... args)
const
161 return go()->template call<R>(methodName, std::forward<Args>(args)...);
167 GenericObject* g =
static_cast<const O*
>(
this)->asGenericObject();
169 throw std::runtime_error(
"This object is null");
174 template <
typename T>
182 template <
typename T,
typename... Args>
186 return boost::make_shared<typename detail::InterfaceImplTraits<T>::SyncType>(std::forward<Args>(args)...);
188 template <
typename T,
typename... Args>
192 return Object<T>(
new T(std::forward<Args>(args)...));
195 #define QI_REGISTER_IMPLEMENTATION_H(interface, impl) \
201 struct InterfaceImplTraits<interface> \
203 using Defined = boost::true_type; \
204 using ImplType = impl; \
205 using LocalType = interface##Local<ImplType>; \
206 using SyncType = interface##LocalSync<LocalType>; \
254 Object(T* ptr, boost::function<
void(T*)> deleter);
259 template<
typename U>
Object(boost::shared_ptr<U> other);
263 operator bool()
const;
292 deleter((T*)obj->
value);
311 qiLogDebug(
"qi.object") <<
"deleteObject " << obj <<
" "
330 boost::weak_ptr<GenericObject>
_ptr;
339 std::stringstream err;
340 err <<
"Object<T> can only be used on registered object types. ("
342 throw std::runtime_error(err.str());
409 _obj->_internal_accept_owner(&other, go);
416 T* ptr =
static_cast<T*
>(other.get());
422 return Object<U>(other).managedObjectPtr();
463 return boost::shared_ptr<T>(&asT(),
boost::bind(&keepManagedObjectPtr, _obj));
469 if (!boost::is_same<T, Empty>::value && obj)
489 if (boost::is_same<T, Empty>::value || !_obj)
492 const auto isMatchingType = [&] {
493 return _obj->type->info() == typeOf<T>()->info()
497 if (!isMatchingType())
500 detail::ProxyGeneratorMap::iterator it = map.find(typeOf<T>()->info());
503 qiLogDebug(
"qitype.anyobject") <<
"Upgrading Object to specialized proxy.";
510 throw std::runtime_error(std::string() +
"Object does not have interface " + typeOf<T>()->infoString());
516 return *
static_cast<T*
>(_obj->value);
528 return _obj.unique();
544 return go()->
connect(signal, target, slot);
556 public TypeImpl<boost::shared_ptr<GenericObject>>
570 #endif // _QITYPE_DETAIL_OBJECT_HXX_
boost::shared_ptr< T > asSharedPtr()
GenericObject * asGenericObject() const
static void noDeleteT(T *)
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
void enableStats(bool enable) const
std::map< unsigned int, MethodStatistics > ObjectStatistics
void checkT()
Check tha value actually has the T interface.
bool operator<(const Object &b) const
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)
void post(const std::string &eventName, Args &&...args) const
static void deleteGenericObjectOnly(GenericObject *obj)
ManagedObjectPtr fromSharedPtr(Object< T > &dst, boost::shared_ptr< U > &other, boost::false_type)
R call(const std::string &methodName, Args &&...args) const
unsigned use_count() const
void destroy()
Deletes storage.
WeakObject(const Object< U > &o)
boost::shared_ptr< class GenericObject > ManagedObjectPtr
boost::false_type Defined
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.
bool operator==(const Object< U > &b) const
Object< T > & operator=(const Object< U > &o)
detail::ManagedObjectPtr managedObjectPtr()
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
static void keepReference(GenericObject *obj, boost::shared_ptr< U > ptr)
qi::FutureSync< T > property(const std::string &name)
const char * infoString()
ObjectTypeInterface * interface()
typename boost::mpl::if_< typename boost::is_same< Empty, Empty >::type, None, Object< Empty >>::type MaybeAnyObject
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
static void keepManagedObjectPtr(detail::ManagedObjectPtr ptr)
bool isTraceEnabled() const
static void noDelete(GenericObject *)
ObjectStatistics stats() const
const ValueType & value(int msecs=FutureTimeout_Infinite) const
Return the value associated to a Future.
bool operator!=(const Object< U > &b) const
static const int INHERITS_FAILED
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.
qi::Future< AnyReference > metaCall(unsigned int method, const GenericFunctionParameters ¶ms, MetaCallType callType=MetaCallType_Auto, Signature returnSignature=Signature())
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 (could be avoided)
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
static void deleteGenericObjectOnlyAndKeep(GenericObject *obj, U)