1 /* 2 * Copyright (C) 2024 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 SELF_REQUEST_MANAGER_H 17 #define SELF_REQUEST_MANAGER_H 18 19 #include <map> 20 #include <singleton.h> 21 #include <string> 22 #include "event_handler.h" 23 #include "event_runner.h" 24 25 #include "i_locator_callback.h" 26 #include "request.h" 27 #include "iremote_stub.h" 28 29 namespace OHOS { 30 namespace Location { 31 class SelfRequestManagerHandler : public AppExecFwk::EventHandler { 32 public: 33 explicit SelfRequestManagerHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner); 34 ~SelfRequestManagerHandler() override; 35 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; 36 }; 37 38 class SelfRequestManager { 39 public: 40 static SelfRequestManager* GetInstance(); 41 SelfRequestManager(); 42 ~SelfRequestManager(); 43 void StartSelfRequest(); 44 void StopSelfRequest(); 45 void ProcessStartSelfRequestEvent(); 46 void ProcessStopSelfRequestEvent(); 47 class mLocatorCallback : public IRemoteStub<ILocatorCallback> { 48 public: 49 void OnLocationReport(const std::unique_ptr<Location>& location); 50 void OnLocatingStatusChange(const int status); 51 void OnErrorReport(const int errorCode); 52 }; 53 54 bool isLocating_ = false; 55 bool locationSwitch_ = false; 56 sptr<ILocatorCallback> callback_; 57 std::shared_ptr<Request> request_; 58 static std::mutex locatorMutex_; 59 std::shared_ptr<SelfRequestManagerHandler> selfRequestManagerHandler_; 60 }; 61 } // namespace Location 62 } // namespace OHOS 63 #endif // SELF_REQUEST_MANAGER_H 64