8#ifndef SEN_CORE_OBJ_DETAIL_NATIVE_OBJECT_IMPL_H
9#define SEN_CORE_OBJ_DETAIL_NATIVE_OBJECT_IMPL_H
34class NativeObjectProxy;
35class FilteredProvider;
42class PipelineComponent;
45namespace sen::kernel::impl
47class RemoteParticipant;
48class LocalParticipant;
61using BufferProvider = std::function<ResizableBufferWriter<FixedMemoryBlock>(std::size_t)>;
74void writePropertyToStream(uint32_t
id,
MaybeRef<T> val, BufferProvider provider);
82 SerializationTraits<T>::write(out,
toValue<T>(var));
91inline void dispatchIfChanged(PropertyFlags& flags,
92 EventBuffer<>& eventBuffer,
99 if (flags.changedInLastCycle())
101 eventBuffer.dispatch(propertyId,
time, objectId, transport,
false,
nullptr, producer);
105inline void unconditionalDispatch(EventBuffer<>& eventBuffer,
112 eventBuffer.dispatch(propertyId,
time, objectId, transport,
false,
nullptr, producer);
116inline void writePropertyIfChanged(PropertyFlags& flags, uint32_t propertyId,
OutputStream& out,
MaybeRef<T> val)
118 if (flags.changedInLastCycle())
120 writePropertyToStream<T>(propertyId, val, out);
125inline void writePropertyIfChanged(PropertyFlags& flags, uint32_t propertyId, BufferProvider provider,
MaybeRef<T> val)
127 if (flags.changedInLastCycle())
129 writePropertyToStream<T>(propertyId, val, provider);
134T getFromMap(
const std::string& name,
const VarMap& map, std::function<
void(
const T&)> validator =
nullptr);
137void tryGetFromMap(
const std::string& name,
140 std::function<
void(
const T&)> validator =
nullptr);
142struct FieldValueGetter
145 const impl::PropertyFlags* flags =
nullptr;
160 out.writeUInt32(valueSize);
161 SerializationTraits<T>::write(out, val);
167 writePropertyToStream<T>(
id, SerializationTraits<T>::serializedSize(val), val, out);
171inline void writePropertyToStream(uint32_t
id,
MaybeRef<T> val, BufferProvider provider)
173 const auto valueSize = SerializationTraits<T>::serializedSize(val);
175 auto writer = provider(getSerializedSize(
id) + getSerializedSize(valueSize));
178 writePropertyToStream<T>(
id, valueSize, val, out);
185 SerializationTraits<T>::read(in, result);
190inline T getFromMap(
const std::string& name,
const VarMap& map, std::function<
void(
const T&)> validator)
194 validator = [](
const T&) {};
197 auto itr = map.find(name);
198 if (itr == map.end())
201 err.append(
"could not find mandatory item '");
203 err.append(
"' in map");
214inline void tryGetFromMap(
const std::string& name,
const VarMap& map, T& val, std::function<
void(
const T&)> validator)
218 validator = [](
const T&) {};
221 auto itr = map.find(name);
222 if (itr != map.end())
226#if SEN_GCC_VERSION_CHECK_SMALLER(12, 0, 0)
227# pragma GCC diagnostic push
228# pragma GCC diagnostic ignored "-Wstringop-overflow"
231# pragma GCC diagnostic pop
API for objects when registered.
Definition component_api.h:170
What can be done while a component is running.
Definition component_api.h:224
void throwRuntimeError(const std::string &err)
Throws std::exception that attempts to collect the stack trace. We also wrap it to avoid including st...
InputStreamTemplate< LittleEndian > InputStream
Definition input_stream.h:84
Var toVariant(const T &val)
Definition core/include/sen/core/io/util.h:160
T toValue(const Var &var)
Definition core/include/sen/core/io/util.h:152
std::function< Value()> ValueGetter
Gets a value from some source.
Definition vm.h:78
#define SEN_UNREACHABLE()
Definition compiler_macros.h:420
std::conditional_t< std::is_arithmetic_v< T >||shouldBePassedByValueV< T >, T, AddConstRef< T > > MaybeRef
returns 'const T&' or 'T' depending on the type
Definition class_helpers.h:46
std::map< std::string, Var, std::less<> > VarMap
A map of vars to represent structures.
Definition var.h:107
@ time
Definition unit.h:34
TransportMode
How to transport information.
Definition type.h:56
Strong type for the unique identifier for a transport timer.
Definition native_object_impl.h:39
OutputStreamTemplate< LittleEndian > OutputStream
Definition output_stream.h:64