blob: fbfa024b06ac412ac8b53aadb0fe7451515b7b1e [file] [log] [blame]
Gong Ke497c4c22020-03-20 10:15:42 +08001/**
2 * \file
3 * \brief Utility functions
4 */
5
Pengfei Liub4734232020-01-17 18:25:10 +08006#ifndef _DVR_UTILS_H_
7#define _DVR_UTILS_H_
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
wentao ma98707a32022-10-20 04:53:46 -070013
14/**\brief read sysfs node
15 * name file name
16 * buf store sysfs value buf
17 * len buf len
18 */
19typedef void (*DVR_Read_Sysfs_Cb)(const char *name, char *buf, int len);
20
21/**\brief write sysfs
22 * name file name
23 * cmd write to sysfs node cmd
24 */
25typedef void (*DVR_Write_Sysfs_Cb)(const char *name, const char *cmd);
26
27/**\brief read prop
28 * name prop name
29 * buf store prop value buf
30 * len buf len
31 */
32typedef void (*DVR_Read_Prop_Cb)(const char *name, char *buf, int len);
33
34/**\brief write prop
35 * name prop name
36 * cmd write to prop node cmd
37 */
38typedef void (*DVR_Write_Prop_Cb)(const char *name, const char *cmd);
39
40
41/**\brief regist rw sysfs cb
42 * \param[in] fun callback
43 * \return
44 * - DVR_SUCCESS
45 * - error
46 */
47int dvr_register_rw_sys(DVR_Read_Sysfs_Cb RCb, DVR_Write_Sysfs_Cb WCb);
48
49/**\brief unregist rw sys cb
50 */
51int dvr_unregister_rw_sys(void);
52
53
54/**\brief regist rw prop cb
55 * \param[in] fun callback
56 * \return
57 * - DVR_SUCCESS
58 * - error
59 */
60
61int dvr_register_rw_prop(DVR_Read_Prop_Cb RCb, DVR_Write_Prop_Cb WCb);
62
63/**\brief unregist rw prop cb */
64int dvr_unregister_rw_prop(void);
65
66
Pengfei Liub4734232020-01-17 18:25:10 +080067/**\brief Write a string cmd to a file
Gong Ke497c4c22020-03-20 10:15:42 +080068 * \param[in] name File name
69 * \param[in] cmd String command
Pengfei Liub4734232020-01-17 18:25:10 +080070 * \return DVR_SUCCESS On success
71 * \return Error code On failure
72 */
wentao ma98707a32022-10-20 04:53:46 -070073
hualing chena540a7e2020-03-27 16:44:05 +080074int dvr_file_echo(const char *name, const char *cmd);
75
wentao ma98707a32022-10-20 04:53:46 -070076
hualing chena540a7e2020-03-27 16:44:05 +080077/**\brief read sysfs file
78 * \param[in] name, File name
79 * \param[out] buf, store sysfs node value
80 * \return DVR_SUCCESS On success
81 * \return Error code On failure
82 */
wentao ma98707a32022-10-20 04:53:46 -070083
hualing chena540a7e2020-03-27 16:44:05 +080084int dvr_file_read(const char *name, char *buf, int len);
85
wentao ma98707a32022-10-20 04:53:46 -070086
87/**\brief Write a string cmd to a prop
88 * \param[in] name, prop name
89 * \param[in] cmd, String command
hualing chena540a7e2020-03-27 16:44:05 +080090 * \return DVR_SUCCESS On success
wentao ma98707a32022-10-20 04:53:46 -070091 * \return Error code On failure
hualing chena540a7e2020-03-27 16:44:05 +080092 */
wentao ma98707a32022-10-20 04:53:46 -070093
94int dvr_prop_echo(const char *name, const char *cmd);
95
96
97/**\brief read prop value
98 * \param[in] name, prop name
99 * \param[out] buf, store prop node value
100 * \return DVR_SUCCESS On success
101 * \return Error code On failure
102 */
103
hualing chena540a7e2020-03-27 16:44:05 +0800104int dvr_prop_read(const char *name, char *buf, int len);
Gong Ke497c4c22020-03-20 10:15:42 +0800105
Wentao MA907b6432022-08-01 06:23:08 +0000106/**\brief calculates the difference between ts1 and ts2
107 * \param[in] ts1, higher bound of the timespec* whose length is calculated
108 * \param[in] ts2, lower bound of the timespec* whose length is calculated
109 * \param[out] ts3, The result timespec* of (ts1-ts2)
110 * \return void
111 */
112void clock_timespec_subtract(struct timespec *ts1, struct timespec *ts2, struct timespec *ts3);
113
Pengfei Liub4734232020-01-17 18:25:10 +0800114#ifdef __cplusplus
115}
116#endif
117
118#endif /*END _DVR_UTILS_H_*/