From 15c94967170f211ae2939d616bdd16a7f502492a Mon Sep 17 00:00:00 2001
From: Jannis Pohlmann <jannis@xfce.org>
Date: Fri, 7 Sep 2012 21:26:29 +0100
Subject: [PATCH 3/6] wiimote: port to AbstractUI, use IdleSource for
 receiving messages

---
 libs/surfaces/wiimote/interface.cc |  42 +---
 libs/surfaces/wiimote/wiimote.cc   | 479 +++++++++++++++++++++----------------
 libs/surfaces/wiimote/wiimote.h    |  84 +++----
 3 files changed, 310 insertions(+), 295 deletions(-)

diff --git a/libs/surfaces/wiimote/interface.cc b/libs/surfaces/wiimote/interface.cc
index 5f622d5..904855f 100644
--- a/libs/surfaces/wiimote/interface.cc
+++ b/libs/surfaces/wiimote/interface.cc
@@ -1,47 +1,25 @@
-#include <pbd/failed_constructor.h>
+#include "pbd/failed_constructor.h"
+#include "pbd/error.h"
 
+#include "ardour/session.h"
 #include "control_protocol/control_protocol.h"
-#include "wiimote.h"
 
-#include "ardour/session.h"
+#include "wiimote.h"
 
 using namespace ARDOUR;
-
-static WiimoteControlProtocol *foo;
+using namespace PBD;
 
 ControlProtocol*
 new_wiimote_protocol (ControlProtocolDescriptor* descriptor, Session* s)
 {
-	WiimoteControlProtocol* wmcp;
-		
-	try {
-		wmcp =  new WiimoteControlProtocol (*s);
-	} catch (failed_constructor& err) {
-		return 0;
-	}
-	
-	if (wmcp-> set_active (true)) {
-		delete wmcp;
-		return 0;
-	}
-
-	foo = wmcp;
-
+	WiimoteControlProtocol* wmcp = new WiimoteControlProtocol (*s);
+	wmcp->set_active (true);
 	return wmcp;
 }
 
 void
-wiimote_control_protocol_cwiid_callback(cwiid_wiimote_t *wiimote, int mesg_count, union cwiid_mesg mesg[], struct timespec *t)
-{
-	assert(foo != 0);
-
-	foo->wiimote_callback(wiimote,mesg_count,mesg,t);
-}
-
-void
 delete_wiimote_protocol (ControlProtocolDescriptor* descriptor, ControlProtocol* cp)
 {
-	foo = 0;
 	delete cp;
 }
 
@@ -62,12 +40,14 @@ static ControlProtocolDescriptor wiimote_descriptor = {
 	initialize : new_wiimote_protocol,
 	destroy : delete_wiimote_protocol
 };
-	
+
 
 extern "C" {
-ControlProtocolDescriptor* 
+
+ControlProtocolDescriptor*
 protocol_descriptor () {
 	return &wiimote_descriptor;
 }
+
 }
 
diff --git a/libs/surfaces/wiimote/wiimote.cc b/libs/surfaces/wiimote/wiimote.cc
index 26f7e18..445ac50 100644
--- a/libs/surfaces/wiimote/wiimote.cc
+++ b/libs/surfaces/wiimote/wiimote.cc
@@ -1,291 +1,346 @@
-#include "wiimote.h"
-
 #include <iostream>
-#include <sigc++/bind.h>
 
-#include "pbd/xml++.h"
+#include "pbd/compose.h"
+#include "pbd/error.h"
+#include "ardour/debug.h"
 #include "ardour/session.h"
-
 #include "i18n.h"
 
+#include "wiimote.h"
 
 using namespace ARDOUR;
 using namespace PBD;
+using namespace std;
 
-void wiimote_control_protocol_cwiid_callback(cwiid_wiimote_t *wiimote, int mesg_count, union cwiid_mesg mesg[], struct timespec *t);
-
-uint16_t WiimoteControlProtocol::button_state = 0;
+#include "pbd/abstract_ui.cc" // instantiate template
 
