14 #include <communicator.h>
17 #include <user_request.h>
22 #include "generated-code.h"
26 on_gps_set_frequency_aiding (TelephonyGps *gps,
27 GDBusMethodInvocation *invocation,
31 struct custom_data *ctx = user_data;
32 UserRequest *ur = NULL;
35 if (!check_access_control (invocation, AC_GPS, "w"))
38 ur = MAKE_UR(ctx, gps, invocation);
41 tcore_user_request_set_data(ur, sizeof(data), (const char*)&data);
42 tcore_user_request_set_command(ur, TREQ_GPS_SET_FREQUENCY_AIDING);
43 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
44 if (ret != TCORE_RETURN_SUCCESS) {
45 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
46 tcore_user_request_unref(ur);
53 on_gps_confirm_measure_pos (TelephonyGps *gps,
54 GDBusMethodInvocation *invocation,
58 struct custom_data *ctx = user_data;
59 UserRequest *ur = NULL;
61 gboolean result = TRUE;
62 guchar *decoded_data = NULL;
65 if (!check_access_control (invocation, AC_GPS, "w"))
68 ur = MAKE_UR(ctx, gps, invocation);
70 decoded_data = g_base64_decode(data, &length);
71 dbg("decoded length=%d", length);
72 tcore_user_request_set_data(ur, length, decoded_data);
73 tcore_user_request_set_command(ur, TREQ_GPS_CONFIRM_MEASURE_POS);
74 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
75 if (ret != TCORE_RETURN_SUCCESS) {
76 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
77 tcore_user_request_unref(ur);
82 telephony_gps_complete_confirm_measure_pos(gps, invocation, result);
89 on_enable_smart_assistant(TelephonyGps *gps,
90 GDBusMethodInvocation *invocation,
93 struct custom_data *ctx = user_data;
94 UserRequest *ur = NULL;
97 if (!check_access_control (invocation, AC_GPS, "w"))
100 ur = MAKE_UR(ctx, gps, invocation);
102 tcore_user_request_set_command(ur, TREQ_ENABLE_SMART_ASSISTANT);
103 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
104 if (ret != TCORE_RETURN_SUCCESS) {
105 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
106 tcore_user_request_unref(ur);
113 on_disable_smart_assistant(TelephonyGps *gps,
114 GDBusMethodInvocation *invocation,
117 struct custom_data *ctx = user_data;
118 UserRequest *ur = NULL;
121 if (!check_access_control (invocation, AC_GPS, "w"))
124 ur = MAKE_UR(ctx, gps, invocation);
126 tcore_user_request_set_command(ur, TREQ_DISABLE_SMART_ASSISTANT);
127 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
128 if (ret != TCORE_RETURN_SUCCESS) {
129 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
130 tcore_user_request_unref(ur);
137 on_sync_smart_assistant_area_list(TelephonyGps *gps,
138 GDBusMethodInvocation *invocation,
143 struct tel_smart_assistant_area_list req;
144 struct custom_data *ctx = user_data;
145 UserRequest *ur = NULL;
148 GVariantIter *iter = NULL;
152 dbg("enter count=%d", count);
154 if (!check_access_control (invocation, AC_GPS, "w"))
157 ur = MAKE_UR(ctx, gps, invocation);
158 memset(&req,0,sizeof(struct tel_smart_assistant_area_list));
160 dbg("count=%d", count);
161 if (count > SMART_ASSISTANT_AREA_LIST_MAX)
162 count = SMART_ASSISTANT_AREA_LIST_MAX;
166 g_variant_get (gv, "v", &b);
167 g_variant_unref (gv);
169 g_variant_get (b, "a(ii)", &iter);
170 while(g_variant_iter_loop(iter,"(ii)",&item1, &item2)){
171 req.area[i].index = item1;
172 req.area[i].mode_state = item2;
177 g_variant_iter_free(iter);
179 tcore_user_request_set_data(ur, sizeof(struct tel_smart_assistant_area_list), &req);
180 tcore_user_request_set_command(ur, TREQ_SYNC_SMART_ASSISTANT_AREA_LIST);
181 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
182 if (ret != TCORE_RETURN_SUCCESS) {
183 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
184 tcore_user_request_unref(ur);
191 on_del_smart_assistant_area_list(TelephonyGps *gps,
192 GDBusMethodInvocation *invocation,
197 struct tel_smart_assistant_area_list req;
198 struct custom_data *ctx = user_data;
199 UserRequest *ur = NULL;
202 GVariantIter *iter = NULL;
207 if (!check_access_control (invocation, AC_GPS, "w"))
210 ur = MAKE_UR(ctx, gps, invocation);
211 memset(&req,0,sizeof(struct tel_smart_assistant_area_list));
213 dbg("count=%d", count);
214 if (count > SMART_ASSISTANT_AREA_LIST_MAX)
215 count = SMART_ASSISTANT_AREA_LIST_MAX;
219 g_variant_get (gv, "v", &b);
220 g_variant_unref (gv);
222 g_variant_get (b, "a(ii)", &iter);
223 while(g_variant_iter_loop(iter,"(ii)",&item1, &item2)){
224 req.area[i].index = item1;
225 req.area[i].mode_state = item2;
230 g_variant_iter_free(iter);
232 tcore_user_request_set_data(ur, sizeof(struct tel_smart_assistant_area_list), &req);
233 tcore_user_request_set_command(ur, TREQ_DEL_SMART_ASSISTANT_AREA_LIST);
234 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
235 if (ret != TCORE_RETURN_SUCCESS) {
236 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
237 tcore_user_request_unref(ur);
244 on_add_smart_assistant_area(TelephonyGps *gps,
245 GDBusMethodInvocation *invocation,
250 struct tel_smart_assistant_area req;
251 struct custom_data *ctx = user_data;
252 UserRequest *ur = NULL;
255 if (!check_access_control (invocation, AC_GPS, "w"))
258 ur = MAKE_UR(ctx, gps, invocation);
259 req.index = fn_index;
260 req.mode_state = mode_state;
261 dbg("index=%d, mode_state=%d",req.index, req.mode_state);
263 tcore_user_request_set_data(ur, sizeof(struct tel_smart_assistant_area), &req);
264 tcore_user_request_set_command(ur, TREQ_ADD_SMART_ASSISTANT_AREA);
265 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
266 if (ret != TCORE_RETURN_SUCCESS) {
267 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
268 tcore_user_request_unref(ur);
274 on_modify_smart_assistant_area(TelephonyGps *gps,
275 GDBusMethodInvocation *invocation,
280 struct tel_smart_assistant_area req;
281 struct custom_data *ctx = user_data;
282 UserRequest *ur = NULL;
285 if (!check_access_control (invocation, AC_GPS, "w"))
288 ur = MAKE_UR(ctx, gps, invocation);
289 req.index = fn_index;
290 req.mode_state = mode_state;
291 dbg("index=%d, mode_state=%d",req.index, req.mode_state);
293 tcore_user_request_set_data(ur, sizeof(struct tel_smart_assistant_area), &req);
294 tcore_user_request_set_command(ur, TREQ_MODIFY_SMART_ASSISTANT_AREA);
295 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
296 if (ret != TCORE_RETURN_SUCCESS) {
297 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
298 tcore_user_request_unref(ur);
305 on_set_smart_assistant_info(TelephonyGps *gps,
306 GDBusMethodInvocation *invocation,
311 struct treq_set_smart_assistant_info req;
312 struct custom_data *ctx = user_data;
313 UserRequest *ur = NULL;
316 if (!check_access_control (invocation, AC_GPS, "w"))
319 ur = MAKE_UR(ctx, gps, invocation);
320 req.index = fn_index;
321 req.lpp_state = lpp_state;
322 dbg("index=%d, lpp_state=%d",req.index, req.lpp_state);
324 tcore_user_request_set_data(ur, sizeof(struct treq_set_smart_assistant_info), &req);
325 tcore_user_request_set_command(ur, TREQ_SET_SMART_ASSISTANT_INFO);
326 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
327 if (ret != TCORE_RETURN_SUCCESS) {
328 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
329 tcore_user_request_unref(ur);
335 gboolean dbus_plugin_setup_gps_interface(TelephonyObjectSkeleton *object, struct custom_data *ctx)
339 gps = telephony_gps_skeleton_new();
340 telephony_object_skeleton_set_gps(object, gps);
344 dbg("gps = %p", gps);
346 g_signal_connect (gps,
347 "handle-set-frequency-aiding",
348 G_CALLBACK (on_gps_set_frequency_aiding),
351 g_signal_connect (gps,
352 "handle-confirm-measure-pos",
353 G_CALLBACK (on_gps_confirm_measure_pos),
356 g_signal_connect (gps,
357 "handle-enable-smart-assistant",
358 G_CALLBACK (on_enable_smart_assistant),
361 g_signal_connect (gps,
362 "handle-disable-smart-assistant",
363 G_CALLBACK (on_disable_smart_assistant),
366 g_signal_connect (gps,
367 "handle-sync-smart-assistant-area-list",
368 G_CALLBACK (on_sync_smart_assistant_area_list),
371 g_signal_connect (gps,
372 "handle-del-smart-assistant-area-list",
373 G_CALLBACK (on_del_smart_assistant_area_list),
376 g_signal_connect (gps,
377 "handle-add-smart-assistant-area",
378 G_CALLBACK (on_add_smart_assistant_area),
381 g_signal_connect (gps,
382 "handle-modify-smart-assistant-area",
383 G_CALLBACK (on_modify_smart_assistant_area),
386 g_signal_connect (gps,
387 "handle-set-smart-assistant-info",
388 G_CALLBACK (on_set_smart_assistant_info),
394 gboolean dbus_plugin_gps_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)
396 const struct tresp_gps_set_frequency_aiding *resp_gps_frequency_aiding = data;
397 const struct tresp_smart_assistant_result *resp_smart_assistant_result = data;
401 char *modem_name = NULL;
402 TcorePlugin *p = NULL;
404 modem_name = tcore_user_request_get_modem_name(ur);
408 p = tcore_server_find_plugin(ctx->server, modem_name);
413 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_GPS);
418 co_gps = (CoreObject *)co_list->data;
419 g_slist_free(co_list);
426 case TRESP_GPS_SET_FREQUENCY_AIDING:
427 dbg("TRESP_GPS_SET_FREQUENCY_AIDING result=%d", resp_gps_frequency_aiding->result);
428 telephony_gps_complete_set_frequency_aiding(dbus_info->interface_object, dbus_info->invocation, resp_gps_frequency_aiding->result);
431 case TRESP_ENABLE_SMART_ASSISTANT:
432 dbg("TRESP_ENABLE_SMART_ASSISTANT result=%d", resp_smart_assistant_result->result);
433 telephony_gps_complete_enable_smart_assistant(dbus_info->interface_object, dbus_info->invocation, resp_smart_assistant_result->result);
436 case TRESP_DISABLE_SMART_ASSISTANT:
437 dbg("TRESP_ENABLE_SMART_ASSISTANT result=%d", resp_smart_assistant_result->result);
438 telephony_gps_complete_disable_smart_assistant(dbus_info->interface_object, dbus_info->invocation, resp_smart_assistant_result->result);
441 case TRESP_SYNC_SMART_ASSISTANT_AREA_LIST:
442 dbg("TRESP_SYNC_SMART_ASSISTANT_AREA_LIST result=%d", resp_smart_assistant_result->result);
443 telephony_gps_complete_sync_smart_assistant_area_list(dbus_info->interface_object, dbus_info->invocation, resp_smart_assistant_result->result);
446 case TRESP_DEL_SMART_ASSISTANT_AREA_LIST:
447 dbg("TRESP_DEL_SMART_ASSISTANT_AREA_LIST result=%d", resp_smart_assistant_result->result);
448 telephony_gps_complete_del_smart_assistant_area_list(dbus_info->interface_object, dbus_info->invocation, resp_smart_assistant_result->result);
451 case TRESP_ADD_SMART_ASSISTANT_AREA:
452 dbg("TRESP_ADD_SMART_ASSISTANT_AREA result=%d", resp_smart_assistant_result->result);
453 telephony_gps_complete_add_smart_assistant_area(dbus_info->interface_object, dbus_info->invocation, resp_smart_assistant_result->result);
456 case TRESP_MODIFY_SMART_ASSISTANT_AREA:
457 dbg("TRESP_MODIFY_SMART_ASSISTANT_AREA result=%d", resp_smart_assistant_result->result);
458 telephony_gps_complete_modify_smart_assistant_area(dbus_info->interface_object, dbus_info->invocation, resp_smart_assistant_result->result);
461 case TRESP_SET_SMART_ASSISTANT_INFO:
462 dbg("TRESP_SET_SMART_ASSISTANT_INFO result=%d", resp_smart_assistant_result->result);
463 telephony_gps_complete_set_smart_assistant_info(dbus_info->interface_object, dbus_info->invocation, resp_smart_assistant_result->result);
467 dbg("not handled cmd[0x%x]", command);
474 gboolean dbus_plugin_gps_notification(struct custom_data *ctx, CoreObject *source, TelephonyObjectSkeleton *object, enum tcore_notification_command command, unsigned int data_len, const void *data)
479 dbg("object is NULL");
482 dbg("Notification!!! Command: [0x%x] CP Name: [%s]",
483 command, tcore_server_get_cp_name_by_plugin(tcore_object_ref_plugin(source)));
485 gps = telephony_object_peek_gps(TELEPHONY_OBJECT(object));
487 case TNOTI_GPS_ASSIST_DATA:
489 gchar *encoded_data = NULL;
490 dbg("gps(%p) TNOTI_GPS_ASSIST_DATA. data=%p, data_len=%d", gps, data, data_len);
491 encoded_data = g_base64_encode((const guchar*)data, data_len);
492 telephony_gps_emit_assist_data(gps, encoded_data);
493 g_free(encoded_data);
497 case TNOTI_GPS_MEASURE_POSITION:
499 gchar *encoded_data = NULL;
500 dbg("gps(%p) TNOTI_GPS_MEASURE_POSITION. data=%p, data_len=%d", gps, data, data_len);
501 encoded_data = g_base64_encode((const guchar*)data, data_len);
502 telephony_gps_emit_measure_position(gps, encoded_data);
503 g_free(encoded_data);
507 case TNOTI_GPS_RESET_ASSIST_DATA:
508 dbg("gps(%p) TNOTI_GPS_RESET_ASSIST_DATA", gps);
509 telephony_gps_emit_reset_assist_data(gps);
512 case TNOTI_GPS_FREQUENCY_AIDING_DATA:
514 gchar *encoded_data = NULL;
515 dbg("gps(%p) TNOTI_GPS_FREQUENCY_AIDING_DATA. data=%p, data_len=%d", gps, data, data_len);
516 encoded_data = g_base64_encode((const guchar*)data, data_len);
517 telephony_gps_emit_frequency_aiding(gps, encoded_data);
518 g_free(encoded_data);
522 case TNOTI_SMART_ASSISTANT_AREA_STATUS:
524 const struct tnoti_smart_assistant_area_status *noti = data;
525 dbg("gps(%p) TNOTI_SMART_ASSISTANT_AREA_STATUS", gps);
526 telephony_gps_emit_area_status(gps, noti->area_status, noti->index);
530 case TNOTI_SMART_ASSISTANT_SYNC_STATUS:
532 const struct tnoti_smart_assistant_sync_status *noti = data;
533 dbg("gps(%p) TNOTI_SMART_ASSISTANT_SYNC_STATUS", gps);
534 telephony_gps_emit_sync_status(gps, noti->init_status, noti->init_fail_cause);
539 dbg("not handled cmd[0x%x]", command);