Sen API
Sen Libraries
Loading...
Searching...
No Matches
native_object_proxy.h
Go to the documentation of this file.
1// === native_object_proxy.h ===========================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_CORE_OBJ_DETAIL_NATIVE_OBJECT_PROXY_H
9#define SEN_CORE_OBJ_DETAIL_NATIVE_OBJECT_PROXY_H
10
11// sen
16#include "sen/core/meta/type.h"
20
21// std
22#include <memory>
23#include <mutex>
24
25namespace sen
26{
27
28// Forward declarations
29class NativeObject;
30
31namespace impl
32{
33
35class SEN_EXPORT NativeObjectProxy: public ProxyObject
36{
37 SEN_NOCOPY_NOMOVE(NativeObjectProxy)
38
39public: // special members
40 NativeObjectProxy(NativeObject* owner, std::string_view localPrefix);
41 ~NativeObjectProxy() override = default;
42
43public: // implements Object
44 [[nodiscard]] ObjectId getId() const noexcept final;
45 [[nodiscard]] const std::string& getName() const noexcept final;
46 [[nodiscard]] ConstTypeHandle<ClassType> getClass() const noexcept override;
47 [[nodiscard]] const ProxyObject* asProxyObject() const noexcept final;
48 [[nodiscard]] ProxyObject* asProxyObject() noexcept final;
49 [[nodiscard]] RemoteObject* asRemoteObject() noexcept final;
50 [[nodiscard]] const RemoteObject* asRemoteObject() const noexcept final;
51 [[nodiscard]] const std::string& getLocalName() const noexcept final;
52 [[nodiscard]] TimeStamp getLastCommitTime() const noexcept final;
53 [[nodiscard]] ConnectionGuard onEventUntyped(const Event* ev, EventCallback<VarList>&& callback) final;
54 [[nodiscard]] ConnectionGuard onPropertyChangedUntyped(const Property* prop, EventCallback<VarList>&& callback) final;
55 void invokeAllPropertyCallbacks() final;
56
57 // NOLINTNEXTLINE
58 void invokeUntyped(const Method* method, const VarList& args, MethodCallback<Var>&& onDone = {}) final;
59 [[nodiscard]] Var getPropertyUntyped(const Property* prop) const final;
60 void drainInputs() override;
61 bool isRemote() const noexcept final;
62
63protected: // called by the generated code
64 void sendWork(std::function<void()>&& work, bool forcePush) const;
65 virtual void drainInputsImpl(TimeStamp lastCommitTime) = 0;
66 [[nodiscard]] virtual Var senImplGetPropertyImpl(MemberHash propertyId) const = 0;
67 [[nodiscard]] ConnId senImplMakeConnectionId() const noexcept;
68 void senImplEventEmitted(MemberHash id, std::function<VarList()>&& argsGetter, const EventInfo& info) final;
69 void removeTypedConnectionOnOwner(ConnId connId);
70 void senImplRemoveUntypedConnection(ConnId id, MemberHash memberHash) override;
71
72private:
73 struct EventCallbackData
74 {
75 uint32_t id;
76 std::shared_ptr<EventCallback<VarList>> callback;
77 };
78
79 using EventCallbackList = std::vector<EventCallbackData>;
80
81 struct EventData
82 {
83 EventCallbackList list;
84 TransportMode transportMode;
85 };
86
87 using EventCallbackMap = std::unordered_map<MemberHash, EventData>;
88
89private:
90 NativeObject* owner_;
91 std::shared_ptr<Object> guard_;
92 std::string localName_;
93 TimeStamp lastCommitTime_;
94 std::unique_ptr<EventCallbackMap> eventCallbacks_;
95 std::recursive_mutex eventCallbacksMutex_;
96};
97
98} // namespace impl
99
100} // namespace sen
101
102#endif // SEN_CORE_OBJ_DETAIL_NATIVE_OBJECT_PROXY_H
An object instantiated in this process. This is the base class for all user-implemented objects.
Definition native_object.h:63
TransportMode
How to transport information.
Definition type.h:56
Definition assert.h:17