• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "request_config.h"
17 
18 #include <parcel.h>
19 
20 #include "constant_definition.h"
21 
22 namespace OHOS {
23 namespace Location {
RequestConfig()24 RequestConfig::RequestConfig()
25 {
26     scenario_ = SCENE_UNSET;
27     priority_ = PRIORITY_FAST_FIRST_FIX;
28     timeInterval_ = 1; // no time interval limit for reporting location
29     distanceInterval_ = 0.0; // no distance interval limit for reporting location
30     maxAccuracy_ = 0.0; // no accuracy limit for reporting location
31     fixNumber_ = 0; // no fix size limit for reporting location
32     timeOut_ = DEFAULT_TIMEOUT_30S;
33 }
34 
RequestConfig(const int scenario)35 RequestConfig::RequestConfig(const int scenario) : scenario_(scenario)
36 {
37     priority_ = PRIORITY_UNSET;
38     timeInterval_ = 1; // no time interval limit for reporting location
39     distanceInterval_ = 0.0; // no distance interval limit for reporting location
40     maxAccuracy_ = 0.0; // no accuracy limit for reporting location
41     fixNumber_ = 0; // no fix size limit for reporting location
42     timeOut_ = DEFAULT_TIMEOUT_30S;
43 }
44 
Set(RequestConfig & requestConfig)45 void RequestConfig::Set(RequestConfig& requestConfig)
46 {
47     scenario_ = requestConfig.GetScenario();
48     priority_ = requestConfig.GetPriority();
49     timeInterval_ = requestConfig.GetTimeInterval();
50     distanceInterval_ = requestConfig.GetDistanceInterval();
51     maxAccuracy_ = requestConfig.GetMaxAccuracy();
52     fixNumber_ = requestConfig.GetFixNumber();
53 }
54 
IsSame(RequestConfig & requestConfig)55 bool RequestConfig::IsSame(RequestConfig& requestConfig)
56 {
57     if (scenario_ != requestConfig.GetScenario()) {
58         return false;
59     }
60     if (scenario_ != SCENE_UNSET) {
61         return true;
62     }
63     return priority_ == requestConfig.GetPriority();
64 }
65 
ReadFromParcel(Parcel & parcel)66 void RequestConfig::ReadFromParcel(Parcel& parcel)
67 {
68     scenario_ = parcel.ReadInt32();
69     priority_ = parcel.ReadInt32();
70     timeInterval_ = parcel.ReadInt32();
71     distanceInterval_ = parcel.ReadDouble();
72     maxAccuracy_ = parcel.ReadFloat();
73     fixNumber_ = parcel.ReadInt32();
74 }
75 
Unmarshalling(Parcel & parcel)76 std::unique_ptr<RequestConfig> RequestConfig::Unmarshalling(Parcel& parcel)
77 {
78     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
79     requestConfig->ReadFromParcel(parcel);
80     return requestConfig;
81 }
82 
Marshalling(Parcel & parcel) const83 bool RequestConfig::Marshalling(Parcel& parcel) const
84 {
85     return parcel.WriteInt32(scenario_) &&
86            parcel.WriteInt32(priority_) &&
87            parcel.WriteInt32(timeInterval_) &&
88            parcel.WriteDouble(distanceInterval_) &&
89            parcel.WriteFloat(maxAccuracy_) &&
90            parcel.WriteInt32(fixNumber_);
91 }
92 
ToString() const93 std::string RequestConfig::ToString() const
94 {
95     std::string str = "scenario : " + std::to_string(scenario_) +
96         ", location priority : " + std::to_string(priority_) +
97         ", timeInterval : " + std::to_string(timeInterval_) +
98         ", distanceInterval : " + std::to_string(distanceInterval_) +
99         ", maxAccuracy : " + std::to_string(maxAccuracy_) +
100         ", fixNumber : " + std::to_string(fixNumber_);
101     return str;
102 }
103 } // namespace Location
104 } // namespace OHOS