• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef LOCATION_DATA_MANAGER_H
17 #define LOCATION_DATA_MANAGER_H
18 
19 #include <map>
20 #include <singleton.h>
21 #include "iremote_object.h"
22 #include "constant_definition.h"
23 #include "i_switch_callback.h"
24 #include "common_utils.h"
25 
26 namespace OHOS {
27 namespace Location {
28 class LocationDataManager : public DelayedSingleton<LocationDataManager> {
29 public:
30     LocationDataManager();
31     ~LocationDataManager();
32     LocationErrCode ReportSwitchState(bool isEnabled);
33     LocationErrCode RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid);
34     LocationErrCode UnregisterSwitchCallback(const sptr<IRemoteObject>& callback);
35     LocationErrCode QuerySwitchState(bool &isEnabled);
36     void SetCachedSwitchState(int32_t state);
37     bool IsSwitchStateReg();
38 private:
39     std::mutex mutex_;
40     std::mutex switchStateMutex_;
41     std::unique_ptr<std::map<pid_t, sptr<ISwitchCallback>>> switchCallbacks_;
42     int32_t cachedSwitchState_ = DISABLED;
43     bool isStateCached_ = false;
44 };
45 }  // namespace Location
46 }  // namespace OHOS
47 #endif // LOCATION_DATA_MANAGER_H
48