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 16 #ifndef JS_COOPERATE_CONTEXT_H 17 #define JS_COOPERATE_CONTEXT_H 18 19 #include <memory> 20 21 #include "js_cooperate_manager.h" 22 #include "napi/native_node_api.h" 23 24 namespace OHOS { 25 namespace Msdp { 26 namespace DeviceStatus { 27 class JsCooperateContext final { 28 public: 29 JsCooperateContext(); 30 DISALLOW_COPY_AND_MOVE(JsCooperateContext); 31 ~JsCooperateContext(); 32 33 static napi_value Export(napi_env env, napi_value exports); 34 static napi_value Enable(napi_env env, napi_callback_info info); 35 static napi_value Start(napi_env env, napi_callback_info info); 36 static napi_value Stop(napi_env env, napi_callback_info info); 37 static napi_value GetState(napi_env env, napi_callback_info info); 38 static napi_value On(napi_env env, napi_callback_info info); 39 static napi_value Off(napi_env env, napi_callback_info info); 40 41 std::shared_ptr<JsCooperateManager> GetJsCoordinationMgr(); 42 43 private: 44 static napi_value CreateInstance(napi_env env); 45 static napi_value JsConstructor(napi_env env, napi_callback_info info); 46 static JsCooperateContext *GetInstance(napi_env env); 47 static void DeclareDeviceCoordinationInterface(napi_env env, napi_value exports); 48 static void DeclareDeviceCoordinationData(napi_env env, napi_value exports); 49 static napi_value EnumClassConstructor(napi_env env, napi_callback_info info); 50 51 std::shared_ptr<JsCooperateManager> mgr_ { nullptr }; 52 std::mutex mutex_; 53 napi_ref contextRef_ { nullptr }; 54 }; 55 } // namespace DeviceStatus 56 } // namespace Msdp 57 } // namespace OHOS 58 #endif // JS_COOPERATE_CONTEXT_H 59