LIRC libraries
Linux Infrared Remote Control
Toggle main menu visibility
Loading...
Searching...
No Matches
driver.c
Go to the documentation of this file.
1
10
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
{
59
return
DRV_ERR_NOT_IMPLEMENTED
;
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
}
drv
struct driver drv
The global driver data that drivers etc are accessing.
Definition
driver.c:28
OPTION_FMT
const char *const OPTION_FMT
sscanf format to parse option_t.
Definition
driver.c:31
curr_driver
const struct driver *const curr_driver
Read-only access to drv for client code.
Definition
driver.c:34
driver.h
Interface to the userspace drivers.
DRVCTL_SET_OPTION
#define DRVCTL_SET_OPTION
Drvctl cmd: Set driver options.
Definition
driver.h:78
default_close
int default_close(void)
For now, a placeholder.
Definition
driver.c:52
get_server_version
int get_server_version(void)
Return numeric server version, m.v.r => 10000 * m + 100 * v + r.
Definition
driver.c:22
default_drvctl
int default_drvctl(unsigned int fd, void *arg)
Return DRV_ERR_NOTIMPLEMENTED.
Definition
driver.c:57
drv_handle_options
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
DRV_ERR_NOT_IMPLEMENTED
#define DRV_ERR_NOT_IMPLEMENTED
drvctl definitions
Definition
driver.h:47
default_open
int default_open(const char *path)
Stores path in drv.device if non-null.
Definition
driver.c:37
DRV_ERR_BAD_OPTION
#define DRV_ERR_BAD_OPTION
drvctl error: cmd is bad
Definition
driver.h:117
lirc_log.h
Logging functionality.
log_info
#define log_info(fmt,...)
Log an info message.
Definition
lirc_log.h:114
logchannel_t
logchannel_t
Log channels used to filter messages.
Definition
lirc_log.h:53
driver
The data the driver exports i.
Definition
driver.h:132
driver::fd
int fd
Set by the driver after init().
Definition
driver.h:142
option_t
Argument for DRV_SET_OPTION.
Definition
driver.h:59
lib
driver.c
Generated by
1.17.0