tprocess.h 2.3 KB
Newer Older
S
shm  
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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/>.
 */

#ifndef _TD_UTIL_PROCESS_H_
#define _TD_UTIL_PROCESS_H_

#include "os.h"
20
#include "tqueue.h"
S
shm  
Shengliang Guan 已提交
21 22 23 24 25

#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
26
typedef enum { PROC_FUNC_REQ = 1, PROC_FUNC_RSP, PROC_FUNC_REGIST, PROC_FUNC_RELEASE } EProcFuncType;
S
Shengliang Guan 已提交
27

28
typedef struct SProcObj SProcObj;
29
typedef void *(*ProcMallocFp)(int32_t contLen, EQItype itype);
S
shm  
Shengliang Guan 已提交
30
typedef void *(*ProcFreeFp)(void *pCont);
S
Shengliang Guan 已提交
31
typedef void (*ProcConsumeFp)(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen,
S
Shengliang Guan 已提交
32
                              EProcFuncType ftype);
S
shm  
Shengliang Guan 已提交
33 34

typedef struct {
S
shm  
Shengliang Guan 已提交
35 36 37 38 39 40
  ProcConsumeFp childConsumeFp;
  ProcMallocFp  childMallocHeadFp;
  ProcFreeFp    childFreeHeadFp;
  ProcMallocFp  childMallocBodyFp;
  ProcFreeFp    childFreeBodyFp;
  ProcConsumeFp parentConsumeFp;
S
shm  
Shengliang Guan 已提交
41
  ProcMallocFp  parentMallocHeadFp;
S
shm  
Shengliang Guan 已提交
42 43 44
  ProcFreeFp    parentFreeHeadFp;
  ProcMallocFp  parentMallocBodyFp;
  ProcFreeFp    parentFreeBodyFp;
S
shm  
Shengliang Guan 已提交
45
  SShm          shm;
46
  void         *parent;
S
shm  
Shengliang Guan 已提交
47
  const char   *name;
S
shm  
Shengliang Guan 已提交
48
  bool          isChild;
S
shm  
Shengliang Guan 已提交
49 50 51
} SProcCfg;

SProcObj *taosProcInit(const SProcCfg *pCfg);
S
shm  
Shengliang Guan 已提交
52
void      taosProcCleanup(SProcObj *pProc);
S
shm  
Shengliang Guan 已提交
53
int32_t   taosProcRun(SProcObj *pProc);
S
Shengliang Guan 已提交
54
void      taosProcStop(SProcObj *pProc);
55 56

int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
57 58
                            void *handle, int64_t handleRef, EProcFuncType ftype);
int64_t taosProcRemoveHandle(SProcObj *pProc, void *handle);
59 60
void    taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle));
void    taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
S
Shengliang Guan 已提交
61
                             EProcFuncType ftype);
S
shm  
Shengliang Guan 已提交
62 63 64 65 66 67

#ifdef __cplusplus
}
#endif

#endif /*_TD_UTIL_PROCESS_H_*/