sbMockCDDevice.cpp
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #include <sbArrayUtils.h>
26 #include <sbICDDevice.h>
27 #include <sbICDDeviceService.h>
28 #include <sbIMockCDDevice.h>
29 #include <sbIMockCDDeviceController.h>
30 
31 #include <nsArrayEnumerator.h>
32 #include <nsCOMArray.h>
33 #include <nsServiceManagerUtils.h>
34 #include <nsICategoryManager.h>
35 #include <nsIGenericFactory.h>
36 
37 
38 //==============================================================================
39 // Mock CD TOC entry implementation
40 //==============================================================================
41 
43 {
44 public:
46  NS_DECL_SBICDTOCENTRY
47 
48  static sbMockCDTOCEntry * New(PRInt32 aFrameOffset,
49  PRTime aLength,
50  PRInt32 aTrackNumber,
51  PRInt16 aTrackMode,
52  nsAString const & aDrive)
53  {
54  return new sbMockCDTOCEntry(aFrameOffset,
55  aLength,
56  aTrackNumber,
57  aTrackMode,
58  aDrive);
59  }
60 
61 protected:
62  sbMockCDTOCEntry(PRInt32 aFrameOffset,
63  PRTime aLength,
64  PRInt32 aTrackNumber,
65  PRInt16 aTrackMode,
66  nsAString const & aDrive) :
67  mFrameOffset(aFrameOffset),
68  mLength(aLength),
69  mTrackNumber(aTrackNumber),
70  mTrackMode(aTrackMode),
71  mDrive(aDrive)
72  {
73 
74  }
75  virtual ~sbMockCDTOCEntry() {}
76 private:
77  PRInt32 mFrameOffset;
78  PRTime mLength;
79  PRInt32 mTrackNumber;
80  PRInt16 mTrackMode;
81  nsString mDrive;
82 };
83 
85 
86 
87 NS_IMETHODIMP
88 sbMockCDTOCEntry::GetFrameOffset(PRInt32 *aFrameOffset)
89 {
90  NS_ENSURE_ARG_POINTER(aFrameOffset);
91 
92  *aFrameOffset = mFrameOffset;
93  return NS_OK;
94 }
95 
96 NS_IMETHODIMP
97 sbMockCDTOCEntry::GetLength(PRTime *aLength)
98 {
99  NS_ENSURE_ARG_POINTER(aLength);
100 
101  *aLength = mLength;
102  return NS_OK;
103 }
104 
105 NS_IMETHODIMP
106 sbMockCDTOCEntry::GetTrackNumber(PRInt32 *aTrackNumber)
107 {
108  NS_ENSURE_ARG_POINTER(aTrackNumber);
109 
110  *aTrackNumber = mTrackNumber;
111  return NS_OK;
112 }
113 
114 NS_IMETHODIMP
115 sbMockCDTOCEntry::GetTrackURI(nsAString & aTrackURI)
116 {
117  nsString uri;
118  uri.AssignLiteral("cdda:///");
119  uri.Append(mDrive);
120  uri.AppendLiteral("/");
121  uri.AppendInt(mTrackNumber);
122  aTrackURI = uri;
123  return NS_OK;
124 }
125 
126 NS_IMETHODIMP
127 sbMockCDTOCEntry::GetTrackMode(PRInt16 *aTrackMode)
128 {
129  NS_ENSURE_ARG_POINTER(aTrackMode);
130 
131  *aTrackMode = mTrackMode;
132  return NS_OK;
133 }
134 
135 //==============================================================================
136 // Mock CD TOC implementation
137 //==============================================================================
138 
140 {
141 public:
143  NS_DECL_SBICDTOC
144  NS_DECL_SBIMOCKCDTOC
145 
146  static sbMockCDTOC * New(PRInt32 aFirstTrackIndex,
147  PRInt32 aLastTrackIndex,
148  PRInt32 aLeadOutTrackOffset)
149  {
150  return new sbMockCDTOC(aFirstTrackIndex,
151  aLastTrackIndex,
152  aLeadOutTrackOffset);
153  }
154  sbMockCDTOC() : mFirstTrackIndex(0),
155  mLastTrackIndex(0),
156  mLeadOutTrackOffset(0) {}
157 protected:
158  sbMockCDTOC(PRInt32 aFirstTrackIndex,
159  PRInt32 aLastTrackIndex,
160  PRInt32 aLeadOutTrackOffset) :
161  mFirstTrackIndex(aFirstTrackIndex),
162  mLastTrackIndex(aLastTrackIndex),
163  mLeadOutTrackOffset(aLeadOutTrackOffset) {}
164 
165 private:
166  nsCOMArray<sbICDTOCEntry> mTracks;
167  PRInt32 mFirstTrackIndex;
168  PRInt32 mLastTrackIndex;
169  PRInt32 mLeadOutTrackOffset;
170 };
171 
172 
174 
175 NS_IMETHODIMP
176 sbMockCDTOC::GetFirstTrackIndex(PRInt32 *aFirstTrackIndex)
177 {
178  NS_ENSURE_ARG_POINTER(aFirstTrackIndex);
179 
180  *aFirstTrackIndex = mFirstTrackIndex;
181 
182  return NS_OK;
183 }
184 
185 NS_IMETHODIMP
186 sbMockCDTOC::GetLastTrackIndex(PRInt32 *aLastTrackIndex)
187 {
188  NS_ENSURE_ARG_POINTER(aLastTrackIndex);
189 
190  *aLastTrackIndex = mLastTrackIndex;
191 
192  return NS_OK;
193 }
194 
195 NS_IMETHODIMP
196 sbMockCDTOC::GetLeadOutTrackOffset(PRInt32 *aLeadOutTrackOffset)
197 {
198  NS_ENSURE_ARG_POINTER(aLeadOutTrackOffset);
199 
200  *aLeadOutTrackOffset = mLeadOutTrackOffset;
201 
202  return NS_OK;
203 }
204 
205 NS_IMETHODIMP
206 sbMockCDTOC::GetTracks(nsIArray * *aTracks)
207 {
208  NS_ENSURE_ARG_POINTER(aTracks);
209 
210  nsresult rv = sbCOMArrayTonsIArray(mTracks, aTracks);
211  NS_ENSURE_SUCCESS(rv, rv);
212 
213  return NS_OK;
214 }
215 
216 NS_IMETHODIMP
217 sbMockCDTOC::AddTocEntry(PRInt32 frameOffset,
218  PRTime length,
219  PRInt32 trackNumber,
220  PRInt16 trackMode)
221 {
223  length,
224  trackNumber,
225  trackMode,
226  NS_LITERAL_STRING("f:"));
227  NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
228 
229  PRBool const added = mTracks.AppendObject(entry);
230  NS_ENSURE_TRUE(added, NS_ERROR_OUT_OF_MEMORY);
231 
232  return NS_OK;
233 }
234 
235 NS_IMETHODIMP
236 sbMockCDTOC::Initialize(PRInt32 aFirstTrackIndex,
237  PRInt32 aLastTrackIndex,
238  PRInt32 aLeadOutTrackOffset)
239 {
240  mFirstTrackIndex = aFirstTrackIndex;
241  mLastTrackIndex = aLastTrackIndex;
242  mLeadOutTrackOffset = aLeadOutTrackOffset;
243 
244  return NS_OK;
245 }
246 
247 //==============================================================================
248 // Mock CD device implementation
249 //==============================================================================
250 
252 {
253 public:
255  NS_DECL_SBICDDEVICE
256  NS_DECL_SBIMOCKCDDEVICE
257 
258  static sbMockCDDevice * New(nsAString const & aName,
259  PRBool aReadable,
260  PRBool aWritable,
261  PRBool aDiscInserted,
262  PRUint32 aDiscType)
263  {
264  return new sbMockCDDevice(aName,
265  aReadable,
266  aWritable,
267  aDiscInserted,
268  aDiscType);
269  }
270 
271  sbMockCDDevice() : mReadable(PR_FALSE),
272  mWritable(PR_FALSE),
273  mDiscInserted(PR_FALSE),
274  mIsDeviceLocked(PR_FALSE),
275  mDiscType(sbICDDevice::AUDIO_DISC_TYPE),
276  mEjected(PR_FALSE) {}
277 
279  {
280  NS_ASSERTION(!mIsDeviceLocked, "ERROR: Device is still locked!!!!!!!!");
281  }
282 
283 protected:
284  sbMockCDDevice(nsAString const & aName,
285  PRBool aReadable,
286  PRBool aWritable,
287  PRBool aDiscInserted,
288  PRUint32 aDiscType) :
289  mName(aName),
290  mReadable(aReadable),
291  mWritable(aWritable),
292  mDiscInserted(aDiscInserted),
293  mDiscType(aDiscType),
294  mEjected(PR_FALSE) {}
295 private:
296  nsString mName;
297  PRBool mReadable;
298  PRBool mWritable;
299  PRBool mDiscInserted;
300  PRBool mIsDeviceLocked;
301  PRUint32 mDiscType;
302  PRBool mEjected;
303  nsCOMPtr<sbICDTOC> mTOC;
304 };
305 
307 
308 NS_IMETHODIMP
309 sbMockCDDevice::GetName(nsAString & aName)
310 {
311  aName = mName;
312  return NS_OK;
313 }
314 
315 NS_IMETHODIMP
316 sbMockCDDevice::GetReadable(PRBool *aReadable)
317 {
318  *aReadable = mReadable;
319  return NS_OK;
320 }
321 
322 NS_IMETHODIMP
323 sbMockCDDevice::GetWriteable(PRBool *aWritable)
324 {
325  *aWritable = mWritable;
326  return NS_OK;
327 }
328 
329 NS_IMETHODIMP
330 sbMockCDDevice::GetIsDiscInserted(PRBool *aDiscInserted)
331 {
332  *aDiscInserted = mDiscInserted;
333  return NS_OK;
334 }
335 
336 NS_IMETHODIMP
337 sbMockCDDevice::GetIdentifier(nsACString & aIdentifier)
338 {
339  // For the mock device, just rely on the device name.
340  aIdentifier.Assign(NS_ConvertUTF16toUTF8(mName));
341  return NS_OK;
342 }
343 
344 NS_IMETHODIMP
345 sbMockCDDevice::GetDiscTOC(sbICDTOC * *aDiscTOC)
346 {
347  NS_ENSURE_ARG_POINTER(aDiscTOC);
348  *aDiscTOC = mTOC;
349  NS_IF_ADDREF(*aDiscTOC);
350  return NS_OK;
351 }
352 
353 NS_IMETHODIMP
354 sbMockCDDevice::GetDiscType(PRUint32 *aDiscType)
355 {
356  *aDiscType = mDiscType;
357  return NS_OK;
358 }
359 
360 NS_IMETHODIMP
361 sbMockCDDevice::Eject()
362 {
363  // Inform the controller of the eject (so it can inform the listeners).
364  mEjected = PR_TRUE;
365  mDiscInserted = PR_FALSE;
366 
367  nsresult rv;
368  nsCOMPtr<sbIMockCDDeviceController> controller =
369  do_GetService(SB_MOCK_CDDEVICECONTROLLER_CONTRACTID, &rv);
370  if (NS_SUCCEEDED(rv) && controller) {
371  nsresult rv = controller->NotifyEject(this);
372  NS_ENSURE_SUCCESS(rv, rv);
373  }
374 
375  return NS_OK;
376 }
377 
378 //------------------------------------------------------------------------------
379 // sbIMockCDDevice
380 
381 NS_IMETHODIMP
382 sbMockCDDevice::Initialize(nsAString const & aName,
383  PRBool aReadable,
384  PRBool aWritable,
385  PRBool aDiscInserted,
386  PRUint32 aDiscType,
387  PRBool aEjected)
388 {
389  mName = aName;
390  mReadable = aReadable;
391  mWritable = aWritable;
392  mDiscInserted = aDiscInserted;
393  mDiscType = aDiscType;
394  mEjected = aEjected;
395 
396  return NS_OK;
397 }
398 
399 NS_IMETHODIMP
400 sbMockCDDevice::GetEjected(PRBool * aEjected)
401 {
402  NS_ENSURE_ARG_POINTER(aEjected);
403 
404  *aEjected = mEjected;
405 
406  return NS_OK;
407 }
408 
409 NS_IMETHODIMP
410 sbMockCDDevice::SetEjected(PRBool aEjected)
411 {
412  mEjected = aEjected;
413 
414  return NS_OK;
415 }
416 
417 NS_IMETHODIMP
418 sbMockCDDevice::SetDiscTOC(sbICDTOC * aDiscTOC)
419 {
420  mTOC = aDiscTOC;
421  mDiscInserted = PR_TRUE;
422  return NS_OK;
423 }
424 
425 NS_IMETHODIMP
426 sbMockCDDevice::GetIsDeviceLocked(PRBool *aIsLocked)
427 {
428  NS_ENSURE_ARG_POINTER(aIsLocked);
429 
430  *aIsLocked = mIsDeviceLocked;
431  return NS_OK;
432 }
433 
434 NS_IMETHODIMP
435 sbMockCDDevice::LockDevice()
436 {
437  mIsDeviceLocked = PR_TRUE;
438  return NS_OK;
439 }
440 
441 NS_IMETHODIMP
442 sbMockCDDevice::UnlockDevice()
443 {
444  mIsDeviceLocked = PR_FALSE;
445  return NS_OK;
446 }
447 
448 //==============================================================================
449 // Mock CD Device TOC Creation Utility Methods
450 //==============================================================================
451 
452 static nsresult
454 {
455  NS_ENSURE_ARG_POINTER(aOutTOC);
456 
457  nsresult rv;
458  nsCOMPtr<sbIMockCDTOC> toc =
459  do_CreateInstance("@songbirdnest.com/Songbird/MockCDTOC;1", &rv);
460  NS_ENSURE_SUCCESS(rv, rv);
461 
462  rv = toc->Initialize(1, 15, 285675);
463  NS_ENSURE_SUCCESS(rv, rv);
464  rv = toc->AddTocEntry(32, 309, 0, sbICDTOCEntry::TRACKMODE_AUDIO);
465  NS_ENSURE_SUCCESS(rv, rv);
466  rv = toc->AddTocEntry(23260, 231, 1, sbICDTOCEntry::TRACKMODE_AUDIO);
467  NS_ENSURE_SUCCESS(rv, rv);
468  rv = toc->AddTocEntry(40612, 242, 2, sbICDTOCEntry::TRACKMODE_AUDIO);
469  NS_ENSURE_SUCCESS(rv, rv);
470  rv = toc->AddTocEntry(58770, 191, 3, sbICDTOCEntry::TRACKMODE_AUDIO);
471  NS_ENSURE_SUCCESS(rv, rv);
472  rv = toc->AddTocEntry(73145, 310, 4, sbICDTOCEntry::TRACKMODE_AUDIO);
473  NS_ENSURE_SUCCESS(rv, rv);
474  rv = toc->AddTocEntry(96415, 290, 5, sbICDTOCEntry::TRACKMODE_AUDIO);
475  NS_ENSURE_SUCCESS(rv, rv);
476  rv = toc->AddTocEntry(118232, 301, 6, sbICDTOCEntry::TRACKMODE_AUDIO);
477  NS_ENSURE_SUCCESS(rv, rv);
478  rv = toc->AddTocEntry(140867, 259, 7, sbICDTOCEntry::TRACKMODE_AUDIO);
479  NS_ENSURE_SUCCESS(rv, rv);
480  rv = toc->AddTocEntry(160322, 316, 8, sbICDTOCEntry::TRACKMODE_AUDIO);
481  NS_ENSURE_SUCCESS(rv, rv);
482  rv = toc->AddTocEntry(184085, 222, 9, sbICDTOCEntry::TRACKMODE_AUDIO);
483  NS_ENSURE_SUCCESS(rv, rv);
484  rv = toc->AddTocEntry(200777, 236, 10, sbICDTOCEntry::TRACKMODE_AUDIO);
485  NS_ENSURE_SUCCESS(rv, rv);
486  rv = toc->AddTocEntry(218535, 185, 11, sbICDTOCEntry::TRACKMODE_AUDIO);
487  NS_ENSURE_SUCCESS(rv, rv);
488  rv = toc->AddTocEntry(232437, 211, 12, sbICDTOCEntry::TRACKMODE_AUDIO);
489  NS_ENSURE_SUCCESS(rv, rv);
490  rv = toc->AddTocEntry(248320, 184, 13, sbICDTOCEntry::TRACKMODE_AUDIO);
491  NS_ENSURE_SUCCESS(rv, rv);
492  rv = toc->AddTocEntry(262145, 313, 14, sbICDTOCEntry::TRACKMODE_AUDIO);
493  NS_ENSURE_SUCCESS(rv, rv);
494 
495  nsCOMPtr<sbICDTOC> qiTOC = do_QueryInterface(toc, &rv);
496  NS_ENSURE_SUCCESS(rv, rv);
497  qiTOC.forget(aOutTOC);
498  return NS_OK;
499 }
500 
501 static nsresult
503 {
504  NS_ENSURE_ARG_POINTER(aOutTOC);
505 
506  nsresult rv;
507  nsCOMPtr<sbIMockCDTOC> toc =
508  do_CreateInstance("@songbirdnest.com/Songbird/MockCDTOC;1", &rv);
509  NS_ENSURE_SUCCESS(rv, rv);
510 
511  rv = toc->Initialize(1, 12, 260335);
512  NS_ENSURE_SUCCESS(rv, rv);
513 
514  rv = toc->AddTocEntry(0, 211, 0, sbICDTOCEntry::TRACKMODE_AUDIO);
515  NS_ENSURE_SUCCESS(rv, rv);
516  rv = toc->AddTocEntry(15847, 200, 1, sbICDTOCEntry::TRACKMODE_AUDIO);
517  NS_ENSURE_SUCCESS(rv, rv);
518  rv = toc->AddTocEntry(30859, 246, 2, sbICDTOCEntry::TRACKMODE_AUDIO);
519  NS_ENSURE_SUCCESS(rv, rv);
520  rv = toc->AddTocEntry(49320, 202, 3, sbICDTOCEntry::TRACKMODE_AUDIO);
521  NS_ENSURE_SUCCESS(rv, rv);
522  rv = toc->AddTocEntry(64479, 245, 4, sbICDTOCEntry::TRACKMODE_AUDIO);
523  NS_ENSURE_SUCCESS(rv, rv);
524  rv = toc->AddTocEntry(82865, 312, 5, sbICDTOCEntry::TRACKMODE_AUDIO);
525  NS_ENSURE_SUCCESS(rv, rv);
526  rv = toc->AddTocEntry(106307, 234, 6, sbICDTOCEntry::TRACKMODE_AUDIO);
527  NS_ENSURE_SUCCESS(rv, rv);
528  rv = toc->AddTocEntry(123929, 243, 7, sbICDTOCEntry::TRACKMODE_AUDIO);
529  NS_ENSURE_SUCCESS(rv, rv);
530  rv = toc->AddTocEntry(142217, 216, 8, sbICDTOCEntry::TRACKMODE_AUDIO);
531  NS_ENSURE_SUCCESS(rv, rv);
532  rv = toc->AddTocEntry(158447, 223, 9, sbICDTOCEntry::TRACKMODE_AUDIO);
533  NS_ENSURE_SUCCESS(rv, rv);
534  rv = toc->AddTocEntry(175179, 223, 10, sbICDTOCEntry::TRACKMODE_AUDIO);
535  NS_ENSURE_SUCCESS(rv, rv);
536  rv = toc->AddTocEntry(203309, 760, 11, sbICDTOCEntry::TRACKMODE_AUDIO);
537  NS_ENSURE_SUCCESS(rv, rv);
538 
539  nsCOMPtr<sbICDTOC> qiTOC = do_QueryInterface(toc, &rv);
540  NS_ENSURE_SUCCESS(rv, rv);
541  qiTOC.forget(aOutTOC);
542  return NS_OK;
543 }
544 
545 static nsresult
547 {
548  NS_ENSURE_ARG_POINTER(aOutTOC);
549 
550  nsresult rv;
551  nsCOMPtr<sbIMockCDTOC> toc =
552  do_CreateInstance("@songbirdnest.com/Songbird/MockCDTOC;1", &rv);
553  NS_ENSURE_SUCCESS(rv, rv);
554 
555  rv = toc->Initialize(1, 11, 225562);
556  NS_ENSURE_SUCCESS(rv, rv);
557 
558  rv = toc->AddTocEntry(150, 248, 0, sbICDTOCEntry::TRACKMODE_AUDIO);
559  NS_ENSURE_SUCCESS(rv, rv);
560  rv = toc->AddTocEntry(18843, 272, 1, sbICDTOCEntry::TRACKMODE_AUDIO);
561  NS_ENSURE_SUCCESS(rv, rv);
562  rv = toc->AddTocEntry(39601, 227, 2, sbICDTOCEntry::TRACKMODE_AUDIO);
563  NS_ENSURE_SUCCESS(rv, rv);
564  rv = toc->AddTocEntry(56966, 296, 3, sbICDTOCEntry::TRACKMODE_AUDIO);
565  NS_ENSURE_SUCCESS(rv, rv);
566  rv = toc->AddTocEntry(79487, 267, 4, sbICDTOCEntry::TRACKMODE_AUDIO);
567  NS_ENSURE_SUCCESS(rv, rv);
568  rv = toc->AddTocEntry(99796, 219, 5, sbICDTOCEntry::TRACKMODE_AUDIO);
569  NS_ENSURE_SUCCESS(rv, rv);
570  rv = toc->AddTocEntry(116534, 226, 6, sbICDTOCEntry::TRACKMODE_AUDIO);
571  NS_ENSURE_SUCCESS(rv, rv);
572  rv = toc->AddTocEntry(133832, 288, 7, sbICDTOCEntry::TRACKMODE_AUDIO);
573  NS_ENSURE_SUCCESS(rv, rv);
574  rv = toc->AddTocEntry(155768, 258, 8, sbICDTOCEntry::TRACKMODE_AUDIO);
575  NS_ENSURE_SUCCESS(rv, rv);
576  rv = toc->AddTocEntry(175400, 330, 9, sbICDTOCEntry::TRACKMODE_AUDIO);
577  NS_ENSURE_SUCCESS(rv, rv);
578  rv = toc->AddTocEntry(200468, 331, 10, sbICDTOCEntry::TRACKMODE_AUDIO);
579  NS_ENSURE_SUCCESS(rv, rv);
580 
581  nsCOMPtr<sbICDTOC> qiTOC = do_QueryInterface(toc, &rv);
582  NS_ENSURE_SUCCESS(rv, rv);
583  qiTOC.forget(aOutTOC);
584  return NS_OK;
585 }
586 
587 static nsresult
589 {
590  NS_ENSURE_ARG_POINTER(aOutTOC);
591 
592  nsresult rv;
593  nsCOMPtr<sbIMockCDTOC> toc =
594  do_CreateInstance("@songbirdnest.com/Songbird/MockCDTOC;1", &rv);
595  NS_ENSURE_SUCCESS(rv, rv);
596 
597  rv = toc->Initialize(1, 19, 190565);
598  NS_ENSURE_SUCCESS(rv, rv);
599 
600  rv = toc->AddTocEntry(150, 76, 0, sbICDTOCEntry::TRACKMODE_AUDIO);
601  NS_ENSURE_SUCCESS(rv, rv);
602  rv = toc->AddTocEntry(5896, 155, 1, sbICDTOCEntry::TRACKMODE_AUDIO);
603  NS_ENSURE_SUCCESS(rv, rv);
604  rv = toc->AddTocEntry(17528, 151, 2, sbICDTOCEntry::TRACKMODE_AUDIO);
605  NS_ENSURE_SUCCESS(rv, rv);
606  rv = toc->AddTocEntry(28879, 156, 3, sbICDTOCEntry::TRACKMODE_AUDIO);
607  NS_ENSURE_SUCCESS(rv, rv);
608  rv = toc->AddTocEntry(40599, 126, 4, sbICDTOCEntry::TRACKMODE_AUDIO);
609  NS_ENSURE_SUCCESS(rv, rv);
610  rv = toc->AddTocEntry(50106, 139, 5, sbICDTOCEntry::TRACKMODE_AUDIO);
611  NS_ENSURE_SUCCESS(rv, rv);
612  rv = toc->AddTocEntry(60584, 64, 6, sbICDTOCEntry::TRACKMODE_AUDIO);
613  NS_ENSURE_SUCCESS(rv, rv);
614  rv = toc->AddTocEntry(65394, 193, 7, sbICDTOCEntry::TRACKMODE_AUDIO);
615  NS_ENSURE_SUCCESS(rv, rv);
616  rv = toc->AddTocEntry(79870, 34, 8, sbICDTOCEntry::TRACKMODE_AUDIO);
617  NS_ENSURE_SUCCESS(rv, rv);
618  rv = toc->AddTocEntry(82446, 106, 9, sbICDTOCEntry::TRACKMODE_AUDIO);
619  NS_ENSURE_SUCCESS(rv, rv);
620  rv = toc->AddTocEntry(90457, 123, 10, sbICDTOCEntry::TRACKMODE_AUDIO);
621  NS_ENSURE_SUCCESS(rv, rv);
622  rv = toc->AddTocEntry(99748, 193, 11, sbICDTOCEntry::TRACKMODE_AUDIO);
623  NS_ENSURE_SUCCESS(rv, rv);
624  rv = toc->AddTocEntry(114258, 126, 12, sbICDTOCEntry::TRACKMODE_AUDIO);
625  NS_ENSURE_SUCCESS(rv, rv);
626  rv = toc->AddTocEntry(123750, 161, 13, sbICDTOCEntry::TRACKMODE_AUDIO);
627  NS_ENSURE_SUCCESS(rv, rv);
628  rv = toc->AddTocEntry(135829, 65, 14, sbICDTOCEntry::TRACKMODE_AUDIO);
629  NS_ENSURE_SUCCESS(rv, rv);
630  rv = toc->AddTocEntry(140754, 167, 15, sbICDTOCEntry::TRACKMODE_AUDIO);
631  NS_ENSURE_SUCCESS(rv, rv);
632  rv = toc->AddTocEntry(153283, 175, 16, sbICDTOCEntry::TRACKMODE_AUDIO);
633  NS_ENSURE_SUCCESS(rv, rv);
634  rv = toc->AddTocEntry(166425, 149, 17, sbICDTOCEntry::TRACKMODE_AUDIO);
635  NS_ENSURE_SUCCESS(rv, rv);
636  rv = toc->AddTocEntry(177440, 179, 18, sbICDTOCEntry::TRACKMODE_AUDIO);
637  NS_ENSURE_SUCCESS(rv, rv);
638 
639  nsCOMPtr<sbICDTOC> qiTOC = do_QueryInterface(toc, &rv);
640  NS_ENSURE_SUCCESS(rv, rv);
641  qiTOC.forget(aOutTOC);
642  return NS_OK;
643 }
644 
645 
646 //==============================================================================
647 // Mock CD Device Service
648 //==============================================================================
649 
652 {
653 public:
654  sbMockCDService();
655  virtual ~sbMockCDService();
656 
658  NS_DECL_SBICDDEVICESERVICE
659  NS_DECL_SBIMOCKCDDEVICECONTROLLER
660 
661  nsresult Init();
662 
663 protected:
664  nsCOMArray<sbICDDeviceListener> mListeners;
665  nsCOMArray<sbICDDevice> mDevices;
666 };
667 
668 
672 
674 {
675 }
676 
678 {
679 }
680 
681 nsresult
683 {
684  NS_ENSURE_TRUE(mDevices.Count() == 0, NS_ERROR_UNEXPECTED);
685 
686  // Create two mock cd devices.
687  nsresult rv;
688  nsCOMPtr<sbIMockCDDevice> device1 =
689  do_CreateInstance("@songbirdnest.com/Songbird/MockCDDevice;1", &rv);
690  NS_ENSURE_SUCCESS(rv, rv);
691 
692  rv = device1->Initialize(
693  NS_LITERAL_STRING("Songbird MockCD Device 8000"),
694  PR_TRUE, // readable
695  PR_FALSE, // writable
696  PR_FALSE, // is disc inserted
698  PR_FALSE); // is disc ejected
699  NS_ENSURE_SUCCESS(rv, rv);
700 
701  nsCOMPtr<sbIMockCDDevice> device2 =
702  do_CreateInstance("@songbirdnest.com/Songbird/MockCDDevice;1", &rv);
703  NS_ENSURE_SUCCESS(rv, rv);
704 
705  rv = device2->Initialize(
706  NS_LITERAL_STRING("Songbird MockCD Device 7000"),
707  PR_TRUE, // readable
708  PR_FALSE, // writable
709  PR_FALSE, // is disc inserted
711  PR_FALSE); // is disc ejected
712  NS_ENSURE_SUCCESS(rv, rv);
713 
714  nsCOMPtr<sbICDDevice> cdDevice1 = do_QueryInterface(device1, &rv);
715  NS_ENSURE_SUCCESS(rv, rv);
716  nsCOMPtr<sbICDDevice> cdDevice2 = do_QueryInterface(device2, &rv);
717  NS_ENSURE_SUCCESS(rv, rv);
718  mDevices.AppendObject(cdDevice1);
719  mDevices.AppendObject(cdDevice2);
720 
721  return NS_OK;
722 }
723 
724 //------------------------------------------------------------------------------
725 // sbICDDeviceService
726 
727 NS_IMETHODIMP
728 sbMockCDService::GetWeight(PRInt32 *aWeight)
729 {
730  NS_ENSURE_ARG_POINTER(aWeight);
731  // return a weight of 0 effectively making the mock CD service selected
732  // only if no other service wants to assume responsibility.
733  *aWeight = 0;
734  return NS_OK;
735 }
736 
737 NS_IMETHODIMP
738 sbMockCDService::GetNbDevices(PRInt32 *aNbDevices)
739 {
740  NS_ENSURE_ARG_POINTER(aNbDevices);
741  *aNbDevices = mDevices.Count();
742  return NS_OK;
743 }
744 
745 NS_IMETHODIMP
746 sbMockCDService::GetDevice(PRInt32 deviceIndex, sbICDDevice **_retval)
747 {
748  NS_ENSURE_ARG_POINTER(_retval);
749  NS_ENSURE_TRUE(deviceIndex < mDevices.Count(), NS_ERROR_UNEXPECTED);
750  NS_IF_ADDREF(*_retval = mDevices[deviceIndex]);
751  return NS_OK;
752 }
753 
754 NS_IMETHODIMP
755 sbMockCDService::GetDeviceFromIdentifier(const nsACString & aDeviceIdentifier,
756  sbICDDevice **_retval)
757 {
758  *_retval = nsnull;
759  for (PRInt32 i = 0; i < mDevices.Count(); i++) {
760  nsCOMPtr<sbICDDevice> curDevice = mDevices[i];
761 
762  nsCString deviceIdentifier;
763  nsresult rv = curDevice->GetIdentifier(deviceIdentifier);
764  NS_ENSURE_SUCCESS(rv, rv);
765 
766  if (deviceIdentifier.Equals(aDeviceIdentifier)) {
767  curDevice.forget(_retval);
768  break;
769  }
770  }
771 
772  return NS_OK;
773 }
774 
775 NS_IMETHODIMP
776 sbMockCDService::GetCDDevices(nsISimpleEnumerator **_retval)
777 {
778  NS_ENSURE_ARG_POINTER(_retval);
779  // Convert to a nsIArray and enumerate.
780  return NS_NewArrayEnumerator(_retval, mDevices);
781 }
782 
783 NS_IMETHODIMP
784 sbMockCDService::RegisterListener(sbICDDeviceListener *listener)
785 {
786  NS_ENSURE_ARG_POINTER(listener);
787  mListeners.AppendObject(listener);
788  return NS_OK;
789 }
790 
791 NS_IMETHODIMP
792 sbMockCDService::RemoveListener(sbICDDeviceListener *listener)
793 {
794  NS_ENSURE_ARG_POINTER(listener);
795  mListeners.RemoveObject(listener);
796  return NS_OK;
797 }
798 
799 //------------------------------------------------------------------------------
800 // sbIMockCDDeviceController
801 
802 NS_IMETHODIMP
803 sbMockCDService::InsertMedia(sbICDDevice *aCDDevice, PRUint16 aMediaDisc)
804 {
805  NS_ENSURE_ARG_POINTER(aCDDevice);
806 
807  // Don't insert media twice.
808  nsresult rv;
809  PRBool isDiscInserted = PR_FALSE;
810  rv = aCDDevice->GetIsDiscInserted(&isDiscInserted);
811  if (NS_FAILED(rv) || isDiscInserted) {
812  return NS_OK;
813  }
814 
815  // Determine which TOC to insert.
816  nsCOMPtr<sbICDTOC> mediaTOC;
817  switch (aMediaDisc) {
819  rv = SB_MakeMidnightRock(getter_AddRefs(mediaTOC));
820  NS_ENSURE_SUCCESS(rv, rv);
821  break;
822 
824  rv = SB_MakeBabyOneMoreTime(getter_AddRefs(mediaTOC));
825  NS_ENSURE_SUCCESS(rv, rv);
826  break;
827 
829  rv = SB_MakeAllThatYouCantLeaveBehind(getter_AddRefs(mediaTOC));
830  NS_ENSURE_SUCCESS(rv, rv);
831  break;
832 
834  rv = SB_MakeIncredibad(getter_AddRefs(mediaTOC));
835  NS_ENSURE_SUCCESS(rv, rv);
836  break;
837  }
838 
839  nsCOMPtr<sbIMockCDDevice> mockDevice = do_QueryInterface(aCDDevice, &rv);
840  NS_ENSURE_SUCCESS(rv, rv);
841 
842  rv = mockDevice->SetDiscTOC(mediaTOC);
843  NS_ENSURE_SUCCESS(rv, rv);
844 
845  // Inform the listeners.
846  for (PRInt32 i = 0; i < mListeners.Count(); i++) {
847  rv = mListeners[i]->OnMediaInserted(aCDDevice);
848  NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
849  "Could not inform the listener of media insertion!");
850  }
851 
852  return NS_OK;
853 }
854 
855 NS_IMETHODIMP
856 sbMockCDService::EjectMedia(sbICDDevice *aCDDevice)
857 {
858  NS_ENSURE_ARG_POINTER(aCDDevice);
859 
860  // Ensure that this is a mock cd device first.
861  nsresult rv;
862  nsCOMPtr<sbIMockCDDevice> mockDevice = do_QueryInterface(aCDDevice, &rv);
863  NS_ENSURE_SUCCESS(rv, rv);
864 
865  PRBool isDiscInserted = PR_FALSE;
866  rv = aCDDevice->GetIsDiscInserted(&isDiscInserted);
867  if (NS_FAILED(rv) || !isDiscInserted) {
868  return NS_OK;
869  }
870 
871  rv = aCDDevice->Eject();
872  NS_ENSURE_SUCCESS(rv, rv);
873 
874  // Inform the listeners
875  for (PRInt32 i = 0; i < mListeners.Count(); i++) {
876  rv = mListeners[i]->OnMediaEjected(aCDDevice);
877  NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
878  "Could not inform the listener of media eject!");
879  }
880 
881  return NS_OK;
882 }
883 
884 NS_IMETHODIMP
885 sbMockCDService::NotifyEject(sbICDDevice *aCDDevice)
886 {
887  NS_ENSURE_ARG_POINTER(aCDDevice);
888 
889  // Ensure that a mock CD device was removed.
890  nsresult rv;
891  nsCOMPtr<sbIMockCDDevice> mockDevice = do_QueryInterface(aCDDevice, &rv);
892  NS_ENSURE_SUCCESS(rv, rv);
893 
894  // Inform the listeners
895  for (PRInt32 i = 0; i < mListeners.Count(); i++) {
896  rv = mListeners[i]->OnMediaEjected(aCDDevice);
897  NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
898  "Could not inform the listener of media eject!");
899  }
900 
901  return NS_OK;
902 }
903 
904 
905 //==============================================================================
906 // XPCOM component registration
907 //==============================================================================
908 
912 
913 static nsModuleComponentInfo sbMockCDDevice[] =
914 {
915  {
919  sbMockCDDeviceConstructor,
920  },
921  {
925  sbMockCDTOCConstructor,
926  },
927  {
931  sbMockCDServiceConstructor
932  }
933 };
934 
935 NS_IMPL_NSGETMODULE(SongbirdMockCDDevice, sbMockCDDevice)
virtual ~sbMockCDService()
#define SB_MOCK_CDDEVICE_CLASSNAME
classDescription entry
Definition: FeedWriter.js:1427
sbMockCDTOCEntry(PRInt32 aFrameOffset, PRTime aLength, PRInt32 aTrackNumber, PRInt16 aTrackMode, nsAString const &aDrive)
nsresult sbCOMArrayTonsIArray(T &aCOMArray, nsIArray **aOutArray)
Definition: sbArrayUtils.h:45
NS_IMPL_THREADSAFE_ISUPPORTS1(sbMockCDTOCEntry, sbICDTOCEntry)
return NS_OK
const unsigned short MOCK_MEDIA_DISC_INCREDIBAD
#define SB_MOCK_CDDEVICECONTROLLER_CONTRACTID
#define SB_MOCK_CDTOC_CID
#define SB_MOCK_CDDEVICE_CONTRACTID
#define SB_MOCK_CDDEVICE_CID
NS_IMPL_THREADSAFE_ISUPPORTS2(sbMockCDService, sbICDDeviceService, sbIMockCDDeviceController) sbMockCDService
static nsresult SB_MakeIncredibad(sbICDTOC **aOutTOC)
nsCOMArray< sbICDDevice > mDevices
virtual ~sbMockCDTOCEntry()
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(sbMockDeviceFirmwareHandler, Init)
const unsigned short MOCK_MEDIA_DISC_MIDNIGHT_ROCK
Definition: sbICDDevice.idl:41
#define SB_MOCK_CDTOC_CONTRACTID
nsCOMArray< sbICDDeviceListener > mListeners
#define SB_MOCK_CDDEVICECONTROLLER_CID
static nsresult SB_MakeAllThatYouCantLeaveBehind(sbICDTOC **aOutTOC)
#define SB_MOCK_CDDEVICECONTROLLER_CLASSNAME
static nsresult SB_MakeBabyOneMoreTime(sbICDTOC **aOutTOC)
static nsresult SB_MakeMidnightRock(sbICDTOC **aOutTOC)
function Init()
NS_DECL_ISUPPORTS NS_DECL_SBICDDEVICESERVICE NS_DECL_SBIMOCKCDDEVICECONTROLLER nsresult Init()
_updateCookies aName
NS_IMPL_NSGETMODULE(SongbirdIdentityServiceComponent, sbIdentityServiceComponent)
const unsigned short TRACKMODE_AUDIO
Definition: sbICDDevice.idl:46
var uri
Definition: FeedWriter.js:1135
#define SB_MOCK_CDTOC_CLASSNAME
sbMockCDTOC(PRInt32 aFirstTrackIndex, PRInt32 aLastTrackIndex, PRInt32 aLeadOutTrackOffset)
sbMockCDDevice(nsAString const &aName, PRBool aReadable, PRBool aWritable, PRBool aDiscInserted, PRUint32 aDiscType)
const unsigned long AUDIO_DISC_TYPE
const unsigned short MOCK_MEDIA_DISC_BABY_ONE_MORE_TIME
NS_GENERIC_FACTORY_CONSTRUCTOR(sbMediaSniffer)
_getSelectedPageStyle s i
NS_DECL_ISUPPORTS NS_DECL_SBICDTOC static NS_DECL_SBIMOCKCDTOC sbMockCDTOC * New(PRInt32 aFirstTrackIndex, PRInt32 aLastTrackIndex, PRInt32 aLeadOutTrackOffset)
NS_DECL_ISUPPORTS static NS_DECL_SBICDTOCENTRY sbMockCDTOCEntry * New(PRInt32 aFrameOffset, PRTime aLength, PRInt32 aTrackNumber, PRInt16 aTrackMode, nsAString const &aDrive)
NS_DECL_ISUPPORTS NS_DECL_SBICDDEVICE static NS_DECL_SBIMOCKCDDEVICE sbMockCDDevice * New(nsAString const &aName, PRBool aReadable, PRBool aWritable, PRBool aDiscInserted, PRUint32 aDiscType)