Debian Codegraph @

test/frei0r-meta.c

raw symbols SCIP
1 /* This file is part of frei0r (https://frei0r.dyne.org)
2 *
3 * Copyright (C) 2024-2025 Dyne.org foundation
4 * designed, written and maintained by Denis Roio <[email protected]>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <string.h>
25 #include <dlfcn.h>
26 #include <libgen.h>
27
28 #include <frei0r.h>
29
30 // frei0r function prototypes
31 typedef int (*f0r_init_f)(void);
32 typedef void (*f0r_deinit_f)(void);
33 typedef void (*f0r_get_plugin_info_f)(f0r_plugin_info_t *info);
34 typedef void (*f0r_get_param_info_f)(f0r_param_info_t *info, int param_index);
35
36 int main(int argc, char **argv) {
37
38 // instance frei0r pointers
39 static void *dl_handle;
40 static f0r_init_f f0r_init;
41 static f0r_init_f f0r_deinit;
42 static f0r_plugin_info_t pi;
43 static f0r_get_plugin_info_f f0r_get_plugin_info;
44 static f0r_get_param_info_f f0r_get_param_info;
45 static f0r_param_info_t param;
46
47 int c;
48
49 if(argc<2) exit(1);
50 const char *file = basename(argv[1]);
51 const char *dir = dirname(argv[1]);
52 char path[256];;
53 snprintf(path, 255,"%s/%s",dir,file);
54 // fprintf(stderr,"%s %s\n",argv[0], file);
55 // load shared library
56 dl_handle = dlopen(path, RTLD_NOW|RTLD_LOCAL);
57 if(!dl_handle) {
58 fprintf(stderr,"error: %s\n",dlerror());
59 exit(1);
60 }
61 // get plugin function calls
62 f0r_init = dlsym(dl_handle,"f0r_init");
63 f0r_deinit = dlsym(dl_handle,"f0r_deinit");
64 f0r_get_plugin_info = dlsym(dl_handle,"f0r_get_plugin_info");
65 f0r_get_param_info = dlsym(dl_handle,"f0r_get_param_info");
66 // always initialize plugin first
67 f0r_init();
68 // get info about plugin
69 f0r_get_plugin_info(&pi);
70 fprintf(stdout,
71 "{\n \"name\":\"%s\",\n \"type\":\"%s\",\n \"author\":\"%s\",\n"
72 " \"explanation\":\"%s\",\n \"color_model\":\"%s\",\n"
73 " \"frei0r_version\":\"%d\",\n \"version\":\"%d.%d\",\n \"num_params\":\"%d\"",
74 pi.name,
75 pi.plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" :
76 pi.plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" :
77 pi.plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" :
78 pi.plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown",
79 pi.author, pi.explanation,
80 pi.color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" :
81 pi.color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" :
82 pi.color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown",
83 pi.frei0r_version, pi.major_version, pi.minor_version, pi.num_params);
84
85 /* // check icon */
86 /* char icon[256]; */
87 /* char *dot = rindex(file, '.'); */
88 /* *dot = 0x0; */
89 /* snprintf(icon,255,"%s/%s.png",dir,file); */
90 /* FILE *icon_fd = fopen(icon,"r"); */
91 /* if(icon_fd) { */
92 /* fprintf(stderr," icon found: %s\n",icon); */
93 /* } */
94
95 // get info about params
96 if(pi.num_params>0) {
97 fprintf(stdout,",\n \"params\":[\n");
98 for(c=0; c<pi.num_params; c++) {
99 f0r_get_param_info(&param, c);
100 fprintf(stdout,
101 " {\n \"name\":\"%s\",\n \"type\":\"%s\",\n \"explanation\":\"%s\"\n }",
102 param.name,
103 param.type == F0R_PARAM_BOOL ? "bool" :
104 param.type == F0R_PARAM_COLOR ? "color" :
105 param.type == F0R_PARAM_DOUBLE ? "number" :
106 param.type == F0R_PARAM_POSITION ? "position" :
107 param.type == F0R_PARAM_STRING ? "string" : "unknown",
108 param.explanation);
109 if(pi.num_params>c+1) {
110 fprintf(stdout,",\n");
111 } else {
112 fprintf(stdout,"\n");
113 }
114 }
115 fprintf(stdout," ]\n");
116 }
117 fprintf(stdout,"\n}\n");
118 fflush(stdout);
119 f0r_deinit();
120 dlclose(dl_handle);
121 exit(0);
122 }