Add .changes file
[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 #include <storage.h>
39 #include <communicator.h>
40
41 #include "monitor.h"
42
43 /* hacking TcoreQueue */
44 struct tcore_queue_type {
45         TcorePlugin *plugin;
46         GQueue *gq;
47 };
48
49 static void _monitor_plugin(Server *s)
50 {
51         GSList *list;
52         TcorePlugin *p;
53         char *str;
54
55         msg("-- Plugins --");
56
57         list = tcore_server_ref_plugins(s);
58         if (!list)
59                 return;
60
61         do {
62                 p = list->data;
63
64                 msg("Name: [%s]", tcore_plugin_get_description(p)->name);
65
66                 str = tcore_plugin_get_filename(p);
67                 msg(" - file: %s", str);
68                 if (str)
69                         free(str);
70
71                 msg(" - addr: %p", p);
72                 msg(" - userdata: %p", tcore_plugin_ref_user_data(p));
73                 msg("");
74
75
76                 list = list->next;
77         } while(list);
78 }
79
80 static void _monitor_storage(Server *s)
81 {
82         GSList *list;
83         Storage *strg;
84         char *str;
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         char *str;
134         int qlen;
135         int i;
136         void *data;
137         unsigned int data_len;
138
139         msg("-- Hals --");
140
141         list = tcore_server_ref_hals(s);
142         if (!list)
143                 return;
144
145         do {
146                 h = list->data;
147
148                 str = tcore_hal_get_name(h);
149                 msg("Name: [%s]", str);
150                 msg(" - addr: %p", h);
151                 msg(" - parent_plugin: %p", tcore_hal_ref_plugin(h));
152                 msg(" - userdata: %p", tcore_hal_ref_user_data(h));
153
154                 q = tcore_hal_ref_queue(h);
155                 if (!q) {
156                         msg("");
157                         list = list->next;
158                         continue;
159                 }
160
161                 if (!(q->gq)) {
162                         msg("");
163                         list = list->next;
164                         continue;
165                 }
166
167                 qlen = tcore_queue_get_length(q);
168                 msg(" - queue: %p, length: %d", q, qlen);
169                 msg("   queue_head: %p", g_queue_peek_head(q->gq));
170                 for (i = 0; i < qlen; i++) {
171                         pending = g_queue_peek_nth(q->gq, i);
172                         msg("   [%02d] pending=%p, id=0x%x, ur=%p", i, pending, tcore_pending_get_id(pending), tcore_pending_ref_user_request(pending));
173                         data_len = 0;
174                         data = tcore_pending_ref_request_data(pending, &data_len);
175                         msg("        data=%p, data_len=%d", data, data_len);
176                 }
177                 msg("   queue_tail: %p", g_queue_peek_tail(q->gq));
178                 msg("");
179
180                 list = list->next;
181         } while(list);
182 }
183
184 void monitor_server_state(Server *s)
185 {
186         _monitor_plugin(s);
187         _monitor_storage(s);
188         _monitor_communicator(s);
189         _monitor_hal(s);
190 }