LIRC libraries
LinuxInfraredRemoteControl
driver.c
Go to the documentation of this file.
1 
11 #include <stdio.h>
12 #include <alloca.h>
13 #include "driver.h"
14 #include "config.h"
15 #include "lirc_log.h"
16 
17 static const logchannel_t logchannel = LOG_LIB;
18 
23 struct driver drv;
24 
26 const char* const OPTION_FMT = "%32s%64s";
27 
29 const struct driver* const curr_driver = &drv;
30 
32 const int GLOB_CHUNK_SIZE = 32;
33 
34 
35 void glob_t_init(glob_t* glob)
36 {
37  memset(glob, 0, sizeof(glob_t));
38  glob->gl_offs = GLOB_CHUNK_SIZE;
39  glob->gl_pathv = (char**) calloc(glob->gl_offs, sizeof(char*));
40 }
41 
42 
43 void glob_t_add_path(glob_t* glob, const char* path)
44 {
45  if (glob->gl_pathc >= glob->gl_offs) {
46  glob->gl_offs += GLOB_CHUNK_SIZE;
47  glob->gl_pathv = realloc(glob->gl_pathv,
48  glob->gl_offs * sizeof(char*));
49  }
50  glob->gl_pathv[glob->gl_pathc] = strdup(path);
51  glob->gl_pathc += 1;
52 }
53 
54 
55 void glob_t_free(glob_t* glob)
56 {
57  int i;
58 
59  for (i = 0; i < glob->gl_pathc; i += 1)
60  free(glob->gl_pathv[i]);
61  free(glob->gl_pathv);
62 }
63 
64 
65 int default_open(const char* path)
66 {
67  static char buff[128];
68 
69  if (path == NULL) {
70  if (drv.device == NULL)
71  drv.device = LIRC_DRIVER_DEVICE;
72  } else {
73  strncpy(buff, path, sizeof(buff) - 1);
74  drv.device = buff;
75  }
76  log_info("Initial device: %s", drv.device);
77  return 0;
78 }
79 
80 int default_close(void)
81 {
82  return 0;
83 }
84 
85 int default_drvctl(unsigned int fd, void* arg)
86 {
88 }
89 
90 
91 int drv_handle_options(const char* options)
92 {
93  char* s;
94  char* token;
95  struct option_t option;
96  int found;
97  char* colon;
98  int result;
99 
100  s = alloca(strlen(options) + 1);
101  strcpy(s, options);
102  for (token = strtok(s, "|"); token != NULL; token = strtok(NULL, "|")) {
103  colon = strstr(token, ":");
104  if (colon == NULL)
105  return DRV_ERR_BAD_OPTION;
106  *colon = ' ';
107  found = sscanf(token, OPTION_FMT, option.key, option.value);
108  if (found != 2)
109  return DRV_ERR_BAD_OPTION;
110  if (!curr_driver->drvctl_func)
111  continue;
112  result = curr_driver->drvctl_func(DRVCTL_SET_OPTION, (void*) &option);
113  if (result != 0)
114  return result;
115  }
116  return 0;
117 }
int default_close(void)
Definition: driver.c:80
#define DRV_ERR_NOT_IMPLEMENTED
Definition: driver.h:112
int fd
Definition: driver.h:137
const struct driver *const curr_driver
Definition: driver.c:29
Logging functionality.
const int GLOB_CHUNK_SIZE
Definition: driver.c:32
Interface to the userspace drivers.
const char *const OPTION_FMT
Definition: driver.c:26
#define DRV_ERR_BAD_OPTION
Definition: driver.h:118
void glob_t_init(glob_t *glob)
Definition: driver.c:35
logchannel_t
Definition: lirc_log.h:53
struct driver drv
Definition: driver.c:23
int default_drvctl(unsigned int fd, void *arg)
Definition: driver.c:85
Definition: driver.h:127
void glob_t_add_path(glob_t *glob, const char *path)
Definition: driver.c:43
int drv_handle_options(const char *options)
Definition: driver.c:91
int(*const drvctl_func)(unsigned int cmd, void *arg)
Definition: driver.h:204
int default_open(const char *path)
Definition: driver.c:65
#define DRVCTL_SET_OPTION
Definition: driver.h:79
const char * device
Definition: driver.h:134
#define log_info(fmt,...)
Definition: lirc_log.h:114
void glob_t_free(glob_t *glob)
Definition: driver.c:55