1 /*
2  * Copyright (c) 2023 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 BASE_NOTIFICATION_ANS_DIALOG_HOST_CLIENT_H
17 #define BASE_NOTIFICATION_ANS_DIALOG_HOST_CLIENT_H
18 
19 #include "ans_dialog_callback_stub.h"
20 
21 #include <memory>
22 #include <mutex>
23 #include <refbase.h>
24 
25 #include "ans_dialog_callback_native_interface.h"
26 
27 namespace OHOS::Notification {
28 class AnsDialogHostClient final : public AnsDialogCallbackStub {
29 public:
30     static bool IsNullptr();
31     static bool CreateIfNullptr(sptr<AnsDialogHostClient>& result);
32     static sptr<AnsDialogHostClient> GetInstance();
33     static void Destroy();
34     static bool SetDialogCallbackInterface(std::unique_ptr<AnsDialogCallbackNativeInterface> dialogCallbackInterface);
35 
36     virtual ~AnsDialogHostClient() = default;
37     DISALLOW_COPY_AND_MOVE(AnsDialogHostClient);
38 
39     void OnDialogStatusChanged(const DialogStatusData& statusData) override;
40 
41 private:
42     inline static sptr<AnsDialogHostClient> instance_ = nullptr;
43     inline static std::mutex instanceMutex_;
44     AnsDialogHostClient() = default;
45 
46     std::unique_ptr<AnsDialogCallbackNativeInterface> dialogCallbackInterface_ = nullptr;
47     std::atomic<bool> hasBeenCalled { false };
48 };
49 } // namespace OHOS::Notification
50 
51 #endif // BASE_NOTIFICATION_ANS_DIALOG_HOST_CLIENT_H
52