• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "want.h"
24 
25 namespace OHOS {
26 namespace AbilityRuntime {
27 struct CJAbilityConnectCallbackFuncs {
28     void (*onConnect)(int64_t id, ElementNameHandle elementNameHandle, int64_t remoteObjectId, int32_t resultCode);
29     void (*onDisconnect)(int64_t id, ElementNameHandle elementNameHandle, int32_t resultCode);
30     void (*release)(int64_t id);
31     void (*onFailed)(int64_t id, int32_t resultCode);
32 };
33 
34 extern "C" {
35 #define EXPORT __attribute__((visibility("default")))
36 EXPORT void RegisterCJAbilityConnectCallbackFuncs(void (*registerFunc)(CJAbilityConnectCallbackFuncs* result));
37 #undef EXPORT
38 };
39 
40 class CJAbilityConnectCallback : public AbilityConnectCallback {
41 public:
CJAbilityConnectCallback(int64_t id)42     explicit CJAbilityConnectCallback(int64_t id) : callbackId_(id) {};
43     ~CJAbilityConnectCallback() override;
44 
45     static sptr<CJAbilityConnectCallback> Create(int64_t id, AAFwk::Want& want);
46     static void Remove(int64_t connectId);
47     static void FindConnection(AAFwk::Want& want, sptr<CJAbilityConnectCallback>& connection, int64_t connectId);
48 
49     void OnAbilityConnectDone(
50         const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int resultCode) override;
51     void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override;
52     void OnFailed(int32_t resultCode);
53 
SetConnectionId(int64_t connectId)54     void SetConnectionId(int64_t connectId)
55     {
56         connectId_ = connectId;
57     }
GetConnectionId()58     int64_t GetConnectionId()
59     {
60         return connectId_;
61     }
62 private:
63     int64_t callbackId_ = 0;
64     int64_t connectId_ = 0;
65 };
66 } // namespace AbilityRuntime
67 } // namespace OHOS
68 
69 #endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_CONNECT_CALLBACK_OBJECT_H
70