Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 6fb884d

Browse files
authored
Merge pull request #401 from openweave/feature/add_generic_trait_catalog
Add GenericTraitCatalogImpl
2 parents f6fb597 + af03cff commit 6fb884d

File tree

6 files changed

+616
-0
lines changed

6 files changed

+616
-0
lines changed

src/include/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ $(nl_public_WeaveProfiles_source_dirstem)/data-management/Current/ViewClient.h \
644644
$(nl_public_WeaveProfiles_source_dirstem)/data-management/Current/TraitData.h \
645645
$(nl_public_WeaveProfiles_source_dirstem)/data-management/Current/SingleResourceTraitCatalog.ipp \
646646
$(nl_public_WeaveProfiles_source_dirstem)/data-management/Current/SingleResourceTraitCatalog.h \
647+
$(nl_public_WeaveProfiles_source_dirstem)/data-management/Current/GenericTraitCatalogImpl.ipp \
648+
$(nl_public_WeaveProfiles_source_dirstem)/data-management/Current/GenericTraitCatalogImpl.h \
647649
$(nl_public_WeaveProfiles_source_dirstem)/data-management/Current/TraitCatalog.h \
648650
$(nl_public_WeaveProfiles_source_dirstem)/data-management/Current/TraitPathStore.h \
649651
$(nl_public_WeaveProfiles_source_dirstem)/data-management/Current/SubscriptionEngine.h \

src/lib/core/WeaveDMConfig.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,19 @@
664664
#define WDM_RESUBSCRIBE_WAIT_TIME_MULTIPLIER_MS 10000
665665
#endif
666666

667+
/**
668+
* @def WEAVE_CONFIG_ENABLE_GENERIC_TRAIT_CATALOG_IMPL
669+
*
670+
* @brief
671+
* Enable (1) or disable (0) GenericTraitCatalogImpl
672+
* in Weave Data Management Next profile. This feature is
673+
* optional and could be disabled.
674+
*
675+
*/
676+
#ifndef WEAVE_CONFIG_ENABLE_GENERIC_TRAIT_CATALOG_IMPL
677+
#define WEAVE_CONFIG_ENABLE_GENERIC_TRAIT_CATALOG_IMPL 0
678+
#endif
679+
667680
// clang-format on
668681

669682
#endif // _WEAVE_DATA_MANAGEMENT_CONFIG_H

