Line data Source code
1 : /*
2 : * Copyright (c) 2025 Project CHIP Authors
3 : * All rights reserved.
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 : #pragma once
18 :
19 : #include <app/data-model-provider/Context.h>
20 : #include <app/data-model-provider/Provider.h>
21 : #include <app/persistence/AttributePersistenceProvider.h>
22 : #include <lib/core/CHIPPersistentStorageDelegate.h>
23 :
24 : namespace chip {
25 : namespace app {
26 :
27 : /// Represents a runtime context for server cluster interfaces to interact
28 : /// with the outside world such as:
29 : /// - notify of state changes to trigger attribute reports
30 : /// - emit events
31 : /// - potentially interact/review global metadata
32 : ///
33 : /// Prefer using `attributeStorage` over calling the global GetAttributePersistenceProvider()
34 : /// so that unit testing is easier and there is less coupling in code.
35 : ///
36 : /// The context object is quite large in terms of exposed functionality and not all clusters use
37 : /// all the information within, however a common context is used to minimize RAM overhead
38 : /// for every cluster maintaining such a context.
39 : struct ServerClusterContext
40 : {
41 : DataModel::Provider * const provider = nullptr; /// underlying provider that the cluster operates in
42 : PersistentStorageDelegate * const storage = nullptr; /// read/write persistent storage
43 : AttributePersistenceProvider * const attributeStorage = nullptr; /// read/write attribute data
44 : DataModel::InteractionModelContext * const interactionContext = nullptr; /// outside-world communication
45 :
46 232 : bool operator!=(const ServerClusterContext & other) const
47 : {
48 232 : return (provider != other.provider) //
49 231 : || (storage != other.storage) //
50 229 : || (attributeStorage != other.attributeStorage) //
51 463 : || (interactionContext != other.interactionContext);
52 : }
53 : };
54 :
55 : } // namespace app
56 : } // namespace chip
|