QuickIO  0.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Enumerations | Functions
protocols.h File Reference

Manages all of the protocols that clients may speak. More...

#include "quickio.h"

Go to the source code of this file.

Classes

struct  protocol_heartbeat
 Useful information about heartbeat timings. More...
 
struct  protocol_frames
 Some protocols (HTTP, looking at you) need a few frames types depending on the type of client they're immediately sending to, so those possiblities are stored here and exposed to all protocols. More...
 
struct  protocol
 What a protocol needs to route messages around. More...
 

Macros

#define PROTOCOLS_HEARTBEAT   "/qio/heartbeat:0=null"
 Full heartbeat event that is fired to clients.
 

Enumerations

enum  protocol_handles { PROT_YES, PROT_MAYBE, PROT_NO }
 If a protocol can handle a client. More...
 
enum  protocol_status { PROT_OK, PROT_AGAIN, PROT_FATAL }
 Responses from the route() functions. More...
 

Functions

struct clientprotocols_new_surrogate (struct protocol *prot)
 Create a new surrogate client bound to the given protocol. More...
 
void protocols_route (struct client *client)
 Route a message from a client to the correct protocol handler. More...
 
void protocols_send (struct client *client, const gchar *ev_path, const gchar *ev_extra, const evs_cb_t server_cb, const gchar *json)
 Write data out to a client, properly framing it as the protocol requires. More...
 
void protocols_closed (struct client *client, guint reason)
 Notification that a client was closed. More...
 
struct protocol_framesprotocols_bcast (const gchar *ev_path, const gchar *json)
 Get an array of framed events, one for each protocol. More...
 
void protocols_bcast_write (struct client *client, const struct protocol_frames *frames)
 Writes the broadcast to the given client.
 
void protocols_bcast_free (struct protocol_frames *frames)
 Frees up the frames allocated by protocols_bcast().
 
void protocols_heartbeat (struct client *client, const struct protocol_heartbeat *hb)
 Run any necessary heartbeating on the given client.
 
struct protocol_heartbeat protocols_heartbeat_get_intervals ()
 Get the heartbeat intervals that should be used in this round of periodic tasks.
 
void protocols_switch (struct client *client, struct protocol *prot)
 Switch a client to a different protocol.
 
void protocols_init ()
 Setup all protocols and get ready to run.
 

Detailed Description

Manages all of the protocols that clients may speak.

Author
Andrew Stone andre.nosp@m.w@cl.nosp@m.ovar..nosp@m.com

Enumeration Type Documentation

If a protocol can handle a client.

Enumerator
PROT_YES 

Can definitely handle the client.

PROT_MAYBE 

Might be able to handle the client, need more data to see.

PROT_NO 

Definitely cannot handle the client.

Responses from the route() functions.

Enumerator
PROT_OK 

Message was handled and routed correctly.

PROT_AGAIN 

Message has not been completely delivered yet, try again with more data.

PROT_FATAL 

The client was killed by the protocol and will not be handled.

Function Documentation

struct protocol_frames* protocols_bcast ( const gchar *  ev_path,
const gchar *  json 
)

Get an array of framed events, one for each protocol.

Parameters
ev_pathThe path of the event
jsonData to send
Returns
The frames that can be passed to protocols_bcast_write() to send to a client. Must be freed with protocols_bcast_free() when done.
void protocols_closed ( struct client client,
guint  reason 
)

Notification that a client was closed.

Parameters
clientThe client that closed
reasonWhat happened to the client
struct client* protocols_new_surrogate ( struct protocol prot)

Create a new surrogate client bound to the given protocol.

Parameters
protThe protocol to bind the new client to.
Returns
A quick-event surrogate client bound to the protocol.
void protocols_route ( struct client client)

Route a message from a client to the correct protocol handler.

Parameters
clientThe client ready for routing
void protocols_send ( struct client client,
const gchar *  ev_path,
const gchar *  ev_extra,
const evs_cb_t  server_cb,
const gchar *  json 
)

Write data out to a client, properly framing it as the protocol requires.

No data validation is done; anything that is passed is assumed to be valid. Use evs_* functions for friendlier, validated, and more idomatic ways of sending messages.

Parameters
clientThe client to write to
ev_pathThe path of the event
ev_extraAny extra path segments
server_cbThe callback expected on the server
jsonData to send with the event. MUST be a properly-formatted JSON string. [not-null]