8 #include <glib-object.h>
15 #include <communicator.h>
18 #include <user_request.h>
21 #include "generated-code.h"
25 on_modem_set_power (TelephonyModem *modem,
26 GDBusMethodInvocation *invocation,
30 struct custom_data *ctx = user_data;
31 UserRequest *ur = NULL;
32 TReturn ret = TCORE_RETURN_SUCCESS;
34 ur = MAKE_UR(ctx, modem, invocation);
35 tcore_user_request_set_data(ur, 0, NULL);
39 tcore_user_request_set_command(ur, TREQ_MODEM_POWER_OFF);
42 tcore_user_request_set_command(ur, TREQ_MODEM_POWER_ON);
45 tcore_user_request_set_command(ur, TREQ_MODEM_POWER_RESET);
48 ret = TCORE_RETURN_EINVAL;
53 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
54 if (ret != TCORE_RETURN_SUCCESS)
60 telephony_modem_complete_set_power(modem, invocation, ret);
66 on_modem_set_flight_mode (TelephonyModem *modem,
67 GDBusMethodInvocation *invocation,
71 struct treq_modem_set_flightmode data;
72 struct custom_data *ctx = user_data;
73 UserRequest *ur = NULL;
78 ur = MAKE_UR(ctx, modem, invocation);
79 tcore_user_request_set_data(ur, sizeof(struct treq_modem_set_flightmode), &data);
80 tcore_user_request_set_command(ur, TREQ_MODEM_SET_FLIGHTMODE);
81 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
82 if (ret != TCORE_RETURN_SUCCESS) {
83 telephony_modem_complete_set_flight_mode(modem, invocation, ret);
84 tcore_user_request_unref(ur);
91 on_modem_get_version (TelephonyModem *modem,
92 GDBusMethodInvocation *invocation,
95 struct custom_data *ctx = user_data;
96 UserRequest *ur = NULL;
99 ur = MAKE_UR(ctx, modem, invocation);
100 tcore_user_request_set_command(ur, TREQ_MODEM_GET_VERSION);
101 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
102 if (ret != TCORE_RETURN_SUCCESS) {
103 telephony_modem_complete_get_version(modem, invocation,
105 NULL, NULL, NULL, NULL);
106 tcore_user_request_unref(ur);
113 on_modem_get_serial_number (TelephonyModem *modem,
114 GDBusMethodInvocation *invocation,
117 struct custom_data *ctx = user_data;
118 UserRequest *ur = NULL;
121 ur = MAKE_UR(ctx, modem, invocation);
122 tcore_user_request_set_command(ur, TREQ_MODEM_GET_SN);
123 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
124 if (ret != TCORE_RETURN_SUCCESS) {
125 telephony_modem_complete_get_serial_number(modem, invocation, ret, NULL);
126 tcore_user_request_unref(ur);
133 on_modem_get_imei (TelephonyModem *modem,
134 GDBusMethodInvocation *invocation,
137 struct custom_data *ctx = user_data;
138 UserRequest *ur = NULL;
141 ur = MAKE_UR(ctx, modem, invocation);
142 tcore_user_request_set_command(ur, TREQ_MODEM_GET_IMEI);
143 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
144 if (ret != TCORE_RETURN_SUCCESS) {
145 telephony_modem_complete_get_imei(modem, invocation, ret, NULL);
146 tcore_user_request_unref(ur);
152 static gboolean on_modem_set_dun_pin_ctrl (TelephonyModem *modem, GDBusMethodInvocation *invocation,
153 gint arg_signal, gboolean arg_status, gpointer user_data)
155 struct treq_modem_set_dun_pin_control data;
156 struct custom_data *ctx = user_data;
157 UserRequest *ur = NULL;
160 data.signal = arg_signal;
161 data.status = arg_status;
163 ur = MAKE_UR(ctx, modem, invocation);
164 tcore_user_request_set_data(ur, sizeof(struct treq_modem_set_dun_pin_control), &data);
165 tcore_user_request_set_command(ur, TREQ_MODEM_SET_DUN_PIN_CONTROL);
166 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
167 if (ret != TCORE_RETURN_SUCCESS) {
168 telephony_modem_complete_set_dun_pin_ctrl(modem, invocation, ret);
169 tcore_user_request_unref(ur);
175 gboolean dbus_plugin_setup_modem_interface(TelephonyObjectSkeleton *object, struct custom_data *ctx)
177 TelephonyModem *modem;
179 modem = telephony_modem_skeleton_new();
180 telephony_object_skeleton_set_modem(object, modem);
181 g_object_unref(modem);
183 g_signal_connect (modem,
185 G_CALLBACK (on_modem_set_power),
188 g_signal_connect (modem,
189 "handle-set-flight-mode",
190 G_CALLBACK (on_modem_set_flight_mode),
193 g_signal_connect (modem,
194 "handle-get-version",
195 G_CALLBACK (on_modem_get_version),
198 g_signal_connect (modem,
199 "handle-get-serial-number",
200 G_CALLBACK (on_modem_get_serial_number),
203 g_signal_connect (modem,
205 G_CALLBACK (on_modem_get_imei),
208 g_signal_connect (modem,
209 "handle-set-dun-pin-ctrl",
210 G_CALLBACK (on_modem_set_dun_pin_ctrl),
217 gboolean dbus_plugin_modem_response(struct custom_data *ctx, UserRequest *ur, struct dbus_request_info *dbus_info, enum tcore_response_command command, unsigned int data_len, const void *data)
219 const struct tresp_modem_set_flightmode *resp_set_flight_mode = data;
220 const struct tresp_modem_set_dun_pin_control *resp_dun_pin_ctrl = data;
221 const struct tresp_modem_get_imei *resp_get_imei = data;
222 const struct tresp_modem_get_sn *resp_get_sn = data;
223 const struct tresp_modem_get_version *resp_get_version = data;
226 case TRESP_MODEM_SET_FLIGHTMODE:
227 dbg("receive TRESP_MODEM_SET_FLIGHTMODE");
228 dbg("resp->result = %d", resp_set_flight_mode->result);
229 telephony_modem_complete_set_flight_mode(dbus_info->interface_object, dbus_info->invocation, resp_set_flight_mode->result);
232 case TRESP_MODEM_POWER_ON:
233 dbg("receive TRESP_MODEM_POWER_ON");
234 telephony_modem_complete_set_power(dbus_info->interface_object, dbus_info->invocation, 0);
237 case TRESP_MODEM_POWER_OFF:
238 dbg("receive TRESP_MODEM_POWER_OFF");
239 telephony_modem_complete_set_power(dbus_info->interface_object, dbus_info->invocation, 0);
242 case TRESP_MODEM_POWER_RESET:
243 dbg("receive TRESP_MODEM_POWER_RESET");
244 telephony_modem_complete_set_power(dbus_info->interface_object, dbus_info->invocation, 0);
247 case TRESP_MODEM_GET_IMEI:
248 dbg("receive TRESP_MODEM_GET_IMEI");
249 telephony_modem_complete_get_imei(dbus_info->interface_object, dbus_info->invocation, resp_get_imei->result, resp_get_imei->imei);
252 case TRESP_MODEM_GET_SN:
253 dbg("receive TRESP_MODEM_GET_SN");
254 telephony_modem_complete_get_serial_number(dbus_info->interface_object, dbus_info->invocation, resp_get_sn->result, resp_get_sn->sn);
257 case TRESP_MODEM_GET_VERSION:
258 dbg("receive TRESP_MODEM_GET_VERSION");
259 telephony_modem_complete_get_version(dbus_info->interface_object, dbus_info->invocation,
260 resp_get_version->result,
261 resp_get_version->software,
262 resp_get_version->hardware,
263 resp_get_version->calibration,
264 resp_get_version->product_code);
267 case TRESP_MODEM_SET_DUN_PIN_CONTROL:
268 dbg("receive TRESP_MODEM_SET_DUN_PIN_CONTROL");
269 dbg("resp->result = %d", resp_dun_pin_ctrl->result);
270 telephony_modem_complete_set_dun_pin_ctrl(dbus_info->interface_object, dbus_info->invocation, resp_dun_pin_ctrl->result);
274 dbg("not handled command[%d]", command);
281 gboolean dbus_plugin_modem_notification(struct custom_data *ctx, const char *plugin_name, TelephonyObjectSkeleton *object, enum tcore_notification_command command, unsigned int data_len, const void *data)
283 TelephonyModem *modem;
284 const struct tnoti_modem_power *info = data;
285 const struct tnoti_modem_dun_pin_control *pin = data;
288 dbg("object is NULL");
292 modem = telephony_object_peek_modem(TELEPHONY_OBJECT(object));
293 dbg("modem = %p", modem);
296 case TNOTI_MODEM_POWER:
297 dbg("modem->state = %d", info->state);
298 telephony_modem_emit_power(modem, info->state);
299 telephony_modem_set_power(modem, info->state);
302 case TNOTI_MODEM_DUN_PIN_CONTROL:
303 dbg("modem dun pin ctrl noti signal(%d), status(%d)", pin->signal, pin->status);
304 telephony_modem_emit_dun_pin_ctrl(modem, pin->signal, pin->status);
307 case TNOTI_MODEM_DUN_EXTERNAL_CALL:
308 dbg("modem dun external call noti");
309 telephony_modem_emit_dun_external_call(modem, TRUE);
313 dbg("not handled command[0x%x]", command);