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 "driver.h"
17 #include "config.h"
18 #include "lirc_log.h"
19 
20 static const logchannel_t logchannel = LOG_LIB;
21 
22 int get_server_version(void) { return VERSION_NODOTS; }
23 
28 struct driver drv;
29 
31 const char* const OPTION_FMT = "%32s%64s";
32 
34 const struct driver* const curr_driver = &drv;
35 
36 
37 int default_open(const char* path)
38 {
39  static char buff[128];
40 
41  if (path == NULL) {
42  if (drv.device == NULL)
43  drv.device = LIRC_DRIVER_DEVICE;
44  } else {
45  strncpy(buff, path, sizeof(buff) - 1);
46  drv.device = buff;
47  }
48  log_info("Initial device: %s", drv.device);
49  return 0;
50 }
51 
52 int default_close(void)
53 {
54  return 0;
55 }
56 
57 int default_drvctl(unsigned int fd, void* arg)
58 {
60 }
61 
62 
63 int drv_handle_options(const char* options)
64 {
65  char* s;
66  char* token;
67  struct option_t option;
68  int found;
69  char* colon;
70  int result;
71 
72  if (options == NULL || strlen(options) == 0)
73  return 0;
74  s = alloca(strlen(options) + 1);
75  strcpy(s, options);
76  for (token = strtok(s, "|"); token != NULL; token = strtok(NULL, "|")) {
77  colon = strstr(token, ":");
78  if (colon == NULL)
79  return DRV_ERR_BAD_OPTION;
80  *colon = ' ';
81  found = sscanf(token, OPTION_FMT, option.key, option.value);
82  if (found != 2)
83  return DRV_ERR_BAD_OPTION;
84  if (!curr_driver->drvctl_func)
85  continue;
86  result = curr_driver->drvctl_func(DRVCTL_SET_OPTION, (void*) &option);
87  if (result != 0)
88  return result;
89  }
90  return 0;
91 }
Argument for DRV_SET_OPTION.
Definition: driver.h:63
int default_close(void)
For now, a placeholder.
Definition: driver.c:52
#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:34
Logging functionality.
Interface to the userspace drivers.
const char *const OPTION_FMT
sscanf format to parse option_t.
Definition: driver.c:31
#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:28
int default_drvctl(unsigned int fd, void *arg)
Return DRV_ERR_NOTIMPLEMENTED.
Definition: driver.c:57
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:63
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:37
#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:22
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