1bc2ed2b3Sopenharmony_ci/*
2bc2ed2b3Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.
3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License.
5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at
6bc2ed2b3Sopenharmony_ci *
7bc2ed2b3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8bc2ed2b3Sopenharmony_ci *
9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and
13bc2ed2b3Sopenharmony_ci * limitations under the License.
14bc2ed2b3Sopenharmony_ci */
15bc2ed2b3Sopenharmony_ci
16bc2ed2b3Sopenharmony_ci#ifndef NFC_NOTIFICATION_PUBLISHER_H
17bc2ed2b3Sopenharmony_ci#define NFC_NOTIFICATION_PUBLISHER_H
18bc2ed2b3Sopenharmony_ci
19bc2ed2b3Sopenharmony_ci#include <mutex>
20bc2ed2b3Sopenharmony_ci#include <string>
21bc2ed2b3Sopenharmony_ci
22bc2ed2b3Sopenharmony_ci#include "nfc_service.h"
23bc2ed2b3Sopenharmony_ci
24bc2ed2b3Sopenharmony_cinamespace OHOS {
25bc2ed2b3Sopenharmony_cinamespace NFC {
26bc2ed2b3Sopenharmony_cinamespace TAG {
27bc2ed2b3Sopenharmony_cienum NfcNotificationId : int {
28bc2ed2b3Sopenharmony_ci    NFC_TAG_DEFAULT_NOTIFICATION_ID = 114000,
29bc2ed2b3Sopenharmony_ci    NFC_BT_NOTIFICATION_ID = 114001,
30bc2ed2b3Sopenharmony_ci    NFC_WIFI_NOTIFICATION_ID = 114002,
31bc2ed2b3Sopenharmony_ci    NFC_TRANSPORT_CARD_NOTIFICATION_ID = 114003,
32bc2ed2b3Sopenharmony_ci    NFC_BROWSER_NOTIFICATION_ID = 114004,
33bc2ed2b3Sopenharmony_ci    NFC_HCE_AID_CONFLICTED_ID = 114005,
34bc2ed2b3Sopenharmony_ci    NFC_NO_HAP_SUPPORTED_NOTIFICATION_ID = 114006,
35bc2ed2b3Sopenharmony_ci};
36bc2ed2b3Sopenharmony_ci
37bc2ed2b3Sopenharmony_citypedef void (NfcNtfCallback)(int notificationId);
38bc2ed2b3Sopenharmony_ci
39bc2ed2b3Sopenharmony_cistruct NfcNtfInterface {
40bc2ed2b3Sopenharmony_ci    void (*publishNotification)(int notificationId, const std::string &name, int balance);
41bc2ed2b3Sopenharmony_ci    void (*regNtfCallback)(NfcNtfCallback *callback);
42bc2ed2b3Sopenharmony_ci};
43bc2ed2b3Sopenharmony_ci
44bc2ed2b3Sopenharmony_ciconstexpr const char* NFC_NTF_LIB_PATH = "libnfc_notification.z.so";
45bc2ed2b3Sopenharmony_ciconstexpr const char* REG_NFC_CALLBACK_FUNC_NAME = "RegNotificationCallback";
46bc2ed2b3Sopenharmony_ciconstexpr const char* PUBLISH_NTF_FUNC_NAME = "PublishNfcNotification";
47bc2ed2b3Sopenharmony_ci
48bc2ed2b3Sopenharmony_ciclass NfcNotificationPublisher {
49bc2ed2b3Sopenharmony_cipublic:
50bc2ed2b3Sopenharmony_ci    static NfcNotificationPublisher& GetInstance(void);
51bc2ed2b3Sopenharmony_ci
52bc2ed2b3Sopenharmony_ci    void PublishNfcNotification(int notificationId, const std::string &name, int balance);
53bc2ed2b3Sopenharmony_ci    void RegNotificationCallback(std::weak_ptr<NfcService> nfcService);
54bc2ed2b3Sopenharmony_ci    void OnNotificationButtonClicked(int notificationId);
55bc2ed2b3Sopenharmony_ci
56bc2ed2b3Sopenharmony_ciprivate:
57bc2ed2b3Sopenharmony_ci    NfcNotificationPublisher();
58bc2ed2b3Sopenharmony_ci    ~NfcNotificationPublisher();
59bc2ed2b3Sopenharmony_ci    NfcNotificationPublisher(const NfcNotificationPublisher&) = delete;
60bc2ed2b3Sopenharmony_ci    NfcNotificationPublisher& operator=(const NfcNotificationPublisher&) = delete;
61bc2ed2b3Sopenharmony_ci
62bc2ed2b3Sopenharmony_ci    void UnloadNfcNtfLib();
63bc2ed2b3Sopenharmony_ci    void InitNfcNtfLib();
64bc2ed2b3Sopenharmony_ci
65bc2ed2b3Sopenharmony_ci    const static int NOTIFICATION_WAIT_TIME_US = 150 * 1000;
66bc2ed2b3Sopenharmony_ci
67bc2ed2b3Sopenharmony_ci    std::mutex mutex_ {};
68bc2ed2b3Sopenharmony_ci    bool isNtfLibLoaded_ = false;
69bc2ed2b3Sopenharmony_ci    void *nfcNtfHandle_ {};
70bc2ed2b3Sopenharmony_ci    NfcNtfInterface nfcNtfInf_ {};
71bc2ed2b3Sopenharmony_ci    bool isInitialized_ = false;
72bc2ed2b3Sopenharmony_ci    std::weak_ptr<NfcService> nfcService_;
73bc2ed2b3Sopenharmony_ci};
74bc2ed2b3Sopenharmony_ci}  // namespace TAG
75bc2ed2b3Sopenharmony_ci}  // namespace NFC
76bc2ed2b3Sopenharmony_ci}  // namespace OHOS
77bc2ed2b3Sopenharmony_ci#endif  // NFC_NOTIFICATION_PUBLISHER_H
78