Merge "Revert "[secureelement] - Checking privileges moved to JS layer"" into tizen_3.0
[platform/core/api/webapi-plugins.git] / src / sound / sound_manager.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef SOUND_SOUND_MANAGER_H_
18 #define SOUND_SOUND_MANAGER_H_
19
20 #include <sound_manager.h>
21
22 #include "common/picojson.h"
23 #include "common/platform_result.h"
24 #include <vconf.h>
25
26 namespace extension {
27 namespace sound {
28
29 class SoundManagerSoundModeChangedListener {
30  public:
31   virtual ~SoundManagerSoundModeChangedListener() {}
32   virtual void OnSoundModeChange(const std::string& newmode) = 0;
33 };
34
35 class SoundInstance;
36
37 class SoundManager {
38  public:
39   explicit SoundManager(SoundInstance& instance);
40   ~SoundManager();
41
42   common::PlatformResult GetSoundMode(std::string* sound_mode_type);
43   common::PlatformResult SetVolume(const picojson::object& args);
44   common::PlatformResult GetVolume(const picojson::object& args,
45                                    double* volume);
46   common::PlatformResult SetSoundModeChangeListener(
47       SoundManagerSoundModeChangedListener* listener);
48   common::PlatformResult UnsetSoundModeChangeListener();
49   common::PlatformResult SetVolumeChangeListener();
50   common::PlatformResult UnsetVolumeChangeListener();
51   void GetDeviceList(sound_device_mask_e mask, picojson::object& out);
52   void DeviceChangeCB(sound_device_h device, bool is_connected, bool check_connection);
53   common::PlatformResult AddDeviceStateChangeListener();
54   common::PlatformResult RemoveDeviceStateChangeListener();
55
56  private:
57
58   std::map<sound_type_e, int> max_volume_map_;
59   bool is_volume_change_listener_;
60
61   static const std::map<std::string, sound_type_e> platform_enum_map_;
62
63   void FillMaxVolumeMap();
64   common::PlatformResult GetMaxVolume(sound_type_e type, int* max_volume);
65   void VolumeChangeCallback(sound_type_e type, unsigned int value);
66
67   static common::PlatformResult StrToPlatformEnum(const std::string& key,
68                                                   sound_type_e* sound_type);
69   static common::PlatformResult PlatformEnumToStr(const sound_type_e value,
70                                                   std::string* sound_type);
71
72   common::PlatformResult GetDeviceInfo(sound_device_h device,
73                                        bool is_connected,
74                                        bool check_connection,
75                                        picojson::object* obj);
76   common::PlatformResult IsDeviceConnected(sound_device_type_e type,
77                                            sound_device_io_direction_e direction,
78                                            picojson::object* obj);
79   static std::string SoundDeviceTypeToString(sound_device_type_e type);
80   static std::string SoundIOTypeToString(sound_device_io_direction_e type);
81   static double ConvertToSystemVolume(int max_volume, int volume);
82   static void soundModeChangedCb(keynode_t* node, void* user_data);
83   bool soundModeChangeListening;
84   bool sound_device_change_listener_;
85   SoundInstance& instance_;
86   SoundManagerSoundModeChangedListener* soundModeListener;
87 };
88
89 }  // namespace sound
90 }  // namespace extension
91
92 #endif  // SOUND_SOUND_MANAGER_H_