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

Provides all utility client functions. More...

#include "quickio.h"

Go to the source code of this file.

Classes

struct  client_sub
 Information about the client's subscription to an event. More...
 
struct  client_cb
 Information necessary to fire a callback. More...
 
struct  client
 Everything that a client needs to function. More...
 

Enumerations

enum  client_sub_state {
  CLIENT_SUB_PENDING, CLIENT_SUB_TOMBSTONED, CLIENT_SUB_CREATED, CLIENT_SUB_ACTIVE,
  CLIENT_SUB_NULL
}
 Client subscriptions go through multiple states, explained here. More...
 

Functions

evs_cb_t client_cb_new (struct client *client, const evs_cb_fn cb_fn, void *cb_data, const qev_free_fn free_fn)
 Creates a callback for the client. More...
 
enum evs_status client_cb_fire (struct client *client, const evs_cb_t server_cb, const evs_cb_t client_cb, gchar *json)
 Fires a callback and frees up everything associated with it. More...
 
void client_cb_prune (struct client *client, const gint64 before)
 Prune any client callbacks that have been hanging around too long.
 
gint64 client_cb_prune_get_before ()
 Get the time before which callbacks should be pruned.
 
gboolean client_sub_active (struct client *client, struct subscription *sub)
 Checks if a client is subscribed to the given susbcription. More...
 
enum client_sub_state client_sub_add (struct client *client, struct subscription *sub)
 Adds the subscription to the client. More...
 
enum client_sub_state client_sub_accept (struct client *client, struct subscription *sub)
 Marks the subscription as accepted. More...
 
void client_sub_reject (struct client *client, struct subscription *sub)
 Removes a pending subscription. More...
 
gboolean client_sub_remove (struct client *client, struct subscription *sub)
 Removes the subscription from the client. More...
 
void client_update_subs_config (const guint64 total, const guint64 pressure, const guint64 min)
 For configuration values: update the fair pool for subs. More...
 
void client_set (struct client *client, const GQuark key, GVariant *val)
 Sets a piece of data on a client. More...
 
GVariant * client_get (struct client *client, const GQuark key)
 Gets some data from a client. More...
 
gboolean client_has (struct client *client, const GQuark key)
 Check if the client has anything set for the given key. More...
 
void client_del (struct client *client, const GQuark key)
 Remove the key from the client. More...
 
void client_closed (struct client *client)
 A client closed and it should start to be cleaned up.
 
void client_free_all (struct client *client)
 A client is being freed and should be completely cleaned up.
 
void client_init ()
 Initialize clients data.
 

Detailed Description

Provides all utility client functions.

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

Enumeration Type Documentation

Client subscriptions go through multiple states, explained here.

Enumerator
CLIENT_SUB_PENDING 

The subscription already exists and is in the pending state (probably went async with verification).

CLIENT_SUB_TOMBSTONED 

The subscription exists and is going to be removed, but evs_on_cb() hasn't been called by the owner, so removal is being delayed until then.

CLIENT_SUB_CREATED 

The subscription was created and is in the pending state.

CLIENT_SUB_ACTIVE 

The subscription is active and valid.

CLIENT_SUB_NULL 

The client has no such subscription.

Function Documentation

enum evs_status client_cb_fire ( struct client client,
const evs_cb_t  server_cb,
const evs_cb_t  client_cb,
gchar *  json 
)

Fires a callback and frees up everything associated with it.

Parameters
clientThe client to create a callback for
server_cbThe callback ID the client sent back for the server.
client_cbThe id of the callback to send to the client
jsonData sent with the callback
evs_cb_t client_cb_new ( struct client client,
const evs_cb_fn  cb_fn,
void *  cb_data,
const qev_free_fn  free_fn 
)

Creates a callback for the client.

If cb_fn is NULL and cb_data is not, it is cleaned up with free_fn, and EVS_NO_CALLBACK is returned.

Parameters
clientThe client to create a callback for
cb_fnThe function to call when the client triggers the callback. [not-null]
cb_dataData to come with the callback [transfer-full]
free_fnFrees cb_data
Returns
The callback ID to give to the client. EVS_NO_CALLBACK if there's an error.
void client_del ( struct client client,
const GQuark  key 
)

Remove the key from the client.

Parameters
clientThe client to get the data from
keyThe key to remove
GVariant* client_get ( struct client client,
const GQuark  key 
)

Gets some data from a client.

Parameters
clientThe client to get the data from
keyThe key to lookup
Returns
A reference to the data. g_variant_unref() when done with it.
gboolean client_has ( struct client client,
const GQuark  key 
)

Check if the client has anything set for the given key.

Parameters
clientThe client to get the data from
keyThe key to lookup
Returns
If the key exists on the client
void client_set ( struct client client,
const GQuark  key,
GVariant *  val 
)

Sets a piece of data on a client.

Parameters
clientThe client to set the data on
keyThe name of the value to set
valThe value for the key. Assumes full ownership over any floating reference. May not be NULL.
enum client_sub_state client_sub_accept ( struct client client,
struct subscription sub 
)

Marks the subscription as accepted.

Parameters
clientThe client to accept the subscription on
subThe subscription to accept
Returns
CLIENT_SUB_TOMBSTONED Since it's possible for a client to unsubscribe from an event before a subscription succeeds, it's possible for approval to fail. If this is returned, only the off callback need be fired; the sub is automaticall removed from the client internally.
CLIENT_SUB_NULL There was an error setting up the subscription: the client should be told to enhance his calm
CLIENT_SUB_ACTIVE Everything went as planned
gboolean client_sub_active ( struct client client,
struct subscription sub 
)

Checks if a client is subscribed to the given susbcription.

Parameters
clientThe client in question
subThe subscription in question [transfer-none]
Returns
If the client has the subscription and it's active.
enum client_sub_state client_sub_add ( struct client client,
struct subscription sub 
)

Adds the subscription to the client.

Parameters
clientThe client in question
subThe subscription in question
Returns
CLIENT_SUB_PENDING When a previous subscription is still pending
CLIENT_SUB_NULL When the client has too many subscriptions and needs to enhance its calm.
CLIENT_SUB_ACTIVE The client is already subscribed to this event, and the event is active.
CLIENT_SUB_CREATED Sub has been accepted and is in the pending state, waiting for a call to client_sub_accept()/reject().
void client_sub_reject ( struct client client,
struct subscription sub 
)

Removes a pending subscription.

Parameters
clientThe client to reject the subscription on
subThe subscription to reject
gboolean client_sub_remove ( struct client client,
struct subscription sub 
)

Removes the subscription from the client.

Parameters
clientThe client in question
subThe subscription in question [transfer-none]
Returns
If the subscription was removed.
void client_update_subs_config ( const guint64  total,
const guint64  pressure,
const guint64  min 
)

For configuration values: update the fair pool for subs.

Parameters
totalThe new total to use
pressureThe new pressure value to use
minThe new min value to use