@geastack/host 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/host/background.cpp +12 -0
- package/host/display.cpp +23 -0
- package/host/http.cpp +236 -32
- package/host/imu.cpp +25 -0
- package/host/local_notifications_apple.mm +199 -0
- package/host/media.cpp +63 -0
- package/host/menu_bar_apple.mm +15 -0
- package/include/gea/embedded-host.h +4 -0
- package/include/host/backends.h +9 -0
- package/include/host/background.h +34 -0
- package/include/host/display.h +3 -0
- package/include/host/http.h +83 -1
- package/include/host/local_notifications.h +56 -0
- package/include/host/media.h +115 -6
- package/include/host/navigator.h +9 -1
- package/include/host/notification_relay.h +84 -0
- package/include/host/phone_link.h +173 -0
- package/package.json +1 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
// Phone notification sync, device side (`PhoneLink` in @geastack/core).
|
|
5
|
+
//
|
|
6
|
+
// Two layers:
|
|
7
|
+
// - PhoneLinkDriver: the platform's BLE work (ANCS client for iPhone, the
|
|
8
|
+
// Relay GATT service for the Android companion). The base class IS the
|
|
9
|
+
// unsupported driver; a platform installs its own with setPhoneLinkDriver().
|
|
10
|
+
// - The event queue below, shared by every platform. A driver posts events
|
|
11
|
+
// from its BLE task with phone_link::post(); the app drains them on the
|
|
12
|
+
// frame task through PhoneLink.next() and reads the current slot.
|
|
13
|
+
//
|
|
14
|
+
// Header-only so no target's source list has to change for the surface to link.
|
|
15
|
+
|
|
16
|
+
#include <cstdint>
|
|
17
|
+
#include <deque>
|
|
18
|
+
#include <mutex>
|
|
19
|
+
#include <string>
|
|
20
|
+
|
|
21
|
+
namespace gea::host {
|
|
22
|
+
|
|
23
|
+
namespace phone_link {
|
|
24
|
+
|
|
25
|
+
enum class EventKind : std::uint8_t { Added = 0, Modified = 1, Removed = 2 };
|
|
26
|
+
|
|
27
|
+
struct Event {
|
|
28
|
+
EventKind kind = EventKind::Added;
|
|
29
|
+
std::uint32_t uid = 0;
|
|
30
|
+
std::string appId;
|
|
31
|
+
std::string appName;
|
|
32
|
+
std::string title;
|
|
33
|
+
std::string subtitle;
|
|
34
|
+
std::string message;
|
|
35
|
+
double time = 0; // epoch ms in the phone's local time, 0 = unknown
|
|
36
|
+
int category = 0; // ANCS CategoryID
|
|
37
|
+
int flags = 0; // ANCS EventFlags
|
|
38
|
+
std::string positiveLabel;
|
|
39
|
+
std::string negativeLabel;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Oldest events are dropped past this many; a phone reconnecting after a long
|
|
43
|
+
// gap replays its pre-existing notifications and must not exhaust RAM.
|
|
44
|
+
inline constexpr std::size_t kMaxQueuedEvents = 48;
|
|
45
|
+
|
|
46
|
+
namespace detail {
|
|
47
|
+
struct Queue {
|
|
48
|
+
std::mutex lock;
|
|
49
|
+
std::deque<Event> pending;
|
|
50
|
+
Event current;
|
|
51
|
+
std::uint32_t seq = 0;
|
|
52
|
+
};
|
|
53
|
+
inline Queue &queue() {
|
|
54
|
+
static Queue q;
|
|
55
|
+
return q;
|
|
56
|
+
}
|
|
57
|
+
} // namespace detail
|
|
58
|
+
|
|
59
|
+
// Thread-safe: call from the BLE host task.
|
|
60
|
+
inline void post(Event event) {
|
|
61
|
+
auto &q = detail::queue();
|
|
62
|
+
std::lock_guard<std::mutex> guard(q.lock);
|
|
63
|
+
if (q.pending.size() >= kMaxQueuedEvents) q.pending.pop_front();
|
|
64
|
+
q.pending.push_back(std::move(event));
|
|
65
|
+
q.seq++;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Drop everything queued (e.g. the phone was forgotten).
|
|
69
|
+
inline void clear() {
|
|
70
|
+
auto &q = detail::queue();
|
|
71
|
+
std::lock_guard<std::mutex> guard(q.lock);
|
|
72
|
+
q.pending.clear();
|
|
73
|
+
q.current = Event{};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
inline bool next() {
|
|
77
|
+
auto &q = detail::queue();
|
|
78
|
+
std::lock_guard<std::mutex> guard(q.lock);
|
|
79
|
+
if (q.pending.empty()) return false;
|
|
80
|
+
q.current = std::move(q.pending.front());
|
|
81
|
+
q.pending.pop_front();
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
inline double seq() {
|
|
86
|
+
auto &q = detail::queue();
|
|
87
|
+
std::lock_guard<std::mutex> guard(q.lock);
|
|
88
|
+
return static_cast<double>(q.seq);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The current slot is only written by next(), which runs on the frame task, so
|
|
92
|
+
// the getters read it without the lock.
|
|
93
|
+
inline const Event ¤t() {
|
|
94
|
+
return detail::queue().current;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
} // namespace phone_link
|
|
98
|
+
|
|
99
|
+
class PhoneLinkDriver {
|
|
100
|
+
public:
|
|
101
|
+
virtual ~PhoneLinkDriver() = default;
|
|
102
|
+
virtual void start(const std::string &name) { (void)name; }
|
|
103
|
+
virtual void stop() {}
|
|
104
|
+
// "unsupported", "off", "advertising", "pairing", "connected" or "ready".
|
|
105
|
+
virtual std::string state() { return "unsupported"; }
|
|
106
|
+
// "ios", "android" or "".
|
|
107
|
+
virtual std::string platform() { return ""; }
|
|
108
|
+
virtual std::string peerName() { return ""; }
|
|
109
|
+
virtual std::string passkey() { return ""; }
|
|
110
|
+
virtual void forget() {}
|
|
111
|
+
virtual double phoneTime() { return 0; }
|
|
112
|
+
virtual void performAction(std::uint32_t uid, bool positive) {
|
|
113
|
+
(void)uid;
|
|
114
|
+
(void)positive;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
namespace phone_link::detail {
|
|
119
|
+
inline PhoneLinkDriver *&driverSlot() {
|
|
120
|
+
static PhoneLinkDriver unsupported;
|
|
121
|
+
static PhoneLinkDriver *driver = &unsupported;
|
|
122
|
+
return driver;
|
|
123
|
+
}
|
|
124
|
+
} // namespace phone_link::detail
|
|
125
|
+
|
|
126
|
+
inline void setPhoneLinkDriver(PhoneLinkDriver *driver) {
|
|
127
|
+
if (driver) phone_link::detail::driverSlot() = driver;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
inline PhoneLinkDriver &phoneLinkDriver() {
|
|
131
|
+
return *phone_link::detail::driverSlot();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
struct PhoneLinkFacade {
|
|
135
|
+
void start(const std::string &name) const { phoneLinkDriver().start(name); }
|
|
136
|
+
void stop() const { phoneLinkDriver().stop(); }
|
|
137
|
+
std::string state() const { return phoneLinkDriver().state(); }
|
|
138
|
+
std::string platform() const { return phoneLinkDriver().platform(); }
|
|
139
|
+
std::string peerName() const { return phoneLinkDriver().peerName(); }
|
|
140
|
+
std::string passkey() const { return phoneLinkDriver().passkey(); }
|
|
141
|
+
void forget() const {
|
|
142
|
+
phoneLinkDriver().forget();
|
|
143
|
+
phone_link::clear();
|
|
144
|
+
}
|
|
145
|
+
double phoneTime() const { return phoneLinkDriver().phoneTime(); }
|
|
146
|
+
double seq() const { return phone_link::seq(); }
|
|
147
|
+
bool next() const { return phone_link::next(); }
|
|
148
|
+
std::string kind() const {
|
|
149
|
+
switch (phone_link::current().kind) {
|
|
150
|
+
case phone_link::EventKind::Modified: return "modified";
|
|
151
|
+
case phone_link::EventKind::Removed: return "removed";
|
|
152
|
+
default: return "added";
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
double uid() const { return static_cast<double>(phone_link::current().uid); }
|
|
156
|
+
std::string appId() const { return phone_link::current().appId; }
|
|
157
|
+
std::string appName() const { return phone_link::current().appName; }
|
|
158
|
+
std::string title() const { return phone_link::current().title; }
|
|
159
|
+
std::string subtitle() const { return phone_link::current().subtitle; }
|
|
160
|
+
std::string message() const { return phone_link::current().message; }
|
|
161
|
+
double time() const { return phone_link::current().time; }
|
|
162
|
+
double category() const { return static_cast<double>(phone_link::current().category); }
|
|
163
|
+
double flags() const { return static_cast<double>(phone_link::current().flags); }
|
|
164
|
+
std::string positiveLabel() const { return phone_link::current().positiveLabel; }
|
|
165
|
+
std::string negativeLabel() const { return phone_link::current().negativeLabel; }
|
|
166
|
+
void performAction(double uid, bool positive) const {
|
|
167
|
+
phoneLinkDriver().performAction(static_cast<std::uint32_t>(uid), positive);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
inline constexpr PhoneLinkFacade PhoneLink{};
|
|
172
|
+
|
|
173
|
+
} // namespace gea::host
|