Switch (badly) to C++
This is so I can use capnproto without adding a 3rd party compiler.
This commit is contained in:
parent
a461c8eb6a
commit
694ef2a466
4
Makefile
4
Makefile
|
@ -4,10 +4,10 @@ bin:
|
|||
mkdir -p bin
|
||||
|
||||
capture: bin capture.c
|
||||
gcc capture.c -o bin/capture
|
||||
g++ capture.c -o bin/capture
|
||||
|
||||
clean:
|
||||
rm -Rf bin
|
||||
|
||||
playback: bin playback.c
|
||||
gcc playback.c -o bin/playback
|
||||
g++ playback.c -o bin/playback
|
||||
|
|
23
capture.c
23
capture.c
|
@ -1,7 +1,9 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -11,10 +13,10 @@
|
|||
#define MAX_EVENTS 16
|
||||
#define CONTENT_BUFFER_SIZE 32
|
||||
|
||||
static char* KEYBOARD = "k";
|
||||
static char* MOUSE = "m";
|
||||
constexpr std::string_view KEYBOARD = "k";
|
||||
constexpr std::string_view MOUSE = "m";
|
||||
|
||||
int dump_event(struct timespec* start, struct input_event* event, char* type);
|
||||
int dump_event(struct timespec* start, struct input_event* event, const std::string_view& type);
|
||||
|
||||
int event_content_keyboard(char* buffer, int buffer_size, struct input_event* event);
|
||||
int event_content_mouse(char* buffer, int buffer_size, struct input_event* event);
|
||||
|
@ -48,7 +50,7 @@ static inline void time_diff(struct timeval* a, struct timespec* b, struct timev
|
|||
}
|
||||
}
|
||||
|
||||
int dump_event(struct timespec* start, struct input_event* event, char* type) {
|
||||
int dump_event(struct timespec* start, struct input_event* event, const std::string_view& type) {
|
||||
struct timespec now;
|
||||
struct timespec diff;
|
||||
char content_buffer[CONTENT_BUFFER_SIZE];
|
||||
|
@ -76,11 +78,11 @@ int dump_event(struct timespec* start, struct input_event* event, char* type) {
|
|||
start->tv_sec = now.tv_sec;
|
||||
start->tv_nsec = now.tv_nsec;
|
||||
|
||||
printf("%ld %ld,%s,%s\n",
|
||||
diff.tv_sec,
|
||||
diff.tv_nsec,
|
||||
type,
|
||||
content_buffer);
|
||||
std::cout <<
|
||||
diff.tv_sec << " " <<
|
||||
diff.tv_nsec << "," <<
|
||||
type << "," <<
|
||||
content_buffer << std::endl;
|
||||
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
|
@ -179,7 +181,7 @@ int stream_events(char* mouse_path, char* keyboard_path, int hotkey_scancode) {
|
|||
struct input_event i_event;
|
||||
while(running) {
|
||||
int event_count = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
|
||||
char* type;
|
||||
std::string_view type;
|
||||
for(int i = 0; i < event_count; i++) {
|
||||
int result = read(events[i].data.fd, &i_event, sizeof(struct input_event));
|
||||
if(result < 0) {
|
||||
|
@ -214,4 +216,5 @@ int stream_events(char* mouse_path, char* keyboard_path, int hotkey_scancode) {
|
|||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue