Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2023 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #include "HeartbeatProcedure.h"
21 :
22 : namespace firebolt::rialto::server
23 : {
24 6 : std::unique_ptr<IHeartbeatProcedureFactory> IHeartbeatProcedureFactory::createFactory()
25 : {
26 6 : return std::make_unique<HeartbeatProcedureFactory>();
27 : }
28 :
29 : std::shared_ptr<IHeartbeatProcedure>
30 6 : HeartbeatProcedureFactory::createHeartbeatProcedure(const std::shared_ptr<IAckSender> &ackSender, std::int32_t pingId) const
31 : {
32 6 : return std::make_shared<HeartbeatProcedure>(ackSender, pingId);
33 : }
34 :
35 7 : HeartbeatProcedure::HeartbeatHandler::HeartbeatHandler(const std::shared_ptr<HeartbeatProcedure> &procedure,
36 7 : std::int32_t pingId)
37 7 : : m_procedure{procedure}, m_kPingId{pingId}, m_success{true}
38 : {
39 : }
40 :
41 14 : HeartbeatProcedure::HeartbeatHandler::~HeartbeatHandler()
42 : {
43 7 : m_procedure->onFinish(m_success);
44 14 : }
45 :
46 2 : void HeartbeatProcedure::HeartbeatHandler::error()
47 : {
48 2 : m_success = false;
49 : }
50 :
51 1 : std::int32_t HeartbeatProcedure::HeartbeatHandler::id() const
52 : {
53 1 : return m_kPingId;
54 : }
55 :
56 6 : HeartbeatProcedure::HeartbeatProcedure(const std::shared_ptr<IAckSender> &ackSender, std::int32_t pingId)
57 6 : : m_ackSender{ackSender}, m_kPingId{pingId}, m_success{true}
58 : {
59 : }
60 :
61 6 : HeartbeatProcedure::~HeartbeatProcedure()
62 : {
63 6 : m_ackSender->send(m_kPingId, m_success);
64 : }
65 :
66 7 : std::unique_ptr<IHeartbeatHandler> HeartbeatProcedure::createHandler()
67 : {
68 7 : return std::make_unique<HeartbeatHandler>(shared_from_this(), m_kPingId);
69 : }
70 :
71 7 : void HeartbeatProcedure::onFinish(bool success)
72 : {
73 7 : if (!success)
74 : {
75 2 : m_success = false;
76 : }
77 7 : }
78 : } // namespace firebolt::rialto::server
|