18 #include "lirc/driver.h" 19 #include "lirc/drv_admin.h" 20 #include "lirc/lirc_options.h" 27 static const char*
const PLUGIN_FILE_EXTENSION =
"so";
31 #define MAX_PLUGINS 256 42 static void* last_plugin = NULL;
47 .device =
"/dev/null",
62 .driver_version =
"0.9.2" 71 static int ends_with_so(
const char* str)
73 char* dot = strrchr(str,
'.');
75 return (NULL == dot) ? 0 : strcmp(dot + 1, PLUGIN_FILE_EXTENSION) == 0;
80 static int line_cmp(
const void* arg1,
const void* arg2)
82 return strcmp(*(
const char**)arg1, *(
const char**)arg2);
87 static struct driver* add_hw_name(
struct driver* hw,
void* arg)
89 char_array* a = (char_array*)arg;
95 a->array[a->size] = strdup(hw->
name);
104 if (drv == (
struct driver*)NULL || name == NULL)
105 return (
struct driver*)NULL;
106 if (strcasecmp(drv->
name, (
char*)name) == 0)
108 return (
struct driver*)NULL;
120 if (last_plugin != NULL)
121 dlclose(last_plugin);
122 last_plugin = dlopen(path, RTLD_NOW);
123 if (last_plugin == NULL) {
127 drivers = (
struct driver**)dlsym(last_plugin,
"hardwares");
128 if (drivers == (
struct driver**)NULL) {
129 log_warn(
"No hardwares entrypoint found in %s", path);
131 for (; *drivers; drivers++) {
132 if ((*drivers)->name == NULL) {
133 log_warn(
"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 log_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)
182 const char* pluginpath_arg)
184 const char* pluginpath;
189 if (pluginpath_arg == NULL) {
193 if (pluginpath == NULL)
196 pluginpath = pluginpath_arg;
198 if (strchr(pluginpath,
':') == (
char*)NULL) {
199 return for_each_plugin_in_dir(pluginpath,
204 tmp_path = alloca(strlen(pluginpath) + 1);
205 strncpy(tmp_path, pluginpath, strlen(pluginpath) + 1);
206 for (s = strtok(tmp_path,
":"); s != NULL; s = strtok(NULL,
":")) {
207 result = for_each_plugin_in_dir(s,
211 if (result != (
struct driver*)NULL)
220 const char* pluginpath)
222 return for_each_path(visit_plugin, func, arg, pluginpath);
228 const char* pluginpath)
230 for_each_path(plugin_guest, NULL, arg, pluginpath);
245 fprintf(stderr,
"Too many plugins (%d)\n",
MAX_PLUGINS);
248 qsort(names.array, names.size,
sizeof(
char*), line_cmp);
249 for (i = 0; i < names.size; i += 1) {
250 fprintf(file,
"%s\n", names.array[i]);
251 free(names.array[i]);
261 memcpy(&drv, &drv_null,
sizeof(
struct driver));
264 if (strcasecmp(name,
"dev/input") == 0)
268 if (found != (
struct driver*)NULL) {
269 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,...)