sbWindowsFormatterClassFactory.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2009 POTI, Inc.
9  * http://www.songbirdnest.com
10  *
11  * This file may be licensed under the terms of of the
12  * GNU General Public License Version 2 (the ``GPL'').
13  *
14  * Software distributed under the License is distributed
15  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
16  * express or implied. See the GPL for the specific language
17  * governing rights and limitations.
18  *
19  * You should have received a copy of the GPL along with this
20  * program. If not, go to http://www.gnu.org/licenses/gpl.html
21  * or write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  *=END SONGBIRD GPL
25  */
26 
32 //------------------------------------------------------------------------------
33 //
34 // Songbird Windows formatter class factory imported services.
35 //
36 //------------------------------------------------------------------------------
37 
38 // Self imports.
40 
41 // Local imports.
42 #include "sbWindowsFormatter.h"
44 
45 // Songbird imports.
46 #include <sbWindowsUtils.h>
47 
48 
49 //------------------------------------------------------------------------------
50 //
51 // Songbird Windows formatter class factory IUnknown implementation.
52 //
53 //------------------------------------------------------------------------------
54 
61 STDMETHODIMP_(ULONG)
63 {
64  // Increment the reference count and return the result.
65  return ++mRefCount;
66 }
67 
68 
76 STDMETHODIMP_(ULONG)
78 {
79  // Decrement the reference count.
80  ULONG refCount = --mRefCount;
81 
82  // Delete self if reference count reaches zero.
83  if (mRefCount == 0)
84  delete this;
85 
86  return refCount;
87 }
88 
89 
101 STDMETHODIMP
103  void** aInterface)
104 {
105  // Validate return arguments.
106  if (IsBadWritePtr(aInterface, sizeof(void*)))
107  return E_POINTER;
108 
109  // Initialize interface to null.
110  *aInterface = NULL;
111 
112  // Return requested interface.
113  if (InlineIsEqualGUID(aIID, IID_IUnknown))
114  *aInterface = static_cast<IUnknown*>(this);
115  else if (InlineIsEqualGUID(aIID, IID_IClassFactory))
116  *aInterface = static_cast<IClassFactory*>(this);
117  else
118  return E_NOINTERFACE;
119 
120  // Add a reference to the interface.
121  (static_cast<IUnknown*>(*aInterface))->AddRef();
122 
123  return S_OK;
124 }
125 
126 
127 //------------------------------------------------------------------------------
128 //
129 // Songbird Windows formatter class factory IClassFactory implementation.
130 //
131 //------------------------------------------------------------------------------
132 
145 STDMETHODIMP
147  REFIID aIID,
148  void** aInstance)
149 {
150  HRESULT result;
151 
152  // Aggregation is not supported.
153  if (aOuter)
154  return CLASS_E_NOAGGREGATION;
155 
156  // Validate return arguments.
157  if (IsBadWritePtr(aInstance, sizeof(void*)))
158  return E_POINTER;
159 
160  // Set result to NULL.
161  *aInstance = NULL;
162 
163  // Create a new addref'ed Songbird Windows format object and set it up for
164  // auto-release.
165  sbWindowsFormatter* windowsFormatter;
166  result = sbWindowsFormatter::New(&windowsFormatter);
167  SB_WIN_ENSURE_SUCCESS(result, result);
168  sbAutoIUnknown autoWindowsFormatter(windowsFormatter);
169 
170  // Get the requested interface.
171  result = windowsFormatter->QueryInterface(aIID, aInstance);
172  if (FAILED(result))
173  return result;
174 
175  return S_OK;
176 }
177 
178 
186 STDMETHODIMP
188 {
189  // Lock or unlock the COM server.
190  if (aLock)
191  COMServerLock();
192  else
193  COMServerUnlock();
194 
195  return S_OK;
196 }
197 
198 
199 //------------------------------------------------------------------------------
200 //
201 // Public Songbird Windows formatter class factory services.
202 //
203 //------------------------------------------------------------------------------
204 
210  mRefCount(0)
211 {
212  // Add a COM server lock.
213  COMServerLock();
214 }
215 
216 
222 {
223  // Remove COM server lock.
224  COMServerUnlock();
225 }
226 
Songbird Windows Formatter Class Factory Definitions.
Songbird Windows Formatter Definitions.
STDMETHOD() QueryInterface(REFIID aIID, void **aInterface)
STDMETHOD() CreateInstance(IUnknown *aOuter, REFIID aIID, void **aInstance)
STDMETHOD() QueryInterface(REFIID aIID, void **aInterface)
Songbird Windows Formatter Component COM Server Definitions.
void COMServerUnlock()
void COMServerLock()
#define SB_WIN_ENSURE_SUCCESS(aHR, aRV)
static HRESULT New(sbWindowsFormatter **aWindowsFormatter)