Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
JniAdapter.hpp
Go to the documentation of this file.
1#pragma once
2
41
42#include "aria/abi/export.hpp"
44#include "aria/subscription.hpp"
45
46#include <jni.h>
47
48#include <cstdint>
49#include <functional>
50#include <memory>
51#include <string>
52#include <string_view>
53
55
56// ─── View wrapper ───────────────────────────────────────────────────────
57
61public:
64 JniView(JNIEnv* env, jobject view);
65
66 ~JniView() override;
67
68 JniView(const JniView&) = delete;
69 JniView& operator=(const JniView&) = delete;
70
74 [[nodiscard]] std::string_view kind() const noexcept override { return "android"; }
75
77 [[nodiscard]] jobject native() const noexcept { return view_; }
78
79private:
80 JavaVM* vm_ = nullptr; // cached to obtain a JNIEnv at destruction time
81 jobject view_; // JNI global reference
82};
83
84// ─── Adapter ────────────────────────────────────────────────────────────
85
91public:
93 explicit JniAdapter(JNIEnv* env);
94
95 ~JniAdapter() override;
96
97 JniAdapter(const JniAdapter&) = delete;
98 JniAdapter& operator=(const JniAdapter&) = delete;
99
100 [[nodiscard]] std::string_view platform_name() const noexcept override {
101 return "android";
102 }
103
104 // ── Text ────────────────────────────────────────────────────────────
105 void set_text(::aria::binding::IView& v, std::string_view text) override;
106 [[nodiscard]] std::string get_text(::aria::binding::IView& v) override;
108 std::function<void(std::string_view)> cb) override;
109
110 // ── Bool ────────────────────────────────────────────────────────────
111 void set_bool(::aria::binding::IView& v, bool value) override;
112 [[nodiscard]] bool get_bool(::aria::binding::IView& v) override;
114 std::function<void(bool)> cb) override;
115
116 // ── Int ─────────────────────────────────────────────────────────────
117 void set_int(::aria::binding::IView& v, int value) override;
118 [[nodiscard]] int get_int(::aria::binding::IView& v) override;
120 std::function<void(int)> cb) override;
121
122 void set_int64(::aria::binding::IView& v, std::int64_t value) override;
123 [[nodiscard]] std::int64_t get_int64(::aria::binding::IView& v) override;
125 std::function<void(std::int64_t)> cb) override;
126
127 void set_uint64(::aria::binding::IView& v, std::uint64_t value) override;
128 [[nodiscard]] std::uint64_t get_uint64(::aria::binding::IView& v) override;
130 std::function<void(std::uint64_t)> cb) override;
131
132 void set_float(::aria::binding::IView& v, float value) override;
133 [[nodiscard]] float get_float(::aria::binding::IView& v) override;
135 std::function<void(float)> cb) override;
136
137 // ── Double ──────────────────────────────────────────────────────────
138 void set_double(::aria::binding::IView& v, double value) override;
139 [[nodiscard]] double get_double(::aria::binding::IView& v) override;
141 std::function<void(double)> cb) override;
142
143 // ── Visibility / enabled ────────────────────────────────────────────
144 void set_visible(::aria::binding::IView& v, bool visible) override;
145 void set_enabled(::aria::binding::IView& v, bool enabled) override;
146
147 // ── Click ───────────────────────────────────────────────────────────
149 std::function<void()> cb) override;
150
151 // ── Java/Kotlin event ingress ───────────────────────────────────────
152 // Android listeners live on the managed side. They call these methods
153 // from JNI to fan a native View event into the subscriptions installed
154 // by on_*_changed / on_click. Pass the same JniView wrapper that was
155 // bound through BindingEngine; notifications for unbound channels are
156 // harmless no-ops.
157 void notify_text_changed(::aria::binding::IView& v, std::string_view value);
160 void notify_int64_changed(::aria::binding::IView& v, std::int64_t value);
161 void notify_uint64_changed(::aria::binding::IView& v, std::uint64_t value);
165
166private:
167 struct Impl;
168 std::shared_ptr<Impl> p_;
169};
170
171} // namespace aria::adapters::jni
RAII handle to a single subscription.
Definition subscription.hpp:44
::aria::Subscription on_float_changed(::aria::binding::IView &v, std::function< void(float)> cb) override
std::string get_text(::aria::binding::IView &v) override
void set_uint64(::aria::binding::IView &v, std::uint64_t value) override
std::int64_t get_int64(::aria::binding::IView &v) override
std::uint64_t get_uint64(::aria::binding::IView &v) override
void notify_float_changed(::aria::binding::IView &v, float value)
void set_visible(::aria::binding::IView &v, bool visible) override
JniAdapter(const JniAdapter &)=delete
void set_double(::aria::binding::IView &v, double value) override
void notify_uint64_changed(::aria::binding::IView &v, std::uint64_t value)
::aria::Subscription on_double_changed(::aria::binding::IView &v, std::function< void(double)> cb) override
JniAdapter & operator=(const JniAdapter &)=delete
void set_bool(::aria::binding::IView &v, bool value) override
void notify_double_changed(::aria::binding::IView &v, double value)
::aria::Subscription on_int64_changed(::aria::binding::IView &v, std::function< void(std::int64_t)> cb) override
float get_float(::aria::binding::IView &v) override
::aria::Subscription on_click(::aria::binding::IView &v, std::function< void()> cb) override
void notify_int_changed(::aria::binding::IView &v, int value)
double get_double(::aria::binding::IView &v) override
void set_text(::aria::binding::IView &v, std::string_view text) override
void notify_text_changed(::aria::binding::IView &v, std::string_view value)
void set_float(::aria::binding::IView &v, float value) override
int get_int(::aria::binding::IView &v) override
void notify_click(::aria::binding::IView &v)
std::string_view platform_name() const noexcept override
Definition JniAdapter.hpp:100
void notify_int64_changed(::aria::binding::IView &v, std::int64_t value)
void set_int(::aria::binding::IView &v, int value) override
void set_int64(::aria::binding::IView &v, std::int64_t value) override
::aria::Subscription on_uint64_changed(::aria::binding::IView &v, std::function< void(std::uint64_t)> cb) override
::aria::Subscription on_int_changed(::aria::binding::IView &v, std::function< void(int)> cb) override
void notify_bool_changed(::aria::binding::IView &v, bool value)
bool get_bool(::aria::binding::IView &v) override
::aria::Subscription on_text_changed(::aria::binding::IView &v, std::function< void(std::string_view)> cb) override
void set_enabled(::aria::binding::IView &v, bool enabled) override
::aria::Subscription on_bool_changed(::aria::binding::IView &v, std::function< void(bool)> cb) override
JniView & operator=(const JniView &)=delete
jobject native() const noexcept
Access the underlying JNI global-ref jobject.
Definition JniAdapter.hpp:77
JniView(const JniView &)=delete
std::string_view kind() const noexcept override
Reported as "android" — this is the runtime platform name, used by BindingEngine for adapter routing ...
Definition JniAdapter.hpp:74
JniView(JNIEnv *env, jobject view)
Construct from a JNI jobject (Android View).
Abstract platform adapter — knows how to read/write/observe widgets.
Definition view_adapter.hpp:80
Abstract platform widget reference.
Definition view_adapter.hpp:28
#define ARIA_JNI_API
Definition export.hpp:75
JniAdapter — Android JNI implementation of aria::binding::IViewAdapter.
Definition JniAdapter.hpp:54