2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef LIBHOMESCREEN_H
18 #define LIBHOMESCREEN_H
23 #include <json-c/json.h>
24 #include <systemd/sd-event.h>
27 #include <afb/afb-wsj1.h>
28 #include <afb/afb-ws-client.h>
37 LibHomeScreen(const LibHomeScreen &) = delete;
38 LibHomeScreen &operator=(const LibHomeScreen &) = delete;
40 using handler_func = std::function<void(json_object*)>;
45 Event_TapShortcut = 1,
46 Event_OnScreenMessage,
49 Event_ReplyShowWindow,
50 Event_ShowNotification,
51 Event_ShowInformation,
56 static const std::vector<std::string> api_list;
57 static const std::vector<std::string> event_list;
60 int init(const int port, const std::string& token);
62 int tapShortcut(const char* application_id);
63 int onScreenMessage(const char* display_message);
64 int onScreenReply(const char* reply_message);
66 void set_event_handler(enum EventType et, handler_func f);
68 void registerCallback(
69 void (*event_cb)(const std::string& event, struct json_object* event_contents),
70 void (*reply_cb)(struct json_object* reply_contents),
71 void (*hangup_cb)(void) = nullptr);
73 int call(const std::string& verb, struct json_object* arg);
74 int call(const char* verb, struct json_object* arg);
75 int subscribe(const std::string& event_name);
76 int unsubscribe(const std::string& event_name);
78 int showWindow(const char* application_id, json_object* json);
79 int hideWindow(const char* application_id);
80 int replyShowWindow(const char* application_id, json_object* json);
81 int showNotification(json_object* json);
82 int showInformation(json_object* json);
83 int getRunnables(void);
87 int initialize_websocket();
89 void (*onEvent)(const std::string& event, struct json_object* event_contents);
90 void (*onReply)(struct json_object* reply);
91 void (*onHangup)(void);
93 struct afb_wsj1* sp_websock;
94 struct afb_wsj1_itf minterface;
99 std::string mtoken = "hs";
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 */