Skip to content

Commit eb4db0f

Browse files
Address review comments.
1 parent 2d7ea48 commit eb4db0f

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/darwin/Framework/CHIP/MTRDefines_Internal.h

+14
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,17 @@ typedef struct {} variable_hidden_by_mtr_hide;
152152
#endif
153153

154154
#define MTR_YES_NO(x) ((x) ? @"YES" : @"NO")
155+
156+
#ifdef DEBUG
157+
#define _MTR_ABSTRACT_METHOD_IMPL(message, ...) \
158+
do { \
159+
MTR_LOG_ERROR(message, __VA_ARGS__); \
160+
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@message, __VA_ARGS__] userInfo:nil]; \
161+
} while (0)
162+
#else // DEBUG
163+
#define _MTR_ABSTRACT_METHOD_IMPL(message, ...) \
164+
MTR_LOG_ERROR(message, __VA_ARGS__)
165+
#endif // DEBUG
166+
167+
#define MTR_ABSTRACT_METHOD() \
168+
_MTR_ABSTRACT_METHOD_IMPL("%@ or some ancestor must implement %@", self.class, NSStringFromSelector(_cmd))

src/darwin/Framework/CHIP/MTRDevice.mm

+5-17
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@
5555
// Disabling pending crashes
5656
#define ENABLE_CONNECTIVITY_MONITORING 0
5757

58-
#ifdef DEBUG
59-
#define MTR_REQUIRE_SUBCLASS_IMPL_PASTED(message) \
60-
MTR_LOG_ERROR(message); \
61-
NSAssert(NO, @message)
62-
#else // DEBUG
63-
#debug MTR_REQUIRE_SUBCLASS_IMPL_PASTED(message) \
64-
MTR_LOG_ERROR(message)
65-
#endif // DEBUG
66-
67-
#define MTR_REQUIRE_SUBCLASS_IMPL(selectorString) \
68-
MTR_REQUIRE_SUBCLASS_IMPL_PASTED("MTRDevice " selectorString " must be handled by subclasses")
69-
7058
@implementation MTRDeviceDelegateInfo
7159
- (instancetype)initWithDelegate:(id<MTRDeviceDelegate>)delegate queue:(dispatch_queue_t)queue interestedPathsForAttributes:(NSArray * _Nullable)interestedPathsForAttributes interestedPathsForEvents:(NSArray * _Nullable)interestedPathsForEvents
7260
{
@@ -1260,7 +1248,7 @@ - (NSUInteger)unitTestNonnullDelegateCount
12601248
attributeID:(NSNumber *)attributeID
12611249
params:(MTRReadParams * _Nullable)params
12621250
{
1263-
MTR_REQUIRE_SUBCLASS_IMPL("readAttributeWithEndpointID:clusterID:attributeID:params:");
1251+
MTR_ABSTRACT_METHOD();
12641252
return nil;
12651253
}
12661254

@@ -1271,12 +1259,12 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
12711259
expectedValueInterval:(NSNumber *)expectedValueInterval
12721260
timedWriteTimeout:(NSNumber * _Nullable)timeout
12731261
{
1274-
MTR_REQUIRE_SUBCLASS_IMPL("writeAttributeWithEndpointID:clusterID:attributeID:value:expectedValueInterval:timedWriteTimeout:");
1262+
MTR_ABSTRACT_METHOD();
12751263
}
12761264

12771265
- (NSArray<NSDictionary<NSString *, id> *> *)readAttributePaths:(NSArray<MTRAttributeRequestPath *> *)attributePaths
12781266
{
1279-
MTR_REQUIRE_SUBCLASS_IMPL("readAttributePaths:");
1267+
MTR_ABSTRACT_METHOD();
12801268
return [NSArray array];
12811269
}
12821270

@@ -1359,7 +1347,7 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
13591347
queue:(dispatch_queue_t)queue
13601348
completion:(MTRDeviceResponseHandler)completion
13611349
{
1362-
MTR_REQUIRE_SUBCLASS_IMPL("_invokeCommandWithEndpointID:clusterID:commandID:commandFields:expectedValues:expectedValueInterval:timedInvokeTimeout:serverSideProcessingTimeout:queue:completion:");
1350+
MTR_ABSTRACT_METHOD();
13631351
}
13641352

13651353
- (void)_invokeKnownCommandWithEndpointID:(NSNumber *)endpointID
@@ -1468,7 +1456,7 @@ - (NSDictionary *)_dataValueWithoutDataVersion:(NSDictionary *)attributeValue
14681456

14691457
- (NSArray<NSDictionary<NSString *, id> *> *)getAllAttributesReport
14701458
{
1471-
MTR_REQUIRE_SUBCLASS_IMPL("getAllAttributesReport");
1459+
MTR_ABSTRACT_METHOD();
14721460
return nil;
14731461
}
14741462

0 commit comments

Comments
 (0)