tsdbMain.c 2.1 KB
Newer Older
H
more  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * 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/>.
 */
H
refact  
Hongze Cheng 已提交
15

H
more  
Hongze Cheng 已提交
16 17
#include "tsdbDef.h"

H
refact  
Hongze Cheng 已提交
18
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions);
H
more  
Hongze Cheng 已提交
19 20 21 22
static void   tsdbFree(STsdb *pTsdb);
static int    tsdbOpenImpl(STsdb *pTsdb);
static void   tsdbCloseImpl(STsdb *pTsdb);

H
refact  
Hongze Cheng 已提交
23
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbOptions) {
H
more  
Hongze Cheng 已提交
24
  STsdb *pTsdb = NULL;
H
more  
Hongze Cheng 已提交
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

  // 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;
  }

H
more  
Hongze Cheng 已提交
52 53 54 55 56
  return pTsdb;
}

void tsdbClose(STsdb *pTsdb) {
  if (pTsdb) {
H
more  
Hongze Cheng 已提交
57 58
    tsdbCloseImpl(pTsdb);
    tsdbFree(pTsdb);
H
more  
Hongze Cheng 已提交
59 60 61 62 63
  }
}

void tsdbRemove(const char *path) { taosRemoveDir(path); }

H
more  
Hongze Cheng 已提交
64
/* ------------------------ STATIC METHODS ------------------------ */
H
refact  
Hongze Cheng 已提交
65
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) {
H
more  
Hongze Cheng 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  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
}