• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "characteristic_profile.h"
17 #include "macro_utils.h"
18 #include "distributed_device_profile_constants.h"
19 #include "nlohmann/json.hpp"
20 #include "profile_utils.h"
21 
22 namespace OHOS {
23 namespace DistributedDeviceProfile {
24 namespace {
25     const std::string TAG = "CharacteristicProfile";
26 }
GetDeviceId() const27 std::string  CharacteristicProfile::GetDeviceId() const
28 {
29     return deviceId_;
30 }
31 
SetDeviceId(const std::string & deviceId)32 void CharacteristicProfile::SetDeviceId(const std::string& deviceId)
33 {
34     deviceId_ = deviceId;
35 }
36 
GetServiceName() const37 std::string  CharacteristicProfile::GetServiceName() const
38 {
39     return serviceName_;
40 }
41 
SetServiceName(const std::string & serviceName)42 void CharacteristicProfile::SetServiceName(const std::string& serviceName)
43 {
44     serviceName_ = serviceName;
45 }
46 
GetCharacteristicKey() const47 std::string  CharacteristicProfile::GetCharacteristicKey() const
48 {
49     return characteristicKey_;
50 }
51 
SetCharacteristicKey(const std::string & characteristicId)52 void CharacteristicProfile::SetCharacteristicKey(const std::string& characteristicId)
53 {
54     characteristicKey_ = characteristicId;
55 }
56 
GetCharacteristicValue() const57 std::string  CharacteristicProfile::GetCharacteristicValue() const
58 {
59     return characteristicValue_;
60 }
61 
SetCharacteristicValue(const std::string & characteristicValue)62 void CharacteristicProfile::SetCharacteristicValue(const std::string& characteristicValue)
63 {
64     characteristicValue_ = characteristicValue;
65 }
66 
Marshalling(MessageParcel & parcel) const67 bool CharacteristicProfile::Marshalling(MessageParcel& parcel) const
68 {
69     WRITE_HELPER_RET(parcel, String, deviceId_, false);
70     WRITE_HELPER_RET(parcel, String, serviceName_, false);
71     WRITE_HELPER_RET(parcel, String, characteristicKey_, false);
72     WRITE_HELPER_RET(parcel, String, characteristicValue_, false);
73     return true;
74 }
75 
UnMarshalling(MessageParcel & parcel)76 bool CharacteristicProfile::UnMarshalling(MessageParcel& parcel)
77 {
78     READ_HELPER_RET(parcel, String, deviceId_, false);
79     READ_HELPER_RET(parcel, String, serviceName_, false);
80     READ_HELPER_RET(parcel, String, characteristicKey_, false);
81     READ_HELPER_RET(parcel, String, characteristicValue_, false);
82     return true;
83 }
84 
operator !=(const CharacteristicProfile & charProfile) const85 bool CharacteristicProfile::operator!=(const CharacteristicProfile& charProfile) const
86 {
87     bool isNotEqual = (deviceId_ != charProfile.GetDeviceId() || serviceName_ != charProfile.GetServiceName() ||
88         characteristicKey_ != charProfile.GetCharacteristicKey() ||
89         characteristicValue_ != charProfile.GetCharacteristicValue());
90     if (isNotEqual) {
91         return true;
92     } else {
93         return false;
94     }
95 }
96 
dump() const97 std::string CharacteristicProfile::dump() const
98 {
99     nlohmann::json json;
100     json[DEVICE_ID] = ProfileUtils::GetAnonyString(deviceId_);
101     json[SERVICE_NAME] = serviceName_;
102     json[CHARACTERISTIC_KEY] = characteristicKey_;
103     json[CHARACTERISTIC_VALUE] = characteristicValue_;
104     return json.dump();
105 }
106 } // namespace DistributedDeviceProfile
107 } // namespace OHOS