2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 * @brief header file of AppsController interface
15 #ifndef __ICO_APF_PRIVATEI_H__
16 #define __ICO_APF_PRIVATEI_H__
18 #include "ico_apf_log.h"
19 #include "ico_uxf_sysdef.h"
21 #include "ico_apf_apimacro.h"
28 * AppsControllerr Protocol(TEXT)
30 * TEXT ="cmd resource appid device id (base id)"
32 * command(Client->AppsController)
33 * "GET BSCR appid disp id" ... Get basic screen
34 * "REL BSCR appid disp id" ... Release basic screen
35 * "GET ISCR appid disp id bid" ... Get interrupt screen
36 * "REL ISCR appid disp id bid" ... Release interrupt screen
37 * "GET OSCR appid disp id" ... Get on screen
38 * "REL OSCR appid disp id" ... Release on screen
39 * "GET BSND appid zone id adjust" ... Get basic sound
40 * "REL BSND appid zone id" ... Release basic sound
41 * "GET ISND appid zone id adjust" ... Get interrupt sound
42 * "REL ISND appid zone id" ... Release interrupt sound
43 * "ADD INPT appid device event" ... Add input switch
44 * "CHG INPT appid device event" ... Change input switch
45 * "DEL INPT appid device event" ... Delete input switch
46 * event(AppsController->Client)
47 * "ACQ BSCR appid disp id" ... Acquired basic screen(with surface visible)
48 * "DEP BSCR appid disp id" ... Deprived basic screen(with surface invisible)
49 * "WAI BSCR appid disp id" ... Waitting basic screen(with surface invisible)
50 * "DES BSCR appid disp id" ... Destoryed basic screen(with surface destory)
51 * * ISCR(interrupt screen), BSND(basic sound), ISND(interrupt sound),
52 * INPT(inout switch) are the same, too.
53 * reply(Client->AppsController)
54 * "ACK BSCR appid disp id" ... OK Reply basic screen
55 * "NAK BSCR appid disp id" ... NG Reply basic screen
56 * * ISCR(interrupt screen), BSND(basic sound), ISND(interrupt sound),
57 * INPT(inout switch) are the same, too.
59 /* Multi Sound Manager Protocol(Text)
63 * command(Client->Multi Sound Manager)
64 * "#stream_mute_set# pid" ... Mute control on(mute)
65 * "#stream_mute_reset# pid" ... Mute control off((no mute)
66 * "#stream_cancel# pid" ... Cancel
67 * "#get_stream_list#" ... Get stream list
69 * "#all_mute_set#" ... Mute on(mute) all streams
70 * "#all_mute_reset#" ... Mute off(no mute) all streams
71 * pid = process Id (decimal)
72 * event(Multi Sound Manager->Client)
73 * "#stream_new# #pid# pid #stream_name# str-name #app_name# app-name #command_end#"
74 * ... Create new sound stream
75 * pid = process Id (decimal)
76 * str-name = stream name
77 * app-name = application name(appid)
78 * "#stream_free# #pid# pid #stream_name# str-name #app_name# app-name #command_end#"
79 * ... End sound stream
80 * reply(Multi Sound Manager->Client)
81 * "#get_stream_list# #stream_state# state #pid# pid
82 * #stream_name# str-name #app_name# app-name #command_end#"
83 * ... reply of #get_stream_list# (multi message)
84 * state = "PA_SINK_INPUT_INIT"
85 * = "PA_SINK_INPUT_DRAINED"
86 * = "PA_SINK_INPUT_RUNNING"
87 * = "PA_SINK_INPUT_CORKED"
88 * = "PA_SINK_INPUT_UNLINKED"
89 * = "INCORRECT_STATUS"
90 * "#get_stream_list# #no_stream# #command_end#"
91 * ... reply of #get_stream_list# (no stream)
94 /* Protocol name on libwebsockets for Application Manager */
95 #define ICO_PROTOCOL_APPSCONTROLLER "ico_apps_controller"
97 /* Protocol name on libwebsockets for Pulse-Audio Plugin(Multi Sound Manager)*/
98 #define ICO_PROTOCOL_MULTISOUNDMANAGER "ico_soundmgr-protocol"
100 /* AppsController resource control command and event */
101 #define ICO_APF_SRESOURCE_STATE_ACQUIRED "ACQ"
102 #define ICO_APF_SRESOURCE_STATE_DEPRIVED "DEP"
103 #define ICO_APF_SRESOURCE_STATE_WAITTING "WAI"
104 #define ICO_APF_SRESOURCE_STATE_RELEASED "DES"
106 #define ICO_APF_SRESOURCE_COMMAND_GET "GET"
107 #define ICO_APF_SRESOURCE_COMMAND_RELEASE "REL"
108 #define ICO_APF_SRESOURCE_COMMAND_ADD "ADD"
109 #define ICO_APF_SRESOURCE_COMMAND_CHANGE "CHG"
110 #define ICO_APF_SRESOURCE_COMMAND_DELETE "DEL"
112 #define ICO_APF_SRESOURCE_REPLY_OK "ACK"
113 #define ICO_APF_SRESOURCE_REPLY_NG "NAK"
114 #define ICO_APF_SRESOURCE_STATE_CONNECTED "CON"
115 #define ICO_APF_SRESOURCE_STATE_DISCONNECTED "DCN"
117 /* AppsController resource control target object */
118 #define ICO_APF_SRESID_BASIC_SCREEN "BSCR"
119 #define ICO_APF_SRESID_INT_SCREEN "ISCR"
120 #define ICO_APF_SRESID_ON_SCREEN "OSCR"
121 #define ICO_APF_SRESID_BASIC_SOUND "BSND"
122 #define ICO_APF_SRESID_INT_SOUND "ISND"
123 #define ICO_APF_SRESID_INPUT_DEV "INPT"
125 /* Multi Sound Manager sound control command */
126 #define ICO_APF_SSOUND_COMMAND_MUTEON "#stream_mute_set#"
127 #define ICO_APF_SSOUND_COMMAND_MUTEOFF "#stream_mute_reset#"
128 #define ICO_APF_SSOUND_COMMAND_CANCEL "#stream_cancel#"
129 #define ICO_APF_SSOUND_COMMAND_GETLIST "#get_stream_list#"
130 #define ICO_APF_SSOUND_COMMAND_FRESH "#fresh#"
131 #define ICO_APF_SSOUND_COMMAND_ALLMUTEON "#all_mute_set#"
132 #define ICO_APF_SSOUND_COMMAND_ALLMUTEOFF "#all_mute_reset#"
134 #define ICO_APF_SSOUND_EVENT_NEW "#stream_new#"
135 #define ICO_APF_SSOUND_EVENT_FREE "#stream_free#"
137 #define ICO_APF_SSOUND_REPLY_LIST "#get_stream_list#"
139 /* Maximum number of send/receive items */
140 #define ICO_APF_RESOURCE_MSG_LEN 256 /* Maximum length of message */
141 #define ICO_APF_RESOURCE_WSOCK_BUFS 128 /* Number of the buffer for send data */
142 #define ICO_APF_RESOURCE_WSOCK_BUFR 64 /* Number of the buffer for receive data*/
143 #define ICO_APF_RESOURCE_IP_LEN 20 /* IP address length */
145 /* Define connection type */
146 #define ICO_APF_COM_TYPE_SERVER 0xf0 /* server type */
147 #define ICO_APF_COM_TYPE_CONNECTION 0x0f /* connection type */
148 #define ICO_APF_COM_TYPE_APPSCTL 0x01 /* connect to AppsController */
149 #define ICO_APF_COM_TYPE_SOUNDMGR 0x02 /* connect to Multi Sound Manager*/
150 #define ICO_APF_COM_TYPE_SVR_APPSCTL 0x11 /* server(listen) for AppsController*/
151 #define ICO_APF_COM_TYPE_SVR_SOUNDMGR 0x12 /* server(listen) for Sound Manager*/
153 /* Defines of Input/Output Event Flags */
154 #define ICO_APF_COM_POLL_READ 1 /* input flag */
155 #define ICO_APF_COM_POLL_WRITE 2 /* output flag */
156 #define ICO_APF_COM_POLL_ERROR 4 /* error flag */
158 /* Data queue for send/receive */
159 typedef struct _ico_apf_com_buffer {
160 short cmd; /* command */
161 short res; /* resource */
162 int pid; /* requeste client pid */
163 char appid[ICO_UXF_MAX_PROCESS_NAME+1];
164 /* application id (for Web application) */
165 char msg[ICO_APF_RESOURCE_MSG_LEN];
167 } ico_apf_com_buffer_t;
169 /* Listener function prototype */
170 typedef struct _ico_apf_com_handle ico_apf_com_handle_t;
171 typedef void (*ico_apf_com_eventlistener)(ico_apf_com_handle_t *handle, int cmd, int res,
172 int pid, char *appid, char *msg, void* user_data);
173 typedef struct _ico_apf_com_poll ico_apf_com_poll_t;
174 typedef void (*ico_apf_com_pollfd_cb)(ico_apf_com_poll_t *fd_ctl[], const int num_fds);
176 /* AppsController Handle */
177 struct _ico_apf_com_handle {
178 ico_apf_com_handle_t *next; /* next handle */
179 short hostid; /* Host Id(unused) */
180 char service_on; /* connected(=1)/ not connect(=0) */
181 char type; /* connection type */
182 char ip[ICO_APF_RESOURCE_IP_LEN];/* IP address */
183 int port; /* port number */
184 int fd; /* Socket file descriptor */
185 ico_apf_com_poll_t *poll; /* poll table */
186 int pid; /* client pid (server only) */
188 struct libwebsocket_context *wsi_context;
189 /* Context of libwebsockets */
190 struct libwebsocket *wsi_connection;/* WSI of libwebsockets */
192 short retry; /* Retry counter */
193 short stoprecv; /* Receive stopped(flow control) */
194 unsigned short shead; /* Head position of send datas */
195 unsigned short stail; /* Tail position of send datas */
196 ico_apf_com_buffer_t *sbuf[ICO_APF_RESOURCE_WSOCK_BUFS];
198 unsigned short rhead; /* Head position of receive datas */
199 unsigned short rtail; /* Tail position of receive datas */
200 ico_apf_com_buffer_t *rbuf[ICO_APF_RESOURCE_WSOCK_BUFR];
201 /* Receive buffers */
202 ico_apf_com_eventlistener listener;
203 /* Listener function(if NULL, not regist)*/
204 void *user_data; /* Listener argument */
207 /* Structure of File Descriptor's Controller */
208 struct _ico_apf_com_poll {
209 ico_apf_com_poll_t *next; /* next table */
210 int fd; /* number of changing File Descriptor */
211 int flags; /* input/output/error flag */
212 void *apf_fd_control; /* address of AppFW's controll table */
213 void *user_data; /* user data */
216 /* API functions prototype */
217 ico_apf_com_handle_t *ico_apf_com_init_client(const char *uri, const int type);
218 ico_apf_com_handle_t *ico_apf_com_init_server(const char *uri, const int type);
219 int ico_apf_com_term_client(ico_apf_com_handle_t *handle);
220 int ico_apf_com_term_server(ico_apf_com_handle_t *handle);
221 int ico_apf_com_isconnected(ico_apf_com_handle_t *handle);
222 int ico_apf_com_send(ico_apf_com_handle_t *handle,
223 const int cmd, const int res, const char *appid, char *msg);
224 int ico_apf_com_addeventlistener(ico_apf_com_handle_t *handle,
225 ico_apf_com_eventlistener listener,
227 int ico_apf_com_removeeventlistener(ico_apf_com_handle_t *handle);
228 void ico_apf_com_dispatch(ico_apf_com_handle_t *handle, const int timeoutms);
230 /* API for file descriptor poll */
231 int ico_apf_com_poll_fd_control(ico_apf_com_pollfd_cb poll_fd_cb);
232 int ico_apf_com_poll_fd_event(ico_apf_com_poll_t *fd_ctl, int flags);
237 #endif /*__ICO_APF_PRIVATEI_H__*/