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 using SelfRequestManagerEventHandle = std::function<void(const AppExecFwk::InnerEvent::Pointer &)>; 34 using SelfRequestManagerEventHandleMap = std::map<int, SelfRequestManagerEventHandle>; 35 explicit SelfRequestManagerHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner); 36 ~SelfRequestManagerHandler() override; 37 private: 38 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; 39 void InitSelfRequestManagerHandlerEventMap(); 40 void StartLocatingEvent(const AppExecFwk::InnerEvent::Pointer& event); 41 void StopLocatingEvent(const AppExecFwk::InnerEvent::Pointer& event); 42 43 SelfRequestManagerEventHandleMap selfRequestManagerHandlerEventMap_; 44 }; 45 46 class SelfRequestManager { 47 public: 48 static SelfRequestManager* GetInstance(); 49 SelfRequestManager(); 50 ~SelfRequestManager(); 51 void StartSelfRequest(const std::shared_ptr<Request>& request); 52 void StopSelfRequest(); 53 void ProcessStartSelfRequestEvent(const std::shared_ptr<Request>& request); 54 void ProcessStopSelfRequestEvent(); 55 class mLocatorCallback : public IRemoteStub<ILocatorCallback> { 56 public: 57 void OnLocationReport(const std::unique_ptr<Location>& location); 58 void OnLocatingStatusChange(const int status); 59 void OnErrorReport(const int errorCode); 60 }; 61 62 bool isLocating_ = false; 63 sptr<ILocatorCallback> callback_; 64 std::shared_ptr<Request> request_; 65 static std::mutex locatorMutex_; 66 std::shared_ptr<SelfRequestManagerHandler> selfRequestManagerHandler_; 67 }; 68 } // namespace Location 69 } // namespace OHOS 70 #endif // SELF_REQUEST_MANAGER_H 71