Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2023 Project CHIP Authors
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 :
18 : #include <app/icd/server/ICDNotifier.h>
19 : #include <cstdint>
20 : #include <cstring>
21 :
22 : namespace chip {
23 : namespace app {
24 :
25 : ICDNotifier ICDNotifier::sICDNotifier;
26 :
27 5 : ICDNotifier::~ICDNotifier()
28 : {
29 5 : memset(mSubscribers, 0, sizeof(mSubscribers));
30 5 : }
31 :
32 10 : CHIP_ERROR ICDNotifier::Subscribe(ICDListener * subscriber)
33 : {
34 10 : CHIP_ERROR err = CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
35 10 : for (auto & sub : mSubscribers)
36 : {
37 10 : if (sub == nullptr)
38 : {
39 10 : sub = subscriber;
40 10 : err = CHIP_NO_ERROR;
41 10 : break;
42 : }
43 : }
44 10 : return err;
45 : }
46 :
47 10 : void ICDNotifier::Unsubscribe(ICDListener * subscriber)
48 : {
49 10 : for (auto & sub : mSubscribers)
50 : {
51 10 : if (sub == subscriber)
52 : {
53 10 : sub = nullptr;
54 10 : break;
55 : }
56 : }
57 10 : }
58 :
59 4 : void ICDNotifier::NotifyNetworkActivityNotification()
60 : {
61 8 : for (auto subscriber : mSubscribers)
62 : {
63 4 : if (subscriber != nullptr)
64 : {
65 4 : subscriber->OnNetworkActivity();
66 : }
67 : }
68 4 : }
69 :
70 4 : void ICDNotifier::NotifyActiveRequestNotification(ICDListener::KeepActiveFlags request)
71 : {
72 8 : for (auto subscriber : mSubscribers)
73 : {
74 4 : if (subscriber != nullptr)
75 : {
76 4 : subscriber->OnKeepActiveRequest(request);
77 : }
78 : }
79 4 : }
80 :
81 4 : void ICDNotifier::NotifyActiveRequestWithdrawal(ICDListener::KeepActiveFlags request)
82 : {
83 8 : for (auto subscriber : mSubscribers)
84 : {
85 4 : if (subscriber != nullptr)
86 : {
87 4 : subscriber->OnActiveRequestWithdrawal(request);
88 : }
89 : }
90 4 : }
91 :
92 : #if CHIP_CONFIG_ENABLE_ICD_DSLS
93 : void ICDNotifier::NotifySITModeRequestNotification()
94 : {
95 : for (auto subscriber : mSubscribers)
96 : {
97 : if (subscriber != nullptr)
98 : {
99 : subscriber->OnSITModeRequest();
100 : }
101 : }
102 : }
103 :
104 : void ICDNotifier::NotifySITModeRequestWithdrawal()
105 : {
106 : for (auto subscriber : mSubscribers)
107 : {
108 : if (subscriber != nullptr)
109 : {
110 : subscriber->OnSITModeRequestWithdrawal();
111 : }
112 : }
113 : }
114 : #endif // CHIP_CONFIG_ENABLE_ICD_DSLS
115 :
116 0 : void ICDNotifier::NotifyICDManagementEvent(ICDListener::ICDManagementEvents event)
117 : {
118 0 : for (auto subscriber : mSubscribers)
119 : {
120 0 : if (subscriber != nullptr)
121 : {
122 0 : subscriber->OnICDManagementServerEvent(event);
123 : }
124 : }
125 0 : }
126 :
127 3 : void ICDNotifier::NotifySubscriptionReport()
128 : {
129 6 : for (auto subscriber : mSubscribers)
130 : {
131 3 : if (subscriber != nullptr)
132 : {
133 3 : subscriber->OnSubscriptionReport();
134 : }
135 : }
136 3 : }
137 :
138 : } // namespace app
139 : } // namespace chip
|