From ea824022ab2a47a36c861c66da9b8115657113ae Mon Sep 17 00:00:00 2001
From: =?utf8?q?Juho=20V=C3=A4h=C3=A4-Herttua?= <juhovh@iki.fi>
Date: Sun, 27 May 2012 20:59:04 +0300
Subject: [PATCH] Simplify the set_log_callback, it is better for thread safety

---
 src/bindings/python/Shairplay.py | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/src/bindings/python/Shairplay.py b/src/bindings/python/Shairplay.py
index 69aec6b..637094c 100644
--- a/src/bindings/python/Shairplay.py
+++ b/src/bindings/python/Shairplay.py
@@ -161,12 +161,6 @@ class RaopCallbacks:
 		pass
 
 class RaopService:
-	def log_callback_cb(self, level, message):
-		if self.log_callback != None:
-			self.log_callback(level, message)
-		else:
-			print message
-
 	def audio_init_cb(self, cls, bits, channels, samplerate):
 		session = self.callbacks.audio_init(bits, channels, samplerate)
 		self.sessions.append(session)
@@ -223,11 +217,6 @@ class RaopService:
 		if self.instance == None:
 			raise RuntimeError("Initializing library failed")
 
-		# We need to hold a reference to the log callback wrapper
-		self.log_callback_pointer = raop_log_callback_prototype(self.log_callback_cb)
-		self.libshairplay.raop_set_log_callback(self.instance, self.log_callback_pointer)
-		self.log_callback = None
-
 	def __del__(self):
 		if self.instance != None:
 			self.libshairplay.raop_destroy(self.instance)
@@ -243,7 +232,9 @@ class RaopService:
 		self.libshairplay.raop_set_log_level(self.instance, level)
 
 	def set_log_callback(self, log_callback):
-		self.log_callback = log_callback
+		# We need to hold a reference to the log callback instance
+		self.log_callback = raop_log_callback_prototype(log_callback)
+		self.libshairplay.raop_set_log_callback(self.instance, self.log_callback)
 
 	def start(self, port, hwaddrstr, password=None):
 		port = c_ushort(port)
-- 
2.43.0