SEGS  0.6.1-develop [d2cac982]
Super Entity Game Server
EventProcessor.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2019 SEGS Team (see AUTHORS.md)
5  * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
6  */
7 
8 #pragma once
9 #include "SEGSEvent.h"
10 #include <ace/Task_Ex_T.h>
11 #include <iosfwd>
12 // Independent Task, each EventProcessor when activated dequeues SEGSEvents,
13 // and dispatches them
14 class EventSrc : public ACE_Task_Ex<ACE_MT_SYNCH,SEGSEvents::Event>
15 {
16 public:
17  using ACE_Task_Ex<ACE_MT_SYNCH,SEGSEvents::Event>::ACE_Task_Ex;
18 };
22 class EventProcessor : public EventSrc
23 {
24 using super = EventSrc;
25 
26 
27  int svc() final;
28 public:
29  int handle_timeout(const ACE_Time_Value &current_time, const void *act /* = 0 */) override final;
30  int open(void *args = nullptr) override;
31  int process_single_event();
32 virtual int putq(SEGSEvents::Event *ev, ACE_Time_Value *timeout=nullptr);
33 virtual uint64_t get_id() const = 0;
34 protected:
37 virtual bool per_thread_startup() { return true; }
38 virtual void per_thread_shutdown() { ; }
39 
40 virtual void dispatch(SEGSEvents::Event *ev)=0;
41 virtual void serialize_from(std::istream &is) = 0;
42 virtual void serialize_to(std::ostream &is) = 0;
43 };
44 #define IMPL_ID(EventProcessorChildType)\
45  enum : uint64_t { processor_id = CompileTimeUtils::hash_64_fnv1a_const(#EventProcessorChildType) };\
46  uint64_t get_id() const override { return processor_id; }
47 
49 {
50  if(ep && ep->thr_count())
51  {
52  ep->putq(SEGSEvents::Finish::s_instance->shallow_copy());
53  ep->wait();
54  }
55 }
Definition: EventProcessor.h:14
Definition: SEGSEvent.h:35
virtual bool per_thread_startup()
Definition: EventProcessor.h:37
static Finish * s_instance
Definition: SEGSEvent.h:96
void shutdown_event_processor_and_wait(EventProcessor *ep)
Definition: EventProcessor.h:48
virtual void per_thread_shutdown()
Definition: EventProcessor.h:38
Definition: EventProcessor.h:22
virtual int putq(SEGSEvents::Event *ev, ACE_Time_Value *timeout=nullptr)
Definition: EventProcessor.cpp:88