19 #include "lirc/driver.h" 20 #include "lirc/drv_admin.h" 21 #include "lirc/lirc_options.h" 28 static const char*
const PLUGIN_FILE_EXTENSION =
"so";
32 #define MAX_PLUGINS 256 43 static void* last_plugin = NULL;
48 .device =
"/dev/null",
63 .driver_version =
"0.9.2" 72 static int ends_with_so(
const char* str)
74 char* dot = strrchr(str,
'.');
76 return (NULL == dot) ? 0 : strcmp(dot + 1, PLUGIN_FILE_EXTENSION) == 0;
81 static int line_cmp(
const void* arg1,
const void* arg2)
83 return strcmp(*(
const char**)arg1, *(
const char**)arg2);
88 static struct driver* add_hw_name(
struct driver* hw,
void* arg)
90 char_array* a = (char_array*)arg;
96 a->array[a->size] = strdup(hw->
name);
105 if (drv == (
struct driver*)NULL || name == NULL)
106 return (
struct driver*)NULL;
107 if (strcasecmp(drv->
name, (
char*)name) == 0)
109 return (
struct driver*)NULL;
121 if (last_plugin != NULL)
122 dlclose(last_plugin);
123 last_plugin = dlopen(path, RTLD_NOW);
124 if (last_plugin == NULL) {
128 drivers = (
struct driver**)dlsym(last_plugin,
"hardwares");
129 if (drivers == (
struct driver**)NULL) {
130 log_warn(
"No hardwares entrypoint found in %s", path);
132 for (; *drivers; drivers++) {
133 if ((*drivers)->name == NULL) {
134 log_warn(
"No driver name in %s", path);
137 result = (*func)(*drivers, arg);
138 if (result != (
struct driver*)NULL)
147 static struct driver* for_each_plugin_in_dir(
const char* dirpath,
158 dir = opendir(dirpath);
160 log_info(
"Cannot open plugindir %s", dirpath);
161 return (
struct driver*)NULL;
163 while ((ent = readdir(dir)) != NULL) {
164 if (!ends_with_so(ent->d_name))
166 strncpy(buff, dirpath,
sizeof(buff) - 1);
167 if (buff[strlen(buff) - 1] ==
'/')
168 buff[strlen(buff) - 1] =
'\0';
169 snprintf(path,
sizeof(path),
170 "%s/%s", buff, ent->d_name);
171 result = plugin_guest(path, drv_guest, arg);
172 if (result != (
struct driver*)NULL)
183 const char* pluginpath_arg)
185 const char* pluginpath;
190 if (pluginpath_arg == NULL) {
194 if (pluginpath == NULL)
197 pluginpath = pluginpath_arg;
199 if (strchr(pluginpath,
':') == (
char*)NULL) {
200 return for_each_plugin_in_dir(pluginpath,
205 tmp_path = alloca(strlen(pluginpath) + 1);
206 strncpy(tmp_path, pluginpath, strlen(pluginpath) + 1);
207 for (s = strtok(tmp_path,
":"); s != NULL; s = strtok(NULL,
":")) {
208 result = for_each_plugin_in_dir(s,
212 if (result != (
struct driver*)NULL)
221 const char* pluginpath)
223 return for_each_path(visit_plugin, func, arg, pluginpath);
229 const char* pluginpath)
231 for_each_path(plugin_guest, NULL, arg, pluginpath);
246 fprintf(stderr,
"Too many plugins (%d)\n",
MAX_PLUGINS);
249 qsort(names.array, names.size,
sizeof(
char*), line_cmp);
250 for (i = 0; i < names.size; i += 1) {
251 fprintf(file,
"%s\n", names.array[i]);
252 free(names.array[i]);
262 memcpy(&drv, &drv_null,
sizeof(
struct driver));
265 if (strcasecmp(name,
"dev/input") == 0)
269 if (found != (
struct driver*)NULL) {
270 memcpy(&drv, found,
sizeof(
struct driver));
const char * ciniparser_getstring(dictionary *d, const char *key, char *def)
Get the string associated to a key.
struct driver *(* plugin_guest_func)(const char *, drv_guest_func, void *)
Interface to the userspace drivers.
#define log_warn(fmt,...)
const struct driver drv_null
#define log_error(fmt,...)
void for_each_plugin(plugin_guest_func plugin_guest, void *arg, const char *pluginpath)
void hw_print_drivers(FILE *file)
Prints all drivers known to the system to the file given as argument.
struct driver *(* drv_guest_func)(struct driver *, void *)
int default_drvctl(unsigned int fd, void *arg)
struct driver * for_each_driver(drv_guest_func func, void *arg, const char *pluginpath)
int hw_choose_driver(const char *name)
int default_open(const char *path)
#define log_info(fmt,...)