Skip to content

Commit 7762024

Browse files
committed
remove overdesign callback
1 parent 625293e commit 7762024

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

examples/chip-tool/commands/common/CHIPCommand.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,12 @@ void CHIPCommand::ExecuteDeferredCleanups(intptr_t ignored)
655655
sDeferredCleanups.clear();
656656
}
657657

658-
void CHIPCommand::RegisterOnCheckInCompleteCallback(CheckInCompleteCallback * handler)
658+
void CHIPCommand::SetOnCheckInCompleteCallback(CheckInCompleteCallback * handler)
659659
{
660-
sCheckInDelegate.RegisterOnCheckInCompleteCallback(handler);
660+
sCheckInDelegate.SetOnCheckInCompleteCallback(handler);
661661
}
662662

663-
void CHIPCommand::UnregisterOnCheckInCompleteCallback(CheckInCompleteCallback * handler)
663+
void CHIPCommand::UnsetOnCheckInCompleteCallback()
664664
{
665-
sCheckInDelegate.UnregisterOnCheckInCompleteCallback(handler);
665+
sCheckInDelegate.UnsetOnCheckInCompleteCallback();
666666
}

examples/chip-tool/commands/common/CHIPCommand.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ class CHIPCommand : public Command
180180

181181
ChipDeviceCommissioner & GetCommissioner(std::string identity);
182182

183-
static void RegisterOnCheckInCompleteCallback(CheckInCompleteCallback * handler);
183+
static void SetOnCheckInCompleteCallback(CheckInCompleteCallback * handler);
184184

185-
static void UnregisterOnCheckInCompleteCallback(CheckInCompleteCallback * handler);
185+
static void UnsetOnCheckInCompleteCallback();
186186

187187
private:
188188
CHIP_ERROR MaybeSetUpStack();

examples/chip-tool/commands/common/ChipToolCheckInDelegate.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CHIP_ERROR ChipToolCheckInDelegate::Init(ICDClientStorage * storage, Interaction
2929
{
3030
VerifyOrReturnError(storage != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
3131
VerifyOrReturnError(mpStorage == nullptr, CHIP_ERROR_INCORRECT_STATE);
32+
VerifyOrReturnError(engine != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
3233
mpStorage = storage;
3334
mpImEngine = engine;
3435
return CHIP_NO_ERROR;
@@ -39,9 +40,9 @@ void ChipToolCheckInDelegate::OnCheckInComplete(const ICDClientInfo & clientInfo
3940
ChipLogProgress(
4041
ICD, "Check In Message processing complete: start_counter=%" PRIu32 " offset=%" PRIu32 " nodeid=" ChipLogFormatScopedNodeId,
4142
clientInfo.start_icd_counter, clientInfo.offset, ChipLogValueScopedNodeId(clientInfo.peer_node));
42-
for (auto handler : mCheckInCompleteCallbacks)
43+
if (mpCheckInCompleteCallbacks != nullptr)
4344
{
44-
handler->OnCheckInComplete(clientInfo);
45+
mpCheckInCompleteCallbacks->OnCheckInComplete(clientInfo);
4546
}
4647
}
4748

@@ -83,12 +84,12 @@ void ChipToolCheckInDelegate::OnKeyRefreshDone(RefreshKeySender * refreshKeySend
8384
}
8485
}
8586

86-
void ChipToolCheckInDelegate::RegisterOnCheckInCompleteCallback(CheckInCompleteCallback * handler)
87+
void ChipToolCheckInDelegate::SetOnCheckInCompleteCallback(CheckInCompleteCallback * handler)
8788
{
88-
chip::DeviceLayer::SystemLayer().ScheduleLambda([this, handler]() { mCheckInCompleteCallbacks.insert(handler); });
89+
mpCheckInCompleteCallbacks = handler;
8990
}
9091

91-
void ChipToolCheckInDelegate::UnregisterOnCheckInCompleteCallback(CheckInCompleteCallback * handler)
92+
void ChipToolCheckInDelegate::UnsetOnCheckInCompleteCallback()
9293
{
93-
chip::DeviceLayer::SystemLayer().ScheduleLambda([this, handler]() { mCheckInCompleteCallbacks.insert(handler); });
94+
mpCheckInCompleteCallbacks = nullptr;
9495
}

examples/chip-tool/commands/common/ChipToolCheckInDelegate.h

+9-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CheckInCompleteCallback
3232
/**
3333
* @brief Callback used to let the application know that a check-in message was received and validated.
3434
*
35-
* The callback will be executed in CHIP main loop. Implementations avoid blocking in this callback.
35+
* The callback will be executed in CHIP main loop. Implementations should avoid blocking operations in this callback.
3636
*
3737
* @param[in] clientInfo - ICDClientInfo object representing the state associated with the
3838
* node that sent the check-in message.
@@ -51,26 +51,24 @@ class ChipToolCheckInDelegate : public chip::app::CheckInDelegate
5151
void OnKeyRefreshDone(chip::app::RefreshKeySender * refreshKeySender, CHIP_ERROR error) override;
5252

5353
/**
54-
* @brief Reigsters a callback when the check-in completes.
54+
* @brief Sets a callback for when the Check-In processing completes.
5555
*
56-
* The registeration will be processed inside CHIP main loop.
56+
* This method does not consider the race condition that the callback is changed during OnCheckInComplete.
5757
*
58-
* @param[in] handler - A pointer to CheckInCompleteCallback to register.
58+
* @param[in] handler - A pointer to the CheckInCompleteCallback to register.
5959
*/
60-
void RegisterOnCheckInCompleteCallback(CheckInCompleteCallback * handler);
60+
void SetOnCheckInCompleteCallback(CheckInCompleteCallback * handler);
6161

6262
/**
63-
* @brief Unreigsters a callback when the check-in completes.
63+
* @brief Unsets the callback for when the Check-In processing completes.
6464
*
65-
* The unregisteration will be processed inside CHIP main loop.
66-
*
67-
* @param[in] handler - A pointer to CheckInCompleteCallback to unregister.
65+
* This method does not consider the race condition that the callback is changed during OnCheckInComplete.
6866
*/
69-
void UnregisterOnCheckInCompleteCallback(CheckInCompleteCallback * handler);
67+
void UnsetOnCheckInCompleteCallback();
7068

7169
private:
7270
chip::app::ICDClientStorage * mpStorage = nullptr;
7371
chip::app::InteractionModelEngine * mpImEngine = nullptr;
7472

75-
std::set<CheckInCompleteCallback *> mCheckInCompleteCallbacks;
73+
CheckInCompleteCallback * mpCheckInCompleteCallbacks;
7674
};

0 commit comments

Comments
 (0)