Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle [app] add binding cluster support #12982

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
*
* Copyright (c) 2021 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/clusters/bindings/BindingManager.h"

CHIP_ERROR InitBindingHandlers();
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
*
* Copyright (c) 2021 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.
*/

#include "binding-handler.h"

#include "app-common/zap-generated/attribute-id.h"
#include "app-common/zap-generated/cluster-id.h"
#include "app-common/zap-generated/command-id.h"
#include "app/CommandSender.h"
#include "app/clusters/bindings/BindingManager.h"
#include "app/server/Server.h"
#include "app/util/af.h"
#include "lib/core/CHIPError.h"

static void BoundDeviceChangedHandler(chip::EndpointId localEndpoint, chip::EndpointId remoteEndpoint, chip::ClusterId clusterId,
chip::OperationalDeviceProxy * peer_device)
{
using namespace chip;
using namespace chip::app;
// Unfortunately generating both cluster server and client code is not supported.
// We need to manually compose the packet here.
// TODO: investigate code generation issue for binding
if (localEndpoint == 1 && clusterId == ZCL_ON_OFF_CLUSTER_ID)
{
uint8_t onOffValue;
emberAfReadServerAttribute(localEndpoint, clusterId, ZCL_ON_OFF_ATTRIBUTE_ID, &onOffValue, sizeof(onOffValue));
CommandId command = onOffValue ? Clusters::OnOff::Commands::On::Id : Clusters::OnOff::Commands::Off::Id;
CommandPathParams cmdParams = { remoteEndpoint, /* group id */ 0, clusterId, command,
(chip::app::CommandPathFlags::kEndpointIdValid) };
CommandSender sender(nullptr, peer_device->GetExchangeManager());
sender.PrepareCommand(cmdParams);
sender.FinishCommand();
peer_device->SendCommands(&sender);
}
}

CHIP_ERROR InitBindingHandlers()
{
chip::BindingManager::GetInstance().SetAppServer(&chip::Server::GetInstance());
chip::BindingManager::GetInstance().RegisterBoundDeviceChangedHandler(BoundDeviceChangedHandler);
return CHIP_NO_ERROR;
}
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import("//build_overrides/chip.gni")

