Skip to content

Commit

Permalink
Add NS_ASSUME_NONNULL_BEGIN to MTRCallbackBridgeBase_internal. (#23849)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Mar 14, 2023
1 parent 08e9b55 commit 1085992
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/darwin/Framework/CHIP/MTRCallbackBridgeBase_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <platform/CHIPDeviceLayer.h>
#include <transport/SessionHandle.h>

NS_ASSUME_NONNULL_BEGIN

/**
* Bridge that allows invoking a given MTRActionBlock on the Matter queue, after
* communication with the device in question has been established, as far as we
Expand All @@ -35,11 +37,7 @@
class MTRCallbackBridgeBase {
};

// TODO: ADD NS_ASSUME_NONNULL_BEGIN to this header. When that happens, note
// that in MTRActionBlock the two callback pointers are nonnull and the two
// arguments of MTRResponseHandler are both nullable.

typedef void (^MTRResponseHandler)(id value, NSError * error);
typedef void (^MTRResponseHandler)(id _Nullable value, NSError * _Nullable error);
typedef void (*MTRErrorCallback)(void * context, CHIP_ERROR error);

/**
Expand Down Expand Up @@ -85,7 +83,7 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
* Construct a callback bridge, which can then have DispatchAction() called
* on it.
*/
MTRCallbackBridge(dispatch_queue_t queue, MTRResponseHandler handler, MTRActionBlock action, T OnSuccessFn)
MTRCallbackBridge(dispatch_queue_t queue, MTRResponseHandler handler, MTRActionBlock _Nonnull action, T OnSuccessFn)
: mQueue(queue)
, mHandler(handler)
, mAction(action)
Expand Down Expand Up @@ -130,7 +128,7 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
* Does not attempt to establish any sessions to devices. Must not be used
* with any action blocks that need a session.
*/
void DispatchLocalAction(MTRLocalActionBlock action)
void DispatchLocalAction(MTRLocalActionBlock _Nonnull action)
{
LogRequestStart();

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

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

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

static void DispatchSuccess(void * context, id value) { DispatchCallbackResult(context, nil, value); }
static void DispatchSuccess(void * context, id _Nullable value) { DispatchCallbackResult(context, nil, value); }

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

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

private:
static void DispatchCallbackResult(void * context, NSError * error, id value)
static void DispatchCallbackResult(void * context, NSError * _Nullable error, id _Nullable value)
{
MTRCallbackBridge * callbackBridge = static_cast<MTRCallbackBridge *>(context);
if (!callbackBridge) {
Expand All @@ -267,7 +265,7 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
}

MTRResponseHandler mHandler;
MTRActionBlock mAction;
MTRActionBlock _Nullable mAction;
bool mKeepAlive = false;

T mSuccess;
Expand All @@ -277,3 +275,5 @@ template <class T> class MTRCallbackBridge : public MTRCallbackBridgeBase {
NSDate * mRequestTime;
NSString * mCookie;
};

NS_ASSUME_NONNULL_END

0 comments on commit 1085992

Please sign in to comment.