summaryrefslogtreecommitdiff
path: root/test/fake-reactor.c
blob: aafe8a3544071cf54803264057f9b93dafeb3d6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "fake-reactor.h"
#include <stdlib.h>

struct reactor {
  struct fake_reactor_impl *impl;
};

struct reactor *reactor_create() {
  return (struct reactor *)calloc(1, sizeof(struct reactor));
}

void reactor_destroy(struct reactor *reactor) { free(reactor); }

void reactor_update(struct reactor *reactor) {}
bool reactor_poll_event(struct reactor *reactor, uint32_t ev_id) {
  if (reactor->impl != NULL) {
    return reactor->impl->poll_event(reactor->impl->userdata, ev_id);
  } else {
    return false;
  }
}

uint32_t reactor_register_interest(struct reactor *reactor, int fd,
                                   enum interest interest) {
  if (reactor->impl != NULL) {
    return reactor->impl->register_interest(reactor->impl->userdata, fd,
                                            interest);
  } else {
    return 0;
  }
}

void reactor_unregister_interest(struct reactor *reactor, uint32_t ev_id) {
  if (reactor->impl != NULL) {
    return reactor->impl->unregister_interest(reactor->impl->userdata, ev_id);
  }
}

struct reactor *fake_reactor_create(struct fake_reactor_impl *impl) {
  struct reactor *r = reactor_create();
  set_reactor_impl(r, impl);
  return r;
}

void set_reactor_impl(struct reactor *reactor, struct fake_reactor_impl *impl) {
  reactor->impl = impl;
}