• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "response_box.h"
17 
18 namespace OHOS {
19 namespace Notification {
20 
NotificationResponseBox()21 NotificationResponseBox::NotificationResponseBox()
22 {
23     if (box_ == nullptr) {
24         return;
25     }
26     box_->SetMessageType(NOTIFICATION_RESPONSE_SYNC);
27 }
28 
NotificationResponseBox(std::shared_ptr<TlvBox> box)29 NotificationResponseBox::NotificationResponseBox(std::shared_ptr<TlvBox> box) : BoxBase(box) {}
30 
SetMessageType(int32_t messageType)31 bool NotificationResponseBox::SetMessageType(int32_t messageType)
32 {
33     if (box_ == nullptr) {
34         return false;
35     }
36     return box_->SetMessageType(messageType);
37 }
38 
SetNotificationHashCode(const std::string & hashCode)39 bool NotificationResponseBox::SetNotificationHashCode(const std::string& hashCode)
40 {
41     if (box_ == nullptr) {
42         return false;
43     }
44     return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_HASHCODE, hashCode));
45 }
46 
SetOperationEventId(const std::string & eventId)47 bool NotificationResponseBox::SetOperationEventId(const std::string& eventId)
48 {
49     if (box_ == nullptr) {
50         return false;
51     }
52     return box_->PutValue(std::make_shared<TlvItem>(OPERATION_EVENT_ID, eventId));
53 }
54 
SetActionName(const std::string & actionName)55 bool NotificationResponseBox::SetActionName(const std::string& actionName)
56 {
57     if (box_ == nullptr) {
58         return false;
59     }
60     return box_->PutValue(std::make_shared<TlvItem>(ACTION_BUTTON_NAME, actionName));
61 }
62 
SetUserInput(const std::string & userInput)63 bool NotificationResponseBox::SetUserInput(const std::string& userInput)
64 {
65     if (box_ == nullptr) {
66         return false;
67     }
68     return box_->PutValue(std::make_shared<TlvItem>(ACTION_USER_INPUT, userInput));
69 }
70 
SetOperationType(int32_t type)71 bool NotificationResponseBox::SetOperationType(int32_t type)
72 {
73     if (box_ == nullptr) {
74         return false;
75     }
76     return box_->PutValue(std::make_shared<TlvItem>(OPERATION_TYPE, type));
77 }
78 
SetOperationBtnIndex(const int32_t index)79 bool NotificationResponseBox::SetOperationBtnIndex(const int32_t index)
80 {
81     if (box_ == nullptr) {
82         return false;
83     }
84     return box_->PutValue(std::make_shared<TlvItem>(OPERATION_BTN_INDEX, index));
85 }
86 
SetOperationJumpType(const int32_t jumpType)87 bool NotificationResponseBox::SetOperationJumpType(const int32_t jumpType)
88 {
89     if (box_ == nullptr) {
90         return false;
91     }
92     return box_->PutValue(std::make_shared<TlvItem>(OPERATION_JUMP_TYPE, jumpType));
93 }
94 
SetMatchType(int32_t type)95 bool NotificationResponseBox::SetMatchType(int32_t type)
96 {
97     if (box_ == nullptr) {
98         return false;
99     }
100     return box_->PutValue(std::make_shared<TlvItem>(MATCH_TYPE, type));
101 }
102 
SetLocalDeviceId(const std::string & deviceId)103 bool NotificationResponseBox::SetLocalDeviceId(const std::string& deviceId)
104 {
105     if (box_ == nullptr) {
106         return false;
107     }
108     return box_->PutValue(std::make_shared<TlvItem>(LOCAL_DEVICE_ID, deviceId));
109 }
110 
SetResponseResult(int32_t result)111 bool NotificationResponseBox::SetResponseResult(int32_t result)
112 {
113     if (box_ == nullptr) {
114         return false;
115     }
116     return box_->PutValue(std::make_shared<TlvItem>(RESULT_CODE, result));
117 }
118 
GetNotificationHashCode(std::string & hashCode) const119 bool NotificationResponseBox::GetNotificationHashCode(std::string& hashCode) const
120 {
121     if (box_ == nullptr) {
122         return false;
123     }
124     return box_->GetStringValue(NOTIFICATION_HASHCODE, hashCode);
125 }
126 
GetOperationEventId(std::string & eventId) const127 bool NotificationResponseBox::GetOperationEventId(std::string& eventId) const
128 {
129     if (box_ == nullptr) {
130         return false;
131     }
132     return box_->GetStringValue(OPERATION_EVENT_ID, eventId);
133 }
134 
GetActionName(std::string & actionName) const135 bool NotificationResponseBox::GetActionName(std::string& actionName) const
136 {
137     if (box_ == nullptr) {
138         return false;
139     }
140     return box_->GetStringValue(ACTION_BUTTON_NAME, actionName);
141 }
142 
GetUserInput(std::string & userInput) const143 bool NotificationResponseBox::GetUserInput(std::string& userInput) const
144 {
145     if (box_ == nullptr) {
146         return false;
147     }
148     return box_->GetStringValue(ACTION_USER_INPUT, userInput);
149 }
150 
GetOperationType(int32_t & type) const151 bool NotificationResponseBox::GetOperationType(int32_t& type) const
152 {
153     if (box_ == nullptr) {
154         return false;
155     }
156     return box_->GetInt32Value(OPERATION_TYPE, type);
157 }
158 
GetOperationBtnIndex(int32_t & index) const159 bool NotificationResponseBox::GetOperationBtnIndex(int32_t& index) const
160 {
161     if (box_ == nullptr) {
162         return false;
163     }
164     return box_->GetInt32Value(OPERATION_BTN_INDEX, index);
165 }
166 
GetOperationJumpType(int32_t & jumpType) const167 bool NotificationResponseBox::GetOperationJumpType(int32_t& jumpType) const
168 {
169     if (box_ == nullptr) {
170         return false;
171     }
172     return box_->GetInt32Value(OPERATION_JUMP_TYPE, jumpType);
173 }
174 
GetMatchType(int32_t & type) const175 bool NotificationResponseBox::GetMatchType(int32_t& type) const
176 {
177     if (box_ == nullptr) {
178         return false;
179     }
180     return box_->GetInt32Value(MATCH_TYPE, type);
181 }
182 
GetLocalDeviceId(std::string & deviceId) const183 bool NotificationResponseBox::GetLocalDeviceId(std::string& deviceId) const
184 {
185     if (box_ == nullptr) {
186         return false;
187     }
188     return box_->GetStringValue(LOCAL_DEVICE_ID, deviceId);
189 }
190 
GetResponseResult(int32_t & result) const191 bool NotificationResponseBox::GetResponseResult(int32_t& result) const
192 {
193     if (box_ == nullptr) {
194         return false;
195     }
196     return box_->GetInt32Value(RESULT_CODE, result);
197 }
198 } // namespace Notification
199 } // namespace OHOS
200