neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_async_task.hpp
Go to the documentation of this file.
1// async_task.hpp
2/*
3 * Copyright (c) 2007, 2020 Leigh Johnston.
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * * Neither the name of Leigh Johnston nor the names of any
19 * other contributors to this software may be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#pragma once
37
38#include <neolib/neolib.hpp>
44
45namespace neolib
46{
47 class i_timer_object;
48
50 {
51 // types
52 public:
54 // constants
55 public:
56 static constexpr std::size_t kDefaultPollCount = 256;
57 // construction
58 public:
59 virtual ~i_async_service() = default;
60 // operations
61 public:
62 virtual bool poll(bool aProcessEvents = true, std::size_t aMaximumPollCount = kDefaultPollCount) = 0;
63 virtual void* native_object() = 0;
64 // helpers
65 public:
66 template <typename NativeObjectType>
67 NativeObjectType& native_object()
68 {
69 return *static_cast<NativeObjectType*>(native_object());
70 }
71 };
72
74 {
75 // types
76 public:
78 // exceptions
79 public:
80 struct task_destroying : std::logic_error { task_destroying() : std::logic_error("neolib::i_timer_service::task_destroying") {} };
81 // operations
82 public:
84 virtual void remove_timer_object(i_timer_object& aObject) = 0;
85 };
86
87 class i_async_task : public i_task, public i_service, public i_reference_counted
88 {
89 // events
90 public:
93 // exceptions
94 public:
95 struct no_message_queue : std::logic_error { no_message_queue() : std::logic_error("i_async_task::no_message_queue") {} };
96 // types
97 public:
99 // operations
100 public:
101 virtual i_thread& thread() const = 0;
102 virtual bool joined() const = 0;
103 virtual void join(i_thread& aThread) = 0;
104 virtual void detach() = 0;
107 virtual bool have_message_queue() const = 0;
108 virtual bool have_messages() const = 0;
109 virtual i_message_queue& create_message_queue(std::function<bool()> aIdleFunction = std::function<bool()>()) = 0;
110 virtual const i_message_queue& message_queue() const = 0;
112 virtual void register_event_queue(i_async_event_queue& aQueue) = 0;
114 virtual bool pump_messages() = 0;
115 virtual bool running() const noexcept = 0;
116 virtual bool halted() const noexcept = 0;
117 virtual void halt() = 0;
118 virtual bool finished() const noexcept = 0;
119 virtual void wait() const noexcept = 0;
120 public:
121 virtual void idle() = 0;
122 public:
123 static uuid const& iid() { static uuid const sIid{ 0x5e572b8a, 0x272a, 0x40d1, 0xa788, { 0xd7, 0x32, 0xf7, 0x74, 0xfc, 0xe5 } }; return sIid; }
124 };
125}
virtual void * native_object()=0
virtual bool poll(bool aProcessEvents=true, std::size_t aMaximumPollCount=kDefaultPollCount)=0
i_async_service abstract_type
static constexpr std::size_t kDefaultPollCount
virtual ~i_async_service()=default
NativeObjectType & native_object()
virtual void register_event_queue(i_async_event_queue &aQueue)=0
virtual i_async_service & io_service()=0
virtual i_message_queue & message_queue()=0
virtual i_timer_service & timer_service()=0
virtual bool finished() const noexcept=0
static uuid const & iid()
virtual void wait() const noexcept=0
i_async_task abstract_type
virtual i_message_queue & create_message_queue(std::function< bool()> aIdleFunction=std::function< bool()>())=0
virtual void unregister_event_queue(i_async_event_queue &aQueue)=0
virtual bool joined() const =0
virtual void halt()=0
virtual bool running() const noexcept=0
virtual bool halted() const noexcept=0
virtual void join(i_thread &aThread)=0
virtual const i_message_queue & message_queue() const =0
virtual bool have_messages() const =0
virtual void idle()=0
virtual bool have_message_queue() const =0
virtual i_thread & thread() const =0
virtual void detach()=0
virtual bool pump_messages()=0
virtual i_timer_object & create_timer_object()=0
virtual void remove_timer_object(i_timer_object &aObject)=0
i_timer_service abstract_type
auto destroyed(Object &aObject, const Handler aHandler)
Definition i_object.hpp:73
auto destroying(Object &aObject, const Handler aHandler)
Definition i_object.hpp:64
#define declare_event(declName,...)
Definition i_event.hpp:305