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 #ifndef OHOS_DISTRIBUTED_DATA_FRAMEWORK_SYSTEM_SYSTEM_H 16 #define OHOS_DISTRIBUTED_DATA_FRAMEWORK_SYSTEM_SYSTEM_H 17 #include <memory> 18 19 #include "concurrent_map.h" 20 #include "error/general_error.h" 21 #include "executor_pool.h" 22 #include "static_acts.h" 23 #include "visibility.h" 24 namespace DistributedDB { 25 struct AutoLaunchParam; 26 } 27 namespace OHOS { 28 class MessageParcel; 29 namespace DistributedData { 30 class API_EXPORT FeatureSystem { 31 public: 32 using Error = GeneralError; 33 inline static constexpr int32_t STUB_SUCCESS = Error::E_OK; 34 enum BindFlag : int32_t { 35 BIND_LAZY, 36 BIND_NOW 37 }; 38 class API_EXPORT Feature { 39 public: 40 struct BindInfo { 41 std::string selfName; 42 uint32_t selfTokenId; 43 std::shared_ptr<ExecutorPool> executors; 44 }; 45 virtual ~Feature(); 46 virtual int OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply) = 0; 47 virtual int32_t OnInitialize(); 48 virtual int32_t OnBind(const BindInfo &bindInfo); 49 virtual int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName); 50 virtual int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index); 51 virtual int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index); 52 virtual int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index); 53 virtual int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); 54 virtual int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); 55 virtual int32_t Online(const std::string &device); 56 virtual int32_t Offline(const std::string &device); 57 virtual int32_t OnReady(const std::string &device); 58 virtual int32_t OnSessionReady(const std::string &device); 59 virtual int32_t OnScreenUnlocked(int32_t user); 60 }; 61 using Creator = std::function<std::shared_ptr<Feature>()>; 62 static FeatureSystem &GetInstance(); 63 int32_t RegisterCreator(const std::string &name, Creator creator, int32_t flag = BIND_LAZY); 64 Creator GetCreator(const std::string &name); 65 int32_t RegisterStaticActs(const std::string &name, std::shared_ptr<StaticActs> staticActs); 66 const ConcurrentMap<std::string, std::shared_ptr<StaticActs>> &GetStaticActs(); 67 std::vector<std::string> GetFeatureName(int32_t flag); 68 69 private: 70 FeatureSystem() = default; 71 FeatureSystem(const FeatureSystem &) = delete; 72 FeatureSystem(FeatureSystem &&) noexcept = delete; 73 FeatureSystem &operator=(const FeatureSystem &) = delete; 74 FeatureSystem &operator=(FeatureSystem &&) = delete; 75 76 ConcurrentMap<std::string, std::pair<Creator, int32_t>> creators_; 77 ConcurrentMap<std::string, std::shared_ptr<StaticActs>> staticActs_; 78 }; 79 } // namespace DistributedData 80 } 81 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORK_SYSTEM_SYSTEM_H 82