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 SYSTEM_SOUND_MNGR_NAPI_H_ 17 #define SYSTEM_SOUND_MNGR_NAPI_H_ 18 19 #include "iringtone_sound_manager.h" 20 #include "ringtone_player_napi.h" 21 #include "napi/native_api.h" 22 #include "napi/native_node_api.h" 23 #include "napi_base_context.h" 24 #include "ability.h" 25 26 namespace OHOS { 27 namespace AudioStandard { 28 static const std::string SYSTEM_SND_MNGR_NAPI_CLASS_NAME = "SystemSoundManager"; 29 30 static const std::map<std::string, RingtoneType> ringtoneTypeMap = { 31 {"RINGTONE_TYPE_DEFAULT", RINGTONE_TYPE_DEFAULT}, 32 {"RINGTONE_TYPE_MULTISIM", RINGTONE_TYPE_MULTISIM} 33 }; 34 35 class SystemSoundManagerNapi { 36 public: 37 static napi_value Init(napi_env env, napi_value exports); 38 39 SystemSoundManagerNapi(); 40 ~SystemSoundManagerNapi(); 41 42 private: 43 static void Destructor(napi_env env, void* nativeObject, void* finalize_hint); 44 static napi_value Construct(napi_env env, napi_callback_info info); 45 static napi_value GetSystemSoundManager(napi_env env, napi_callback_info info); 46 static napi_value SetSystemRingtoneUri(napi_env env, napi_callback_info info); 47 static napi_value GetSystemRingtoneUri(napi_env env, napi_callback_info info); 48 static napi_value GetSystemRingtonePlayer(napi_env env, napi_callback_info info); 49 static napi_value SetSystemNotificationUri(napi_env env, napi_callback_info info); 50 static napi_value GetSystemNotificationUri(napi_env env, napi_callback_info info); 51 static napi_value SetSystemAlarmUri(napi_env env, napi_callback_info info); 52 static napi_value GetSystemAlarmUri(napi_env env, napi_callback_info info); 53 static napi_status AddNamedProperty(napi_env env, napi_value object, const std::string name, int32_t enumValue); 54 static napi_value CreateRingtoneTypeObject(napi_env env); 55 static std::shared_ptr<AbilityRuntime::Context> GetAbilityContext(napi_env env, napi_value contextArg); 56 57 static napi_ref ringtoneType_; 58 static napi_ref sConstructor_; 59 60 napi_env env_; 61 napi_ref wrapper_; 62 63 std::shared_ptr<IRingtoneSoundManager> sysSoundMgrClient_ = nullptr; 64 }; 65 66 struct SystemSoundManagerAsyncContext { 67 napi_env env; 68 napi_async_work work; 69 napi_deferred deferred; 70 napi_ref callbackRef; 71 bool status; 72 SystemSoundManagerNapi *objectInfo; 73 std::shared_ptr<AbilityRuntime::Context> abilityContext_; 74 std::string uri; 75 std::shared_ptr<IRingtonePlayer> ringtonePlayer; 76 int32_t ringtoneType; 77 }; 78 } // namespace AudioStandard 79 } // namespace OHOS 80 #endif /* SYSTEM_SOUND_MNGR_NAPI_H_ */