52 lines
1.4 KiB
C
52 lines
1.4 KiB
C
#include <pthread.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include "commonTypes.h"
|
|
#include "ringbuffer.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
bool stopSignal;
|
|
} sinkThreadContext_t;
|
|
|
|
void sinkStop(void *ptr) {
|
|
commonThreadHandle_t *handle = (commonThreadHandle_t*)ptr;
|
|
sinkThreadContext_t *context = (sinkThreadContext_t*)handle->sinkContext;
|
|
|
|
context->stopSignal = true;
|
|
fprintf(stderr, "sink thread, stop flagged\n");
|
|
}
|
|
|
|
|
|
void *sink(void *ptr) {
|
|
fprintf(stderr, "sink entered\n");
|
|
|
|
commonThreadHandle_t *handle = (commonThreadHandle_t*)ptr;
|
|
sinkThreadContext_t *context = (sinkThreadContext_t*) malloc(sizeof(sinkThreadContext_t));
|
|
handle->sinkContext = (void*)context;
|
|
context->stopSignal = false;
|
|
|
|
while (! context->stopSignal) {
|
|
auditItem_t *auditItem = (auditItem_t*)ringbufferGet(handle->ringbuffer);
|
|
|
|
if (auditItem != NULL) {
|
|
printf("AuditItem: Time: %ld\n", auditItem->ts);
|
|
printf("AuditItem: Topic: %s\n", auditItem->topic);
|
|
printf("AuditItem: Payload: %s\n", auditItem->payload);
|
|
|
|
free(auditItem->topic);
|
|
auditItem->topic = NULL;
|
|
free(auditItem->payload);
|
|
auditItem->payload = NULL;
|
|
free(auditItem);
|
|
auditItem = NULL;
|
|
}
|
|
}
|
|
|
|
fprintf(stderr, "sink thread stopped\n");
|
|
return (void*)NULL;
|
|
}
|
|
|