Commit e3c16fda authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Changed 'labcomm' to 'labcomm2014' for C-code.

parent f11ec7ba
This diff is collapsed.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_reader.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_default_scheduler.h>
#include <labcomm2014_fd_reader.h>
#include <labcomm2014_default_error_handler.h>
#include <labcomm2014_default_memory.h>
#include <labcomm2014_default_scheduler.h>
#include "gen/simple.h"
#include <stdio.h>
......@@ -57,33 +57,33 @@ static void handle_simple_TwoFixedArrays(simple_TwoFixedArrays *d,void *context)
int main(int argc, char *argv[]) {
int fd;
struct labcomm_decoder *decoder;
struct labcomm2014_decoder *decoder;
void *context = NULL;
char *filename = argv[1];
printf("C decoder reading from %s\n", filename);
fd = open(filename, O_RDONLY);
decoder = labcomm_decoder_new(labcomm_fd_reader_new(
labcomm_default_memory, fd, 1),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm_default_scheduler);
decoder = labcomm2014_decoder_new(labcomm2014_fd_reader_new(
labcomm2014_default_memory, fd, 1),
labcomm2014_default_error_handler,
labcomm2014_default_memory,
labcomm2014_default_scheduler);
if (!decoder) {
printf("Failed to allocate decoder %s:%d\n", __FUNCTION__, __LINE__);
return 1;
}
labcomm_decoder_register_simple_doavoid(decoder, handle_simple_doavoid, context);
labcomm_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context);
labcomm_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context);
labcomm_decoder_register_simple_IntString(decoder, handle_simple_IntString, context);
labcomm_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context);
labcomm_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context);
labcomm2014_decoder_register_simple_doavoid(decoder, handle_simple_doavoid, context);
labcomm2014_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context);
labcomm2014_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context);
labcomm2014_decoder_register_simple_IntString(decoder, handle_simple_IntString, context);
labcomm2014_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context);
labcomm2014_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context);
printf("Decoding:\n");
labcomm_decoder_run(decoder);
labcomm2014_decoder_run(decoder);
printf("--- End Of File ---:\n");
labcomm_decoder_free(decoder);
labcomm2014_decoder_free(decoder);
return 0;
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_writer.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_default_scheduler.h>
#include <labcomm2014_fd_writer.h>
#include <labcomm2014_default_error_handler.h>
#include <labcomm2014_default_memory.h>
#include <labcomm2014_default_scheduler.h>
#include "gen/simple.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
int fd;
struct labcomm_encoder *encoder;
struct labcomm2014_encoder *encoder;
char *filename = argv[1];
printf("C encoder writing to %s\n", filename);
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
encoder = labcomm_encoder_new(labcomm_fd_writer_new(
labcomm_default_memory, fd, 1),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm_default_scheduler);
labcomm_encoder_register_simple_doavoid(encoder);
labcomm_encoder_register_simple_theTwoInts(encoder);
labcomm_encoder_register_simple_anotherTwoInts(encoder);
labcomm_encoder_register_simple_IntString(encoder);
labcomm_encode_simple_doavoid(encoder);
encoder = labcomm2014_encoder_new(labcomm2014_fd_writer_new(
labcomm2014_default_memory, fd, 1),
labcomm2014_default_error_handler,
labcomm2014_default_memory,
labcomm2014_default_scheduler);
labcomm2014_encoder_register_simple_doavoid(encoder);
labcomm2014_encoder_register_simple_theTwoInts(encoder);
labcomm2014_encoder_register_simple_anotherTwoInts(encoder);
labcomm2014_encoder_register_simple_IntString(encoder);
labcomm2014_encode_simple_doavoid(encoder);
simple_IntString is;
is.x = 24;
is.s = "Hello, LabComm!";
printf("Encoding IntString, x=%d, s=%s\n", is.x, is.s);
labcomm_encode_simple_IntString(encoder, &is);
labcomm2014_encode_simple_IntString(encoder, &is);
simple_theTwoInts ti;
ti.a = 13;
ti.b = 37;
printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
labcomm_encode_simple_theTwoInts(encoder, &ti);
labcomm2014_encode_simple_theTwoInts(encoder, &ti);
simple_anotherTwoInts ati;
ati.a = 23;
ati.b = 47;
printf("Encoding anotherTwoInts, a=%d, b=%d\n", ati.a, ati.b);
labcomm_encode_simple_anotherTwoInts(encoder, &ati);
labcomm2014_encode_simple_anotherTwoInts(encoder, &ati);
int foo[20];
labcomm_encoder_register_simple_TwoArrays(encoder);
labcomm2014_encoder_register_simple_TwoArrays(encoder);
simple_TwoArrays ta;
ta.fixed.a[0] = 17;
......@@ -61,12 +61,12 @@ int main(int argc, char *argv[]) {
}
printf("Encoding TwoArrays...\n");
labcomm_encode_simple_TwoArrays(encoder, &ta);
labcomm2014_encode_simple_TwoArrays(encoder, &ta);
ti.a = 23;
ti.b = 47;
printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
labcomm_encode_simple_theTwoInts(encoder, &ti);
labcomm2014_encode_simple_theTwoInts(encoder, &ti);
simple_TwoFixedArrays tfa;
......@@ -82,8 +82,8 @@ int main(int argc, char *argv[]) {
tfa.b.a[1][2] = 63;
printf("Encoding TwoFixedArrays...\n");
labcomm_encoder_register_simple_TwoFixedArrays(encoder);
labcomm_encode_simple_TwoFixedArrays(encoder, &tfa);
labcomm2014_encoder_register_simple_TwoFixedArrays(encoder);
labcomm2014_encode_simple_TwoFixedArrays(encoder, &tfa);
return 0;
}
......@@ -36,12 +36,12 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <labcomm.h>
#include <labcomm_fd_reader.h>
#include <labcomm_fd_writer.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_pthread_scheduler.h>
#include <labcomm2014.h>
#include <labcomm2014_fd_reader.h>
#include <labcomm2014_fd_writer.h>
#include <labcomm2014_default_error_handler.h>
#include <labcomm2014_default_memory.h>
#include <labcomm2014_pthread_scheduler.h>
#include "decimating.h"
#include "introspecting.h"
#include "gen/types.h"
......@@ -63,13 +63,13 @@ static void handle_Product(int32_t *value, void *context)
static void *run_decoder(void *context)
{
struct labcomm_decoder *decoder = context;
struct labcomm2014_decoder *decoder = context;
int result;
labcomm_decoder_register_types_Sum(decoder, handle_Sum, NULL);
labcomm_decoder_register_types_Diff(decoder, handle_Diff, NULL);
labcomm2014_decoder_register_types_Sum(decoder, handle_Sum, NULL);
labcomm2014_decoder_register_types_Diff(decoder, handle_Diff, NULL);
do {
result = labcomm_decoder_decode_one(decoder);
result = labcomm2014_decoder_decode_one(decoder);
} while (result >= 0);
return NULL;
}
......@@ -87,10 +87,10 @@ int main(int argc, char *argv[])
struct introspecting *introspecting;
char *hostname;
int port;
struct labcomm_scheduler *scheduler;
struct labcomm_decoder *decoder;
struct labcomm_encoder *encoder;
struct labcomm_time *next;
struct labcomm2014_scheduler *scheduler;
struct labcomm2014_decoder *decoder;
struct labcomm2014_encoder *encoder;
struct labcomm2014_time *next;
int32_t i, j;
hostname = argv[1];
......@@ -128,13 +128,13 @@ int main(int argc, char *argv[])
nodelay = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay));
scheduler = labcomm_pthread_scheduler_new(labcomm_default_memory);
decimating = decimating_new(labcomm_fd_reader_new(labcomm_default_memory,
scheduler = labcomm2014_pthread_scheduler_new(labcomm2014_default_memory);
decimating = decimating_new(labcomm2014_fd_reader_new(labcomm2014_default_memory,
fd, 1),
labcomm_fd_writer_new(labcomm_default_memory,
labcomm2014_fd_writer_new(labcomm2014_default_memory,
fd, 0),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
scheduler);
if (decimating == NULL) {
/* Warning: might leak reader and writer at this point */
......@@ -142,45 +142,45 @@ int main(int argc, char *argv[])
}
introspecting = introspecting_new(decimating->reader,
decimating->writer,
labcomm_default_error_handler,
labcomm_default_memory,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
scheduler);
if (introspecting == NULL) {
/* Warning: might leak reader and writer at this point */
goto out;
}
decoder = labcomm_decoder_new(introspecting->reader,
labcomm_default_error_handler,
labcomm_default_memory,
decoder = labcomm2014_decoder_new(introspecting->reader,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
scheduler);
encoder = labcomm_encoder_new(introspecting->writer,
labcomm_default_error_handler,
labcomm_default_memory,
encoder = labcomm2014_encoder_new(introspecting->writer,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
scheduler);
pthread_t rdt;
pthread_create(&rdt, NULL, run_decoder, decoder);
labcomm_encoder_register_types_A(encoder);
labcomm_encoder_register_types_B(encoder);
labcomm_encoder_register_types_Terminate(encoder);
labcomm2014_encoder_register_types_A(encoder);
labcomm2014_encoder_register_types_B(encoder);
labcomm2014_encoder_register_types_Terminate(encoder);
err = labcomm_decoder_ioctl_types_Sum(decoder, SET_DECIMATION, 2);
err = labcomm_decoder_ioctl_types_Diff(decoder, SET_DECIMATION, 4);
err = labcomm2014_decoder_ioctl_types_Sum(decoder, SET_DECIMATION, 2);
err = labcomm2014_decoder_ioctl_types_Diff(decoder, SET_DECIMATION, 4);
next = labcomm_scheduler_now(scheduler);
next = labcomm2014_scheduler_now(scheduler);
for (i = 0 ; i < 4 ; i++) {
if (i == 2) {
labcomm_decoder_register_types_Product(decoder, handle_Product, NULL);
labcomm2014_decoder_register_types_Product(decoder, handle_Product, NULL);
}
for (j = 0 ; j < 4 ; j++) {
printf("\nA=%d B=%d: ", i, j);
labcomm_encode_types_A(encoder, &i);
labcomm_encode_types_B(encoder, &j);
labcomm_time_add_usec(next, 100000);
labcomm_scheduler_sleep(scheduler, next);
labcomm2014_encode_types_A(encoder, &i);
labcomm2014_encode_types_B(encoder, &j);
labcomm2014_time_add_usec(next, 100000);
labcomm2014_scheduler_sleep(scheduler, next);
}
}
printf("\n");
labcomm_encode_types_Terminate(encoder);
labcomm2014_encode_types_Terminate(encoder);
out:
return 0;
......
......@@ -23,18 +23,18 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "labcomm_private.h"
#include "labcomm2014_private.h"
#include "decimating.h"
#include "gen/decimating_messages.h"
struct decimating_private {
struct decimating decimating;
struct labcomm_error_handler *error;
struct labcomm_memory *memory;
struct labcomm_scheduler *scheduler;
struct labcomm2014_error_handler *error;
struct labcomm2014_memory *memory;
struct labcomm2014_scheduler *scheduler;
int encoder_initialized;
struct labcomm_reader_action_context reader_action_context;
struct labcomm_writer_action_context writer_action_context;
struct labcomm2014_reader_action_context reader_action_context;
struct labcomm2014_writer_action_context writer_action_context;
LABCOMM_SIGNATURE_ARRAY_DEF(writer_decimation,
struct decimation {
int n;
......@@ -50,25 +50,25 @@ static void set_decimation(
struct decimating_private *decimating = context;
struct decimation *decimation;
labcomm_scheduler_data_lock(decimating->scheduler);
labcomm2014_scheduler_data_lock(decimating->scheduler);
decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory,
decimating->writer_decimation,
struct decimation,
value->signature_index);
decimation->n = value->decimation;
decimation->current = 0;
labcomm_scheduler_data_unlock(decimating->scheduler);
labcomm2014_scheduler_data_unlock(decimating->scheduler);
}
static int wrap_reader_alloc(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context)
struct labcomm2014_reader *r,
struct labcomm2014_reader_action_context *action_context)
{
struct decimating_private *decimating = action_context->context;
labcomm_decoder_register_decimating_messages_set_decimation(
labcomm2014_decoder_register_decimating_messages_set_decimation(
r->decoder, set_decimation, decimating);
return labcomm_reader_alloc(r, action_context->next);
return labcomm2014_reader_alloc(r, action_context->next);
}
struct send_set_decimation {
......@@ -80,11 +80,11 @@ struct send_set_decimation {
static void send_set_decimation(void *arg)
{
struct send_set_decimation *msg = arg;
struct labcomm_memory *memory = msg->decimating->memory;
struct labcomm2014_memory *memory = msg->decimating->memory;
labcomm_encode_decimating_messages_set_decimation(
labcomm2014_encode_decimating_messages_set_decimation(
msg->decimating->decimating.writer->encoder, &msg->set_decimation);
labcomm_memory_free(memory, 1, msg);
labcomm2014_memory_free(memory, 1, msg);
}
static void enqueue_decimation(struct decimating_private *decimating,
......@@ -92,21 +92,21 @@ static void enqueue_decimation(struct decimating_private *decimating,
int amount)
{
struct send_set_decimation *msg;
msg = labcomm_memory_alloc(decimating->memory, 1, sizeof(*msg));
msg = labcomm2014_memory_alloc(decimating->memory, 1, sizeof(*msg));
if (msg) {
msg->decimating = decimating;
msg->set_decimation.decimation = amount;
msg->set_decimation.signature_index = remote_index;
labcomm_scheduler_enqueue(decimating->scheduler, 0,
labcomm2014_scheduler_enqueue(decimating->scheduler, 0,
send_set_decimation, msg);
}
}
static int wrap_reader_start(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
int local_index, int remote_index, const struct labcomm_signature *signature,
struct labcomm2014_reader *r,
struct labcomm2014_reader_action_context *action_context,
int local_index, int remote_index, const struct labcomm2014_signature *signature,
void *value)
{
struct decimating_private *decimating = action_context->context;
......@@ -114,26 +114,26 @@ static int wrap_reader_start(
if (value == NULL) {
int *decimation, amount;
labcomm_scheduler_data_lock(decimating->scheduler);
labcomm2014_scheduler_data_lock(decimating->scheduler);
decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory,
decimating->reader_decimation,
int,
local_index);
amount = *decimation;
labcomm_scheduler_data_unlock(decimating->scheduler);
labcomm2014_scheduler_data_unlock(decimating->scheduler);
if (remote_index != 0 && amount != 0) {
enqueue_decimation(decimating, remote_index, amount);
}
}
return labcomm_reader_start(r, action_context->next,
return labcomm2014_reader_start(r, action_context->next,
local_index, remote_index, signature, value);
}
static int wrap_reader_ioctl(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
struct labcomm2014_reader *r,
struct labcomm2014_reader_action_context *action_context,
int local_index, int remote_index,
const struct labcomm_signature *signature,
const struct labcomm2014_signature *signature,
uint32_t action, va_list args)
{
struct decimating_private *decimating = action_context->context;
......@@ -147,26 +147,26 @@ static int wrap_reader_ioctl(
amount = va_arg(va, int);
va_end(va);
labcomm_scheduler_data_lock(decimating->scheduler);
labcomm2014_scheduler_data_lock(decimating->scheduler);
decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory,
decimating->reader_decimation,
int,
local_index);
*decimation = amount;
labcomm_scheduler_data_unlock(decimating->scheduler);
labcomm2014_scheduler_data_unlock(decimating->scheduler);
if (remote_index) {
enqueue_decimation(decimating, remote_index, amount);
}
} else {
return labcomm_reader_ioctl(r, action_context->next,
return labcomm2014_reader_ioctl(r, action_context->next,
local_index, remote_index, signature,
action, args);
}
return 0;
}
struct labcomm_reader_action decimating_reader_action = {
struct labcomm2014_reader_action decimating_reader_action = {
.alloc = wrap_reader_alloc,
.free = NULL,
.start = wrap_reader_start,
......@@ -179,25 +179,25 @@ static void register_signatures(void *context)
{
struct decimating_private *decimating = context;
labcomm_encoder_register_decimating_messages_set_decimation(
labcomm2014_encoder_register_decimating_messages_set_decimation(
decimating->decimating.writer->encoder);
}
static int wrap_writer_alloc(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context)
struct labcomm2014_writer *w,
struct labcomm2014_writer_action_context *action_context)
{
struct decimating_private *decimating = action_context->context;
labcomm_scheduler_enqueue(decimating->scheduler,
labcomm2014_scheduler_enqueue(decimating->scheduler,
0, register_signatures, decimating);
return labcomm_writer_alloc(w, action_context->next);
return labcomm2014_writer_alloc(w, action_context->next);
}
static int wrap_writer_start(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
int index, const struct labcomm_signature *signature,
struct labcomm2014_writer *w,
struct labcomm2014_writer_action_context *action_context,
int index, const struct labcomm2014_signature *signature,
void *value)
{
struct decimating_private *decimating = action_context->context;
......@@ -207,7 +207,7 @@ static int wrap_writer_start(
if (index < LABCOMM_USER) {
result = 0;
} else {
labcomm_scheduler_data_lock(decimating->scheduler);
labcomm2014_scheduler_data_lock(decimating->scheduler);
decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory,
decimating->writer_decimation,
struct decimation, index);
......@@ -218,16 +218,16 @@ static int wrap_writer_start(
decimation->current = 0;
result = 0;
}
labcomm_scheduler_data_unlock(decimating->scheduler);
labcomm2014_scheduler_data_unlock(decimating->scheduler);
}
if (result == 0) {
result = labcomm_writer_start(w, action_context->next,
result = labcomm2014_writer_start(w, action_context->next,
index, signature, value);
}
return result;
}
struct labcomm_writer_action decimating_writer_action = {
struct labcomm2014_writer_action decimating_writer_action = {
.alloc = wrap_writer_alloc,
.free = NULL,
.start = wrap_writer_start,
......@@ -237,11 +237,11 @@ struct labcomm_writer_action decimating_writer_action = {
};
struct decimating *decimating_new(
struct labcomm_reader *reader,
struct labcomm_writer *writer,
struct labcomm_error_handler *error,
struct labcomm_memory *memory,
struct labcomm_scheduler *scheduler)
struct labcomm2014_reader *reader,
struct labcomm2014_writer *writer,
struct labcomm2014_error_handler *error,
struct labcomm2014_memory *memory,
struct labcomm2014_scheduler *scheduler)
{
struct decimating_private *result;
......
#ifndef __DECIMATING_H__
#define __DECIMATING_H__
#include <labcomm.h>
#include <labcomm_ioctl.h>
#include <labcomm2014.h>
#include <labcomm2014_ioctl.h>
struct decimating {
struct labcomm_reader *reader;
struct labcomm_writer *writer;
struct labcomm2014_reader *reader;
struct labcomm2014_writer *writer;
};
extern struct decimating *decimating_new(
struct labcomm_reader *reader,
struct labcomm_writer *writer,
struct labcomm_error_handler *error,
struct labcomm_memory *memory,
struct labcomm_scheduler *scheduler);
struct labcomm2014_reader *reader,
struct labcomm2014_writer *writer,
struct labcomm2014_error_handler *error,
struct labcomm2014_memory *memory,
struct labcomm2014_scheduler *scheduler);
#define SET_DECIMATION LABCOMM_IOSW('d',0,int)
......
......@@ -23,18 +23,18 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "labcomm_private.h"
#include "labcomm2014_private.h"
#include "introspecting.h"
#include "gen/introspecting_messages.h"
struct introspecting_private {
struct introspecting introspecting;
struct labcomm_error_handler *error;
struct labcomm_memory *memory;
struct labcomm_scheduler *scheduler;
struct labcomm2014_error_handler *error;
struct labcomm2014_memory *memory;
struct labcomm2014_scheduler *scheduler;
struct labcomm_reader_action_context reader_action_context;
struct labcomm_writer_action_context writer_action_context;
struct labcomm2014_reader_action_context reader_action_context;
struct labcomm2014_writer_action_context writer_action_context;
LABCOMM_SIGNATURE_ARRAY_DEF(remote,
struct remote {
char *name;
......@@ -44,13 +44,13 @@ struct introspecting_private {
LABCOMM_SIGNATURE_ARRAY_DEF(local,
struct local {
enum introspecting_status status;
const struct labcomm_signature *signature;
const struct labcomm2014_signature *signature;