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