2 // Tizen Web Device API
3 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include "SoundUtil.h"
20 #include <PlatformException.h>
25 using namespace DeviceAPI::Common;
30 std::string SoundUtil::soundTypeToString(sound_type_e sound_type)
33 case SOUND_TYPE_SYSTEM:
35 case SOUND_TYPE_NOTIFICATION:
37 case SOUND_TYPE_ALARM:
39 case SOUND_TYPE_MEDIA:
41 #ifndef PROFILE_WEARABLE
42 case SOUND_TYPE_VOICE:
45 case SOUND_TYPE_RINGTONE:
48 LOGE("Invalid SoundSoundType : %d", sound_type);
49 throw TypeMismatchException("Invalid SoundSoundType");
53 sound_type_e SoundUtil::stringToSoundType(std::string sound_type_str)
55 if (sound_type_str == SYSTEM) {
56 return SOUND_TYPE_SYSTEM;
57 } else if (sound_type_str == NOTIFICATION) {
58 return SOUND_TYPE_NOTIFICATION;
59 } else if (sound_type_str == ALARM) {
60 return SOUND_TYPE_ALARM;
61 } else if (sound_type_str == MEDIA) {
62 return SOUND_TYPE_MEDIA;
63 #ifndef PROFILE_WEARABLE
64 } else if (sound_type_str == VOICE) {
65 return SOUND_TYPE_VOICE;
67 } else if (sound_type_str == RINGTONE) {
68 return SOUND_TYPE_RINGTONE;
70 LOGE("Invalid SoundSoundType : %s", sound_type_str.c_str());
71 throw TypeMismatchException("Invalid SoundSoundType");
75 std::string SoundUtil::soundModeToString(SoundModeType sound_mode)
78 case SOUND_MODE_TYPE_SOUND:
80 case SOUND_MODE_TYPE_VIBRATE:
82 case SOUND_MODE_TYPE_MUTE:
85 LOGE("Invalid SoundMode: %d", sound_mode);
86 throw TypeMismatchException("Invalid SoundMode");
90 SoundModeType SoundUtil::stringToSoundMode(std::string sound_mode_str)
92 if (sound_mode_str == SOUND) {
93 return SOUND_MODE_TYPE_SOUND;
94 } else if (sound_mode_str == VIBRATE) {
95 return SOUND_MODE_TYPE_VIBRATE;
96 } else if (sound_mode_str == MUTE) {
97 return SOUND_MODE_TYPE_MUTE;
99 LOGE("Invalid SoundMode: %s", sound_mode_str.c_str());
100 throw TypeMismatchException("Invalid SoundMode");
104 std::string& SoundUtil::getSoundErrorMessage(const int errorCode){
106 case SOUND_MANAGER_ERROR_OUT_OF_MEMORY:
107 return errOutOfMemory;
108 case SOUND_MANAGER_ERROR_INVALID_PARAMETER:
109 return errInvalidParameter;
110 case SOUND_MANAGER_ERROR_INVALID_OPERATION:
111 return errInvalidOperation;
112 #ifndef PROFILE_WEARABLE
113 case SOUND_MANAGER_ERROR_PERMISSION_DENIED:
114 return errPermissionDenied;
115 case SOUND_MANAGER_ERROR_NOT_SUPPORTED:
116 return errNotSupported;
117 case SOUND_MANAGER_ERROR_NO_DATA:
120 case SOUND_MANAGER_ERROR_NO_PLAYING_SOUND:
121 return errNoPlayingSound ;
122 case SOUND_MANAGER_ERROR_INTERNAL:
124 case SOUND_MANAGER_ERROR_POLICY:
131 std::string SoundUtil::getSoundLogMessage(const int errorCode, const std::string &hint){
132 std::stringstream ss;
133 ss << "Failed " << hint << " : " << getSoundErrorMessage(errorCode) << ", " << errorCode;
134 return std::string(ss.str());