LIRC libraries: /home/mk/tmp/lirc/lib/driver.c (0851399 2016-05-03 10:48:56 +0200) Source File

| LIRC libraries LinuxInfraredRemoteControl

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
16 static const logchannel_t logchannel = LOG_LIB;
17
22 struct driver drv;
23
25 const char* const OPTION_FMT = "%32s%64s";
26
28 const struct driver* const curr_driver = &drv;
29
31 const int GLOB_CHUNK_SIZE = 32;
32
33
34 void glob_t_init(glob_t* glob)
35 {
36 memset(glob, 0, sizeof(glob_t));
37 glob->gl_offs = GLOB_CHUNK_SIZE;
38 glob->gl_pathv = (char**) calloc(glob->gl_offs, sizeof(char*));
39 }
40
41
42 void glob_t_add_path(glob_t* glob, const char* path)
43 {
44 if (glob->gl_pathc >= glob->gl_offs) {
45 glob->gl_offs += GLOB_CHUNK_SIZE;
46 glob->gl_pathv = realloc(glob->gl_pathv,
47 glob->gl_offs * sizeof(char*));
48 }
49 glob->gl_pathv[glob->gl_pathc] = strdup(path);
50 glob->gl_pathc += 1;
51 }
52
53
54 void glob_t_free(glob_t* glob)
55 {
56 int i;
57
58 for (i = 0; i < glob->gl_pathc; i += 1)
59 free(glob->gl_pathv[i]);
60 free(glob->gl_pathv);
61 }
62
63
64 int default_open(const char* path)
65 {
66 static char buff[128];
67
68 if (path == NULL) {
69 if (drv.device == NULL)
70 drv.device = LIRC_DRIVER_DEVICE;
71 } else {
72 strncpy(buff, path, sizeof(buff) - 1);
73 drv.device = buff;
74 }
75 log_info("Initial device: %s", drv.device);
76 return 0;
77 }
78
79 int default_close(void)
80 {
81 return 0;
82 }
83
84 int default_drvctl(unsigned int fd, void* arg)
85 {
86 return DRV_ERR_NOT_IMPLEMENTED;
87 }
88
89
90 int drv_handle_options(const char* options)
91 {
92 char* s;
93 char* token;
94 struct option_t option;
95 int found;
96 char* colon;
97 int result;
98
99 s = alloca(strlen(options) + 1);
100 strcpy(s, options);
101 for (token = strtok(s, "|"); token != NULL; token = strtok(NULL, "|")) {
102 colon = strstr(token, ":");
103 if (colon == NULL)
104 return DRV_ERR_BAD_OPTION;
105 *colon = ' ';
106 found = sscanf(token, OPTION_FMT, option.key, option.value);
107 if (found != 2)
108 return DRV_ERR_BAD_OPTION;
109 if (!curr_driver->drvctl_func)
110 continue;
111 result = curr_driver->drvctl_func(DRVCTL_SET_OPTION, (void*) &option);
112 if (result != 0)
113 return result;
114 }
115 return 0;
116 }
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