diff options
-rw-r--r-- | kiro-trb.c | 35 | ||||
-rw-r--r-- | kiro-trb.h | 24 | ||||
-rw-r--r-- | test.c | 1 |
3 files changed, 40 insertions, 20 deletions
@@ -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); +} @@ -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 @@ -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 |