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_SERVICE_MANAGER_H
17 #define OHOS_ABILITY_SERVICE_MANAGER_H
18 
19 #include "ability_connection.h"
20 
21 #include <list>
22 #include <mutex>
23 
24 #include "nocopyable.h"
25 #include "want.h"
26 
27 namespace OHOS {
28 typedef struct {
29     const IAbilityConnection *conn;
30     void *storeArg;
31     SvcIdentity *sid;
32 } StoreArgs;
33 
34 class AbilityServiceManager {
35 public:
GetInstance()36     static AbilityServiceManager &GetInstance()
37     {
38         static AbilityServiceManager instance;
39         return instance;
40     }
41     ~AbilityServiceManager();
42     int ConnectAbility(const Want &want, const IAbilityConnection &conn, uint64_t token, void *storeArg);
43     int DisconnectAbility(const IAbilityConnection &conn, uint64_t token);
44 
45 private:
46     AbilityServiceManager() = default;
47     StoreArgs *AddStoreArgs(const IAbilityConnection &conn, void *storeArg);
48     StoreArgs *GetStoreArgs(const IAbilityConnection &conn) const;
49     StoreArgs *RemoveStoreArgs(const IAbilityConnection *conn, StoreArgs *storeArgs);
50     static int32_t ConnectAbilityCallBack(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option);
51     static void ClearStore(StoreArgs *storeArgs);
52     std::list<StoreArgs *> storeList_;
53     std::mutex mutex_;
54     IpcObjectStub objectStub_;
55 
56     DISALLOW_COPY_AND_MOVE(AbilityServiceManager);
57 };
58 } // namespace OHOS
59 
60 #endif // OHOS_ABILITY_SERVICE_MANAGER_H
61