#ifndef __PROCESS_RUN_HPP__ #define __PROCESS_RUN_HPP__ #include // TODO(benh): Replace shared_ptr with unique_ptr. #include #include namespace process { namespace internal { template class ThunkProcess : public Process > { public: ThunkProcess(std::tr1::shared_ptr > _thunk, std::tr1::shared_ptr > _promise) : thunk(_thunk), promise(_promise) {} virtual ~ThunkProcess() {} protected: virtual void serve(const Event& event) { promise->set((*thunk)()); } private: std::tr1::shared_ptr > thunk; std::tr1::shared_ptr > promise; }; } // namespace internal { template Future run(R (*method)(void)) { std::tr1::shared_ptr > thunk( new std::tr1::function( std::tr1::bind(method))); std::tr1::shared_ptr > promise(new Promise()); Future future = promise->future(); terminate(spawn(new internal::ThunkProcess(thunk, promise), true)); return future; } #define TEMPLATE(Z, N, DATA) \ template \ Future run( \ R (*method)(ENUM_PARAMS(N, P)), \ ENUM_BINARY_PARAMS(N, A, a)) \ { \ std::tr1::shared_ptr > thunk( \ new std::tr1::function( \ std::tr1::bind(method, ENUM_PARAMS(N, a)))); \ \ std::tr1::shared_ptr > promise(new Promise()); \ Future future = promise->future(); \ \ terminate(spawn(new internal::ThunkProcess(thunk, promise), true)); \ \ return future; \ } REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9. #undef TEMPLATE } // namespace process { #endif // __PROCESS_RUN_HPP__