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_ABILITY_THREAD_CLIENT_H
17 #define OHOS_ABILITY_THREAD_CLIENT_H
18 
19 #include "bundle_info.h"
20 #include "ipc_skeleton.h"
21 #include "util/abilityms_status.h"
22 #include "want.h"
23 
24 namespace OHOS {
25 typedef struct {
26     uint64_t token;
27     int32_t state;
28 } TransactionState;
29 
30 typedef struct {
31     char *bundleName;
32     SvcIdentity svcIdentity;
33 } AppInfo;
34 
35 class AbilityRecord;
36 class AbilityThreadClient {
37 public:
38     AbilityThreadClient(uint64_t token, pid_t callingPid, const SvcIdentity &svcIdentity, OnRemoteDead handler);
39     AbilityThreadClient(const AbilityThreadClient &client);
40     ~AbilityThreadClient();
41 
42     AbilityMsStatus Initialize(const char *bundleName);
43     uint64_t GetToken() const;
44     pid_t GetPid() const;
45     const SvcIdentity &GetSvcIdentity() const;
46     AbilityMsStatus AbilityTransaction(const TransactionState &state, const Want &want, AbilityType abilityType) const;
47     AbilityMsStatus AppInitTransaction(const BundleInfo &bundleInfo);
48     AbilityMsStatus AppExitTransaction();
49     AbilityMsStatus ConnectAbility(const Want &want, uint64_t token) const;
50     AbilityMsStatus DisconnectAbility(const Want &want, uint64_t token) const;
51     AbilityMsStatus ConnectAbilityDone(const Want &want, const SvcIdentity &serviceSid,
52         const SvcIdentity &connectSid) const;
53     AbilityMsStatus DisconnectAbilityDone(const Want &want, const SvcIdentity &connectSid) const;
54     AbilityMsStatus DumpAbilityTransaction(const Want &want, uint64_t token);
55 private:
56     uint64_t token_ = -1;
57     pid_t pid_ = -1;
58     uint32_t cbid_ = -1;
59     const SvcIdentity svcIdentity_;
60     const OnRemoteDead deathHandler_;
61     static const int MAX_OBJECTS = 2;
62 };
63 } // namespace OHOS
64 #endif // OHOS_ABILITY_THREAD_CLIENT_H
65