Raise openError on open failure
authorStefan Vogel <sv@exept.de>
Tue, 09 Mar 2004 12:24:17 +0100
changeset 1422 59ad87529b94
parent 1421 56012c7b8a0b
child 1423 f192a7708747
Raise openError on open failure
SoundStream.st
--- a/SoundStream.st	Tue Mar 09 00:56:49 2004 +0100
+++ b/SoundStream.st	Tue Mar 09 12:24:17 2004 +0100
@@ -1535,20 +1535,6 @@
 
 !SoundStream methodsFor:'redefined'!
 
-XXclose
-    OperatingSystem getOSType = 'irix' ifTrue:[
-	^ self closeFile
-    ].
-    OperatingSystem getOSType = 'win32' ifTrue:[
-	^ self closeFile
-    ].
-
-    super close
-
-    "Created: 17.11.1995 / 17:27:26 / cg"
-    "Modified: 17.11.1995 / 17:47:13 / cg"
-!
-
 closeFile
     "a stream has been collected - close the file"
 
@@ -2070,46 +2056,9 @@
     ^ super nextPutBytes:count from:anObject startingAt:start
 !
 
-openForReadWrite
-    |rslt|
-
-    mode := #readWrite.
-    didWrite := false.
-    (rslt :=  self openWithMode:ReadWriteMode) notNil ifTrue:[
-        Lobby register:self
-    ].
-    ^ rslt
-!
-
-openForReading
-    |rslt|
+openWithMode:aMode
+    |ok|
 
-    mode := #readonly.
-    didWrite := false.
-    (rslt :=  self openWithMode:ReadMode) notNil ifTrue:[
-	Lobby register:self
-    ].
-    ^ rslt
-!
-
-openForWriting
-    "open the file writeonly.
-     If the file does not exist its an error, return nil; 
-     otherwise return the receiver."
-
-    |rslt|
-
-    mode := #writeonly.
-    didWrite := true.
-    (rslt := self openWithMode:WriteMode) notNil ifTrue:[
-	Lobby register:self
-    ].
-    ^ rslt
-
-    "Created: / 15.12.1997 / 13:13:56 / cg"
-!
-
-openWithMode:aMode
 %{
 #ifdef IRIS_AUDIO
   {
@@ -2142,7 +2091,7 @@
         __INST(alPort) = t = __MKEXTERNALADDRESS(p); __STORE(self, t);
     } else {
         __INST(alPort) = nil;
-        RETURN (nil);
+        goto out;
     }
     __INST(binary) = true;
 
@@ -2178,9 +2127,10 @@
     __INST(sampleRate) = __MKSMALLINT(params[3]);
 
     ALfreeconfig(config);
-    RETURN (self);
+    ok = true;
+    goto out;
   }
-#endif /* SGI_AUDIO */
+#endif /* IRIS_AUDIO */
 
 #ifdef WIN32
 # ifdef USE_DIRECTSOUND
@@ -2197,7 +2147,7 @@
     /* Create the DS object */
     if ((result = DirectSoundCreate(NULL, &t_pDirectSound, NULL)) != DS_OK) {
         fprintf(stderr,"SoundStream: Cannot open default sound device!!\n");
-        RETURN (nil);
+        goto out;
     }
 
     /* Define the wave format structure */
@@ -2221,7 +2171,7 @@
                                                  &t_pDSPrimeBuffer, NULL)) != DS_OK) {
         fprintf(stderr,"SoundStream: Cannot get the primary DS buffer address!\n");
         IDirectSound_Release(t_pDirectSound);
-        RETURN (nil);
+        goto out;
     }
 
     /* Set the primary DS buffer sound format.  We have to do this because
@@ -2231,9 +2181,9 @@
         IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
         IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
         IDirectSound_Release(t_pDirectSound);
-        RETURN (nil);
+        goto out;
     }
-#  endif
+#  endif /* 0 */
 
     /* Setup the secondary DS buffer description */
     t_cbBufSize = RT_BUFFER_SIZE * sizeof(short) * NBUFS;
@@ -2251,7 +2201,7 @@
         IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
         IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
         IDirectSound_Release(t_pDirectSound);
-        RETURN (nil);
+        goto out;
     }
 
     /* Lock the DS buffer */
@@ -2262,7 +2212,7 @@
         IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
         IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
         IDirectSound_Release(t_pDirectSound);
-        RETURN (nil);
+        goto out;
     }
 
     /* Zero the DS buffer */
@@ -2275,7 +2225,7 @@
         IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
         IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
         IDirectSound_Release(t_pDirectSound);
-        RETURN (nil);
+        goto out;
     }
 
     __INST(bufferOffset) = __MKSMALLINT(0);  // reset last write position to start of buffer
@@ -2287,7 +2237,8 @@
         IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
         IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
         IDirectSound_Release(t_pDirectSound);
-        RETURN (nil);
+        ok = false;
+        goto out;
     }
 
     {
@@ -2296,9 +2247,10 @@
         __INST(pDSBuffer) = t = __MKEXTERNALADDRESS(t_pDSBuffer); __STORE(self, t);
         __INST(pDirectSound) = t = __MKEXTERNALADDRESS(t_pDirectSound); __STORE(self, t);
     }
-    RETURN (self);
+    ok = true;
+    goto out;
   }
-# else /* WAVEOUT */
+# else /* !USE_DIRECTSOUND */
   {
     PCMWAVEFORMAT waveFormat;
     int r;
@@ -2306,7 +2258,8 @@
     OBJ oWaveHandle;
 
     if ((oWaveHandle = __INST(waveHandle)) != nil) {
-        RETURN(self);
+        ok = false;
+        goto out;
     }
 
     waveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;
@@ -2324,7 +2277,8 @@
                     CALLBACK_FUNCTION);
     if (r != 0) {
         printf("waveOutOpen\n");
-        RETURN (nil);
+        ok = false;
+        goto out;
     }
 
     (void)waveOutReset(t_waveHandle);
@@ -2356,10 +2310,11 @@
         }
         audioWrite(null, DATALEN);
     }
-#endif
-    RETURN(self);
+#endif /* 0 */
+    ok = true;
+    goto out;
   }
-# endif
+# endif /* !USE_DIRECTSOUND */
 #endif /* WIN32 */
 
 #ifdef DEV_AUDIO
@@ -2390,7 +2345,8 @@
                     __BEGIN_INTERRUPTABLE__
                     close(__fd);
                     __END_INTERRUPTABLE__
-                    RETURN (nil);
+                    ok = false;
+                    goto out;
                 } 
                 setbuf(f, NULL);
                 __INST(buffered) = false;
@@ -2409,15 +2365,27 @@
                 }
 # endif
 #endif
-                RETURN (self);
+                ok = true;
+                goto out;
             }
         }
 
 #endif /* DEV_AUDIO */
-
+out:;
 %}.
-    "its a regular file open (i.e. /dev/audio) "
-    ^ super openWithMode:aMode
+    ok == false ifTrue:[
+        self openError. 
+        "not reached"
+        ^ nil.
+    ].
+        
+    ok isNil ifTrue:[
+        "its a regular file open (i.e. /dev/audio) "
+        ^ super openWithMode:aMode.
+    ].
+
+    Lobby register:self.
+    ^ self.
 ! !
 
 !SoundStream methodsFor:'sine wave generation'!
@@ -2692,7 +2660,7 @@
 !SoundStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.61 2003-07-12 15:07:49 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.62 2004-03-09 11:24:17 stefan Exp $'
 ! !
 
 SoundStream initialize!