= lcb_set_stat_callback(3couchbase) :doctype: manpage Trond Norbye NAME ---- lcb_set_stat_callback - Set callback for stats SYNOPSIS -------- cc [ flag ... ] file... -lcouchbase [ library ... ] #include lcb_stat_callback lcb_set_stat_callback(lcb_t, lcb_stat_callback); DESCRIPTION ----------- lcb_set_stat_callback() is used to set a new callback function to handle server stat commands for a given libcouchbase instance. The callback parameter is a the callback function to call for each stat response. Passing NULL as the callback function may be used to query the current callback function. The lcb_stat_callback is a function with the following signature: void function(lcb_t instance, const void *cookie, lcb_error_t error, lcb_server_stat_resp_t *resp); instance is the libcouchbase instance that this response is called from. The cookie is cookie you passed to lcb_server_stats. error is the error status of this operation. If the error is LCB_SUCCESS the resp is a pointer to the result for the operation. lcb_server_stat_resp_t is a structure defined in : typedef struct lcb_server_stat_resp_st { int version; /* The entry in "v" to use */ union { struct { const char *server_endpoint; /* which server reported this */ const void *key; /* The stat key */ lcb_size_t nkey; /* The length of the stat key */ const void *bytes; /* The value for the key */ lcb_size_t nbytes; /* The number of bytes in the value */ } v0; } v; } lcb_server_stat_resp_t; The callback function will be called multiple times (one time per server statistic) with a final call with server_enpoint set to NULL to indicate the last invocation of the callback. RETURN VALUES ------------- lcb_set_stat_callback() returns the previous callback function. EXAMPLES -------- Example 1: Query the current callback #include ... lcb_t instance; ... lcb_stat_callback old; old = lcb_set_stat_callback(instance, NULL); ... Example 2: Install custom callback #include ... static void callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_stat_resp_t *resp) { if (error == LCB_SUCCESS) { switch (resp->version) { ... /* handle the known formats */ ... default: /* handle unknown formats */ } } else { /* handle errors */ } } ... lcb_t instance; ... lcb_set_stat_callback(instance, callback); ... ATTRIBUTES ---------- See lcb_attributes(5) for descriptions of the following attributes: [options="header"] |======================================= | ATTRIBUTE TYPE | ATTRIBUTE VALUE | Interface Stability | Committed | MT-Level | MT-Safe |======================================= COPYRIGHT --------- Copyright 2010-2013 Couchbase, Inc. SEE ALSO -------- Learn more at . libcouchbase(3lib), lcb_server_stats(3couchbase), lcb_attributes(5)