sdb.h 2.1 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

S
Shengliang Guan 已提交
16 17
#ifndef _TD_SDB_H_
#define _TD_SDB_H_
S
Shengliang Guan 已提交
18

S
Shengliang Guan 已提交
19
#include "cJSON.h"
S
Shengliang Guan 已提交
20

S
Shengliang Guan 已提交
21 22 23
#ifdef __cplusplus
extern "C" {
#endif
S
Shengliang Guan 已提交
24

S
Shengliang Guan 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
typedef enum {
  MN_SDB_START = 0,
  MN_SDB_CLUSTER = 1,
  MN_SDB_DNODE = 2,
  MN_SDB_MNODE = 3,
  MN_SDB_ACCT = 4,
  MN_SDB_AUTH = 5,
  MN_SDB_USER = 6,
  MN_SDB_DB = 7,
  MN_SDB_VGROUP = 8,
  MN_SDB_STABLE = 9,
  MN_SDB_FUNC = 10,
  MN_SDB_OPER = 11,
  MN_SDB_MAX = 12
} EMnSdb;

typedef enum { MN_OP_START = 0, MN_OP_INSERT = 1, MN_OP_UPDATE = 2, MN_OP_DELETE = 3, MN_OP_MAX = 4 } EMnOp;

typedef enum { MN_KEY_START = 0, MN_KEY_BINARY = 1, MN_KEY_INT32 = 2, MN_KEY_INT64 = 3, MN_KEY_MAX } EMnKey;

typedef enum { MN_SDB_STAT_AVAIL = 0, MN_SDB_STAT_DROPPED = 1 } EMnSdbStat;

typedef struct {
  int8_t type;
  int8_t status;
  int8_t align[6];
} SdbHead;

S
Shengliang Guan 已提交
53 54 55
typedef void (*SdbDeployFp)();
typedef void *(*SdbDecodeFp)(cJSON *root);
typedef int32_t (*SdbEncodeFp)(void *pHead, char *buf, int32_t maxLen);
S
Shengliang Guan 已提交
56

S
Shengliang Guan 已提交
57 58
int32_t sdbInit();
void    sdbCleanup();
S
Shengliang Guan 已提交
59

S
Shengliang Guan 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
int32_t sdbRead();
int32_t sdbCommit();

int32_t sdbDeploy();
void    sdbUnDeploy();

void   *sdbInsertRow(EMnSdb sdb, void *pObj);
void    sdbDeleteRow(EMnSdb sdb, void *pHead);
void   *sdbUpdateRow(EMnSdb sdb, void *pHead);
void   *sdbGetRow(EMnSdb sdb, void *pKey);
void   *sdbFetchRow(EMnSdb sdb, void *pIter);
void    sdbCancelFetch(EMnSdb sdb, void *pIter);
int32_t sdbGetCount(EMnSdb sdb);

void sdbSetFp(EMnSdb, EMnKey, SdbDeployFp, SdbEncodeFp, SdbDecodeFp, int32_t dataSize);
S
Shengliang Guan 已提交
75

S
Shengliang Guan 已提交
76 77 78
#ifdef __cplusplus
}
#endif
S
Shengliang Guan 已提交
79

S
Shengliang Guan 已提交
80
#endif /*_TD_SDB_H_*/