sparse-tools/include/bs_types.h

127 lines
2.1 KiB
C

//
// Created by haraldwolff on 13.08.22.
//
#pragma once
#include <stdint.h>
#include <pthread.h>
typedef enum {
SR_SENDER = (1<<8),
SR_RECEIVER = (1<<9),
SR_TEST = (1<<10)
} sr_mode_t;
typedef enum {
BS_SIMULATE = (1<<0),
BS_LISTENER = (1<<2),
BS_VERBOSE = (1<<3),
BS_DEBUG = (1 << 4),
BS_SHUTDOWN = (1<<5),
BS_ALLOC = (1<<6),
} tool_flags_t;
typedef enum {
BS_SENDER = (1<<0),
BS_RECEIVER = (1<<1),
BS_COMPRESSION_MASK
= (0xFF << 8),
BS_COMPRESSION_BZ2
= (1<<8),
BS_PROTO_MASK = (0xFF << 16),
BS_LINEAR = (1<<16),
BS_MERKLE = (2<<16)
} bs_flags_t;
typedef enum {
BSS_COMM = (1<<0),
BSS_ANALYZE = (1<<1),
BSS_SYNC = (1<<2),
BSS_TRANSFER = (1<<3)
} bs_state_flags_t;
typedef struct {
int magic;
bs_flags_t bs_flags;
long filesize;
int blocksize;
} bs_hello_t;
typedef struct {
int hours;
int minutes;
int seconds;
} bs_time_t;
typedef enum {
BS_PRG_ANALYZE = (1 << 0),
BS_PRG_SYNC = (1 << 1),
BS_PRG_TRANSFER = (1 << 2),
} bs_progress_steps_t;
typedef enum {
BS_MSG_REQUEST = 0,
BS_MSG_RESPONSE = (1<<0),
BS_MSG_PROGRESS = (1<<1),
BS_MSG_GOODBYE = (1<<2),
// (1<<3),
BS_MSG_MERKLE_SYNC = (1<<4),
BS_MSG_BLOCKDATA = (1<<5),
} bs_msg_t;
typedef struct {
bs_progress_steps_t step; // current step worked on
int32_t distance; // progress needed to reach 100%
int32_t progress; // progress made so far
int32_t duration; // time needed so far
} bs_msg_progress_t;
typedef struct {
int32_t level;
int32_t start;
int32_t length;
} bs_msg_sync_t;
typedef struct {
int32_t blockno;
} bs_msg_transfer_t;
typedef struct bs_msg_buffer bs_msg_buffer_t;
struct bs_msg_buffer{
bs_msg_buffer_t *next;
bs_msg_t msg_type;
int msg_length;
int payload_length;
union {
char msg[1024];
bs_msg_progress_t progress;
bs_msg_sync_t sync;
bs_msg_transfer_t transfer;
};
union {
char *payload;
int32_t *payload_i32;
uint32_t *payload_ui32;
uint64_t *payload_i64;
uint64_t *payload_ui64;
};
};
typedef enum { Q_NONE, Q_WAIT } bs_msg_queue_flags_t;
typedef struct {
pthread_mutex_t mutex;
pthread_cond_t cond;
bs_msg_buffer_t *first;
bs_msg_buffer_t *last;
} bs_msg_queue_t;
typedef struct bs_engine bs_engine_t;