summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimo Dritschler <timo.dritschler@kit.edu>2015-03-02 20:16:32 +0100
committerTimo Dritschler <timo.dritschler@kit.edu>2015-03-09 17:05:14 +0100
commit138cf0430005193de7777ebf72328f819876e775 (patch)
treeac0ce378157eb0bd3a227a23411bccf6ec1c4b5e /src
parent004c2e0cb4da35e2d26ffa30310921515bc2ee6e (diff)
downloadkiro-138cf0430005193de7777ebf72328f819876e775.tar.gz
kiro-138cf0430005193de7777ebf72328f819876e775.tar.bz2
kiro-138cf0430005193de7777ebf72328f819876e775.tar.xz
kiro-138cf0430005193de7777ebf72328f819876e775.zip
Added kiro_sb_get_data_blocking interface
Diffstat (limited to 'src')
-rw-r--r--src/kiro-sb.c49
-rw-r--r--src/kiro-sb.h27
2 files changed, 62 insertions, 14 deletions
diff --git a/src/kiro-sb.c b/src/kiro-sb.c
index c0487e0..0c044fe 100644
--- a/src/kiro-sb.c
+++ b/src/kiro-sb.c
@@ -188,7 +188,7 @@ idle_func (KiroSbPrivate *priv)
kiro_client_sync_partial (priv->client, 0, sizeof(struct KiroTrbInfo), 0);
kiro_trb_refresh (priv->trb);
if ((old_offset != header->offset) && 0 < header->offset) {
- gulong offset = (gulong) (kiro_trb_get_element (priv->trb, 1) - kiro_trb_get_raw_buffer (priv->trb));
+ gulong offset = (gulong) (kiro_trb_get_element (priv->trb, -1) - kiro_trb_get_raw_buffer (priv->trb));
kiro_client_sync_partial (priv->client, offset, kiro_trb_get_element_size (priv->trb), offset);
g_hook_list_invoke_check (&(priv->callbacks), FALSE);
}
@@ -227,7 +227,7 @@ kiro_sb_serve (KiroSb *self, gulong size)
g_return_val_if_fail ((priv->trb = kiro_trb_new ()), FALSE);
- if (0 > kiro_trb_reshape (priv->trb, size, 2)) {
+ if (0 > kiro_trb_reshape (priv->trb, size, 3)) {
g_debug ("Failed to create KIRO ring buffer");
kiro_trb_free (priv->trb);
return FALSE;
@@ -251,19 +251,48 @@ kiro_sb_serve (KiroSb *self, gulong size)
}
+KiroContinueFlag
+ready_callback (gboolean *ready)
+{
+ *ready = TRUE;
+ return KIRO_CALLBACK_REMOVE;
+}
+
+
void *
-kiro_sb_get_data (KiroSb *self)
+kiro_sb_get_data_blocking (KiroSb *self)
{
g_return_val_if_fail (self != NULL, NULL);
+ gboolean *ready = g_malloc(sizeof (gboolean));
+ if (!ready)
+ return NULL;
+ *ready = FALSE;
+ kiro_sb_add_sync_callback (self, (KiroSbSyncCallbackFunc)ready_callback, ready);
+
+ while (!(*ready)) {}
+ g_free (ready);
+ return kiro_sb_get_data (self);
+}
+
+
+void *
+kiro_sb_get_data (KiroSb *self)
+{
+ g_return_val_if_fail (self != NULL, NULL);
KiroSbPrivate *priv = KIRO_SB_GET_PRIVATE (self);
- g_return_val_if_fail (priv->initialized != 2, NULL);
struct KiroTrbInfo *header = kiro_trb_get_raw_buffer (priv->trb);
- if (header->offset > 1)
- return kiro_trb_get_element (priv->trb, 1);
- else
- return kiro_trb_get_element (priv->trb, 0);
+ switch (header->offset) {
+ case 0:
+ return kiro_trb_get_element (priv->trb, 0);
+ break;
+ case 1:
+ return kiro_trb_get_element (priv->trb, 1);
+ break;
+ default:
+ return kiro_trb_get_element (priv->trb, -1);
+ }
}
@@ -322,14 +351,14 @@ kiro_sb_clone (KiroSb *self, const gchar* address, const gchar* port)
gulong
-kiro_sb_add_sync_callback (KiroSb *self, KiroSbSyncCallbackFunc func)
+kiro_sb_add_sync_callback (KiroSb *self, KiroSbSyncCallbackFunc func, void *user_data)
{
g_return_val_if_fail (self != NULL, 0);
KiroSbPrivate *priv = KIRO_SB_GET_PRIVATE (self);
GHook *new_hook = g_hook_alloc (&(priv->callbacks));
- new_hook->data = self;
+ new_hook->data = user_data;
new_hook->func = (GHookCheckFunc)func;
g_hook_append (&(priv->callbacks), new_hook);
return new_hook->hook_id;
diff --git a/src/kiro-sb.h b/src/kiro-sb.h
index a2f0148..0af8afe 100644
--- a/src/kiro-sb.h
+++ b/src/kiro-sb.h
@@ -117,7 +117,8 @@ typedef gboolean KiroContinueFlag;
/**
* KiroSbSyncCallbackFunc - Function type for sync callbacks os a #KiroSb
- * @sb: (transfer none): The #KiroSb which invoked this callback
+ * @user_data: (transfer none): The #user_data which was provided during
+ * registration of this callback
* Returns: A #KiroContinueFlag
* Description:
* Defines the type of a callback function which will be invoked every time
@@ -129,7 +130,7 @@ typedef gboolean KiroContinueFlag;
* See also:
* kiro_sb_add_sync_callback, kiro_sb_remove_sync_callback, kiro_sb_clear_sync_callbacks
*/
-typedef KiroContinueFlag (*KiroSbSyncCallbackFunc) (KiroSb *sb);
+typedef KiroContinueFlag (*KiroSbSyncCallbackFunc) (void *user_data);
/**
* kiro_sb_add_sync_callback - Add a sync callback to the #KiroSb
@@ -146,7 +147,7 @@ typedef KiroContinueFlag (*KiroSbSyncCallbackFunc) (KiroSb *sb);
* See also:
* kiro_sb_remove_sync_callback, kiro_sb_clear_sync_callbacks
*/
-gulong kiro_sb_add_sync_callback (KiroSb *sb, KiroSbSyncCallbackFunc callback);
+gulong kiro_sb_add_sync_callback (KiroSb *sb, KiroSbSyncCallbackFunc callback, void *user_data);
/**
* kiro_sb_remove_sync_callback - Remove a callback from the list
@@ -265,11 +266,29 @@ void kiro_sb_thaw (KiroSb *sb);
* after a sync, you should use memcpy().
* See also:
* kiro_sb_freeze, kiro_sb_serve, kiro_sb_clone, kiro_sb_push,
- * kiro_sb_push_dma
+ * kiro_sb_push_dma, kiro_sb_get_data_blocking
*/
void* kiro_sb_get_data (KiroSb *sb);
/**
+ * kiro_sb_get_data_blocking - Wait for new data and return a pointer to it
+ * @sb: (transfer none) The #KiroSb to get the data from
+ * Returns: A void pointer the stored data
+ * Description:
+ * Calling this function will do the same thing as kiro_sb_get_data, but it
+ * will internaly wait until new data has arived before returning it.
+ * Note:
+ * The returned pointer to the element might become invalid at any time by
+ * automatic or manual sync. Under no circumstances might the returned pointer
+ * be freed by the user. If you want to ensure access to the pointed-to data
+ * after a sync, you should use memcpy().
+ * See also:
+ * kiro_sb_freeze, kiro_sb_serve, kiro_sb_clone, kiro_sb_push,
+ * kiro_sb_push_dma, kiro_sb_get_data
+ */
+void* kiro_sb_get_data_blocking (KiroSb *sb);
+
+/**
* kiro_sb_push - Push data into the memory
* @sb: (transfer none) The #KiroSb to get the data from
* @data: (transfer none) void pointer to copy data from