Skip to content

Commit

Permalink
[im] Land IM AttributeWriting protocol (#7994)
Browse files Browse the repository at this point in the history
* [im] Land IM WriteRequest message

* ember code cleanup

* Run Codegen
  • Loading branch information
erjiaqing authored and pull[bot] committed Aug 11, 2021
1 parent 18f38c5 commit 1719714
Show file tree
Hide file tree
Showing 29 changed files with 1,299 additions and 938 deletions.
47 changes: 47 additions & 0 deletions examples/pump-app/pump-common/gen/CHIPClientCallbacks.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/pump-app/pump-common/gen/CHIPClientCallbacks.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/pump-app/pump-common/gen/CHIPClusters.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 6 additions & 19 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ CHIP_ERROR InteractionModelEngine::NewCommandSender(CommandSender ** const apCom
return CHIP_ERROR_NO_MEMORY;
}

CHIP_ERROR InteractionModelEngine::NewReadClient(ReadClient ** const apReadClient, intptr_t aAppIdentifier)
CHIP_ERROR InteractionModelEngine::NewReadClient(ReadClient ** const apReadClient, uint64_t aAppIdentifier)
{
CHIP_ERROR err = CHIP_ERROR_NO_MEMORY;

Expand All @@ -158,9 +158,9 @@ CHIP_ERROR InteractionModelEngine::NewReadClient(ReadClient ** const apReadClien
return err;
}

CHIP_ERROR InteractionModelEngine::NewWriteClient(WriteClient ** const apWriteClient)
CHIP_ERROR InteractionModelEngine::NewWriteClient(WriteClientHandle & apWriteClient, uint64_t aApplicationIdentifier)
{
*apWriteClient = nullptr;
apWriteClient.SetWriteClient(nullptr);

for (auto & writeClient : mWriteClients)
{
Expand All @@ -169,8 +169,8 @@ CHIP_ERROR InteractionModelEngine::NewWriteClient(WriteClient ** const apWriteCl
continue;
}

ReturnErrorOnFailure(writeClient.Init(mpExchangeMgr, mpDelegate));
*apWriteClient = &writeClient;
ReturnLogErrorOnFailure(writeClient.Init(mpExchangeMgr, mpDelegate, aApplicationIdentifier));
apWriteClient.SetWriteClient(&writeClient);
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -321,7 +321,7 @@ CHIP_ERROR InteractionModelEngine::SendReadRequest(NodeId aNodeId, FabricIndex a
EventPathParams * apEventPathParamsList, size_t aEventPathParamsListSize,
AttributePathParams * apAttributePathParamsList,
size_t aAttributePathParamsListSize, EventNumber aEventNumber,
intptr_t aAppIdentifier)
uint64_t aAppIdentifier)
{
ReadClient * client = nullptr;
CHIP_ERROR err = CHIP_NO_ERROR;
Expand All @@ -335,19 +335,6 @@ CHIP_ERROR InteractionModelEngine::SendReadRequest(NodeId aNodeId, FabricIndex a
return err;
}

CHIP_ERROR __attribute__((weak))
WriteSingleClusterData(ClusterInfo & aClusterInfo, TLV::TLVReader & aReader, WriteHandler * apWriteHandler)
{
ChipLogDetail(DataManagement,
"Received Cluster Attribute: Cluster=" ChipLogFormatMEI " NodeId=0x" ChipLogFormatX64 " Endpoint=%" PRIx16
" FieldId=%" PRIx32 " ListIndex=%" PRIx16,
ChipLogValueMEI(aClusterInfo.mClusterId), ChipLogValueX64(aClusterInfo.mNodeId), aClusterInfo.mEndpointId,
aClusterInfo.mFieldId, aClusterInfo.mListIndex);
ChipLogError(DataManagement,
"Default WriteSingleClusterData is called, this should be replaced by actual dispatched for cluster");
return CHIP_NO_ERROR;
}

uint16_t InteractionModelEngine::GetReadClientArrayIndex(const ReadClient * const apReadClient) const
{
return static_cast<uint16_t>(apReadClient - mReadClients);
Expand Down
10 changes: 7 additions & 3 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,22 @@ class InteractionModelEngine : public Messaging::ExchangeDelegate
CHIP_ERROR SendReadRequest(NodeId aNodeId, FabricIndex aFabricIndex, SecureSessionHandle * apSecureSession,
EventPathParams * apEventPathParamsList, size_t aEventPathParamsListSize,
AttributePathParams * apAttributePathParamsList, size_t aAttributePathParamsListSize,
EventNumber aEventNumber, intptr_t aAppIdentifier = 0);
EventNumber aEventNumber, uint64_t aAppIdentifier = 0);

/**
* Retrieve a WriteClient that the SDK consumer can use to send a write. If the call succeeds,
* see WriteClient documentation for lifetime handling.
*
* The Write interaction is more like Invoke interaction (cluster specific commands) since it will include cluster specific
* payload, and may have the need to encode non-scalar values (like structs and arrays). Thus we use WriteClientHandle to
* prevent user's code from leaking WriteClients.
*
* @param[out] apWriteClient A pointer to the WriteClient object.
*
* @retval #CHIP_ERROR_NO_MEMORY If there is no WriteClient available
* @retval #CHIP_NO_ERROR On success.
*/
CHIP_ERROR NewWriteClient(WriteClient ** const apWriteClient);
CHIP_ERROR NewWriteClient(WriteClientHandle & apWriteClient, uint64_t aApplicationIdentifier = 0);

/**
* Get read client index in mReadClients
Expand Down Expand Up @@ -177,7 +181,7 @@ class InteractionModelEngine : public Messaging::ExchangeDelegate
* @retval #CHIP_ERROR_INCORRECT_STATE If there is no ReadClient available
* @retval #CHIP_NO_ERROR On success.
*/
CHIP_ERROR NewReadClient(ReadClient ** const apReadClient, intptr_t aAppIdentifier);
CHIP_ERROR NewReadClient(ReadClient ** const apReadClient, uint64_t aAppIdentifier);

Messaging::ExchangeManager * mpExchangeMgr = nullptr;
InteractionModelDelegate * mpDelegate = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace chip {
namespace app {

CHIP_ERROR ReadClient::Init(Messaging::ExchangeManager * apExchangeMgr, InteractionModelDelegate * apDelegate,
intptr_t aAppIdentifier)
uint64_t aAppIdentifier)
{
CHIP_ERROR err = CHIP_NO_ERROR;
// Error if already initialized.
Expand Down
6 changes: 3 additions & 3 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ReadClient : public Messaging::ExchangeDelegate
AttributePathParams * apAttributePathParamsList, size_t aAttributePathParamsListSize,
EventNumber aEventNumber);

intptr_t GetAppIdentifier() const { return mAppIdentifier; }
uint64_t GetAppIdentifier() const { return mAppIdentifier; }
Messaging::ExchangeContext * GetExchangeContext() const { return mpExchangeCtx; }

private:
Expand Down Expand Up @@ -105,7 +105,7 @@ class ReadClient : public Messaging::ExchangeDelegate
* @retval #CHIP_NO_ERROR On success.
*
*/
CHIP_ERROR Init(Messaging::ExchangeManager * apExchangeMgr, InteractionModelDelegate * apDelegate, intptr_t aAppIdentifier);
CHIP_ERROR Init(Messaging::ExchangeManager * apExchangeMgr, InteractionModelDelegate * apDelegate, uint64_t aAppIdentifier);

virtual ~ReadClient() = default;

Expand Down Expand Up @@ -140,7 +140,7 @@ class ReadClient : public Messaging::ExchangeDelegate
Messaging::ExchangeContext * mpExchangeCtx = nullptr;
InteractionModelDelegate * mpDelegate = nullptr;
ClientState mState = ClientState::Uninitialized;
intptr_t mAppIdentifier = 0;
uint64_t mAppIdentifier = 0;
};

}; // namespace app
Expand Down
21 changes: 20 additions & 1 deletion src/app/WriteClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
namespace chip {
namespace app {

CHIP_ERROR WriteClient::Init(Messaging::ExchangeManager * apExchangeMgr, InteractionModelDelegate * apDelegate)
CHIP_ERROR WriteClient::Init(Messaging::ExchangeManager * apExchangeMgr, InteractionModelDelegate * apDelegate,
uint64_t aApplicationIdentifier)
{
VerifyOrReturnError(apExchangeMgr != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(mpExchangeMgr == nullptr, CHIP_ERROR_INCORRECT_STATE);
Expand All @@ -50,6 +51,7 @@ CHIP_ERROR WriteClient::Init(Messaging::ExchangeManager * apExchangeMgr, Interac
mpExchangeMgr = apExchangeMgr;
mpDelegate = apDelegate;
mAttributeStatusIndex = 0;
mAppIdentifier = aApplicationIdentifier;
MoveToState(State::Initialized);

return CHIP_NO_ERROR;
Expand Down Expand Up @@ -396,5 +398,22 @@ CHIP_ERROR WriteClient::ProcessAttributeStatusElement(AttributeStatusElement::Pa
return err;
}

CHIP_ERROR WriteClientHandle::SendWriteRequest(NodeId aNodeId, FabricIndex aFabricIndex, SecureSessionHandle * apSecureSession)
{
CHIP_ERROR err = mpWriteClient->SendWriteRequest(aNodeId, aFabricIndex, apSecureSession);

if (err == CHIP_NO_ERROR)
{
// On success, the InteractionModelEngine will be responible to take care of the lifecycle of the WriteClient, so we release
// the WriteClient without closing it.
mpWriteClient = nullptr;
}
else
{
SetWriteClient(nullptr);
}
return err;
}

} // namespace app
} // namespace chip
Loading

0 comments on commit 1719714

Please sign in to comment.