CardSight 0.1.0
C API reference for the CardSight firmware and application
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
9
10#ifndef CARDSIGHT_DEVICE_H
11#define CARDSIGHT_DEVICE_H
12
13#include <stdbool.h>
14
16#define DEVICE_NAME_MAX 32
17
21struct device {
23 struct device *parent;
24 void (*release)(struct device *dev);
26};
27
33void device_initialize(struct device *dev);
35void get_device(struct device *dev);
36
45static inline void put_device(struct device *dev)
46{
47 if (dev != NULL && dev->refcount > 0 && --dev->refcount == 0 && dev->release != NULL) {
48 dev->release(dev);
49 }
50}
51
52#endif /* CARDSIGHT_DEVICE_H */
void get_device(struct device *dev)
Take one more reference; NULL is ignored.
#define DEVICE_NAME_MAX
Longest device name, including the terminating zero.
Definition device.h:16
void device_initialize(struct device *dev)
Prepare a device structure: zero it and take the initial reference.
Reference-counted object shared between the driver and its users.
Definition device.h:21
struct device * parent
Definition device.h:23
int refcount
Definition device.h:25
char name[DEVICE_NAME_MAX]
Definition device.h:22
void(* release)(struct device *dev)
Definition device.h:24