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 #include "concurrent_map.h" 19 #include "visibility.h" 20 namespace DistributedDB { 21 struct AutoLaunchParam; 22 } 23 namespace OHOS { 24 class MessageParcel; 25 namespace DistributedData { 26 class API_EXPORT FeatureSystem { 27 public: 28 static constexpr int32_t STUB_SUCCESS = 0; 29 class API_EXPORT Feature { 30 public: 31 virtual ~Feature(); 32 virtual int OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply) = 0; 33 virtual int32_t OnInitialize(); 34 virtual int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName); 35 virtual int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); 36 virtual int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); 37 virtual int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); 38 virtual int32_t Online(const std::string &device); 39 virtual int32_t Offline(const std::string &device); 40 virtual int32_t OnReady(const std::string &device); 41 }; 42 using Creator = std::function<std::shared_ptr<Feature>()>; 43 static FeatureSystem &GetInstance(); 44 int32_t RegisterCreator(const std::string &name, Creator creator); 45 Creator GetCreator(const std::string &name); 46 47 private: 48 FeatureSystem() = default; 49 FeatureSystem(const FeatureSystem &) = delete; 50 FeatureSystem(FeatureSystem &&) noexcept = delete; 51 FeatureSystem &operator=(const FeatureSystem &) = delete; 52 FeatureSystem &operator=(FeatureSystem &&) = delete; 53 54 ConcurrentMap<std::string, Creator> creators_; 55 }; 56 } // namespace DistributedData 57 } 58 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORK_SYSTEM_SYSTEM_H 59