LIRC libraries
LinuxInfraredRemoteControl
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
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 {
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 }
int default_close(void)
Definition: driver.c:43
#define DRV_ERR_NOT_IMPLEMENTED
Definition: driver.h:68
int fd
Definition: driver.h:93
Logging functionality.
Interface to the userspace drivers.
const char *const OPTION_FMT
Definition: driver.c:23
#define DRV_ERR_BAD_OPTION
Definition: driver.h:74
int(*const drvctl_func)(unsigned int cmd, void *arg)
Definition: driver.h:160
struct driver drv
Definition: driver.c:20
int default_drvctl(unsigned int fd, void *arg)
Definition: driver.c:48
Definition: driver.h:83
int drv_handle_options(const char *options)
Definition: driver.c:54
int default_open(const char *path)
Definition: driver.c:28
#define DRVCTL_SET_OPTION
Definition: driver.h:62
const struct driver const * curr_driver
Definition: driver.c:26
const char * device
Definition: driver.h:90