18 #include "lirc/driver.h"
19 #include "lirc/drv_admin.h"
20 #include "lirc/lirc_options.h"
25 static const char*
const PLUGIN_FILE_EXTENSION =
"so";
29 #define MAX_PLUGINS 256
40 static void* last_plugin = NULL;
45 .device =
"/dev/null",
60 .driver_version =
"0.9.2"
69 static int ends_with_so(
const char* str)
71 char* dot = strrchr(str,
'.');
73 return (NULL == dot) ? 0 : strcmp(dot + 1, PLUGIN_FILE_EXTENSION) == 0;
78 static int line_cmp(
const void* arg1,
const void* arg2)
80 return strcmp(*(
const char**)arg1, *(
const char**)arg2);
85 static struct driver* add_hw_name(
struct driver* hw,
void* arg)
87 char_array* a = (char_array*)arg;
90 logprintf(LIRC_ERROR,
"Too many plugins(%d)",
MAX_PLUGINS);
93 a->array[a->size] = strdup(hw->
name);
102 if (drv == (
struct driver*)NULL || name == NULL)
103 return (
struct driver*)NULL;
104 if (strcasecmp(drv->
name, (
char*)name) == 0)
106 return (
struct driver*)NULL;
118 if (last_plugin != NULL)
119 dlclose(last_plugin);
120 last_plugin = dlopen(path, RTLD_NOW);
121 if (last_plugin == NULL) {
122 logprintf(LIRC_ERROR, dlerror());
125 drivers = (
struct driver**)dlsym(last_plugin,
"hardwares");
126 if (drivers == (
struct driver**)NULL) {
127 logprintf(LIRC_WARNING,
128 "No hardwares entrypoint found in %s", path);
130 for (; *drivers; drivers++) {
131 if ((*drivers)->name == NULL) {
132 logprintf(LIRC_WARNING,
133 "No driver name in %s", path);
136 result = (*func)(*drivers, arg);
137 if (result != (
struct driver*)NULL)
146 static struct driver* for_each_plugin_in_dir(
const char* dirpath,
157 dir = opendir(dirpath);
159 logprintf(LIRC_INFO,
"Cannot open plugindir %s", dirpath);
160 return (
struct driver*)NULL;
162 while ((ent = readdir(dir)) != NULL) {
163 if (!ends_with_so(ent->d_name))
165 strncpy(buff, dirpath,
sizeof(buff) - 1);
166 if (buff[strlen(buff) - 1] ==
'/')
167 buff[strlen(buff) - 1] =
'\0';
168 snprintf(path,
sizeof(path),
169 "%s/%s", buff, ent->d_name);
170 result = plugin_guest(path, drv_guest, arg);
171 if (result != (
struct driver*)NULL)
183 const char* pluginpath;
191 if (pluginpath == NULL)
193 if (strchr(pluginpath,
':') == (
char*)NULL) {
194 return for_each_plugin_in_dir(pluginpath,
199 tmp_path = alloca(strlen(pluginpath) + 1);
200 strncpy(tmp_path, pluginpath, strlen(pluginpath) + 1);
201 for (s = strtok(tmp_path,
":"); s != NULL; s = strtok(NULL,
":")) {
202 result = for_each_plugin_in_dir(s,
206 if (result != (
struct driver*)NULL)
215 return for_each_path(visit_plugin, func, arg);
221 for_each_path(plugin_guest, NULL, arg);
236 fprintf(stderr,
"Too many plugins (%d)\n",
MAX_PLUGINS);
239 qsort(names.array, names.size,
sizeof(
char*), line_cmp);
240 for (i = 0; i < names.size; i += 1) {
241 fprintf(file,
"%s\n", names.array[i]);
242 free(names.array[i]);
252 memcpy(&drv, &drv_null,
sizeof(
struct driver));
255 if (strcasecmp(name,
"dev/input") == 0)
259 if (found != (
struct driver*)NULL) {
260 memcpy(&drv, found,
sizeof(
struct driver));
const char * ciniparser_getstring(dictionary *d, const char *key, char *def)
Get the string associated to a key.
Interface to the userspace drivers.
const struct driver drv_null
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 *(* plugin_guest_func)(const char *, drv_guest_func, void *)
int hw_choose_driver(const char *name)
int default_open(const char *path)
void for_each_plugin(plugin_guest_func plugin_guest, void *arg)
struct driver * for_each_driver(drv_guest_func func, void *arg)