-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackend.h
More file actions
74 lines (60 loc) · 1.85 KB
/
backend.h
File metadata and controls
74 lines (60 loc) · 1.85 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef _BACKEND_H
#define _BACKEND_H
#include <inttypes.h>
#include <stdint.h>
#include <stdbool.h>
typedef uint64_t id;
#define PRIid PRIu64
typedef struct {
id id;
char *user;
char *content;
char *posted_at;
char *attachment;
char *extended;
} blastdata;
typedef struct {
// Invariant: If count > 0 then error == 0
// If != 0, the call has failed. When we know more there will be useful
// error codes here...
int error;
// String explanation of what went wrong.
// Invariant: (error == 0) == (error_message == NULL)
char *error_message;
// Tokens to pass to paging.
id before_token;
id after_token;
// Number of blasts then a pointer to that many valid blasts.
// Invariant: If count == 0 then blasts == NULL
uint64_t count;
blastdata *blasts;
} resultset;
typedef struct {
uint16_t page_size;
char *host;
char *database;
char *username;
} settings;
typedef struct mouthpiece mouthpiece;
mouthpiece *conch_connect(settings settings);
void conch_disconnect(mouthpiece *mp);
resultset *conch_recent_blasts(mouthpiece *mp);
resultset *conch_blasts_before(mouthpiece *mp, id before_token);
resultset *conch_blasts_after(mouthpiece *mp, id after_token);
typedef struct {
// id == 0 indicates an error and will result in a non-null error_message
id post;
char *error_message;
} blastresult;
blastresult *conch_blast_post(mouthpiece *mp, char *user, char *content,
char *extended);
void conch_resultset_free(resultset *results);
void conch_blastresult_free(blastresult *result);
typedef struct {
uint64_t last_notify;
mouthpiece *mouthpiece;
} notifications;
void conch_notifications_init(notifications *notifications, mouthpiece *mp);
bool conch_notifications_poll(notifications *notifications);
bool conch_notifications_await(notifications *notifications, int timeout_ms);
#endif /* _BACKEND_H */