Fix python bindings to hold a reference to sessions
authorJuho Vähä-Herttua <juhovh@iki.fi>
Mon, 19 Mar 2012 07:54:06 +0000 (09:54 +0200)
committerJuho Vähä-Herttua <juhovh@iki.fi>
Wed, 16 May 2012 21:33:32 +0000 (00:33 +0300)
src/bindings/python/Shairplay.py

index 35142f196a39d5bcc69ae125018b95fe06a3e6b7..f9dc919bf0881d89395bb48d3e64a006c61f81d9 100644 (file)
@@ -1,3 +1,4 @@
+# coding=utf-8
 '''
        Copyright (C) 2012  Juho Vähä-Herttua
 
@@ -122,7 +123,8 @@ class RaopCallbacks:
 class RaopService:
        def audio_init_cb(self, cls, bits, channels, samplerate):
                session = self.callbacks.audio_init(bits, channels, samplerate)
-               return py_object(session)
+               self.sessions.append(session)
+               return session
 
        def audio_set_volume_cb(self, cls, sessionptr, volume):
                session = cast(sessionptr, py_object).value
@@ -140,11 +142,14 @@ class RaopService:
        def audio_destroy_cb(self, cls, sessionptr):
                session = cast(sessionptr, py_object).value
                self.callbacks.audio_destroy(session)
+               if session in self.sessions:
+                       self.sessions.remove(session)
 
 
        def __init__(self, libshairplay, callbacks):
                self.libshairplay = libshairplay
                self.callbacks = callbacks
+               self.sessions = []
                self.instance = None
 
                # We need to hold a reference to native_callbacks