adjust
This commit is contained in:
44
source/uapi/monitor_user.c
Normal file
44
source/uapi/monitor_user.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "monitor_user.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DEVICE "/dev/variable_monitor"
|
||||
int file_desc = -1;
|
||||
|
||||
/// @brief start watch
|
||||
/// @param w_arg
|
||||
/// @return 0 means success, other means fail
|
||||
int start_watch(watch_arg w_arg) {
|
||||
if (file_desc < 0) {
|
||||
file_desc = open(DEVICE, 0);
|
||||
}
|
||||
if (file_desc < 0) {
|
||||
printf("Can't open device file: %s\n", DEVICE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ioctl(file_desc, 1, &w_arg) < 0) {
|
||||
printf("ioctl failed\n");
|
||||
close(file_desc);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// @brief cancel watch
|
||||
/// @return 0 means success, other means fail
|
||||
int cancel_watch() {
|
||||
if (file_desc < 0) {
|
||||
file_desc = open(DEVICE, 0);
|
||||
}
|
||||
if (file_desc < 0) {
|
||||
printf("Device not open: %s,%d \n", DEVICE, file_desc);
|
||||
return file_desc;
|
||||
}
|
||||
|
||||
close(file_desc);
|
||||
file_desc = -1;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user