1 /* 2 * Copyright (c) 2021 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_FORM_EXTENSION_CONTEXT_H 17 #define OHOS_ABILITY_RUNTIME_JS_FORM_EXTENSION_CONTEXT_H 18 19 #include <memory> 20 21 #include "form_extension_context.h" 22 #include "ability_connect_callback.h" 23 #include "event_handler.h" 24 #include "native_engine/native_engine.h" 25 26 namespace OHOS { 27 namespace AbilityRuntime { 28 napi_value CreateJsFormExtensionContext(napi_env env, std::shared_ptr<FormExtensionContext> context); 29 30 class JSFormExtensionConnection : public AbilityConnectCallback { 31 public: 32 explicit JSFormExtensionConnection(napi_env env); 33 ~JSFormExtensionConnection(); 34 void OnAbilityConnectDone( 35 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override; 36 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; 37 void HandleOnAbilityConnectDone( 38 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode); 39 void HandleOnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode); 40 void SetJsConnectionObject(napi_value jsConnectionObject); 41 void RemoveConnectionObject(); 42 void CallJsFailed(int32_t errorCode); 43 void SetConnectionId(int64_t id); 44 int64_t GetConnectionId(); 45 private: 46 napi_env env_; 47 std::unique_ptr<NativeReference> jsConnectionObject_ = nullptr; 48 int64_t connectionId_ = -1; 49 }; 50 51 struct ConnectionKey { 52 AAFwk::Want want; 53 int64_t id; 54 }; 55 56 struct key_compare { operatorkey_compare57 bool operator()(const ConnectionKey &key1, const ConnectionKey &key2) const 58 { 59 if (key1.id < key2.id) { 60 return true; 61 } 62 return false; 63 } 64 }; 65 } // namespace AbilityRuntime 66 } // namespace OHOS 67 #endif // OHOS_ABILITY_RUNTIME_JS_FORM_EXTENSION_CONTEXT_H 68