first version of textlog with GUI

introducing generic "view" with two instantiations: stdout and textlist
This commit is contained in:
Cedric Roux
2016-04-28 15:02:01 +02:00
parent 29859bb930
commit ca945b53de
10 changed files with 326 additions and 11 deletions
+35
View File
@@ -0,0 +1,35 @@
#include "view.h"
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
struct stdout {
view common;
pthread_mutex_t lock;
};
static void clear(view *this)
{
/* do nothing */
}
static void append(view *_this, char *s)
{
struct stdout *this = (struct stdout *)_this;
if (pthread_mutex_lock(&this->lock)) abort();
printf("%s\n", s);
if (pthread_mutex_unlock(&this->lock)) abort();
}
view *new_stdout(void)
{
struct stdout *ret = calloc(1, sizeof(struct stdout));
if (ret == NULL) abort();
ret->common.clear = clear;
ret->common.append = (void (*)(view *, ...))append;
if (pthread_mutex_init(&ret->lock, NULL)) abort();
return (view *)ret;
}