event_local.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include "event.h"
  3. #include "scheduler_cookie.h"
  4. #include "event_load.h"
  5. #include <util/system/type_name.h>
  6. namespace NActors {
  7. template <typename TEv, ui32 TEventType>
  8. class TEventLocal: public TEventBase<TEv, TEventType> {
  9. public:
  10. TString ToStringHeader() const override {
  11. return TypeName<TEv>();
  12. }
  13. bool SerializeToArcadiaStream(TChunkSerializer* /*serializer*/) const override {
  14. Y_ABORT("Serialization of local event %s type %" PRIu32, TypeName<TEv>().data(), TEventType);
  15. }
  16. bool IsSerializable() const override {
  17. return false;
  18. }
  19. static IEventBase* Load(TEventSerializedData*) {
  20. Y_ABORT("Loading of local event %s type %" PRIu32, TypeName<TEv>().data(), TEventType);
  21. }
  22. };
  23. template <typename TEv, ui32 TEventType>
  24. class TEventScheduler: public TEventLocal<TEv, TEventType> {
  25. public:
  26. TSchedulerCookieHolder Cookie;
  27. TEventScheduler(ISchedulerCookie* cookie)
  28. : Cookie(cookie)
  29. {
  30. }
  31. };
  32. template <ui32 TEventType>
  33. class TEventSchedulerEv: public TEventScheduler<TEventSchedulerEv<TEventType>, TEventType> {
  34. public:
  35. TEventSchedulerEv(ISchedulerCookie* cookie)
  36. : TEventScheduler<TEventSchedulerEv<TEventType>, TEventType>(cookie)
  37. {
  38. }
  39. };
  40. template <typename TEv, ui32 TEventType>
  41. class TEventSimple: public TEventBase<TEv, TEventType> {
  42. public:
  43. TString ToStringHeader() const override {
  44. static TString header(TypeName<TEv>());
  45. return header;
  46. }
  47. bool SerializeToArcadiaStream(TChunkSerializer* /*serializer*/) const override {
  48. static_assert(sizeof(TEv) == sizeof(TEventSimple<TEv, TEventType>), "Descendant should be an empty class");
  49. return true;
  50. }
  51. bool IsSerializable() const override {
  52. return true;
  53. }
  54. static IEventBase* Load(NActors::TEventSerializedData*) {
  55. return new TEv();
  56. }
  57. static IEventBase* Load(const TString&) {
  58. return new TEv();
  59. }
  60. };
  61. }