Skip to content

Commit

Permalink
step 1: duplicate MTRDevice
Browse files Browse the repository at this point in the history
start closing off `MTRDevice` direct use

add a note to self / reviewers

fix `newBaseDevice` / `removeExpectedValue[s]` error

ty @bzbarsky-apple

move `MTRDevice_Concrete.h` to Project scope

was Public

note to self about coming change in MTRDeviceController

move some MTRDevice utilities

to MTRDevice_Internal.h where they are at least shared between MTRDevice and MTRDevice_Concrete.

but probably they merit their own files - the header is getting heavy

add subclass-facing init to `MTRDevice`

superclass for `MTRDevice_Concrete` code was `NSObject`, but now is `MTRDevice`, which hides its `init`s.

fix build of `MTRDevice_Internal.h`

Revert "move some MTRDevice utilities"

This reverts commit ba7331f.

fix MTRDevice_Concrete block-scoped pointer types

move clamped number to utilities

remove duplicated MTRClampedNumber implementations

more `MTRClampedNumber` cleanup

duplicate MTRDeviceDelegateInfo for now

restore prematurely removed `MTRDevice` methods

move common `MTRDeviceClusterData` keys

remove now-obsolete include for CodeUtils

remove duplicate `MTRDeviceClusterData`

remove duplicate key symbols from `MTRDevice_Concrete`

remove availability annotations for nonpublic API

Restyled by whitespace

Restyled by clang-format

remove superfluous init/new signatures

available by default
  • Loading branch information
kiel-apple committed Aug 6, 2024
1 parent 7ee93d2 commit a1560ff
Show file tree
Hide file tree
Showing 8 changed files with 4,285 additions and 19 deletions.
23 changes: 9 additions & 14 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,6 @@ - (BOOL)callDelegateSynchronouslyWithBlock:(void (^)(id<MTRDeviceDelegate>))bloc
#endif
@end

NSNumber * MTRClampedNumber(NSNumber * aNumber, NSNumber * min, NSNumber * max)
{
if ([aNumber compare:min] == NSOrderedAscending) {
return min;
} else if ([aNumber compare:max] == NSOrderedDescending) {
return max;
}
return aNumber;
}

/* BEGIN DRAGONS: Note methods here cannot be renamed, and are used by private callers, do not rename, remove or modify behavior here */

@interface NSObject (MatterPrivateForInternalDragonsDoNotFeed)
Expand Down Expand Up @@ -252,10 +242,6 @@ @implementation MTRDeviceClusterData {
NSMutableDictionary<NSNumber *, MTRDeviceDataValueDictionary> * _attributes;
}

static NSString * const sDataVersionKey = @"dataVersion";
static NSString * const sAttributesKey = @"attributes";
static NSString * const sLastInitialSubscribeLatencyKey = @"lastInitialSubscribeLatency";

- (void)storeValue:(MTRDeviceDataValueDictionary _Nullable)value forAttribute:(NSNumber *)attribute
{
_attributes[attribute] = value;
Expand Down Expand Up @@ -498,6 +484,15 @@ @implementation MTRDevice {
NSMutableSet<MTRDeviceDelegateInfo *> * _delegates;
}

- (instancetype)initForSubclasses
{
if (self = [super init]) {
// nothing, as superclass of MTRDevice is NSObject
}

return self;
}

- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller
{
if (self = [super init]) {
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ - (MTRDevice *)_setupDeviceForNodeID:(NSNumber *)nodeID prefetchedClusterData:(N
{
os_unfair_lock_assert_owner(&_deviceMapLock);

// kmo: change to _Concrete
MTRDevice * deviceToReturn = [[MTRDevice alloc] initWithNodeID:nodeID controller:self];
// If we're not running, don't add the device to our map. That would
// create a cycle that nothing would break. Just return the device,
Expand Down
29 changes: 29 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
*
* Copyright (c) 2022-2023 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.
*/

#import <Foundation/Foundation.h>
#import <Matter/MTRDevice.h>

NS_ASSUME_NONNULL_BEGIN

@class MTRDeviceController;

@interface MTRDevice_Concrete : MTRDevice

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit a1560ff

Please sign in to comment.