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 Refactor CHIPDevice class to Operational and Commissionee device proxy #10809

Closed
wants to merge 3 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
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/clusters/ModelCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CHIP_ERROR ModelCommand::RunCommand()
return err;
}

void ModelCommand::OnDeviceConnectedFn(void * context, chip::Controller::Device * device)
void ModelCommand::OnDeviceConnectedFn(void * context, ChipDevice * device)
{
ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
VerifyOrReturn(command != nullptr,
Expand Down
6 changes: 3 additions & 3 deletions examples/chip-tool/commands/clusters/ModelCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class ModelCommand : public CHIPCommand
{
public:
using ChipDevice = ::chip::Controller::Device;
using ChipDevice = ::chip::DeviceProxy;

ModelCommand(const char * commandName) :
CHIPCommand(commandName), mOnDeviceConnectedCallback(OnDeviceConnectedFn, this),
Expand All @@ -57,6 +57,6 @@ class ModelCommand : public CHIPCommand
static void OnDeviceConnectedFn(void * context, ChipDevice * device);
static void OnDeviceConnectionFailureFn(void * context, NodeId deviceId, CHIP_ERROR error);

chip::Callback::Callback<chip::Controller::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::Controller::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
};
3 changes: 1 addition & 2 deletions examples/chip-tool/commands/common/CHIPCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ class PersistentStorage;
class CHIPCommand : public Command
{
public:
using ChipDevice = ::chip::Controller::Device;
using ChipDevice = ::chip::DeviceProxy;
using ChipDeviceCommissioner = ::chip::Controller::DeviceCommissioner;
using ChipDeviceController = ::chip::Controller::DeviceController;
using ChipSerializedDevice = ::chip::Controller::SerializedDevice;
using IPAddress = ::chip::Inet::IPAddress;
using NodeId = ::chip::NodeId;
using PeerAddress = ::chip::Transport::PeerAddress;
Expand Down
11 changes: 6 additions & 5 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ CHIP_ERROR PairingCommand::RunInternal(NodeId remoteId)
return err;
}

void PairingCommand::OnDeviceConnectedFn(void * context, chip::Controller::Device * device)
void PairingCommand::OnDeviceConnectedFn(void * context, chip::DeviceProxy * device)
{
PairingCommand * command = reinterpret_cast<PairingCommand *>(context);
command->OpenCommissioningWindow();
Expand Down Expand Up @@ -153,8 +153,7 @@ CHIP_ERROR PairingCommand::PairWithMdns(NodeId remoteId)

CHIP_ERROR PairingCommand::PairWithoutSecurity(NodeId remoteId, PeerAddress address)
{
ChipSerializedDevice serializedTestDevice;
return mController.PairTestDeviceWithoutSecurity(remoteId, address, serializedTestDevice);
return CHIP_NO_ERROR;
}

CHIP_ERROR PairingCommand::Unpair(NodeId remoteId)
Expand All @@ -166,7 +165,9 @@ CHIP_ERROR PairingCommand::Unpair(NodeId remoteId)

CHIP_ERROR PairingCommand::OpenCommissioningWindow()
{
CHIP_ERROR err = mController.OpenCommissioningWindow(mNodeId, mTimeout, mIteration, mDiscriminator, mCommissioningWindowOption);
SetupPayload payload;
CHIP_ERROR err =
mController.OpenCommissioningWindow(mNodeId, mTimeout, mIteration, mDiscriminator, mCommissioningWindowOption, payload);
SetCommandExitStatus(err);
return err;
}
Expand Down Expand Up @@ -246,7 +247,7 @@ CHIP_ERROR PairingCommand::SetupNetwork()
break;
case PairingNetworkType::WiFi:
case PairingNetworkType::Thread:
err = mController.GetDevice(mNodeId, &mDevice);
err = mController.GetDeviceBeingCommissioned(mNodeId, &mDevice);
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(chipTool, "Setup failure! No pairing for device: %" PRIu64, mNodeId));

mCluster.Associate(mDevice, mEndpointId);
Expand Down
8 changes: 4 additions & 4 deletions examples/chip-tool/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ class PairingCommand : public CHIPCommand,
chip::Callback::Callback<NetworkCommissioningClusterAddWiFiNetworkResponseCallback> * mOnAddWiFiNetworkCallback = nullptr;
chip::Callback::Callback<NetworkCommissioningClusterEnableNetworkResponseCallback> * mOnEnableNetworkCallback = nullptr;
chip::Callback::Callback<DefaultFailureCallback> * mOnFailureCallback = nullptr;
ChipDevice * mDevice;
chip::CommissioneeDeviceProxy * mDevice;
chip::Controller::NetworkCommissioningCluster mCluster;
chip::EndpointId mEndpointId = 0;

static void OnDeviceConnectedFn(void * context, chip::Controller::Device * device);
static void OnDeviceConnectedFn(void * context, chip::DeviceProxy * device);
static void OnDeviceConnectionFailureFn(void * context, NodeId deviceId, CHIP_ERROR error);

chip::Callback::Callback<chip::Controller::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::Controller::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
};
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/reporting/ReportingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CHIP_ERROR ReportingCommand::RunCommand()
return err;
}

