LIRC libraries LinuxInfraredRemoteControl

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

driver.c
Go to the documentation of this file.
1
11 #include <stdio.h>
12 #include "driver.h"
13 #include "config.h"
14 #include "lirc_log.h"
15
20 struct driver drv;
21
23 const char* const OPTION_FMT = "%32s%64s";
24
26 const struct driver const* curr_driver = &drv;
27
28 int default_open(const char* path)
29 {
30 static char buff[128];
31
32 if (path == NULL) {
33 if (drv.device == NULL)
34 drv.device = LIRC_DRIVER_DEVICE;
35 } else {
36 strncpy(buff, path, sizeof(buff) - 1);
37 drv.device = buff;
38 }
39 logprintf(LIRC_INFO, "Initial device: %s", drv.device);
40 return 0;
41 }
42
43 int default_close(void)
44 {
45 return 0;
46 }
47
48 int default_drvctl(unsigned int fd, void* arg)
49 {
50 return DRV_ERR_NOT_IMPLEMENTED;
51 }
52
53
54 int drv_handle_options(const char* options)
55 {
56 char* s;
57 char* token;
58 struct option_t option;
59 int found;
60 char* colon;
61 int result;
62
63 s = alloca(strlen(options) + 1);
64 strcpy(s, options);
65 for (token = strtok(s, "|"); token != NULL; token = strtok(NULL, "|")) {
66 colon = strstr(token, ":");
67 if (colon == NULL)
68 return DRV_ERR_BAD_OPTION;
69 *colon = ' ';
70 found = sscanf(token, OPTION_FMT, option.key, option.value);
71 if (found != 2)
72 return DRV_ERR_BAD_OPTION;
73 if (!curr_driver->drvctl_func)
74 continue;
75 result = curr_driver->drvctl_func(DRVCTL_SET_OPTION, (void*) &option);
76 if (result != 0)
77 return result;
78 }
79 return 0;
80 }
option_t
Definition: driver.h:43
default_close
int default_close(void)
Definition: driver.c:43
DRV_ERR_NOT_IMPLEMENTED
#define DRV_ERR_NOT_IMPLEMENTED
Definition: driver.h:68
driver::fd
int fd
Definition: driver.h:93
lirc_log.h
Logging functionality.
driver.h
Interface to the userspace drivers.
OPTION_FMT
const char *const OPTION_FMT
Definition: driver.c:23
DRV_ERR_BAD_OPTION
#define DRV_ERR_BAD_OPTION
Definition: driver.h:74
drv
struct driver drv
Definition: driver.c:20
default_drvctl
int default_drvctl(unsigned int fd, void *arg)
Definition: driver.c:48
driver
Definition: driver.h:83
drv_handle_options
int drv_handle_options(const char *options)
Definition: driver.c:54
driver::drvctl_func
int(*const drvctl_func)(unsigned int cmd, void *arg)
Definition: driver.h:160
default_open
int default_open(const char *path)
Definition: driver.c:28
DRVCTL_SET_OPTION
#define DRVCTL_SET_OPTION
Definition: driver.h:62
curr_driver
const struct driver const * curr_driver
Definition: driver.c:26
driver::device
const char * device
Definition: driver.h:90