Files
cosmopolite/clients/c/cosmopolite.h

71 lines
1.7 KiB
C
Raw Normal View History

2015-06-06 10:44:46 -07:00
#ifndef _COSMOPOLITE_H
#define _COSMOPOLITE_H
#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-14 00:33:10 +00:00
#include <stdint.h>
2015-06-06 10:44:46 -07:00
#define COSMO_UUID_SIZE 37
2015-06-07 15:30:08 -07:00
typedef struct {
2015-06-18 04:27:17 +00:00
void (*connect)(void *);
2015-06-15 03:26:41 +00:00
void (*logout)(void *);
void (*message)(const json_t *, void *);
2015-06-07 15:30:08 -07:00
} cosmo_callbacks;
2015-06-06 10:44:46 -07:00
typedef struct {
char client_id[COSMO_UUID_SIZE];
char instance_id[COSMO_UUID_SIZE];
2015-06-07 15:30:08 -07:00
cosmo_callbacks callbacks;
void *passthrough;
2015-06-06 10:44:46 -07:00
pthread_mutex_t lock;
pthread_cond_t cond;
bool shutdown;
char *profile;
2015-06-06 10:44:46 -07:00
json_t *command_queue;
2015-06-15 02:27:03 +00:00
json_t *ack;
json_t *subscriptions;
2015-06-06 10:44:46 -07:00
uint64_t next_delay_ms;
unsigned int seedp;
2015-06-06 10:44:46 -07:00
2015-06-18 04:27:17 +00:00
enum {
INITIAL_CONNECT,
CONNECTED,
DISCONNECTED,
} connect_state;
enum {
LOGIN_UNKNOWN,
LOGGED_OUT,
LOGGED_IN,
} login_state;
2015-06-06 10:44:46 -07:00
pthread_t thread;
CURL *curl;
2015-06-06 10:44:46 -07:00
} cosmo;
void cosmo_uuid(char *uuid);
2015-06-06 10:44:46 -07:00
cosmo *cosmo_create(const char *base_url, const char *client_id, const cosmo_callbacks *callbacks, void *passthrough);
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);
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);
void cosmo_send_message(cosmo *instance, json_t *subject, json_t *message);
2015-06-06 10:44:46 -07:00
json_t *cosmo_get_messages(cosmo *instance, json_t *subject);
json_t *cosmo_get_last_message(cosmo *instance, json_t *subject);
2015-06-06 16:05:11 -07:00
// TODO
json_t *cosmo_get_pins(cosmo *instance, json_t *subject);
void cosmo_pin(cosmo *instance, json_t *subject, json_t *message);
void cosmo_unpin(cosmo *instance, json_t *subject, json_t *message);
2015-06-06 16:05:11 -07:00
2015-06-06 10:44:46 -07:00
#endif