Loading...
Searching...
No Matches
driver.c
Go to the documentation of this file.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include "driver.h"
#include "config.h"
#include "lirc_log.h"
static const logchannel_t logchannel = LOG_LIB;
int get_server_version(void) { return VERSION_NODOTS; }
struct driver drv;
const char* const OPTION_FMT = "%32s%64s";
const struct driver* const curr_driver = &drv;
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;
if (options == NULL || strlen(options) == 0)
return 0;
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;
}
drv
struct driver drv
The global driver data that drivers etc are accessing.
Definition driver.c:28
OPTION_FMT
const char *const OPTION_FMT
sscanf format to parse option_t.
Definition driver.c:31
curr_driver
const struct driver *const curr_driver
Read-only access to drv for client code.
Definition driver.c:34
driver.h
Interface to the userspace drivers.
DRVCTL_SET_OPTION
#define DRVCTL_SET_OPTION
Drvctl cmd: Set driver options.
Definition driver.h:78
default_close
int default_close(void)
For now, a placeholder.
Definition driver.c:52
get_server_version
int get_server_version(void)
Return numeric server version, m.v.r => 10000 * m + 100 * v + r.
Definition driver.c:22
default_drvctl
int default_drvctl(unsigned int fd, void *arg)
Return DRV_ERR_NOTIMPLEMENTED.
Definition driver.c:57
drv_handle_options
int drv_handle_options(const char *options)
Parse an option string "key:value;key:value..." and invoke drvctl DRV_SET_OPTION as appropriate.
Definition driver.c:63
DRV_ERR_NOT_IMPLEMENTED
#define DRV_ERR_NOT_IMPLEMENTED
drvctl definitions
Definition driver.h:47
default_open
int default_open(const char *path)
Stores path in drv.device if non-null.
Definition driver.c:37
DRV_ERR_BAD_OPTION
#define DRV_ERR_BAD_OPTION
drvctl error: cmd is bad
Definition driver.h:117
lirc_log.h
Logging functionality.
log_info
#define log_info(fmt,...)
Log an info message.
Definition lirc_log.h:114
logchannel_t
logchannel_t
Log channels used to filter messages.
Definition lirc_log.h:53
driver
The data the driver exports i.
Definition driver.h:132
driver::fd
int fd
Set by the driver after init().
Definition driver.h:142
option_t
Argument for DRV_SET_OPTION.
Definition driver.h:59