#ifndef __OPT_LOG_H__
#define __OPT_LOG_H__
#include "../common.h"
#include "open62541.h"
#include "tag.h"
#include <sqlite3.h>
#include <dy_utils/lnxall_buffer.h>


#define OPT_LOG_TABLE_MAX_ITEM   2000

#define OPT_LOG_NUM_GET "SELECT COUNT(*) FROM opt_log;"
#define OPT_LOG_GET_TO_UA "SELECT * FROM opt_log ORDER BY id DESC LIMIT %d OFFSET %d;"


typedef struct opt_log_info_s
{
    list_head_t list;
    sem_t sem;
    pthread_mutex_t mutex;
    char name[16];
    uint32_t time; // 空闲计时（秒）

    sqlite3 *db;
    sqlite3_stmt *insert_stmt;
    char db_path[256];

    pthread_mutex_t db_mutex;
} opt_log_s;

struct opt_log_buf
{
    int                num;
    struct lnxall_buff buff;
};

opt_log_s *new_opt_log(char *name);
int delete_opt_log(opt_log_s *this_p);
int opt_log_start(opt_log_s *this_p);
int opt_log_add(opt_log_s *this_p, const char *who, const char *opt,const char *optdev, const char *what, const char *content);
struct opt_log_buf* get_opt_log_data(int jump, int num);
#endif