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 OHOS_GLOBAL_I18N_I18N_SERVICE_EVENT_H 17 #define OHOS_GLOBAL_I18N_I18N_SERVICE_EVENT_H 18 19 #include <functional> 20 #include <memory> 21 #include <singleton.h> 22 #include <string> 23 #include <unordered_map> 24 #include "common_event_subscriber.h" 25 #include "system_ability.h" 26 #include "want.h" 27 28 namespace OHOS { 29 namespace Global { 30 namespace I18n { 31 class I18nServiceEvent { 32 public: 33 I18nServiceEvent(); 34 ~I18nServiceEvent(); 35 36 void CheckStartReason(const SystemAbilityOnDemandReason& startReason); 37 void SubscriberEvent(); 38 void OnReceiveEvent(const EventFwk::CommonEventData& data); 39 40 private: 41 class I18nServiceSubscriber : public EventFwk::CommonEventSubscriber { 42 public: I18nServiceSubscriber(const EventFwk::CommonEventSubscribeInfo& subscribeInfo, I18nServiceEvent& registry)43 explicit I18nServiceSubscriber(const EventFwk::CommonEventSubscribeInfo& subscribeInfo, 44 I18nServiceEvent& registry) : CommonEventSubscriber(subscribeInfo), registry_(registry) 45 {} 46 47 ~I18nServiceSubscriber() = default; 48 49 void OnReceiveEvent(const EventFwk::CommonEventData& data) override 50 { 51 registry_.OnReceiveEvent(data); 52 } 53 54 private: 55 I18nServiceEvent& registry_; 56 }; 57 58 void HandleMultiUser(const std::string& action, const std::string& localId); 59 60 std::shared_ptr<I18nServiceSubscriber> subscriber = nullptr; 61 static const int RETRY; 62 }; 63 } // namespace I18n 64 } // namespace Global 65 } // namespace OHOS 66 #endif // OHOS_GLOBAL_I18N_I18N_SERVICE_EVENT_H