mirror of
https://github.com/stupidcomputer/jsfw.git
synced 2024-12-26 21:42:23 -06:00
housekeeping
This commit is contained in:
parent
2297685cd6
commit
5bdf9f4c58
6
client.c
6
client.c
@ -1,6 +1,4 @@
|
|||||||
#include<stdint.h>
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void client_run(char * address, uint16_t port) {
|
void client_run(char *address, uint16_t port) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
5
hid.c
5
hid.c
@ -1,17 +1,16 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
#include <linux/joystick.h>
|
#include <pthread.h>
|
||||||
#include <linux/uinput.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "hid.h"
|
#include "hid.h"
|
||||||
#include "main.h"
|
|
||||||
#include "vec.h"
|
#include "vec.h"
|
||||||
|
|
||||||
// List of uniq of the currently known devices
|
// List of uniq of the currently known devices
|
||||||
|
2
hid.h
2
hid.h
@ -2,9 +2,7 @@
|
|||||||
#ifndef HID_H
|
#ifndef HID_H
|
||||||
#define HID_H
|
#define HID_H
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "vec.h"
|
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef uint64_t uniq_t;
|
typedef uint64_t uniq_t;
|
||||||
|
10
main.c
10
main.c
@ -1,13 +1,8 @@
|
|||||||
#include <fcntl.h>
|
|
||||||
#include <linux/joystick.h>
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "hid.h"
|
#include "hid.h"
|
||||||
@ -19,7 +14,6 @@ const char *USAGE[] = {
|
|||||||
"jsfw client [address] [port]\n",
|
"jsfw client [address] [port]\n",
|
||||||
"jsfw server [port]\n",
|
"jsfw server [port]\n",
|
||||||
};
|
};
|
||||||
const size_t EVENT_SIZE = sizeof(struct js_event);
|
|
||||||
|
|
||||||
uint16_t parse_port(const char *str) {
|
uint16_t parse_port(const char *str) {
|
||||||
long long n = atoll(str);
|
long long n = atoll(str);
|
||||||
@ -29,7 +23,7 @@ uint16_t parse_port(const char *str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void server(uint16_t port) {
|
void server(uint16_t port) {
|
||||||
printf("Server (port: %u).\n\n", port);
|
printf("[Server (port: %u)]\n\n", port);
|
||||||
|
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
pthread_create(&thread, NULL, hid_thread, NULL);
|
pthread_create(&thread, NULL, hid_thread, NULL);
|
||||||
@ -37,7 +31,7 @@ void server(uint16_t port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void client(char *address, uint16_t port) {
|
void client(char *address, uint16_t port) {
|
||||||
printf("Client (%s:%d)\n\n", address, port);
|
printf("[Client (%s:%d)]\n\n", address, port);
|
||||||
client_run(address, port);
|
client_run(address, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
server.c
9
server.c
@ -1,20 +1,19 @@
|
|||||||
#include <arpa/inet.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
|
#include <poll.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/poll.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "hid.h"
|
#include "hid.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "vec.h"
|
|
||||||
|
|
||||||
struct Connection {
|
struct Connection {
|
||||||
int socket;
|
int socket;
|
||||||
|
1
util.c
1
util.c
@ -1,4 +1,3 @@
|
|||||||
#include<limits.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
26
vec.c
26
vec.c
@ -1,7 +1,7 @@
|
|||||||
|
#include "vec.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "vec.h"
|
|
||||||
|
|
||||||
#define INIT_CAP 8
|
#define INIT_CAP 8
|
||||||
|
|
||||||
@ -10,9 +10,7 @@ static void handle_alloc_error() {
|
|||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec vec_new(size_t data_size) {
|
Vec vec_new(size_t data_size) { return vec_cap(data_size, INIT_CAP); }
|
||||||
return vec_cap(data_size, INIT_CAP);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec vec_cap(size_t data_size, size_t initial_capacity) {
|
Vec vec_cap(size_t data_size, size_t initial_capacity) {
|
||||||
Vec v;
|
Vec v;
|
||||||
@ -24,10 +22,12 @@ Vec vec_cap(size_t data_size, size_t initial_capacity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void vec_grow(Vec *v, size_t cap) {
|
static inline void vec_grow(Vec *v, size_t cap) {
|
||||||
if(v->cap >= cap) return;
|
if (v->cap >= cap)
|
||||||
|
return;
|
||||||
size_t new_cap = cap > v->cap * 2 ? cap : v->cap * 2;
|
size_t new_cap = cap > v->cap * 2 ? cap : v->cap * 2;
|
||||||
void *new_data = realloc(v->data, new_cap * v->stride);
|
void *new_data = realloc(v->data, new_cap * v->stride);
|
||||||
if(new_data == NULL) handle_alloc_error();
|
if (new_data == NULL)
|
||||||
|
handle_alloc_error();
|
||||||
v->data = new_data;
|
v->data = new_data;
|
||||||
v->cap = new_cap;
|
v->cap = new_cap;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,8 @@ void vec_pop(Vec * v, void * data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *vec_get(Vec *v, size_t index) {
|
void *vec_get(Vec *v, size_t index) {
|
||||||
if(index >= v->len) return NULL;
|
if (index >= v->len)
|
||||||
|
return NULL;
|
||||||
return v->data + index * v->stride;
|
return v->data + index * v->stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,17 +85,14 @@ void vec_remove(Vec * v, size_t index, void * data) {
|
|||||||
memmove(slot, slot + v->stride, (v->len - index) * v->stride);
|
memmove(slot, slot + v->stride, (v->len - index) * v->stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vec_clear(Vec * v) {
|
void vec_clear(Vec *v) { v->len = 0; }
|
||||||
v->len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void vec_extend(Vec *v, void *data, size_t len) {
|
void vec_extend(Vec *v, void *data, size_t len) {
|
||||||
if(len == 0) return;
|
if (len == 0)
|
||||||
|
return;
|
||||||
vec_grow(v, v->len + len);
|
vec_grow(v, v->len + len);
|
||||||
memcpy(v->data + v->stride * v->len, data, v->stride * len);
|
memcpy(v->data + v->stride * v->len, data, v->stride * len);
|
||||||
v->len += len;
|
v->len += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vec_free(Vec v) {
|
void vec_free(Vec v) { free(v.data); }
|
||||||
free(v.data);
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user