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,
54 Event_RegisterShortcut,
57 Event_CancelDestination,
58 Event_StartNavigation,
63 static const std::vector<std::string> api_list;
64 static const std::vector<std::string> event_list;
67 int init(const int port, const std::string& token);
69 int tapShortcut(const char* application_id);
70 int onScreenMessage(const char* display_message);
71 int onScreenReply(const char* reply_message);
73 void set_event_handler(enum EventType et, handler_func f);
74 void publishSubscription(void);
76 void registerCallback(
77 void (*event_cb)(const std::string& event, struct json_object* event_contents),
78 void (*reply_cb)(struct json_object* reply_contents),
79 void (*hangup_cb)(void) = nullptr);
81 int call(const std::string& verb, struct json_object* arg);
82 int call(const char* verb, struct json_object* arg);
83 int subscribe(const std::string& event_name);
84 int unsubscribe(const std::string& event_name);
86 int showWindow(const char* application_id, json_object* json);
87 int hideWindow(const char* application_id);
88 int replyShowWindow(const char* application_id, json_object* json);
89 int showNotification(json_object* json);
90 int showInformation(json_object* json);
91 int getRunnables(void);
92 int registerShortcut(const char* application_id, json_object* json);
93 int updateShortcut(const char* application_id, json_object* json);
96 int initialize_websocket();
97 int getEventType(const char *event);
99 void (*onEvent)(const std::string& event, struct json_object* event_contents);
100 void (*onReply)(struct json_object* reply);
101 void (*onHangup)(void);
103 struct afb_wsj1* sp_websock;
104 struct afb_wsj1_itf minterface;
109 std::string mtoken = "hs";
111 std::map<EventType, handler_func> handlers;
114 /* Don't use/ Internal only */
115 void on_hangup(void *closure, struct afb_wsj1 *wsj);
116 void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
117 void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
118 void on_reply(void *closure, struct afb_wsj1_msg *msg);
121 #endif /* LIBHOMESCREEN_H */