-WiimoteControlProtocol::WiimoteControlProtocol ( Session & session) 
-	: ControlProtocol ( session, "Wiimote"),
-	  main_thread_quit (false),
-	  restart_discovery (false),
-	  callback_thread_registered_for_ardour (false),
-	  wiimote_handle (0)
+WiimoteControlProtocol::WiimoteControlProtocol (Session& session)
+	: ControlProtocol (session, X_("Wiimote"))
+	, AbstractUI<WiimoteControlUIRequest> ("wiimote")
+	, wiimote (0)
+	, idle_source (0)
+	, button_state (0)
 {
-	main_thread = Glib::Thread::create( sigc::mem_fun(*this, &WiimoteControlProtocol::wiimote_main), true);
 }
 
-WiimoteControlProtocol::~WiimoteControlProtocol()
+WiimoteControlProtocol::~WiimoteControlProtocol ()
 {
-	main_thread_quit = true;
-	slot_cond.signal();
-	main_thread->join();
-
-	if (wiimote_handle) {
-		cwiid_close(wiimote_handle);
-	}
-
-	std::cerr << "Wiimote: closed" << std::endl;
+	// FIXME this causes Ardour to hang on exit
+	stop ();
 }
 
 bool 
-WiimoteControlProtocol::probe()
+WiimoteControlProtocol::probe ()
 {
 	return true;
 }
 
-void
-WiimoteControlProtocol::wiimote_callback(cwiid_wiimote_t *wiimote, int mesg_count, union cwiid_mesg mesg[], struct timespec *t)
+int
+WiimoteControlProtocol::set_active (bool yn)
 {
-	int i;
-	uint16_t b;
+	int result;
 
-	if (!callback_thread_registered_for_ardour) {
-		register_thread("Wiimote Control Protocol");
-		callback_thread_registered_for_ardour = true;
-	}
+	DEBUG_TRACE (DEBUG::WiimoteControl, string_compose ("WiimoteControlProtocol::set_active init with yn: '%1'\n", yn));
 
-        for (i=0; i < mesg_count; i++)
-	{
-		if (mesg[i].type == CWIID_MESG_ERROR) {	
-			std::cerr << "Wiimote: disconnect" << std::endl;
-			restart_discovery = true;
-			slot_cond.signal();
-			return;
-		}
+	/* do nothing if the active state is not changing */
+	if (yn == _active) {
+		return 0;
+	}
 
-		if (mesg[i].type != CWIID_MESG_BTN) continue;
+	if (yn) {
+		/* activate Wiimote control surface */
+		result = start ();
+	} else {
+		/* deactivate Wiimote control surface */
+		result = stop ();
+	}
 
-		// what buttons are pressed down which weren't pressed down last time
-		b = (mesg[i].btn_mesg.buttons ^ button_state) & mesg[i].btn_mesg.buttons;
+	/* remember new active state */
+	_active = yn;
 
-		button_state = mesg[i].btn_mesg.buttons;
-	
-		// if B is pressed down
-		if (button_state & CWIID_BTN_B) {
-			if (b & CWIID_BTN_A) { // B is down and A is pressed
-				access_action("Transport/ToggleRollForgetCapture");
-			}
+	DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::set_active done\n");
 
-			if (b & CWIID_BTN_LEFT) {
-				access_action("Editor/playhead-to-previous-region-boundary");
-			}
-			if (b & CWIID_BTN_RIGHT) {
-				access_action("Editor/playhead-to-next-region-boundary");
-			}
-			if (b & CWIID_BTN_UP) {
-				next_marker();
-			}
-			if (b & CWIID_BTN_DOWN) {
-				prev_marker();
-			}
-
-			if (b & CWIID_BTN_HOME) {
-				access_action("Editor/add-location-from-playhead");
-			}
+	return result;
+}
 
-			if (b & CWIID_BTN_MINUS) {	
-				access_action("Transport/GotoStart");
-			}
-			
-			if (b & CWIID_BTN_PLUS) {
-				access_action("Transport/GotoEnd");
-			}
+XMLNode&
+WiimoteControlProtocol::get_state ()
+{
+	XMLNode *node = new XMLNode ("Protocol");
+	node->add_property (X_("name"), ARDOUR::ControlProtocol::_name);
+	node->add_property (X_("feedback"), "0");
+	return *node;
+}
 
-			continue;
-		}
+int
+WiimoteControlProtocol::set_state (const XMLNode& node, int version)
+{
+	return 0;
+}
 
+void
+WiimoteControlProtocol::do_request (WiimoteControlUIRequest* req)
+{
+	DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::do_request init\n");
 
-		if (b & CWIID_BTN_A) {
-			access_action("Transport/ToggleRoll");
-		}
+	if (req->type == CallSlot) {
+		call_slot (MISSING_INVALIDATOR, req->the_slot);
+	} else if (req->type == Quit) {
+		stop ();
+	}
 
-		if (b & CWIID_BTN_1) { // 1
-			access_action("Editor/track-record-enable-toggle");
-		}
-		if (b & CWIID_BTN_2) { // 2
-			rec_enable_toggle();
-		}
+	DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::do_request done\n");
+}
 
-		// d-pad
-		if (b & CWIID_BTN_LEFT) { // left
-			access_action("Editor/nudge-playhead-backward");
-		}
-		if (b & CWIID_BTN_RIGHT) { // right
-			access_action("Editor/nudge-playhead-forward");
-		}
-		if (b & CWIID_BTN_DOWN) { // down
-			access_action("Editor/select-next-route");
-		}
-		if (b & CWIID_BTN_UP) { // up
-			access_action("Editor/select-prev-route");
-		}
+int
+WiimoteControlProtocol::start ()
+{
+	DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::start init\n");
 
+	// start the Wiimote control UI; it will run in its own thread context
+	BaseUI::run ();
 
-		if (b & CWIID_BTN_PLUS) { // +
-			access_action("Editor/temporal-zoom-in");
-		}
-		if (b & CWIID_BTN_MINUS) { // -
-			access_action("Editor/temporal-zoom-out");
-		}
-		if (b & CWIID_BTN_HOME) { // "home"
-			// no op, yet. any suggestions?
-			access_action("Editor/playhead-to-edit");
-		}
+	DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::start done\n");
 
-	}
+	return 0;
 }
 
