@@ -498,7 +498,6 @@ WEAVE_ERROR GenericTraitUpdatableDataSink::GetBoolean(const char * apPath, bool
498498 nl::Weave::TLV::TLVReader reader;
499499 PacketBuffer * pMsgBuf = NULL ;
500500 PropertyPathHandle propertyPathHandle = kNullPropertyPathHandle ;
501- ;
502501 std::map<PropertyPathHandle, PacketBuffer *>::iterator it;
503502
504503 err = GetSchemaEngine ()->MapPathToHandle (apPath, propertyPathHandle);
@@ -537,7 +536,6 @@ WEAVE_ERROR GenericTraitUpdatableDataSink::GetBytes(const char * apPath, BytesDa
537536 nl::Weave::TLV::TLVReader reader;
538537 PacketBuffer * pMsgBuf = NULL ;
539538 PropertyPathHandle propertyPathHandle = kNullPropertyPathHandle ;
540- ;
541539 std::map<PropertyPathHandle, PacketBuffer *>::iterator it;
542540
543541 err = GetSchemaEngine ()->MapPathToHandle (apPath, propertyPathHandle);
@@ -558,8 +556,12 @@ WEAVE_ERROR GenericTraitUpdatableDataSink::GetBytes(const char * apPath, BytesDa
558556 SuccessOrExit (err);
559557
560558 apBytesData->mDataLen = reader.GetLength ();
561- err = reader.GetDataPtr (apBytesData->mpDataBuf );
562- SuccessOrExit (err);
559+ WeaveLogProgress (DataManagement, " GetBytes with length %d" , apBytesData->mDataLen );
560+ if (apBytesData->mDataLen != 0 )
561+ {
562+ err = reader.GetDataPtr (apBytesData->mpDataBuf );
563+ SuccessOrExit (err);
564+ }
563565
564566exit:
565567 WeaveLogFunctError (err);
@@ -618,7 +620,6 @@ WEAVE_ERROR GenericTraitUpdatableDataSink::IsNull(const char * apPath, bool & aI
618620 nl::Weave::TLV::TLVReader reader;
619621 PacketBuffer * pMsgBuf = NULL ;
620622 PropertyPathHandle propertyPathHandle = kNullPropertyPathHandle ;
621- ;
622623 std::map<PropertyPathHandle, PacketBuffer *>::iterator it;
623624
624625 err = GetSchemaEngine ()->MapPathToHandle (apPath, propertyPathHandle);
@@ -658,7 +659,6 @@ WEAVE_ERROR GenericTraitUpdatableDataSink::GetStringArray(const char * apPath, s
658659 nl::Weave::TLV::TLVReader reader;
659660 PacketBuffer * pMsgBuf = NULL ;
660661 PropertyPathHandle propertyPathHandle = kNullPropertyPathHandle ;
661- ;
662662 TLVType OuterContainerType;
663663 std::map<PropertyPathHandle, PacketBuffer *>::iterator it;
664664
@@ -686,8 +686,13 @@ WEAVE_ERROR GenericTraitUpdatableDataSink::GetStringArray(const char * apPath, s
686686 {
687687 int length = reader.GetLength ();
688688 const uint8_t * pDataBuf = NULL ;
689- err = reader.GetDataPtr (pDataBuf);
690- SuccessOrExit (err);
689+ WeaveLogProgress (DataManagement, " GetStringArray with length %d" , length);
690+ if (length != 0 )
691+ {
692+ err = reader.GetDataPtr (pDataBuf);
693+ SuccessOrExit (err);
694+ }
695+
691696 std::string val ((char *) pDataBuf, length);
692697 aValueVector.push_back (val);
693698 }
@@ -740,6 +745,36 @@ WEAVE_ERROR GenericTraitUpdatableDataSink::Get(const char * apPath, T & aValue)
740745 return err;
741746}
742747
748+ WEAVE_ERROR GenericTraitUpdatableDataSink::DeleteData (const char * apPath)
749+ {
750+ WEAVE_ERROR err = WEAVE_NO_ERROR;
751+ nl::Weave::TLV::TLVReader reader;
752+ PacketBuffer * pMsgBuf = NULL ;
753+ PropertyPathHandle propertyPathHandle = kNullPropertyPathHandle ;
754+ std::map<PropertyPathHandle, PacketBuffer *>::iterator it;
755+
756+ err = GetSchemaEngine ()->MapPathToHandle (apPath, propertyPathHandle);
757+ SuccessOrExit (err);
758+
759+ it = mPathTlvDataMap .find (propertyPathHandle);
760+ VerifyOrExit (it != mPathTlvDataMap .end (), err = WEAVE_ERROR_INVALID_TLV_TAG);
761+
762+ if (NULL != it->second )
763+ {
764+ PacketBuffer::Free (it->second );
765+ it->second = NULL ;
766+ WeaveLogProgress (DataManagement, " Deleted data in mPathTlvDataMap for path %s" , apPath);
767+ }
768+
769+ mPathTlvDataMap .erase (it);
770+
771+ err = ClearUpdated (GetSubscriptionClient (), propertyPathHandle);
772+
773+ exit:
774+ WeaveLogFunctError (err);
775+ return err;
776+ }
777+
743778WEAVE_ERROR
744779GenericTraitUpdatableDataSink::SetLeafData (PropertyPathHandle aLeafHandle, TLVReader & aReader)
745780{
@@ -903,9 +938,9 @@ void WdmClient::ClientEventCallback(void * const aAppState, SubscriptionClient::
903938{
904939 WEAVE_ERROR err = WEAVE_NO_ERROR;
905940 WdmClient * const pWdmClient = reinterpret_cast <WdmClient *>(aAppState);
906-
907- OpState savedOpState = pWdmClient->mOpState ;
908- WeaveLogDetail (DataManagement, " WDM ClientEventCallback: current op is, %d" , savedOpState);
941+ DeviceStatus * deviceStatus = NULL ;
942+ OpState savedOpState = pWdmClient->mOpState ;
943+ WeaveLogDetail (DataManagement, " WdmClient ClientEventCallback: current op is, %d, event is %d " , savedOpState, aEvent );
909944
910945 switch (aEvent)
911946 {
@@ -984,31 +1019,46 @@ void WdmClient::ClientEventCallback(void * const aAppState, SubscriptionClient::
9841019 case SubscriptionClient::kEvent_OnSubscriptionTerminated :
9851020 WeaveLogDetail (DataManagement, " Client->kEvent_OnSubscriptionTerminated. Reason: %u, peer = 0x%" PRIX64 " \n " ,
9861021 aInParam.mSubscriptionTerminated .mReason , aInParam.mSubscriptionTerminated .mClient ->GetPeerNodeId ());
987- pWdmClient->mpSubscriptionClient ->AbortSubscription ();
988- err = WEAVE_ERROR_INCORRECT_STATE;
1022+ VerifyOrExit (kOpState_RefreshData == savedOpState, err = WEAVE_ERROR_INCORRECT_STATE);
1023+ deviceStatus = new DeviceStatus ();
1024+ deviceStatus->StatusProfileId = aInParam.mSubscriptionTerminated .mStatusProfileId ;
1025+ deviceStatus->StatusCode = aInParam.mSubscriptionTerminated .mStatusCode ;
1026+ deviceStatus->SystemErrorCode = aInParam.mSubscriptionTerminated .mReason ;
1027+ err = aInParam.mSubscriptionTerminated .mReason ;
9891028 break ;
9901029 case SubscriptionClient::kEvent_OnUpdateComplete :
1030+ VerifyOrExit (kOpState_FlushUpdate == savedOpState, err = WEAVE_ERROR_INCORRECT_STATE);
9911031 if ((aInParam.mUpdateComplete .mReason == WEAVE_NO_ERROR) &&
9921032 (nl::Weave::Profiles::kWeaveProfile_Common == aInParam.mUpdateComplete .mStatusProfileId ) &&
9931033 (nl::Weave::Profiles::Common::kStatus_Success == aInParam.mUpdateComplete .mStatusCode ))
9941034 {
995- WeaveLogDetail (DataManagement, " Update: path result: success" );
1035+ WeaveLogDetail (DataManagement, " Update: path result: success, tdh %" PRIu16 " , ph %" PRIu16 " ." ,
1036+ aInParam.mUpdateComplete .mTraitDataHandle , aInParam.mUpdateComplete .mPropertyPathHandle );
9961037 }
9971038 else
9981039 {
999- WeaveLogDetail (DataManagement, " Update: path failed: %s, %s, tdh %" PRIu16 " , will %sretry, discard failed change" ,
1040+
1041+ WeaveLogDetail (DataManagement,
1042+ " Update: path failed: %s, %s, tdh %" PRIu16 " , ph %" PRIu16 " , %s, discard failed change" ,
10001043 ErrorStr (aInParam.mUpdateComplete .mReason ),
10011044 nl::StatusReportStr (aInParam.mUpdateComplete .mStatusProfileId , aInParam.mUpdateComplete .mStatusCode ),
1002- aInParam.mUpdateComplete .mTraitDataHandle , aInParam.mUpdateComplete .mWillRetry ? " " : " not " );
1045+ aInParam.mUpdateComplete .mTraitDataHandle , aInParam.mUpdateComplete .mPropertyPathHandle ,
1046+ aInParam.mUpdateComplete .mWillRetry ? " will retry" : " will not retry" );
1047+
1048+ err = pWdmClient->UpdateFailedPathResults (
1049+ pWdmClient, aInParam.mUpdateComplete .mTraitDataHandle , aInParam.mUpdateComplete .mPropertyPathHandle ,
1050+ aInParam.mUpdateComplete .mReason , aInParam.mUpdateComplete .mStatusProfileId , aInParam.mUpdateComplete .mStatusCode );
10031051 }
10041052
10051053 break ;
10061054 case SubscriptionClient::kEvent_OnNoMorePendingUpdates :
1007- // TODO: notify application with all status for updated paths
10081055 WeaveLogDetail (DataManagement, " Update: no more pending updates" );
10091056 VerifyOrExit (kOpState_FlushUpdate == savedOpState, err = WEAVE_ERROR_INCORRECT_STATE);
10101057 pWdmClient->mpSubscriptionClient ->DiscardUpdates ();
1011- pWdmClient->mOnComplete .General (pWdmClient->mpContext , pWdmClient->mpAppReqState );
1058+ pWdmClient->mOnComplete .FlushUpdate (pWdmClient->mpContext , pWdmClient->mpAppReqState ,
1059+ pWdmClient->mFailedFlushPathStatus .size (), pWdmClient->mFailedFlushPathStatus .data ());
1060+ pWdmClient->mFailedFlushPathStatus .clear ();
1061+ pWdmClient->mFailedPaths .clear ();
10121062 pWdmClient->mpContext = NULL ;
10131063 pWdmClient->ClearOpState ();
10141064 break ;
@@ -1021,12 +1071,37 @@ void WdmClient::ClientEventCallback(void * const aAppState, SubscriptionClient::
10211071exit:
10221072 if (WEAVE_NO_ERROR != err)
10231073 {
1024- WeaveLogError (DataManagement, " WDM ClientEventCallback failure: err = %d" , err);
1025- pWdmClient->mOnError (pWdmClient->mpContext , pWdmClient->mpAppReqState , err, NULL );
1074+ WeaveLogError (DataManagement, " WdmClient ClientEventCallback failure: err = %d" , err);
1075+
1076+ if (pWdmClient->mOnError )
1077+ {
1078+ pWdmClient->mOnError (pWdmClient->mpContext , pWdmClient->mpAppReqState , err, deviceStatus);
1079+ pWdmClient->mOnError = NULL ;
1080+ }
1081+
1082+ if (kOpState_FlushUpdate == savedOpState)
1083+ {
1084+ pWdmClient->mpSubscriptionClient ->DiscardUpdates ();
1085+ pWdmClient->mFailedFlushPathStatus .clear ();
1086+ pWdmClient->mFailedPaths .clear ();
1087+ }
1088+
1089+ if (kOpState_RefreshData == savedOpState)
1090+ {
1091+ pWdmClient->mpSubscriptionClient ->AbortSubscription ();
1092+ pWdmClient->mSinkCatalog .Iterate (ClearDataSinkVersion, pWdmClient);
1093+ }
1094+
10261095 pWdmClient->mpContext = NULL ;
10271096 pWdmClient->ClearOpState ();
10281097 }
10291098
1099+ if (deviceStatus != NULL )
1100+ {
1101+ delete deviceStatus;
1102+ deviceStatus = NULL ;
1103+ }
1104+
10301105 return ;
10311106}
10321107
@@ -1050,6 +1125,8 @@ WEAVE_ERROR WdmClient::Init(WeaveMessageLayer * apMsgLayer, Binding * apBinding)
10501125 State = kState_Initialized ;
10511126 mpContext = NULL ;
10521127 ClearOpState ();
1128+ mFailedFlushPathStatus .clear ();
1129+ mFailedPaths .clear ();
10531130
10541131exit:
10551132 return WEAVE_NO_ERROR;
@@ -1060,14 +1137,48 @@ void WdmClient::SetNodeId(uint64_t aNodeId)
10601137 mSinkCatalog .SetNodeId (aNodeId);
10611138}
10621139
1140+ WEAVE_ERROR WdmClient::UpdateFailedPathResults (WdmClient * const apWdmClient, TraitDataHandle mTraitDataHandle ,
1141+ PropertyPathHandle mPropertyPathHandle , uint32_t aReason, uint32_t aStatusProfileId,
1142+ uint16_t aStatusCode)
1143+ {
1144+ TraitDataSink * dataSink = NULL ;
1145+ WEAVE_ERROR err = WEAVE_NO_ERROR;
1146+ WdmClientFlushUpdateStatus updateStatus;
1147+ std::string path;
1148+
1149+ err = apWdmClient->mSinkCatalog .Locate (mTraitDataHandle , &dataSink);
1150+ SuccessOrExit (err);
1151+
1152+ err = dataSink->GetSchemaEngine ()->MapHandleToPath (mPropertyPathHandle , path);
1153+ SuccessOrExit (err);
1154+
1155+ mFailedPaths .push_back (path);
1156+ updateStatus.mpPath = mFailedPaths .back ().c_str ();
1157+ updateStatus.mPathLen = mFailedPaths .back ().length ();
1158+ updateStatus.mErrorCode = aReason;
1159+ updateStatus.mDevStatus .SystemErrorCode = aReason;
1160+ updateStatus.mDevStatus .StatusProfileId = aStatusProfileId;
1161+ updateStatus.mDevStatus .StatusCode = aStatusCode;
1162+ updateStatus.mpDataSink = dataSink;
1163+ mFailedFlushPathStatus .push_back (updateStatus);
1164+ WeaveLogError (DataManagement, " Update: faild path is %s, length is %d" , updateStatus.mpPath , updateStatus.mPathLen );
1165+
1166+ exit:
1167+ if (WEAVE_NO_ERROR != err)
1168+ {
1169+ WeaveLogError (DataManagement, " Fail in UpdateFailedPathResults with err = %d" , err);
1170+ }
1171+ return err;
1172+ }
1173+
10631174WEAVE_ERROR WdmClient::NewDataSink (const ResourceIdentifier & aResourceId, uint32_t aProfileId, uint64_t aInstanceId,
10641175 const char * apPath, GenericTraitUpdatableDataSink *& apGenericTraitUpdatableDataSink)
10651176{
10661177 WEAVE_ERROR err = WEAVE_NO_ERROR;
10671178 PropertyPathHandle handle = kNullPropertyPathHandle ;
10681179
10691180 const TraitSchemaEngine * pEngine = TraitSchemaDirectory::GetTraitSchemaEngine (aProfileId);
1070- VerifyOrExit (pEngine != NULL , err = WEAVE_ERROR_INCORRECT_STATE );
1181+ VerifyOrExit (pEngine != NULL , err = WEAVE_ERROR_INVALID_PROFILE_ID );
10711182
10721183 VerifyOrExit (mpSubscriptionClient != NULL , err = WEAVE_ERROR_INCORRECT_STATE);
10731184
@@ -1093,6 +1204,7 @@ WEAVE_ERROR WdmClient::NewDataSink(const ResourceIdentifier & aResourceId, uint3
10931204 apGenericTraitUpdatableDataSink->SetSubscriptionClient (mpSubscriptionClient);
10941205
10951206exit:
1207+ WeaveLogFunctError (err);
10961208 return err;
10971209}
10981210
@@ -1111,15 +1223,19 @@ WEAVE_ERROR WdmClient::GetDataSink(const ResourceIdentifier & aResourceId, uint3
11111223 return err;
11121224}
11131225
1114- WEAVE_ERROR WdmClient::FlushUpdate (void * apAppReqState, DMCompleteFunct onComplete, DMErrorFunct onError)
1226+ WEAVE_ERROR WdmClient::FlushUpdate (void * apAppReqState, DMFlushUpdateCompleteFunct onComplete, DMErrorFunct onError)
11151227{
11161228 VerifyOrExit (mOpState == kOpState_Idle , WeaveLogError (DataManagement, " FlushUpdate with OpState %d" , mOpState ));
11171229
1118- mpAppReqState = apAppReqState;
1119- mOnComplete .General = onComplete;
1120- mOnError = onError;
1121- mOpState = kOpState_FlushUpdate ;
1122- mpContext = this ;
1230+ mpAppReqState = apAppReqState;
1231+ mOnComplete .FlushUpdate = onComplete;
1232+ mOnError = onError;
1233+ mOpState = kOpState_FlushUpdate ;
1234+ mpContext = this ;
1235+
1236+ mFailedFlushPathStatus .clear ();
1237+ mFailedPaths .clear ();
1238+
11231239 mpSubscriptionClient->FlushUpdate (true );
11241240
11251241exit:
0 commit comments