-
Notifications
You must be signed in to change notification settings - Fork 0
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
Im/record callback in command sender #2
base: master
Are you sure you want to change the base?
Changes from all commits
3932f02
c318fd5
3356783
323ad8a
4038717
0394902
5905256
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <ClusterObjectCommandSenderCallback.h> | ||
|
||
#include <app/CommandSender.h> | ||
#include <app/common/StatusElement.h> | ||
#include <app/data-model/Decode.h> | ||
|
||
#include <functional> | ||
|
||
namespace chip { | ||
namespace app { | ||
template <> | ||
void ClusterObjectCommandSenderCallback<void>::OnResponse(const CommandSender * apCommandSender, | ||
const CommandPath::Type & aCommandPath, TLV::TLVReader & aReader) | ||
{ | ||
mOnResponse(apCommandSender, aCommandPath); | ||
} | ||
|
||
} // namespace app | ||
} // namespace chip |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,85 @@ | ||||||
/* | ||||||
* | ||||||
* Copyright (c) 2021 Project CHIP Authors | ||||||
* All rights reserved. | ||||||
* | ||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
* you may not use this file except in compliance with the License. | ||||||
* You may obtain a copy of the License at | ||||||
* | ||||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||||
* | ||||||
* Unless required by applicable law or agreed to in writing, software | ||||||
* distributed under the License is distributed on an "AS IS" BASIS, | ||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
* See the License for the specific language governing permissions and | ||||||
* limitations under the License. | ||||||
*/ | ||||||
|
||||||
#pragma once | ||||||
|
||||||
#include <app/CommandSender.h> | ||||||
#include <app/common/StatusElement.h> | ||||||
#include <app/data-model/Decode.h> | ||||||
|
||||||
#include <functional> | ||||||
|
||||||
namespace chip { | ||||||
namespace app { | ||||||
|
||||||
template <typename ClusterObjectT> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
class ClusterObjectCommandSenderCallback final : public CommandSender::Delegate | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still seems like a mouthful...any other name suggestions that are less wordy? |
||||||
{ | ||||||
public: | ||||||
template <typename ClusterObjectT2> | ||||||
using OnResponseCallbackType<ClusterObjectT2> = | ||||||
std::function<void(const CommandSender *, const CommandPath::Type &, const ClusterObjectT2 &)>; | ||||||
|
||||||
template <> | ||||||
using OnResponseCallbackType<void> = std::function<void(const CommandSender *, const CommandPath::Type &)>; | ||||||
|
||||||
using OnErrorCallbackTyoe = | ||||||
std::function<void(const CommandSender *, Protocols::InteractionModel::Status aIMStatus, CHIP_ERROR aError)>; | ||||||
|
||||||
using OnFinalCallbackType = std::function<void(CommandSender *, ClusterObjectCommandSenderCallback<ClusterObjectT> *)>; | ||||||
|
||||||
ClusterObjectCommandSenderCallback(OnResponseCallbackType<ClusterObjectT> aOnResponse, OnErrorCallbackTyoe aOnError, | ||||||
OnFinalCallbackType aOnFinal) : | ||||||
mOnResponse(aOnResponse), | ||||||
mOnError(aOnError), mOnFinal(aOnFinal) | ||||||
{} | ||||||
|
||||||
void OnResponse(const CommandSender * apCommandSender, const CommandPath::Type & aCommandPath, TLV::TLVReader & aReader); | ||||||
void OnError(const CommandSender * apCommandSender, Protocols::InteractionModel::Status aIMStatus, CHIP_ERROR aError) | ||||||
{ | ||||||
mOnError(apCommandSender, aIMStatus, aError); | ||||||
} | ||||||
void OnFinal(CommandSender * apCommandSender) { mOnFinal(apCommandSender, this); } | ||||||
|
||||||
private: | ||||||
OnResponseCallbackType<ClusterObjectT> mOnResponse; | ||||||
OnErrorCallbackTyoe mOnError; | ||||||
OnFinalCallbackType mOnFinal; | ||||||
}; | ||||||
|
||||||
template <typename ClusterObjectT> | ||||||
void ClusterObjectCommandSenderCallback<ClusterObjectT>::OnResponse(const CommandSender * apCommandSender, | ||||||
const CommandPath::Type & aCommandPath, | ||||||
TLV::TLVReader & aReader) | ||||||
{ | ||||||
ClusterObjectT response; | ||||||
CHIP_ERROR err = DataModel::Decode(aReader, response); | ||||||
if (err != CHIP_NO_ERROR) | ||||||
{ | ||||||
mOnError(err); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the other two arguments? |
||||||
return; | ||||||
} | ||||||
mOnResponse(apCommandSender, aCommandPath, response); | ||||||
} | ||||||
|
||||||
template <> | ||||||
void ClusterObjectCommandSenderCallback<void>::OnResponse(const CommandSender * apCommandSender, | ||||||
const CommandPath::Type & aCommandPath, TLV::TLVReader & aReader); | ||||||
|
||||||
} // namespace app | ||||||
} // namespace chip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a brief description of what this class does.