sbBaseMediacoreVolumeControl.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
32 
33 #include <prprf.h>
34 
35 
40 #ifdef PR_LOGGING
41 static PRLogModuleInfo* gBaseMediacoreVolumeControl = nsnull;
42 #define TRACE(args) PR_LOG(gBaseMediacoreVolumeControl , PR_LOG_DEBUG, args)
43 #define LOG(args) PR_LOG(gBaseMediacoreVolumeControl , PR_LOG_WARN, args)
44 #else
45 #define TRACE(args) /* nothing */
46 #define LOG(args) /* nothing */
47 #endif
48 
49 void SB_ConvertFloatVolToJSStringValue(PRFloat64 aVol,
50  nsACString &aStrVol)
51 {
52  char volume[64] = {0};
53  PR_snprintf(volume, 64, "%lg", aVol);
54 
55  // We have to replace the decimal point character with '.' so that
56  // parseFloat in JS still understands that this number is a floating point
57  // number. The JS Standard dictates that parseFloat _ONLY_ supports '.' as
58  // it's decimal point character.
59  volume[1] = '.';
60 
61  aStrVol.Assign(volume);
62 
63  return;
64 }
65 
68 
70 : mMonitor(nsnull)
71 , mMute(PR_FALSE)
72 , mVolume(0)
73 {
74  MOZ_COUNT_CTOR(sbBaseMediacoreVolumeControl);
75 
76 #ifdef PR_LOGGING
77  if (!gBaseMediacoreVolumeControl)
78  gBaseMediacoreVolumeControl = PR_NewLogModule("sbBaseMediacoreVolumeControl");
79 #endif
80 
81  TRACE(("sbBaseMediacoreVolumeControl[0x%x] - Created", this));
82 }
83 
85 {
86  TRACE(("sbBaseMediacoreVolumeControl[0x%x] - Destroyed", this));
87 
88  MOZ_COUNT_DTOR(sbBaseMediacoreVolumeControl);
89 
90  if(mMonitor) {
91  nsAutoMonitor::DestroyMonitor(mMonitor);
92  }
93 }
94 
95 nsresult
97 {
98  TRACE(("sbBaseMediacoreVolumeControl[0x%x] - InitBaseMediacoreVolumeControl", this));
99 
100  mMonitor = nsAutoMonitor::NewMonitor("sbBaseMediacoreVolumeControl::mMonitor");
101  NS_ENSURE_TRUE(mMonitor, NS_ERROR_OUT_OF_MEMORY);
102 
104 }
105 
106 NS_IMETHODIMP
107 sbBaseMediacoreVolumeControl::GetMute(PRBool *aMute)
108 {
109  TRACE(("sbBaseMediacoreVolumeControl[0x%x] - GetMute", this));
110  NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
111  NS_ENSURE_ARG_POINTER(aMute);
112 
113  nsAutoMonitor mon(mMonitor);
114  *aMute = mMute;
115 
116  return NS_OK;
117 }
118 
119 NS_IMETHODIMP
120 sbBaseMediacoreVolumeControl::SetMute(PRBool aMute)
121 {
122  TRACE(("sbBaseMediacoreVolumeControl[0x%x] - SetMute", this));
123  NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
124 
125  nsresult rv = OnSetMute(aMute);
126  NS_ENSURE_SUCCESS(rv, rv);
127 
128  nsAutoMonitor mon(mMonitor);
129  mMute = aMute;
130 
131  return NS_OK;
132 }
133 
134 NS_IMETHODIMP
135 sbBaseMediacoreVolumeControl::GetVolume(double *aVolume)
136 {
137  TRACE(("sbBaseMediacoreVolumeControl[0x%x] - GetVolume", this));
138  NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
139  NS_ENSURE_ARG_POINTER(aVolume);
140 
141  nsAutoMonitor mon(mMonitor);
142  *aVolume = mVolume;
143 
144  return NS_OK;
145 }
146 
147 NS_IMETHODIMP
148 sbBaseMediacoreVolumeControl::SetVolume(double aVolume)
149 {
150  TRACE(("sbBaseMediacoreVolumeControl[0x%x] - SetVolume", this));
151  NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
152 
153  nsresult rv = OnSetVolume(aVolume);
154  NS_ENSURE_SUCCESS(rv, rv);
155 
156  nsAutoMonitor mon(mMonitor);
157  mVolume = aVolume;
158 
159  return NS_OK;
160 }
161 
162 /*virtual*/ nsresult
164 {
170  return NS_ERROR_NOT_IMPLEMENTED;
171 }
172 
173 /*virtual*/ nsresult
175 {
184  return NS_ERROR_NOT_IMPLEMENTED;
185 }
186 
187 /*virtual*/ nsresult
189 {
198  return NS_ERROR_NOT_IMPLEMENTED;
199 }
return NS_OK
virtual nsresult OnSetMute(PRBool aMute)
void SB_ConvertFloatVolToJSStringValue(PRFloat64 aVol, nsACString &aStrVol)
#define TRACE(args)
virtual nsresult OnSetVolume(PRFloat64 aVolume)
Songbird Mediacore Event Definition.
NS_IMPL_THREADSAFE_ISUPPORTS1(sbBaseMediacoreVolumeControl, sbIMediacoreVolumeControl) sbBaseMediacoreVolumeControl