Cory McWilliams
2328f3afb5
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 23m20s
100 lines
2.7 KiB
C
100 lines
2.7 KiB
C
#pragma once
|
|
|
|
#include "ssb.h"
|
|
|
|
#include "quickjs.h"
|
|
|
|
typedef struct _tf_ssb_connection_t tf_ssb_connection_t;
|
|
|
|
/**
|
|
** SSB EBT state.
|
|
*/
|
|
typedef struct _tf_ssb_ebt_t tf_ssb_ebt_t;
|
|
|
|
/**
|
|
** An EBT clock entry (identity + sequence pair).
|
|
*/
|
|
typedef struct _tf_ssb_ebt_clock_entry_t
|
|
{
|
|
/** The identity. */
|
|
char id[k_id_base64_len];
|
|
/** The sequence number. */
|
|
int64_t value;
|
|
} tf_ssb_ebt_clock_entry_t;
|
|
|
|
/**
|
|
** A set of IDs and sequence values.
|
|
*/
|
|
typedef struct _tf_ssb_ebt_clock_t
|
|
{
|
|
/** Number of entries. */
|
|
int count;
|
|
/** Clock entries. */
|
|
tf_ssb_ebt_clock_entry_t entries[];
|
|
} tf_ssb_ebt_clock_t;
|
|
|
|
/**
|
|
** A callback with EBT clock state.
|
|
*/
|
|
typedef void(tf_ssb_ebt_clock_callback_t)(const tf_ssb_ebt_clock_t* clock, int32_t request_number, void* user_data);
|
|
|
|
/**
|
|
** Create an EBT instance.
|
|
** @param connection The SSB connection to which this EBT state applies.
|
|
** @return The EBT instance.
|
|
*/
|
|
tf_ssb_ebt_t* tf_ssb_ebt_create(tf_ssb_connection_t* connection);
|
|
|
|
/**
|
|
** Update the EBT state with a received clock.
|
|
** @param ebt The EBT instance.
|
|
** @param context The JS context.
|
|
** @param clock The received clock.
|
|
*/
|
|
void tf_ssb_ebt_receive_clock(tf_ssb_ebt_t* ebt, JSContext* context, JSValue clock);
|
|
|
|
/**
|
|
** Get the EBT clock state to send.
|
|
** @param ebt The EBT instance.
|
|
** @param request_number The request number for which the clock will be sent.
|
|
** @param callback Called with the clock when determined.
|
|
** @param user_data User data passed to the callback.
|
|
*/
|
|
void tf_ssb_ebt_get_send_clock(tf_ssb_ebt_t* ebt, int32_t request_number, tf_ssb_ebt_clock_callback_t* callback, void* user_data);
|
|
|
|
/**
|
|
** Get the set of messages requested to be sent.
|
|
** @param ebt The EBT instance.
|
|
** @return A clock of identities and sequence numbers indicating which messages
|
|
** are due to be sent. The caller must free with tf_free().
|
|
*/
|
|
tf_ssb_ebt_clock_t* tf_ssb_ebt_get_messages_to_send(tf_ssb_ebt_t* ebt);
|
|
|
|
/**
|
|
** Update the clock state indicating the messages that have been sent for an account.
|
|
** @param ebt The EBT instance.
|
|
** @param id The identity to update.
|
|
** @param sequence The maximum sequence number sent.
|
|
*/
|
|
void tf_ssb_ebt_set_messages_sent(tf_ssb_ebt_t* ebt, const char* id, int64_t sequence);
|
|
|
|
/**
|
|
** Destroy an EBT instance.
|
|
** @param ebt The EBT instance.
|
|
*/
|
|
void tf_ssb_ebt_destroy(tf_ssb_ebt_t* ebt);
|
|
|
|
/**
|
|
** Get whether sending the clock is pending.
|
|
** @param ebt The EBT instance.
|
|
** @return The last value set by tf_ssb_ebt_set_send_clock_pending().
|
|
*/
|
|
int tf_ssb_ebt_get_send_clock_pending(tf_ssb_ebt_t* ebt);
|
|
|
|
/**
|
|
** Set whether sending the clock is pending.
|
|
** @param ebt The EBT instance.
|
|
** @param pending A value representing the pending status.
|
|
*/
|
|
void tf_ssb_ebt_set_send_clock_pending(tf_ssb_ebt_t* ebt, int pending);
|