1/*
2 * Copyright (C) 2024 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 NFC_NOTIFICATION_PUBLISHER_H
17#define NFC_NOTIFICATION_PUBLISHER_H
18
19#include <mutex>
20#include <string>
21
22#include "nfc_service.h"
23
24namespace OHOS {
25namespace NFC {
26namespace TAG {
27enum NfcNotificationId : int {
28    NFC_TAG_DEFAULT_NOTIFICATION_ID = 114000,
29    NFC_BT_NOTIFICATION_ID = 114001,
30    NFC_WIFI_NOTIFICATION_ID = 114002,
31    NFC_TRANSPORT_CARD_NOTIFICATION_ID = 114003,
32    NFC_BROWSER_NOTIFICATION_ID = 114004,
33    NFC_HCE_AID_CONFLICTED_ID = 114005,
34    NFC_NO_HAP_SUPPORTED_NOTIFICATION_ID = 114006,
35};
36
37typedef void (NfcNtfCallback)(int notificationId);
38
39struct NfcNtfInterface {
40    void (*publishNotification)(int notificationId, const std::string &name, int balance);
41    void (*regNtfCallback)(NfcNtfCallback *callback);
42};
43
44constexpr const char* NFC_NTF_LIB_PATH = "libnfc_notification.z.so";
45constexpr const char* REG_NFC_CALLBACK_FUNC_NAME = "RegNotificationCallback";
46constexpr const char* PUBLISH_NTF_FUNC_NAME = "PublishNfcNotification";
47
48class NfcNotificationPublisher {
49public:
50    static NfcNotificationPublisher& GetInstance(void);
51
52    void PublishNfcNotification(int notificationId, const std::string &name, int balance);
53    void RegNotificationCallback(std::weak_ptr<NfcService> nfcService);
54    void OnNotificationButtonClicked(int notificationId);
55
56private:
57    NfcNotificationPublisher();
58    ~NfcNotificationPublisher();
59    NfcNotificationPublisher(const NfcNotificationPublisher&) = delete;
60    NfcNotificationPublisher& operator=(const NfcNotificationPublisher&) = delete;
61
62    void UnloadNfcNtfLib();
63    void InitNfcNtfLib();
64
65    const static int NOTIFICATION_WAIT_TIME_US = 150 * 1000;
66
67    std::mutex mutex_ {};
68    bool isNtfLibLoaded_ = false;
69    void *nfcNtfHandle_ {};
70    NfcNtfInterface nfcNtfInf_ {};
71    bool isInitialized_ = false;
72    std::weak_ptr<NfcService> nfcService_;
73};
74}  // namespace TAG
75}  // namespace NFC
76}  // namespace OHOS
77#endif  // NFC_NOTIFICATION_PUBLISHER_H
78