test
[apps/homescreen.git] / src / gst-wayland-demo.hpp
1 /*
2  * Copyright (c) 2017 Panasonic Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 #ifndef GST_WAYLAND_HPP
23 #define GST_WAYLAND_HPP
24
25 #include <string>
26 #include <vector>
27 #include <map>
28 #include <algorithm>
29
30 #include <gio/gio.h>
31
32 #include <ilm/ilm_control.h>
33 #include <ilm/ilm_input.h>
34
35 #include <libwindowmanager.h>
36 #include <libhomescreen.hpp>
37
38 #define AGL_FATAL(fmt, ...) fatal("ERROR: " fmt "\n", ##__VA_ARGS__)
39 #define AGL_WARN(fmt, ...) warn("WARNING: " fmt "\n", ##__VA_ARGS__)
40 #define AGL_DEBUG(fmt, ...) debug("DEBUG: " fmt "\n", ##__VA_ARGS__)
41 #define AGL_TRACE(file,line) debug("%s:%d\n", file,line);
42
43 void fatal (const char* format, ...);
44 void warn (const char* format, ...);
45 void debug (const char* format, ...);
46
47 struct Carla_Info {
48   std::string yaw;
49   double longitude;
50   double latitude;
51   int speed;
52 };
53
54 class ILMControl
55 {
56   public:
57     ILMControl(notificationFunc callback, void *user_data) {
58         ilm_init();
59         ilm_registerNotification(callback, user_data);
60     }
61
62     ~ILMControl(void) {
63         ilm_unregisterNotification();
64         ilm_destroy();
65         AGL_DEBUG("ilm_destory().\n");
66     }
67 };
68
69 class RunXDG
70 {
71   public:
72     RunXDG(int port, const char* token, const char* id);
73
74     void start(void);
75     void notify_ivi_control_cb(ilmObjectType object, t_ilm_uint id,
76                                t_ilm_bool created);
77     static void notify_ivi_control_cb_static (ilmObjectType object,
78                                               t_ilm_uint id,
79                                               t_ilm_bool created,
80                                               void *user_data);
81     void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
82
83   private:
84     std::string m_role;
85     std::string m_path;
86
87     std::string m_id;
88     pid_t m_pid;
89
90     int m_port;
91     std::string m_token;
92
93     struct afb_wsj1* sp_websock;
94     struct afb_wsj1_itf minterface;
95     sd_event* mploop;
96     std::string muri;
97     struct Carla_Info m_carla_info; 
98
99     LibWindowmanager *m_wm;
100     LibHomeScreen *m_hs;
101     ILMControl *m_ic;
102
103     t_ilm_surface m_ivi_id;
104
105     std::map<int, int> m_surfaces;  // pair of <afm:rid, ivi:id>
106
107     bool m_pending_create = false;
108
109     int init_wm(void);
110     int init_hs(void);
111     int init_carlaclient(void);
112
113     int parse_config(const char *file);
114
115     void setup_ivi_surface(void);
116 };
117
118 #endif  // GST_WAYLAND_HPP