forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread-border-router-management-server.h
107 lines (93 loc) · 4.3 KB
/
thread-border-router-management-server.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
*
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <app-common/zap-generated/cluster-objects.h>
#include <app/AttributeAccessInterface.h>
#include <app/CommandHandlerInterface.h>
#include <app/ConcreteCommandPath.h>
#include <app/FailSafeContext.h>
#include <app/clusters/thread-border-router-management-server/thread-br-delegate.h>
#include <app/reporting/reporting.h>
#include <lib/core/Optional.h>
#include <lib/support/Span.h>
namespace chip {
namespace app {
namespace Clusters {
namespace ThreadBorderRouterManagement {
class ServerInstance : public CommandHandlerInterface,
public AttributeAccessInterface,
public Delegate::ActivateDatasetCallback,
public Delegate::AttributeChangeCallback
{
public:
using Status = Protocols::InteractionModel::Status;
ServerInstance(EndpointId endpointId, Delegate * delegate, FailSafeContext & failSafeContext) :
CommandHandlerInterface(Optional<EndpointId>(endpointId), Id),
AttributeAccessInterface(Optional<EndpointId>(endpointId), Id), mDelegate(delegate), mServerEndpointId(endpointId),
mFailsafeContext(failSafeContext)
{}
virtual ~ServerInstance() = default;
CHIP_ERROR Init();
// CommandHanlerInterface
void InvokeCommand(HandlerContext & ctx) override;
// AttributeAccessInterface
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
// ActivateDatasetCallback
void OnActivateDatasetComplete(uint32_t sequenceNum, CHIP_ERROR error) override;
// AttributeChangeCallback
void ReportAttributeChanged(AttributeId attributeId) override;
private:
// TODO: Split the business logic from the unit test class
friend class TestThreadBorderRouterManagementCluster;
// Command Handlers
Status HandleGetActiveDatasetRequest(HandlerContext & ctx, Thread::OperationalDataset & dataset)
{
return HandleGetDatasetRequest(ctx, Delegate::DatasetType::kActive, dataset);
}
Status HandleGetPendingDatasetRequest(HandlerContext & ctx, Thread::OperationalDataset & dataset)
{
return HandleGetDatasetRequest(ctx, Delegate::DatasetType::kPending, dataset);
}
Status HandleSetActiveDatasetRequest(HandlerContext & ctx, const Commands::SetActiveDatasetRequest::DecodableType & req);
Status HandleSetPendingDatasetRequest(HandlerContext & ctx, const Commands::SetPendingDatasetRequest::DecodableType & req);
Status HandleGetDatasetRequest(HandlerContext & ctx, Delegate::DatasetType type, Thread::OperationalDataset & dataset);
// Attribute Read handlers
void ReadFeatureMap(BitFlags<Feature> & feature);
std::optional<uint64_t> ReadActiveDatasetTimestamp();
std::optional<uint64_t> ReadPendingDatasetTimestamp();
CHIP_ERROR ReadBorderRouterName(MutableCharSpan & borderRouterName);
CHIP_ERROR ReadBorderAgentID(MutableByteSpan & borderAgentId);
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
void SetSkipCASESessionCheck(bool skipCheck) { mSkipCASESessionCheck = skipCheck; }
bool mSkipCASESessionCheck;
#endif
bool IsCommandOverCASESession(CommandHandlerInterface::HandlerContext & ctx);
static void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
void OnFailSafeTimerExpired();
void CommitSavedBreadcrumb();
Delegate * mDelegate;
app::CommandHandler::Handle mAsyncCommandHandle;
ConcreteCommandPath mPath = ConcreteCommandPath(0, 0, 0);
Optional<uint64_t> mBreadcrumb;
uint32_t mSetActiveDatasetSequenceNumber = 0;
EndpointId mServerEndpointId;
FailSafeContext & mFailsafeContext;
};
} // namespace ThreadBorderRouterManagement
} // namespace Clusters
} // namespace app
} // namespace chip