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 TcoreHal *hal = data;
108 struct custom_data *custom;
110 #define BUF_LEN_MAX 512
111 char buf[BUF_LEN_MAX];
114 custom = tcore_hal_ref_user_data(hal);
115 memset(buf, 0, BUF_LEN_MAX);
116 n = vdpram_tty_read(custom->vdpram_fd, buf, BUF_LEN_MAX);
118 err("tty_read error. return_valute = %d", n);
122 dbg("vdpram recv (ret = %d)", n);
123 tcore_hal_emit_recv_callback(hal, n, buf);
128 static guint register_gio_watch(TcoreHal *h, int fd, void *callback)
130 GIOChannel *channel = NULL;
133 if (fd < 0 || !callback)
136 channel = g_io_channel_unix_new(fd);
137 source = g_io_add_watch(channel, G_IO_IN, (GIOFunc) callback, h);
138 g_io_channel_unref(channel);
145 /*static int power_tx_pwr_on_exec(int nFd)
151 static gboolean on_load()
158 static gboolean on_init(TcorePlugin *plugin)
161 struct custom_data *data;
171 data = calloc(sizeof(struct custom_data), 1);
172 memset(data, 0, sizeof(struct custom_data));
174 data->vdpram_fd = vdpram_open();
179 hal = tcore_hal_new(plugin, "vmodem", &hops, TCORE_HAL_MODE_CUSTOM);
180 tcore_hal_link_user_data(hal, data);
182 data->watch_id_vdpram= register_gio_watch(hal, data->vdpram_fd, on_recv_vdpram_message);
184 dbg("vdpram_fd = %d, watch_id_vdpram=%d ", data->vdpram_fd, data->watch_id_vdpram);
186 if (!vdpram_poweron(data->vdpram_fd))
187 err("vdpram_poweron Failed");
189 // power_tx_pwr_on_exec(data->vdpram_fd);
194 static void on_unload(TcorePlugin *plugin)
202 struct tcore_plugin_define_desc plugin_define_desc =
205 .priority = TCORE_PLUGIN_PRIORITY_HIGH,