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 #ifndef FOUNDATION_ABILITY_FORM_FWK_SERVICES_INCLUDE_FORM_EVENT_HANDLER_H 17 #define FOUNDATION_ABILITY_FORM_FWK_SERVICES_INCLUDE_FORM_EVENT_HANDLER_H 18 19 #include <memory> 20 #include <set> 21 #include "event_handler.h" 22 #include "event_runner.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 namespace MSG { 27 const int64_t FORM_SHARE_INFO_DELAY_MSG = 1; 28 const int64_t FORM_PACKAGE_FREE_INSTALL_DELAY_MSG = 2; 29 } 30 31 class FormEventTimeoutObserver { 32 public: 33 FormEventTimeoutObserver() = default; 34 virtual ~FormEventTimeoutObserver() = default; 35 36 virtual void OnEventTimeoutResponse(int64_t msg, int64_t eventId) = 0; 37 }; 38 39 /** 40 * @class FormEventHandler 41 * FormEventHandler handling the form event. 42 */ 43 class FormEventHandler : public EventHandler { 44 public: 45 FormEventHandler(const std::shared_ptr<EventRunner> &runner); 46 virtual ~FormEventHandler() = default; 47 48 static int64_t GetEventId(); 49 50 /** 51 * Register event timeout observer. 52 * 53 * @param observer The observer of form event timeout. 54 */ 55 void RegisterEventTimeoutObserver(const std::shared_ptr<FormEventTimeoutObserver> &observer); 56 57 /** 58 * Unregister event timeout observer. 59 * 60 * @param observer The observer of form event timeout. 61 */ 62 void UnregisterEventTimeoutObserver(const std::shared_ptr<FormEventTimeoutObserver> &observer); 63 64 private: 65 /** 66 * ProcessEvent with request. 67 * 68 * @param event, inner event loop. 69 */ 70 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 71 72 private: 73 static int64_t eventId_; 74 std::set<std::shared_ptr<FormEventTimeoutObserver>> observers_; 75 mutable std::mutex observerMutex_; 76 }; 77 } // namespace AppExecFwk 78 } // namespace OHOS 79 #endif // FOUNDATION_ABILITY_FORM_FWK_SERVICES_INCLUDE_FORM_EVENT_HANDLER_H 80