Skip to content

Commit 2d7ea48

Browse files
Clean up the "subclasses must implement this" machinery in MTRDevice.
We had a lot of copy/paste that we can factor out.
1 parent 2396bb4 commit 2d7ea48

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+17-30
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@
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+
5870
@implementation MTRDeviceDelegateInfo
5971
- (instancetype)initWithDelegate:(id<MTRDeviceDelegate>)delegate queue:(dispatch_queue_t)queue interestedPathsForAttributes:(NSArray * _Nullable)interestedPathsForAttributes interestedPathsForEvents:(NSArray * _Nullable)interestedPathsForEvents
6072
{
@@ -1248,12 +1260,7 @@ - (NSUInteger)unitTestNonnullDelegateCount
12481260
attributeID:(NSNumber *)attributeID
12491261
params:(MTRReadParams * _Nullable)params
12501262
{
1251-
#define MTRDeviceErrorStr "MTRDevice readAttributeWithEndpointID:clusterID:attributeID:params: must be handled by subclasses"
1252-
MTR_LOG_ERROR(MTRDeviceErrorStr);
1253-
#ifdef DEBUG
1254-
NSAssert(NO, @MTRDeviceErrorStr);
1255-
#endif // DEBUG
1256-
#undef MTRDeviceErrorStr
1263+
MTR_REQUIRE_SUBCLASS_IMPL("readAttributeWithEndpointID:clusterID:attributeID:params:");
12571264
return nil;
12581265
}
12591266

@@ -1264,22 +1271,12 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
12641271
expectedValueInterval:(NSNumber *)expectedValueInterval
12651272
timedWriteTimeout:(NSNumber * _Nullable)timeout
12661273
{
1267-
#define MTRDeviceErrorStr "MTRDevice writeAttributeWithEndpointID:clusterID:attributeID:value:expectedValueInterval:timedWriteTimeout: must be handled by subclasses"
1268-
MTR_LOG_ERROR(MTRDeviceErrorStr);
1269-
#ifdef DEBUG
1270-
NSAssert(NO, @MTRDeviceErrorStr);
1271-
#endif // DEBUG
1272-
#undef MTRDeviceErrorStr
1274+
MTR_REQUIRE_SUBCLASS_IMPL("writeAttributeWithEndpointID:clusterID:attributeID:value:expectedValueInterval:timedWriteTimeout:");
12731275
}
12741276

12751277
- (NSArray<NSDictionary<NSString *, id> *> *)readAttributePaths:(NSArray<MTRAttributeRequestPath *> *)attributePaths
12761278
{
1277-
#define MTRDeviceErrorStr "MTRDevice readAttributePaths: must be handled by subclasses"
1278-
MTR_LOG_ERROR(MTRDeviceErrorStr);
1279-
#ifdef DEBUG
1280-
NSAssert(NO, @MTRDeviceErrorStr);
1281-
#endif // DEBUG
1282-
#undef MTRDeviceErrorStr
1279+
MTR_REQUIRE_SUBCLASS_IMPL("readAttributePaths:");
12831280
return [NSArray array];
12841281
}
12851282

@@ -1362,12 +1359,7 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
13621359
queue:(dispatch_queue_t)queue
13631360
completion:(MTRDeviceResponseHandler)completion
13641361
{
1365-
#define MTRDeviceErrorStr "MTRDevice _invokeCommandWithEndpointID: must be handled by subclasses"
1366-
MTR_LOG_ERROR(MTRDeviceErrorStr);
1367-
#ifdef DEBUG
1368-
NSAssert(NO, @MTRDeviceErrorStr);
1369-
#endif // DEBUG
1370-
#undef MTRDeviceErrorStr
1362+
MTR_REQUIRE_SUBCLASS_IMPL("_invokeCommandWithEndpointID:clusterID:commandID:commandFields:expectedValues:expectedValueInterval:timedInvokeTimeout:serverSideProcessingTimeout:queue:completion:");
13711363
}
13721364

13731365
- (void)_invokeKnownCommandWithEndpointID:(NSNumber *)endpointID
@@ -1476,12 +1468,7 @@ - (NSDictionary *)_dataValueWithoutDataVersion:(NSDictionary *)attributeValue
14761468

14771469
- (NSArray<NSDictionary<NSString *, id> *> *)getAllAttributesReport
14781470
{
1479-
#define MTRDeviceErrorStr "MTRDevice getAllAttributesReport must be handled by subclasses that support it"
1480-
MTR_LOG_ERROR(MTRDeviceErrorStr);
1481-
#ifdef DEBUG
1482-
NSAssert(NO, @MTRDeviceErrorStr);
1483-
#endif // DEBUG
1484-
#undef MTRDeviceErrorStr
1471+
MTR_REQUIRE_SUBCLASS_IMPL("getAllAttributesReport");
14851472
return nil;
14861473
}
14871474

0 commit comments

Comments
 (0)