tizen 2.3 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Sound / SoundUtil.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include "SoundUtil.h"
19
20 #include <PlatformException.h>
21 #include <Logger.h>
22
23 #include <sstream>
24
25 using namespace DeviceAPI::Common;
26
27 namespace DeviceAPI {
28 namespace Sound {
29
30 std::string SoundUtil::soundTypeToString(sound_type_e sound_type)
31 {
32     switch (sound_type) {
33         case SOUND_TYPE_SYSTEM:
34             return SYSTEM;
35         case SOUND_TYPE_NOTIFICATION:
36             return NOTIFICATION;
37         case SOUND_TYPE_ALARM:
38             return ALARM;
39         case SOUND_TYPE_MEDIA:
40             return MEDIA;
41 #ifndef PROFILE_WEARABLE
42         case SOUND_TYPE_VOICE:
43             return VOICE;
44 #endif
45         case SOUND_TYPE_RINGTONE:
46             return RINGTONE;
47         default:
48             LOGE("Invalid SoundSoundType : %d", sound_type);
49             throw TypeMismatchException("Invalid SoundSoundType");
50     }
51 }
52
53 sound_type_e SoundUtil::stringToSoundType(std::string sound_type_str)
54 {
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;
66 #endif
67     } else if (sound_type_str == RINGTONE) {
68         return SOUND_TYPE_RINGTONE;
69     } else {
70         LOGE("Invalid SoundSoundType : %s", sound_type_str.c_str());
71         throw TypeMismatchException("Invalid SoundSoundType");
72     }
73 }
74
75 std::string SoundUtil::soundModeToString(SoundModeType sound_mode)
76 {
77     switch (sound_mode) {
78         case SOUND_MODE_TYPE_SOUND:
79             return SOUND;
80         case SOUND_MODE_TYPE_VIBRATE:
81             return VIBRATE;
82         case SOUND_MODE_TYPE_MUTE:
83             return MUTE;
84         default:
85             LOGE("Invalid SoundMode: %d", sound_mode);
86             throw TypeMismatchException("Invalid SoundMode");
87     }
88 }
89
90 SoundModeType SoundUtil::stringToSoundMode(std::string sound_mode_str)
91 {
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;
98     } else {
99         LOGE("Invalid SoundMode: %s", sound_mode_str.c_str());
100         throw TypeMismatchException("Invalid SoundMode");
101     }
102 }
103
104 std::string& SoundUtil::getSoundErrorMessage(const int errorCode){
105     switch(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:
118             return errNoData ;
119 #endif
120         case SOUND_MANAGER_ERROR_NO_PLAYING_SOUND:
121             return errNoPlayingSound ;
122         case SOUND_MANAGER_ERROR_INTERNAL:
123             return errInternal;
124         case SOUND_MANAGER_ERROR_POLICY:
125             return errPolicy;
126         default:
127             return errUnknown;
128     }
129 }
130
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());
135 }
136
137
138 } // Sound
139 } // DeviceAPI