• 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 <list>
25 #include "napi/native_api.h"
26 #include "napi/native_node_api.h"
27 #include "cast_engine_log.h"
28 #include "cast_engine_common.h"
29 #include "napi_errors.h"
30 #include "cast_engine_errors.h"
31 #include "cast_session_manager.h"
32 #include "napi_cast_session_manager_listener.h"
33 
34 namespace OHOS {
35 namespace CastEngine {
36 namespace CastEngineClient {
37 class EXPORT NapiCastSessionManager {
38 public:
39     using OnEventHandlerType = std::function<napi_status(napi_env, napi_value)>;
40     using OffEventHandlerType = std::function<napi_status(napi_env, napi_value)>;
41 
42     static napi_value Init(napi_env env, napi_value exports);
43 
44 private:
45     static napi_value StartDiscovery(napi_env env, napi_callback_info info);
46     static napi_value StopDiscovery(napi_env env, napi_callback_info info);
47     static napi_value SetDiscoverable(napi_env env, napi_callback_info info);
48     static napi_value CreateCastSession(napi_env env, napi_callback_info info);
49     static napi_value Release(napi_env env, napi_callback_info info);
50 
51     static napi_value OnEvent(napi_env env, napi_callback_info info);
52     static napi_value OffEvent(napi_env env, napi_callback_info info);
53 
54     static napi_status OnServiceDied(napi_env env, napi_value callback);
55     static napi_status OnDeviceFound(napi_env env, napi_value callback);
56     static napi_status OnSessionCreated(napi_env env, napi_value callback);
57     static napi_status OnDeviceOffline(napi_env env, napi_value callback);
58 
59     static napi_status OffServiceDie(napi_env env, napi_value callback);
60     static napi_status OffDeviceFound(napi_env env, napi_value callback);
61     static napi_status OffSessionCreated(napi_env env, napi_value callback);
62     static napi_status OffDeviceOffline(napi_env env, napi_value callback);
63 
64     static napi_status RegisterNativeSessionManagerListener();
65     static std::map<std::string, std::pair<OnEventHandlerType, OffEventHandlerType>> eventHandlers_;
66     static std::shared_ptr<NapiCastSessionManagerListener> listener_;
67 };
68 } // namespace CastEngineClient
69 } // namespace CastEngine
70 } // namespace OHOS
71 #endif