sbIPDMarshall.h
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 
27 #ifndef __SB_IPD_MARSHALL_H__
28 #define __SB_IPD_MARSHALL_H__
29 
30 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 //
33 // iPod device marshall defs.
34 //
35 //------------------------------------------------------------------------------
36 //------------------------------------------------------------------------------
37 
43 //------------------------------------------------------------------------------
44 //
45 // iPod device marshall imported services.
46 //
47 //------------------------------------------------------------------------------
48 
49 // Local imports.
50 #include "sbIPDUtils.h"
51 
52 // Songbird imports.
53 #include <sbBaseDeviceMarshall.h>
54 #include <sbIDeviceManager.h>
55 #include <sbIDeviceRegistrar.h>
56 
57 // Mozilla imports.
58 #include <nsAutoLock.h>
59 #include <nsAutoPtr.h>
60 #include <nsIClassInfo.h>
61 #include <nsInterfaceHashtable.h>
62 
63 // MacOS X imports.
64 #include <Carbon/Carbon.h>
65 
66 //------------------------------------------------------------------------------
67 //
68 // iPod device marshall definitions.
69 //
70 //------------------------------------------------------------------------------
71 
72 //
73 // iPod device marshall XPCOM component definitions.
74 //XXXeps should move out of platform specific file
75 //
76 
77 #define SB_IPDMARSHALL_CONTRACTID "@songbirdnest.com/Songbird/IPDMarshall;1"
78 #define SB_IPDMARSHALL_CLASSNAME "iPod Device Marshall"
79 #define SB_IPDMARSHALL_DESCRIPTION "iPod Device Marshall"
80 #define SB_IPDMARSHALL_CID \
81 { \
82  0xbbca0e8c, \
83  0x78a3, \
84  0x4f13, \
85  { 0xae, 0x2b, 0x0f, 0xed, 0xb9, 0x47, 0xdf, 0x37 } \
86 }
87 
88 
89 //------------------------------------------------------------------------------
90 //
91 // iPod device marshall classes.
92 //
93 //------------------------------------------------------------------------------
94 
100 template<class RefType>
101 class cfref {
102  RefType mRef;
103 public:
104  cfref() : mRef(NULL) {}
105  cfref(RefType ref) : mRef(ref) {}
106  ~cfref() { if(mRef) ::CFRelease(mRef); }
107 
108  RefType operator=(RefType ref)
109  {
110  if (mRef && mRef != ref)
111  ::CFRelease(mRef);
112  return (mRef = ref);
113  }
114 
115  operator RefType() { return mRef; }
116  operator int() { return (mRef != NULL); }
117 };
118 
119 
125 class sbAutoFinalizeVolumeMonitor;
126 
127 class sbIPDMarshall : public sbBaseDeviceMarshall,
128  public nsIClassInfo
129 {
130  //----------------------------------------------------------------------------
131  //
132  // Class friends.
133  //
134  //----------------------------------------------------------------------------
135 
137 
138 
139  //----------------------------------------------------------------------------
140  //
141  // Public interface.
142  //
143  //----------------------------------------------------------------------------
144 
145 public:
146 
147  //
148  // Inherited interfaces.
149  //
150 
152  NS_DECL_SBIDEVICEMARSHALL
153  NS_DECL_NSICLASSINFO
154 
155 
156  //
157  // Constructors/destructors.
158  //
159 
160  sbIPDMarshall();
161 
162  virtual ~sbIPDMarshall();
163 
164 
165  //----------------------------------------------------------------------------
166  //
167  // Private interface.
168  //
169  //----------------------------------------------------------------------------
170 
171 private:
172 
173  //
174  // Internal services fields.
175  //
176  // mMonitor Marshall services monitor.
177  // mDeviceManager Device manager.
178  // mDeviceRegistrar Device registrar.
179  // mDeviceList List of devices.
180  // mEventHandler Volume event handler proc.
181  // mEventHandlerRef Volume event handler reference.
182  //
183 
184  PRMonitor *mMonitor;
185  nsCOMPtr<sbIDeviceManager2> mDeviceManager;
186  nsCOMPtr<sbIDeviceRegistrar> mDeviceRegistrar;
187  nsInterfaceHashtable<nsUint32HashKey, nsISupports>
188  mDeviceList;
189  EventHandlerProcPtr mVolumeEventHandler;
190  EventHandlerRef mVolumeEventHandlerRef;
191 
192 
193  //
194  // iPod device marshall monitor services.
195  //
196 
197  nsresult InitializeVolumeMonitor();
198 
199  void FinalizeVolumeMonitor();
200 
201  static pascal OSStatus VolumeEventHandler(EventHandlerCallRef aNextHandler,
202  EventRef aEventRef,
203  void* aHandlerCtx);
204 
205  void VolumeEventHandler(EventHandlerCallRef aNextHandler,
206  EventRef aEventRef);
207 
208  void HandleAddedEvent(FSVolumeRefNum aVolumeRefNum);
209 
210  void HandleRemovedEvent(FSVolumeRefNum aVolumeRefNum);
211 
212 
213  //
214  // Internal services.
215  //
216 
217  nsresult ScanForConnectedDevices();
218 
219  PRBool IsIPod(FSVolumeRefNum aVolumeRefNum);
220 
221  nsresult GetVolumePath(FSVolumeRefNum aVolumeRefNum,
222  nsAString& aVolumePath);
223 
224  nsresult GetFirewireGUID(FSVolumeRefNum aVolumeRefNum,
225  nsAString& aFirewireGUID);
226 };
227 
228 
234 SB_AUTO_CLASS(sbAutoFinalizeVolumeMonitor,
235  sbIPDMarshall*,
236  mValue,
237  mValue->FinalizeVolumeMonitor(),
238  mValue = nsnull);
239 
240 
241 #endif /* __SB_IPD_MARSHALL_H__ */
242 
Songbird iPod Device Utility Definitions.
RefType operator=(RefType ref)
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICEMARSHALL NS_DECL_NSICLASSINFO sbIPDMarshall()
friend class sbAutoFinalizeVolumeMonitor
cfref(RefType ref)
gWaitForCompletion mDeviceManager
SB_AUTO_CLASS(sbAutoFinalizeVolumeMonitor, sbIPDMarshall *, mValue, mValue->FinalizeVolumeMonitor(), mValue=nsnull)
virtual ~sbIPDMarshall()