Initial refactoring merge
[platform/core/telephony/tel-plugin-dbus_tapi.git] / src / dtapi_manager.c
1 /*
2  * tel-plugin-dbus_tapi
3  *
4  * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
5  * Copyright (c) 2013 Intel Corporation. All rights reserved.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include "dtapi_manager.h"
21 #include "dtapi_util.h"
22
23 #include <server.h>
24
25 #define AC_MANAGER      "telephony_framework::api_manager"
26
27 static void
28 dtapi_manager_get_modems(TelephonyManager *mgr, GDBusMethodInvocation *invocation,
29         Server *server)
30 {
31         GSList *cp_name_list, *temp_list;
32         gchar **list;
33         unsigned int count;
34         const char *name = NULL;
35         dbg("Entry");
36
37         cp_name_list = tcore_server_get_modem_plugin_list(server);
38         if (cp_name_list == NULL) {
39                 err("Modem List is NULL");
40                 telephony_manager_complete_get_modems(mgr, invocation, NULL);
41                 return;
42         }
43
44         count = g_slist_length(cp_name_list);
45         list = g_try_malloc0(sizeof(gchar *) * (count+1));
46
47         count = 0;
48         temp_list = cp_name_list;
49         for ( ; cp_name_list ; cp_name_list = cp_name_list->next) {
50                 name = cp_name_list->data;
51                 list[count] = g_strdup(name);
52                 dbg("list[%d]: %s", count, list[count]);
53                 count++;
54         }
55
56         telephony_manager_complete_get_modems(mgr, invocation, (const gchar **)list);
57
58         /* Free memory */
59         for (;count > 0; count--)
60                 g_free(list[count]);
61
62         g_free(list);
63
64         /* Freeing the received list of CP names */
65         g_slist_free_full(temp_list, g_free);
66 }
67
68 TelephonyManager *dtapi_manager_new(Server *server)
69 {
70         TelephonyManager *mgr = telephony_manager_skeleton_new();
71         tcore_check_return_value_assert(NULL != mgr, NULL);
72
73         g_signal_connect(mgr, "handle-get-modems",
74                 G_CALLBACK(dtapi_manager_get_modems), server);
75
76         return mgr;
77 }