| 1 |
#pragma once |
| 2 |
|
| 3 |
/* |
| 4 |
* Reply Registry |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <c-list.h> |
| 8 |
#include <c-rbtree.h> |
| 9 |
#include <c-stdaux.h> |
| 10 |
#include <stdlib.h> |
| 11 |
#include "util/user.h" |
| 12 |
|
| 13 |
typedef struct ReplySlot ReplySlot; |
| 14 |
typedef struct ReplyRegistry ReplyRegistry; |
| 15 |
typedef struct ReplyOwner ReplyOwner; |
| 16 |
|
| 17 |
enum { |
| 18 |
_REPLY_E_SUCCESS, |
| 19 |
|
| 20 |
REPLY_E_EXISTS, |
| 21 |
REPLY_E_QUOTA, |
| 22 |
}; |
| 23 |
|
| 24 |
struct ReplySlot { |
| 25 |
ReplyRegistry *registry; |
| 26 |
ReplyOwner *owner; |
| 27 |
UserCharge charge; |
| 28 |
uint64_t id; |
| 29 |
uint32_t serial; |
| 30 |
CRBNode registry_node; |
| 31 |
CList owner_link; |
| 32 |
}; |
| 33 |
|
| 34 |
struct ReplyRegistry { |
| 35 |
CRBTree reply_tree; |
| 36 |
}; |
| 37 |
|
| 38 |
#define REPLY_REGISTRY_INIT { \ |
| 39 |
.reply_tree = C_RBTREE_INIT, \ |
| 40 |
} |
| 41 |
|
| 42 |
struct ReplyOwner { |
| 43 |
CList reply_list; |
| 44 |
}; |
| 45 |
|
| 46 |
#define REPLY_OWNER_INIT(_x) { \ |
| 47 |
.reply_list = C_LIST_INIT((_x).reply_list), \ |
| 48 |
} |
| 49 |
|
| 50 |
int reply_slot_new(ReplySlot **replyp, ReplyRegistry *registry, ReplyOwner *owner, User *user, User *actor, uint64_t id, uint32_t serial); |
| 51 |
ReplySlot *reply_slot_free(ReplySlot *slot); |
| 52 |
|
| 53 |
ReplySlot *reply_slot_get_by_id(ReplyRegistry *registry, uint64_t id, uint32_t serial); |
| 54 |
|
| 55 |
void reply_registry_init(ReplyRegistry *registry); |
| 56 |
void reply_registry_deinit(ReplyRegistry *registry); |
| 57 |
|
| 58 |
void reply_owner_init(ReplyOwner *owner); |
| 59 |
void reply_owner_deinit(ReplyOwner *owner); |
| 60 |
|
| 61 |
void reply_owner_get_stats(ReplyOwner *owner, unsigned int *n_objectsp); |
| 62 |
|
| 63 |
C_DEFINE_CLEANUP(ReplySlot *, reply_slot_free); |