1 /* 2 * Copyright (C) 2022 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 #ifndef LOCATION_LOCATING_REQUIRED_DATA_CONFIG_H 17 #define LOCATION_LOCATING_REQUIRED_DATA_CONFIG_H 18 19 #include <parcel.h> 20 #include <string> 21 22 namespace OHOS { 23 namespace Location { 24 class LocatingRequiredDataConfig : public Parcelable { 25 public: LocatingRequiredDataConfig()26 LocatingRequiredDataConfig() 27 { 28 type_ = 0; 29 needStartScan_ = false; 30 scanIntervalMs_ = 0; 31 scanTimeoutMs_ = DEFAULT_TIMEOUT_30S; 32 } 33 LocatingRequiredDataConfig(LocatingRequiredDataConfig & LocatingRequiredDataConfig)34 explicit LocatingRequiredDataConfig(LocatingRequiredDataConfig& LocatingRequiredDataConfig) 35 { 36 SetType(LocatingRequiredDataConfig.GetType()); 37 SetNeedStartScan(LocatingRequiredDataConfig.GetNeedStartScan()); 38 SetScanIntervalMs(LocatingRequiredDataConfig.GetScanIntervalMs()); 39 SetScanTimeoutMs(LocatingRequiredDataConfig.GetScanTimeoutMs()); 40 } 41 42 ~LocatingRequiredDataConfig() override = default; 43 GetType()44 inline int GetType() const 45 { 46 return type_; 47 } 48 SetType(int type)49 inline void SetType(int type) 50 { 51 type_ = type; 52 } 53 GetNeedStartScan()54 inline bool GetNeedStartScan() const 55 { 56 return needStartScan_; 57 } 58 SetNeedStartScan(bool needStartScan)59 inline void SetNeedStartScan(bool needStartScan) 60 { 61 needStartScan_ = needStartScan; 62 } 63 GetScanIntervalMs()64 inline int GetScanIntervalMs() const 65 { 66 return scanIntervalMs_; 67 } 68 SetScanIntervalMs(int scanIntervalMs)69 inline void SetScanIntervalMs(int scanIntervalMs) 70 { 71 scanIntervalMs_ = scanIntervalMs; 72 } 73 GetScanTimeoutMs()74 inline int GetScanTimeoutMs() const 75 { 76 return scanTimeoutMs_; 77 } 78 SetScanTimeoutMs(int scanTimeoutMs)79 inline void SetScanTimeoutMs(int scanTimeoutMs) 80 { 81 scanTimeoutMs_ = scanTimeoutMs; 82 } 83 ReadFromParcel(Parcel & parcel)84 void ReadFromParcel(Parcel& parcel) 85 { 86 type_ = parcel.ReadInt32(); 87 needStartScan_ = parcel.ReadBool(); 88 scanIntervalMs_ = parcel.ReadInt32(); 89 scanTimeoutMs_ = parcel.ReadInt32(); 90 } 91 Marshalling(Parcel & parcel)92 bool Marshalling(Parcel& parcel) const override 93 { 94 return parcel.WriteInt32(type_) && 95 parcel.WriteBool(needStartScan_) && 96 parcel.WriteInt32(scanIntervalMs_) && 97 parcel.WriteInt32(scanTimeoutMs_); 98 } 99 Unmarshalling(Parcel & parcel)100 static std::shared_ptr<LocatingRequiredDataConfig> Unmarshalling(Parcel& parcel) 101 { 102 auto locatingRequiredDataConfig = std::make_shared<LocatingRequiredDataConfig>(); 103 locatingRequiredDataConfig->ReadFromParcel(parcel); 104 return locatingRequiredDataConfig; 105 } 106 ToString()107 std::string ToString() 108 { 109 std::string str = "type_ : " + std::to_string(type_) + 110 ", needStartScan_ : " + (needStartScan_ ? "true" : "false") + 111 ", scanIntervalMs_ : " + std::to_string(scanIntervalMs_) + 112 ", scanTimeoutMs_ : " + std::to_string(scanTimeoutMs_); 113 return str; 114 } 115 116 private: 117 int type_; 118 bool needStartScan_; 119 int scanIntervalMs_; 120 int scanTimeoutMs_; 121 }; 122 } // namespace Location 123 } // namespace OHOS 124 #endif // LOCATION_LOCATING_REQUIRED_DATA_CONFIG_H