• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-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  * Description: supply napi interface for cast session manager.
15  * Author: zhangjingnan
16  * Create: 2022-7-11
17  */
18 
19 #ifndef NAPI_CAST_SESSION_MANAGER_H_
20 #define NAPI_CAST_SESSION_MANAGER_H_
21 
22 #include <map>
23 #include <memory>
24 #include <mutex>
25 #include <list>
26 #include "napi/native_api.h"
27 #include "napi/native_node_api.h"
28 #include "cast_engine_log.h"
29 #include "cast_engine_common.h"
30 #include "napi_errors.h"
31 #include "cast_engine_errors.h"
32 #include "cast_session_manager.h"
33 #include "napi_cast_session_manager_listener.h"
34 
35 namespace OHOS {
36 namespace CastEngine {
37 namespace CastEngineClient {
38 class EXPORT NapiCastSessionManager {
39 public:
40     using OnEventHandlerType = std::function<napi_status(napi_env, napi_value)>;
41     using OffEventHandlerType = std::function<napi_status(napi_env, napi_value)>;
42 
43     static napi_value Init(napi_env env, napi_value exports);
44 
45 private:
46     static napi_value StartDiscovery(napi_env env, napi_callback_info info);
47     static napi_value StopDiscovery(napi_env env, napi_callback_info info);
48     static napi_value SetDiscoverable(napi_env env, napi_callback_info info);
49     static napi_value CreateCastSession(napi_env env, napi_callback_info info);
50     static napi_value Release(napi_env env, napi_callback_info info);
51 
52     static napi_value OnEvent(napi_env env, napi_callback_info info);
53     static napi_value OffEvent(napi_env env, napi_callback_info info);
54 
55     static napi_status OnServiceDied(napi_env env, napi_value callback);
56     static napi_status OnDeviceFound(napi_env env, napi_value callback);
57     static napi_status OnSessionCreated(napi_env env, napi_value callback);
58     static napi_status OnDeviceOffline(napi_env env, napi_value callback);
59 
60     static napi_status OffServiceDie(napi_env env, napi_value callback);
61     static napi_status OffDeviceFound(napi_env env, napi_value callback);
62     static napi_status OffSessionCreated(napi_env env, napi_value callback);
63     static napi_status OffDeviceOffline(napi_env env, napi_value callback);
64 
65     static napi_status RegisterNativeSessionManagerListener();
66     static napi_status UnRegisterNativeSessionManagerListener();
67 
68     static std::mutex mutex_;
69     static std::map<std::string, std::pair<OnEventHandlerType, OffEventHandlerType>> eventHandlers_;
70     static std::shared_ptr<NapiCastSessionManagerListener> listener_;
71 };
72 } // namespace CastEngineClient
73 } // namespace CastEngine
74 } // namespace OHOS
75 #endif