tizen 2.3.1 release
[framework/web/mobile/wrt-plugins-tizen.git] / src / Sound / SoundManager.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_MANAGER_H__
19 #define __TIZEN_SOUND_MANAGER_H__
20
21 #include <SecurityAccessor.h>
22 #include <sound_manager.h>
23
24 #include <vconf.h>
25 #include <vconf-keys.h>
26
27 #include <JSStringRefWrapper.h>
28
29 #include "SoundTypes.h"
30 #include "VolumeChangeCallback.h"
31 #include "SoundDeviceStateChangeCallback.h"
32
33 using namespace DeviceAPI::Common;
34
35 namespace DeviceAPI {
36 namespace Sound {
37
38 class SoundModeChangeListener
39 {
40 public:
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();
45
46     virtual void onChangeSoundMode(SoundModeType mode);
47
48 private:
49     JSContextRef m_context;
50     JSObjectRef m_thisObject;
51     JSObjectRef m_function;
52 };
53
54 typedef std::shared_ptr<SoundModeChangeListener> SoundModeChangeListenerPtr;
55
56 class SoundManager : public Common::SecurityAccessor{
57 public:
58     static SoundManager* getInstance();
59
60     void setVolume(sound_type_e type, double volume);
61     double getVolume(sound_type_e type);
62
63     void setVolumeChangeListener(VolumeChangeCallback *callback);
64     void unsetVolumeChangeListener();
65
66     SoundModeType getSoundMode();
67
68     void setSoundModeChangeListener(SoundModeChangeListenerPtr listener);
69     void unsetSoundModeChangeListener();
70
71     void onChangeSoundMode(SoundModeType mode);
72
73     std::vector<SoundDeviceInfoPtr> getConnectedDeviceList();
74     std::vector<SoundDeviceInfoPtr> getActivatedDeviceList();
75
76     const long addDeviceStateChangeListener(SoundDeviceStateChangeCallbackPtr callback);
77     void removeDeviceStateChangeListener(long id);
78
79 private:
80     SoundManager();
81     virtual ~SoundManager();
82
83     SoundManager(SoundManager const&) = delete;
84     SoundManager& operator=(SoundManager const&) = delete;
85
86     //Volume
87     static void volumeChangeCallback(sound_type_e type, unsigned int value, void *userData);
88     void broadcastEvent(sound_type_e type, unsigned int value);
89
90     VolumeChangeCallback *m_eventListener;
91     std::map<sound_type_e, int> m_maxVolumeMap;
92     std::map<int, int> m_userToSystemValueMap;
93
94     //Sound Mode
95     SoundModeType m_currentSoundMode;
96     SoundModeChangeListenerPtr m_listener;
97     bool m_listeningPlatformEvent;
98
99     //Sound Device
100     std::vector<SoundDeviceInfoPtr> m_connectedDeviceList;
101     std::vector<SoundDeviceInfoPtr> m_activatedDeviceList;
102
103     static bool isThisDeviceConnected(sound_device_type_e deviceType, sound_device_io_direction_e IOType);
104
105     long m_deviceStateChangeListenerCnt;
106     std::map<long, SoundDeviceStateChangeCallbackPtr> m_deviceStateChangeListeners;
107
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);
112
113     void setAllDeviceInfo(SoundDeviceInfoPtr info, sound_device_h device, bool isConnected);
114
115     bool unsetDeviceChangeListeners();
116
117     enum {
118         CONNECTIVITY,
119         ACTIVATION,
120     };
121 };
122
123 } // Sound
124 } // DeviceAPI
125
126
127 #endif // __TIZEN_SOUND_MANAGER_H__