Skip to content

Commit ccbdd31

Browse files
authored
Merge branch 'master' into feature/app-install-flow-public
2 parents 47739c2 + 3bc5667 commit ccbdd31

File tree

4 files changed

+29
-57
lines changed

4 files changed

+29
-57
lines changed

examples/network-manager-app/linux/main.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,36 @@ using namespace chip;
2828
using namespace chip::app;
2929
using namespace chip::app::Clusters;
3030

31-
void ApplicationInit() {}
32-
void ApplicationShutdown() {}
33-
3431
ByteSpan ByteSpanFromCharSpan(CharSpan span)
3532
{
3633
return ByteSpan(Uint8::from_const_char(span.data()), span.size());
3734
}
3835

3936
std::optional<DefaultThreadNetworkDirectoryServer> gThreadNetworkDirectoryServer;
40-
void emberAfThreadNetworkDirectoryClusterInitCallback(chip::EndpointId endpoint)
37+
void emberAfThreadNetworkDirectoryClusterInitCallback(EndpointId endpoint)
4138
{
4239
VerifyOrDie(!gThreadNetworkDirectoryServer);
4340
gThreadNetworkDirectoryServer.emplace(endpoint).Init();
4441
}
4542

46-
int main(int argc, char * argv[])
43+
std::optional<WiFiNetworkManagementServer> gWiFiNetworkManagementServer;
44+
void emberAfWiFiNetworkManagementClusterInitCallback(EndpointId endpoint)
45+
{
46+
VerifyOrDie(!gWiFiNetworkManagementServer);
47+
gWiFiNetworkManagementServer.emplace(endpoint).Init();
48+
}
49+
50+
void ApplicationInit()
4751
{
48-
if (ChipLinuxAppInit(argc, argv) != 0)
49-
{
50-
return -1;
51-
}
52+
gWiFiNetworkManagementServer->SetNetworkCredentials(ByteSpanFromCharSpan("MatterAP"_span),
53+
ByteSpanFromCharSpan("Setec Astronomy"_span));
54+
}
5255

53-
WiFiNetworkManagementServer::Instance().SetNetworkCredentials(ByteSpanFromCharSpan("MatterAP"_span),
54-
ByteSpanFromCharSpan("Setec Astronomy"_span));
56+
void ApplicationShutdown() {}
5557

58+
int main(int argc, char * argv[])
59+
{
60+
VerifyOrReturnValue(ChipLinuxAppInit(argc, argv) == 0, -1);
5661
ChipLinuxAppMainLoop();
5762
return 0;
5863
}

src/app/clusters/wifi-network-management-server/wifi-network-management-server.cpp

+6-32
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include <app/AttributeAccessInterfaceRegistry.h>
2121
#include <app/InteractionModelEngine.h>
2222
#include <app/reporting/reporting.h>
23-
#include <app/util/config.h>
24-
#include <lib/core/Global.h>
2523
#include <lib/support/CodeUtils.h>
2624

2725
#include <algorithm>
@@ -55,18 +53,11 @@ bool IsValidWpaPersonalCredential(ByteSpan credential)
5553
return false;
5654
}
5755

58-
Global<WiFiNetworkManagementServer> gWiFiNetworkManagementServerInstance;
59-
6056
} // namespace
6157

62-
WiFiNetworkManagementServer & WiFiNetworkManagementServer::Instance()
63-
{
64-
return gWiFiNetworkManagementServerInstance.get();
65-
}
66-
67-
WiFiNetworkManagementServer::WiFiNetworkManagementServer() :
68-
AttributeAccessInterface(NullOptional, WiFiNetworkManagement::Id),
69-
CommandHandlerInterface(NullOptional, WiFiNetworkManagement::Id)
58+
WiFiNetworkManagementServer::WiFiNetworkManagementServer(EndpointId endpoint) :
59+
AttributeAccessInterface(MakeOptional(endpoint), WiFiNetworkManagement::Id),
60+
CommandHandlerInterface(MakeOptional(endpoint), WiFiNetworkManagement::Id)
7061
{}
7162

7263
WiFiNetworkManagementServer::~WiFiNetworkManagementServer()
@@ -75,12 +66,8 @@ WiFiNetworkManagementServer::~WiFiNetworkManagementServer()
7566
InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this);
7667
}
7768

78-
CHIP_ERROR WiFiNetworkManagementServer::Init(EndpointId endpoint)
69+
CHIP_ERROR WiFiNetworkManagementServer::Init()
7970
{
80-
VerifyOrReturnError(endpoint != kInvalidEndpointId, CHIP_ERROR_INVALID_ARGUMENT);
81-
VerifyOrReturnError(mEndpointId == kInvalidEndpointId, CHIP_ERROR_INCORRECT_STATE);
82-
83-
mEndpointId = endpoint;
8471
VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INTERNAL);
8572
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this));
8673
return CHIP_NO_ERROR;
@@ -92,7 +79,7 @@ CHIP_ERROR WiFiNetworkManagementServer::ClearNetworkCredentials()
9279

