Global Classes
class qi::Object
Functions (class qi::Object)
qi::detail::GenericObjectBounce<O>::forceExecutionContext
qi::detail::GenericObjectBounce<O>::connect
qi::detail::GenericObjectBounce<O>::metaPost
qi::detail::GenericObjectBounce<O>::findMethod
qi::detail::GenericObjectBounce<O>::executionContext
qi::detail::GenericObjectBounce<O>::clearStats
qi::detail::GenericObjectBounce<O>::metaCall
qi::detail::GenericObjectBounce<O>::metaObject
qi::detail::GenericObjectBounce<O>::enableTrace
qi::detail::GenericObjectBounce<O>::stats
qi::detail::GenericObjectBounce<O>::enableStats
qi::detail::GenericObjectBounce<O>::isStatsEnabled
qi::detail::GenericObjectBounce<O>::disconnect
qi::detail::GenericObjectBounce<O>::setProperty
qi::detail::GenericObjectBounce<O>::isTraceEnabled
qi::Object<T>::operator Object<Empty>
qi::Object<T>::deleteGenericObjectOnly
qi::Object<T>::deleteCustomDeleter
qi::Object<T>::keepManagedObjectPtr
qi::Object<T>::deleteGenericObjectOnlyAndKeep
qi::Object<T>::managedObjectPtr
qi::AnyObject is a specialization of qi::Object that provides type
erasure on objects, similar to what qi::AnyValue does on values. It can only
work on registered objects. We’ll use Graph::Drawer from the
registering guide. You can make an qi::Object from
a boost::shared_ptr.
qi::AnyObject obj = boost::make_shared<Graph::Drawer>();
qi::Object uses a shared_ptr semantics, so the object will be destroyed when
there are no more references to it. You can also get a qi::AnyObject from a
session, another service, etc.
You can call a function with call or async if you want the call to be asynchronous. You can also connect signals and change properties.
// do a synchronous call
obj.call<bool>("draw", Graph::Point(10, 20), Graph::Green);
// do an ansynchronous call
qi::Future<bool> future =
obj.async<bool>("draw", Graph::Point(10, 20), Graph::Green);
// do stuff...
future.wait();
// connect a signal and disconnect it
int id = obj.connect("drawDone", &mycallback);
obj.disconnect(id);
// set a property and get it
obj.setProperty("origin", Graph::Point(0, 12));
Graph::Point p = obj.property<Graph::Point>("origin");
std::cout << p.y << std::endl; // 12
When connecting a callback, as usual, the signature of the callback must match the signature of the signal. But since we are in a type-erased context, if this rule is not respected, the error will only appear (in the logs) when the signal is triggered, not at compile-time or at the connection.
Furthermore, the connect() function expects any type of boost::function
since we don’t know that until runtime, so it must be explicitly cast to the
correct type, particularly in case of boost::bind.
// this works because mycallback has a specific signature
obj.connect("drawDone", &mycallback);
// this fails at compile time because boost::bind does not force a signature
obj.connect("drawDone", boost::bind(mycallback, _1));
// this works, you must specify the signature expected by the signal
obj.connect("drawDone",
boost::function<void(const Point&)>(boost::bind(mycallback, _1)));
qi::Object can be specialized with T if the object is T or inherits from T.
qi::Object<Graph::Drawer> obj = boost::make_shared<Graph::Drawer>();
obj->draw(Graph::Point(11, 12), Graph::Green);
qi::Object‘s specializations do not work with remote objects yet.
Some methods in the services you will use expect an object as argument, for instance Logger::addListener(Object<LogListener> listener);. To call this method, you must first implement the LogListener interface into your own class, and then wrap a pointer to an instance of this class into an Object<LogListener> or a qi::AnyObject that will take ownership of the pointer:
class MyLogListener: public LogListener
{
// Implement LogListener interface
};
void someFunction()
{
qi::AnyObject logger = session.service("Logger");
qi::AnyObject o(boost::make_shared<LogListener>());
logger.call("addListener", o);
}
In the example above, your instance of MyLogListener will be kept alive as long as the logger service holds a qi::AnyObject on it. The same holds true when returning objects.
#include <qi/anyobject.hpp>
qi::detail::GenericObjectBounce< Object< T > >qi::AnyModuleObject(GenericObject* go)Object(T* ptr)Object(GenericObject* go, boost::function<void(GenericObject*)> deleter)Object(T* ptr, boost::function<void(T*)> deleter)Object()Object(const Object<U>& o)operator=(const Object<U>& o)Object(const Object& o)operator=(const Object& o)Object(const qi::Future<MaybeAnyObject>& fobj)Object(const qi::FutureSync<MaybeAnyObject>& fobj)Object(GenericObject* go, boost::shared_ptr<U> other)Object(boost::shared_ptr<U> other)operator<(const Object& b) constoperator!=(const Object<U>& b) constoperator==(const Object<U>& b) constoperator bool() constoperator Object<Empty>() constasSharedPtr()asT() constoperator->() constoperator*() constunique() constasGenericObject() constreset()use_count() constinterface()checkT()managedObjectPtr()metaObject() constmetaCall(unsigned int method, const GenericFunctionParameters& params, MetaCallType callType, Signature returnSignature)findMethod(const std::string& name, const GenericFunctionParameters& parameters) constmetaCall(const std::string& nameWithOptionalSignature, const GenericFunctionParameters& params, MetaCallType callType, Signature returnSignature)metaPost(unsigned int event, const GenericFunctionParameters& params) constmetaPost(const std::string& nameWithOptionalSignature, const GenericFunctionParameters& in) const()connect(const std::string& eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel) constconnect(const std::string& name, const SignalSubscriber& functor) constconnect(unsigned int signal, const SignalSubscriber& subscriber) constconnect(unsigned int signal, AnyObject target, unsigned int slot) constdisconnect(SignalLink linkId) constproperty(const std::string& name) constsetProperty(const std::string& name, const T& val) constproperty(unsigned int id) constsetProperty(unsigned int id, const AnyValue& val) constexecutionContext() constisStatsEnabled() constenableStats(bool enable) conststats() constclearStats() constisTraceEnabled() constenableTrace(bool enable)forceExecutionContext(boost::shared_ptr<qi::ExecutionContext> ec)()()keepManagedObjectPtr(detail::ManagedObjectPtr)noDeleteT(T*)noDelete(GenericObject*)deleteGenericObjectOnly(GenericObject* obj)deleteGenericObjectOnlyAndKeep(GenericObject* obj, U)deleteCustomDeleter(GenericObject* obj, boost::function<void(T*)> deleter)Type erased object that has a known interface T.
In case T is unknown, you can use qi::AnyObject which aliases to Object<qi::Empty>.
You can then use the object with type-erasure or call the object directly using the operator ->.
qi::Object<T>::keepManagedObjectPtr(detail::ManagedObjectPtr)¶qi::Object<T>::noDeleteT(T*)¶qi::Object<T>::noDelete(GenericObject*)¶qi::Object<T>::deleteGenericObjectOnly(GenericObject* obj)¶qi::Object<T>::deleteGenericObjectOnlyAndKeep(GenericObject* obj, U)¶qi::Object<T>::deleteCustomDeleter(GenericObject* obj, boost::function<void(T*)> deleter)¶qi::Object<T>::Object(GenericObject* go)¶These constructors take ownership of the underlying pointers. If a callback is given, it will be called instead of the default behavior of deleting the stored GenericObject and the underlying T object.
qi::Object<T>::Object(T* ptr)¶qi::Object<T>::Object(GenericObject* go, boost::function<void(GenericObject*)> deleter)¶qi::Object<T>::Object(T* ptr, boost::function<void(T*)> deleter)¶qi::Object<T>::Object()¶qi::Object<T>::Object(const Object<U>& o)¶qi::Object<T>::operator=(const Object<U>& o)¶qi::Object<T>::Object(const Object& o)¶qi::Object<T>::operator=(const Object& o)¶qi::Object<T>::Object(const qi::Future<MaybeAnyObject>& fobj)¶qi::Object<T>::Object(const qi::FutureSync<MaybeAnyObject>& fobj)¶Shares ref counter with other, which must handle the destruction of go.
qi::Object<T>::operator<(const Object& b) const¶qi::Object<T>::operator!=(const Object<U>& b) const¶qi::Object<T>::operator==(const Object<U>& b) const¶qi::Object<T>::operator bool() const¶qi::Object<T>::operator Object<Empty>() const¶qi::Object<T>::asT() const¶qi::Object<T>::operator->() const¶qi::Object<T>::operator*() const¶qi::Object<T>::unique() const¶qi::Object<T>::asGenericObject() const¶qi::Object<T>::reset()¶qi::Object<T>::use_count() const¶qi::Object<T>::interface()¶qi::Object<T>::checkT()¶Check tha value actually has the T interface.
qi::Object<T>::managedObjectPtr()¶qi::detail::GenericObjectBounce<O>::metaObject() const¶qi::detail::GenericObjectBounce<O>::metaCall(unsigned int method, const GenericFunctionParameters& params, MetaCallType callType = MetaCallType_Auto, Signature returnSignature = Signature()¶qi::detail::GenericObjectBounce<O>::findMethod(const std::string& name, const GenericFunctionParameters& parameters) const¶qi::detail::GenericObjectBounce<O>::metaCall(const std::string& nameWithOptionalSignature, const GenericFunctionParameters& params, MetaCallType callType = MetaCallType_Auto, Signature returnSignature = Signature()¶qi::detail::GenericObjectBounce<O>::metaPost(unsigned int event, const GenericFunctionParameters& params) const¶qi::detail::GenericObjectBounce<O>::metaPost(const std::string& nameWithOptionalSignature, const GenericFunctionParameters& in) const¶()qi::detail::GenericObjectBounce<O>::connect(const std::string& eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel = MetaCallType_Auto) const¶qi::detail::GenericObjectBounce<O>::connect(const std::string& name, const SignalSubscriber& functor) const¶qi::detail::GenericObjectBounce<O>::connect(unsigned int signal, const SignalSubscriber& subscriber) const¶qi::detail::GenericObjectBounce<O>::connect(unsigned int signal, AnyObject target, unsigned int slot) const¶qi::detail::GenericObjectBounce<O>::disconnect(SignalLink linkId) const¶qi::detail::GenericObjectBounce<O>::property(const std::string& name) const¶qi::detail::GenericObjectBounce<O>::setProperty(const std::string& name, const T& val) const¶qi::detail::GenericObjectBounce<O>::property(unsigned int id) const¶qi::detail::GenericObjectBounce<O>::setProperty(unsigned int id, const AnyValue& val) const¶qi::detail::GenericObjectBounce<O>::executionContext() const¶qi::detail::GenericObjectBounce<O>::isStatsEnabled() const¶qi::detail::GenericObjectBounce<O>::enableStats(bool enable) const¶qi::detail::GenericObjectBounce<O>::stats() const¶qi::detail::GenericObjectBounce<O>::clearStats() const¶qi::detail::GenericObjectBounce<O>::isTraceEnabled() const¶qi::detail::GenericObjectBounce<O>::enableTrace(bool enable)¶()()