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 #ifndef NAPI_AUDIO_CAPTURER_INFO_CHANGE_CALLBACK_H
16 #define NAPI_AUDIO_CAPTURER_INFO_CHANGE_CALLBACK_H
17 
18 #include <uv.h>
19 #include <list>
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 #include "napi_async_work.h"
23 #include "audio_capturer.h"
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 class NapiAudioCapturerInfoChangeCallback : public AudioCapturerInfoChangeCallback {
28 public:
29     explicit NapiAudioCapturerInfoChangeCallback(napi_env env);
30     virtual ~NapiAudioCapturerInfoChangeCallback();
31     void SaveCallbackReference(napi_value args);
32     void OnStateChange(const AudioCapturerChangeInfo &capturerChangeInfo) override;
33     bool ContainSameJsCallback(napi_value args);
34 
35 private:
36     struct AudioCapturerChangeInfoJsCallback {
37         napi_ref callback_;
38         napi_env env_;
39         AudioCapturerChangeInfo capturerChangeInfo_;
40     };
41 
42     static void WorkCallbackCompleted(uv_work_t* work, int status);
43     void OnJsCallbackCapturerChangeInfo(napi_ref method, const AudioCapturerChangeInfo &capturerChangeInfo);
44 
45     std::mutex mutex_;
46     napi_env env_ = nullptr;
47     napi_ref callback_ = nullptr;
48 };
49 }  // namespace AudioStandard
50 }  // namespace OHOS
51 #endif /* NAPI_AUDIO_CAPTURER_INFO_CHANGE_CALLBACK_H */