Skip to content

Commit

Permalink
Merge pull request openweave#14 from gandreello/bug/future-proof-wdm-…
Browse files Browse the repository at this point in the history
…update-response

WDM UpdateResponse messages
  • Loading branch information
robszewczyk authored Aug 16, 2018
2 parents 5591b7e + c87c5b9 commit b634685
Show file tree
Hide file tree
Showing 10 changed files with 1,194 additions and 57 deletions.
430 changes: 388 additions & 42 deletions src/lib/profiles/data-management/Current/MessageDef.cpp

Large diffs are not rendered by default.

91 changes: 85 additions & 6 deletions src/lib/profiles/data-management/Current/MessageDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class BuilderBase
{
public:
void ResetError(void);
void ResetError(WEAVE_ERROR aErr);
WEAVE_ERROR GetError(void) const { return mError; };
nl::Weave::TLV::TLVWriter * GetWriter(void) { return mpWriter; };

Expand Down Expand Up @@ -224,6 +225,7 @@ class ListBuilderBase : public BuilderBase

public:
WEAVE_ERROR Init(nl::Weave::TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse);
WEAVE_ERROR Init(nl::Weave::TLV::TLVWriter * const apWriter);
};

/**
Expand Down Expand Up @@ -324,6 +326,7 @@ namespace StatusElement {
};

class Parser;
class Builder;
}; // namespace DataElement

/**
Expand All @@ -342,16 +345,36 @@ class StatusElement::Parser : public ParserBase
// 3) any tag can only appear once
// At the top level of the structure, unknown tags are ignored for foward compatibility
WEAVE_ERROR CheckSchemaValidity(void) const;
WEAVE_ERROR CheckSchemaValidityDeprecated(void) const;
WEAVE_ERROR CheckSchemaValidityCurrent(void) const;

// WEAVE_END_OF_TLV if there is no such element
// WEAVE_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
WEAVE_ERROR GetProfileID(uint32_t * apProfileID) const;
WEAVE_ERROR GetProfileIDAndStatusCode(uint32_t * apProfileID, uint16_t * aStatusCode) const;

// WEAVE_END_OF_TLV if there is no such element
// WEAVE_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
WEAVE_ERROR GetStatus(uint16_t * apStatus) const;
private:
bool mDeprecatedFormat;
};

/**
* @brief
* WDM Status Element encoder definition
*/
class StatusElement::Builder : public ListBuilderBase
{
public:
WEAVE_ERROR Init(nl::Weave::TLV::TLVWriter * const apWriter);
WEAVE_ERROR InitDeprecated(nl::Weave::TLV::TLVWriter * const apWriter);

StatusElement::Builder & ProfileIDAndStatus(const uint32_t aProfileID, const uint16_t aStatusCode);

StatusElement::Builder & EndOfStatusElement(void);

private:
bool mDeprecatedFormat;
};


/**
* @brief
* WDM Data Element definition
Expand Down Expand Up @@ -661,14 +684,35 @@ class VersionList::Builder : public ListBuilderBase

namespace StatusList {
class Parser;
class Builder;
}; // namespace StatusList

/**
* StatusList builder.
* Supports both the current and the deprecated StatusList format.
*/
class StatusList::Builder : public ListBuilderBase
{
public:

/**
* Write the list as an array of structures, instead of an array of arrays.
*/
void UseDeprecatedFormat() { this->mDeprecatedFormat = true; }

StatusList::Builder & AddStatus(uint32_t aProfileID, uint16_t aStatusCode);

StatusList::Builder & EndOfStatusList(void);
private:
bool mDeprecatedFormat;

};

class StatusList::Parser : public ListParserBase
{
public:
WEAVE_ERROR CheckSchemaValidity(void) const;
WEAVE_ERROR GetVersion(uint64_t * const apVersion);
WEAVE_ERROR GetStatusAndProfileID(uint32_t * const apProfileID, uint16_t * const apStatusCode);
WEAVE_ERROR GetProfileIDAndStatusCode(uint32_t * const apProfileID, uint16_t * const apStatusCode);
};

namespace ViewRequest {
Expand Down Expand Up @@ -1477,6 +1521,41 @@ namespace UpdateResponse {
};

class Parser;
class Builder;
};

/**
* @brief
* WDM Update Response encoder definition
*/
class UpdateResponse::Builder : public BuilderBase
{
public:
WEAVE_ERROR Init(nl::Weave::TLV::TLVWriter * const apWriter);
/**
* @brief Create the VersionList::Builder
*
* @return A reference to a VersionList::Builder
*/
VersionList::Builder & CreateVersionListBuilder(void);

/**
* @brief Create the StatusList::Builder
*
* @return A reference to a StatusList::Builder
*/
StatusList::Builder & CreateStatusListBuilder(void);

/**
* @brief Mark the end of this message
*
* @return A reference to *this
*/
UpdateResponse::Builder & EndOfResponse(void);

private:
VersionList::Builder mVersionListBuilder;
StatusList::Builder mStatusListBuilder;
};

class UpdateResponse::Parser : public ParserBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ void SubscriptionClient::OnUpdateConfirm(WEAVE_ERROR aReason, nl::Weave::Profile
{
err = statusList.Next();

err = statusList.GetStatusAndProfileID(&profileID, &statusCode);
err = statusList.GetProfileIDAndStatusCode(&profileID, &statusCode);
SuccessOrExit(err);
}

Expand Down
2 changes: 1 addition & 1 deletion src/system/SystemObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ inline void ObjectPool<T, N>::GetNumObjectsInUse(unsigned int aStartIndex, unsig

aNumInUse += count;
}
#endif
#endif // WEAVE_SYSTEM_CONFIG_PROVIDE_STATISTICS


template<class T, unsigned int N>
Expand Down
9 changes: 9 additions & 0 deletions src/test-apps/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ check_PROGRAMS += \
TestTDM \
TestPathStore \
TestWdmUpdateEncoder \
TestWdmUpdateResponse \
$(NULL)

if WEAVE_BUILD_WARM
Expand Down Expand Up @@ -450,6 +451,7 @@ local_test_programs += \
TestWarm \
TestPathStore \
TestWdmUpdateEncoder \
TestWdmUpdateResponse \
$(NULL)
endif

Expand Down Expand Up @@ -1212,6 +1214,13 @@ TestWdmUpdateEncoder_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_s
TestWdmUpdateEncoder_LDFLAGS = $(AM_CPPFLAGS)
TestWdmUpdateEncoder_LDADD = libWeaveTestCommon.a $(COMMON_LDADD)

TestWdmUpdateResponse_SOURCES = TestWdmUpdateResponse.cpp \
TestPersistedStorageImplementation.cpp

TestWdmUpdateResponse_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/test-apps/schema
TestWdmUpdateResponse_LDFLAGS = $(AM_CPPFLAGS)
TestWdmUpdateResponse_LDADD = libWeaveTestCommon.a $(COMMON_LDADD)

TestFabricStateDelegate_SOURCES = TestFabricStateDelegate.cpp TestPersistedStorageImplementation.cpp
TestFabricStateDelegate_LDFLAGS = $(AM_CPPFLAGS)
TestFabricStateDelegate_LDADD = libWeaveTestCommon.a $(COMMON_LDADD)
Expand Down
Loading

0 comments on commit b634685

Please sign in to comment.