1 /* 2 * Copyright (C) 2021-2022 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 NATIVE_CALL_MANAGER_UTILS_H 17 #define NATIVE_CALL_MANAGER_UTILS_H 18 19 #include "napi/native_api.h" 20 #include "napi/native_node_api.h" 21 #include "napi_call_manager_types.h" 22 #include "string_ex.h" 23 #include "telephony_napi_common_error.h" 24 25 namespace OHOS { 26 namespace Telephony { 27 enum { 28 CALL_MANAGER_UNKNOWN_EVENT = 0, 29 CALL_MANAGER_DIAL_CALL, 30 CALL_MANAGER_ANSWER_CALL, 31 CALL_MANAGER_REJECT_CALL, 32 CALL_MANAGER_DISCONNECT_CALL, 33 CALL_MANAGER_HOLD_CALL, 34 CALL_MANAGER_UNHOLD_CALL, 35 CALL_MANAGER_SWITCH_CALL, 36 CALL_MANAGER_GET_CALL_WAITING, 37 CALL_MANAGER_SET_CALL_WAITING, 38 CALL_MANAGER_GET_CALL_RESTRICTION, 39 CALL_MANAGER_SET_CALL_RESTRICTION, 40 CALL_MANAGER_GET_CALL_TRANSFER, 41 CALL_MANAGER_SET_CALL_TRANSFER, 42 CALL_MANAGER_ENABLE_IMS_SWITCH, 43 CALL_MANAGER_DISABLE_IMS_SWITCH, 44 CALL_MANAGER_IS_EMERGENCY_CALL, 45 CALL_MANAGER_IS_RINGING, 46 CALL_MANAGER_MUTE_RINGER, 47 }; 48 49 /** 50 * call_manager NAPI utility class. 51 */ 52 class NapiCallManagerUtils { 53 public: 54 static bool MatchValueType(napi_env env, napi_value value, napi_valuetype targetType); 55 static napi_value CreateUndefined(napi_env env); 56 static napi_value CreateErrorMessage(napi_env env, std::string msg); 57 static napi_value CreateErrorMessageWithErrorCode( 58 napi_env env, std::string message, int32_t errorCode = ERROR_DEFAULT); 59 static napi_value ToInt32Value(napi_env env, int32_t value); 60 static napi_value GetNamedProperty(napi_env env, napi_value object, const std::string &propertyName); 61 static std::string GetStringProperty(napi_env env, napi_value object, const std::string &propertyName); 62 static int32_t GetIntProperty(napi_env env, napi_value object, const std::string &propertyName); 63 static bool GetUssdIntProperty(napi_env env, napi_value object, const std::string &propertyName, int32_t &result); 64 static bool GetUssdStringProperty( 65 napi_env env, napi_value object, const std::string &propertyName, std::string &result); 66 static bool GetBoolProperty(napi_env env, napi_value object, const std::string &propertyName); 67 static void SetPropertyInt32(napi_env env, napi_value object, std::string name, int32_t value); 68 static void SetPropertyStringUtf8(napi_env env, napi_value object, std::string name, std::string value); 69 static void SetPropertyBoolean(napi_env env, napi_value object, std::string name, int32_t value); 70 static napi_value CreateEnumConstructor(napi_env env, napi_callback_info info); 71 static napi_value CreateErrorCodeAndMessageForJs(napi_env env, int32_t errorCode, int32_t eventId); 72 73 private: 74 static std::string GetEventName(int32_t eventId); 75 static std::string GetEventPermission(int32_t eventId); 76 }; 77 } // namespace Telephony 78 } // namespace OHOS 79 80 #endif