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 
18 struct driver drv;
19 
21 const char* const OPTION_FMT = "%32s%64s";
22 
24 const struct driver const* curr_driver = &drv;
25 
26 int default_open(const char* path)
27 {
28  static char buff[128];
29  strncpy(buff, path, sizeof(buff));
30  drv.device = buff;
31  return 0;
32 }
33 
35 {
36  return 0;
37 }
38 
39 int default_drvctl(unsigned int fd, void* arg)
40 {
42 }
43 
44 
45 int drv_handle_options(const char* options)
46 {
47  char* s;
48  char* token;
49  struct option_t option;
50  int found;
51  char* colon;
52 
53  s = alloca(strlen(options) + 1);
54  strcpy(s, options);
55  for (token = strtok(s, "|"); token != NULL; token = strtok(NULL, "|")){
56  colon=strstr(token, ":");
57  if (colon == NULL)
58  return DRV_ERR_BAD_OPTION;
59  *colon = ' ';
60  found = sscanf(token, OPTION_FMT, option.key, option.value);
61  if (found != 2)
62  return DRV_ERR_BAD_OPTION;
63  if (!curr_driver->drvctl_func)
64  continue;
65  curr_driver->drvctl_func(DRVCTL_SET_OPTION, (void*) &option);
66  }
67  return 0;
68 }
69 
70 
int default_close()
Definition: driver.c:34
#define DRV_ERR_NOT_IMPLEMENTED
Definition: driver.h:69
int fd
Definition: driver.h:88
Interface to the userspace drivers.
const char *const OPTION_FMT
Definition: driver.c:21
#define DRV_ERR_BAD_OPTION
Definition: driver.h:75
int(*const drvctl_func)(unsigned int cmd, void *arg)
Definition: driver.h:155
struct driver drv
Definition: driver.c:18
int default_drvctl(unsigned int fd, void *arg)
Definition: driver.c:39
Definition: driver.h:81
int drv_handle_options(const char *options)
Definition: driver.c:45
int default_open(const char *path)
Definition: driver.c:26
#define DRVCTL_SET_OPTION
Definition: driver.h:63
const struct driver const * curr_driver
Definition: driver.c:24
const char * device
Definition: driver.h:85