• 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_5S;
33     timestamp_ = 0;
34     isNeedPoi_ = false;
35     isNeedLocation_ = true;
36 }
37 
RequestConfig(const int scenario)38 RequestConfig::RequestConfig(const int scenario) : scenario_(scenario)
39 {
40     priority_ = PRIORITY_UNSET;
41     timeInterval_ = 1; // no time interval limit for reporting location
42     distanceInterval_ = 0.0; // no distance interval limit for reporting location
43     maxAccuracy_ = 0.0; // no accuracy limit for reporting location
44     fixNumber_ = 0; // no fix size limit for reporting location
45     timeOut_ = DEFAULT_TIMEOUT_5S;
46     timestamp_ = 0;
47     isNeedPoi_ = false;
48     isNeedLocation_ = true;
49 }
50 
Set(RequestConfig & requestConfig)51 void RequestConfig::Set(RequestConfig& requestConfig)
52 {
53     scenario_ = requestConfig.GetScenario();
54     priority_ = requestConfig.GetPriority();
55     timeInterval_ = requestConfig.GetTimeInterval();
56     distanceInterval_ = requestConfig.GetDistanceInterval();
57     maxAccuracy_ = requestConfig.GetMaxAccuracy();
58     fixNumber_ = requestConfig.GetFixNumber();
59     timeOut_ = requestConfig.GetTimeOut();
60     timestamp_ = requestConfig.GetTimeStamp();
61     isNeedPoi_ = requestConfig.GetIsNeedPoi();
62     isNeedLocation_ = requestConfig.GetIsNeedLocation();
63 }
64 
IsSame(RequestConfig & requestConfig)65 bool RequestConfig::IsSame(RequestConfig& requestConfig)
66 {
67     if (scenario_ != requestConfig.GetScenario()) {
68         return false;
69     }
70     if (scenario_ != SCENE_UNSET) {
71         return true;
72     }
73     return priority_ == requestConfig.GetPriority();
74 }
75 
ReadFromParcel(Parcel & parcel)76 void RequestConfig::ReadFromParcel(Parcel& parcel)
77 {
78     scenario_ = parcel.ReadInt32();
79     priority_ = parcel.ReadInt32();
80     timeInterval_ = parcel.ReadInt32();
81     distanceInterval_ = parcel.ReadDouble();
82     maxAccuracy_ = parcel.ReadFloat();
83     fixNumber_ = parcel.ReadInt32();
84     timeOut_ = parcel.ReadInt32();
85     isNeedPoi_ = parcel.ReadBool();
86     isNeedLocation_ = parcel.ReadBool();
87 }
88 
Unmarshalling(Parcel & parcel)89 RequestConfig* RequestConfig::Unmarshalling(Parcel& parcel)
90 {
91     auto requestConfig = new RequestConfig();
92     requestConfig->ReadFromParcel(parcel);
93     return requestConfig;
94 }
95 
Marshalling(Parcel & parcel) const96 bool RequestConfig::Marshalling(Parcel& parcel) const
97 {
98     return parcel.WriteInt32(scenario_) &&
99            parcel.WriteInt32(priority_) &&
100            parcel.WriteInt32(timeInterval_) &&
101            parcel.WriteDouble(distanceInterval_) &&
102            parcel.WriteFloat(maxAccuracy_) &&
103            parcel.WriteInt32(fixNumber_) &&
104            parcel.WriteInt32(timeOut_) &&
105            parcel.WriteBool(isNeedPoi_) &&
106            parcel.WriteBool(isNeedLocation_);
107 }
108 
IsRequestForAccuracy()109 bool RequestConfig::IsRequestForAccuracy()
110 {
111     if (priority_ == LOCATION_PRIORITY_ACCURACY ||
112         (scenario_ == SCENE_UNSET && priority_ == PRIORITY_ACCURACY) ||
113         scenario_ == SCENE_NAVIGATION ||
114         scenario_ == SCENE_TRAJECTORY_TRACKING ||
115         scenario_ == SCENE_CAR_HAILING) {
116         return true;
117     } else {
118         return false;
119     }
120 }
121 
ToString() const122 std::string RequestConfig::ToString() const
123 {
124     std::string str = "scenario : " + std::to_string(scenario_) +
125         ", location priority : " + std::to_string(priority_) +
126         ", timeInterval : " + std::to_string(timeInterval_) +
127         ", distanceInterval : " + std::to_string(distanceInterval_) +
128         ", maxAccuracy : " + std::to_string(maxAccuracy_) +
129         ", fixNumber : " + std::to_string(fixNumber_) +
130         ", timeOut : " + std::to_string(timeOut_) +
131         ", isNeedPoiInfomation : " + std::to_string(isNeedPoi_) +
132         ", isNeedLocation : " + std::to_string(isNeedLocation_);
133     return str;
134 }
135 } // namespace Location
136 } // namespace OHOS