• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_CALL_CONTAINER_H
17 #define OHOS_ABILITY_RUNTIME_CALL_CONTAINER_H
18 
19 #include <map>
20 #include <string>
21 #include <mutex>
22 
23 #include "ability_connect_callback_interface.h"
24 #include "call_record.h"
25 #include "element_name.h"
26 #include "iremote_object.h"
27 #include "nocopyable.h"
28 
29 namespace OHOS {
30 namespace AAFwk {
31 class CallRecord;
32 /**
33  * @class CallContainer
34  * CallContainer provides a facility for managing the call records of ability.
35  */
36 class CallContainer : public std::enable_shared_from_this<CallContainer> {
37 public:
38     using CallMapType = std::map<sptr<IRemoteObject>, std::shared_ptr<CallRecord>>;
39     using RecipientMapType = std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>>;
40 
41     CallContainer();
42     virtual ~CallContainer();
43 
44     void AddCallRecord(const sptr<IAbilityConnection> & connect, const std::shared_ptr<CallRecord>& callRecord);
45     std::shared_ptr<CallRecord> GetCallRecord(const sptr<IAbilityConnection> & connect) const;
46     bool RemoveCallRecord(const sptr<IAbilityConnection> & connect);
47     bool CallRequestDone(const sptr<IRemoteObject> & callStub);
48     void Dump(std::vector<std::string> &info) const;
49     bool IsNeedToCallRequest() const;
50 
51 private:
52     void RemoveConnectDeathRecipient(const sptr<IAbilityConnection> &connect);
53     void AddConnectDeathRecipient(const sptr<IAbilityConnection> &connect);
54     void OnConnectionDied(const wptr<IRemoteObject> & remote);
55 
56 private:
57     CallMapType callRecordMap_;
58     RecipientMapType deathRecipientMap_;
59 
60     DISALLOW_COPY_AND_MOVE(CallContainer);
61 };
62 }  // namespace AAFwk
63 }  // namespace OHOS
64 #endif  // OHOS_ABILITY_RUNTIME_CALL_CONTAINER_H
65 
66