• 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 "device_icon_info.h"
17 
18 #include "cJSON.h"
19 #include "distributed_device_profile_constants.h"
20 #include "ipc_utils.h"
21 #include "macro_utils.h"
22 
23 namespace OHOS {
24 namespace DistributedDeviceProfile {
25 namespace {
26     const std::string TAG = "DeviceIconInfo";
27     const std::string DEVICE_ICON_WISE_VERSION = "wiseVersion";
28     const std::string DEVICE_ICON_SIZE = "iconSize";
29 }
30 
GetId() const31 int32_t DeviceIconInfo::GetId() const
32 {
33     return id_;
34 }
35 
SetId(const int32_t id)36 void DeviceIconInfo::SetId(const int32_t id)
37 {
38     this->id_ = id;
39 }
40 
GetProductId() const41 std::string DeviceIconInfo::GetProductId() const
42 {
43     return productId_;
44 }
45 
SetProductId(const std::string & productId)46 void DeviceIconInfo::SetProductId(const std::string& productId)
47 {
48     this->productId_ = productId;
49 }
50 
GetInternalModel() const51 std::string DeviceIconInfo::GetInternalModel() const
52 {
53     return internalModel_;
54 }
55 
SetInternalModel(const std::string & internalModel)56 void DeviceIconInfo::SetInternalModel(const std::string& internalModel)
57 {
58     internalModel_ = internalModel;
59 }
60 
GetSubProductId() const61 std::string DeviceIconInfo::GetSubProductId() const
62 {
63     return subProductId_;
64 }
65 
SetSubProductId(const std::string & subProductId)66 void DeviceIconInfo::SetSubProductId(const std::string& subProductId)
67 {
68     this->subProductId_ = subProductId;
69 }
70 
GetImageType() const71 std::string DeviceIconInfo::GetImageType() const
72 {
73     return imageType_;
74 }
75 
SetImageType(const std::string & imageType)76 void DeviceIconInfo::SetImageType(const std::string& imageType)
77 {
78     this->imageType_ = imageType;
79 }
80 
GetSpecName() const81 std::string DeviceIconInfo::GetSpecName() const
82 {
83     return specName_;
84 }
85 
SetSpecName(const std::string & specName)86 void DeviceIconInfo::SetSpecName(const std::string& specName)
87 {
88     this->specName_ = specName;
89 }
90 
GetVersion() const91 std::string DeviceIconInfo::GetVersion() const
92 {
93     return version_;
94 }
95 
SetVersion(const std::string & version)96 void DeviceIconInfo::SetVersion(const std::string& version)
97 {
98     version_ = version;
99 }
100 
GetWiseVersion() const101 std::string DeviceIconInfo::GetWiseVersion() const
102 {
103     return wiseVersion_;
104 }
105 
SetWiseVersion(const std::string & wiseVersion)106 void DeviceIconInfo::SetWiseVersion(const std::string& wiseVersion)
107 {
108     wiseVersion_ = wiseVersion;
109 }
110 
GetUrl() const111 std::string DeviceIconInfo::GetUrl() const
112 {
113     return url_;
114 }
115 
SetUrl(const std::string & url)116 void DeviceIconInfo::SetUrl(const std::string& url)
117 {
118     url_ = url;
119 }
120 
GetIcon() const121 std::vector<uint8_t> DeviceIconInfo::GetIcon() const
122 {
123     return icon_;
124 }
125 
SetIcon(const std::vector<uint8_t> & icon)126 void DeviceIconInfo::SetIcon(const std::vector<uint8_t>& icon)
127 {
128     this->icon_ = icon;
129 }
130 
Marshalling(MessageParcel & parcel) const131 bool DeviceIconInfo::Marshalling(MessageParcel& parcel) const
132 {
133     WRITE_HELPER_RET(parcel, String, productId_, false);
134     WRITE_HELPER_RET(parcel, String, internalModel_, false);
135     WRITE_HELPER_RET(parcel, String, subProductId_, false);
136     WRITE_HELPER_RET(parcel, String, imageType_, false);
137     WRITE_HELPER_RET(parcel, String, specName_, false);
138     WRITE_HELPER_RET(parcel, String, version_, false);
139     WRITE_HELPER_RET(parcel, String, wiseVersion_, false);
140     WRITE_HELPER_RET(parcel, String, url_, false);
141     IpcUtils::Marshalling(parcel, icon_);
142     return true;
143 }
144 
UnMarshalling(MessageParcel & parcel)145 bool DeviceIconInfo::UnMarshalling(MessageParcel& parcel)
146 {
147     READ_HELPER_RET(parcel, String, productId_, false);
148     READ_HELPER_RET(parcel, String, internalModel_, false);
149     READ_HELPER_RET(parcel, String, subProductId_, false);
150     READ_HELPER_RET(parcel, String, imageType_, false);
151     READ_HELPER_RET(parcel, String, specName_, false);
152     READ_HELPER_RET(parcel, String, version_, false);
153     READ_HELPER_RET(parcel, String, wiseVersion_, false);
154     READ_HELPER_RET(parcel, String, url_, false);
155     IpcUtils::UnMarshalling(parcel, icon_);
156     return true;
157 }
158 
operator !=(const DeviceIconInfo & other) const159 bool DeviceIconInfo::operator!=(const DeviceIconInfo& other) const
160 {
161     bool isNotEqual = (id_ != other.GetId() || productId_ != other.GetProductId() ||
162         internalModel_ != other.GetInternalModel() ||
163         subProductId_ != other.GetSubProductId() || imageType_ != other.GetImageType() ||
164         specName_ != other.GetSpecName() || version_ != other.GetVersion() || wiseVersion_ != other.GetWiseVersion() ||
165         url_ != other.GetUrl() || icon_ != other.GetIcon());
166     if (isNotEqual) {
167         return true;
168     } else {
169         return false;
170     }
171 }
172 
dump() const173 std::string DeviceIconInfo::dump() const
174 {
175     cJSON* json = cJSON_CreateObject();
176     if (json == NULL) {
177         return EMPTY_STRING;
178     }
179     cJSON_AddNumberToObject(json, ID.c_str(), id_);
180     cJSON_AddStringToObject(json, PRODUCT_ID.c_str(), productId_.c_str());
181     cJSON_AddStringToObject(json, INTERNAL_MODEL.c_str(), internalModel_.c_str());
182     cJSON_AddStringToObject(json, SUB_PRODUCT_ID.c_str(), subProductId_.c_str());
183     cJSON_AddStringToObject(json, IMAGE_TYPE.c_str(), imageType_.c_str());
184     cJSON_AddStringToObject(json, SPEC_NAME.c_str(), specName_.c_str());
185     cJSON_AddStringToObject(json, SPEC_NAME.c_str(), specName_.c_str());
186     cJSON_AddStringToObject(json, DEVICE_ICON_VERSION.c_str(), version_.c_str());
187     cJSON_AddStringToObject(json, DEVICE_ICON_WISE_VERSION.c_str(), wiseVersion_.c_str());
188     cJSON_AddStringToObject(json, DEVICE_ICON_URL.c_str(), url_.c_str());
189     cJSON_AddNumberToObject(json, DEVICE_ICON_SIZE.c_str(), icon_.size());
190     char* jsonChars = cJSON_PrintUnformatted(json);
191     cJSON_Delete(json);
192     if (jsonChars == NULL) {
193         HILOGE("cJSON formatted to string failed!");
194         return EMPTY_STRING;
195     }
196     std::string jsonStr = jsonChars;
197     cJSON_free(jsonChars);
198     return jsonStr;
199 }
200 } // namespace DistributedDeviceProfile
201 } // namespace OHOS
202