#ifndef AIRMAP_CONTEXT_H_ #define AIRMAP_CONTEXT_H_ #include #include #include #include #include #include #include #include #include namespace airmap { /// Context consitutes the point-of-entry for interaction with the classes and interfaces /// in airmap::*. class Context : DoNotCopyOrMove { public: /// ReturnCode enumerates all known return values for a call to run or exec. enum class ReturnCode { success = 0, /// Execution finished successfully error = 1, /// Execution finished with an error already_running = 2 /// Indicates that the context is already executing on another thread }; /// @cond using ClientCreateResult = Outcome, Error>; using ClientCreateCallback = std::function; using MonitorClientCreateResult = Outcome, Error>; using MonitorClientCreateCallback = std::function; using CreateResult = Outcome, Error>; using SignalHandler = std::function; using SignalSet = std::unordered_set; /// @endcond /// create tries to assemble and return a new Context instance. static CreateResult create(const std::shared_ptr& logger); /// create_client_with_configuration schedules creation of a new client with 'configuration' /// and reports results to 'cb'. virtual void create_client_with_configuration(const Client::Configuration& configuration, const ClientCreateCallback& cb) = 0; /// create_monitor_client_with_configuration schedules creation of a new monitor::Client with 'configuration' /// and reports results to 'cb'. virtual void create_monitor_client_with_configuration(const monitor::Client::Configuration& configuration, const MonitorClientCreateCallback& cb) = 0; /// exec hands a thread of execution to a Context instance, monitoring /// the signals present in 'signal_set' and dispatching incoming signals /// to the registered handlers. /// /// Implementations are expected to block the current thread until /// either an error occured or the user explicitly requests a Context /// instance to stop. virtual ReturnCode exec(const SignalSet& signal_set, const SignalHandler& handler) = 0; /// run hands a thread of execution to the context. /// /// Implementations are expected to block the current thread until /// either an error occured or the user explicitly requests a Context /// instance to stop. virtual ReturnCode run() = 0; /// stop requests an instance to shut down its operation and return from /// run. virtual void stop(ReturnCode rc = ReturnCode::success) = 0; /// dispatch executes 'task' on the thread running this Context instance. virtual void dispatch(const std::function& task) = 0; /// schedule_in schedules execution of 'functor' in 'wait_for' [us]. virtual void schedule_in(const Microseconds& wait_for, const std::function& functor) = 0; protected: /// @cond Context() = default; /// @endcond }; } // namespace airmap #endif // AIRMAP_CONTEXT_H_