9380
mSsidLen = 0;
9481
mPassphrase.SetLength(0);
95-
MatterReportingAttributeChangeCallback(mEndpointId, WiFiNetworkManagement::Id, Ssid::Id);
82+
MatterReportingAttributeChangeCallback(GetEndpointId(), WiFiNetworkManagement::Id, Ssid::Id);
9683
return CHIP_NO_ERROR;
9784
}
9885

@@ -114,7 +101,7 @@ CHIP_ERROR WiFiNetworkManagementServer::SetNetworkCredentials(ByteSpan ssid, Byt
114101
// Note: The spec currently defines no way to signal a passphrase change
115102
if (ssidChanged)
116103
{
117-
MatterReportingAttributeChangeCallback(mEndpointId, WiFiNetworkManagement::Id, Ssid::Id);
104+
MatterReportingAttributeChangeCallback(GetEndpointId(), WiFiNetworkManagement::Id, Ssid::Id);
118105
}
119106
return CHIP_NO_ERROR;
120107
}
@@ -160,17 +147,4 @@ void WiFiNetworkManagementServer::HandleNetworkPassphraseRequest(HandlerContext
160147
} // namespace app
161148
} // namespace chip
162149

163-
#if defined(MATTER_DM_WIFI_NETWORK_MANAGEMENT_CLUSTER_SERVER_ENDPOINT_COUNT) && \
164-
MATTER_DM_WIFI_NETWORK_MANAGEMENT_CLUSTER_SERVER_ENDPOINT_COUNT > 1
165-
#error Only a single Wi-Fi Network Management Cluster instance is supported.
166-
#endif
167-
168150
void MatterWiFiNetworkManagementPluginServerInitCallback() {}
169-
170-
void emberAfWiFiNetworkManagementClusterServerInitCallback(EndpointId endpoint)
171-
{
172-
// We could delay constructing the instance until this point; however it's not
173-
// clear if this is inconvenient in terms of forcing the application to initialize
174-
// the network credentials later than it otherwise would.
175-
LogErrorOnFailure(chip::app::Clusters::WiFiNetworkManagementServer::Instance().Init(endpoint));
176-
}

src/app/clusters/wifi-network-management-server/wifi-network-management-server.h

+7-13
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
#include <app-common/zap-generated/cluster-objects.h>
2121
#include <app/AttributeAccessInterface.h>
2222
#include <app/CommandHandlerInterface.h>
23-
#include <crypto/CHIPCryptoPAL.h>
2423
#include <lib/core/CHIPError.h>
25-
#include <lib/core/Global.h>
2624
#include <lib/support/Span.h>
2725

2826
void emberAfWiFiNetworkManagementClusterServerInitCallback(chip::EndpointId);
@@ -34,30 +32,26 @@ namespace Clusters {
3432
class WiFiNetworkManagementServer : private AttributeAccessInterface, private CommandHandlerInterface
3533
{
3634
public:
37-
static WiFiNetworkManagementServer & Instance();
35+
WiFiNetworkManagementServer(EndpointId endpoint);
36+
~WiFiNetworkManagementServer();
37+
38+
CHIP_ERROR Init();
3839

3940
CHIP_ERROR ClearNetworkCredentials();
4041
CHIP_ERROR SetNetworkCredentials(ByteSpan ssid, ByteSpan passphrase);
4142

42-
private:
43-
friend Global<WiFiNetworkManagementServer>;
44-
friend void ::emberAfWiFiNetworkManagementClusterServerInitCallback(chip::EndpointId);
45-
46-
WiFiNetworkManagementServer();
47-
~WiFiNetworkManagementServer();
48-
CHIP_ERROR Init(EndpointId endpoint);
49-
5043
WiFiNetworkManagementServer(WiFiNetworkManagementServer const &) = delete;
5144
WiFiNetworkManagementServer & operator=(WiFiNetworkManagementServer const &) = delete;
5245

46+
private:
47+
EndpointId GetEndpointId() { return AttributeAccessInterface::GetEndpointId().Value(); }
48+
5349
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
5450
void InvokeCommand(HandlerContext & handlerContext) override;
5551

5652
void HandleNetworkPassphraseRequest(HandlerContext & ctx,
5753
const WiFiNetworkManagement::Commands::NetworkPassphraseRequest::DecodableType & req);
5854

59-
EndpointId mEndpointId = kInvalidEndpointId;
60-
6155
uint8_t mSsid[32];
6256
uint8_t mSsidLen = 0;
6357
static_assert(std::numeric_limits<decltype(mSsidLen)>::max() >= sizeof(mSsid));

src/app/common/templates/config-data.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ ClustersWithInitFunctions:
5959
- Mode Select
6060
- Sample MEI
6161
- Scenes Management
62-
- Wi-Fi Network Management
6362

6463
ClustersWithAttributeChangedFunctions:
6564
- Bridged Device Basic

0 commit comments

Comments
 (0)