-void
-WiimoteControlProtocol::update_led_state()
+int
+WiimoteControlProtocol::stop ()
 {
-	ENSURE_WIIMOTE_THREAD(sigc::mem_fun(*this, &WiimoteControlProtocol::update_led_state));
+	DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::stop init\n");
 
-	uint8_t state = 0;
+	// release the idle source used for checking for incoming messages
+	g_source_destroy (idle_source);
+	g_source_unref (idle_source);
+	idle_source = 0;
 
-	if (session->transport_rolling()) {
-		state |= CWIID_LED1_ON;
-	}
+	// stop the Wiimote control UI
+	BaseUI::quit ();
 
-	if (session->actively_recording()) {
-		state |= CWIID_LED4_ON;
-	}
+	DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::stop done\n");
 
-	cwiid_set_led(wiimote_handle, state);
+	return 0;
 }
 
 void
-WiimoteControlProtocol::_wiimote_main ()
+WiimoteControlProtocol::thread_init ()
 {
-	bdaddr_t bdaddr;
-	unsigned char rpt_mode = 0;
+	DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::thread_init init\n");
 
-	register_thread ("Wiimote");
+	pthread_set_name (X_("wiimote"));
 
-wiimote_discovery:
+	// allow to make requests to the GUI and RT thread(s)
+	PBD::notify_gui_about_thread_creation (X_("gui"), pthread_self (), X_("wiimote"), 2048);
+	SessionEvent::create_per_thread_pool (X_("wiimote"), 128);
 
-	std::cerr << "Wiimote: discovering, press 1+2" << std::endl;
+	// set up an idle source to check for incoming messages from the Wiimote
+	Glib::RefPtr<Glib::IdleSource> source = Glib::IdleSource::create ();
+	source->connect (sigc::mem_fun (*this, &WiimoteControlProtocol::idle));
+	source->attach (_main_loop->get_context ());
 
- 	while (!wiimote_handle && !main_thread_quit) {
-		bdaddr = (bdaddr_t) {{0, 0, 0, 0, 0, 0}};
-		callback_thread_registered_for_ardour = false;
-		wiimote_handle = cwiid_open(&bdaddr, 0);
+	// grab a reference on the underlying idle source to keep it around
+	idle_source = source->gobj ();
+	g_source_ref (idle_source);
 
-		if (!wiimote_handle && !main_thread_quit) {
-			sleep(1); 
-			// We don't know whether the issue was a timeout or a configuration 
-			// issue
-		}
+	DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::thread_init done\n");
+}
+
+bool
+WiimoteControlProtocol::idle ()
+{
+	// if the Wiimote is not connected, ask the user to connect it now;
+	// if that fails, try again by calling the idle source again
+	if (!connect_wiimote ()) {
+		sleep (1);
+		return TRUE;
 	}
 
-	if (main_thread_quit) {
-		// The corner case where the wiimote is bound at the same time as
-		// the control protocol is destroyed
-		if (wiimote_handle) {
-			cwiid_close(wiimote_handle);
+	int i;
+	int mesg_count;
+	union cwiid_mesg *mesg;
+	struct timespec timestamp;
+
+	cwiid_get_mesg (wiimote, &mesg_count, &mesg, &timestamp);
+
+	for (i = 0; i < mesg_count; i++) {
+		// reset the Wiimote handle when receiving errors, so that the user
+		// is asked to reconnect it when the idle source is called next time
+		if (mesg[i].type == CWIID_MESG_ERROR) {
+			cerr << "Wiimote: disconnected" << endl;
+			if (wiimote) {
+				cwiid_close (wiimote);
+				wiimote = 0;
+			}
+			return TRUE;
 		}
-		wiimote_handle = 0;
 
-		std::cerr << "Wiimote Control Protocol stopped before connected to a wiimote" << std::endl;
-		return;
-	}
+		// skip non-button events
+		if (mesg[i].type != CWIID_MESG_BTN) {
+			continue;
+		}
 
-	std::cerr << "Wiimote: connected" << std::endl;
-	WiimoteControlProtocol::button_state = 0;
+		// drop buttons from the event that were already pressed before
+		uint16_t b = mesg[i].btn_mesg.buttons & ~button_state;
 
-	if (cwiid_enable(wiimote_handle, CWIID_FLAG_REPEAT_BTN)) {
-		std::cerr << "cwiid_enable(), error" << std::endl;
-		cwiid_close(wiimote_handle);
-		wiimote_handle = 0;
-		return;
-	}
-	if (cwiid_set_mesg_callback(wiimote_handle, wiimote_control_protocol_cwiid_callback)) {
-		std::cerr << "cwiid_set_mesg_callback(), couldn't connect callback" << std::endl;
-		cwiid_close(wiimote_handle);
-		wiimote_handle = 0;
-		return;
-	} 
-	if (cwiid_command(wiimote_handle, CWIID_CMD_RPT_MODE, CWIID_RPT_BTN)) {
-		std::cerr << "cwiid_command(), RPT_MODE error" << std::endl;
-		cwiid_close(wiimote_handle);
-		wiimote_handle = 0;
-		return;
-	}
+		// remember new button state
+		button_state = mesg[i].btn_mesg.buttons;
 
-	rpt_mode |= CWIID_RPT_BTN;
-	cwiid_enable(wiimote_handle, CWIID_FLAG_MESG_IFC);
-	cwiid_set_rpt_mode(wiimote_handle, rpt_mode);
+		if (button_state & CWIID_BTN_B) {
+			// B + A = abort recording and jump back
+			if (b & CWIID_BTN_A) {
+				access_action ("Transport/ToggleRollForgetCapture");
+			}
 
-	transport_state_conn = session->TransportStateChange.connect(sigc::mem_fun(*this, &WiimoteControlProtocol::update_led_state));
-	record_state_conn = session->RecordStateChanged.connect(sigc::mem_fun(*this, &WiimoteControlProtocol::update_led_state));
+			// B + left = move playhead to previous region boundary
+			if (b & CWIID_BTN_LEFT) {
+				access_action ("Editor/playhead-to-previous-region-boundary");
+			}
 
-	std::cerr << "Wiimote: initialization done, waiting for callbacks / quit" << std::endl;
+			// B + right = move playhead to next region boundary
+			if (b & CWIID_BTN_RIGHT) {
+				access_action ("Editor/playhead-to-next-region-boundary");
+			}
 
-	while (!main_thread_quit) {
-		slot_mutex.lock();
-		while (slot_list.empty() && !main_thread_quit && !restart_discovery)
-			slot_cond.wait(slot_mutex);
+			// B + up = move playhead to next marker
+			if (b & CWIID_BTN_UP) {
+				next_marker ();
+			}
 
-		if (main_thread_quit) {
-			slot_mutex.unlock();
-			break;
-		}
+			// B + down = move playhead to prev marker
+			if (b & CWIID_BTN_DOWN) {
+				prev_marker ();
+			}
 
-		if (restart_discovery) {
-			std::cerr << "Wiimote: closing wiimote and restarting discovery" << std::endl;
-			if (wiimote_handle) {
-				cwiid_close(wiimote_handle);
-				wiimote_handle = 0;
+			// B + Home = add marker at playhead
+			if (b & CWIID_BTN_HOME) {
+				access_action ("Editor/add-location-from-playhead");
 			}
-			slot_mutex.unlock();
-			restart_discovery = false;
-			goto wiimote_discovery;
-		}
 
-		sigc::slot<void> call_me = *slot_list.begin();
-		slot_list.pop_front();
-		slot_mutex.unlock();
+			// B + minus = move playhead to the start
+			if (b & CWIID_BTN_MINUS) {
+				access_action ("Transport/GotoStart");
+			}
 
-		call_me();
-	}
+			// B + plus = move playhead to the end
+			if (b & CWIID_BTN_PLUS) {
+				access_action ("Transport/GotoEnd");
+			}
+		} else {
+			// A = toggle playback
+			if (b & CWIID_BTN_A) {
+				access_action ("Transport/ToggleRoll");
+			}
 
+			// 1 = toggle recording on the current track
+			if (b & CWIID_BTN_1) {
+				access_action ("Editor/track-record-enable-toggle");
+			}
 
-	std::cerr << "Wiimote: main thread stopped" << std::endl;
-	return 0;
-}
+			// 2 = enable recording in general
+			if (b & CWIID_BTN_2) {
+				rec_enable_toggle ();
+			}
 
+			// left = move playhead back a bit
+			if (b & CWIID_BTN_LEFT) {
+				access_action ("Editor/nudge-playhead-backward");
+			}
 
-int
-WiimoteControlProtocol::set_active (bool yn)
-{
-	// Let's not care about this just yet
-	return 0;
+			// right = move playhead forward a bit
+			if (b & CWIID_BTN_RIGHT) {
+				access_action ("Editor/nudge-playhead-forward");
+			}
 
-}
+			// up = select previous track
+			if (b & CWIID_BTN_UP) {
+				access_action ("Editor/select-prev-route");
+			}
 
-XMLNode&
-WiimoteControlProtocol::get_state()
-{
-	XMLNode *node = new XMLNode ("Protocol");
-        node->add_property (X_("name"), _name);
-        node->add_property (X_("feedback"), "0");
+			// down = select next track
+			if (b & CWIID_BTN_DOWN) {
+				access_action ("Editor/select-next-route");
+			}
 
-	return *node;
+			// + = zoom in
+			if (b & CWIID_BTN_PLUS) {
+				access_action ("Editor/temporal-zoom-in");
+			}
+
+			// - = zoom out
+			if (b & CWIID_BTN_MINUS) {
+				access_action ("Editor/temporal-zoom-out");
+			}
+
+			// home = no-op
+			if (b & CWIID_BTN_HOME) {
+				access_action ("Editor/playhead-to-edit");
+			}
+		}
+	}
+
+	return TRUE;
 }
 
-int
-WiimoteControlProtocol::set_state(const XMLNode& node)
+bool
+WiimoteControlProtocol::connect_wiimote ()
 {
-	return 0;
+	// do nothing if we already have a Wiimote
+	if (wiimote) {
+		return true;
+	}
+
+	bool success = true;
+
+	// if we don't have a Wiimote yet, try to discover it; if that
+	// fails, wait for a short period of time and try again
+	if (!wiimote) {
+		cerr << "Wiimote: Not discovered yet, press 1+2 to connect" << endl;
+
+		bdaddr_t bdaddr = {{ 0, 0, 0, 0, 0, 0 }};
+		wiimote = cwiid_open (&bdaddr, 0);
+		if (!wiimote) {
+			success = false;
+		} else {
+			// a Wiimote was discovered
+			cerr << "Wiimote: Connected successfully" << endl;
+
+			// attach the WiimoteControlProtocol object to the Wiimote handle
+			if (cwiid_set_data (wiimote, this)) {
+				cerr << "Wiimote: Failed to attach control protocol" << endl;
+				success = false;
+			}
+
+			// clear the last button state to start processing events cleanly
+			button_state = 0;
+		}
+	}
+
+	// enable message based communication with the Wiimote
+	if (success && cwiid_enable (wiimote, CWIID_FLAG_MESG_IFC)) {
+		cerr << "Wiimote: Failed to enable message based communication" << endl;
+		success = false;
+	}
+
+	// enable button events to be received from the Wiimote
+	if (success && cwiid_command (wiimote, CWIID_CMD_RPT_MODE, CWIID_RPT_BTN)) {
+		cerr << "Wiimote: Failed to enable button events" << endl;
+		success = false;
+	}
+
+	// receive an event for every single button pressed, not just when
+	// a different button was pressed than before
+	if (success && cwiid_enable (wiimote, CWIID_FLAG_REPEAT_BTN)) {
+		cerr << "Wiimote: Failed to enable repeated button events" << endl;
+		success = false;
+	}
+
+	// reset Wiimote handle if the configuration failed
+	if (!success && wiimote) {
+		cwiid_close (wiimote);
+		wiimote = 0;
+	}
+
+	return success;
 }
+
diff --git a/libs/surfaces/wiimote/wiimote.h b/libs/surfaces/wiimote/wiimote.h
index 4ab1974..e0dec14 100644
--- a/libs/surfaces/wiimote/wiimote.h
+++ b/libs/surfaces/wiimote/wiimote.h
@@ -1,69 +1,49 @@
 #ifndef ardour_wiimote_control_protocol_h
 #define ardour_wiimote_control_protocol_h
 
+#include <cwiid.h>
+
+#include "pbd/abstract_ui.h"
 #include "ardour/types.h"
 #include "control_protocol/control_protocol.h"
 
-#include <glibmm/threads.h>
+struct WiimoteControlUIRequest : public BaseUI::BaseRequestObject {
+public:
+	WiimoteControlUIRequest () {}
+	~WiimoteControlUIRequest () {}
+};
+
+class WiimoteControlProtocol
+	: public ARDOUR::ControlProtocol
+	, public AbstractUI<WiimoteControlUIRequest>
+{
+public:
+	WiimoteControlProtocol (ARDOUR::Session &);
+	virtual ~WiimoteControlProtocol ();
 
-#include "pbd/abstract_ui.h"
+	static bool probe ();
+	int set_active (bool yn);
 
-#include <cwiid.h>
+	XMLNode& get_state ();
+	int set_state (const XMLNode&, int version);
 
+	void wiimote_callback (cwiid_wiimote_t* wiimote, int mesg_count, union cwiid_mesg msg[], struct timespec* t);
 
-namespace ARDOUR {
-        class Session;
-}
+protected:
+	void do_request (WiimoteControlUIRequest*);
+	int start ();
+	int stop ();
 
-#define ENSURE_WIIMOTE_THREAD(slot) \
-	if (Glib::Threads::Thread::self() != main_thread) {	\
-		slot_mutex.lock();\
-		slot_list.push_back(slot);\
-		slot_cond.signal();\
-		slot_mutex.unlock();\
-		return;\
-	} 
+	void thread_init ();
 
+	bool idle ();
+	bool connect_wiimote ();
 
-class WiimoteControlProtocol : public ARDOUR::ControlProtocol {
-  public:
-    WiimoteControlProtocol (ARDOUR::Session &);
-    virtual ~WiimoteControlProtocol ();
-    
-    static bool probe();
-    
-    int set_active (bool yn);
-    XMLNode& get_state();
-    int set_state(const XMLNode&);
-    
-    void wiimote_callback(cwiid_wiimote_t *, int, union cwiid_mesg [], 
-			  struct timespec *);
-    
-  private:
-    
-    void wiimote_main();
-    volatile bool main_thread_quit;
-    volatile bool restart_discovery;
-    
-    Glib::Threads::Thread *main_thread;
-    
-    void update_led_state();
-    
-    bool callback_thread_registered_for_ardour;
-    
-    static uint16_t button_state;
-    
-    cwiid_wiimote_t *wiimote_handle;
-    
-    Glib::Threads::Cond slot_cond;
-    Glib::Threads::Mutex slot_mutex;
-    
-    std::list< sigc::slot<void> > slot_list;
-    
-    sigc::connection transport_state_conn;
-    sigc::connection record_state_conn;
+protected:
+	cwiid_wiimote_t* wiimote;
+	GSource *idle_source;
+	uint16_t button_state;
 };
 
-
 #endif  /* ardour_wiimote_control_protocol_h */
 
-- 
1.7.11.4

