LIRC libraries
LinuxInfraredRemoteControl
driver.c
Go to the documentation of this file.
1 
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 #include <stdio.h>
16 #include <alloca.h>
17 #include "driver.h"
18 #include "config.h"
19 #include "lirc_log.h"
20 
21 static const logchannel_t logchannel = LOG_LIB;
22 
23 int get_server_version(void) { return VERSION_NODOTS; }
24 
29 struct driver drv;
30 
32 const char* const OPTION_FMT = "%32s%64s";
33 
35 const struct driver* const curr_driver = &drv;
36 
37 
38 int default_open(const char* path)
39 {
40  static char buff[128];
41 
42  if (path == NULL) {
43  if (drv.device == NULL)
44  drv.device = LIRC_DRIVER_DEVICE;
45  } else {
46  strncpy(buff, path, sizeof(buff) - 1);
47  drv.device = buff;
48  }
49  log_info("Initial device: %s", drv.device);
50  return 0;
51 }
52 
53 int default_close(void)
54 {
55  return 0;
56 }
57 
58 int default_drvctl(unsigned int fd, void* arg)
59 {
61 }
62 
63 
64 int drv_handle_options(const char* options)
65 {
66  char* s;
67  char* token;
68  struct option_t option;
69  int found;
70  char* colon;
71  int result;
72 
73  if (options == NULL || strlen(options) == 0)
74  return 0;
75  s = alloca(strlen(options) + 1);
76  strcpy(s, options);
77  for (token = strtok(s, "|"); token != NULL; token = strtok(NULL, "|")) {
78  colon = strstr(token, ":");
79  if (colon == NULL)
80  return DRV_ERR_BAD_OPTION;
81  *colon = ' ';
82  found = sscanf(token, OPTION_FMT, option.key, option.value);
83  if (found != 2)
84  return DRV_ERR_BAD_OPTION;
85  if (!curr_driver->drvctl_func)
86  continue;
87  result = curr_driver->drvctl_func(DRVCTL_SET_OPTION, (void*) &option);
88  if (result != 0)
89  return result;
90  }
91  return 0;
92 }
Argument for DRV_SET_OPTION.
Definition: driver.h:63
int default_close(void)
For now, a placeholder.
Definition: driver.c:53
#define DRV_ERR_NOT_IMPLEMENTED
drvctl definitions
Definition: driver.h:115
int fd
Set by the driver after init().
Definition: driver.h:146
const struct driver *const curr_driver
Read-only access to drv for client code.
Definition: driver.c:35
Logging functionality.
Interface to the userspace drivers.
const char *const OPTION_FMT
sscanf format to parse option_t.
Definition: driver.c:32
#define DRV_ERR_BAD_OPTION
drvctl error: cmd is bad
Definition: driver.h:121
logchannel_t
Log channels used to filter messages.
Definition: lirc_log.h:53
struct driver drv
The global driver data that drivers etc are accessing.
Definition: driver.c:29
int default_drvctl(unsigned int fd, void *arg)
Return DRV_ERR_NOTIMPLEMENTED.
Definition: driver.c:58
The data the driver exports i.
Definition: driver.h:136
int drv_handle_options(const char *options)
Parse an option string "key:value;key:value..." and invoke drvctl DRV_SET_OPTION as appropriate...
Definition: driver.c:64
int(*const drvctl_func)(unsigned int cmd, void *arg)
Generic driver control function with semantics as defined by driver Returns 0 on success, else a positive error code.
Definition: driver.h:213
int default_open(const char *path)
Stores path in drv.device if non-null.
Definition: driver.c:38
#define DRVCTL_SET_OPTION
Drvctl cmd: Set driver options.
Definition: driver.h:82
int get_server_version(void)
Return numeric server version, m.v.r => 10000 * m + 100 * v + r.
Definition: driver.c:23
const char * device
Name of the device (string).
Definition: driver.h:143
#define log_info(fmt,...)
Log an info message.
Definition: lirc_log.h:114