src/lib/profiles/WeaveProfiles.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ nl_WeaveProfiles_sources
4141
@top_builddir@/src/lib/profiles/data-management/Current/SubscriptionHandler.cpp \
4242
@top_builddir@/src/lib/profiles/data-management/Current/TraitData.cpp \
4343
@top_builddir@/src/lib/profiles/data-management/Current/SingleResourceTraitCatalog.cpp \
44+
@top_builddir@/src/lib/profiles/data-management/Current/GenericTraitCatalogImpl.cpp \
4445
@top_builddir@/src/lib/profiles/data-management/Current/TraitPathStore.cpp \
4546
@top_builddir@/src/lib/profiles/data-management/Current/ViewClient.cpp \
4647
@top_builddir@/src/lib/profiles/data-management/Current/Command.cpp \
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
*
3+
* Copyright (c) 2020 Google LLC.
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <map>
20+
#include <limits>
21+
#include <Weave/Profiles/data-management/Current/WdmManagedNamespace.h>
22+
#include <Weave/Profiles/data-management/Current/GenericTraitCatalogImpl.h>
23+
#include <Weave/Profiles/data-management/Current/GenericTraitCatalogImpl.ipp>
24+
25+
namespace nl {
26+
namespace Weave {
27+
namespace Profiles {
28+
namespace WeaveMakeManagedNamespaceIdentifier(DataManagement, kWeaveManagedNamespaceDesignation_Current) {
29+
template class GenericTraitCatalogImpl<TraitDataSink>;
30+
template class GenericTraitCatalogImpl<TraitDataSource>;
31+
}; // namespace WeaveMakeManagedNamespaceIdentifier(DataManagement, kWeaveManagedNamespaceDesignation_Current)
32+
}; // namespace Profiles
33+
}; // namespace Weave
34+
}; // namespace nl
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
*
3+
* Copyright (c) 2020 Google LLC.
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* @file
21+
* Defines generic trait catalogs that are used to house trait data sources/sinks and can be used with the
22+
* various WDM engines to correctly map to/from resources specified in a WDM path to actual trait
23+
* data instances.
24+
*
25+
*/
26+
27+
#ifndef _WEAVE_DATA_MANAGEMENT_GENERIC_TRAIT_CATALOG_IMPL_CURRENT_H
28+
#define _WEAVE_DATA_MANAGEMENT_GENERIC_TRAIT_CATALOG_IMPL_CURRENT_H
29+
30+
#include <map>
31+
#include <queue>
32+
#include <limits>
33+
#include <Weave/Profiles/data-management/Current/WdmManagedNamespace.h>
34+
#include <Weave/Profiles/data-management/TraitCatalog.h>
35+
36+
namespace nl {
37+
namespace Weave {
38+
namespace Profiles {
39+
namespace WeaveMakeManagedNamespaceIdentifier(DataManagement, kWeaveManagedNamespaceDesignation_Current) {
40+
/**
41+
* @class GenericTraitCatalogImpl
42+
*
43+
* @brief A Weave provided implementation of the TraitCatalogBase interface for a collection of trait data instances
44+
* that all refer to the same resource. It provides a c++ map-backed storage for these instances.
45+
*/
46+
template <typename T>
47+
class GenericTraitCatalogImpl : public TraitCatalogBase<T>
48+
{
49+
public:
50+
GenericTraitCatalogImpl(void);
51+
virtual ~GenericTraitCatalogImpl(void);
52+
53+
void SetNodeId(uint64_t aNodeId);
54+
55+
WEAVE_ERROR Add(const ResourceIdentifier & aResourceId, const uint64_t & aInstanceId, PropertyPathHandle basePathHandle,
56+
T * traitInstance, TraitDataHandle & aHandle);
57+
WEAVE_ERROR Remove(T * traitInstance);
58+
WEAVE_ERROR Remove(TraitDataHandle aHandle);
59+
WEAVE_ERROR PrepareSubscriptionSpecificPathList(TraitPath * pathList, uint16_t pathListSize, TraitDataHandle aHandle);
60+
WEAVE_ERROR PrepareSubscriptionPathList(TraitPath * pathList, uint16_t pathListSize, uint16_t & pathListLen);
61+
WEAVE_ERROR Clear(void);
62+
63+
virtual WEAVE_ERROR AddressToHandle(TLV::TLVReader & aReader, TraitDataHandle & aHandle,
64+
SchemaVersionRange & aSchemaVersionRange) const;
65+
virtual WEAVE_ERROR HandleToAddress(TraitDataHandle aHandle, TLV::TLVWriter & aWriter,
66+
SchemaVersionRange & aSchemaVersionRange) const;
67+
virtual WEAVE_ERROR Locate(TraitDataHandle aHandle, T ** aTraitInstance) const;
68+
virtual WEAVE_ERROR Locate(T * aTraitInstance, TraitDataHandle & aHandle) const;
69+
70+
WEAVE_ERROR Locate(uint32_t aProfileId, uint64_t aInstanceId, ResourceIdentifier aResourceId, TraitDataHandle & aHandle) const;
71+
72+
WEAVE_ERROR Locate(uint32_t aProfileId, uint64_t aInstanceId, ResourceIdentifier aResourceId, T ** aTraitInstance) const;
73+
74+
virtual WEAVE_ERROR DispatchEvent(uint16_t aEvent, void * aContext) const;
75+
virtual void Iterate(IteratorCallback aCallback, void * aContext);
76+
#if WEAVE_CONFIG_ENABLE_WDM_UPDATE
77+
virtual WEAVE_ERROR GetInstanceId(TraitDataHandle aHandle, uint64_t & aInstanceId) const;
78+
virtual WEAVE_ERROR GetResourceId(TraitDataHandle aHandle, ResourceIdentifier & aResourceId) const;
79+
#endif // WEAVE_CONFIG_ENABLE_WDM_UPDATE
80+
81+
/**
82+
* Return the number of trait instances in the catalog.
83+
*/
84+
uint32_t Size(void) const;
85+
86+
private:
87+
struct CatalogItem
88+
{
89+
uint32_t mProfileId;
90+
uint64_t mInstanceId;
91+
ResourceIdentifier mResourceId;
92+
T * mItem;
93+
PropertyPathHandle mBasePathHandle;
94+
};
95+
96+
TraitDataHandle GetNextHandle();
97+
98+
uint64_t mNodeId;
99+
std::map<TraitDataHandle, CatalogItem *> mItemStore;
100+
std::queue<TraitDataHandle> mRecycledHandles;
101+
};
102+
103+
typedef GenericTraitCatalogImpl<TraitDataSink> GenericTraitSinkCatalog;
104+
typedef GenericTraitCatalogImpl<TraitDataSource> GenericTraitSourceCatalog;
105+
106+
}; // namespace WeaveMakeManagedNamespaceIdentifier(DataManagement, kWeaveManagedNamespaceDesignation_Current)
107+
}; // namespace Profiles
108+
}; // namespace Weave
109+
}; // namespace nl
110+
111+
#endif // _WEAVE_DATA_MANAGEMENT_GENERIC_TRAIT_CATALOG_IMPL_CURRENT_H

0 commit comments

Comments
 (0)