2024-08-14 00:33:52 +03:00
|
|
|
#ifndef PROCESSING_H_
|
|
|
|
#define PROCESSING_H_
|
|
|
|
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include "events.h"
|
|
|
|
|
|
|
|
typedef struct io_handling IOHandling;
|
|
|
|
|
|
|
|
// no virtual multiinheritance
|
|
|
|
struct io_handling {
|
|
|
|
EventPositionBase * self;
|
|
|
|
void (*handle_io) (EventPositionBase * self, int fd, bool is_output);
|
|
|
|
bool enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
size_t length;
|
|
|
|
size_t capacity;
|
|
|
|
int *fds;
|
|
|
|
IOHandling **subscribers;
|
|
|
|
} IOSubscriptionList;
|
|
|
|
|
|
|
|
typedef struct delay_list DelayList;
|
|
|
|
|
|
|
|
struct delay_list {
|
2024-08-14 14:47:55 +03:00
|
|
|
void (*callback) (EventPositionBase * target, void * closure, const AbsoluteTime * time);
|
2024-08-14 00:33:52 +03:00
|
|
|
EventPositionBase *target;
|
|
|
|
void *closure;
|
|
|
|
DelayList *next;
|
2024-08-14 14:47:55 +03:00
|
|
|
AbsoluteTime time;
|
2024-08-14 00:33:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
IOSubscriptionList wait_input, wait_output;
|
|
|
|
DelayList *wait_delay;
|
2024-08-14 14:47:55 +03:00
|
|
|
AbsoluteTime reached_time;
|
2024-08-14 00:33:52 +03:00
|
|
|
int32_t pass_priority;
|
|
|
|
bool has_future_events;
|
|
|
|
} ProcessingState;
|
|
|
|
|
|
|
|
void io_subscription_list_init(IOSubscriptionList * lst, size_t capacity);
|
|
|
|
void io_subscription_list_deinit(IOSubscriptionList * lst);
|
|
|
|
void io_subscription_list_add(IOSubscriptionList * lst, int fd, IOHandling *subscriber);
|
|
|
|
|
2024-08-14 14:47:55 +03:00
|
|
|
bool schedule_delay(ProcessingState * state, EventPositionBase * target, void (*callback) (EventPositionBase*, void*, const AbsoluteTime*), const AbsoluteTime * time);
|
|
|
|
bool process_io(ProcessingState * state, const RelativeTime * timeout);
|
2024-08-14 00:33:52 +03:00
|
|
|
void process_iteration(ProcessingState * state);
|
|
|
|
|
|
|
|
#endif /* end of include guard: PROCESSING_H_ */
|