1 /* 2 * Copyright (c) 2020 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_BUNDLE_CALLBACK_H 17 #define OHOS_BUNDLE_CALLBACK_H 18 19 #include <string> 20 #include <string.h> 21 #include <algorithm> 22 #include <unordered_map> 23 #include <vector> 24 25 #include "appexecfwk_errors.h" 26 #include "bundle_callback_utils.h" 27 #include "ipc_skeleton.h" 28 #include "nocopyable.h" 29 30 namespace OHOS { 31 class BundleCallback { 32 public: 33 ~BundleCallback(); GetInstance()34 static BundleCallback& GetInstance() 35 { 36 static BundleCallback instance; 37 return instance; 38 } 39 40 int32_t RegisterBundleStateCallback(const BundleStateCallback &callback, const char *bundleName, void *data); 41 int32_t UnregisterBundleStateCallback(); 42 int32_t GenerateLocalServiceId(); 43 int32_t TransmitServiceId(const SvcIdentity &svc, bool flag); 44 BundleCallbackInfo GetCallbackInfoByName(const char *bundleName); 45 private: 46 BundleCallback() = default; 47 48 BundleStateCallback bundleStateCallback_ { nullptr }; // register callback for all apps 49 SvcIdentity *svcIdentity_ { nullptr }; 50 IpcObjectStub objectStub_ {}; 51 void *innerData_ { nullptr }; 52 std::unordered_map<std::string, BundleCallbackInfo> callbackMap_ {}; 53 54 DISALLOW_COPY_AND_MOVE(BundleCallback); 55 }; 56 } // namespace OHOS 57 #endif // OHOS_BUNDLE_CALLBACK_H