1 /* 2 * Copyright (c) 2023 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_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_CALLBACK_H 17 #define OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_CALLBACK_H 18 19 #include <chrono> 20 #include <iremote_object.h> 21 22 #include "auto_startup_callback_stub.h" 23 #include "auto_startup_info.h" 24 #include "native_engine/native_engine.h" 25 #include "native_engine/native_value.h" 26 #include "parcel.h" 27 28 class NativeReference; 29 namespace OHOS { 30 namespace AbilityRuntime { 31 /** 32 * 33 * @class JsAbilityAutoStartupCallBack 34 */ 35 class JsAbilityAutoStartupCallBack : public AutoStartupCallBackStub { 36 public: 37 explicit JsAbilityAutoStartupCallBack(napi_env env); 38 virtual ~JsAbilityAutoStartupCallBack(); 39 void Register(napi_value value); 40 void UnRegister(napi_value value); 41 void OnAutoStartupOn(const AutoStartupInfo &info) override; 42 void OnAutoStartupOff(const AutoStartupInfo &info) override; 43 bool IsCallbacksEmpty(); 44 45 private: 46 void JSCallFunction(const AutoStartupInfo &info, const std::string &methodName); 47 void JSCallFunctionWorker(const AutoStartupInfo &info, const std::string &methodName); 48 bool IsJsCallbackEquals(const std::shared_ptr<NativeReference> &callback, napi_value value); 49 50 napi_env env_; 51 std::vector<std::shared_ptr<NativeReference>> callbacks_; 52 std::mutex mutexlock_; 53 }; 54 } // namespace AbilityRuntime 55 } // namespace OHOS 56 #endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_CALLBACK_H 57