[Messaging] Refactor MessageConversation related code
[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 <vconf.h>
23 #include "common/picojson.h"
24 #include "common/platform_result.h"
25
26 namespace extension {
27 namespace sound {
28
29 class SoundManagerSoundModeChangedListener {
30  public:
31   virtual ~SoundManagerSoundModeChangedListener() {
32   }
33   virtual void OnSoundModeChange(const std::string& newmode) = 0;
34 };
35
36 class SoundInstance;
37
38 class SoundManager {
39  public:
40   explicit SoundManager(SoundInstance& instance);
41   ~SoundManager();
42
43   common::PlatformResult GetSoundMode(std::string* sound_mode_type);
44   common::PlatformResult SetVolume(const picojson::object& args);
45   common::PlatformResult GetVolume(const picojson::object& args, double* volume);
46   common::PlatformResult SetSoundModeChangeListener(SoundManagerSoundModeChangedListener* listener);
47   common::PlatformResult UnsetSoundModeChangeListener();
48   common::PlatformResult SetVolumeChangeListener();
49   common::PlatformResult UnsetVolumeChangeListener();
50   void GetDeviceList(sound_device_mask_e mask, picojson::object& out);
51   void DeviceChangeCB(sound_device_h device, bool is_connected, bool check_connection);
52   common::PlatformResult AddDeviceStateChangeListener();
53   common::PlatformResult RemoveDeviceStateChangeListener();
54
55  private:
56   std::map<sound_type_e, int> max_volume_map_;
57   bool is_volume_change_listener_;
58   int volume_change_listener_id_;
59
60   static const std::map<std::string, sound_type_e> platform_enum_map_;
61
62   void FillMaxVolumeMap();
63   common::PlatformResult GetMaxVolume(sound_type_e type, int* max_volume);
64   void VolumeChangeCallback(sound_type_e type, unsigned int value);
65
66   static common::PlatformResult StrToPlatformEnum(const std::string& key, sound_type_e* sound_type);
67   static common::PlatformResult PlatformEnumToStr(const sound_type_e value,
68                                                   std::string* sound_type);
69
70   common::PlatformResult GetDeviceInfo(sound_device_h device, bool is_connected,
71                                        bool check_connection, picojson::object* obj);
72   common::PlatformResult IsDeviceConnected(sound_device_type_e type,
73                                            sound_device_io_direction_e direction,
74                                            picojson::object* obj);
75   static std::string SoundDeviceTypeToString(sound_device_type_e type);
76   static std::string SoundIOTypeToString(sound_device_io_direction_e type);
77   static double ConvertToSystemVolume(int max_volume, int volume);
78   static void soundModeChangedCb(keynode_t* node, void* user_data);
79   bool soundModeChangeListening;
80   bool is_sound_device_change_listener_;
81   int sound_device_connection_listener_id_;
82   int sound_device_state_listener_id_;
83   SoundInstance& instance_;
84   SoundManagerSoundModeChangedListener* soundModeListener;
85 };
86
87 }  // namespace sound
88 }  // namespace extension
89
90 #endif  // SOUND_SOUND_MANAGER_H_