source: roaraudio/roarclients/roarpluginrunner.c @ 5346:82b51c5c7b13

Last change on this file since 5346:82b51c5c7b13 was 5346:82b51c5c7b13, checked in by phi, 12 years ago

nicer and more gdb like output of arrays with similar element values

File size: 7.4 KB
Line 
1//roarpluginrunner.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2011
5 *
6 *  This file is part of roarclients 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
26int g_verbose = 0;
27#define ROAR_DBG_INFOVAR g_verbose
28
29#include <roaraudio.h>
30
31enum action {
32 RUN,
33 EXPLAIN
34};
35
36static struct roar_dl_librarypara * g_para = NULL;
37
38void usage (const char * progname) {
39 fprintf(stderr, "Usage: %s [OPTIONS]... PLUGIN\n", progname);
40
41 fprintf(stderr, "\nOptions:\n\n");
42
43 fprintf(stderr, " -h --help         - This help.\n"
44                 "    --verbose      - Be verbose. Can be used multiple times.\n"
45                 "    --run          - Run plugin.\n"
46                 "    --explain      - Explain plugin.\n");
47}
48
49static int do_run(const char * name) {
50 struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, g_para);
51
52 if ( lhandle == NULL )
53  return -1;
54
55 roar_dl_appsched_trigger(lhandle, ROAR_DL_APPSCHED_INIT);
56
57 while (roar_dl_appsched_trigger(lhandle, ROAR_DL_APPSCHED_WAIT) == 0)
58  roar_dl_appsched_trigger(lhandle, ROAR_DL_APPSCHED_UPDATE);
59
60 roar_dl_appsched_trigger(lhandle, ROAR_DL_APPSCHED_UPDATE);
61 roar_dl_appsched_trigger(lhandle, ROAR_DL_APPSCHED_FREE);
62
63 roar_dl_unref(lhandle);
64 return 0;
65}
66
67static const char * _ptr2str(const void * p) {
68 static char buf[24];
69
70 if ( p == NULL )
71  return "<not set>";
72
73 snprintf(buf, sizeof(buf), "%p", p);
74
75 return buf;
76}
77
78static const char * _ptrrange2str(const void * p, size_t len) {
79 static char buf[48];
80
81 if ( p == NULL )
82  return "<not set>";
83
84 if ( len == 0 )
85  return _ptr2str(p);
86
87 snprintf(buf, sizeof(buf), "%p-%p", p, p + len);
88
89 return buf;
90}
91
92static int do_explain(const char * name) {
93 struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_LAZY, 0, NULL);
94 struct roar_dl_libraryinst * (*func)(struct roar_dl_librarypara * para);
95 struct roar_dl_libraryinst * lib;
96 int libok = 0, libnameok = 0;
97 int tmp;
98 int i;
99
100 if ( lhandle == NULL )
101  return -1;
102
103 func = roar_dl_getsym(lhandle, "_roaraudio_library_init", -1);
104 if ( func == NULL ) {
105  fprintf(stderr, "Warning: Not a RA lib: %s\n", name);
106  roar_dl_unref(lhandle);
107  return 0;
108 }
109
110 lib = func(g_para);
111 if ( lib == NULL ) {
112  fprintf(stderr, "Warning: Can not RA init: %s\n", name);
113  roar_dl_unref(lhandle);
114  return 0;
115 }
116
117 if ( lib->version == ROAR_DL_LIBINST_VERSION && lib->len == sizeof(*lib) ) {
118  libok = 1;
119 }
120
121 printf("lib                     = %s\n", _ptr2str(lib));
122 printf("|-> version             = %i (%smatch)\n", lib->version, lib->version == ROAR_DL_LIBINST_VERSION ? "" : "no ");
123 printf("%c-> len                 = %zu (%smatch)\n", libok ? '|' : '\\', lib->len, lib->len == sizeof(*lib) ? "" : "no ");
124
125 if ( libok ) {
126  printf("|-> unload              = %s\n", _ptr2str(lib->unload));
127  printf("|-> func                = {");
128  i = 0;
129  while (i < ROAR_DL_FN_MAX) {
130   for (tmp = 0; i < ROAR_DL_FN_MAX; i++) {
131    if ( lib->func[i] != NULL ) {
132     break;
133    }
134    tmp++;
135   }
136   if (tmp)
137    printf("%i x <not set>%s", tmp, i < (ROAR_DL_FN_MAX-1) ? ", " : "");
138
139   if ( i < ROAR_DL_FN_MAX ) {
140    printf("[%i] = %s%s", i, _ptr2str(lib->func[i]), i < (ROAR_DL_FN_MAX-1) ? ", " : "");
141    i++;
142   }
143  }
144
145  printf("}\n");
146  printf("|-> libname             = %s\n", _ptr2str(lib->libname));
147  if ( lib->libname != NULL ) {
148   if ( lib->libname->version == ROAR_DL_LIBNAME_VERSION && lib->libname->len == sizeof(*(lib->libname)) ) {
149    libnameok = 1;
150   }
151   printf("|   |-> version         = %i (%smatch)\n", lib->libname->version,
152                                                      lib->libname->version == ROAR_DL_LIBNAME_VERSION ? "" : "no ");
153   printf("|   %c-> len             = %zu (%smatch)\n", libnameok ? '|' : '\\', lib->libname->len,
154                                                      lib->libname->len == sizeof(*(lib->libname)) ? "" : "no ");
155   if ( libnameok ) {
156#define _ps(c,name) \
157    tmp = (lib->libname->name) != NULL; \
158    printf("|   %c-> %-15s = %s%s%s\n", (c), #name, tmp ? "\"" : "", \
159                                    tmp ? (lib->libname->name) : "<not set>", tmp ? "\"" : "");
160
161    _ps('|', name);
162    _ps('|', libname);
163    _ps('|', libversion);
164    _ps('|', abiversion);
165    _ps('|', description);
166    _ps('|', contact);
167    _ps('|', authors);
168    _ps('\\', license);
169#undef _ps
170   }
171  }
172  printf("|-> global_data_len     = %zu\n", lib->global_data_len);
173  printf("|-> global_data_init    = %s\n", _ptrrange2str(lib->global_data_init, lib->global_data_len));
174  printf("|-> global_data_pointer = %s\n", _ptr2str(lib->global_data_pointer));
175  printf("|-> libdep              = %s\n", _ptr2str(lib->libdep));
176  printf("|-> libdep_len          = %zu\n", lib->libdep_len);
177  printf("\\-> appsched            = %s\n", _ptr2str(lib->appsched));
178  if ( lib->appsched != NULL ) {
179   printf("    |-> init            = %s\n", _ptr2str(lib->appsched->init));
180   printf("    |-> free            = %s\n", _ptr2str(lib->appsched->free));
181   printf("    |-> update          = %s\n", _ptr2str(lib->appsched->update));
182   printf("    |-> tick            = %s\n", _ptr2str(lib->appsched->tick));
183   printf("    \\-> wait            = %s\n", _ptr2str(lib->appsched->wait));
184  }
185 }
186
187 roar_dl_unref(lhandle);
188 return 0;
189}
190
191static int do_plugin(enum action action, const char * name) {
192 switch (action) {
193  case EXPLAIN:
194    return do_explain(name);
195   break;
196  case RUN:
197    return do_run(name);
198   break;
199  default:
200    roar_err_set(ROAR_ERROR_BADRQC);
201    return -1;
202   break;
203 }
204}
205
206static inline void _clear_para(void) {
207 if ( g_para == NULL )
208  return;
209
210 roar_dl_para_unref(g_para);
211 g_para = NULL;
212}
213
214int main (int argc, char * argv[]) {
215 const char * appname    = "roarpluginrunner";
216 const char * abiversion = NULL;
217 const char * pluginargs = NULL;
218 enum action action = RUN;
219 int ret = 0;
220 int i;
221 char * k;
222
223 for (i = 1; i < argc; i++) {
224  k = argv[i];
225
226  if ( !strcmp(k, "-h") || !strcmp(k, "--help") ) {
227   usage(argv[0]);
228   return 0;
229  } else if ( !strcmp(k, "--run") ) {
230   action = RUN;
231  } else if ( !strcmp(k, "--explain") ) {
232   action = EXPLAIN;
233  } else if ( !strcmp(k, "--verbose") ) {
234   g_verbose++;
235  } else if ( !strcmp(k, "--appname") ) {
236   appname = argv[++i];
237   _clear_para();
238  } else if ( !strcmp(k, "--abiversion") ) {
239   abiversion = argv[++i];
240   _clear_para();
241  } else if ( !strcmp(k, "--args") ) {
242   pluginargs = argv[++i];
243   _clear_para();
244  } else {
245   if ( g_para == NULL )
246    g_para = roar_dl_para_new(pluginargs, NULL, appname, abiversion);
247   roar_err_set(ROAR_ERROR_NONE);
248   if ( do_plugin(action, k) == -1 ) {
249    fprintf(stderr, "Error loading plugin: %s\n",
250                    roar_error != ROAR_ERROR_NONE ? roar_error2str(roar_error) : roar_dl_errstr(NULL));
251    ret = 1;
252   }
253  }
254 }
255
256 _clear_para();
257
258 return ret;
259}
260
261//ll
Note: See TracBrowser for help on using the repository browser.