Skip to content

Commit

Permalink
Renaming CHIP -> Matter
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple committed Jun 29, 2022
1 parent 9d2eeb0 commit 2f615b9
Show file tree
Hide file tree
Showing 192 changed files with 71,287 additions and 47,346 deletions.
18 changes: 16 additions & 2 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ assert(chip_build_tools)
config("config") {
include_dirs = [
".",
"${chip_root}/src/darwin/Framework/CHIP/zap-generated",
"${chip_root}/src/darwin/Framework/CHIP",
"${chip_root}/examples/darwin-framework-tool/commands/common",
"${chip_root}/zzz_generated/darwin-framework-tool",
"${chip_root}/zzz_generated/controller-clusters",
"${chip_root}/examples/chip-tool/commands/clusters/ComplexArgument.h",
"/tmp/macos_framework_output",
]

framework_dirs = [
"/tmp/macos_framework_output",
]

defines = [
"CONFIG_ENABLE_YAML_TESTS=${config_enable_yaml_tests}",
"CONFIG_USE_INTERACTIVE_MODE=${config_use_interactive_mode}",
Expand All @@ -51,12 +59,16 @@ executable("darwin-framework-tool") {
# privilege-storage.cpp.
"${chip_root}/src/app/util/privilege-storage.cpp",
"${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp",
"${chip_root}/zzz_generated/controller-clusters/zap-generated/CHIPClusters.h",
"commands/clusters/ClusterCommandBridge.h",
"commands/clusters/ModelCommandBridge.mm",
"commands/clusters/ReportCommandBridge.h",
"commands/clusters/WriteAttributeCommandBridge.h",
"commands/common/CHIPCommandBridge.mm",
"commands/common/CHIPCommandStorageDelegate.mm",
"commands/common/MTRLogging.h",
"commands/common/MTRError_Utils.h",
"commands/common/MTRError.mm",
"commands/common/CHIPToolKeypair.mm",
"commands/pairing/Commands.h",
"commands/pairing/OpenCommissioningWindowCommand.h",
Expand All @@ -73,19 +85,21 @@ executable("darwin-framework-tool") {
}

if (config_enable_yaml_tests) {
sources += [ "${chip_root}/zzz_generated/darwin-framework-tool/zap-generated/cluster/CHIPTestClustersObjc.mm" ]
sources += [ "${chip_root}/zzz_generated/darwin-framework-tool/zap-generated/cluster/MTRTestClustersObjc.mm" ]
}

deps = [
"${chip_root}/examples/chip-tool:chip-tool-utils",
"${chip_root}/src/app/server",
"${chip_root}/src/darwin/Framework/CHIP",
"${chip_root}/src/darwin/Framework/CHIP:static-matter",
"${chip_root}/src/lib",
"${chip_root}/src/platform",
"${chip_root}/third_party/inipp",
"${chip_root}/third_party/jsoncpp",
]

frameworks = [ "Matter.framework", "Security.framework" ]

public_configs = [ ":config" ]

output_dir = root_out_dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

#pragma once

#import <CHIP/CHIP.h>
#import <CHIP/CHIPDevice_Internal.h> // For NSObjectFromCHIPTLV

#import <Matter/Matter.h>
#import "MTRError_Utils.h"

#include <lib/support/UnitTestUtils.h>

#include "ModelCommandBridge.h"
Expand All @@ -46,7 +48,7 @@ class ClusterCommand : public ModelCommand {

~ClusterCommand() {}

CHIP_ERROR SendCommand(CHIPDevice * _Nonnull device, chip::EndpointId endpointId) override
CHIP_ERROR SendCommand(MTRDevice * _Nonnull device, chip::EndpointId endpointId) override
{
chip::TLV::TLVWriter writer;
chip::TLV::TLVReader reader;
Expand All @@ -67,7 +69,7 @@ class ClusterCommand : public ModelCommand {
return ClusterCommand::SendCommand(device, endpointId, mClusterId, mCommandId, commandFields);
}

CHIP_ERROR SendCommand(CHIPDevice * _Nonnull device, chip::EndpointId endpointId, chip::ClusterId clusterId,
CHIP_ERROR SendCommand(MTRDevice * _Nonnull device, chip::EndpointId endpointId, chip::ClusterId clusterId,
chip::CommandId commandId, id _Nonnull commandFields)
{
uint16_t repeatCount = mRepeatCount.ValueOr(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ModelCommand : public CHIPCommandBridge
CHIP_ERROR RunCommand() override;
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(10); }

virtual CHIP_ERROR SendCommand(CHIPDevice * _Nonnull device, chip::EndpointId endPointId) = 0;
virtual CHIP_ERROR SendCommand(MTRDevice * _Nonnull device, chip::EndpointId endPointId) = 0;

private:
chip::NodeId mNodeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,37 @@
#include "ModelCommandBridge.h"
#include <inttypes.h>

#import <Matter/Matter.h>

using namespace ::chip;

CHIP_ERROR ModelCommand::RunCommand()
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);

MTRDeviceController * commissioner = CurrentCommissioner();
ChipLogProgress(chipTool, "Sending command to node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));
[CurrentCommissioner() getConnectedDevice:mNodeId
queue:callbackQueue
completionHandler:^(CHIPDevice * _Nullable device, NSError * _Nullable error) {
if (error != nil) {
SetCommandExitStatus(error, "Error getting connected device");
return;
}

CHIP_ERROR err;
if (device == nil) {
err = CHIP_ERROR_INTERNAL;
} else {
err = SendCommand(device, mEndPointId);
}

if (err != CHIP_NO_ERROR) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
SetCommandExitStatus(err);
return;
}
}];
[commissioner getConnectedDevice:mNodeId
queue:callbackQueue
completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) {
if (error != nil) {
SetCommandExitStatus(error, "Error getting connected device");
return;
}

CHIP_ERROR err;
if (device == nil) {
err = CHIP_ERROR_INTERNAL;
} else {
err = SendCommand(device, mEndPointId);
}

if (err != CHIP_NO_ERROR) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
SetCommandExitStatus(err);
return;
}
}];
return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class ReadAttribute : public ModelCommand {

~ReadAttribute() {}

CHIP_ERROR SendCommand(CHIPDevice * _Nonnull device, chip::EndpointId endpointId) override
CHIP_ERROR SendCommand(MTRDevice * _Nonnull device, chip::EndpointId endpointId) override
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
CHIPReadParams * params = [[CHIPReadParams alloc] init];
MTRReadParams * params = [[MTRReadParams alloc] init];
params.fabricFiltered = mFabricFiltered.HasValue() ? [NSNumber numberWithBool:mFabricFiltered.Value()] : nil;
[device
readAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
Expand Down Expand Up @@ -125,10 +125,10 @@ class SubscribeAttribute : public ModelCommand {

~SubscribeAttribute() {}

CHIP_ERROR SendCommand(CHIPDevice * _Nonnull device, chip::EndpointId endpointId) override
CHIP_ERROR SendCommand(MTRDevice * _Nonnull device, chip::EndpointId endpointId) override
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
CHIPSubscribeParams * params = [[CHIPSubscribeParams alloc] init];
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
params.keepPreviousSubscriptions
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
[device subscribeAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
Expand Down Expand Up @@ -195,11 +195,11 @@ class SubscribeEvent : public ModelCommand {

~SubscribeEvent() {}

CHIP_ERROR SendCommand(CHIPDevice * _Nonnull device, chip::EndpointId endpointId) override
CHIP_ERROR SendCommand(MTRDevice * _Nonnull device, chip::EndpointId endpointId) override
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);

CHIPSubscribeParams * params = [[CHIPSubscribeParams alloc] init];
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
params.keepPreviousSubscriptions
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
[device subscribeWithQueue:callbackQueue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "ModelCommandBridge.h"

#import <Matter/Matter.h>
#import "MTRError_Utils.h"

class WriteAttribute : public ModelCommand {
public:
WriteAttribute()
Expand All @@ -44,7 +47,7 @@ class WriteAttribute : public ModelCommand {

~WriteAttribute() {}

CHIP_ERROR SendCommand(CHIPDevice * _Nonnull device, chip::EndpointId endpointId) override
CHIP_ERROR SendCommand(MTRDevice * _Nonnull device, chip::EndpointId endpointId) override
{
chip::TLV::TLVWriter writer;
chip::TLV::TLVReader reader;
Expand All @@ -66,7 +69,7 @@ class WriteAttribute : public ModelCommand {
return WriteAttribute::SendCommand(device, endpointId, mClusterId, mAttributeId, value);
}

CHIP_ERROR SendCommand(CHIPDevice * _Nonnull device, chip::EndpointId endpointId, chip::ClusterId clusterId,
CHIP_ERROR SendCommand(MTRDevice * _Nonnull device, chip::EndpointId endpointId, chip::ClusterId clusterId,
chip::AttributeId attributeId, id _Nonnull value)
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#pragma once
#import <CHIP/CHIP.h>
#import <Matter/Matter.h>
#include <commands/common/Command.h>
#include <commands/common/CredentialIssuerCommands.h>
#include <map>
Expand Down Expand Up @@ -67,9 +67,9 @@ class CHIPCommandBridge : public Command
void SetIdentity(const char * identity);

// This method returns the commissioner instance to be used for running the command.
CHIPDeviceController * CurrentCommissioner();
MTRDeviceController * CurrentCommissioner();

CHIPDeviceController * GetCommissioner(const char * identity);
MTRDeviceController * GetCommissioner(const char * identity);

// Will log the given string and given error (as progress if success, error
// if failure).
Expand Down Expand Up @@ -106,10 +106,10 @@ class CHIPCommandBridge : public Command
void MaybeTearDownStack();

// Our three controllers: alpha, beta, gamma.
static std::map<std::string, CHIPDeviceController *> mControllers;
static std::map<std::string, MTRDeviceController *> mControllers;

// The current controller; the one the current command should be using.
CHIPDeviceController * mCurrentController;
MTRDeviceController * mCurrentController;

std::condition_variable cvWaitingForResponse;
std::mutex cvWaitingForResponseMutex;
Expand Down
23 changes: 12 additions & 11 deletions examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
#include "CHIPCommandBridge.h"

#import "CHIPToolKeypair.h"
#import <CHIP/CHIP.h>
#import <CHIP/CHIPError_Internal.h>
#import <Matter/Matter.h>

#include <core/CHIPBuildConfig.h>
#include <lib/core/CHIPVendorIdentifiers.hpp>

#include "MTRError_Utils.h"

const uint16_t kListenPort = 5541;
static CHIPToolPersistentStorageDelegate * storage = nil;
std::set<CHIPCommandBridge *> CHIPCommandBridge::sDeferredCleanups;
std::map<std::string, CHIPDeviceController *> CHIPCommandBridge::mControllers;
std::map<std::string, MTRDeviceController *> CHIPCommandBridge::mControllers;

CHIP_ERROR CHIPCommandBridge::Run()
{
Expand Down Expand Up @@ -61,13 +62,13 @@
CHIPToolKeypair * nocSigner = [[CHIPToolKeypair alloc] init];
storage = [[CHIPToolPersistentStorageDelegate alloc] init];

auto factory = [MatterControllerFactory sharedInstance];
auto factory = [MTRControllerFactory sharedInstance];
if (factory == nil) {
ChipLogError(chipTool, "Controller factory is nil");
return CHIP_ERROR_INTERNAL;
}

auto params = [[MatterControllerFactoryParams alloc] initWithStorage:storage];
auto params = [[MTRControllerFactoryParams alloc] initWithStorage:storage];
params.port = @(kListenPort);
params.startServer = YES;

Expand All @@ -82,7 +83,7 @@

constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
for (size_t i = 0; i < ArraySize(identities); ++i) {
auto controllerParams = [[CHIPDeviceControllerStartupParams alloc] initWithSigningKeypair:nocSigner
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:nocSigner
fabricId:(i + 1)
ipk:ipk];

Expand Down Expand Up @@ -124,9 +125,9 @@
mCurrentController = mControllers[name];
}

CHIPDeviceController * CHIPCommandBridge::CurrentCommissioner() { return mCurrentController; }
MTRDeviceController * CHIPCommandBridge::CurrentCommissioner() { return mCurrentController; }

CHIPDeviceController * CHIPCommandBridge::GetCommissioner(const char * identity) { return mControllers[identity]; }
MTRDeviceController * CHIPCommandBridge::GetCommissioner(const char * identity) { return mControllers[identity]; }

void CHIPCommandBridge::ShutdownCommissioner()
{
Expand All @@ -137,7 +138,7 @@
mControllers.clear();
mCurrentController = nil;

[[MatterControllerFactory sharedInstance] shutdown];
[[MTRControllerFactory sharedInstance] shutdown];
}

CHIP_ERROR CHIPCommandBridge::StartWaiting(chip::System::Clock::Timeout duration)
Expand Down Expand Up @@ -167,13 +168,13 @@
if (logString != nullptr) {
LogNSError(logString, error);
}
CHIP_ERROR err = [CHIPError errorToCHIPErrorCode:error];
CHIP_ERROR err = MTRErrorToCHIPErrorCode(error);
SetCommandExitStatus(err);
}

void CHIPCommandBridge::LogNSError(const char * logString, NSError * error)
{
CHIP_ERROR err = [CHIPError errorToCHIPErrorCode:error];
CHIP_ERROR err = MTRErrorToCHIPErrorCode(error);
if (err == CHIP_NO_ERROR) {
ChipLogProgress(chipTool, "%s: %s", logString, chip::ErrorStr(err));
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#import <CHIP/CHIP.h>
#import <Matter/Matter.h>
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface CHIPToolPersistentStorageDelegate : NSObject <CHIPPersistentStorageDelegate>
@interface CHIPToolPersistentStorageDelegate : NSObject <MTRPersistentStorageDelegate>
- (nullable NSData *)storageDataForKey:(NSString *)key;
- (BOOL)setStorageData:(NSData *)value forKey:(NSString *)key;
- (BOOL)removeStorageDataForKey:(NSString *)key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "CHIPCommandStorageDelegate.h"

#import <Matter/Matter.h>

NSString * const kCHIPToolDefaultsDomain = @"com.apple.chiptool";

id CHIPGetDomainValueForKey(NSString * domain, NSString * key)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "CHIPCommandStorageDelegate.h"
#import <CHIP/CHIP.h>
#import <Matter/Matter.h>
#include <crypto/CHIPCryptoPAL.h>

@interface CHIPToolKeypair : NSObject <CHIPKeypair>
@interface CHIPToolKeypair : NSObject <MTRKeypair>
- (BOOL)initialize;
- (NSData *)ECDSA_sign_message_raw:(NSData *)message;
- (SecKeyRef)pubkey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "CHIPToolKeypair.h"
#include <CHIP/CHIP.h>
#import <Matter/Matter.h>
#include <credentials/CHIPCert.h>
#include <crypto/CHIPCryptoPAL.h>
#include <lib/asn1/ASN1.h>
Expand Down
Loading

0 comments on commit 2f615b9

Please sign in to comment.