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 TELEPHONY_IMS_CORE_SERVICE_CLIENT_H
17 #define TELEPHONY_IMS_CORE_SERVICE_CLIENT_H
18 
19 #include "singleton.h"
20 #include "rwlock.h"
21 #include "ims_core_service_interface.h"
22 #include "event_handler.h"
23 #include "radio_event.h"
24 #include "event_runner.h"
25 #include "iremote_stub.h"
26 #include "system_ability_status_change_stub.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 class ImsCoreServiceClient {
31     DECLARE_DELAYED_SINGLETON(ImsCoreServiceClient);
32 
33 public:
34     void Init();
35     void UnInit();
36     int32_t RegisterImsCoreServiceCallbackHandler(
37         int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &handler);
38     std::shared_ptr<AppExecFwk::EventHandler> GetHandler(int32_t slotId);
39     int32_t GetImsRegistrationStatus(int32_t slotId);
40     int32_t GetPhoneNumberFromIMPU(int32_t slotId, std::string &phoneNumber);
41 
42 public:
43     sptr<ImsCoreServiceInterface> GetImsCoreServiceProxy();
44 
45 private:
46     class SystemAbilityListener : public SystemAbilityStatusChangeStub {
47     public:
SystemAbilityListener()48         SystemAbilityListener() {}
~SystemAbilityListener()49         ~SystemAbilityListener() {}
50     public:
51         void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
52         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
53     };
54 
55 private:
56     bool IsConnect() const;
57     int32_t RegisterImsCoreServiceCallback();
58     int32_t ReConnectService();
59     void Clean();
60 
61 private:
62     std::mutex mutex_;
63     sptr<ImsCoreServiceInterface> imsCoreServiceProxy_ = nullptr;
64     sptr<ImsCoreServiceCallbackInterface> imsCoreServiceCallback_ = nullptr;
65     std::map<int32_t, std::shared_ptr<AppExecFwk::EventHandler>> handlerMap_;
66     Utils::RWLock rwClientLock_;
67     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
68 };
69 } // namespace Telephony
70 } // namespace OHOS
71 #endif // TELEPHONY_IMS_CORE_SERVICE_CLIENT_H
72