5 * Copyright (C) 2012 Intel Corporation. All rights reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include <user_request.h>
38 #include "pr3_audio.h"
40 #define BUF_LEN_MAX 512
47 static TReturn hal_power(TcoreHal *hal, gboolean flag)
49 struct custom_data *user_data;
51 user_data = tcore_hal_ref_user_data(hal);
53 return TCORE_RETURN_FAILURE;
57 dbg("Phone Power On success (fd:%d)", user_data->tty_fd);
59 tcore_hal_set_power_state(hal, TRUE);
62 dbg("Phone Power Off success.");
64 tcore_hal_set_power_state(hal, FALSE);
67 return TCORE_RETURN_SUCCESS;
71 static TReturn hal_send(TcoreHal *hal, unsigned int data_len, void *data)
74 struct custom_data *user_data;
76 if (tcore_hal_get_power_state(hal) == FALSE)
77 return TCORE_RETURN_FAILURE;
79 user_data = tcore_hal_ref_user_data(hal);
81 return TCORE_RETURN_FAILURE;
83 ret = tty_write(user_data->tty_fd, data, data_len);
85 err("tty_write failed");
87 return TCORE_RETURN_FAILURE;
90 dbg("tty_write success ret=%d (fd=%d, len=%d)", ret, user_data->tty_fd, data_len);
92 return TCORE_RETURN_SUCCESS;
96 static struct tcore_hal_operations hops =
100 .set_sound_path = pr3_audio_set_sound_path,
103 static gboolean on_recv_tty_message(GIOChannel *channel, GIOCondition condition, gpointer data)
105 TcoreHal *hal = data;
106 struct custom_data *custom;
107 char buf[BUF_LEN_MAX];
110 custom = tcore_hal_ref_user_data(hal);
111 memset(buf, 0, BUF_LEN_MAX);
112 n = tty_read(custom->tty_fd, buf, BUF_LEN_MAX);
114 err("tty_read error. return_valute = %d", n);
118 dbg("tty recv (ret = %d)", n);
119 tcore_hal_emit_recv_callback(hal, n, buf);
121 tcore_hal_dispatch_response_data(hal, 0, n, buf);
126 static guint register_gio_watch(TcoreHal *h, int fd, void *callback)
128 GIOChannel *channel = NULL;
131 if (fd < 0 || !callback)
134 channel = g_io_channel_unix_new(fd);
135 source = g_io_add_watch(channel, G_IO_IN, (GIOFunc) callback, h);
136 g_io_channel_unref(channel);
142 static gboolean on_load()
149 static gboolean on_init(TcorePlugin *plugin)
152 struct custom_data *data;
160 data = calloc(sizeof(struct custom_data), 1);
161 memset(data, 0, sizeof(struct custom_data));
163 data->tty_fd = tty_open();
166 hal = tcore_hal_new(plugin, "imc-pr3", &hops, TCORE_HAL_MODE_AT);
167 tcore_hal_link_user_data(hal, data);
169 data->watch_id_tty= register_gio_watch(hal, data->tty_fd, on_recv_tty_message);
171 dbg("tty_fd = %d, watch_id_tty=%d ", data->tty_fd, data->watch_id_tty);
173 if (pr3_audio_init() != TRUE)
174 err("Error in audio initialization")
180 static void on_unload(TcorePlugin *plugin)
185 if (pr3_audio_unload() != TRUE)
186 err("Error in audio unload")
191 struct tcore_plugin_define_desc plugin_define_desc =
194 .priority = TCORE_PLUGIN_PRIORITY_HIGH,