• 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 "state_box.h"
17 
18 namespace OHOS {
19 namespace Notification {
20 
NotifticationStateBox()21 NotifticationStateBox::NotifticationStateBox()
22 {
23     if (box_ == nullptr) {
24         return;
25     }
26     box_->SetMessageType(NOTIFICATION_STATE_SYNC);
27 }
28 
NotifticationStateBox(std::shared_ptr<TlvBox> box)29 NotifticationStateBox::NotifticationStateBox(std::shared_ptr<TlvBox> box) : BoxBase(box)
30 {
31 }
32 
33 #ifdef DISTRIBUTED_FEATURE_MASTER
GetDeviceType(std::string & deviceType)34 bool NotifticationStateBox::GetDeviceType(std::string& deviceType)
35 {
36     if (box_ == nullptr) {
37         return false;
38     }
39     return box_->GetStringValue(LOCAL_DEVICE_TYPE, deviceType);
40 }
41 
GetDeviceId(std::string & deviceId)42 bool NotifticationStateBox::GetDeviceId(std::string& deviceId)
43 {
44     if (box_ == nullptr) {
45         return false;
46     }
47     return box_->GetStringValue(LOCAL_DEVICE_ID, deviceId);
48 }
49 
GetState(int32_t & state)50 bool NotifticationStateBox::GetState(int32_t& state)
51 {
52     if (box_ == nullptr) {
53         return false;
54     }
55     return box_->GetInt32Value(LOCAL_DEVICE_STATUS, state);
56 }
57 
GetLiveViewEnable(bool & enable)58 bool NotifticationStateBox::GetLiveViewEnable(bool& enable)
59 {
60     if (box_ == nullptr) {
61         return false;
62     }
63     return box_->GetBoolValue(LIVEVIEW_SYNC_ENABLE, enable);
64 }
65 
GetNotificationEnable(bool & enable)66 bool NotifticationStateBox::GetNotificationEnable(bool& enable)
67 {
68     if (box_ == nullptr) {
69         return false;
70     }
71     return box_->GetBoolValue(NOTIFICATION_SYNC_ENABLE, enable);
72 }
73 #else
SetDeviceType(const std::string & deviceType)74 bool NotifticationStateBox::SetDeviceType(const std::string& deviceType)
75 {
76     if (box_ == nullptr) {
77         return false;
78     }
79     return box_->PutValue(std::make_shared<TlvItem>(LOCAL_DEVICE_TYPE, deviceType));
80 }
81 
SetDeviceId(const std::string & deviceId)82 bool NotifticationStateBox::SetDeviceId(const std::string& deviceId)
83 {
84     if (box_ == nullptr) {
85         return false;
86     }
87     return box_->PutValue(std::make_shared<TlvItem>(LOCAL_DEVICE_ID, deviceId));
88 }
89 
SetState(int32_t state)90 bool NotifticationStateBox::SetState(int32_t state)
91 {
92     if (box_ == nullptr) {
93         return false;
94     }
95     return box_->PutValue(std::make_shared<TlvItem>(LOCAL_DEVICE_STATUS, state));
96 }
97 
SetLiveViewEnable(bool enable)98 bool NotifticationStateBox::SetLiveViewEnable(bool enable)
99 {
100     if (box_ == nullptr) {
101         return false;
102     }
103     return box_->PutValue(std::make_shared<TlvItem>(LIVEVIEW_SYNC_ENABLE, enable));
104 }
105 
SetNotificationEnable(bool enable)106 bool NotifticationStateBox::SetNotificationEnable(bool enable)
107 {
108     if (box_ == nullptr) {
109         return false;
110     }
111     return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_SYNC_ENABLE, enable));
112 }
113 #endif
114 }
115 }
116