summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <Sam@XPS-SUSE.site>2008-11-29 18:44:41 +0900
committerSam Spilsbury <Sam@XPS-SUSE.site>2008-11-29 18:44:41 +0900
commitad4a2000161d801454163789fa4628156ea30da0 (patch)
tree5e9585ba180a5a9df834a5100579dc1e8da300c3
parent310903eb134faf19574165f1421ec3cc69424030 (diff)
downloadwiimote-ad4a2000161d801454163789fa4628156ea30da0.tar.gz
wiimote-ad4a2000161d801454163789fa4628156ea30da0.tar.bz2
* Drop in some frameworks for dynamic memory management, stuff I should have done a LONG time ago
-rw-r--r--compiz-wiimote.h12
-rw-r--r--wiimote.c71
2 files changed, 82 insertions, 1 deletions
diff --git a/compiz-wiimote.h b/compiz-wiimote.h
index 73b02ae..897a554 100644
--- a/compiz-wiimote.h
+++ b/compiz-wiimote.h
@@ -319,6 +319,7 @@ typedef struct _CompWiimote
CompTimeoutHandle lightsTimeoutHandle;
pthread_t connectWiimote; /* Threading Handler */
+ struct _CompWiimote *next; // The future $$$$$$ =)
} CompWiimote;
@@ -329,9 +330,11 @@ typedef struct _WiimoteDisplay
int screenPrivateIndex;
int count;
- CompWiimote cWiimote[MAX_WIIMOTES];
+ CompWiimote cWiimote[MAX_WIIMOTES]; // The past
int nWiimote;
+ CompWiimote *wiimotes; // The future $$$$$$$$ =)
+
/* Hack */
int firstRoot;
@@ -435,6 +438,13 @@ wiimoteSendInfo (CompDisplay *d,
CompOption *option,
int nOption);
+/* wiimote.c */
+CompWiimote *
+wiimoteAddWiimote (CompDisplay *d);
+void
+wiimoteRemoveWiimote (CompDisplay *d,
+ CompWiimote *wiimote);
+
/* Shortcut Macros --------------------------------------------------- */
#define toggle_bit(bf,b) \
diff --git a/wiimote.c b/wiimote.c
index 68f0a8f..2a42806 100644
--- a/wiimote.c
+++ b/wiimote.c
@@ -65,6 +65,77 @@ wiimoteDisplayOptionChanged (CompDisplay *d,
}
}
+/* Memory Management ----------------------------------------------------- */
+
+CompWiimote *
+wiimoteAddWiimote (CompDisplay *d)
+{
+ WIIMOTE_DISPLAY (d);
+ CompWiimote *wiimote;
+
+ if (!ad->wiimotes)
+ {
+ ad->wiimotes = calloc (1, sizeof (CompWiimote));
+ if (!ad->wiimotes)
+ return NULL;
+ ad->wiimotes->next = NULL;
+ wiimote = ad->wiimotes;
+ }
+ else
+ {
+ for (wiimote = ad->wiimotes; wiimote->next; wiimote = wiimote->next) ;
+
+ wiimote->next = calloc (1 , sizeof (CompWiimote));
+ if (!wiimote->next)
+ return NULL;
+ wiimote->next->next = NULL;
+ wiimote = wiimote->next;
+ }
+
+ wiimote->connected = FALSE;
+ wiimote->initiated = FALSE;
+ wiimote->initSet = FALSE;
+
+ return wiimote;
+}
+
+void
+wiimoteRemoveWiimote (CompDisplay *d,
+ CompWiimote *wiimote)
+{
+ WIIMOTE_DISPLAY (d);
+ CompWiimote *run;
+
+ if (wiimote == ad->wiimotes)
+ {
+ if (ad->wiimotes->next)
+ ad->wiimotes = ad->wiimotes->next;
+ else
+ ad->wiimotes = NULL;
+
+ /* Let CWiiD handle some of the other memory management */
+
+ free (wiimote);
+ }
+ else
+ {
+ for (run = ad->wiimotes; run; run = run->next)
+ {
+ if (run == wiimote)
+ {
+ if (run->next)
+ run = run->next;
+ else
+ run = NULL;
+
+ free (wiimote);
+ break;
+ }
+ }
+ }
+}
+
+
/* Core Initialization --------------------------------------------------- */
/* Use initCore() to find the first display (c->displays) */