117 lines
2.5 KiB
C
117 lines
2.5 KiB
C
#ifndef _DS_INNER_H_
|
|
#define _DS_INNER_H_
|
|
|
|
#include <stdint.h>
|
|
#include <pthread.h>
|
|
|
|
#include "list.h"
|
|
#include "dataserver_rb.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*Context of connection*/
|
|
struct ds_connection_s {
|
|
struct list_head head;
|
|
|
|
/*tmp buf for send*/
|
|
uint8_t *buf;
|
|
uint64_t data_cnt_in;
|
|
uint64_t data_cnt_out;
|
|
|
|
/*for debug*/
|
|
uint8_t *dbg;
|
|
int dbg_total;
|
|
int dbg_size;
|
|
void *server;
|
|
void *dbg_dl;
|
|
struct list_head controls;
|
|
void (*dbg_free)(void *);
|
|
|
|
pthread_t wr_thread;
|
|
pthread_t rd_thread;
|
|
int active;
|
|
int wr_active;
|
|
int rd_active;
|
|
|
|
#define MAX_NAME_SIZE 255
|
|
char device[MAX_NAME_SIZE + 1];
|
|
char client[MAX_NAME_SIZE + 1];
|
|
|
|
#define MAX_SETTINGS_SIZE 255
|
|
char settings[MAX_SETTINGS_SIZE + 1];
|
|
|
|
int (*init)(struct ds_connection_s *, void *arg);
|
|
void (*deinit)(struct ds_connection_s *);
|
|
int (*start)(struct ds_connection_s *);
|
|
void (*stop)(struct ds_connection_s *);
|
|
int (*read)(struct ds_connection_s *, void *, size_t);
|
|
int (*write)(struct ds_connection_s *, void *, size_t);
|
|
|
|
/*connection fd*/
|
|
int fd;
|
|
|
|
void *priv;
|
|
|
|
/*ringbuffer*/
|
|
ds_rb_t rb;
|
|
|
|
pthread_mutex_t lock;
|
|
};
|
|
|
|
typedef struct ds_connection_s ds_connection_t;
|
|
|
|
/*Context of server*/
|
|
struct ds_server_s {
|
|
/*connections to the server*/
|
|
struct list_head conns;
|
|
|
|
pthread_t thread;
|
|
int running;
|
|
|
|
int (*init)(struct ds_server_s *, void *arg1, void *arg2);
|
|
void (*deinit)(struct ds_server_s *);
|
|
void (*stop)(struct ds_server_s *);
|
|
|
|
/*the listened fd*/
|
|
int fd;
|
|
/*the event fd*/
|
|
int evt_fd;
|
|
|
|
void *priv;
|
|
};
|
|
|
|
typedef struct ds_server_s ds_server_t;
|
|
|
|
int ds_connection_manage_data_in(ds_connection_t *conn);
|
|
int ds_connection_manage_data_out(ds_connection_t *conn);
|
|
ds_connection_t* ds_connection_create(void);
|
|
int ds_connection_start(ds_server_t *server, ds_connection_t *conn, void *priv);
|
|
int ds_connection_stop(ds_connection_t *conn);
|
|
int ds_connection_cleanup(ds_connection_t *conn);
|
|
int ds_server_start(ds_server_t *server, void *arg1, void *arg2, void*(*task)(void*));
|
|
int ds_server_stop(ds_server_t *server);
|
|
int ds_server_cleanup_connections(ds_server_t *server, int force);
|
|
|
|
/**
|
|
* @brief definition for control item structure
|
|
*/
|
|
typedef int (*cmd_process_fn_t)(ds_connection_t *conn,
|
|
uint8_t *cmd, size_t cmd_size, uint8_t *resp, size_t resp_size);
|
|
|
|
typedef struct {
|
|
struct list_head head;
|
|
|
|
char cmd[64];
|
|
char desc[128];
|
|
cmd_process_fn_t fn;
|
|
} ds_control_t;
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|