tizen 2.3.1 release
[framework/web/mobile/wrt-plugins-tizen.git] / src / Sound / SoundUtil.h
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 #ifndef __TIZEN_SOUND_UTIL_H__
19 #define __TIZEN_SOUND_UTIL_H__
20
21 #include <string>
22
23 #include <sound_manager.h>
24 #include <PlatformException.h>
25 #include <Logger.h>
26
27 namespace DeviceAPI {
28 namespace Sound {
29
30 namespace {
31 const std::string SYSTEM = "SYSTEM";
32 const std::string NOTIFICATION = "NOTIFICATION";
33 const std::string ALARM = "ALARM";
34 const std::string MEDIA = "MEDIA";
35 const std::string VOICE = "VOICE";
36 const std::string RINGTONE = "RINGTONE";
37
38 const std::string SOUND = "SOUND";
39 const std::string VIBRATE = "VIBRATE";
40 const std::string MUTE = "MUTE";
41
42 // Sound device type
43 const std::string SPEAKER = "SPEAKER";
44 const std::string RECEIVER = "RECEIVER";
45 const std::string AUDIO_JACK = "AUDIO_JACK";
46 const std::string BLUETOOTH = "BLUETOOTH";
47 const std::string HDMI = "HDMI";
48 const std::string MIRRORING = "MIRRORING";
49 const std::string USB_AUDIO = "USB_AUDIO";
50 const std::string MIC = "MIC";
51
52 // Sound IO type
53 const std::string IN = "IN";
54 const std::string OUT = "OUT";
55 const std::string BOTH = "BOTH";
56
57 // ErrorMessage
58 static std::string errOutOfMemory = "Out of memory";
59 static std::string errInvalidParameter = "Invalid parameter";
60 static std::string errInvalidOperation = "Invalid Operation";
61 static std::string errPermissionDenied = "Permission denied";
62 static std::string errNotSupported = "Not supported";
63 static std::string errNoData = "No data";
64 static std::string errNoPlayingSound = "No playing sound";
65 static std::string errInternal = "Internal Error";
66 static std::string errPolicy = "Policy Error";
67 static std::string errUnknown = "Unknown error";
68 }
69
70 enum SoundModeType
71 {
72     SOUND_MODE_TYPE_SOUND,
73     SOUND_MODE_TYPE_VIBRATE,
74     SOUND_MODE_TYPE_MUTE
75 };
76
77 class SoundUtil
78 {
79 public:
80     static std::string soundTypeToString(sound_type_e sound_type);
81     static sound_type_e stringToSoundType(std::string sound_type_str);
82
83     static std::string soundModeToString(SoundModeType sound_mode);
84     static SoundModeType stringToSoundMode(std::string sound_mode_str);
85
86     static std::string soundDeviceTypeToString(sound_device_type_e soundDevice);
87     static sound_device_type_e stringToSoundDeviceType(std::string soundDevice);
88
89     static std::string soundIOTypeToString(sound_device_io_direction_e IOType);
90     static sound_device_io_direction_e stringToSoundIOType(std::string IOType);
91
92     template <class T = DeviceAPI::Common::UnknownException>
93     static void throwSoundException(const int errorCode, const std::string& hint) {
94         std::string message = SoundUtil::getSoundLogMessage(errorCode, hint);
95         LOGE("%s", message.c_str());
96         throw T(message.c_str());
97     }
98
99     template <class T = DeviceAPI::Common::UnknownException>
100     static void throwSoundException(const std::string& hint) {
101         LOGE("%s", hint.c_str());
102         throw T(hint.c_str());
103     }
104
105     static std::string& getSoundErrorMessage(const int errorCode);
106     static std::string getSoundLogMessage(const int errorCode, const std::string& hint);
107 private:
108 };
109
110 } // Sound
111 } // DeviceAPI
112
113
114 #endif // __TIZEN_SOUND_UTIL_H__