driver.c
Go to the documentation of this file.
#include <stdio.h>
#include "driver.h"
#include "config.h"
#include "lirc_log.h"
static const logchannel_t logchannel = LOG_LIB;
struct driver drv;
const char* const OPTION_FMT = "%32s%64s";
const struct driver* const curr_driver = &drv;
const int GLOB_CHUNK_SIZE = 32;
void glob_t_init(glob_t* glob)
{
memset(glob, 0, sizeof(glob_t));
glob->gl_offs = GLOB_CHUNK_SIZE;
glob->gl_pathv = (char**) calloc(glob->gl_offs, sizeof(char*));
}
void glob_t_add_path(glob_t* glob, const char* path)
{
if (glob->gl_pathc >= glob->gl_offs) {
glob->gl_offs += GLOB_CHUNK_SIZE;
glob->gl_pathv = realloc(glob->gl_pathv,
glob->gl_offs * sizeof(char*));
}
glob->gl_pathv[glob->gl_pathc] = strdup(path);
glob->gl_pathc += 1;
}
void glob_t_free(glob_t* glob)
{
int i;
for (i = 0; i < glob->gl_pathc; i += 1)
free(glob->gl_pathv[i]);
free(glob->gl_pathv);
}
int default_open(const char* path)
{
static char buff[128];
if (path == NULL) {
if (drv.device == NULL)
drv.device = LIRC_DRIVER_DEVICE;
} else {
strncpy(buff, path, sizeof(buff) - 1);
drv.device = buff;
}
log_info("Initial device: %s", drv.device);
return 0;
}
int default_close(void)
{
return 0;
}
int default_drvctl(unsigned int fd, void* arg)
{
return DRV_ERR_NOT_IMPLEMENTED;
}
int drv_handle_options(const char* options)
{
char* s;
char* token;
struct option_t option;
int found;
char* colon;
int result;
s = alloca(strlen(options) + 1);
strcpy(s, options);
for (token = strtok(s, "|"); token != NULL; token = strtok(NULL, "|")) {
colon = strstr(token, ":");
if (colon == NULL)
return DRV_ERR_BAD_OPTION;
*colon = ' ';
found = sscanf(token, OPTION_FMT, option.key, option.value);
if (found != 2)
return DRV_ERR_BAD_OPTION;
if (!curr_driver->drvctl_func)
continue;
result = curr_driver->drvctl_func(DRVCTL_SET_OPTION, (void*) &option);
if (result != 0)
return result;
}
return 0;
}
option_t
Definition: driver.h:60
default_close
int default_close(void)
Definition: driver.c:79
DRV_ERR_NOT_IMPLEMENTED
#define DRV_ERR_NOT_IMPLEMENTED
Definition: driver.h:112
driver::fd
int fd
Definition: driver.h:137
curr_driver
const struct driver *const curr_driver
Definition: driver.c:28
lirc_log.h
Logging functionality.
GLOB_CHUNK_SIZE
const int GLOB_CHUNK_SIZE
Definition: driver.c:31
driver.h
Interface to the userspace drivers.
OPTION_FMT
const char *const OPTION_FMT
Definition: driver.c:25
DRV_ERR_BAD_OPTION
#define DRV_ERR_BAD_OPTION
Definition: driver.h:118
glob_t_init
void glob_t_init(glob_t *glob)
Definition: driver.c:34
logchannel_t
logchannel_t
Definition: lirc_log.h:53
drv
struct driver drv
Definition: driver.c:22
default_drvctl
int default_drvctl(unsigned int fd, void *arg)
Definition: driver.c:84
driver
Definition: driver.h:127
glob_t_add_path
void glob_t_add_path(glob_t *glob, const char *path)
Definition: driver.c:42
drv_handle_options
int drv_handle_options(const char *options)
Definition: driver.c:90
driver::drvctl_func
int(*const drvctl_func)(unsigned int cmd, void *arg)
Definition: driver.h:204
default_open
int default_open(const char *path)
Definition: driver.c:64
DRVCTL_SET_OPTION
#define DRVCTL_SET_OPTION
Definition: driver.h:79
driver::device
const char * device
Definition: driver.h:134
log_info
#define log_info(fmt,...)
Definition: lirc_log.h:114
glob_t_free
void glob_t_free(glob_t *glob)
Definition: driver.c:54