Skip to content

Commit 3301790

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Add NS_ASSUME_NONNULL_BEGIN to MTRCallbackBridgeBase_internal. (#23849)
This way we can explicitly annotate which bits might be null. For some of the block pointers we apparently need to explicitly specify _Nonnull even with NS_ASSUME_NONNULL_BEGIN. Maybe because of the templating involved.
1 parent 0e1c28e commit 3301790

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/darwin/Framework/CHIP/MTRCallbackBridgeBase_internal.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <platform/CHIPDeviceLayer.h>
2828
#include <transport/SessionHandle.h>
2929

30+
NS_ASSUME_NONNULL_BEGIN
31+
3032
/**
3133
* Bridge that allows invoking a given MTRActionBlock on the Matter queue, after
3234
* communication with the device in question has been established, as far as we
@@ -35,11 +37,7 @@
3537
class MTRCallbackBridgeBase {
3638
};
3739

38-
// TODO: ADD NS_ASSUME_NONNULL_BEGIN to this header. When that happens, note
39-
// that in MTRActionBlock the two callback pointers are nonnull and the two
40-
// arguments of MTRResponseHandler are both nullable.
41-
42-
typedef void (^MTRResponseHandler)(id value, NSError * error);
40+
typedef void (^MTRResponseHandler)(id _Nullable value, NSError * _Nullable error);
4341
typedef void (*MTRErrorCallback)(void * context, CHIP_ERROR error);
4442

4543
/**
@@ -85,7 +83,7 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
8583
* Construct a callback bridge, which can then have DispatchAction() called
8684
* on it.
8785
*/
88-
MTRCallbackBridge(dispatch_queue_t queue, MTRResponseHandler handler, MTRActionBlock action, T OnSuccessFn)
86+
MTRCallbackBridge(dispatch_queue_t queue, MTRResponseHandler handler, MTRActionBlock _Nonnull action, T OnSuccessFn)
8987
: mQueue(queue)
9088
, mHandler(handler)
9189
, mAction(action)
@@ -130,7 +128,7 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
130128
* Does not attempt to establish any sessions to devices. Must not be used
131129
* with any action blocks that need a session.
132130
*/
133-
void DispatchLocalAction(MTRLocalActionBlock action)
131+
void DispatchLocalAction(MTRLocalActionBlock _Nonnull action)
134132
{
135133
LogRequestStart();
136134

@@ -187,8 +185,8 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
187185
ChipLogDetail(Controller, "%s", mCookie.UTF8String);
188186
}
189187

190-
void MaybeDoAction(
191-
chip::Messaging::ExchangeManager * exchangeManager, const chip::Optional<chip::SessionHandle> & session, NSError * error)
188+
void MaybeDoAction(chip::Messaging::ExchangeManager * _Nullable exchangeManager,
189+
const chip::Optional<chip::SessionHandle> & session, NSError * _Nullable error)
192190
{
193191
// Make sure we don't hold on to our action longer than we have to.
194192
auto action = mAction;
@@ -213,7 +211,7 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
213211

214212
static void OnFailureFn(void * context, CHIP_ERROR error) { DispatchFailure(context, [MTRError errorForCHIPErrorCode:error]); }
215213

216-
static void DispatchSuccess(void * context, id value) { DispatchCallbackResult(context, nil, value); }
214+
static void DispatchSuccess(void * context, id _Nullable value) { DispatchCallbackResult(context, nil, value); }
217215

218216
static void DispatchFailure(void * context, NSError * error) { DispatchCallbackResult(context, error, nil); }
219217

@@ -241,7 +239,7 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
241239
dispatch_queue_t mQueue;
242240

243241
private:
244-
static void DispatchCallbackResult(void * context, NSError * error, id value)
242+
static void DispatchCallbackResult(void * context, NSError * _Nullable error, id _Nullable value)
245243
{
246244
MTRCallbackBridge * callbackBridge = static_cast<MTRCallbackBridge *>(context);
247245
if (!callbackBridge) {
@@ -267,7 +265,7 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
267265
}
268266

269267
MTRResponseHandler mHandler;
270-
MTRActionBlock mAction;
268+
MTRActionBlock _Nullable mAction;
271269
bool mKeepAlive = false;
272270

273271
T mSuccess;
@@ -277,3 +275,5 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
277275
NSDate * mRequestTime;
278276
NSString * mCookie;
279277
};
278+
279+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)