26 #include <sbICDDevice.h>
27 #include <sbICDDeviceService.h>
28 #include <sbIMockCDDevice.h>
29 #include <sbIMockCDDeviceController.h>
31 #include <nsArrayEnumerator.h>
32 #include <nsCOMArray.h>
33 #include <nsServiceManagerUtils.h>
34 #include <nsICategoryManager.h>
35 #include <nsIGenericFactory.h>
52 nsAString
const & aDrive)
66 nsAString
const & aDrive) :
67 mFrameOffset(aFrameOffset),
69 mTrackNumber(aTrackNumber),
70 mTrackMode(aTrackMode),
88 sbMockCDTOCEntry::GetFrameOffset(PRInt32 *aFrameOffset)
90 NS_ENSURE_ARG_POINTER(aFrameOffset);
92 *aFrameOffset = mFrameOffset;
97 sbMockCDTOCEntry::GetLength(PRTime *aLength)
99 NS_ENSURE_ARG_POINTER(aLength);
106 sbMockCDTOCEntry::GetTrackNumber(PRInt32 *aTrackNumber)
108 NS_ENSURE_ARG_POINTER(aTrackNumber);
110 *aTrackNumber = mTrackNumber;
115 sbMockCDTOCEntry::GetTrackURI(nsAString & aTrackURI)
118 uri.AssignLiteral(
"cdda:///");
120 uri.AppendLiteral(
"/");
121 uri.AppendInt(mTrackNumber);
127 sbMockCDTOCEntry::GetTrackMode(PRInt16 *aTrackMode)
129 NS_ENSURE_ARG_POINTER(aTrackMode);
131 *aTrackMode = mTrackMode;
147 PRInt32 aLastTrackIndex,
148 PRInt32 aLeadOutTrackOffset)
152 aLeadOutTrackOffset);
156 mLeadOutTrackOffset(0) {}
159 PRInt32 aLastTrackIndex,
160 PRInt32 aLeadOutTrackOffset) :
161 mFirstTrackIndex(aFirstTrackIndex),
162 mLastTrackIndex(aLastTrackIndex),
163 mLeadOutTrackOffset(aLeadOutTrackOffset) {}
166 nsCOMArray<sbICDTOCEntry> mTracks;
167 PRInt32 mFirstTrackIndex;
168 PRInt32 mLastTrackIndex;
169 PRInt32 mLeadOutTrackOffset;
176 sbMockCDTOC::GetFirstTrackIndex(PRInt32 *aFirstTrackIndex)
178 NS_ENSURE_ARG_POINTER(aFirstTrackIndex);
180 *aFirstTrackIndex = mFirstTrackIndex;
186 sbMockCDTOC::GetLastTrackIndex(PRInt32 *aLastTrackIndex)
188 NS_ENSURE_ARG_POINTER(aLastTrackIndex);
190 *aLastTrackIndex = mLastTrackIndex;
196 sbMockCDTOC::GetLeadOutTrackOffset(PRInt32 *aLeadOutTrackOffset)
198 NS_ENSURE_ARG_POINTER(aLeadOutTrackOffset);
200 *aLeadOutTrackOffset = mLeadOutTrackOffset;
206 sbMockCDTOC::GetTracks(nsIArray * *aTracks)
208 NS_ENSURE_ARG_POINTER(aTracks);
211 NS_ENSURE_SUCCESS(rv, rv);
217 sbMockCDTOC::AddTocEntry(PRInt32 frameOffset,
226 NS_LITERAL_STRING(
"f:"));
227 NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
229 PRBool
const added = mTracks.AppendObject(entry);
230 NS_ENSURE_TRUE(added, NS_ERROR_OUT_OF_MEMORY);
236 sbMockCDTOC::Initialize(PRInt32 aFirstTrackIndex,
237 PRInt32 aLastTrackIndex,
238 PRInt32 aLeadOutTrackOffset)
240 mFirstTrackIndex = aFirstTrackIndex;
241 mLastTrackIndex = aLastTrackIndex;
242 mLeadOutTrackOffset = aLeadOutTrackOffset;
256 NS_DECL_SBIMOCKCDDEVICE
261 PRBool aDiscInserted,
273 mDiscInserted(PR_FALSE),
274 mIsDeviceLocked(PR_FALSE),
276 mEjected(PR_FALSE) {}
280 NS_ASSERTION(!mIsDeviceLocked,
"ERROR: Device is still locked!!!!!!!!");
287 PRBool aDiscInserted,
288 PRUint32 aDiscType) :
290 mReadable(aReadable),
291 mWritable(aWritable),
292 mDiscInserted(aDiscInserted),
293 mDiscType(aDiscType),
294 mEjected(PR_FALSE) {}
299 PRBool mDiscInserted;
300 PRBool mIsDeviceLocked;
303 nsCOMPtr<sbICDTOC> mTOC;
316 sbMockCDDevice::GetReadable(PRBool *aReadable)
318 *aReadable = mReadable;
323 sbMockCDDevice::GetWriteable(PRBool *aWritable)
325 *aWritable = mWritable;
330 sbMockCDDevice::GetIsDiscInserted(PRBool *aDiscInserted)
332 *aDiscInserted = mDiscInserted;
337 sbMockCDDevice::GetIdentifier(nsACString & aIdentifier)
340 aIdentifier.Assign(NS_ConvertUTF16toUTF8(mName));
345 sbMockCDDevice::GetDiscTOC(
sbICDTOC * *aDiscTOC)
347 NS_ENSURE_ARG_POINTER(aDiscTOC);
349 NS_IF_ADDREF(*aDiscTOC);
354 sbMockCDDevice::GetDiscType(PRUint32 *aDiscType)
356 *aDiscType = mDiscType;
361 sbMockCDDevice::Eject()
365 mDiscInserted = PR_FALSE;
368 nsCOMPtr<sbIMockCDDeviceController> controller =
370 if (NS_SUCCEEDED(rv) && controller) {
371 nsresult rv = controller->NotifyEject(
this);
372 NS_ENSURE_SUCCESS(rv, rv);
382 sbMockCDDevice::Initialize(nsAString
const &
aName,
385 PRBool aDiscInserted,
390 mReadable = aReadable;
391 mWritable = aWritable;
392 mDiscInserted = aDiscInserted;
393 mDiscType = aDiscType;
400 sbMockCDDevice::GetEjected(PRBool * aEjected)
402 NS_ENSURE_ARG_POINTER(aEjected);
404 *aEjected = mEjected;
410 sbMockCDDevice::SetEjected(PRBool aEjected)
418 sbMockCDDevice::SetDiscTOC(
sbICDTOC * aDiscTOC)
421 mDiscInserted = PR_TRUE;
426 sbMockCDDevice::GetIsDeviceLocked(PRBool *aIsLocked)
428 NS_ENSURE_ARG_POINTER(aIsLocked);
430 *aIsLocked = mIsDeviceLocked;
435 sbMockCDDevice::LockDevice()
437 mIsDeviceLocked = PR_TRUE;
442 sbMockCDDevice::UnlockDevice()
444 mIsDeviceLocked = PR_FALSE;
455 NS_ENSURE_ARG_POINTER(aOutTOC);
458 nsCOMPtr<sbIMockCDTOC> toc =
459 do_CreateInstance(
"@songbirdnest.com/Songbird/MockCDTOC;1", &rv);
460 NS_ENSURE_SUCCESS(rv, rv);
462 rv = toc->Initialize(1, 15, 285675);
463 NS_ENSURE_SUCCESS(rv, rv);
465 NS_ENSURE_SUCCESS(rv, rv);
467 NS_ENSURE_SUCCESS(rv, rv);
469 NS_ENSURE_SUCCESS(rv, rv);
471 NS_ENSURE_SUCCESS(rv, rv);
473 NS_ENSURE_SUCCESS(rv, rv);
475 NS_ENSURE_SUCCESS(rv, rv);
477 NS_ENSURE_SUCCESS(rv, rv);
479 NS_ENSURE_SUCCESS(rv, rv);
481 NS_ENSURE_SUCCESS(rv, rv);
483 NS_ENSURE_SUCCESS(rv, rv);
485 NS_ENSURE_SUCCESS(rv, rv);
487 NS_ENSURE_SUCCESS(rv, rv);
489 NS_ENSURE_SUCCESS(rv, rv);
491 NS_ENSURE_SUCCESS(rv, rv);
493 NS_ENSURE_SUCCESS(rv, rv);
495 nsCOMPtr<sbICDTOC> qiTOC = do_QueryInterface(toc, &rv);
496 NS_ENSURE_SUCCESS(rv, rv);
497 qiTOC.forget(aOutTOC);
504 NS_ENSURE_ARG_POINTER(aOutTOC);
507 nsCOMPtr<sbIMockCDTOC> toc =
508 do_CreateInstance(
"@songbirdnest.com/Songbird/MockCDTOC;1", &rv);
509 NS_ENSURE_SUCCESS(rv, rv);
511 rv = toc->Initialize(1, 12, 260335);
512 NS_ENSURE_SUCCESS(rv, rv);
515 NS_ENSURE_SUCCESS(rv, rv);
517 NS_ENSURE_SUCCESS(rv, rv);
519 NS_ENSURE_SUCCESS(rv, rv);
521 NS_ENSURE_SUCCESS(rv, rv);
523 NS_ENSURE_SUCCESS(rv, rv);
525 NS_ENSURE_SUCCESS(rv, rv);
527 NS_ENSURE_SUCCESS(rv, rv);
529 NS_ENSURE_SUCCESS(rv, rv);
531 NS_ENSURE_SUCCESS(rv, rv);
533 NS_ENSURE_SUCCESS(rv, rv);
535 NS_ENSURE_SUCCESS(rv, rv);
537 NS_ENSURE_SUCCESS(rv, rv);
539 nsCOMPtr<sbICDTOC> qiTOC = do_QueryInterface(toc, &rv);
540 NS_ENSURE_SUCCESS(rv, rv);
541 qiTOC.forget(aOutTOC);
548 NS_ENSURE_ARG_POINTER(aOutTOC);
551 nsCOMPtr<sbIMockCDTOC> toc =
552 do_CreateInstance(
"@songbirdnest.com/Songbird/MockCDTOC;1", &rv);
553 NS_ENSURE_SUCCESS(rv, rv);
555 rv = toc->Initialize(1, 11, 225562);
556 NS_ENSURE_SUCCESS(rv, rv);
559 NS_ENSURE_SUCCESS(rv, rv);
561 NS_ENSURE_SUCCESS(rv, rv);
563 NS_ENSURE_SUCCESS(rv, rv);
565 NS_ENSURE_SUCCESS(rv, rv);
567 NS_ENSURE_SUCCESS(rv, rv);
569 NS_ENSURE_SUCCESS(rv, rv);
571 NS_ENSURE_SUCCESS(rv, rv);
573 NS_ENSURE_SUCCESS(rv, rv);
575 NS_ENSURE_SUCCESS(rv, rv);
577 NS_ENSURE_SUCCESS(rv, rv);
579 NS_ENSURE_SUCCESS(rv, rv);
581 nsCOMPtr<sbICDTOC> qiTOC = do_QueryInterface(toc, &rv);
582 NS_ENSURE_SUCCESS(rv, rv);
583 qiTOC.forget(aOutTOC);
590 NS_ENSURE_ARG_POINTER(aOutTOC);
593 nsCOMPtr<sbIMockCDTOC> toc =
594 do_CreateInstance(
"@songbirdnest.com/Songbird/MockCDTOC;1", &rv);
595 NS_ENSURE_SUCCESS(rv, rv);
597 rv = toc->Initialize(1, 19, 190565);
598 NS_ENSURE_SUCCESS(rv, rv);
601 NS_ENSURE_SUCCESS(rv, rv);
603 NS_ENSURE_SUCCESS(rv, rv);
605 NS_ENSURE_SUCCESS(rv, rv);
607 NS_ENSURE_SUCCESS(rv, rv);
609 NS_ENSURE_SUCCESS(rv, rv);
611 NS_ENSURE_SUCCESS(rv, rv);
613 NS_ENSURE_SUCCESS(rv, rv);
615 NS_ENSURE_SUCCESS(rv, rv);
617 NS_ENSURE_SUCCESS(rv, rv);
619 NS_ENSURE_SUCCESS(rv, rv);
621 NS_ENSURE_SUCCESS(rv, rv);
623 NS_ENSURE_SUCCESS(rv, rv);
625 NS_ENSURE_SUCCESS(rv, rv);
627 NS_ENSURE_SUCCESS(rv, rv);
629 NS_ENSURE_SUCCESS(rv, rv);
631 NS_ENSURE_SUCCESS(rv, rv);
633 NS_ENSURE_SUCCESS(rv, rv);
635 NS_ENSURE_SUCCESS(rv, rv);
637 NS_ENSURE_SUCCESS(rv, rv);
639 nsCOMPtr<sbICDTOC> qiTOC = do_QueryInterface(toc, &rv);
640 NS_ENSURE_SUCCESS(rv, rv);
641 qiTOC.forget(aOutTOC);
658 NS_DECL_SBICDDEVICESERVICE
659 NS_DECL_SBIMOCKCDDEVICECONTROLLER
684 NS_ENSURE_TRUE(
mDevices.Count() == 0, NS_ERROR_UNEXPECTED);
688 nsCOMPtr<sbIMockCDDevice> device1 =
689 do_CreateInstance(
"@songbirdnest.com/Songbird/MockCDDevice;1", &rv);
690 NS_ENSURE_SUCCESS(rv, rv);
692 rv = device1->Initialize(
693 NS_LITERAL_STRING(
"Songbird MockCD Device 8000"),
699 NS_ENSURE_SUCCESS(rv, rv);
701 nsCOMPtr<sbIMockCDDevice> device2 =
702 do_CreateInstance(
"@songbirdnest.com/Songbird/MockCDDevice;1", &rv);
703 NS_ENSURE_SUCCESS(rv, rv);
705 rv = device2->Initialize(
706 NS_LITERAL_STRING(
"Songbird MockCD Device 7000"),
712 NS_ENSURE_SUCCESS(rv, rv);
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);
728 sbMockCDService::GetWeight(PRInt32 *aWeight)
730 NS_ENSURE_ARG_POINTER(aWeight);
738 sbMockCDService::GetNbDevices(PRInt32 *aNbDevices)
740 NS_ENSURE_ARG_POINTER(aNbDevices);
746 sbMockCDService::GetDevice(PRInt32 deviceIndex,
sbICDDevice **_retval)
748 NS_ENSURE_ARG_POINTER(_retval);
749 NS_ENSURE_TRUE(deviceIndex <
mDevices.Count(), NS_ERROR_UNEXPECTED);
750 NS_IF_ADDREF(*_retval =
mDevices[deviceIndex]);
755 sbMockCDService::GetDeviceFromIdentifier(
const nsACString & aDeviceIdentifier,
760 nsCOMPtr<sbICDDevice> curDevice =
mDevices[
i];
762 nsCString deviceIdentifier;
763 nsresult rv = curDevice->GetIdentifier(deviceIdentifier);
764 NS_ENSURE_SUCCESS(rv, rv);
766 if (deviceIdentifier.Equals(aDeviceIdentifier)) {
767 curDevice.forget(_retval);
778 NS_ENSURE_ARG_POINTER(_retval);
780 return NS_NewArrayEnumerator(_retval,
mDevices);
786 NS_ENSURE_ARG_POINTER(listener);
794 NS_ENSURE_ARG_POINTER(listener);
803 sbMockCDService::InsertMedia(
sbICDDevice *aCDDevice, PRUint16 aMediaDisc)
805 NS_ENSURE_ARG_POINTER(aCDDevice);
809 PRBool isDiscInserted = PR_FALSE;
810 rv = aCDDevice->GetIsDiscInserted(&isDiscInserted);
811 if (NS_FAILED(rv) || isDiscInserted) {
816 nsCOMPtr<sbICDTOC> mediaTOC;
817 switch (aMediaDisc) {
820 NS_ENSURE_SUCCESS(rv, rv);
825 NS_ENSURE_SUCCESS(rv, rv);
830 NS_ENSURE_SUCCESS(rv, rv);
835 NS_ENSURE_SUCCESS(rv, rv);
839 nsCOMPtr<sbIMockCDDevice> mockDevice = do_QueryInterface(aCDDevice, &rv);
840 NS_ENSURE_SUCCESS(rv, rv);
842 rv = mockDevice->SetDiscTOC(mediaTOC);
843 NS_ENSURE_SUCCESS(rv, rv);
848 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
849 "Could not inform the listener of media insertion!");
856 sbMockCDService::EjectMedia(
sbICDDevice *aCDDevice)
858 NS_ENSURE_ARG_POINTER(aCDDevice);
862 nsCOMPtr<sbIMockCDDevice> mockDevice = do_QueryInterface(aCDDevice, &rv);
863 NS_ENSURE_SUCCESS(rv, rv);
865 PRBool isDiscInserted = PR_FALSE;
866 rv = aCDDevice->GetIsDiscInserted(&isDiscInserted);
867 if (NS_FAILED(rv) || !isDiscInserted) {
871 rv = aCDDevice->Eject();
872 NS_ENSURE_SUCCESS(rv, rv);
877 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
878 "Could not inform the listener of media eject!");
885 sbMockCDService::NotifyEject(
sbICDDevice *aCDDevice)
887 NS_ENSURE_ARG_POINTER(aCDDevice);
891 nsCOMPtr<sbIMockCDDevice> mockDevice = do_QueryInterface(aCDDevice, &rv);
892 NS_ENSURE_SUCCESS(rv, rv);
897 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
898 "Could not inform the listener of media eject!");
919 sbMockCDDeviceConstructor,
925 sbMockCDTOCConstructor,
931 sbMockCDServiceConstructor
virtual ~sbMockCDService()
#define SB_MOCK_CDDEVICE_CLASSNAME
sbMockCDTOCEntry(PRInt32 aFrameOffset, PRTime aLength, PRInt32 aTrackNumber, PRInt16 aTrackMode, nsAString const &aDrive)
nsresult sbCOMArrayTonsIArray(T &aCOMArray, nsIArray **aOutArray)
NS_IMPL_THREADSAFE_ISUPPORTS1(sbMockCDTOCEntry, sbICDTOCEntry)
const unsigned short MOCK_MEDIA_DISC_INCREDIBAD
const unsigned short MOCK_MEDIA_DISC_U2
#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
#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)
NS_DECL_ISUPPORTS NS_DECL_SBICDDEVICESERVICE NS_DECL_SBIMOCKCDDEVICECONTROLLER nsresult Init()
NS_IMPL_NSGETMODULE(SongbirdIdentityServiceComponent, sbIdentityServiceComponent)
const unsigned short TRACKMODE_AUDIO
#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
_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)