2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3 * Copyright (c) 2018,2019 TOYOTA MOTOR CORPORATION
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #ifndef LIBHOMESCREEN_H
19 #define LIBHOMESCREEN_H
24 #include <json-c/json.h>
25 #include <systemd/sd-event.h>
28 #include <afb/afb-wsj1.h>
29 #include <afb/afb-ws-client.h>
38 LibHomeScreen(const LibHomeScreen &) = delete;
39 LibHomeScreen &operator=(const LibHomeScreen &) = delete;
41 using handler_func = std::function<void(json_object*)>;
46 Event_TapShortcut = 1,
47 Event_OnScreenMessage,
50 Event_ReplyShowWindow,
51 Event_ShowNotification,
52 Event_ShowInformation,
57 static const std::vector<std::string> api_list;
58 static const std::vector<std::string> event_list;
61 int init(const char *hostname, const int port, const char *token);
62 int init(const int port, const std::string& token);
64 int tapShortcut(const char* application_id);
65 int onScreenMessage(const char* display_message);
66 int onScreenReply(const char* reply_message);
68 void set_event_handler(enum EventType et, handler_func f);
70 void registerCallback(
71 void (*event_cb)(const std::string& event, struct json_object* event_contents),
72 void (*reply_cb)(struct json_object* reply_contents),
73 void (*hangup_cb)(void) = nullptr);
75 int call(const std::string& verb, struct json_object* arg);
76 int call(const char* verb, struct json_object* arg);
77 int subscribe(const std::string& event_name);
78 int unsubscribe(const std::string& event_name);
80 int showWindow(const char* application_id, json_object* json);
81 int hideWindow(const char* application_id);
82 int replyShowWindow(const char* application_id, json_object* json);
83 int showNotification(json_object* json);
84 int showInformation(json_object* json);
85 int getRunnables(void);
89 int initialize_websocket();
90 int initialize_websocket(const char *hostname, const int port, const char *token);
92 void (*onEvent)(const std::string& event, struct json_object* event_contents);
93 void (*onReply)(struct json_object* reply);
94 void (*onHangup)(void);
96 struct afb_wsj1* sp_websock;
97 struct afb_wsj1_itf minterface;
101 std::map<EventType, handler_func> handlers;
104 /* Don't use/ Internal only */
105 void on_hangup(void *closure, struct afb_wsj1 *wsj);
106 void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
107 void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
108 void on_reply(void *closure, struct afb_wsj1_msg *msg);
111 #endif /* LIBHOMESCREEN_H */