diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | command.c | 14 | ||||
-rw-r--r-- | command.h | 2 | ||||
-rw-r--r-- | control.c | 6 | ||||
-rw-r--r-- | control.h | 1 | ||||
-rw-r--r-- | nfcommander.c | 41 | ||||
-rw-r--r-- | reader.c | 6 | ||||
-rw-r--r-- | reader.h | 1 |
8 files changed, 69 insertions, 4 deletions
@@ -1,7 +1,7 @@ .PHONY: all CFLAGS += -g -Wall -Wpedantic -CORE_OBJS = control.o reader.o config.o +CORE_OBJS = control.o reader.o config.o command.o PLUGINS = reader_yhy.so reader_yhy.so: LDLIBS = -lyhy diff --git a/command.c b/command.c new file mode 100644 index 0000000..c7a7be8 --- /dev/null +++ b/command.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +#include "command.h" + +int command_handle(int fd){ + //TODO + printf("Handling data on command fd\n"); + return 0; +} + +void command_free(){ + //TODO + printf("Shutting down any remaining commands\n"); +} diff --git a/command.h b/command.h new file mode 100644 index 0000000..7bae5ae --- /dev/null +++ b/command.h @@ -0,0 +1,2 @@ +int command_handle(int fd); +void command_free(); @@ -8,6 +8,12 @@ int control_start(){ return 0; } +int control_handle(int fd){ + //TODO + printf("Handling data on control fd\n"); + return 0; +} + void control_free(){ printf("Shutting down control interface\n"); } @@ -1,2 +1,3 @@ int control_start(); +int control_handle(int fd); void control_free(); diff --git a/nfcommander.c b/nfcommander.c index ceadec7..3c58d6c 100644 --- a/nfcommander.c +++ b/nfcommander.c @@ -7,6 +7,15 @@ #include "config.h" #include "reader.h" #include "control.h" +#include "command.h" + +typedef union { + struct { + uint32_t system; + uint32_t fd; + } components; + uint64_t u64; +} epoll_private_t; static volatile sig_atomic_t shutdown_requested = 0; static int epoll_fd = -1; @@ -23,9 +32,14 @@ static int usage(char* fn){ } int core_manage_fd(int fd, int manage, notification_target_t system){ + epoll_private_t data = { + .components.system = system, + .components.fd = fd + }; + struct epoll_event event = { .events = EPOLLIN, - .data.u32 = system + .data.u64 = data.u64 }; if(epoll_ctl(epoll_fd, manage ? EPOLL_CTL_ADD : EPOLL_CTL_DEL, fd, &event)){ @@ -37,6 +51,10 @@ int core_manage_fd(int fd, int manage, notification_target_t system){ } int main(int argc, char** argv){ + size_t n; + int event_count; + epoll_private_t polldata; + if(argc < 2){ return usage(argv[0]); } @@ -66,12 +84,28 @@ int main(int argc, char** argv){ //handle events while(!shutdown_requested){ - int event_count = epoll_wait(epoll_fd, events, sizeof(events) / sizeof(struct epoll_event), 1000); + event_count = epoll_wait(epoll_fd, events, sizeof(events) / sizeof(struct epoll_event), 1000); if(event_count < 0){ break; } - printf("%d events\n", event_count); + for(n = 0; n < event_count; n++){ + polldata.u64 = events[n].data.u64; + switch(polldata.components.system){ + case system_control: + control_handle(polldata.components.fd); + break; + case system_reader: + reader_handle(polldata.components.fd); + break; + case system_command: + command_handle(polldata.components.fd); + break; + default: + printf("Unhandled target system for fd %d\n", polldata.components.fd); + break; + } + } } //clean up @@ -79,5 +113,6 @@ int main(int argc, char** argv){ epoll_fd = -1; reader_free(); control_free(); + command_free(); config_free(); } @@ -28,6 +28,12 @@ int reader_init(){ return 0; } +int reader_handle(int fd){ + //TODO + printf("Handling data on reader fd\n"); + return 0; +} + void reader_free(){ if(reader_module){ dlclose(reader_module); @@ -1,2 +1,3 @@ int reader_init(); +int reader_handle(int fd); void reader_free(); |