Execute tcore_server_exit() when SIGTERM happened
[platform/core/telephony/telephony-daemon.git] / src / monitor.c
1 /*
2  * telephony-daemon
3  *
4  * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include "monitor.h"
22
23 #include <stdlib.h>
24 #include <glib.h>
25
26 #include <communicator.h>
27 #include <user_request.h>
28 #include <storage.h>
29 #include <server.h>
30 #include <plugin.h>
31 #include <queue.h>
32 #include <hal.h>
33 #include <core_object.h>
34
35 #define NOTUSED(var) (var = var)
36
37 /* hacking TcoreQueue */
38 struct tcore_queue_type {
39         TcorePlugin *plugin;
40         GQueue *gq;
41 };
42
43 static void _hash_dump(gpointer key, gpointer value, gpointer user_data)
44 {
45         NOTUSED(user_data);
46
47         msg("         - %s: [%s]", key, value);
48 }
49
50 static void _monitor_core_objects(GSList *list)
51 {
52         CoreObject *co;
53         GHashTable *prop;
54
55         do {
56                 co = list->data;
57
58                 msg("     Name: [%s]", tcore_object_ref_name(co));
59                 msg("       - addr: %p", co);
60                 msg("       - type: %p", tcore_object_get_type(co));
61                 msg("       - hal: %p", tcore_object_get_hal(co));
62
63                 prop = tcore_object_ref_property_hash(co);
64                 if (prop) {
65                         msg("       - Properties: %d", g_hash_table_size(prop));
66                         g_hash_table_foreach(prop, _hash_dump, NULL);
67                 }
68
69                 list = list->next;
70         } while (list);
71 }
72
73 static void _monitor_plugin(Server *s)
74 {
75         GSList *list;
76         GSList *co_list;
77         TcorePlugin *p;
78         char *str;
79
80         msg("-- Plugins --");
81
82         list = tcore_server_ref_plugins(s);
83         if (!list)
84                 return;
85
86         do {
87                 p = list->data;
88
89                 msg("Name: [%s]", tcore_plugin_get_description(p)->name);
90
91                 str = tcore_plugin_get_filename(p);
92                 if (str) {
93                         msg(" - file: %s", str);
94                         free(str);
95                 }
96
97                 msg(" - addr: %p", p);
98                 msg(" - userdata: %p", tcore_plugin_ref_user_data(p));
99
100                 co_list = tcore_plugin_get_core_objects(p);
101                 if (co_list) {
102                         msg(" - core_object list: %d", g_slist_length(co_list));
103
104                         _monitor_core_objects(co_list);
105                         g_slist_free(co_list);
106                 }
107
108                 msg("");
109
110                 list = list->next;
111         } while (list);
112 }
113
114 static void _monitor_storage(Server *s)
115 {
116         GSList *list;
117         Storage *strg;
118
119         msg("-- Storages --");
120
121         list = tcore_server_ref_storages(s);
122         if (!list)
123                 return;
124
125         do {
126                 strg = list->data;
127
128                 msg("Name: [%s]", tcore_storage_ref_name(strg));
129                 msg(" - addr: %p", strg);
130                 msg("");
131
132                 list = list->next;
133         } while (list);
134 }
135
136 static void _monitor_communicator(Server *s)
137 {
138         GSList *list;
139         Communicator *comm;
140
141         msg("-- Coomunicators --");
142
143         list = tcore_server_ref_communicators(s);
144         if (!list)
145                 return;
146
147         do {
148                 comm = list->data;
149
150                 msg("Name: [%s]", tcore_communicator_ref_name(comm));
151                 msg(" - addr: %p", comm);
152                 msg(" - parent_plugin: %p", tcore_communicator_ref_plugin(comm));
153                 msg(" - userdata: %p", tcore_communicator_ref_user_data(comm));
154                 msg("");
155
156                 list = list->next;
157         } while (list);
158 }
159
160 static void _monitor_hal(Server *s)
161 {
162         GSList *list;
163         TcoreHal *h;
164         TcoreQueue *q;
165         TcorePending *pending;
166         UserRequest *ur;
167         char *str;
168         int qlen;
169         int i;
170         void *data;
171         unsigned int data_len;
172
173         msg("-- Hals --");
174
175         list = tcore_server_ref_hals(s);
176         if (!list)
177                 return;
178
179         do {
180                 h = list->data;
181
182                 str = tcore_hal_get_name(h);
183                 if (str) {
184                         msg("Name: [%s]", str);
185                         free(str);
186                 }
187                 msg(" - addr: %p", h);
188                 msg(" - parent_plugin: %p", tcore_hal_ref_plugin(h));
189                 msg(" - userdata: %p", tcore_hal_ref_user_data(h));
190
191                 q = tcore_hal_ref_queue(h);
192                 if (!q) {
193                         msg("");
194                         list = list->next;
195                         continue;
196                 }
197
198                 if (!(q->gq)) {
199                         msg("");
200                         list = list->next;
201                         continue;
202                 }
203
204                 qlen = tcore_queue_get_length(q);
205                 msg(" - queue: %p, length: %d", q, qlen);
206                 msg("   queue_head: %p", g_queue_peek_head(q->gq));
207                 for (i = 0; i < qlen; i++) {
208                         pending = g_queue_peek_nth(q->gq, i);
209                         ur = tcore_pending_ref_user_request(pending);
210                         msg("   [%02d] pending=%p, id=0x%x, ur=%p", i, pending, tcore_pending_get_id(pending), ur);
211                         if (ur)
212                                 msg("        ur request command = 0x%x", tcore_user_request_get_command(ur));
213
214                         data_len = 0;
215                         data = tcore_pending_ref_request_data(pending, &data_len);
216                         msg("        data=%p, data_len=%d", data, data_len);
217                 }
218                 msg("   queue_tail: %p", g_queue_peek_tail(q->gq));
219                 msg("");
220
221                 list = list->next;
222         } while (list);
223 }
224
225 void monitor_server_state(Server *s)
226 {
227         _monitor_plugin(s);
228         _monitor_storage(s);
229         _monitor_communicator(s);
230         _monitor_hal(s);
231 }