QuickIO  0.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
evs.h
Go to the documentation of this file.
1 
12 #pragma once
13 #include "quickio.h"
14 
18 #define EVS_NO_CALLBACK (0l)
19 
23 typedef guint64 evs_cb_t;
24 
31 typedef enum evs_status (*evs_handler_fn)(
32  struct client *client,
33  const gchar *ev_extra,
34  const evs_cb_t client_cb,
35  gchar *json);
36 
43 typedef void (*evs_off_fn)(
44  struct client *client,
45  const gchar *ev_extra);
46 
50 typedef enum evs_status (*evs_cb_fn)(
51  struct client *client,
52  const void *data,
53  const evs_cb_t client_cb,
54  gchar *json);
55 
59 enum evs_status {
68 
77 
88 };
89 
95 enum evs_code {
99  CODE_OK = 200,
100 
105 
109  CODE_BAD = 400,
110 
114  CODE_UNAUTH = 401,
115 
121 
127 
132 };
133 
141 struct evs_on_info {
145  gchar *ev_extra;
146 
150  struct subscription *sub;
151 
155  struct client *client;
156 
161 };
162 
179 typedef enum evs_status (*evs_on_fn)(const struct evs_on_info *info);
180 
184 struct event {
188  gchar *ev_path;
189 
194 
199 
204 
208  gboolean handle_children;
209 
219  GHashTable *subs;
220 
224  GRWLock subs_lock;
225 };
226 
230 void event_init(
231  struct event *ev,
232  const gchar *ev_path,
233  const evs_handler_fn handler_fn,
234  const evs_on_fn on_fn,
235  const evs_off_fn off_fn,
236  const gboolean handle_children);
237 
241 void event_clear(struct event *ev);
242 
262 struct event* evs_add_handler(
263  const gchar *ev_prefix,
264  const gchar *ev_path,
266  const evs_on_fn on_fn,
267  const evs_off_fn off_fn,
268  const gboolean handle_children);
269 
275 enum evs_status evs_no_on(const struct evs_on_info *info);
276 
287 guint evs_clean_path(gchar *ev_path);
288 
304 GString* evs_make_path(
305  const gchar *ev_prefix,
306  const gchar *ev_path,
307  const gchar *ev_extra);
308 
322 void evs_route(
323  struct client *client,
324  gchar *ev_path,
325  const evs_cb_t client_cb,
326  gchar *json);
327 
341 void evs_on(
342  struct client *client,
343  struct event *ev,
344  gchar *ev_extra,
345  const evs_cb_t client_cb);
346 
359 void evs_send(
360  struct client *client,
361  struct event *ev,
362  const gchar *ev_extra,
363  const gchar *json);
364 
373 void evs_send_info(const struct evs_on_info *info, const gchar *json);
374 
385 void evs_send_sub(
386  struct client *client,
387  struct subscription *sub,
388  const gchar *json);
389 
408 void evs_send_full(
409  struct client *client,
410  struct event *ev,
411  const gchar *ev_extra,
412  const gchar *json,
413  const evs_cb_fn cb_fn,
414  void *cb_data,
415  const qev_free_fn free_fn);
416 
431 void evs_send_info_full(
432  const struct evs_on_info *info,
433  const gchar *json,
434  const evs_cb_fn cb_fn,
435  void *cb_data,
436  const qev_free_fn free_fn);
437 
454 void evs_send_sub_full(
455  struct client *client,
456  struct subscription *sub,
457  const gchar *json,
458  const evs_cb_fn cb_fn,
459  void *cb_data,
460  const qev_free_fn free_fn);
461 
488  struct client *client,
489  const gchar *ev_prefix,
490  const gchar *ev_path,
491  const gchar *ev_extra,
492  const gchar *json,
493  const evs_cb_fn cb_fn,
494  void *cb_data,
495  const qev_free_fn free_fn);
496 
507 void evs_on_cb(
508  const gboolean success,
509  const struct evs_on_info *info);
510 
523  const struct evs_on_info *info,
524  const gboolean with_ev_extra);
525 
533 void evs_on_info_free(struct evs_on_info *info);
534 
545 void evs_off(
546  struct client *client,
547  struct event *ev,
548  const gchar *ev_extra);
549 
560 void evs_client_offd(struct client *client, struct subscription *sub);
561 
572 void evs_cb(
573  struct client *client,
574  const evs_cb_t client_cb,
575  const gchar *json);
576 
596 void evs_cb_with_cb(
597  struct client *client,
598  const evs_cb_t client_cb,
599  const gchar *json,
600  const evs_cb_fn cb_fn,
601  void *cb_data,
602  const qev_free_fn free_fn);
603 
620 void evs_err_cb(
621  struct client *client,
622  const evs_cb_t client_cb,
623  const enum evs_code code,
624  const gchar *err_msg,
625  const gchar *json);
626 
656 void evs_cb_full(
657  struct client *client,
658  const evs_cb_t client_cb,
659  const enum evs_code code,
660  const gchar *err_msg,
661  const gchar *json,
662  const evs_cb_fn cb_fn,
663  void *cb_data,
664  const qev_free_fn free_fn);
665 
676 void evs_broadcast(
677  struct event *ev,
678  const gchar *ev_extra,
679  const gchar *json);
680 
684 void evs_client_close(struct client *client);
685 
694 void evs_broadcast_path(
695  const gchar *ev_path,
696  const gchar *json);
697 
704 void evs_broadcast_tick();
705 
712 void evs_pre_init();
713 
717 void evs_init();
void evs_cb_with_cb(struct client *client, const evs_cb_t client_cb, const gchar *json, const evs_cb_fn cb_fn, void *cb_data, const qev_free_fn free_fn)
Sends a CODE_OK callback to a client while requesting a callback from the client. ...
void evs_init()
Initialize the stats in events.
void evs_on_info_free(struct evs_on_info *info)
Clean up the copy of struct evs_on_info, releasing any references made.
A previous request for the exact same thing is currently being processed.
Definition: evs.h:104
Malformed data was sent.
Definition: evs.h:109
evs_status
From handlers, these values instruct the server how to handle everything.
Definition: evs.h:59
guint64 evs_cb_t
Callbacks are just gigantic integers, 0 meaning "no callback".
Definition: evs.h:23
Everything went as expected.
Definition: evs.h:99
void evs_cb_full(struct client *client, const evs_cb_t client_cb, const enum evs_code code, const gchar *err_msg, const gchar *json, const evs_cb_fn cb_fn, void *cb_data, const qev_free_fn free_fn)
Sends a callback to a client, with all possible data.
void evs_broadcast_tick()
Do the actual event broadcasting.
guint evs_clean_path(gchar *ev_path)
Given an arbitrary, full path, clean it up entirely (in place) so that it conforms with QIO standards...
evs_code
Codes used for callbacks.
Definition: evs.h:95
void event_init(struct event *ev, const gchar *ev_path, const evs_handler_fn handler_fn, const evs_on_fn on_fn, const evs_off_fn off_fn, const gboolean handle_children)
Intialize a new struct event
struct client * client
Can be 1 of 3 things, depending on client type: 1) If the client is a surrogate, then points to the c...
Definition: client.h:224
You're not allowed to do that.
Definition: evs.h:114
Events are stored in a prefix tree for fast, nice lookups.
Definition: evs.h:184
void evs_send(struct client *client, struct event *ev, const gchar *ev_extra, const gchar *json)
Sends an event to a specific client.
Yeah, I'm going to need you to go ahead and not use something that doesn't exist. ...
Definition: evs.h:120
void evs_err_cb(struct client *client, const evs_cb_t client_cb, const enum evs_code code, const gchar *err_msg, const gchar *json)
Sends a callback to a client with an error code and message.
The server understood the request but needs to client to calm down.
Definition: evs.h:126
struct event * evs_add_handler(const gchar *ev_prefix, const gchar *ev_path, const evs_handler_fn handler_fn, const evs_on_fn on_fn, const evs_off_fn off_fn, const gboolean handle_children)
Creates a handler for an event.
void evs_send_sub(struct client *client, struct subscription *sub, const gchar *json)
Sends an event to a specific client.
void evs_on_cb(const gboolean success, const struct evs_on_info *info)
Subscribes a client to an event without any callback checks.
struct client * client
The client that sent the subscription.
Definition: evs.h:155
evs_on_fn on_fn
Called when client attempts to subscribe to event.
Definition: evs.h:198
GString * evs_make_path(const gchar *ev_prefix, const gchar *ev_path, const gchar *ev_extra)
Given a path, make it such that is matches exactly what QIO expects paths to be.
gchar * ev_path
The event path for this node.
Definition: evs.h:188
void evs_client_close(struct client *client)
Cleans up after the client when it closes.
void evs_send_info(const struct evs_on_info *info, const gchar *json)
Sends an event to a specific client.
void evs_route(struct client *client, gchar *ev_path, const evs_cb_t client_cb, gchar *json)
Routes an event from a client.
GRWLock subs_lock
Lock for subs.
Definition: evs.h:224
Everything that a client needs to function.
Definition: client.h:100
void evs_send_sub_full(struct client *client, struct subscription *sub, const gchar *json, const evs_cb_fn cb_fn, void *cb_data, const qev_free_fn free_fn)
Sends an event to a specific client, requesting a callback from the client.
enum evs_status(* evs_on_fn)(const struct evs_on_info *info)
The handler for when a client subscribes.
Definition: evs.h:179
void evs_cb(struct client *client, const evs_cb_t client_cb, const gchar *json)
Sends a CODE_OK callback to a client.
GHashTable * data
Any extra data that can be attached to a client using client_{get,set,del,has}(). ...
Definition: client.h:158
void evs_send_full(struct client *client, struct event *ev, const gchar *ev_extra, const gchar *json, const evs_cb_fn cb_fn, void *cb_data, const qev_free_fn free_fn)
Sends an event to a specific client, requesting a callback from the client.
void evs_broadcast(struct event *ev, const gchar *ev_extra, const gchar *json)
Broadcast a message to all clients listening on the event.
evs_cb_t client_cb
The callback id to be sent.
Definition: evs.h:160
Information necessary to fire a callback.
Definition: client.h:70
struct subscription * sub
Reference to the susbcription.
Definition: evs.h:150
void evs_send_info_full(const struct evs_on_info *info, const gchar *json, const evs_cb_fn cb_fn, void *cb_data, const qev_free_fn free_fn)
Sends an event to a specific client, requesting a callback from the client.
struct evs_on_info * evs_on_info_copy(const struct evs_on_info *info, const gboolean with_ev_extra)
Make a copy of the evs_on_info(), returning a reference that is safe to use from another thread...
void evs_pre_init()
Initialize events.
gchar * ev_extra
Any extra parameters sent with the event.
Definition: evs.h:145
Every header, definition, and whatnot QuickIO needs to run.
evs_handler_fn handler_fn
Function called when client sends event to the server.
Definition: evs.h:193
void evs_send_bruteforce(struct client *client, const gchar *ev_prefix, const gchar *ev_path, const gchar *ev_extra, const gchar *json, const evs_cb_fn cb_fn, void *cb_data, const qev_free_fn free_fn)
Send an event to a client, damn the consequences.
The event was handled and any necessary callbacks (including error callbacks) have been dispatched by...
Definition: evs.h:87
The event was handled and a default callback should be sent, if the client requested.
Definition: evs.h:67
void evs_broadcast_path(const gchar *ev_path, const gchar *json)
Broadcast a message to all clients listening on the event.
GHashTable * subs
All of the children subscriptions to this event, referenced by extra path segments.
Definition: evs.h:219
void evs_client_offd(struct client *client, struct subscription *sub)
The client was unsubscribed from an event, and any callbacks should be fired immediately.
There was an error with the handler and a generic error should be sent back to the client...
Definition: evs.h:76
An unknown error occurred.
Definition: evs.h:131
Contains all the fields necessary to send a callback to a client about a subscription.
Definition: evs.h:141
void evs_on(struct client *client, struct event *ev, gchar *ev_extra, const evs_cb_t client_cb)
Subscribes the client to the event, checking with the event's subscriber callback that such things ar...
evs_off_fn off_fn
Called when client unsubscribes from event.
Definition: evs.h:203
void(* qev_free_fn)(void *)
Function type for a typical free function.
Definition: qev.h:185
Events are what are located at the paths, whereas subscriptions are what are located at ev_path + ev_...
Definition: sub.h:20
void(* evs_off_fn)(struct client *client, const gchar *ev_extra)
The handler for when a client unsubscribes.
Definition: evs.h:43
enum evs_status(* evs_handler_fn)(struct client *client, const gchar *ev_extra, const evs_cb_t client_cb, gchar *json)
The handler function type.
Definition: evs.h:31
void evs_off(struct client *client, struct event *ev, const gchar *ev_extra)
Remove a client from an event.
enum evs_status evs_no_on(const struct evs_on_info *info)
Doesn't allow anyone to subscribe to the event.
enum evs_status(* evs_cb_fn)(struct client *client, const void *data, const evs_cb_t client_cb, gchar *json)
Function called when the client sends a callback to the server.
Definition: evs.h:50
void event_clear(struct event *ev)
Clean up all memory inside a struct event
gboolean handle_children
If this event wants to handle all children paths.
Definition: evs.h:208