• 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 "match_box.h"
17 
18 namespace OHOS {
19 namespace Notification {
20 
NotifticationMatchBox()21 NotifticationMatchBox::NotifticationMatchBox()
22 {
23     if (box_ == nullptr) {
24         return;
25     }
26     box_->SetMessageType(NOTIFICATION_MATCH_SYNC);
27 }
28 
NotifticationMatchBox(std::shared_ptr<TlvBox> box)29 NotifticationMatchBox::NotifticationMatchBox(std::shared_ptr<TlvBox> box) : BoxBase(box)
30 {
31 }
32 
SetPeerDeviceType(const int32_t & deviceType)33 bool NotifticationMatchBox::SetPeerDeviceType(const int32_t& deviceType)
34 {
35     if (box_ == nullptr) {
36         return false;
37     }
38     return box_->PutValue(std::make_shared<TlvItem>(PEER_DEVICE_TYPE, deviceType));
39 }
40 
SetPeerDeviceId(const std::string & deviceId)41 bool NotifticationMatchBox::SetPeerDeviceId(const std::string& deviceId)
42 {
43     if (box_ == nullptr) {
44         return false;
45     }
46     return box_->PutValue(std::make_shared<TlvItem>(PEER_DEVICE_ID, deviceId));
47 }
48 
SetLocalDeviceType(const int32_t & deviceType)49 bool NotifticationMatchBox::SetLocalDeviceType(const int32_t& deviceType)
50 {
51     if (box_ == nullptr) {
52         return false;
53     }
54     return box_->PutValue(std::make_shared<TlvItem>(LOCAL_DEVICE_TYPE, deviceType));
55 }
56 
SetLocalDeviceId(const std::string & deviceId)57 bool NotifticationMatchBox::SetLocalDeviceId(const std::string& deviceId)
58 {
59     if (box_ == nullptr) {
60         return false;
61     }
62     return box_->PutValue(std::make_shared<TlvItem>(LOCAL_DEVICE_ID, deviceId));
63 }
64 
SetVersion(int32_t version)65 bool NotifticationMatchBox::SetVersion(int32_t version)
66 {
67     if (box_ == nullptr) {
68         return false;
69     }
70     return box_->PutValue(std::make_shared<TlvItem>(LOCAL_VERSION, version));
71 }
72 
SetMatchType(int32_t type)73 bool NotifticationMatchBox::SetMatchType(int32_t type)
74 {
75     if (box_ == nullptr) {
76         return false;
77     }
78     return box_->PutValue(std::make_shared<TlvItem>(MATCH_TYPE, type));
79 }
80 
GetPeerDeviceType(int32_t & deviceType)81 bool NotifticationMatchBox::GetPeerDeviceType(int32_t& deviceType)
82 {
83     if (box_ == nullptr) {
84         return false;
85     }
86     return box_->GetInt32Value(PEER_DEVICE_TYPE, deviceType);
87 }
88 
GetPeerDeviceId(std::string & deviceId)89 bool NotifticationMatchBox::GetPeerDeviceId(std::string& deviceId)
90 {
91     if (box_ == nullptr) {
92         return false;
93     }
94     return box_->GetStringValue(PEER_DEVICE_ID, deviceId);
95 }
96 
GetLocalDeviceType(int32_t & deviceType)97 bool NotifticationMatchBox::GetLocalDeviceType(int32_t& deviceType)
98 {
99     if (box_ == nullptr) {
100         return false;
101     }
102     return box_->GetInt32Value(LOCAL_DEVICE_TYPE, deviceType);
103 }
104 
GetLocalDeviceId(std::string & deviceId)105 bool NotifticationMatchBox::GetLocalDeviceId(std::string& deviceId)
106 {
107     if (box_ == nullptr) {
108         return false;
109     }
110     return box_->GetStringValue(LOCAL_DEVICE_ID, deviceId);
111 }
112 
GetVersion(int32_t & version)113 bool NotifticationMatchBox::GetVersion(int32_t& version)
114 {
115     if (box_ == nullptr) {
116         return false;
117     }
118     return box_->GetInt32Value(LOCAL_VERSION, version);
119 }
120 
GetMatchType(int32_t & type)121 bool NotifticationMatchBox::GetMatchType(int32_t& type)
122 {
123     if (box_ == nullptr) {
124         return false;
125     }
126     return box_->GetInt32Value(MATCH_TYPE, type);
127 }
128 }
129 }
130