source: roaraudio/plugins/universal/debug-notify.c @ 5961:06e7fd9e4c25

Last change on this file since 5961:06e7fd9e4c25 was 5961:06e7fd9e4c25, checked in by phi, 10 years ago

Updates of copyright and license headers

File size: 8.5 KB
Line 
1//debug-notify.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2014
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27#include <ctype.h>
28
29static struct roar_subscriber * subscription_client_delete = NULL;
30
31static int command_get_name(int cmd, const char ** name) {
32 static const struct {
33  const int cmd;
34  const char * name;
35 } cmds[] = {
36  {ROAR_CMD_NOOP,                    "NOOP"},
37  {ROAR_CMD_IDENTIFY,                "IDENTIFY"},
38  {ROAR_CMD_AUTH,                    "AUTH"},
39  {ROAR_CMD_NEW_STREAM,              "NEW_STREAM"},
40  {ROAR_CMD_SET_META,                "SET_META"},
41  {ROAR_CMD_EXEC_STREAM,             "EXEC_STREAM"},
42  {ROAR_CMD_QUIT,                    "QUIT"},
43  {ROAR_CMD_GET_STANDBY,             "GET_STANDBY"},
44  {ROAR_CMD_SET_STANDBY,             "SET_STANDBY"},
45  {ROAR_CMD_SERVER_INFO,             "SERVER_INFO"},
46  {ROAR_CMD_SERVER_STATS,            "SERVER_STATS"},
47  {ROAR_CMD_SERVER_OINFO,            "SERVER_OINFO"},
48  {ROAR_CMD_ADD_DATA,                "ADD_DATA"},
49  {ROAR_CMD_EXIT,                    "EXIT"},
50  {ROAR_CMD_LIST_STREAMS,            "LIST_STREAMS"},
51  {ROAR_CMD_LIST_CLIENTS,            "LIST_CLIENTS"},
52  {ROAR_CMD_GET_CLIENT,              "GET_CLIENT"},
53  {ROAR_CMD_GET_STREAM,              "GET_STREAM"},
54  {ROAR_CMD_KICK,                    "KICK"},
55  {ROAR_CMD_SET_VOL,                 "SET_VOL"},
56  {ROAR_CMD_GET_VOL,                 "GET_VOL"},
57  {ROAR_CMD_CON_STREAM,              "CON_STREAM"},
58  {ROAR_CMD_GET_META,                "GET_META"},
59  {ROAR_CMD_LIST_META,               "LIST_META"},
60  {ROAR_CMD_BEEP,                    "BEEP"},
61  {ROAR_CMD_GET_STREAM_PARA,         "GET_STREAM_PARA"},
62  {ROAR_CMD_SET_STREAM_PARA,         "SET_STREAM_PARA"},
63  {ROAR_CMD_ATTACH,                  "ATTACH"},
64  {ROAR_CMD_DETACH,                  "DETACH"},
65  {ROAR_CMD_PASSFH,                  "PASSFH"},
66  {ROAR_CMD_GETTIMEOFDAY,            "GETTIMEOFDAY"},
67  {ROAR_CMD_WHOAMI,                  "WHOAMI"},
68  {ROAR_CMD_DEVCTL,                  "DEVCTL"},
69  {ROAR_CMD_CAPS,                    "CAPS"},
70  {ROAR_CMD_WAIT,                    "WAIT"},
71  {ROAR_CMD_NOTIFY,                  "NOTIFY"},
72  {ROAR_CMD_SEEK,                    "SEEK"},
73  {ROAR_CMD_CLIENTCTL,               "CLIENTCTL"},
74  {ROAR_CMD_LOOKUP,                  "LOOKUP"},
75  {ROAR_CMD_CONCTL,                  "CONCTL"},
76  {ROAR_CMD_SHIFT_DATA,              "SHIFT_DATA"},
77  {ROAR_CMD_RAUM_SEEKTABLE,          "RAUM_SEEKTABLE"},
78  {ROAR_CMD_RAUM_PICTURE,            "RAUM_PICTURE"},
79  {ROAR_CMD_RAUM_SYNC,               "RAUM_SYNC"},
80  {ROAR_CMD_EPERM,                   "EPERM"},
81  {ROAR_CMD_OK_STOP,                 "OK_STOP"},
82  {ROAR_CMD_OK,                      "OK"},
83  {ROAR_CMD_ERROR,                   "ERROR"},
84  {ROAR_CMD_EOL,                     "EOL"}
85 };
86 size_t i;
87
88 for (i = 0; i < (sizeof(cmds)/sizeof(*cmds)); i++) {
89  if ( cmds[i].cmd == cmd ) {
90   *name = cmds[i].name;
91   return 0;
92  }
93 }
94
95 roar_err_set(ROAR_ERROR_NOENT);
96 return -1;
97}
98
99static void dbg_notify_cb(struct roar_notify_core * core, struct roar_event * event, void * userdata) {
100 char buf[1024] = "";
101 char estr[1024] = "/* ROAR_??? */";
102 char ttstr[1024] = "/* ROAR_OT_??? */";
103 const char * ttname;
104 uint32_t ev = ROAR_EVENT_GET_TYPE(event);
105 int i;
106
107 ttname = roar_ot2str(event->target_type);
108 if ( ttname != NULL ) {
109  snprintf(ttstr, sizeof(ttstr)-1, "/* ROAR_OT_%s */", ttname);
110  buf[sizeof(ttstr)-1] = 0;
111  for (i = 0; ttstr[i] != 0; i++)
112   if ( islower(ttstr[i]) )
113    ttstr[i] = toupper(ttstr[i]);
114 }
115
116 if ( ev == ROAR_NOTIFY_SPECIAL ) {
117  snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_SPECIAL */");
118 } else if ( ROAR_NOTIFY_IS_CMD(ev) ) {
119  if ( command_get_name(ROAR_NOTIFY_EVENT2CMD(ev), &ttname) == -1 ) {
120   snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_CMD2EVENT(%lu) */", (long unsigned int)ROAR_NOTIFY_EVENT2CMD(ev));
121  } else {
122   snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_CMD2EVENT(ROAR_CMD_%s) */", ttname);
123   for (i = 0; estr[i] != 0; i++)
124    if ( islower(estr[i]) )
125     estr[i] = toupper(estr[i]);
126  }
127 } else if ( ROAR_NOTIFY_IS_EGRP(ev) ) {
128  snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_EGRP2EVENT(%lu) */", (long unsigned int)ROAR_NOTIFY_EVENT2EGRP(ev));
129 } else if ( ROAR_NOTIFY_IS_OE(ev) ) {
130  switch (ev) {
131   // OE basics:
132   case ROAR_OE_BASICS_CHANGE_STATE:
133     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_CHANGE_STATE */");
134    break;
135   case ROAR_OE_BASICS_CHANGE_FLAGS:
136     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_CHANGE_FLAGS */");
137    break;
138   case ROAR_OE_BASICS_NEW:
139     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_NEW */");
140    break;
141   case ROAR_OE_BASICS_DELETE:
142     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_DELETE */");
143    break;
144   // OE Streams:
145   case ROAR_OE_STREAM_CHANGE_VOLUME:
146     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_STREAM_CHANGE_VOLUME */");
147    break;
148   case ROAR_OE_STREAM_XRUN:
149     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_STREAM_XRUN */");
150    break;
151   case ROAR_OE_STREAM_META_UPDATE:
152     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_STREAM_META_UPDATE */");
153    break;
154   // OE Default:
155   default:
156     snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_OE2EVENT(%lu) */", (long unsigned int)ROAR_NOTIFY_EVENT2OE(ev));
157    break;
158  }
159 } else if ( ROAR_NOTIFY_IS_DATA(ev) ) {
160  switch (ev) {
161   case ROAR_DATA_DMX512_CHANNEL_UPDATE:
162     snprintf(estr, sizeof(estr)-1, "/* ROAR_DATA_DMX512_CHANNEL_UPDATE */");
163    break;
164   case ROAR_DATA_DMX512_EVENT:
165     snprintf(estr, sizeof(estr)-1, "/* ROAR_DATA_DMX512_EVENT */");
166    break;
167   // DATA Default:
168   default:
169     snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_EVENT2DATA(ROAR_DATA_GROUP(%s) + %lu) */", roar_dir2str(ROAR_DATA_EVENT2DIR(ROAR_NOTIFY_EVENT2DATA(ev))), (long unsigned int)ROAR_DATA_EVENT2EVENT(ROAR_NOTIFY_EVENT2DATA(ev)));
170    break;
171  }
172 } else if ( ROAR_NOTIFY_IS_USER(ev) ) {
173  snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_USER2EVENT(%lu) */", (long unsigned int)ROAR_NOTIFY_EVENT2USER(ev));
174 }
175
176 buf[sizeof(estr)-1] = 0;
177
178 if ( event->flags & ROAR_EVENT_FLAG_PROXYEVENT ) {
179  snprintf(buf, sizeof(buf)-1, ".event_proxy=0x%.8x%s, ", (int)event->event_proxy, estr);
180  buf[sizeof(buf)-1] = 0;
181 }
182
183 roar_debug_msg(ROAR_DEBUG_TYPE_DEBUG, __LINE__, __FILE__, ROAR_DBG_PREFIX, "dbg_notify_cb(core=%p, event=%p{.flags=0x%.8x, event=0x%.8x%s, %s.emitter=%i, .target=%i, .target_type=%i%s, .arg0=%i, .arg1=%i, .arg2=%p}, userdata=%p) = (void)",
184           core, event,
185           (int)event->flags,
186           (int)event->event,
187           (event->flags & ROAR_EVENT_FLAG_PROXYEVENT ? "" : estr),
188           buf,
189           event->emitter,
190           event->target,
191           event->target_type,
192           ttstr,
193           event->arg0,
194           event->arg1,
195           event->arg2,
196           userdata);
197}
198
199static int init(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) {
200 struct roar_event event;
201
202 (void)para, (void)lib;
203
204 memset(&event, 0, sizeof(event));
205
206 event.event = ROAR_EGRP_ANY_EVENT;
207
208 event.emitter = -1;
209 event.target = -1;
210 event.target_type = -1;
211
212 subscription_client_delete = roar_notify_core_subscribe(NULL, &event, dbg_notify_cb, NULL);
213
214 return 0;
215}
216
217static int unload(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) {
218 (void)para, (void)lib;
219
220 roar_notify_core_unsubscribe(NULL, subscription_client_delete);
221
222 return 0;
223}
224
225ROAR_DL_PLUGIN_START(debug_notify) {
226 ROAR_DL_PLUGIN_META_PRODUCT_NIV("debug-notify", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
227 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
228 ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0);
229 ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org");
230 ROAR_DL_PLUGIN_META_DESC("This plugin will print all messages passed via notify bus");
231 ROAR_DL_PLUGIN_REG(ROAR_DL_FN_INIT, init);
232 ROAR_DL_PLUGIN_REG_UNLOAD(unload);
233} ROAR_DL_PLUGIN_END
234
235//ll
Note: See TracBrowser for help on using the repository browser.