void ReportingCommand::OnDeviceConnectedFn(void * context, chip::Controller::Device * device)
void ReportingCommand::OnDeviceConnectedFn(void * context, chip::DeviceProxy * device)
{
ReportingCommand * command = reinterpret_cast<ReportingCommand *>(context);
VerifyOrReturn(command != nullptr,
Expand Down
6 changes: 3 additions & 3 deletions examples/chip-tool/commands/reporting/ReportingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class ReportingCommand : public CHIPCommand
NodeId mNodeId;
uint8_t mEndPointId;

static void OnDeviceConnectedFn(void * context, chip::Controller::Device * device);
static void OnDeviceConnectedFn(void * context, chip::DeviceProxy * device);
static void OnDeviceConnectionFailureFn(void * context, NodeId deviceId, CHIP_ERROR error);

chip::Callback::Callback<chip::Controller::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::Controller::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
};
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CHIP_ERROR TestCommand::RunCommand()
return mController.GetConnectedDevice(mNodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback);
}

void TestCommand::OnDeviceConnectedFn(void * context, chip::Controller::Device * device)
void TestCommand::OnDeviceConnectedFn(void * context, chip::DeviceProxy * device)
{
ChipLogProgress(chipTool, " **** Test Setup: Device Connected\n");
auto * command = static_cast<TestCommand *>(context);
Expand Down
6 changes: 3 additions & 3 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestCommand : public CHIPCommand
ChipDevice * mDevice;
chip::NodeId mNodeId;

static void OnDeviceConnectedFn(void * context, chip::Controller::Device * device);
static void OnDeviceConnectedFn(void * context, chip::DeviceProxy * device);
static void OnDeviceConnectionFailureFn(void * context, NodeId deviceId, CHIP_ERROR error);
static void OnWaitForMsFn(chip::System::Layer * systemLayer, void * context);

Expand Down Expand Up @@ -179,8 +179,8 @@ class TestCommand : public CHIPCommand

bool CheckValueAsString(const char * itemName, chip::CharSpan current, const char * expected);

chip::Callback::Callback<chip::Controller::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::Controller::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;

void Wait()
{
Expand Down
6 changes: 3 additions & 3 deletions examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <app-common/zap-generated/enums.h>
#include <app/server/Server.h>
#include <app/util/util.h>
#include <controller/CHIPDevice.h>
#include <controller/CHIPDeviceControllerFactory.h>
#include <controller/CommissioneeDeviceProxy.h>
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
Expand Down Expand Up @@ -49,6 +49,8 @@
using chip::ByteSpan;
using chip::CharSpan;
using chip::EndpointId;
using chip::OnDeviceConnected;
using chip::OnDeviceConnectionFailure;
using chip::VendorId;
using chip::ArgParser::HelpOptions;
using chip::ArgParser::OptionDef;
Expand All @@ -59,8 +61,6 @@ using chip::Callback::Callback;
using chip::Controller::Device;
using chip::Controller::DeviceController;
using chip::Controller::ExampleOperationalCredentialsIssuer;
using chip::Controller::OnDeviceConnected;
using chip::Controller::OnDeviceConnectionFailure;

// TODO: would be nicer to encapsulate these globals and the callbacks in some sort of class
chip::Messaging::ExchangeContext * exchangeCtx = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static_library("app") {
"Command.h",
"CommandHandler.cpp",
"CommandSender.cpp",
"DeviceProxy.h",
"EventManagement.cpp",
"InteractionModelEngine.cpp",
"MessageDef/AttributeDataElement.cpp",
Expand Down Expand Up @@ -93,6 +94,8 @@ static_library("app") {
"MessageDef/TimedRequest.cpp",
"MessageDef/WriteRequest.cpp",
"MessageDef/WriteResponse.cpp",
"OperationalDeviceProxy.cpp",
"OperationalDeviceProxy.h",
"ReadClient.cpp",
"ReadHandler.cpp",
"WriteClient.cpp",
Expand All @@ -112,6 +115,7 @@ static_library("app") {

public_deps = [
":app_buildconfig",
"${chip_root}/src/app/util:device_callbacks_manager",
"${chip_root}/src/lib/support",
"${chip_root}/src/messaging",
"${chip_root}/src/protocols/secure_channel",
Expand Down
128 changes: 128 additions & 0 deletions src/app/DeviceProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
*
* Copyright (c) 2020-2021 Project CHIP Authors
* All rights reserved.
*
* 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.
*/

/**
* @file
* This file contains definitions for DeviceProxy base class. The objects of this
* class will be used by applications to interact with peer CHIP devices.
* The class provides mechanism to construct, send and receive messages to and
* from the corresponding CHIP devices.
*/

#pragma once

#include <app/CommandSender.h>
#include <app/DeviceControllerInteractionModelDelegate.h>
#include <app/InteractionModelEngine.h>
#include <app/util/CHIPDeviceCallbacksMgr.h>
#include <lib/core/CHIPCallback.h>
#include <lib/core/CHIPCore.h>
#include <lib/support/DLLUtil.h>

namespace chip {

class DLL_EXPORT DeviceProxy
{
public:
virtual ~DeviceProxy() {}
DeviceProxy() {}

/**
* Called when a connection is closing.
* The object releases all resources associated with the connection.
*/
virtual void OnConnectionExpired(SessionHandle session) = 0;

/**
* Mark any open session with the device as expired.
*/
virtual CHIP_ERROR Disconnect() = 0;

virtual NodeId GetDeviceId() const = 0;

virtual bool GetAddress(Inet::IPAddress & addr, uint16_t & port) const { return false; }

virtual CHIP_ERROR SendReadAttributeRequest(app::AttributePathParams aPath, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, app::TLVDataFilter aTlvDataFilter) = 0;

virtual CHIP_ERROR SendSubscribeAttributeRequest(app::AttributePathParams aPath, uint16_t mMinIntervalFloorSeconds,
uint16_t mMaxIntervalCeilingSeconds, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback) = 0;

virtual CHIP_ERROR SendWriteAttributeRequest(app::WriteClientHandle aHandle, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback) = 0;

virtual CHIP_ERROR SendCommands(app::CommandSender * commandObj) = 0;

virtual void AddReportHandler(EndpointId endpoint, ClusterId cluster, AttributeId attribute,
Callback::Cancelable * onReportCallback, app::TLVDataFilter tlvDataFilter) = 0;

// These two functions are pretty tricky, it is used to bridge the response, we need to implement interaction model delegate
// on the app side instead of register callbacks here. The IM delegate can provide more infomation then callback and it is
// type-safe.
// TODO: Implement interaction model delegate in the application.
virtual void AddIMResponseHandler(app::CommandSender * commandObj, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback) = 0;

virtual void CancelIMResponseHandler(app::CommandSender * commandObj) = 0;

virtual Controller::DeviceControllerInteractionModelDelegate * GetInteractionModelDelegate() = 0;

virtual Messaging::ExchangeManager * GetExchangeManager() const = 0;

virtual chip::Optional<SessionHandle> GetSecureSession() const = 0;

virtual bool IsActive() const { return true; }
};

/**
* This class defines an interface for an object that the user of Device
* can register as a delegate. The delegate object will be called by the
* Device when a new message or status update is received from the corresponding
* CHIP device.
*/
class DLL_EXPORT DeviceStatusDelegate
{
public:
virtual ~DeviceStatusDelegate() {}

/**
* @brief
* Called when a message is received from the device.
*
* @param[in] msg Received message buffer.
*/
virtual void OnMessage(System::PacketBufferHandle && msg) = 0;

/**
* @brief
* Called when response to OpenPairingWindow is received from the device.
*
* @param[in] status CHIP_NO_ERROR on success, or corresponding error.
*/
virtual void OnPairingWindowOpenStatus(CHIP_ERROR status){};

/**
* @brief
* Called when device status is updated.
*
*/
virtual void OnStatusChange(void){};
};

} // namespace chip
Loading