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

#define _DEFAULT_SOURCE
#include "tmsgcb.h"
18
#include "taoserror.h"
19
#include "trpc.h"
S
Shengliang Guan 已提交
20

S
Shengliang Guan 已提交
21
static SMsgCb defaultMsgCb;
S
shm  
Shengliang Guan 已提交
22

S
Shengliang Guan 已提交
23
void tmsgSetDefault(const SMsgCb* msgcb) { defaultMsgCb = *msgcb; }
S
shm  
Shengliang Guan 已提交
24

S
Shengliang Guan 已提交
25
int32_t tmsgPutToQueue(const SMsgCb* msgcb, EQueueType qtype, SRpcMsg* pMsg) {
26 27 28 29 30 31
  int32_t code = (*msgcb->putToQueueFp)(msgcb->mgmt, qtype, pMsg);
  if (code != 0) {
    rpcFreeCont(pMsg->pCont);
    pMsg->pCont = NULL;
  }
  return code;
S
Shengliang Guan 已提交
32 33
}

S
Shengliang Guan 已提交
34
int32_t tmsgGetQueueSize(const SMsgCb* msgcb, int32_t vgId, EQueueType qtype) {
S
Shengliang Guan 已提交
35
  return (*msgcb->qsizeFp)(msgcb->mgmt, vgId, qtype);
S
Shengliang Guan 已提交
36 37
}

38 39 40 41 42 43 44 45
int32_t tmsgSendReq(const SEpSet* epSet, SRpcMsg* pMsg) {
  int32_t code = (*defaultMsgCb.sendReqFp)(epSet, pMsg);
  if (code != 0) {
    rpcFreeCont(pMsg->pCont);
    pMsg->pCont = NULL;
  }
  return code;
}
S
Shengliang Guan 已提交
46

S
Shengliang Guan 已提交
47
void tmsgSendRsp(SRpcMsg* pMsg) { return (*defaultMsgCb.sendRspFp)(pMsg); }
S
Shengliang Guan 已提交
48

S
Shengliang Guan 已提交
49
void tmsgSendRedirectRsp(SRpcMsg* pMsg, const SEpSet* pNewEpSet) { (*defaultMsgCb.sendRedirectRspFp)(pMsg, pNewEpSet); }
S
Shengliang Guan 已提交
50

S
Shengliang Guan 已提交
51
void tmsgRegisterBrokenLinkArg(SRpcMsg* pMsg) { (*defaultMsgCb.registerBrokenLinkArgFp)(pMsg); }
S
shm  
Shengliang Guan 已提交
52

S
Shengliang Guan 已提交
53
void tmsgReleaseHandle(SRpcHandleInfo* pHandle, int8_t type) { (*defaultMsgCb.releaseHandleFp)(pHandle, type); }
S
Shengliang Guan 已提交
54

55
void tmsgReportStartup(const char* name, const char* desc) { (*defaultMsgCb.reportStartupFp)(name, desc); }