upload tizen1.0 source
[profile/ivi/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
39 #include "monitor.h"
40
41 /* hacking TcoreQueue */
42 struct tcore_queue_type {
43         TcorePlugin *plugin;
44         GQueue *gq;
45 };
46
47 static void _monitor_plugin(Server *s)
48 {
49         GSList *list;
50         TcorePlugin *p;
51         char *str;
52
53         msg("-- Plugins --");
54
55         list = tcore_server_ref_plugins(s);
56         if (!list)
57                 return;
58
59         do {
60                 p = list->data;
61
62                 msg("Name: [%s]", tcore_plugin_get_description(p)->name);
63
64                 str = tcore_plugin_get_filename(p);
65                 msg(" - file: %s", str);
66                 if (str)
67                         free(str);
68
69                 msg(" - addr: %p", p);
70                 msg(" - ref_hal: %p", tcore_plugin_ref_hal(p));
71                 if (tcore_plugin_ref_hal(p)) {
72                         str = tcore_hal_get_name(tcore_plugin_ref_hal(p));
73                         msg(" - ref_hal_name: %s", str);
74                         if (str)
75                                 free(str);
76                 }
77                 msg(" - userdata: %p", tcore_plugin_ref_user_data(p));
78                 msg("");
79
80
81                 list = list->next;
82         } while(list);
83 }
84
85 static void _monitor_storage(Server *s)
86 {
87         GSList *list;
88         Storage *strg;
89         char *str;
90
91         msg("-- Storages --");
92
93         list = tcore_server_ref_storages(s);
94         if (!list)
95                 return;
96
97         do {
98                 strg = list->data;
99
100                 msg("Name: [%s]", tcore_storage_ref_name(strg));
101                 msg(" - addr: %p", strg);
102                 msg("");
103
104                 list = list->next;
105         } while(list);
106 }
107
108 static void _monitor_communicator(Server *s)
109 {
110         GSList *list;
111         Communicator *comm;
112
113         msg("-- Coomunicators --");
114
115         list = tcore_server_ref_communicators(s);
116         if (!list)
117                 return;
118
119         do {
120                 comm = list->data;
121
122                 msg("Name: [%s]", tcore_communicator_ref_name(comm));
123                 msg(" - addr: %p", comm);
124                 msg(" - parent_plugin: %p", tcore_communicator_ref_plugin(comm));
125                 msg(" - userdata: %p", tcore_communicator_ref_user_data(comm));
126                 msg("");
127
128                 list = list->next;
129         } while(list);
130 }
131
132 static void _monitor_hal(Server *s)
133 {
134         GSList *list;
135         TcoreHal *h;
136         TcoreQueue *q;
137         TcorePending *pending;
138         char *str;
139         int qlen;
140         int i;
141         void *data;
142         unsigned int data_len;
143
144         msg("-- Hals --");
145
146         list = tcore_server_ref_hals(s);
147         if (!list)
148                 return;
149
150         do {
151                 h = list->data;
152
153                 str = tcore_hal_get_name(h);
154                 msg("Name: [%s]", str);
155                 msg(" - addr: %p", h);
156                 msg(" - parent_plugin: %p", tcore_hal_ref_plugin(h));
157                 msg(" - userdata: %p", tcore_hal_ref_user_data(h));
158
159                 q = tcore_hal_ref_queue(h);
160                 if (!q) {
161                         msg("");
162                         list = list->next;
163                         continue;
164                 }
165
166                 if (!(q->gq)) {
167                         msg("");
168                         list = list->next;
169                         continue;
170                 }
171
172                 qlen = tcore_queue_get_length(q);
173                 msg(" - queue: %p, length: %d", q, qlen);
174                 msg("   queue_head: %p", g_queue_peek_head(q->gq));
175                 for (i = 0; i < qlen; i++) {
176                         pending = g_queue_peek_nth(q->gq, i);
177                         msg("   [%02d] pending=%p, id=0x%x, ur=%p", i, pending, tcore_pending_get_id(pending), tcore_pending_ref_user_request(pending));
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 }