Callback framework, message callback.

This commit is contained in:
Ian Gulliver
2015-06-07 15:30:08 -07:00
parent e24794b229
commit 8d9683a00c
3 changed files with 24 additions and 10 deletions

View File

@@ -2,19 +2,23 @@
#include "cosmopolite.h"
void on_message(const json_t *message) {
printf("new message: %lld\n", json_integer_value(json_object_get(message, "id")));
}
int main(int argc, char *argv[]) {
char client_id[COSMO_UUID_SIZE];
cosmo_uuid(client_id);
cosmo *instance = cosmo_create("https://playground.cosmopolite.org/cosmopolite", client_id);
cosmo_callbacks callbacks = {
.message = on_message
};
cosmo *instance = cosmo_create("https://playground.cosmopolite.org/cosmopolite", client_id, &callbacks);
json_t *subject = cosmo_subject("foobar", NULL, NULL);
cosmo_subscribe(instance, subject, -1, 0);
json_t *message = json_string("test from C");
cosmo_send_message(instance, subject, message);
json_decref(message);
json_decref(subject);
sleep(5);
printf("profile: %s\n", cosmo_current_profile(instance));
sleep(120);
sleep(20);
cosmo_shutdown(instance);
return 0;