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 "trust_device_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 = "TrustDeviceProfile";
26 }
GetDeviceId() const27 std::string TrustDeviceProfile::GetDeviceId() const
28 {
29 return deviceId_;
30 }
31
SetDeviceId(const std::string & deviceId)32 void TrustDeviceProfile::SetDeviceId(const std::string& deviceId)
33 {
34 deviceId_ = deviceId;
35 }
36
GetDeviceIdType() const37 int32_t TrustDeviceProfile::GetDeviceIdType() const
38 {
39 return deviceIdType_;
40 }
41
SetDeviceIdType(int32_t deviceType)42 void TrustDeviceProfile::SetDeviceIdType(int32_t deviceType)
43 {
44 deviceIdType_ = deviceType;
45 }
46
GetDeviceIdHash() const47 std::string TrustDeviceProfile::GetDeviceIdHash() const
48 {
49 return deviceIdHash_;
50 }
51
SetDeviceIdHash(const std::string & deviceIdHash)52 void TrustDeviceProfile::SetDeviceIdHash(const std::string& deviceIdHash)
53 {
54 deviceIdHash_ = deviceIdHash;
55 }
56
GetStatus() const57 int32_t TrustDeviceProfile::GetStatus() const
58 {
59 return status_;
60 }
61
SetStatus(int32_t status)62 void TrustDeviceProfile::SetStatus(int32_t status)
63 {
64 status_ = status;
65 }
66
Marshalling(MessageParcel & parcel) const67 bool TrustDeviceProfile::Marshalling(MessageParcel& parcel) const
68 {
69 WRITE_HELPER_RET(parcel, String, deviceId_, false);
70 WRITE_HELPER_RET(parcel, Uint32, deviceIdType_, false);
71 WRITE_HELPER_RET(parcel, String, deviceIdHash_, false);
72 WRITE_HELPER_RET(parcel, Int32, status_, false);
73 return true;
74 }
75
UnMarshalling(MessageParcel & parcel)76 bool TrustDeviceProfile::UnMarshalling(MessageParcel& parcel)
77 {
78 READ_HELPER_RET(parcel, String, deviceId_, false);
79 READ_HELPER_RET(parcel, Uint32, deviceIdType_, false);
80 READ_HELPER_RET(parcel, String, deviceIdHash_, false);
81 READ_HELPER_RET(parcel, Int32, status_, false);
82 return true;
83 }
84
dump() const85 std::string TrustDeviceProfile::dump() const
86 {
87 nlohmann::json json;
88 json[DEVICE_ID] = ProfileUtils::GetAnonyString(deviceId_);
89 json[DEVICE_ID_TYPE] = deviceIdType_;
90 json[DEVICE_ID_HASH] = deviceIdHash_;
91 json[STATUS] = status_;
92 return json.dump();
93 }
94 } // namespace DistributedDeviceProfile
95 } // namespace OHOS