4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Junhwan An <jh48.an@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
36 #include <user_request.h>
43 guint watch_id_vdpram;
46 static TReturn hal_power(TcoreHal *hal, gboolean flag)
48 struct custom_data *user_data;
50 user_data = tcore_hal_ref_user_data(hal);
52 return TCORE_RETURN_FAILURE;
56 if (FALSE == vdpram_poweron(user_data->vdpram_fd)) {
57 err("vdpram_poweron failed");
58 return TCORE_RETURN_FAILURE;
60 tcore_hal_set_power_state(hal, TRUE);
64 if (FALSE == vdpram_poweroff(user_data->vdpram_fd)) {
65 err("vdpram_poweroff failed");
66 return TCORE_RETURN_FAILURE;
68 tcore_hal_set_power_state(hal, FALSE);
71 return TCORE_RETURN_SUCCESS;
75 static TReturn hal_send(TcoreHal *hal, unsigned int data_len, void *data)
78 struct custom_data *user_data;
80 if (tcore_hal_get_power_state(hal) == FALSE)
81 return TCORE_RETURN_FAILURE;
83 user_data = tcore_hal_ref_user_data(hal);
85 return TCORE_RETURN_FAILURE;
87 ret = vdpram_tty_write(user_data->vdpram_fd, data, data_len);
89 err("vdpram_tty_write failed");
90 return TCORE_RETURN_FAILURE;
93 dbg("vdpram_tty_write success ret=%d (fd=%d, len=%d)", ret, user_data->vdpram_fd, data_len);
94 return TCORE_RETURN_SUCCESS;
99 static struct tcore_hal_operations hops =
105 static gboolean on_recv_vdpram_message(GIOChannel *channel, GIOCondition condition, gpointer data)
107 TcorePlugin *plugin = data;
109 struct custom_data *custom;
111 #define BUF_LEN_MAX 512
112 char buf[BUF_LEN_MAX];
115 hal = tcore_plugin_ref_hal(plugin);
116 custom = tcore_hal_ref_user_data(hal);
117 memset(buf, 0, BUF_LEN_MAX);
118 n = vdpram_tty_read(custom->vdpram_fd, buf, BUF_LEN_MAX);
120 err("tty_read error. return_valute = %d", n);
124 dbg("vdpram recv (ret = %d)", n);
125 tcore_hal_emit_recv_callback(hal, n, buf);
130 static guint register_gio_watch(TcorePlugin *plugin, int fd, void *callback)
132 GIOChannel *channel = NULL;
135 if (fd < 0 || !callback)
138 channel = g_io_channel_unix_new(fd);
139 source = g_io_add_watch(channel, G_IO_IN, (GIOFunc) callback, plugin);
140 g_io_channel_unref(channel);
147 /*static int power_tx_pwr_on_exec(int nFd)
153 static gboolean on_load()
160 static gboolean on_init(TcorePlugin *plugin)
163 struct custom_data *data;
173 data = calloc(sizeof(struct custom_data), 1);
174 memset(data, 0, sizeof(struct custom_data));
176 data->vdpram_fd = vdpram_open();
181 hal = tcore_hal_new(plugin, "vmodem", &hops);
182 tcore_hal_link_user_data(hal, data);
184 data->watch_id_vdpram= register_gio_watch(plugin, data->vdpram_fd, on_recv_vdpram_message);
186 dbg("vdpram_fd = %d, watch_id_vdpram=%d ", data->vdpram_fd, data->watch_id_vdpram);
188 if (!vdpram_poweron(data->vdpram_fd))
189 err("vdpram_poweron Failed");
191 // power_tx_pwr_on_exec(data->vdpram_fd);
196 static void on_unload(TcorePlugin *plugin)
204 struct tcore_plugin_define_desc plugin_define_desc =
207 .priority = TCORE_PLUGIN_PRIORITY_HIGH,