executable("chip-all-clusters-app") {
sources = [
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/binding-handler.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp",
"include/tv-callbacks.cpp",
Expand Down
2 changes: 2 additions & 0 deletions examples/all-clusters-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <app/util/af.h>

#include "AppMain.h"
#include "binding-handler.h"

bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::CommandHandler * commandObj)
{
Expand Down Expand Up @@ -71,6 +72,7 @@ static Identify gIdentify1 = {
int main(int argc, char * argv[])
{
VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0);
VerifyOrDie(InitBindingHandlers() == CHIP_NO_ERROR);
ChipLinuxAppMainLoop();
return 0;
}
12 changes: 1 addition & 11 deletions examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* limitations under the License.
*/

#include <app/CASEClientPool.h>
#include <app/OperationalDeviceProxyPool.h>
#include <app/server/Server.h>
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
Expand All @@ -31,7 +29,6 @@

using chip::BDXDownloader;
using chip::ByteSpan;
using chip::CASEClientPool;
using chip::CharSpan;
using chip::EndpointId;
using chip::FabricIndex;
Expand All @@ -40,7 +37,6 @@ using chip::LinuxOTAImageProcessor;
using chip::NodeId;
using chip::OnDeviceConnected;
using chip::OnDeviceConnectionFailure;
using chip::OperationalDeviceProxyPool;
using chip::OTADownloader;
using chip::OTAImageProcessorParams;
using chip::OTARequestor;
Expand All @@ -55,15 +51,10 @@ using namespace chip::ArgParser;
using namespace chip::Messaging;
using namespace chip::app::Clusters::OtaSoftwareUpdateProvider::Commands;

constexpr size_t kMaxActiveCaseClients = 2;
constexpr size_t kMaxActiveDevices = 8;

OTARequestor gRequestorCore;
LinuxOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
LinuxOTAImageProcessor gImageProcessor;
CASEClientPool<kMaxActiveCaseClients> gCASEClientPool;
OperationalDeviceProxyPool<kMaxActiveDevices> gDevicePool;

bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue);
void OnStartDelayTimerHandler(Layer * systemLayer, void * appState);
Expand Down Expand Up @@ -195,6 +186,7 @@ int main(int argc, char * argv[])

// Init Data Model and CHIP App Server with user specified UDP port
Server::GetInstance().Init(nullptr, requestorSecurePort);
chip::Dnssd::Resolver::Instance().Init(chip::DeviceLayer::UDPEndPointManager());
ChipLogProgress(SoftwareUpdate, "Initializing the Application Server. Listening on UDP port %d", requestorSecurePort);

// Initialize device attestation config
Expand All @@ -205,8 +197,6 @@ int main(int argc, char * argv[])

// Set server instance used for session establishment
chip::Server * server = &(chip::Server::GetInstance());
server->SetCASEClientPool(&gCASEClientPool);
server->SetDevicePool(&gDevicePool);
gRequestorCore.SetServerInstance(server);

// Connect the Requestor and Requestor Driver objects
Expand Down
2 changes: 2 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ static_library("app") {
"AttributePathExpandIterator.cpp",
"AttributePathExpandIterator.h",
"AttributePathParams.h",
"BindingCallbackStub.cpp",
"BufferedReadCallback.cpp",
"CASEClient.cpp",
"CASEClient.h",
"CASEClient.h",
"CASEClientPool.h",
"CASESessionManager.cpp",
"CASESessionManager.h",
Expand Down
24 changes: 24 additions & 0 deletions src/app/BindingCallbackStub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
*
* Copyright (c) 2021 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.
*/

#include <app/ConcreteAttributePath.h>

// The stub callback for devices without binding server enabled.
// The functional callback is at app/clusters/bindings/bindings.cpp
void __attribute__((weak))
MatterBindingClusterServerAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath)
{}
2 changes: 2 additions & 0 deletions src/app/CASESessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <app/CASESessionManager.h>
#include <platform/CHIPDeviceLayer.h>

namespace chip {

Expand Down Expand Up @@ -117,6 +118,7 @@ void CASESessionManager::OnSessionReleased(SessionHandle sessionHandle)
VerifyOrReturn(session != nullptr, ChipLogDetail(Controller, "OnSessionReleased was called for unknown device, ignoring it."));

session->OnSessionReleased(sessionHandle);
ReleaseSession(session);
}

OperationalDeviceProxy * CASESessionManager::FindSession(SessionHandle session)
Expand Down
8 changes: 6 additions & 2 deletions src/app/CASESessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ class CASESessionManager : public SessionReleaseDelegate, public Dnssd::Resolver
public:
CASESessionManager() = delete;

CASESessionManager(CASESessionManagerConfig & params)
CASESessionManager(const CASESessionManagerConfig & params)
{
VerifyOrDie(params.sessionInitParams.Validate() == CHIP_NO_ERROR);

mConfig = params;
}

CHIP_ERROR Init()
{
if (mConfig.dnsResolver == nullptr)
{
VerifyOrDie(mDNSResolver.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR);
ReturnErrorOnFailure(mDNSResolver.Init(DeviceLayer::UDPEndPointManager()));
mDNSResolver.SetResolverDelegate(this);
mConfig.dnsResolver = &mDNSResolver;
}
return CHIP_NO_ERROR;
}

virtual ~CASESessionManager() { mDNSResolver.Shutdown(); }
Expand Down
2 changes: 1 addition & 1 deletion src/app/OperationalDeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct DeviceProxyInitParams

Optional<ReliableMessageProtocolConfig> mrpLocalConfig = Optional<ReliableMessageProtocolConfig>::Missing();

CHIP_ERROR Validate()
CHIP_ERROR Validate() const
{
ReturnErrorCodeIf(sessionManager == nullptr, CHIP_ERROR_INCORRECT_STATE);
ReturnErrorCodeIf(exchangeMgr == nullptr, CHIP_ERROR_INCORRECT_STATE);
Expand Down
6 changes: 6 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ template("chip_data_model") {
"${_app_root}/util/ContentApp.cpp",
"${_app_root}/util/ContentAppPlatform.cpp",
]
} else if (cluster == "bindings") {
sources += [
"${_app_root}/clusters/${cluster}/${cluster}.cpp",
"${_app_root}/clusters/${cluster}/BindingManager.cpp",
"${_app_root}/clusters/${cluster}/BindingManager.h",
]
} else {
sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ]
}
Expand Down
Loading