Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsSystemSoundRequest Class Reference
Inheritance diagram for nsSystemSoundRequest:
Inheritance graph
Collaboration diagram for nsSystemSoundRequest:
Collaboration graph

List of all members.

Public Member Functions

 nsSystemSoundRequest ()
virtual ~nsSystemSoundRequest ()
Init (nsISound *aSound, ConstStr255Param aSoundName)
virtual nsresult PlaySound ()
NS_DECL_ISUPPORTS NS_IMETHOD Notify (nsITimer *timer)=0
void notify (in nsITimer timer)

Static Public Member Functions

static nsSoundRequestGetFromISupports (nsISupports *inSupports)

Protected Member Functions

void DonePlaying ()
nsresult Cleanup ()

Static Protected Member Functions

static pascal void SoundCallback (SndChannelPtr chan, SndCommand *theCmd)

Protected Attributes

Handle mSoundHandle
SndChannelPtr mSndChannel
SndCallBackUPP mSoundCallback
Boolean mSoundDone
nsCOMPtr< nsISoundmSound
nsCOMPtr< nsITimermTimer

Detailed Description

Definition at line 104 of file nsSound.cpp.

Constructor & Destructor Documentation

Definition at line 516 of file nsSound.cpp.

: mSoundHandle(nsnull)
, mSndChannel(nsnull)
, mSoundCallback(nsnull)
, mSoundDone(false)
  printf("%%%%%%%% Made nsSystemSoundRequest\n");

Definition at line 527 of file nsSound.cpp.

  if (mSoundHandle) {
    // unlock the sound resource handle and make it purgeable.

  if (mSndChannel)
    ::SndDisposeChannel(mSndChannel, true);

  if (mSoundCallback)
  printf("%%%%%%%% Deleted nsSystemSoundRequest\n");

Member Function Documentation

nsresult nsSoundRequest::Cleanup ( void  ) [protected, inherited]

Definition at line 485 of file nsSound.cpp.

  nsresult rv = NS_OK;
  printf("Sound playback done\n");
  // kill the timer
  if (mTimer) {
    mTimer = nsnull;
  // remove from parent array. Use a deathGrip to ensure that it's OK
  // to clear mSound.
  nsCOMPtr<nsISupports>   deathGrip(this);
  if (mSound.get())
    nsSound*    macSound = NS_REINTERPRET_CAST(nsSound*, mSound.get());
    rv = macSound->RemoveRequest(NS_STATIC_CAST(nsITimerCallback*, this));
    mSound = nsnull;
  return rv;

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 630 of file nsSound.cpp.

  mSoundDone = true;

Here is the caller graph for this function:

nsSoundRequest * nsSoundRequest::GetFromISupports ( nsISupports *  inSupports) [static, inherited]

Definition at line 472 of file nsSound.cpp.

  if (!inSupports) return nsnull;
  // test to see if this is really a nsSoundRequest by trying a QI
  nsCOMPtr<nsITimerCallback>  timerCallback = do_QueryInterface(inSupports);
  if (!timerCallback) return nsnull;
  return NS_REINTERPRET_CAST(nsSoundRequest*, inSupports);

Here is the call graph for this function:

nsresult nsSystemSoundRequest::Init ( nsISound aSound,
ConstStr255Param  aSoundName 

Definition at line 549 of file nsSound.cpp.

  mSound = aSound;

  mSoundCallback = NewSndCallBackUPP(nsSystemSoundRequest::SoundCallback);
  if (!mSoundCallback) return NS_ERROR_OUT_OF_MEMORY;
  mSoundHandle = ::GetNamedResource('snd ', aSoundName);
  if (!mSoundHandle) return NS_ERROR_FAILURE;
  // make sure the resource is loaded
  if (!mSoundHandle || !*mSoundHandle) return NS_ERROR_FAILURE;
  // and lock it high
  OSErr err = ::SndNewChannel(&mSndChannel, 0, 0, mSoundCallback);
  if (err != noErr) return NS_ERROR_FAILURE;

  return NS_OK;

Here is the call graph for this function:

void nsITimerCallback::notify ( in nsITimer  timer) [inherited]
aTimerthe timer which has expired
NS_DECL_ISUPPORTS NS_IMETHOD nsSoundRequest::Notify ( nsITimer timer) [pure virtual, inherited]

Implements nsSoundRequest.

Definition at line 573 of file nsSound.cpp.

  NS_ASSERTION(mSndChannel && mSoundHandle, "Should have sound channel here");
  if (!mSndChannel || !mSoundHandle) {
  nsresult rv;
  // set up a timer. This is used to sniff for mSoundDone (which is set by the channel callback).
  mTimer = do_CreateInstance(";1", &rv);    // release previous timer, if any
  if (NS_FAILED(rv)) {
    return rv;

  OSErr err = ::SndPlay(mSndChannel, (SndListHandle)mSoundHandle, true /* async */);
  if (err != noErr) {
     return NS_ERROR_FAILURE;

  // now queue up a sound completion command so we get a callback when
  // the sound is done.
  SndCommand    theCmd = { callBackCmd, 0, 0 };
  theCmd.param2 = (long)this;
  err = ::SndDoCommand(mSndChannel, &theCmd, false);   // wait for the channel
  if (err != noErr) {
    return NS_ERROR_FAILURE;
  const PRInt32   kSoundTimerInterval = 250;      // 250 milliseconds
  rv = mTimer->InitWithCallback(NS_STATIC_CAST(nsITimerCallback*, this), kSoundTimerInterval,
  if (NS_FAILED(rv)) {
    return rv;

  return NS_OK;

Here is the call graph for this function:

pascal void nsSystemSoundRequest::SoundCallback ( SndChannelPtr  chan,
SndCommand *  theCmd 
) [static, protected]

Definition at line 637 of file nsSound.cpp.

  nsSystemSoundRequest*   soundRequest = NS_REINTERPRET_CAST(nsSystemSoundRequest*, theCmd->param2);
  if (soundRequest)

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

SndChannelPtr nsSystemSoundRequest::mSndChannel [protected]

Definition at line 128 of file nsSound.cpp.

nsCOMPtr<nsISound> nsSoundRequest::mSound [protected, inherited]

Definition at line 98 of file nsSound.cpp.

SndCallBackUPP nsSystemSoundRequest::mSoundCallback [protected]

Definition at line 129 of file nsSound.cpp.

Definition at line 131 of file nsSound.cpp.

Definition at line 127 of file nsSound.cpp.

nsCOMPtr<nsITimer> nsSoundRequest::mTimer [protected, inherited]

Definition at line 99 of file nsSound.cpp.

The documentation for this class was generated from the following file: