9981143f8fcba2e0569e4ccf48c1e73bc2e472bf
[platform/core/telephony/telephony-daemon.git] / src / monitor.c
1 /*
2  * telephony-daemon
3  *
4  * Copyright (c) 2012 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 <stdio.h>
22 #include <string.h>
23 #include <pthread.h>
24 #include <unistd.h>
25 #include <stdlib.h>
26 #include <time.h>
27 #include <dlfcn.h>
28 #include <getopt.h>
29
30 #include <glib.h>
31 #include <glib-object.h>
32
33 #include <tcore.h>
34 #include <plugin.h>
35 #include <server.h>
36 #include <hal.h>
37 #include <queue.h>
38 #include <storage.h>
39 #include <communicator.h>
40 #include <user_request.h>
41
42 #include "monitor.h"
43
44 /* hacking TcoreQueue */
45 struct tcore_queue_type {
46         TcorePlugin *plugin;
47         GQueue *gq;
48 };
49
50 static void _monitor_plugin(Server *s)
51 {
52         GSList *list;
53         TcorePlugin *p;
54         char *str;
55
56         msg("-- Plugins --");
57
58         list = tcore_server_ref_plugins(s);
59         if (!list)
60                 return;
61
62         do {
63                 p = list->data;
64
65                 msg("Name: [%s]", tcore_plugin_get_description(p)->name);
66
67                 str = tcore_plugin_get_filename(p);
68                 msg(" - file: %s", str);
69                 if (str)
70                         free(str);
71
72                 msg(" - addr: %p", p);
73                 msg(" - userdata: %p", tcore_plugin_ref_user_data(p));
74                 msg("");
75
76
77                 list = list->next;
78         } while(list);
79 }
80
81 static void _monitor_storage(Server *s)
82 {
83         GSList *list;
84         Storage *strg;
85
86         msg("-- Storages --");
87
88         list = tcore_server_ref_storages(s);
89         if (!list)
90                 return;
91
92         do {
93                 strg = list->data;
94
95                 msg("Name: [%s]", tcore_storage_ref_name(strg));
96                 msg(" - addr: %p", strg);
97                 msg("");
98
99                 list = list->next;
100         } while(list);
101 }
102
103 static void _monitor_communicator(Server *s)
104 {
105         GSList *list;
106         Communicator *comm;
107
108         msg("-- Coomunicators --");
109
110         list = tcore_server_ref_communicators(s);
111         if (!list)
112                 return;
113
114         do {
115                 comm = list->data;
116
117                 msg("Name: [%s]", tcore_communicator_ref_name(comm));
118                 msg(" - addr: %p", comm);
119                 msg(" - parent_plugin: %p", tcore_communicator_ref_plugin(comm));
120                 msg(" - userdata: %p", tcore_communicator_ref_user_data(comm));
121                 msg("");
122
123                 list = list->next;
124         } while(list);
125 }
126
127 static void _monitor_hal(Server *s)
128 {
129         GSList *list;
130         TcoreHal *h;
131         TcoreQueue *q;
132         TcorePending *pending;
133         UserRequest *ur;
134         char *str;
135         int qlen;
136         int i;
137         void *data;
138         unsigned int data_len;
139
140         msg("-- Hals --");
141
142         list = tcore_server_ref_hals(s);
143         if (!list)
144                 return;
145
146         do {
147                 h = list->data;
148
149                 str = tcore_hal_get_name(h);
150                 msg("Name: [%s]", str);
151                 msg(" - addr: %p", h);
152                 msg(" - parent_plugin: %p", tcore_hal_ref_plugin(h));
153                 msg(" - userdata: %p", tcore_hal_ref_user_data(h));
154
155                 q = tcore_hal_ref_queue(h);
156                 if (!q) {
157                         msg("");
158                         list = list->next;
159                         continue;
160                 }
161
162                 if (!(q->gq)) {
163                         msg("");
164                         list = list->next;
165                         continue;
166                 }
167
168                 qlen = tcore_queue_get_length(q);
169                 msg(" - queue: %p, length: %d", q, qlen);
170                 msg("   queue_head: %p", g_queue_peek_head(q->gq));
171                 for (i = 0; i < qlen; i++) {
172                         pending = g_queue_peek_nth(q->gq, i);
173                         ur = tcore_pending_ref_user_request(pending);
174                         msg("   [%02d] pending=%p, id=0x%x, ur=%p", i, pending, tcore_pending_get_id(pending), ur);
175                         if (ur) {
176                                 msg("        ur request command = 0x%x", tcore_user_request_get_command(ur));
177                         }
178                         data_len = 0;
179                         data = tcore_pending_ref_request_data(pending, &data_len);
180                         msg("        data=%p, data_len=%d", data, data_len);
181                 }
182                 msg("   queue_tail: %p", g_queue_peek_tail(q->gq));
183                 msg("");
184
185                 list = list->next;
186         } while(list);
187 }
188
189 void monitor_server_state(Server *s)
190 {
191         _monitor_plugin(s);
192         _monitor_storage(s);
193         _monitor_communicator(s);
194         _monitor_hal(s);
195 }