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 #ifndef __TIZEN_SOUND_MANAGER_H__
19 #define __TIZEN_SOUND_MANAGER_H__
21 #include <SecurityAccessor.h>
22 #include <sound_manager.h>
25 #include <vconf-keys.h>
27 #include <JSStringRefWrapper.h>
29 #include "SoundTypes.h"
30 #include "VolumeChangeCallback.h"
31 #include "SoundDeviceStateChangeCallback.h"
33 using namespace DeviceAPI::Common;
38 class SoundModeChangeListener
41 // context MUST be a global context.
42 // function MUST be a function object. There is no validation check when invoking.
43 SoundModeChangeListener(JSContextRef context, JSObjectRef thisObject, JSObjectRef function);
44 virtual ~SoundModeChangeListener();
46 virtual void onChangeSoundMode(SoundModeType mode);
49 JSContextRef m_context;
50 JSObjectRef m_thisObject;
51 JSObjectRef m_function;
54 typedef std::shared_ptr<SoundModeChangeListener> SoundModeChangeListenerPtr;
56 class SoundManager : public Common::SecurityAccessor{
58 static SoundManager* getInstance();
60 void setVolume(sound_type_e type, double volume);
61 double getVolume(sound_type_e type);
63 void setVolumeChangeListener(VolumeChangeCallback *callback);
64 void unsetVolumeChangeListener();
66 SoundModeType getSoundMode();
68 void setSoundModeChangeListener(SoundModeChangeListenerPtr listener);
69 void unsetSoundModeChangeListener();
71 void onChangeSoundMode(SoundModeType mode);
73 std::vector<SoundDeviceInfoPtr> getConnectedDeviceList();
74 std::vector<SoundDeviceInfoPtr> getActivatedDeviceList();
76 const long addDeviceStateChangeListener(SoundDeviceStateChangeCallbackPtr callback);
77 void removeDeviceStateChangeListener(long id);
81 virtual ~SoundManager();
83 SoundManager(SoundManager const&) = delete;
84 SoundManager& operator=(SoundManager const&) = delete;
87 static void volumeChangeCallback(sound_type_e type, unsigned int value, void *userData);
88 void broadcastEvent(sound_type_e type, unsigned int value);
90 VolumeChangeCallback *m_eventListener;
91 std::map<sound_type_e, int> m_maxVolumeMap;
92 std::map<int, int> m_userToSystemValueMap;
95 SoundModeType m_currentSoundMode;
96 SoundModeChangeListenerPtr m_listener;
97 bool m_listeningPlatformEvent;
100 std::vector<SoundDeviceInfoPtr> m_connectedDeviceList;
101 std::vector<SoundDeviceInfoPtr> m_activatedDeviceList;
103 static bool isThisDeviceConnected(sound_device_type_e deviceType, sound_device_io_direction_e IOType);
105 long m_deviceStateChangeListenerCnt;
106 std::map<long, SoundDeviceStateChangeCallbackPtr> m_deviceStateChangeListeners;
108 static void deviceConnectionChangeCB(sound_device_h device, bool isConnected, void *userData);
109 static void deviceActivationChangeCB(sound_device_h device, sound_device_changed_info_e changedInfo, void *userData);
110 void broadcastDeviceStateChangeEvent(sound_device_h device, bool isConnected);
111 static gboolean complete(void *data);
113 void setAllDeviceInfo(SoundDeviceInfoPtr info, sound_device_h device, bool isConnected);
115 bool unsetDeviceChangeListeners();
127 #endif // __TIZEN_SOUND_MANAGER_H__