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 // Held by shared_ptr: senImplEventEmitted queues work items that capture this and may
74 // run after senImplRemoveUntypedConnection erases the slot.
75 struct PropertyCallbackData
76 {
77 uint32_t id;
78 std::shared_ptr<EventCallback<VarList>> callback;
79 };
80
81 using PropertyCallbackList = std::vector<PropertyCallbackData>;
82
83 struct PropertyData
84 {
85 PropertyCallbackList list;
86 TransportMode transportMode;
87 };
88
89 using PropertyCallbackMap = std::unordered_map<MemberHash, PropertyData>;
90
91private:
92 NativeObject* owner_;
93 std::shared_ptr<Object> guard_;
94 std::string localName_;
95 TimeStamp lastCommitTime_;
96 std::unique_ptr<PropertyCallbackMap> propertyCallbacks_;
97 std::recursive_mutex propertyCallbacksMutex_;
98};
99
100} // namespace impl
101
102} // namespace sen
103
104#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