1 #define KOALA_INTEROP_MODULE ArkUINativeModule
2
3 #include <deque>
4 #include <stdexcept>
5 #include "events.h"
6 #include "common-interop.h"
7 #include "interop-types.h"
8 #include "securec.h"
9
10 static std::deque<EventBuffer> eventQueue;
11
sendEvent(const EventBuffer * event)12 void sendEvent(const EventBuffer* event) {
13 eventQueue.push_back(*event);
14 }
15
impl_CheckArkoalaGeneratedEvents(KByte * result,KInt size)16 KInt impl_CheckArkoalaGeneratedEvents(KByte* result, KInt size) {
17 if (((size_t)size) < sizeof(EventBuffer::buffer))
18 INTEROP_FATAL("Expected buffer size be not less than sizeof(EventBuffer) bytes");
19
20 if (!eventQueue.size())
21 return 0;
22
23 if (memcpy_s(result, sizeof(EventBuffer::buffer), eventQueue.front().buffer,
24 sizeof(EventBuffer::buffer)) != 0) {
25 return 0;
26 }
27 eventQueue.pop_front();
28 return 1;
29 }
KOALA_INTEROP_2(CheckArkoalaGeneratedEvents,KInt,KByte *,KInt)30 KOALA_INTEROP_2(CheckArkoalaGeneratedEvents, KInt, KByte*, KInt)
31
32 KInt impl_InjectEvent(KByte* data, KInt size) {
33 if ((size_t)size >= sizeof(EventBuffer::buffer))
34 return 0;
35
36 EventBuffer event;
37 if (memcpy_s(event.buffer, sizeof(EventBuffer::buffer), data, size) != 0) {
38 return 0;
39 }
40
41 sendEvent(&event);
42 return 1;
43 }
KOALA_INTEROP_2(InjectEvent,KInt,KByte *,KInt)44 KOALA_INTEROP_2(InjectEvent, KInt, KByte*, KInt)
45
46 void impl_EmulateTextInputEvent(KInt nodeId, const KStringPtr& text) {
47 }
48 // KOALA_INTEROP_V2(EmulateTextInputEvent, KInt, KStringPtr) // TODO Where to place it?
49