tmsgcb.c 2.2 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 "transLog.h"
20
#include "trpc.h"
S
Shengliang Guan 已提交
21

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

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

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

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

39 40 41 42 43 44 45 46
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 已提交
47

48 49 50 51 52 53 54
void tmsgSendRsp(SRpcMsg* pMsg) {
#if 1
  rpcSendResponse(pMsg);
#else
  return (*defaultMsgCb.sendRspFp)(pMsg);
#endif
}
S
Shengliang Guan 已提交
55

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

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

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

62 63
bool tmsgUpdateDnodeInfo(int32_t* dnodeId, int64_t* clusterId, char* fqdn, uint16_t* port) {
  return (*defaultMsgCb.updateDnodeInfoFp)(defaultMsgCb.data, dnodeId, clusterId, fqdn, port);
64
}
65 66 67 68 69 70

void tmsgUpdateDnodeEpSet(SEpSet* epset) {
  for (int32_t i = 0; i < epset->numOfEps; ++i) {
    tmsgUpdateDnodeInfo(NULL, NULL, epset->eps[i].fqdn, &epset->eps[i].port);
  }
}