2015-06-06 10:44:46 -07:00
|
|
|
#ifndef _COSMOPOLITE_H
|
|
|
|
|
#define _COSMOPOLITE_H
|
|
|
|
|
|
2015-06-06 10:54:58 -07:00
|
|
|
#include <curl/curl.h>
|
2015-06-06 10:44:46 -07:00
|
|
|
#include <jansson.h>
|
2015-06-06 14:43:40 -07:00
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <stdbool.h>
|
2015-06-06 10:44:46 -07:00
|
|
|
|
|
|
|
|
#define COSMO_UUID_SIZE 37
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
char client_id[COSMO_UUID_SIZE];
|
|
|
|
|
char instance_id[COSMO_UUID_SIZE];
|
|
|
|
|
|
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
|
pthread_cond_t cond;
|
|
|
|
|
bool shutdown;
|
2015-06-06 17:15:32 -07:00
|
|
|
char *profile;
|
2015-06-06 10:44:46 -07:00
|
|
|
json_t *command_queue;
|
2015-06-06 17:15:32 -07:00
|
|
|
json_t *subscriptions;
|
2015-06-06 10:44:46 -07:00
|
|
|
uint64_t next_delay_ms;
|
|
|
|
|
|
|
|
|
|
pthread_t thread;
|
2015-06-06 10:54:58 -07:00
|
|
|
CURL *curl;
|
2015-06-06 10:44:46 -07:00
|
|
|
} cosmo;
|
|
|
|
|
|
2015-06-06 14:59:08 -07:00
|
|
|
void cosmo_uuid(char *uuid);
|
2015-06-06 10:44:46 -07:00
|
|
|
|
|
|
|
|
cosmo *cosmo_create(const char *base_url, const char *client_id);
|
2015-06-06 14:59:08 -07:00
|
|
|
void cosmo_shutdown(cosmo *instance);
|
2015-06-06 10:44:46 -07:00
|
|
|
|
2015-06-06 15:32:13 -07:00
|
|
|
const char *cosmo_current_profile(cosmo *instance);
|
|
|
|
|
|
2015-06-06 10:44:46 -07:00
|
|
|
json_t *cosmo_subject(const char *name, const char *readable_only_by, const char *writeable_only_by);
|
2015-06-06 17:15:32 -07:00
|
|
|
void cosmo_subscribe(cosmo *instance, json_t *subject, const json_int_t messages, const json_int_t last_id);
|
|
|
|
|
void cosmo_unsubscribe(cosmo *instance, json_t *subject);
|
2015-06-06 14:56:23 -07:00
|
|
|
void cosmo_send_message(cosmo *instance, const json_t *subject, json_t *message);
|
2015-06-06 10:44:46 -07:00
|
|
|
|
2015-06-06 16:05:11 -07:00
|
|
|
// TODO
|
|
|
|
|
json_t *cosmo_get_messages(cosmo *instance, const json_t *subject);
|
|
|
|
|
json_t *cosmo_get_last_message(cosmo *instance, const json_t *subject);
|
|
|
|
|
json_t *cosmo_get_pins(cosmo *instance, const json_t *subject);
|
|
|
|
|
|
|
|
|
|
// Hard TODO
|
|
|
|
|
void cosmo_pin(cosmo *instance, const json_t *subject, json_t *message);
|
|
|
|
|
void cosmo_unpin(cosmo *instance, const json_t *subject, json_t *message);
|
|
|
|
|
|
2015-06-06 10:44:46 -07:00
|
|
|
#endif
|