Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Show changes
Showing
with 1023 additions and 16 deletions
/*
labcomm2014_renaming_decoder.h -- a stacked decoder that renames samples
Copyright 2015 Anders Blomdell <anders.blomdell@control.lth.se>
This file is part of LabComm.
LabComm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LabComm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LABCOMM2014_RENAMING_DECODER_H__
#define __LABCOMM2014_RENAMING_DECODER_H__
#include "labcomm2014.h"
#include "labcomm2014_renaming.h"
struct labcomm2014_decoder *labcomm2014_renaming_decoder_new(
struct labcomm2014_decoder *d,
struct labcomm2014_renaming_registry *r,
char *(*rename)(struct labcomm2014_memory *m, char *name, void *context),
void *context);
#endif
/*
labcomm2014_renaming_encoder.c -- a stacked encoder that renames samples
Copyright 2015 Anders Blomdell <anders.blomdell@control.lth.se>
This file is part of LabComm.
LabComm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LabComm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include "labcomm2014_renaming_encoder.h"
#include "labcomm2014.h"
#include "labcomm2014_private.h"
#include "labcomm2014_renaming_private.h"
struct encoder {
struct labcomm2014_encoder encoder;
struct labcomm2014_encoder *next;
struct labcomm2014_renaming_registry *registry;
char *(*rename_func)(struct labcomm2014_memory *m, char *name, void *context);
void *context;
LABCOMM_SIGNATURE_ARRAY_DEF(renamed,
struct labcomm2014_renaming_rename *);
};
static struct labcomm2014_renaming_rename *get_renamed(
struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature)
{
struct labcomm2014_renaming_rename *result;
struct encoder *ie = e->context;
int index;
index = labcomm2014_get_local_index(signature);
labcomm2014_scheduler_writer_lock(e->scheduler);
result = LABCOMM_SIGNATURE_ARRAY_GET(ie->renamed,
struct labcomm2014_renaming_rename *,
index, NULL);
labcomm2014_scheduler_writer_unlock(e->scheduler);
return result;
}
static struct labcomm2014_renaming_rename *set_renamed(
struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature)
{
struct labcomm2014_renaming_rename *result = NULL;
result = get_renamed(e, signature);
if (result == NULL) {
struct encoder *ie = e->context;
struct labcomm2014_renaming_rename **renamed;
struct labcomm2014_renaming_rename *entry = NULL;
int index;
index = labcomm2014_get_local_index(signature);
entry = labcomm2014_renaming_rename_new(ie->registry, signature,
ie->rename_func, ie->context);
if (entry == NULL) { goto out; }
labcomm2014_scheduler_writer_lock(e->scheduler);
renamed = LABCOMM_SIGNATURE_ARRAY_REF(e->memory, ie->renamed,
struct labcomm2014_renaming_rename *,
index);
if (renamed == NULL) { goto free_unlock; }
if (*renamed != NULL) { result = *renamed; goto free_unlock; }
*renamed = entry;
result = entry;
goto unlock;
free_unlock:
labcomm2014_renaming_rename_free(ie->registry, entry);
unlock:
labcomm2014_scheduler_writer_unlock(e->scheduler);
out:
;
}
return result;
}
static int do_type_register(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature)
{
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = get_renamed(e, signature);
if (renamed) {
/* Register base type and renamed type */
ie->next->type_register(ie->next, signature);
return ie->next->type_register(
ie->next, labcomm2014_renaming_rename_signature(renamed));
} else {
return ie->next->type_register(ie->next, signature);
}
}
static int do_type_bind(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature,
char has_deps)
{
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = get_renamed(e, signature);
if (renamed) {
return ie->next->type_bind(
ie->next, labcomm2014_renaming_rename_signature(renamed), 1);
} else {
return ie->next->type_bind(ie->next, signature, has_deps);
}
}
static int do_sample_register(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature,
labcomm2014_encoder_function encode)
{
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = set_renamed(e, signature);
return ie->next->sample_register(
ie->next, labcomm2014_renaming_rename_signature(renamed), encode);
}
static int do_ref_register(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature)
{
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = set_renamed(e, signature);
return ie->next->ref_register(ie->next,
labcomm2014_renaming_rename_signature(renamed));
}
static int do_encode(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature,
labcomm2014_encoder_function encode,
void *value)
{
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = get_renamed(e, signature);
if (renamed == NULL) {
return -EINVAL;
} else {
return ie->next->encode(ie->next,
labcomm2014_renaming_rename_signature(renamed),
encode, value);
}
}
static int do_ioctl(struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature,
uint32_t ioctl_action, va_list args)
{
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = get_renamed(e, signature);
if (renamed != NULL) {
signature = labcomm2014_renaming_rename_signature(renamed);
}
return ie->next->ioctl(ie->next, signature, ioctl_action, args);
}
static int do_sample_ref_to_index(
struct labcomm2014_encoder *e,
const struct labcomm2014_sample_ref *sample_ref)
{
struct encoder *ie = e->context;
return ie->next->sample_ref_to_index(ie->next,sample_ref);
}
static const struct labcomm2014_sample_ref *do_ref_get(
struct labcomm2014_encoder *e,
const struct labcomm2014_signature *signature)
{
const struct labcomm2014_renaming_rename *renamed;
struct encoder *ie = e->context;
renamed = get_renamed(e, signature);
if (renamed == NULL) {
return ie->next->ref_get(ie->next, signature);
} else {
return ie->next->ref_get(
ie->next, labcomm2014_renaming_rename_signature(renamed));
}
}
static void do_free(struct labcomm2014_encoder *e)
{
struct encoder *ie = e->context;
int i;
LABCOMM_SIGNATURE_ARRAY_FOREACH(ie->renamed,
struct labcomm2014_renaming_rename *, i) {
struct labcomm2014_renaming_rename *r;
r = LABCOMM_SIGNATURE_ARRAY_GET(ie->renamed,
struct labcomm2014_renaming_rename *, i,
NULL);
if (r) {
labcomm2014_renaming_rename_free(ie->registry, r);
}
}
LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, ie->renamed, struct labcomm2014_renaming_rename *);
labcomm2014_memory_free(e->memory, 0, ie);
}
struct labcomm2014_encoder *labcomm2014_renaming_encoder_new(
struct labcomm2014_encoder *e,
struct labcomm2014_renaming_registry *registry,
char *(*rename)(struct labcomm2014_memory *m, char *name, void *context),
void *context)
{
struct encoder *result;
result = labcomm2014_memory_alloc(e->memory, 0, sizeof(*result));
if (!result) {
return NULL;
} else {
result->encoder.context = result;
result->encoder.writer = e->writer;
result->encoder.error = e->error;
result->encoder.memory = e->memory;
result->encoder.scheduler = e->scheduler;
result->encoder.free = do_free;
result->encoder.type_register = do_type_register;
result->encoder.type_bind = do_type_bind;
result->encoder.sample_register = do_sample_register;
result->encoder.ref_register = do_ref_register;
result->encoder.encode = do_encode;
result->encoder.ioctl = do_ioctl;
result->encoder.sample_ref_to_index = do_sample_ref_to_index;
result->encoder.ref_get = do_ref_get;
result->next = e;
result->registry = registry;
result->rename_func = rename;
result->context = context;
LABCOMM_SIGNATURE_ARRAY_INIT(result->renamed,
struct labcomm2014_renaming_rename *);
return &(result->encoder);
}
}
/*
labcomm2014_renaming_encoder.h -- a stacked encoder that renames samples
Copyright 2015 Anders Blomdell <anders.blomdell@control.lth.se>
This file is part of LabComm.
LabComm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LabComm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LABCOMM2014_RENAMING_ENCODER_H__
#define __LABCOMM2014_RENAMING_ENCODER_H__
#include "labcomm2014.h"
#include "labcomm2014_renaming.h"
struct labcomm2014_encoder *labcomm2014_renaming_encoder_new(
struct labcomm2014_encoder *e,
struct labcomm2014_renaming_registry *r,
char *(*rename)(struct labcomm2014_memory *m, char *name, void *context),
void *context);
#endif
/*
labcomm2014_renaming_private.h -- functions intended for renaming
encoders and decoders
Copyright 2015 Anders Blomdell <anders.blomdell@control.lth.se>
This file is part of LabComm.
LabComm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LabComm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LABCOMM2014_RENAMING__PRIVATE_H__
#define __LABCOMM2014_RENAMING_PRIVATE_H__
#include "labcomm2014.h"
#include "labcomm2014_renaming.h"
struct labcomm2014_renaming_rename *labcomm2014_renaming_rename_new(
struct labcomm2014_renaming_registry *r,
const struct labcomm2014_signature *signature,
char *(*rename)(struct labcomm2014_memory *m, char *name, void *context),
void *context);
void labcomm2014_renaming_rename_free(
struct labcomm2014_renaming_registry *r,
struct labcomm2014_renaming_rename *rename);
const struct labcomm2014_signature *labcomm2014_renaming_rename_signature(
const struct labcomm2014_renaming_rename *rename);
#endif
/*
labcomm2014_renaming_registry.c -- renaming registry
Copyright 2015 Anders Blomdell <anders.blomdell@control.lth.se>
This file is part of LabComm.
LabComm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LabComm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "labcomm2014.h"
#include "labcomm2014_private.h"
#include "labcomm2014_renaming_private.h"
struct alias {
int usecount;
struct alias *next;
char *name;
};
struct registry {
struct registry *base; /* NULL if this is the base type */
const struct labcomm2014_signature *signature;
struct labcomm2014_renaming_rename *rename;
};
struct labcomm2014_renaming_rename {
struct labcomm2014_renaming_rename *next;
int use_count;
struct registry *base;
struct labcomm2014_signature signature;
struct labcomm2014_signature_data s_treedata[2];
};
struct labcomm2014_renaming_registry {
struct labcomm2014_error_handler *error;
struct labcomm2014_memory *memory;
struct labcomm2014_scheduler *scheduler;
LABCOMM_SIGNATURE_ARRAY_DEF(registry, struct registry *);
};
struct labcomm2014_renaming_registry *labcomm2014_renaming_registry_new(
struct labcomm2014_error_handler *error,
struct labcomm2014_memory *memory,
struct labcomm2014_scheduler *scheduler)
{
struct labcomm2014_renaming_registry *result;
result = labcomm2014_memory_alloc(memory, 0, sizeof(*result));
if (! result) {
return NULL;
} else {
result->error = error;
result->memory = memory;
result->scheduler = scheduler;
LABCOMM_SIGNATURE_ARRAY_INIT(result->registry, struct registry *);
return result;
}
}
void labcomm2014_renaming_registry_free(
struct labcomm2014_renaming_registry *r)
{
LABCOMM_SIGNATURE_ARRAY_FREE(r->memory, r->registry, struct registry *);
labcomm2014_memory_free(r->memory, 0, r);
}
static struct registry *registry_new(
struct labcomm2014_renaming_registry *r,
const struct labcomm2014_signature *signature,
struct registry *base)
{
/* Called with registry locked */
struct registry *result = NULL;
struct registry **registry;
int index;
index = labcomm2014_get_local_index(signature);
if (index <= 0) {
labcomm2014_error_warning(r->error,
LABCOMM2014_ERROR_MEMORY,
"Signature has no index: %s\n",
signature->name);
goto out;
}
registry = LABCOMM_SIGNATURE_ARRAY_REF(r->memory, r->registry,
struct registry *, index);
if (registry == NULL) { goto out; }
if (*registry != NULL) {
result = *registry;
} else {
/* Add previosly unknown sample to registry */
registry = LABCOMM_SIGNATURE_ARRAY_REF(r->memory, r->registry,
struct registry *, index);
if (registry == NULL) { goto out; }
result = labcomm2014_memory_alloc(r->memory, 0, sizeof(*result));
if (result == NULL) { goto out; }
result->base = base;
result->signature = signature;
result->rename = NULL;
*registry = result;
}
out:
return result;
}
struct labcomm2014_renaming_rename *labcomm2014_renaming_rename_new(
struct labcomm2014_renaming_registry *r,
const struct labcomm2014_signature *signature,
char *(*rename)(struct labcomm2014_memory *m, char *name, void *context),
void *context)
{
struct labcomm2014_renaming_rename *result = NULL;
labcomm2014_scheduler_data_lock(r->scheduler);
{
char *new_name = NULL;
static struct registry *base, *renamed;
struct labcomm2014_renaming_rename **l;
base = registry_new(r, signature, NULL);
if (base == NULL) { goto out; }
if (base->base) {
base = base->base;
}
/* Find if renamed entry already exists */
new_name = rename(r->memory, signature->name, context);
if (new_name == NULL) { goto out; }
for (l = &base->rename ; *l ; l = &(*l)->next) {
if (strcmp((*l)->signature.name, new_name) == 0) { break; }
}
if ((*l) == NULL) {
/* Create a new rename entry */
struct labcomm2014_renaming_rename *entry = NULL;
entry = labcomm2014_memory_alloc(r->memory, 0, sizeof(*entry));
if (entry == NULL) { goto out; }
entry->signature.name = new_name;
new_name = NULL;
entry->signature.encoded_size = base->signature->encoded_size;
entry->signature.size = base->signature->size;
entry->signature.signature = base->signature->signature;
entry->signature.index = 0;
#ifndef LABCOMM_NO_TYPEDECL
struct labcomm2014_signature_data s_treedata[2] = {
LABCOMM_SIGDEF_SIGNATURE(*base->signature),
LABCOMM_SIGDEF_END
};
entry->s_treedata[0] = s_treedata[0];
entry->s_treedata[1] = s_treedata[1];
entry->signature.tdsize = sizeof(entry->s_treedata);
entry->signature.treedata = entry->s_treedata;
#endif
labcomm2014_set_local_index(&entry->signature);
renamed = registry_new(r, &entry->signature, base);
if (renamed == NULL) {
/* Failed to create registry entry */
labcomm2014_memory_free(r->memory, 0, entry);
goto out;
} else {
entry->next = NULL;
entry->use_count = 0;
entry->base = base;
(*l) = entry;
}
}
result = *l;
if (result) {
result->use_count++;
}
out:
if (new_name != NULL) {
labcomm2014_memory_free(r->memory, 0, new_name);
}
}
labcomm2014_scheduler_data_unlock(r->scheduler);
return result;
}
void labcomm2014_renaming_rename_free(
struct labcomm2014_renaming_registry *r,
struct labcomm2014_renaming_rename *rename)
{
labcomm2014_scheduler_data_lock(r->scheduler);
rename->use_count--;
if (rename->use_count == 0) {
int index;
struct labcomm2014_renaming_rename **l;
struct registry **registry;
for (l = &rename->base->rename ; *l ; l = &(*l)->next) {
if (*l == rename) { break; }
}
*l = rename->next;
if (rename->base->rename == NULL) {
/* Last use of base signature */
index = labcomm2014_get_local_index(rename->base->signature);
registry = LABCOMM_SIGNATURE_ARRAY_REF(r->memory, r->registry,
struct registry *, index);
labcomm2014_memory_free(r->memory, 0, *registry);
*registry = NULL;
}
index = labcomm2014_get_local_index(&rename->signature);
registry = LABCOMM_SIGNATURE_ARRAY_REF(r->memory, r->registry,
struct registry *, index);
labcomm2014_memory_free(r->memory, 0, *registry);
*registry = NULL;
/* TODO: We should return the index to the pool*/
labcomm2014_memory_free(r->memory, 0, rename->signature.name);
labcomm2014_memory_free(r->memory, 0, rename);
}
labcomm2014_scheduler_data_unlock(r->scheduler);
}
const struct labcomm2014_signature *labcomm2014_renaming_rename_signature(
const struct labcomm2014_renaming_rename *rename)
{
return &rename->signature;
}
/*
labcomm_scheduler.c -- labcomm task coordination
labcomm2014_scheduler.c -- labcomm2014 task coordination
Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>
......@@ -20,7 +20,7 @@
*/
#include <errno.h>
#include "labcomm_scheduler_private.h"
#include "labcomm2014_scheduler_private.h"
#define SCHEDULER_scheduler(scheduler, ...) scheduler
#define SCHEDULER(func, ...) \
......@@ -30,32 +30,32 @@
} \
return -ENOSYS;
int labcomm_scheduler_free(struct labcomm_scheduler *s)
int labcomm2014_scheduler_free(struct labcomm2014_scheduler *s)
{
SCHEDULER(free, s);
}
int labcomm_scheduler_writer_lock(struct labcomm_scheduler *s)
int labcomm2014_scheduler_writer_lock(struct labcomm2014_scheduler *s)
{
SCHEDULER(writer_lock, s);
}
int labcomm_scheduler_writer_unlock(struct labcomm_scheduler *s)
int labcomm2014_scheduler_writer_unlock(struct labcomm2014_scheduler *s)
{
SCHEDULER(writer_unlock, s);
}
int labcomm_scheduler_data_lock(struct labcomm_scheduler *s)
int labcomm2014_scheduler_data_lock(struct labcomm2014_scheduler *s)
{
SCHEDULER(data_lock, s);
}
int labcomm_scheduler_data_unlock(struct labcomm_scheduler *s)
int labcomm2014_scheduler_data_unlock(struct labcomm2014_scheduler *s)
{
SCHEDULER(data_unlock, s);
}
struct labcomm_time *labcomm_scheduler_now(struct labcomm_scheduler *s)
struct labcomm2014_time *labcomm2014_scheduler_now(struct labcomm2014_scheduler *s)
{
if (s && s->action->now) {
return s->action->now(s);
......@@ -63,18 +63,18 @@ struct labcomm_time *labcomm_scheduler_now(struct labcomm_scheduler *s)
return NULL;
}
int labcomm_scheduler_sleep(struct labcomm_scheduler *s,
struct labcomm_time *wakeup)
int labcomm2014_scheduler_sleep(struct labcomm2014_scheduler *s,
struct labcomm2014_time *wakeup)
{
SCHEDULER(sleep, s, wakeup);
}
int labcomm_scheduler_wakeup(struct labcomm_scheduler *s)
int labcomm2014_scheduler_wakeup(struct labcomm2014_scheduler *s)
{
SCHEDULER(wakeup, s);
}
int labcomm_scheduler_enqueue(struct labcomm_scheduler *s,
int labcomm2014_scheduler_enqueue(struct labcomm2014_scheduler *s,
uint32_t delay,
void (*func)(void *context),
void *context)
......
/*
labcomm_scheduler.h -- labcomm task coordination
labcomm2014_scheduler.h -- labcomm2014 task coordination
Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>
......@@ -19,35 +19,39 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LABCOMM_SCHEDULER_H_
#define _LABCOMM_SCHEDULER_H_
#ifndef __LABCOMM2014_SCHEDULER_H__
#define __LABCOMM2014_SCHEDULER_H__
#include <unistd.h>
#include <stdint.h>
#ifdef LABCOMM_COMPAT
#include LABCOMM_COMPAT
#else
#include <unistd.h>
#include <stdint.h>
#endif
struct labcomm_time;
struct labcomm2014_time;
int labcomm_time_free(struct labcomm_time *t);
int labcomm_time_add_usec(struct labcomm_time *t, uint32_t usec);
int labcomm2014_time_free(struct labcomm2014_time *t);
int labcomm2014_time_add_usec(struct labcomm2014_time *t, uint32_t usec);
struct labcomm_scheduler;
struct labcomm2014_scheduler;
int labcomm_scheduler_free(struct labcomm_scheduler *s);
int labcomm2014_scheduler_free(struct labcomm2014_scheduler *s);
/* Lock and event handling */
int labcomm_scheduler_writer_lock(struct labcomm_scheduler *s);
int labcomm_scheduler_writer_unlock(struct labcomm_scheduler *s);
int labcomm_scheduler_data_lock(struct labcomm_scheduler *s);
int labcomm_scheduler_data_unlock(struct labcomm_scheduler *s);
int labcomm2014_scheduler_writer_lock(struct labcomm2014_scheduler *s);
int labcomm2014_scheduler_writer_unlock(struct labcomm2014_scheduler *s);
int labcomm2014_scheduler_data_lock(struct labcomm2014_scheduler *s);
int labcomm2014_scheduler_data_unlock(struct labcomm2014_scheduler *s);
/* Time handling */
struct labcomm_time *labcomm_scheduler_now(struct labcomm_scheduler *s);
int labcomm_scheduler_sleep(struct labcomm_scheduler *s,
struct labcomm_time *wakeup);
int labcomm_scheduler_wakeup(struct labcomm_scheduler *s);
struct labcomm2014_time *labcomm2014_scheduler_now(struct labcomm2014_scheduler *s);
int labcomm2014_scheduler_sleep(struct labcomm2014_scheduler *s,
struct labcomm2014_time *wakeup);
int labcomm2014_scheduler_wakeup(struct labcomm2014_scheduler *s);
/* Deferred action handling */
int labcomm_scheduler_enqueue(struct labcomm_scheduler *s,
int labcomm2014_scheduler_enqueue(struct labcomm2014_scheduler *s,
uint32_t delay,
void (*deferred)(void *context),
void *context);
......
/*
labcomm_scheduler.h -- labcomm task coordination, semi-private part
labcomm2014_scheduler.h -- labcomm2014 task coordination, semi-private part
Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>
......@@ -19,32 +19,37 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LABCOMM_SCHEDULER_PRIVATE_H_
#define _LABCOMM_SCHEDULER_PRIVATE_H_
#ifndef __LABCOMM2014_SCHEDULER_PRIVATE_H__
#define __LABCOMM2014_SCHEDULER_PRIVATE_H__
#include <unistd.h>
#include "labcomm_scheduler.h"
#ifdef LABCOMM_COMPAT
#include LABCOMM_COMPAT
#else
#include <unistd.h>
#endif
#include "labcomm2014_scheduler.h"
struct labcomm_time {
const struct labcomm_time_action {
int (*free)(struct labcomm_time *t);
int (*add_usec)(struct labcomm_time *t, uint32_t usec);
struct labcomm2014_time {
const struct labcomm2014_time_action {
int (*free)(struct labcomm2014_time *t);
int (*add_usec)(struct labcomm2014_time *t, uint32_t usec);
} *action;
void *context;
};
struct labcomm_scheduler {
const struct labcomm_scheduler_action {
int (*free)(struct labcomm_scheduler *s);
int (*writer_lock)(struct labcomm_scheduler *s);
int (*writer_unlock)(struct labcomm_scheduler *s);
int (*data_lock)(struct labcomm_scheduler *s);
int (*data_unlock)(struct labcomm_scheduler *s);
struct labcomm_time *(*now)(struct labcomm_scheduler *s);
int (*sleep)(struct labcomm_scheduler *s,
struct labcomm_time *wakeup);
int (*wakeup)(struct labcomm_scheduler *s);
int (*enqueue)(struct labcomm_scheduler *s,
struct labcomm2014_scheduler {
const struct labcomm2014_scheduler_action {
int (*free)(struct labcomm2014_scheduler *s);
int (*writer_lock)(struct labcomm2014_scheduler *s);
int (*writer_unlock)(struct labcomm2014_scheduler *s);
int (*data_lock)(struct labcomm2014_scheduler *s);
int (*data_unlock)(struct labcomm2014_scheduler *s);
struct labcomm2014_time *(*now)(struct labcomm2014_scheduler *s);
int (*sleep)(struct labcomm2014_scheduler *s,
struct labcomm2014_time *wakeup);
int (*wakeup)(struct labcomm2014_scheduler *s);
int (*enqueue)(struct labcomm2014_scheduler *s,
uint32_t delay,
void (*deferred)(void *context),
void *context);
......
/*
labcomm_time.c -- labcomm time handling
labcomm2014_time.c -- labcomm2014 time handling
Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>
......@@ -20,7 +20,7 @@
*/
#include <errno.h>
#include "labcomm_scheduler_private.h"
#include "labcomm2014_scheduler_private.h"
#define TIME_time(time, ...) time
#define TIME(func, ...) \
......@@ -30,12 +30,12 @@
} \
return -ENOSYS;
int labcomm_time_free(struct labcomm_time *s)
int labcomm2014_time_free(struct labcomm2014_time *s)
{
TIME(free, s);
}
int labcomm_time_add_usec(struct labcomm_time *s, uint32_t usec)
int labcomm2014_time_add_usec(struct labcomm2014_time *s, uint32_t usec)
{
TIME(add_usec, s, usec);
}
......
#include "labcomm2014.h"
#include <string.h> // for memcmp
#include <stdio.h> // for debug printf
/* Dump signature bytes on stdout
*/
void labcomm2014_signature_print(struct labcomm2014_signature_data *signature)
{
struct labcomm2014_signature_data *p = signature ;
while (p->length != -1) {
if (p->length) {
int i;
for ( i = 0 ; i < p->length ; i++) {
printf("%02x ", p->u.bytes[i]);
}
} else if(p->u.signature){
labcomm2014_signature_print(p->u.signature->treedata);
} else {
printf("neither data nor ref, bailing out.\n");
return;
}
p+=1;
}
printf("\n");
}
static labcomm2014_bool sig_dump_checked(struct labcomm2014_signature_data *signature,
char *buf, int *len, int buflen);
/* buf (out) : byte array to write signature into
len (in/out): input: buf size, out: signature length
return LABCOMM2014_TRUE if aborted due to overrun
*/
labcomm2014_bool labcomm2014_signature_dump(struct labcomm2014_signature_data *signature,
char *buf, int *len)
{
int buflen = *len;
*len = 0;
return sig_dump_checked(signature, buf, len, buflen);
}
/* internal function with bounds checking for buf.
* buflen: capacity of buf
*/
static labcomm2014_bool sig_dump_checked(struct labcomm2014_signature_data *signature,
char *buf, int *len, int buflen)
{
struct labcomm2014_signature_data *p = signature;
while ( (p->length != -1) && (*len < buflen)) {
if (p->length) {
int i;
for ( i = 0 ; (i < p->length) && (*len < buflen); i++) {
*buf++ = p->u.bytes[i];
++*len;
}
} else if(p->u.signature){
int tmplen=*len;
//recursing. c.f. dump()
sig_dump_checked(p->u.signature->treedata, buf, len, buflen);
int inner_len = *len-tmplen;
buf += inner_len;
} else {
//printf("neither data nor ref, bailing out.\n");
return LABCOMM2014_TRUE;
}
p+=1;
}
return (*len >= buflen);
}
/* compare signature (flattened, if needed) to other
return LABCOMM2014_TRUE if equal
*/
labcomm2014_bool labcomm2014_signature_cmp( struct labcomm2014_signature_data *s1,
struct labcomm2014_signature_data *s2)
{
int buflen=512;
char buf1[buflen];
int len1=buflen;
char buf2[buflen];
int len2=buflen;
labcomm2014_bool res1 = labcomm2014_signature_dump(s1, buf1, &len1);
labcomm2014_bool res2 = labcomm2014_signature_dump(s2, buf2, &len2);
if(res1 || res2) {
printf("WARNING: OVERRUN\n");
return LABCOMM2014_FALSE;
} else {
return(len1 == len2 && memcmp(buf1, buf2, len1)==0);
}
}
/* maps a function f(char b, struct labcomm2014_signature *s, void *context)
* on each byte (or type ref) in the signature.
*
* If flatten, the signature is flattened to a byte array, and the
* second argument to f is always zero.
*
* Otherwise, when a type ref is encountered, f is called with the first
* argument zero and the referenced type as the second argument.
*
* The context parameter is passed on, unaltered, to f
*/
void map_signature( void(*f)(char, const struct labcomm2014_signature *, void *),
void *context,
const struct labcomm2014_signature *signature, labcomm2014_bool flatten)
{
struct labcomm2014_signature_data* p = signature->treedata;
while (p->length != -1) {
//fprintf(stderr, "%p %x\n", p, p->length);
if (p->length) {
int i;
for ( i = 0 ; i < p->length ; i++) {
(*f)(p->u.bytes[i], 0, context);
}
} else if (p->u.signature) {
if(p->u.signature == 0) printf("p->u.signature == null\n");
if(flatten) {
map_signature(f, context, p->u.signature, flatten);
} else {
(*f)(0, p->u.signature, context);
}
} else {
fprintf(stderr, "neither data nor ref, bailing out.\n");
return;
}
p+=1;
}
}
#ifndef __LABCOMM2014_TYPE_SIGNATURE_H__
#define __LABCOMM2014_TYPE_SIGNATURE_H__
//XXX move to common.h
#ifndef labcomm2014_bool
#define labcomm2014_bool char
#define LABCOMM2014_TRUE 1
#define LABCOMM2014_FALSE 0
#endif
/*
* Signature entry
*/
#ifndef LABCOMM_NO_TYPEDECL
#ifdef USE_UNIONS
/* Useful for C99 and up (or GCC without -pedantic) */
#define LABCOMM_SIGDEF_BYTES_OR_SIGNATURE \
union { \
char *bytes; \
struct labcomm2014_signature* signature; \
} u;
#define LABCOMM_SIGDEF_BYTES(l, b) { l, .u.bytes=b }
#define LABCOMM_SIGDEF_SIGNATURE(s) { 0, .u.signature=&s } // addressof, as s is pointing at the sig struct, not directly the the sig_bytes[]
#define LABCOMM_SIGDEF_END { -1, .u.bytes=0 }
#else
#define LABCOMM_SIGDEF_BYTES_OR_SIGNATURE \
struct { \
char *bytes; \
const struct labcomm2014_signature *signature; \
} u;
#define LABCOMM_SIGDEF_BYTES(l, b) { l, { b, 0 } }
#define LABCOMM_SIGDEF_SIGNATURE(s) { 0, { 0, &s } }
#define LABCOMM_SIGDEF_END { -1, { 0, 0 } }
#endif
struct labcomm2014_signature_data {
int length;
LABCOMM_SIGDEF_BYTES_OR_SIGNATURE
};
#endif
struct labcomm2014_sample_ref;
struct labcomm2014_signature {
char *name;
int (*encoded_size)(const struct labcomm2014_signature *sig, void *); /* void* refers to sample_data */
int size;
unsigned char *signature;
int index;
#ifndef LABCOMM_NO_TYPEDECL
int tdsize;
struct labcomm2014_signature_data *treedata;
#endif
#ifdef LABCOMM_EXPERIMENTAL_CACHED_ENCODED_SIZE
int cached_encoded_size; // -1 if not initialized or type is variable size
#endif
};
/* a struct for "raw" type_defs, to be used as an intermediate representation
* between decoder and signature parser
*/
struct labcomm2014_raw_type_def {
char *name;
int index;
int length;
char *signature_data;
};
/* a struct for type bindings
*/
struct labcomm2014_type_binding {
int sample_index;
int type_index;
};
/*
* functions
*/
/* register a handler for type_defs and type bindings
*/
int labcomm2014_decoder_register_labcomm2014_type_def(
struct labcomm2014_decoder *d,
void (*handler)(
struct labcomm2014_raw_type_def *v,
void *context
),
void *context
);
int labcomm2014_decoder_register_labcomm2014_type_binding(
struct labcomm2014_decoder *d,
void (*handler)(
struct labcomm2014_type_binding *v,
void *context
),
void *context
);
/* Dump signature bytes on stdout
*/
void labcomm2014_signature_print(struct labcomm2014_signature_data *signature);
/* compare signatures (flattened, if needed) to other
* return LABCOMM2014_TRUE if equal
*/
labcomm2014_bool labcomm2014_signature_cmp( struct labcomm2014_signature_data *s2,
struct labcomm2014_signature_data *s1);
/* flatten and dump signature to a byte array.
* buf (out) : byte array to write signature into
* len (in/out): input: buf size, out: signature length
*
* return LABCOMM2014_TRUE if aborted due to overrun
*/
labcomm2014_bool labcomm2014_signature_dump(struct labcomm2014_signature_data *signature,
char *buf, int *len);
/* maps function f on each byte in the signature
* if flatten, the signature is flattened, and the second argument of
* f is always zero
* otherwise, when a type ref is encountered, f is called with the first
* argument zero and the type ref as the second argument.
*/
void map_signature( void(*f)(char, const struct labcomm2014_signature *, void *),
void *context,
const struct labcomm2014_signature *signature, labcomm2014_bool flatten);
#endif
gen
File moved
sample void V;
typedef void unused_t;
typedef void v_t;
sample v_t V;
sample byte B;
sample struct {
int i;
} S1;
sample int I[_];
sample struct { int i; } P[_];
sample void UnusedE;
sample void UnusedD;
sample sample R[4];
sample string S;
sample int A[8];
sample struct {
string s1;
string s2;
} NS;
sample string AS[_];