7 #ifndef _QI_TYPE_DETAIL_GENERIC_OBJECT_HPP_
8 #define _QI_TYPE_DETAIL_GENERIC_OBJECT_HPP_
13 #include <boost/smart_ptr/enable_shared_from_this.hpp>
23 # pragma warning( push )
24 # pragma warning( disable: 4251 )
41 ,
public boost::enable_shared_from_this<GenericObject>
52 const std::string& eventName,
64 const std::string& eventName,
75 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
76 template<typename R> R call( \
77 const std::string& methodName comma \
78 QI_GEN_ARGSDECLSAMETYPE(n, qi::AutoAnyReference));
82 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
83 template<typename R> qi::Future<R> async( \
84 const std::string& methodName comma \
85 QI_GEN_ARGSDECLSAMETYPE(n, qi::AutoAnyReference));
105 void post(
const std::string& eventName,
123 template <
typename FUNCTOR_TYPE>
170 template <
typename FUNCTION_TYPE>
172 FUNCTION_TYPE callback,
182 template <
typename T>
184 template <
typename T>
186 template <
typename T>
197 #define pushi(z, n,_) params.push_back(p ## n);
199 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
200 template <typename R> \
201 R GenericObject::call(const std::string& methodName comma \
202 QI_GEN_ARGSDECLSAMETYPE(n, qi::AutoAnyReference)) \
204 BOOST_STATIC_ASSERT_MSG(!detail::isFuture<R>::value, \
205 "return type of call must not be a Future"); \
206 if (!value || !type) \
208 throw std::runtime_error("Invalid GenericObject"); \
210 std::vector<qi::AnyReference> params; \
212 BOOST_PP_REPEAT(n, pushi, _) \
213 qi::Future<AnyReference> fmeta = metaCall( \
214 methodName, params, MetaCallType_Direct, typeOf<R>()->signature()); \
215 return detail::extractFuture<R>(fmeta); \
217 template <typename R> \
218 qi::Future<R> GenericObject::async( \
219 const std::string& methodName comma \
220 QI_GEN_ARGSDECLSAMETYPE(n, qi::AutoAnyReference)) \
222 BOOST_STATIC_ASSERT_MSG(!detail::isFuture<R>::value, \
223 "return type of async must not be a Future"); \
224 if (!value || !type) \
226 return makeFutureError<R>("Invalid GenericObject"); \
228 std::vector<qi::AnyReference> params; \
230 BOOST_PP_REPEAT(n, pushi, _) \
231 qi::Promise<R> res(&qi::PromiseNoop<R>); \
232 qi::Future<AnyReference> fmeta = metaCall( \
233 methodName, params, MetaCallType_Queued, typeOf<R>()->signature()); \
234 qi::adaptFutureUnwrap(fmeta, res); \
235 return res.future(); \
247 return makeFutureError<T>(
"Property not found");
250 f.connect(
boost::bind(&detail::futureAdapterVal<T>,_1, p),
260 return makeFutureError<void>(
"Property not found");
281 return AnyReference((*val)->type, (*val)->value);
284 virtual void set(
void** storage, AnyReference source)
288 if (source.type()->info() == info())
297 set(storage, source.content());
302 detail::ManagedObjectPtr op(
new GenericObject(static_cast<ObjectTypeInterface*>(source.type()), source.rawValue()));
307 PointerTypeInterface* ptype =
static_cast<PointerTypeInterface*
>(source.type());
310 qiLogInfo() <<
"Object will *not* track original shared pointer";
311 set(storage, *source);
314 throw std::runtime_error((std::string)
"Cannot assign non-object " + source.type()->infoString() +
" to Object");
317 typedef DefaultTypeImplMethods<detail::ManagedObjectPtr, TypeByPointerPOD<detail::ManagedObjectPtr> > Methods;
324 # pragma warning( pop )
static AnyFunction from(F func)
qi::FutureSync< SignalLink > connect(const std::string &eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel=MetaCallType_Direct)
qi::Future< AnyReference > metaCall(ExecutionContext *ec, ObjectThreadingModel objectThreadingModel, MetaCallType methodThreadingModel, MetaCallType callType, AnyObject manageable, unsigned int methodId, AnyFunction func, const GenericFunctionParameters ¶ms, bool noCloneFirst=false, unsigned int callerId=0, qi::os::timeval postTimestamp=qi::os::timeval())
#define qiLogCategory(Cat)
boost::function< RF > bind(const AF &fun,...)
static AnyValue from(const T &r)
Honor the default behavior.
dll import/export and compiler message
#define qiLogWarning(...)
Log in warning mode.
Future< T > future() const
Get a future linked to this promise. Can be called multiple times.
boost::shared_ptr< class GenericObject > ManagedObjectPtr
Future< R > async(boost::function< R()> callback, uint64_t usDelay=0)
Force a synchronous call.
#define qiLogInfo(...)
Log in info mode.
#define _QI_BOUNCE_TYPE_METHODS(Bounce)
Implement all methods of Type as bouncers to Bouncer.
qi::FutureSync< void > setProperty(const std::string &name, const T &val)
#define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)
ObjectTypeInterface * type
qi::FutureSync< T > property(const std::string &name)
const MetaObject & metaObject()