• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <sstream>
16 #include <string>
17 #include "heartbeat.h"
18 #include "serial_struct.h"
19 namespace Hdc {
AddHeartbeatCount(void)20 void HdcHeartbeat::AddHeartbeatCount(void)
21 {
22     heartbeatCount++;
23 }
24 
AddMessageCount(void)25 void HdcHeartbeat::AddMessageCount(void)
26 {
27     messageCount++;
28 }
29 
GetHeartbeatCount(void) const30 uint64_t HdcHeartbeat::GetHeartbeatCount(void) const
31 {
32     return heartbeatCount;
33 }
34 
ToString(void) const35 std::string HdcHeartbeat::ToString(void) const
36 {
37     std::stringstream ss;
38     ss << "heartbeat count is " << heartbeatCount << " and messages count is " << messageCount;
39     return ss.str();
40 }
41 
HandleRecvHeartbeatMsg(uint8_t * payload,int payloadSize)42 std::string HdcHeartbeat::HandleRecvHeartbeatMsg(uint8_t *payload, int payloadSize)
43 {
44     if (payloadSize <= 0) {
45         return "invalid heartbeat message";
46     }
47     string s = string(reinterpret_cast<char *>(payload), payloadSize);
48     HdcSessionBase::HeartbeatMsg heartbeat;
49     SerialStruct::ParseFromString(heartbeat, s);
50     std::stringstream ss;
51     ss << "heartbeat count is " << heartbeat.heartbeatCount;
52     return ss.str();
53 }
54 
SetSupportHeartbeat(bool heartbeatStatus)55 void HdcHeartbeat::SetSupportHeartbeat(bool heartbeatStatus)
56 {
57     supportHeartbeat = heartbeatStatus;
58 }
59 
GetSupportHeartbeat()60 bool HdcHeartbeat::GetSupportHeartbeat()
61 {
62     return supportHeartbeat;
63 }
64 }   //namespace Hdc