Skip to content

Commit

Permalink
Implement a subscribe-to-all API for Darwin. (#12851)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Apr 11, 2022
1 parent 3ff7ed9 commit 1462930
Show file tree
Hide file tree
Showing 16 changed files with 10,471 additions and 951 deletions.
12 changes: 10 additions & 2 deletions src/app/zap-templates/templates/chip/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,21 @@ function chip_available_cluster_commands(options)
* Checks whether a type is an enum for purposes of its chipType. That includes
* both spec-defined enum types and types that we map to enum types in our code.
*/
function if_chip_enum(type, options)
async function if_chip_enum(type, options)
{
if (type.toLowerCase() == 'vendor_id') {
return options.fn(this);
}

return zclHelper.if_is_enum.call(this, type, options);
let pkgId = await templateUtil.ensureZclPackageId(this);
let checkResult = await zclHelper.isEnum(this.global.db, type, pkgId);
let result;
if (checkResult != 'unknown') {
result = options.fn(this);
} else {
result = options.inverse(this);
}
return templateUtil.templatePromise(this.global, result);
}

//
Expand Down
8 changes: 4 additions & 4 deletions src/controller/java/zap-generated/CHIPClusters-JNI.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/darwin/Framework/CHIP.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
2F79A67726CE6672006377B0 /* im-client-callbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2F79A67626CE6672006377B0 /* im-client-callbacks.cpp */; };
2FD775552695557E00FF4B12 /* error-mapping.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2FD775542695557E00FF4B12 /* error-mapping.cpp */; };
5129BCFD26A9EE3300122DDF /* CHIPError.h in Headers */ = {isa = PBXBuildFile; fileRef = 5129BCFC26A9EE3300122DDF /* CHIPError.h */; settings = {ATTRIBUTES = (Public, ); }; };
513DDB862761F69300DAA01A /* CHIPAttributeTLVValueDecoder_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 513DDB852761F69300DAA01A /* CHIPAttributeTLVValueDecoder_Internal.h */; };
513DDB8A2761F6F900DAA01A /* CHIPAttributeTLVValueDecoder.mm in Sources */ = {isa = PBXBuildFile; fileRef = 513DDB892761F6F900DAA01A /* CHIPAttributeTLVValueDecoder.mm */; };
5145F81027435A5500225B60 /* CHIPListUtils_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 5145F80F27435A5400225B60 /* CHIPListUtils_internal.h */; };
51B22C1E2740CB0A008D5055 /* CHIPStructsObjc.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B22C1D2740CB0A008D5055 /* CHIPStructsObjc.h */; settings = {ATTRIBUTES = (Public, ); }; };
51B22C222740CB1D008D5055 /* CHIPCommandPayloadsObjc.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B22C212740CB1D008D5055 /* CHIPCommandPayloadsObjc.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -141,6 +143,8 @@
2F79A67626CE6672006377B0 /* im-client-callbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "im-client-callbacks.cpp"; path = "../../../app/util/im-client-callbacks.cpp"; sourceTree = "<group>"; };
2FD775542695557E00FF4B12 /* error-mapping.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "error-mapping.cpp"; path = "../../../app/util/error-mapping.cpp"; sourceTree = "<group>"; };
5129BCFC26A9EE3300122DDF /* CHIPError.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CHIPError.h; path = CHIP/CHIPError.h; sourceTree = "<group>"; };
513DDB852761F69300DAA01A /* CHIPAttributeTLVValueDecoder_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHIPAttributeTLVValueDecoder_Internal.h; sourceTree = "<group>"; };
513DDB892761F6F900DAA01A /* CHIPAttributeTLVValueDecoder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CHIPAttributeTLVValueDecoder.mm; path = "zap-generated/CHIPAttributeTLVValueDecoder.mm"; sourceTree = "<group>"; };
5145F80F27435A5400225B60 /* CHIPListUtils_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHIPListUtils_internal.h; sourceTree = "<group>"; };
51B22C1D2740CB0A008D5055 /* CHIPStructsObjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CHIPStructsObjc.h; path = "zap-generated/CHIPStructsObjc.h"; sourceTree = "<group>"; };
51B22C212740CB1D008D5055 /* CHIPCommandPayloadsObjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CHIPCommandPayloadsObjc.h; path = "zap-generated/CHIPCommandPayloadsObjc.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -226,6 +230,7 @@
1EC4CE5825CC26AB00D7304F /* CHIPGeneratedFiles */ = {
isa = PBXGroup;
children = (
513DDB892761F6F900DAA01A /* CHIPAttributeTLVValueDecoder.mm */,
51B22C292740CB47008D5055 /* CHIPCommandPayloadsObjc.mm */,
51B22C252740CB32008D5055 /* CHIPStructsObjc.mm */,
51B22C212740CB1D008D5055 /* CHIPCommandPayloadsObjc.h */,
Expand Down Expand Up @@ -268,6 +273,7 @@
B202528F2459E34F00F97062 /* CHIP */ = {
isa = PBXGroup;
children = (
513DDB852761F69300DAA01A /* CHIPAttributeTLVValueDecoder_Internal.h */,
5145F80F27435A5400225B60 /* CHIPListUtils_internal.h */,
1ED276E326C5832500547A89 /* CHIPCluster.h */,
1ED276E126C5812A00547A89 /* CHIPCluster.mm */,
Expand Down Expand Up @@ -346,6 +352,7 @@
1E16A90326B98AF100683C53 /* CHIPTestClustersObjc.h in Headers */,
2C1B027B2641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.h in Headers */,
B289D4212639C0D300D4E314 /* CHIPOnboardingPayloadParser.h in Headers */,
513DDB862761F69300DAA01A /* CHIPAttributeTLVValueDecoder_Internal.h in Headers */,
2CB7163F252F731E0026E2BB /* CHIPDevicePairingDelegate.h in Headers */,
2C222AD0255C620600E446B9 /* CHIPDevice.h in Headers */,
991DC0842475F45400C13860 /* CHIPDeviceController.h in Headers */,
Expand Down Expand Up @@ -518,6 +525,7 @@
1E857310265519AE0050A4D9 /* IMClusterCommandHandler.cpp in Sources */,
1ED276E026C57CF000547A89 /* CHIPCallbackBridge.mm in Sources */,
1E85732D26551A490050A4D9 /* util.cpp in Sources */,
513DDB8A2761F6F900DAA01A /* CHIPAttributeTLVValueDecoder.mm in Sources */,
1E85732B26551A490050A4D9 /* af-main-common.cpp in Sources */,
2FD775552695557E00FF4B12 /* error-mapping.cpp in Sources */,
1E85732A26551A490050A4D9 /* ember-compatibility-functions.cpp in Sources */,
Expand Down
31 changes: 31 additions & 0 deletions src/darwin/Framework/CHIP/CHIPAttributeTLVValueDecoder_Internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* Copyright (c) 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.
*/

#pragma once

#import <Foundation/Foundation.h>

#include <app/ConcreteAttributePath.h>
#include <lib/core/CHIPError.h>
#include <lib/core/CHIPTLV.h>

NS_ASSUME_NONNULL_BEGIN

id CHIPDecodeAttributeValue(const chip::app::ConcreteAttributePath & aPath, chip::TLV::TLVReader & aReader, CHIP_ERROR * aError);

NS_ASSUME_NONNULL_END
39 changes: 39 additions & 0 deletions src/darwin/Framework/CHIP/CHIPDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,50 @@

NS_ASSUME_NONNULL_BEGIN

typedef void (^SubscriptionEstablishedHandler)(void);

@interface CHIPDevice : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

/**
* Subscribe to receive attribute reports for everything (all endpoints, all
* clusters, all attributes, all events) on the device.
*
* reportHandler will be called any time a data update is available (with a
* non-nil "value" and nil "error"), or any time there is an error (with a nil
* "value" and non-nil "error"). If it's called with an error, that will
* terminate the subscription.
*
* The array passed to reportHandler will contain CHIPAttributeReport instances.
*
* subscriptionEstablishedHandler, if not nil, will be called once the
* subscription is established. This will be _after_ the first (priming) call
* to reportHandler.
*
* TODO: The "all events" part does not work yet.
*/
- (void)subscribeWithQueue:(dispatch_queue_t)queue
minInterval:(uint16_t)minInterval
maxInterval:(uint16_t)maxInterval
reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler
subscriptionEstablished:(SubscriptionEstablishedHandler _Nullable)subscriptionEstablishedHandler;
@end

@interface CHIPAttributePath : NSObject
@property (nonatomic, readonly, strong, nonnull) NSNumber * endpoint;
@property (nonatomic, readonly, strong, nonnull) NSNumber * cluster;
@property (nonatomic, readonly, strong, nonnull) NSNumber * attribute;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
@end

@interface CHIPAttributeReport : NSObject
@property (nonatomic, readonly, strong, nonnull) CHIPAttributePath * path;
// value is nullable because nullable attributes can have nil as value.
@property (nonatomic, readonly, strong, nullable) id value;
@end

NS_ASSUME_NONNULL_END
Expand Down
Loading

0 comments on commit 1462930

Please sign in to comment.