jsfw/main.c

65 lines
1.5 KiB
C
Raw Normal View History

2022-08-30 11:45:53 -05:00
#include "client.h"
2022-08-27 19:29:43 -05:00
#include "hid.h"
2022-08-29 17:27:03 -05:00
#include "server.h"
2022-08-30 08:37:34 -05:00
#include "util.h"
2022-08-27 19:29:43 -05:00
2022-08-30 17:54:56 -05:00
#include <stdint.h>
#include <stdio.h>
#include <string.h>
2022-08-30 11:45:53 -05:00
const char *USAGE[] = {
2022-10-07 18:36:53 -05:00
"jsfw client [address] [port] [config]\n",
"jsfw server [port] [config]\n",
2022-08-27 19:29:43 -05:00
};
2022-09-11 04:23:31 -05:00
// Start the server
2022-10-07 18:36:53 -05:00
void server(uint16_t port, char *config_path) {
printf("[Server (0.0.0.0:%u)] <- %s\n\n", port, config_path);
2022-08-27 19:29:43 -05:00
2022-10-07 18:36:53 -05:00
server_run(port, config_path);
2022-08-29 17:27:03 -05:00
}
2022-08-27 19:29:43 -05:00
2022-09-11 04:23:31 -05:00
// Start the client
2022-10-07 18:36:53 -05:00
void client(char *address, uint16_t port, char *config_path) {
printf("[Client (%s:%d)] <- %s\n\n", address, port, config_path);
client_run(address, port, config_path);
2022-08-27 19:29:43 -05:00
}
2022-08-30 11:45:53 -05:00
int main(int argc, char *argv[]) {
if (argc < 2) {
2022-08-27 19:29:43 -05:00
printf("Usage: %s", USAGE[0]);
printf(" %s", USAGE[1]);
return 1;
}
2022-08-30 11:45:53 -05:00
char *mode = argv[1];
2022-08-27 19:29:43 -05:00
2022-08-30 11:45:53 -05:00
if (strcmp(mode, "server") == 0) {
2022-10-07 18:36:53 -05:00
if (argc < 4) {
2022-08-27 19:29:43 -05:00
panicf("Usage: %s", USAGE[1]);
2022-09-11 04:23:31 -05:00
}
2022-08-27 19:29:43 -05:00
2022-10-07 18:36:53 -05:00
uint16_t port = parse_port(argv[2]);
char *config_path = argv[3];
server(port, config_path);
2022-08-27 19:29:43 -05:00
2022-08-30 11:45:53 -05:00
} else if (strcmp(mode, "client") == 0) {
2022-10-07 18:36:53 -05:00
if (argc < 5) {
2022-08-27 19:29:43 -05:00
panicf("Usage: %s", USAGE[0]);
2022-09-11 04:23:31 -05:00
}
2022-08-27 19:29:43 -05:00
2022-10-07 18:36:53 -05:00
char *address = argv[2];
uint16_t port = parse_port(argv[3]);
char *config_path = argv[4];
client(address, port, config_path);
2022-08-27 19:29:43 -05:00
} else {
printf("Unknown mode: '%s'\n", mode);
printf("Usage: %s", USAGE[0]);
printf(" %s", USAGE[1]);
return 1;
}
return 0;
}