• 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 "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 = "DeviceProfile";
26 }
GetDeviceId() const27 std::string DeviceProfile::GetDeviceId() const
28 {
29     return deviceId_;
30 }
31 
SetDeviceId(const std::string & deviceId)32 void DeviceProfile::SetDeviceId(const std::string& deviceId)
33 {
34     deviceId_ = deviceId;
35 }
36 
GetDeviceTypeName() const37 std::string DeviceProfile::GetDeviceTypeName() const
38 {
39     return deviceTypeName_;
40 }
41 
SetDeviceTypeName(const std::string & deviceTypeName)42 void DeviceProfile::SetDeviceTypeName(const std::string &deviceTypeName)
43 {
44     deviceTypeName_ = deviceTypeName;
45 }
46 
GetDeviceTypeId() const47 int32_t DeviceProfile::GetDeviceTypeId() const
48 {
49     return deviceTypeId_;
50 }
51 
SetDeviceTypeId(int32_t deviceTypeId)52 void DeviceProfile::SetDeviceTypeId(int32_t deviceTypeId)
53 {
54     deviceTypeId_ = deviceTypeId;
55 }
56 
GetDeviceName() const57 std::string DeviceProfile::GetDeviceName() const
58 {
59     return deviceName_;
60 }
61 
SetDeviceName(const std::string & deviceName)62 void DeviceProfile::SetDeviceName(const std::string& deviceName)
63 {
64     deviceName_ = deviceName;
65 }
66 
GetManufactureName() const67 std::string DeviceProfile::GetManufactureName() const
68 {
69     return manufactureName_;
70 }
71 
SetManufactureName(std::string manufactureName)72 void DeviceProfile::SetManufactureName(std::string manufactureName)
73 {
74     manufactureName_ = manufactureName;
75 }
76 
GetDeviceModel() const77 std::string DeviceProfile::GetDeviceModel() const
78 {
79     return deviceModel_;
80 }
81 
SetDeviceModel(const std::string & deviceModel)82 void DeviceProfile::SetDeviceModel(const std::string &deviceModel)
83 {
84     deviceModel_ = deviceModel;
85 }
86 
GetSerialNumberId() const87 std::string DeviceProfile::GetSerialNumberId() const
88 {
89     return serialNumberId_;
90 }
91 
SetSerialNumberId(const std::string & serialNumberId)92 void DeviceProfile::SetSerialNumberId(const std::string &serialNumberId)
93 {
94     serialNumberId_ = serialNumberId;
95 }
96 
GetStorageCapability() const97 int64_t DeviceProfile::GetStorageCapability() const
98 {
99     return storageCapability_;
100 }
101 
SetStorageCapability(int64_t storageCapability)102 void DeviceProfile::SetStorageCapability(int64_t storageCapability)
103 {
104     storageCapability_ = storageCapability;
105 }
106 
GetOsApiLevel() const107 int32_t DeviceProfile::GetOsApiLevel() const
108 {
109     return osApiLevel_;
110 }
111 
SetOsApiLevel(int32_t osApiLevel)112 void DeviceProfile::SetOsApiLevel(int32_t osApiLevel)
113 {
114     osApiLevel_ = osApiLevel;
115 }
116 
GetOsVersion() const117 std::string DeviceProfile::GetOsVersion() const
118 {
119     return osVersion_;
120 }
121 
SetOsVersion(const std::string & osVersion)122 void DeviceProfile::SetOsVersion(const std::string& osVersion)
123 {
124     osVersion_ = osVersion;
125 }
126 
GetOsType() const127 int32_t DeviceProfile::GetOsType() const
128 {
129     return osType_;
130 }
131 
SetOsType(int32_t osType)132 void DeviceProfile::SetOsType(int32_t osType)
133 {
134     osType_ = osType;
135 }
136 
GetOsSysCap() const137 std::string DeviceProfile::GetOsSysCap() const
138 {
139     return osSysCap_;
140 }
141 
SetOsSysCap(const std::string & osSysCap)142 void DeviceProfile::SetOsSysCap(const std::string& osSysCap)
143 {
144     osSysCap_ = osSysCap;
145 }
146 
Marshalling(MessageParcel & parcel) const147 bool DeviceProfile::Marshalling(MessageParcel& parcel) const
148 {
149     WRITE_HELPER_RET(parcel, String, deviceId_, false);
150     WRITE_HELPER_RET(parcel, String, deviceTypeName_, false);
151     WRITE_HELPER_RET(parcel, Int32, deviceTypeId_, false);
152     WRITE_HELPER_RET(parcel, String, deviceName_, false);
153     WRITE_HELPER_RET(parcel, String, manufactureName_, false);
154     WRITE_HELPER_RET(parcel, String, deviceModel_, false);
155     WRITE_HELPER_RET(parcel, String, serialNumberId_, false);
156     WRITE_HELPER_RET(parcel, Int64, storageCapability_, false);
157     WRITE_HELPER_RET(parcel, String, osSysCap_, false);
158     WRITE_HELPER_RET(parcel, Int32, osApiLevel_, false);
159     WRITE_HELPER_RET(parcel, String, osVersion_, false);
160     WRITE_HELPER_RET(parcel, Int32, osType_, false);
161     return true;
162 }
163 
UnMarshalling(MessageParcel & parcel)164 bool DeviceProfile::UnMarshalling(MessageParcel& parcel)
165 {
166     READ_HELPER_RET(parcel, String, deviceId_, false);
167     READ_HELPER_RET(parcel, String, deviceTypeName_, false);
168     READ_HELPER_RET(parcel, Int32, deviceTypeId_, false);
169     READ_HELPER_RET(parcel, String, deviceName_, false);
170     READ_HELPER_RET(parcel, String, manufactureName_, false);
171     READ_HELPER_RET(parcel, String, deviceModel_, false);
172     READ_HELPER_RET(parcel, String, serialNumberId_, false);
173     READ_HELPER_RET(parcel, Int64, storageCapability_, false);
174     READ_HELPER_RET(parcel, String, osSysCap_, false);
175     READ_HELPER_RET(parcel, Int32, osApiLevel_, false);
176     READ_HELPER_RET(parcel, String, osVersion_, false);
177     READ_HELPER_RET(parcel, Int32, osType_, false);
178     return true;
179 }
180 
operator !=(const DeviceProfile & deviceProfile) const181 bool DeviceProfile::operator!=(const DeviceProfile& deviceProfile) const
182 {
183     bool isNotEqual = (deviceId_ != deviceProfile.GetDeviceId() || deviceTypeName_ != deviceProfile.GetDeviceTypeName()
184         || deviceTypeId_ != deviceProfile.GetDeviceTypeId() || deviceName_ != deviceProfile.GetDeviceName() ||
185         manufactureName_ != deviceProfile.GetManufactureName() || deviceModel_ != deviceProfile.GetDeviceModel() ||
186         serialNumberId_ != deviceProfile.GetSerialNumberId() || storageCapability_ !=
187         deviceProfile.GetStorageCapability() || osSysCap_ != deviceProfile.GetOsSysCap() || osApiLevel_ !=
188         deviceProfile.GetOsApiLevel() || osVersion_ != deviceProfile.GetOsVersion() || osType_ !=
189         deviceProfile.GetOsType());
190     if (isNotEqual) {
191         return true;
192     } else {
193         return false;
194     }
195 }
196 
dump() const197 std::string DeviceProfile::dump() const
198 {
199     nlohmann::json json;
200     json[DEVICE_ID] = ProfileUtils::GetAnonyString(deviceId_);
201     json[DEVICE_TYPE_NAME] = deviceTypeName_;
202     json[DEVICE_TYPE_ID] = deviceTypeId_;
203     json[DEVICE_NAME] = deviceName_;
204     json[MANUFACTURE_NAME] = manufactureName_;
205     json[DEVICE_MODEL] = deviceModel_;
206     json[SERIAL_NUMBER_ID] = serialNumberId_;
207     json[STORAGE_CAPACITY] = storageCapability_;
208     json[OS_SYS_CAPACITY] = osSysCap_;
209     json[OS_API_LEVEL] = osApiLevel_;
210     json[OS_VERSION] = osVersion_;
211     json[OS_TYPE] = osType_;
212     return json.dump();
213 }
214 } // namespace DistributedDeviceProfile
215 } // namespace OHOS