Luanti 5.16.0-dev
 
Loading...
Searching...
No Matches
sscsm_ievent.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Luanti authors
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#pragma once
6
7#include <memory>
8#include <type_traits>
9
11
12// Event triggered from the main env for the SSCSM env.
14{
15 virtual ~ISSCSMEvent() = default;
16
17 // Note: No return value (difference to ISSCSMRequest). These are not callbacks
18 // that you can run at arbitrary locations, because the untrusted code could
19 // then clobber your local variables.
20 virtual void exec(SSCSMEnvironment *cntrl) = 0;
21};
22
23// FIXME: actually serialize, and replace this with a string
24using SerializedSSCSMEvent = std::unique_ptr<ISSCSMEvent>;
25
26template <typename T>
28{
29 static_assert(std::is_base_of_v<ISSCSMEvent, T>);
30
31 return std::make_unique<T>(event);
32}
33
34inline std::unique_ptr<ISSCSMEvent> deserializeSSCSMEvent(SerializedSSCSMEvent event_serialized)
35{
36 // The actual deserialization will have to use a type tag, and then choose
37 // the appropriate deserializer.
38 return event_serialized;
39}
The thread that runs SSCSM code.
Definition sscsm_environment.h:26
std::unique_ptr< ISSCSMEvent > deserializeSSCSMEvent(SerializedSSCSMEvent event_serialized)
Definition sscsm_ievent.h:34
SerializedSSCSMEvent serializeSSCSMEvent(const T &event)
Definition sscsm_ievent.h:27
std::unique_ptr< ISSCSMEvent > SerializedSSCSMEvent
Definition sscsm_ievent.h:24
Definition sscsm_ievent.h:14
virtual void exec(SSCSMEnvironment *cntrl)=0
virtual ~ISSCSMEvent()=default