#include <mongoc/mongoc.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
|
static void _server_changed (const mongoc_apm_server_changed_t *event) {
|
mongoc_client_t *client;
|
mongoc_server_description_t *sd;
|
|
MONGOC_DEBUG ("server changed event - begin");
|
client = mongoc_apm_server_changed_get_context (event);
|
sd = mongoc_client_select_server (client, true, NULL, NULL);
|
mongoc_server_description_destroy (sd);
|
MONGOC_DEBUG ("server changed event - end");
|
}
|
|
int
|
main (int argc, char *argv[])
|
{
|
mongoc_client_t *client;
|
mongoc_apm_callbacks_t *callbacks;
|
mongoc_server_description_t *sd;
|
|
mongoc_init ();
|
client = mongoc_client_new ("mongodb://localhost:27017");
|
/* Set a server changed callback. */
|
callbacks = mongoc_apm_callbacks_new ();
|
mongoc_apm_set_server_changed_cb (callbacks, _server_changed);
|
mongoc_client_set_apm_callbacks (client, callbacks, client);
|
sd = mongoc_client_select_server (client, true, NULL, NULL);
|
mongoc_server_description_destroy (sd);
|
mongoc_client_destroy (client);
|
mongoc_apm_callbacks_destroy (callbacks);
|
mongoc_cleanup ();
|
}
|