Skip to content

Commit

Permalink
Add ReadClient and ReaderHandler and interactionModelDelegate
Browse files Browse the repository at this point in the history
Problem:
Need read client to send IM read request and process report and read handler to process
read request, need interaction model delegate to notify zcl the actions
in corresponse for particular IM callback.

Summary of Changes:
-- Add read client to send IM read request and process report.
-- Add read handler to process read request
-- Add interaction model delgate to notify when each IM event stream is received and
all reports have been received
  • Loading branch information
yunhanw-google committed Mar 10, 2021
1 parent 312438f commit b8daefd
Show file tree
Hide file tree
Showing 14 changed files with 1,329 additions and 181 deletions.
2 changes: 2 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ static_library("app") {
"MessageDef/ReportData.h",
"MessageDef/StatusElement.cpp",
"MessageDef/StatusElement.h",
"ReadClient.cpp",
"ReadHandler.cpp",
"decoder.cpp",
"encoder.cpp",
]
Expand Down
2 changes: 1 addition & 1 deletion src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CHIP_ERROR CommandHandler::SendCommandResponse()
err = FinalizeCommandsMessage();
SuccessOrExit(err);

VerifyOrExit(mpExchangeCtx != NULL, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::InvokeCommandResponse, std::move(mCommandMessageBuf),
Messaging::SendFlags(Messaging::SendMessageFlags::kNone));
SuccessOrExit(err);
Expand Down
1 change: 0 additions & 1 deletion src/app/CommandSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ void CommandSender::OnMessageReceived(Messaging::ExchangeContext * apExchangeCon

exit:
Reset();
return;
}

void CommandSender::OnResponseTimeout(Messaging::ExchangeContext * apExchangeContext)
Expand Down
118 changes: 118 additions & 0 deletions src/app/InteractionModelDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* 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.
*/

/**
* @file
* This file defines the classes corresponding to CHIP Interaction Model Delegate.
*
*/

#pragma once

#include <core/CHIPCore.h>
#include <messaging/ExchangeContext.h>
#include <system/SystemPacketBuffer.h>

namespace chip {
namespace app {

struct EventPathParams;

/**
* @brief
* This class provides a skeleton for the callback functions. The functions will be
* called by InteractionModel on specific CallbackId. If the user of InteractionModel
* is interested in receiving these callbacks, they can specialize this class and handle
* each CallbackId in their implementation of this class.
*/
class InteractionModelDelegate
{
public:
virtual ~InteractionModelDelegate() {}

// Interaction Model would use the below callbackID as discriminator and notify the zcl/app the particular interaction
// has completed or is happening or need more things from upper layer via InParam and OutParam
// The below callbacks may or may not be necessary for upper zcl, once the zcl integration is complete, we will revisit these
enum class CallbackId
{
// Read Client
/**
* Sent when it is ready to send the ReadRequest. The
* application is expected to fill in the attribute/event paths that it wants to
* read/subscribe to.
*/
kReadRequestPrepareNeeded,
// IM notify zcl events can be further processed in app.
kEventStreamReceived,

// IM notify zcl all reports have been processed.
kReportProcessed,
};

/**
* Incoming parameters sent with callback generated directly from this component
*
*/
union InParam
{
InParam() { Clear(); }

void Clear(void) { memset(this, 0, sizeof(*this)); }

struct
{
// ExchangeContext managed externally and should not be closed by zcl processing.
Messaging::ExchangeContext * exchangeContext;
// EventList tlv reader, upper layer can process event list.
chip::TLV::TLVReader * reader;
} mEventStreamReceived;
};

/**
* Outgoing parameters sent with CallbackId generated directly from this component
*
*/
union OutParam
{
OutParam() { Clear(); }
void Clear(void) { memset(this, 0, sizeof(*this)); }

struct
{
EventPathParams * eventPathParamsList; //< Pointer to a list of event path parameter ZCL are intereted in
size_t eventPathParamsListSize; //< Number of event paths in mpEventPathList
uint64_t eventNumber; //< A event number it has already to limit the set of retrieved events on the server for
// optimization purposes
} mReadRequestPrepareNeeded;
};

/**
* @brief Set the callback function
* @param[in] aCallbackId A function pointer for particular call back
* @param[in] aInParam A const reference to the input parameter for this CallbackId
* @param[out] aOutParam A reference to the output parameter for this CallbackId
*/
virtual void HandleIMCallBack(CallbackId aCallbackId, const InParam & aInParam, OutParam & aOutParam) = 0;

void DefaultCallbackIdHandler(CallbackId aCallbackId, const InParam & aInParam, OutParam & aOutParam)
{
ChipLogDetail(DataManagement, "%s CallbackId: %d", __func__, aCallbackId);
}
};

} // namespace app
} // namespace chip
Loading

0 comments on commit b8daefd

Please sign in to comment.