1 /*
2  * Copyright (c) 2024 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_CJ_ABILITY_CONNECT_CALLBACK_OBJECT_H
17 #define OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONNECT_CALLBACK_OBJECT_H
18 
19 #include <cstdint>
20 
21 #include "ability_connect_callback.h"
22 #include "cj_element_name_ffi.h"
23 
24 extern "C" {
25 struct CJAbilityConnectCallbackFuncs {
26     void (*onConnect)(int64_t id, ElementNameHandle elementNameHandle, int64_t remoteObjectId, int32_t resultCode);
27     void (*onDisconnect)(int64_t id, ElementNameHandle elementNameHandle, int32_t resultCode);
28     void (*release)(int64_t id);
29 };
30 
31 #define EXPORT __attribute__((visibility("default")))
32 EXPORT void RegisterCJAbilityConnectCallbackFuncs(void (*registerFunc)(CJAbilityConnectCallbackFuncs* result));
33 #undef EXPORT
34 };
35 
36 namespace OHOS {
37 namespace AbilityRuntime {
38 class CJAbilityConnectCallback : public AbilityConnectCallback {
39 public:
CJAbilityConnectCallback(int64_t id)40     explicit CJAbilityConnectCallback(int64_t id) : callbackId_(id) {};
41     ~CJAbilityConnectCallback() override;
42 
43     void OnAbilityConnectDone(
44         const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int resultCode) override;
45     void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override;
46 
47 private:
48     int64_t callbackId_ = 0;
49 };
50 } // namespace AbilityRuntime
51 } // namespace OHOS
52 
53 #endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONNECT_CALLBACK_OBJECT_H
54