Line data Source code
1 : /*
2 : * Copyright (c) 2021 Project CHIP Authors
3 : *
4 : * Licensed under the Apache License, Version 2.0 (the "License");
5 : * you may not use this file except in compliance with the License.
6 : * You may obtain a copy of the License at
7 : *
8 : * http://www.apache.org/licenses/LICENSE-2.0
9 : *
10 : * Unless required by applicable law or agreed to in writing, software
11 : * distributed under the License is distributed on an "AS IS" BASIS,
12 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : * See the License for the specific language governing permissions and
14 : * limitations under the License.
15 : */
16 : #pragma once
17 :
18 : #include <access/SubjectDescriptor.h>
19 : #include <app/ConcreteAttributePath.h>
20 : #include <app/ConcreteCommandPath.h>
21 :
22 : namespace chip {
23 :
24 : /// Allows for application hooks for processing attribute and command operations
25 : class DataModelCallbacks
26 : {
27 : public:
28 : enum class OperationType
29 : {
30 : Read,
31 : Write
32 : };
33 :
34 : enum class OperationOrder
35 : {
36 : Pre,
37 : Post
38 : };
39 :
40 72 : virtual ~DataModelCallbacks() = default;
41 :
42 : /// This callback is called on attribute operations:
43 : /// - for reads and writes
44 : /// - both before and after attribute read/writes
45 : ///
46 : /// NOTE: PostRead is only called on read success.
47 13271 : virtual void AttributeOperation(OperationType operation, OperationOrder order, const chip::app::ConcreteAttributePath & path) {}
48 :
49 : /// This callback is called once for every command dispatch, before the dispatch is actually
50 : /// done towards the receiver.
51 : ///
52 : /// This method is called once for every CommandDataIB (i.e. it may be called several times
53 : /// in the case of batch invoke, where a single `InvokeRequestMessage` may contain several
54 : /// CommandDataIB entries).
55 : ///
56 : /// Returning an error here will prevent the command to be dispatched further
57 27 : virtual CHIP_ERROR PreCommandReceived(const chip::app::ConcreteCommandPath & commandPath,
58 : const chip::Access::SubjectDescriptor & subjectDescriptor)
59 : {
60 27 : return CHIP_NO_ERROR;
61 : }
62 :
63 : /// This callback is called once for every command dispatch, after the dispatch is actually
64 : /// done towards the receiver.
65 : ///
66 : /// This method is called once for every CommandDataIB (i.e. it may be called several times
67 : /// in the case of batch invoke, where a single `InvokeRequestMessage` may contain several
68 : /// CommandDataIB entries).
69 27 : virtual void PostCommandReceived(const chip::app::ConcreteCommandPath & commandPath,
70 : const chip::Access::SubjectDescriptor & subjectDescriptor)
71 27 : {}
72 :
73 : static DataModelCallbacks * GetInstance();
74 : static DataModelCallbacks * SetInstance(DataModelCallbacks * newInstance);
75 : };
76 :
77 : } // namespace chip
|