提交 641f5b56 编写于 作者: H Hongze Cheng

more

上级 e7c9b83a
......@@ -22,7 +22,8 @@ extern "C" {
extern const STsdbOptions defautlTsdbOptions;
int tsdbValidateOptions(const STsdbOptions *);
int tsdbValidateOptions(const STsdbOptions *);
void tsdbOptionsCopy(STsdbOptions *pDest, const STsdbOptions *pSrc);
#ifdef __cplusplus
}
......
......@@ -15,18 +15,80 @@
#include "tsdbDef.h"
static STsdb *tsdbNew(const char *path, const STsdbOptions *pTsdbOptions);
static void tsdbFree(STsdb *pTsdb);
static int tsdbOpenImpl(STsdb *pTsdb);
static void tsdbCloseImpl(STsdb *pTsdb);
STsdb *tsdbOpen(const char *path, const STsdbOptions *pTsdbOptions) {
STsdb *pTsdb = NULL;
/* TODO */
// Set default TSDB Options
if (pTsdbOptions == NULL) {
pTsdbOptions = &defautlTsdbOptions;
}
// Validate the options
if (tsdbValidateOptions(pTsdbOptions) < 0) {
// TODO: handle error
return NULL;
}
// Create the handle
pTsdb = tsdbNew(path, pTsdbOptions);
if (pTsdb == NULL) {
// TODO: handle error
return NULL;
}
taosMkDir(path);
// Open the TSDB
if (tsdbOpenImpl(pTsdb) < 0) {
// TODO: handle error
return NULL;
}
return pTsdb;
}
void tsdbClose(STsdb *pTsdb) {
if (pTsdb) {
/* TODO */
tsdbCloseImpl(pTsdb);
tsdbFree(pTsdb);
}
}
void tsdbRemove(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */
\ No newline at end of file
/* ------------------------ STATIC METHODS ------------------------ */
static STsdb *tsdbNew(const char *path, const STsdbOptions *pTsdbOptions) {
STsdb *pTsdb = NULL;
pTsdb = (STsdb *)calloc(1, sizeof(STsdb));
if (pTsdb == NULL) {
// TODO: handle error
return NULL;
}
pTsdb->path = strdup(path);
tsdbOptionsCopy(&(pTsdb->options), pTsdbOptions);
return pTsdb;
}
static void tsdbFree(STsdb *pTsdb) {
if (pTsdb) {
tfree(pTsdb->path);
free(pTsdb);
}
}
static int tsdbOpenImpl(STsdb *pTsdb) {
// TODO
return 0;
}
static void tsdbCloseImpl(STsdb *pTsdb) {
// TODO
}
\ No newline at end of file
......@@ -30,3 +30,5 @@ int tsdbValidateOptions(const STsdbOptions *pTsdbOptions) {
// TODO
return 0;
}
void tsdbOptionsCopy(STsdbOptions *pDest, const STsdbOptions *pSrc) { memcpy(pDest, pSrc, sizeof(STsdbOptions)); }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册