Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up the "subclasses must implement this" machinery in MTRDevice. #35657

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/darwin/Framework/CHIP/MTRDefines_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,17 @@ typedef struct {} variable_hidden_by_mtr_hide;
#endif

#define MTR_YES_NO(x) ((x) ? @"YES" : @"NO")

#ifdef DEBUG
#define _MTR_ABSTRACT_METHOD_IMPL(message, ...) \
do { \
MTR_LOG_ERROR(message, __VA_ARGS__); \
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@message, __VA_ARGS__] userInfo:nil]; \
} while (0)
#else // DEBUG
#define _MTR_ABSTRACT_METHOD_IMPL(message, ...) \
MTR_LOG_ERROR(message, __VA_ARGS__)
#endif // DEBUG

#define MTR_ABSTRACT_METHOD() \
_MTR_ABSTRACT_METHOD_IMPL("%@ or some ancestor must implement %@", self.class, NSStringFromSelector(_cmd))
35 changes: 5 additions & 30 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1248,12 +1248,7 @@ - (NSUInteger)unitTestNonnullDelegateCount
attributeID:(NSNumber *)attributeID
params:(MTRReadParams * _Nullable)params
{
#define MTRDeviceErrorStr "MTRDevice readAttributeWithEndpointID:clusterID:attributeID:params: must be handled by subclasses"
MTR_LOG_ERROR(MTRDeviceErrorStr);
#ifdef DEBUG
NSAssert(NO, @MTRDeviceErrorStr);
#endif // DEBUG
#undef MTRDeviceErrorStr
MTR_ABSTRACT_METHOD();
return nil;
}

Expand All @@ -1264,22 +1259,12 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
expectedValueInterval:(NSNumber *)expectedValueInterval
timedWriteTimeout:(NSNumber * _Nullable)timeout
{
#define MTRDeviceErrorStr "MTRDevice writeAttributeWithEndpointID:clusterID:attributeID:value:expectedValueInterval:timedWriteTimeout: must be handled by subclasses"
MTR_LOG_ERROR(MTRDeviceErrorStr);
#ifdef DEBUG
NSAssert(NO, @MTRDeviceErrorStr);
#endif // DEBUG
#undef MTRDeviceErrorStr
MTR_ABSTRACT_METHOD();
}

- (NSArray<NSDictionary<NSString *, id> *> *)readAttributePaths:(NSArray<MTRAttributeRequestPath *> *)attributePaths
{
#define MTRDeviceErrorStr "MTRDevice readAttributePaths: must be handled by subclasses"
MTR_LOG_ERROR(MTRDeviceErrorStr);
#ifdef DEBUG
NSAssert(NO, @MTRDeviceErrorStr);
#endif // DEBUG
#undef MTRDeviceErrorStr
MTR_ABSTRACT_METHOD();
return [NSArray array];
}

Expand Down Expand Up @@ -1362,12 +1347,7 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
queue:(dispatch_queue_t)queue
completion:(MTRDeviceResponseHandler)completion
{
#define MTRDeviceErrorStr "MTRDevice _invokeCommandWithEndpointID: must be handled by subclasses"
MTR_LOG_ERROR(MTRDeviceErrorStr);
#ifdef DEBUG
NSAssert(NO, @MTRDeviceErrorStr);
#endif // DEBUG
#undef MTRDeviceErrorStr
MTR_ABSTRACT_METHOD();
}

- (void)_invokeKnownCommandWithEndpointID:(NSNumber *)endpointID
Expand Down Expand Up @@ -1476,12 +1456,7 @@ - (NSDictionary *)_dataValueWithoutDataVersion:(NSDictionary *)attributeValue

- (NSArray<NSDictionary<NSString *, id> *> *)getAllAttributesReport
{
#define MTRDeviceErrorStr "MTRDevice getAllAttributesReport must be handled by subclasses that support it"
MTR_LOG_ERROR(MTRDeviceErrorStr);
#ifdef DEBUG
NSAssert(NO, @MTRDeviceErrorStr);
#endif // DEBUG
#undef MTRDeviceErrorStr
MTR_ABSTRACT_METHOD();
return nil;
}

Expand Down
Loading