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 : #include <app/data-model-provider/EventsGenerator.h>
18 :
19 : namespace chip::app::DataModel::internal {
20 :
21 4 : std::optional<EventNumber> GenerateEvent(const EventOptions & eventOptions, EventsGenerator & generator,
22 : EventLoggingDelegate & delegate, bool isFabricSensitiveEvent)
23 : {
24 : // this skips generating the event if it is fabric-sensitive but the provided event data is not
25 : // associated with any fabric.
26 4 : if (isFabricSensitiveEvent && (eventOptions.mFabricIndex == kUndefinedFabricIndex))
27 : {
28 1 : ChipLogError(EventLogging, "Event encode failure: no fabric index for fabric scoped event");
29 1 : return std::nullopt;
30 : }
31 :
32 : //
33 : // Unlike attributes which have a different 'EncodeForRead' for fabric-scoped structs,
34 : // fabric-sensitive events don't require that since the actual omission of the event in its entirety
35 : // happens within the event management framework itself at the time of access.
36 : //
37 : // The 'mFabricIndex' field in the event options above is encoded out-of-band alongside the event payload
38 : // and used to match against the accessing fabric.
39 : //
40 : EventNumber eventNumber;
41 3 : CHIP_ERROR err = generator.GenerateEvent(&delegate, eventOptions, eventNumber);
42 3 : if (err != CHIP_NO_ERROR)
43 : {
44 0 : ChipLogError(EventLogging, "Failed to generate event: %" CHIP_ERROR_FORMAT, err.Format());
45 0 : return std::nullopt;
46 : }
47 :
48 3 : return eventNumber;
49 : }
50 :
51 : } // namespace chip::app::DataModel::internal
|