summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Dritschler <timo.dritschler@kit.edu>2014-04-25 18:59:55 +0200
committerTimo Dritschler <timo.dritschler@kit.edu>2014-04-25 19:37:32 +0200
commit2b5ad5dfa5baa9a243051022510600fd8a82fd20 (patch)
treef89739a609478ff69bf18267553e67980ff3f28d
parentd17929dce11210dad47036c55f0fa60cb224392f (diff)
downloadkiro-2b5ad5dfa5baa9a243051022510600fd8a82fd20.tar.gz
kiro-2b5ad5dfa5baa9a243051022510600fd8a82fd20.tar.bz2
kiro-2b5ad5dfa5baa9a243051022510600fd8a82fd20.tar.xz
kiro-2b5ad5dfa5baa9a243051022510600fd8a82fd20.zip
Added 'kiro_trb_refresh' that refreshes all internal meta
information based on the memory content Added 'kiro_trb_is_setup' to check if the buffer is consistent
-rw-r--r--kiro-trb.c35
-rw-r--r--kiro-trb.h24
-rw-r--r--test.c1
3 files changed, 40 insertions, 20 deletions
diff --git a/kiro-trb.c b/kiro-trb.c
index 3718102..b433e38 100644
--- a/kiro-trb.c
+++ b/kiro-trb.c
@@ -48,9 +48,9 @@ struct _KiroTrbPrivate {
/* 'Real' private structures */
/* (Not accessible by properties) */
int initialized; // 1 if Buffer is Valid, 0 otherwise
- void* mem; // Access to the actual buffer in Memory
- void* frame_top; // First byte of the buffer storage
- void* current; // Pointer to the current fill state
+ void *mem; // Access to the actual buffer in Memory
+ void *frame_top; // First byte of the buffer storage
+ void *current; // Pointer to the current fill state
uint64_t element_size;
uint64_t max_elements;
uint64_t iteration; // How many times the buffer has wraped around
@@ -166,6 +166,13 @@ void kiro_trb_flush (KiroTrb *self)
}
+int kiro_trb_is_setup (KiroTrb *self)
+{
+ KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
+ return priv->initialized;
+}
+
+
int kiro_trb_reshape (KiroTrb *self, uint64_t element_size, uint64_t element_count)
{
size_t new_size = (element_size * element_count) + sizeof(struct KiroTrbInfo);
@@ -194,22 +201,30 @@ int kiro_trb_push (KiroTrb *self, void *element_in)
priv->current = priv->frame_top;
priv->iteration++;
}
+ write_header(priv);
return 0;
}
-void kiro_trb_ingest (KiroTrb *self, void *buff_in)
+void kiro_trb_refresh (KiroTrb *self)
{
KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- struct KiroTrbInfo *tmp = (struct KiroTrbInfo *)buff_in;
- if(priv->mem)
- free(priv->mem);
- priv->mem = buff_in;
+ struct KiroTrbInfo *tmp = (struct KiroTrbInfo *)priv->mem;
priv->buff_size = tmp->buffer_size_bytes;
priv->element_size = tmp->element_size;
priv->max_elements = (tmp->buffer_size_bytes - sizeof(struct KiroTrbInfo)) / tmp->element_size;
priv->iteration = tmp->offset / priv->max_elements;
- priv->frame_top = buff_in + sizeof(struct KiroTrbInfo);
+ priv->frame_top = priv->mem + sizeof(struct KiroTrbInfo);
priv->current = priv->frame_top + ((tmp->offset % priv->max_elements) * priv->element_size);
priv->initialized = 1;
-} \ No newline at end of file
+}
+
+
+void kiro_trb_ingest (KiroTrb *self, void *buff_in)
+{
+ KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
+ if(priv->mem)
+ free(priv->mem);
+ priv->mem = buff_in;
+ kiro_trb_refresh(self);
+}
diff --git a/kiro-trb.h b/kiro-trb.h
index db0cd8e..0a39a4a 100644
--- a/kiro-trb.h
+++ b/kiro-trb.h
@@ -86,25 +86,29 @@ GObject kiro_trb_new (void);
/* trb functions */
-uint64_t kiro_trb_get_element_count (KiroTrb*);
+uint64_t kiro_trb_get_element_count (KiroTrb* trb);
-uint64_t kiro_trb_get_element_size (KiroTrb*);
+uint64_t kiro_trb_get_element_size (KiroTrb* trb);
-uint64_t kiro_trb_get_max_elements (KiroTrb*);
+uint64_t kiro_trb_get_max_elements (KiroTrb* trb);
-uint64_t kiro_trb_get_raw_size (KiroTrb*);
+uint64_t kiro_trb_get_raw_size (KiroTrb* trb);
-void* kiro_trb_get_raw_buffer (KiroTrb*);
+void* kiro_trb_get_raw_buffer (KiroTrb* trb);
-void* kiro_trb_get_element (KiroTrb*, uint64_t);
+void* kiro_trb_get_element (KiroTrb* trb, uint64_t index);
-void kiro_trb_flush (KiroTrb*);
+void kiro_trb_flush (KiroTrb* trb);
-int kiro_trb_reshape (KiroTrb*, uint64_t, uint64_t);
+int kiro_trb_is_setup (KiroTrb* trb);
-int kiro_trb_push (KiroTrb*, void*);
+int kiro_trb_reshape (KiroTrb* trb, uint64_t element_size, uint64_t element_count);
-void kiro_trb_ingest (KiroTrb*, void*);
+int kiro_trb_push (KiroTrb* trb, void* source);
+
+void kiro_trb_refresh (KiroTrb* trb);
+
+void kiro_trb_ingest (KiroTrb* trb, void* source);
G_END_DECLS
diff --git a/test.c b/test.c
index b49e333..56ed5cf 100644
--- a/test.c
+++ b/test.c
@@ -45,6 +45,7 @@ int main(void)
printf("Stored in New: %x\n", *maman);
sleep(1);
g_object_unref(rb);
+ g_object_unref(rb2);
return 0;
} \ No newline at end of file