aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/core/event_local.h
blob: f337b39fbe21739607e195a05d467e8f67475bf6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once

#include "event.h"
#include "scheduler_cookie.h"
#include "event_load.h"
#include <util/system/type_name.h>

namespace NActors {
    template <typename TEv, ui32 TEventType>
    class TEventLocal: public TEventBase<TEv, TEventType> {
    public:
        TString ToStringHeader() const override {
            return TypeName<TEv>();
        }

        bool SerializeToArcadiaStream(TChunkSerializer* /*serializer*/) const override {
            Y_FAIL("Serialization of local event %s type %" PRIu32, TypeName<TEv>().data(), TEventType);
        }

        bool IsSerializable() const override {
            return false;
        }

        static IEventBase* Load(TEventSerializedData*) {
            Y_FAIL("Loading of local event %s type %" PRIu32, TypeName<TEv>().data(), TEventType);
        }
    };

    template <typename TEv, ui32 TEventType>
    class TEventScheduler: public TEventLocal<TEv, TEventType> {
    public:
        TSchedulerCookieHolder Cookie;

        TEventScheduler(ISchedulerCookie* cookie)
            : Cookie(cookie)
        {
        }
    };

    template <ui32 TEventType>
    class TEventSchedulerEv: public TEventScheduler<TEventSchedulerEv<TEventType>, TEventType> {
    public:
        TEventSchedulerEv(ISchedulerCookie* cookie)
            : TEventScheduler<TEventSchedulerEv<TEventType>, TEventType>(cookie)
        {
        }
    };

    template <typename TEv, ui32 TEventType>
    class TEventSimple: public TEventBase<TEv, TEventType> { 
    public:
        TString ToStringHeader() const override {
            static TString header(TypeName<TEv>());
            return header;
        }

        bool SerializeToArcadiaStream(TChunkSerializer* /*serializer*/) const override {
            static_assert(sizeof(TEv) == sizeof(TEventSimple<TEv, TEventType>), "Descendant should be an empty class");
            return true;
        }

        bool IsSerializable() const override {
            return true;
        }

        static IEventBase* Load(NActors::TEventSerializedData*) {
            return new TEv();
        }

        static IEventBase* Load(const TString&) {
            return new TEv();
        }
    };
}