yasmine
async_behavior.hpp
Go to the documentation of this file.
1 // //
3 // This file is part of the Seadex yasmine ecosystem (http://yasmine.seadex.de). //
4 // Copyright (C) 2016-2017 Seadex GmbH //
5 // //
6 // Licensing information is available in the folder "license" which is part of this distribution. //
7 // The same information is available on the www @ http://yasmine.seadex.de/Licenses.html. //
8 // //
10 
11 
12 #ifndef ASYNC_BEHAVIOR_A799E0CD_DD3E_45EA_BF47_586C94FC32CB
13 #define ASYNC_BEHAVIOR_A799E0CD_DD3E_45EA_BF47_586C94FC32CB
14 
15 
16 #include "essentials/non_copyable.hpp"
17 #include "essentials/compatibility/thread.hpp"
18 
19 #include "async_behavior_fwd.hpp"
20 
21 
22 namespace sxy
23 {
24 
25 
26 class event;
27 class simple_state_base;
28 class async_event_handler;
29 class event_collector;
30 
31 
33 {
34 
35 
36 public:
38  virtual ~async_behavior() SX_NOEXCEPT;
39  SX_NO_COPY(async_behavior)
40  void run( const event& _event, event_collector& _event_collector, const simple_state_base& _simple_state, async_event_handler& _async_event_handler );
41  void halt_and_join();
42 
43 protected:
44  bool should_stop() const;
45 
46 
47 private:
48  void work( const event& _event, event_collector& _event_collector, const simple_state_base& _simple_state,
49  async_event_handler& _async_event_handler );
50  virtual void run_impl( const event& _event, event_collector& _event_collector,
51  async_event_handler& _async_event_handler ) = 0;
52  virtual void notify_should_stop();
53  void join();
54 
55  sxe::SX_UNIQUE_PTR<sxe::thread> worker_;
56  mutable sxe::mutex mutex_;
57  bool run_;
58 
59 
60 };
61 
62 
63 }
64 
65 
66 #endif
Definition: event_collector.hpp:25
Definition: simple_state_base.hpp:24
bool should_stop() const
Definition: async_behavior.cpp:64
async_behavior()
Definition: async_behavior.cpp:26
void run(const event &_event, event_collector &_event_collector, const simple_state_base &_simple_state, async_event_handler &_async_event_handler)
Definition: async_behavior.cpp:42
virtual ~async_behavior() SX_NOEXCEPT
Definition: async_behavior.cpp:35
Interface of an event. An event has an ID, a name and a priority (for processing by the async state m...
Definition: event.hpp:28
Definition: async_event_handler.hpp:22
Definition: adapter_cpp11.hpp:21
Definition: join.hpp:24
void halt_and_join()
Definition: async_behavior.cpp:52
Definition: async_behavior.hpp:32