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 "service_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 = "ServiceProfile";
26 }
27
ServiceProfile(const std::string & deviceId,const std::string & serviceName,const std::string & serviceType)28 ServiceProfile::ServiceProfile(const std::string& deviceId, const std::string& serviceName,
29 const std::string& serviceType) : deviceId_(deviceId), serviceName_(serviceName), serviceType_(serviceType)
30 {
31 HILOGI("constructor!");
32 }
ServiceProfile()33 ServiceProfile::ServiceProfile()
34 {
35 HILOGI("constructor!");
36 }
37
~ServiceProfile()38 ServiceProfile::~ServiceProfile()
39 {
40 HILOGI("destructor");
41 }
42
GetDeviceId() const43 std::string ServiceProfile::GetDeviceId() const
44 {
45 return deviceId_;
46 }
47
SetDeviceId(const std::string & deviceId)48 void ServiceProfile::SetDeviceId(const std::string& deviceId)
49 {
50 deviceId_ = deviceId;
51 }
52
GetServiceName() const53 std::string ServiceProfile::GetServiceName() const
54 {
55 return serviceName_;
56 }
57
SetServiceName(const std::string & serviceName)58 void ServiceProfile::SetServiceName(const std::string& serviceName)
59 {
60 serviceName_ = serviceName;
61 }
62
GetServiceType() const63 std::string ServiceProfile::GetServiceType() const
64 {
65 return serviceType_;
66 }
67
SetServiceType(const std::string & serviceType)68 void ServiceProfile::SetServiceType(const std::string& serviceType)
69 {
70 serviceType_ = serviceType;
71 }
72
Marshalling(MessageParcel & parcel) const73 bool ServiceProfile::Marshalling(MessageParcel& parcel) const
74 {
75 WRITE_HELPER_RET(parcel, String, deviceId_, false);
76 WRITE_HELPER_RET(parcel, String, serviceName_, false);
77 WRITE_HELPER_RET(parcel, String, serviceType_, false);
78 return true;
79 }
80
UnMarshalling(MessageParcel & parcel)81 bool ServiceProfile::UnMarshalling(MessageParcel& parcel)
82 {
83 READ_HELPER_RET(parcel, String, deviceId_, false);
84 READ_HELPER_RET(parcel, String, serviceName_, false);
85 READ_HELPER_RET(parcel, String, serviceType_, false);
86 return true;
87 }
88
operator !=(const ServiceProfile & serviceProfile) const89 bool ServiceProfile::operator!=(const ServiceProfile& serviceProfile) const
90 {
91 bool isNotEqual = (deviceId_ != serviceProfile.GetDeviceId() || serviceName_ != serviceProfile.GetServiceName() ||
92 serviceType_ != serviceProfile.GetServiceType());
93 if (isNotEqual) {
94 return true;
95 } else {
96 return false;
97 }
98 }
99
dump() const100 std::string ServiceProfile::dump() const
101 {
102 nlohmann::json json;
103 json[DEVICE_ID] = ProfileUtils::GetAnonyString(deviceId_);
104 json[SERVICE_NAME] = serviceName_;
105 json[SERVICE_TYPE] = serviceType_;
106 return json.dump();
107 }
108 } // namespace DistributedDeviceProfile
109 } // namespace OHOS