summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Dritschler <timo.dritschler@kit.edu>2014-08-29 14:06:44 +0200
committerTimo Dritschler <timo.dritschler@kit.edu>2014-08-29 14:06:44 +0200
commit4dff7a9ffb8355100482c9955bbb6889fe237bb4 (patch)
tree8f3dd0838b9485daa0037c3e3227363f276b489f
parentfc283a62d93fb5705cc955919ee109b2e915f912 (diff)
downloadkiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.tar.gz
kiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.tar.bz2
kiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.tar.xz
kiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.zip
Fix #6: Changed coding style to match UFO Project
-rw-r--r--src/kiro-client.c228
-rw-r--r--src/kiro-client.h20
-rw-r--r--src/kiro-rdma.h188
-rw-r--r--src/kiro-server.c341
-rw-r--r--src/kiro-server.h14
-rw-r--r--src/kiro-trb.c226
-rw-r--r--src/kiro-trb.h68
-rw-r--r--test/test-client.c109
-rw-r--r--test/test-server.c179
-rw-r--r--test/test.c44
10 files changed, 742 insertions, 675 deletions
diff --git a/src/kiro-client.c b/src/kiro-client.c
index 1fd7860..b930595 100644
--- a/src/kiro-client.c
+++ b/src/kiro-client.c
@@ -53,23 +53,25 @@ struct _KiroClientPrivate {
/* (Not accessible by properties) */
struct rdma_event_channel *ec; // Main Event Channel
struct rdma_cm_id *conn; // Connection to the Server
-
+
};
G_DEFINE_TYPE (KiroClient, kiro_client, G_TYPE_OBJECT);
-KiroClient*
-kiro_client_new (void) {
+KiroClient *
+kiro_client_new (void)
+{
return g_object_new (KIRO_TYPE_CLIENT, NULL);
}
-static void kiro_client_init (KiroClient *self)
+static void
+kiro_client_init (KiroClient *self)
{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
- memset(priv, 0, sizeof(&priv));
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
+ memset (priv, 0, sizeof (&priv));
}
static void
@@ -83,177 +85,183 @@ kiro_client_finalize (GObject *object)
static void
kiro_client_class_init (KiroClientClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = kiro_client_finalize;
- g_type_class_add_private(klass, sizeof(KiroClientPrivate));
+ g_type_class_add_private (klass, sizeof (KiroClientPrivate));
}
-int kiro_client_connect (KiroClient *self, char *address, char* port)
+int
+kiro_client_connect (KiroClient *self, char *address, char *port)
{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
- if(priv->conn)
- {
- printf("Already connected to server.\n");
+ if (priv->conn) {
+ printf ("Already connected to server.\n");
return -1;
}
-
+
struct rdma_addrinfo hints, *res_addrinfo;
- memset(&hints, 0, sizeof(hints));
+
+ memset (&hints, 0, sizeof (hints));
+
hints.ai_port_space = RDMA_PS_IB;
- if(rdma_getaddrinfo(address, port, &hints, &res_addrinfo))
- {
- printf("Failed to contruct address information for %s:%s\n",address, port);
+
+ if (rdma_getaddrinfo (address, port, &hints, &res_addrinfo)) {
+ printf ("Failed to contruct address information for %s:%s\n", address, port);
return -1;
}
- printf("Address information created.\n");
-
+
+ printf ("Address information created.\n");
struct ibv_qp_init_attr qp_attr;
- memset(&qp_attr, 0, sizeof(qp_attr));
+ memset (&qp_attr, 0, sizeof (qp_attr));
qp_attr.cap.max_send_wr = 10;
qp_attr.cap.max_recv_wr = 10;
qp_attr.cap.max_send_sge = 1;
qp_attr.cap.max_recv_sge = 1;
qp_attr.qp_context = priv->conn;
qp_attr.sq_sig_all = 1;
-
- if(rdma_create_ep(&(priv->conn), res_addrinfo, NULL, &qp_attr))
- {
- printf("Endpoint creation failed with error: %i\n", errno);
+
+ if (rdma_create_ep (& (priv->conn), res_addrinfo, NULL, &qp_attr)) {
+ printf ("Endpoint creation failed with error: %i\n", errno);
return -1;
}
- printf("Route to server resolved.\n");
-
- struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc(1,sizeof(struct kiro_connection_context));
- if(!ctx)
- {
- printf("Failed to create connection context.\n");
- rdma_destroy_ep(priv->conn);
+
+ printf ("Route to server resolved.\n");
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc (1, sizeof (struct kiro_connection_context));
+
+ if (!ctx) {
+ printf ("Failed to create connection context.\n");
+ rdma_destroy_ep (priv->conn);
return -1;
}
-
- ctx->cf_mr_send = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
- ctx->cf_mr_recv = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
- if(!ctx->cf_mr_recv || !ctx->cf_mr_send)
- {
- printf("Failed to allocate Control Flow Memory Container.\n");
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ ctx->cf_mr_send = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
+ ctx->cf_mr_recv = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
+
+ if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
+ printf ("Failed to allocate Control Flow Memory Container.\n");
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
-
- ctx->cf_mr_recv = kiro_create_rdma_memory(priv->conn->pd, sizeof(struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
- ctx->cf_mr_send = kiro_create_rdma_memory(priv->conn->pd, sizeof(struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
- if(!ctx->cf_mr_recv || !ctx->cf_mr_send)
- {
- printf("Failed to register control message memory.\n");
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ ctx->cf_mr_recv = kiro_create_rdma_memory (priv->conn->pd, sizeof (struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
+ ctx->cf_mr_send = kiro_create_rdma_memory (priv->conn->pd, sizeof (struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
+
+ if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
+ printf ("Failed to register control message memory.\n");
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
- ctx->cf_mr_recv->size = ctx->cf_mr_send->size = sizeof(struct kiro_ctrl_msg);
+
+ ctx->cf_mr_recv->size = ctx->cf_mr_send->size = sizeof (struct kiro_ctrl_msg);
priv->conn->context = ctx;
-
- if(rdma_post_recv(priv->conn, priv->conn, ctx->cf_mr_recv->mem, ctx->cf_mr_recv->size, ctx->cf_mr_recv->mr))
- {
- printf("Posting preemtive receive for connection failed with error: %i\n", errno);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_post_recv (priv->conn, priv->conn, ctx->cf_mr_recv->mem, ctx->cf_mr_recv->size, ctx->cf_mr_recv->mr)) {
+ printf ("Posting preemtive receive for connection failed with error: %i\n", errno);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
-
- if(rdma_connect(priv->conn, NULL))
- {
- printf("Failed to establish connection to the server.\n");
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_connect (priv->conn, NULL)) {
+ printf ("Failed to establish connection to the server.\n");
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
- printf("Connected to server.\n");
-
-
+
+ printf ("Connected to server.\n");
struct ibv_wc wc;
- if(rdma_get_recv_comp(priv->conn, &wc) < 0)
- {
- printf("Failure waiting for POST from server.\n");
- rdma_disconnect(priv->conn);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_get_recv_comp (priv->conn, &wc) < 0) {
+ printf ("Failure waiting for POST from server.\n");
+ rdma_disconnect (priv->conn);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
- printf("Got Message from Server.\n");
- ctx->peer_mr = (((struct kiro_ctrl_msg *)(ctx->cf_mr_recv->mem))->peer_mri);
- printf("Expected Memory Size is: %u\n",ctx->peer_mr.length);
-
- ctx->rdma_mr = kiro_create_rdma_memory(priv->conn->pd, ctx->peer_mr.length, IBV_ACCESS_LOCAL_WRITE);
- if(!ctx->rdma_mr)
- {
- printf("Failed to allocate memory for receive buffer.\n");
- rdma_disconnect(priv->conn);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ printf ("Got Message from Server.\n");
+ ctx->peer_mr = (((struct kiro_ctrl_msg *) (ctx->cf_mr_recv->mem))->peer_mri);
+ printf ("Expected Memory Size is: %u\n", ctx->peer_mr.length);
+ ctx->rdma_mr = kiro_create_rdma_memory (priv->conn->pd, ctx->peer_mr.length, IBV_ACCESS_LOCAL_WRITE);
+
+ if (!ctx->rdma_mr) {
+ printf ("Failed to allocate memory for receive buffer.\n");
+ rdma_disconnect (priv->conn);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
- printf("Connection setup completed successfully!\n");
-
+
+ printf ("Connection setup completed successfully!\n");
return 0;
}
-int kiro_client_sync (KiroClient *self)
-{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
+int
+kiro_client_sync (KiroClient *self)
+{
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
struct kiro_connection_context *ctx = (struct kiro_connection_context *)priv->conn->context;
-
- if(rdma_post_read(priv->conn, priv->conn, ctx->rdma_mr->mem, ctx->peer_mr.length, ctx->rdma_mr->mr, 0, ctx->peer_mr.addr, ctx->peer_mr.rkey))
- {
- printf("Failed to read from server.\n");
- rdma_disconnect(priv->conn);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_post_read (priv->conn, priv->conn, ctx->rdma_mr->mem, ctx->peer_mr.length, ctx->rdma_mr->mr, 0, ctx->peer_mr.addr, ctx->peer_mr.rkey)) {
+ printf ("Failed to read from server.\n");
+ rdma_disconnect (priv->conn);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
-
+
struct ibv_wc wc;
- if(rdma_get_send_comp(priv->conn, &wc) < 0)
- {
- printf("Failure reading from server.\n");
- rdma_disconnect(priv->conn);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_get_send_comp (priv->conn, &wc) < 0) {
+ printf ("Failure reading from server.\n");
+ rdma_disconnect (priv->conn);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
+
return 0;
}
-void* kiro_client_get_memory (KiroClient *self)
+void *
+kiro_client_get_memory (KiroClient *self)
{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
- if(!priv->conn)
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
+
+ if (!priv->conn)
return NULL;
struct kiro_connection_context *ctx = (struct kiro_connection_context *)priv->conn->context;
- if(!ctx->rdma_mr)
+
+ if (!ctx->rdma_mr)
return NULL;
-
+
return ctx->rdma_mr->mem;
}
-size_t kiro_client_get_memory_size (KiroClient *self)
+size_t
+kiro_client_get_memory_size (KiroClient *self)
{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
- if(!priv->conn)
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
+
+ if (!priv->conn)
return 0;
struct kiro_connection_context *ctx = (struct kiro_connection_context *)priv->conn->context;
- if(!ctx->rdma_mr)
+
+ if (!ctx->rdma_mr)
return 0;
-
+
return ctx->rdma_mr->size;
}
diff --git a/src/kiro-client.h b/src/kiro-client.h
index fc98b3f..146845b 100644
--- a/src/kiro-client.h
+++ b/src/kiro-client.h
@@ -24,7 +24,7 @@
* KiroClient implements the client / active / consumer side of the the RDMA
* Communication Channel. It uses a KIRO-CLIENT to manage data read from the Server.
*/
-
+
#ifndef __KIRO_CLIENT_H
#define __KIRO_CLIENT_H
@@ -47,9 +47,9 @@ typedef struct _KiroClientPrivate KiroClientPrivate;
struct _KiroClient {
-
+
GObject parent;
-
+
/*< private >*/
KiroClientPrivate *priv;
};
@@ -62,9 +62,9 @@ struct _KiroClient {
*/
struct _KiroClientClass {
-
+
GObjectClass parent_class;
-
+
};
@@ -72,18 +72,18 @@ struct _KiroClientClass {
/* GObject and GType functions */
GType kiro_client_get_type (void);
-KiroClient* kiro_client_new (void);
+KiroClient *kiro_client_new (void);
/* client functions */
-int kiro_client_connect (KiroClient* client, char* dest_addr, char* dest_port);
+int kiro_client_connect (KiroClient *client, char *dest_addr, char *dest_port);
-int kiro_client_sync (KiroClient* client);
+int kiro_client_sync (KiroClient *client);
-void* kiro_client_get_memory (KiroClient* client);
+void *kiro_client_get_memory (KiroClient *client);
-size_t kior_client_get_memory_size (KiroClient* client);
+size_t kior_client_get_memory_size (KiroClient *client);
G_END_DECLS
diff --git a/src/kiro-rdma.h b/src/kiro-rdma.h
index 8779b2e..2ebbcf6 100644
--- a/src/kiro-rdma.h
+++ b/src/kiro-rdma.h
@@ -25,9 +25,9 @@
#include <rdma/rdma_cma.h>
-
+
struct kiro_connection_context {
-
+
// Information and necessary structurs
uint32_t identifier; // Unique Identifier for this connection (Application Specific)
struct kiro_rdma_mem *cf_mr_recv; // Control-Flow Memory Region Receive
@@ -35,52 +35,52 @@ struct kiro_connection_context {
struct kiro_rdma_mem *rdma_mr; // Memory Region for RDMA Operations
struct ibv_mr peer_mr; // RDMA Memory Region Information of the peer
-
+
enum {
KIRO_IDLE,
KIRO_MRI_REQUESTED, // Memory Region Information Requested
KIRO_RDMA_ESTABLISHED, // MRI Exchange complete. RDMA is ready
KIRO_RDMA_ACTIVE // RDMA Operation is being performed
} rdma_state;
-
+
};
struct kiro_ctrl_msg {
-
+
enum {
KIRO_REQ_RDMA, // Requesting RDMA Access to/from the peer
KIRO_ACK_RDMA, // acknowledge RDMA Request and provide Memory Region Information
KIRO_REJ_RDMA // RDMA Request rejected :( (peer_mri will be invalid)
} msg_type;
-
+
struct ibv_mr peer_mri;
-
+
};
struct kiro_rdma_mem {
-
- void *mem; // Pointer to the beginning of the memory block
+
+ void *mem; // Pointer to the beginning of the memory block
struct ibv_mr *mr; // Memory Region associated with the memory
size_t size; // Size in Bytes of the memory block
};
-static int kiro_attach_qp (struct rdma_cm_id *id)
+static int
+kiro_attach_qp (struct rdma_cm_id *id)
{
- if(!id)
+ if (!id)
return -1;
-
- id->pd = ibv_alloc_pd(id->verbs);
- id->send_cq_channel = ibv_create_comp_channel(id->verbs);
+
+ id->pd = ibv_alloc_pd (id->verbs);
+ id->send_cq_channel = ibv_create_comp_channel (id->verbs);
id->recv_cq_channel = id->send_cq_channel; //we use one shared completion channel
- id->send_cq = ibv_create_cq(id->verbs, 1, id, id->send_cq_channel, 0);
+ id->send_cq = ibv_create_cq (id->verbs, 1, id, id->send_cq_channel, 0);
id->recv_cq = id->send_cq; //we use one shared completion queue
-
struct ibv_qp_init_attr qp_attr;
- memset(&qp_attr, 0, sizeof(struct ibv_qp_init_attr));
+ memset (&qp_attr, 0, sizeof (struct ibv_qp_init_attr));
qp_attr.qp_context = (uintptr_t)id;
qp_attr.send_cq = id->send_cq;
qp_attr.recv_cq = id->recv_cq;
@@ -89,131 +89,129 @@ static int kiro_attach_qp (struct rdma_cm_id *id)
qp_attr.cap.max_recv_wr = 1;
qp_attr.cap.max_send_sge = 1;
qp_attr.cap.max_recv_sge = 1;
-
- return rdma_create_qp(id, id->pd, &qp_attr);
+ return rdma_create_qp (id, id->pd, &qp_attr);
}
-static int kiro_register_rdma_memory (struct ibv_pd *pd, struct ibv_mr **mr, void *mem, size_t mem_size, int access)
+static int
+kiro_register_rdma_memory (struct ibv_pd *pd, struct ibv_mr **mr, void *mem, size_t mem_size, int access)
{
-
- if(mem_size == 0)
- {
- printf("Cant allocate memory of size '0'.\n");
+ if (mem_size == 0) {
+ printf ("Cant allocate memory of size '0'.\n");
return -1;
}
-
+
void *mem_handle = mem;
-
- if(!mem_handle)
- mem_handle = malloc(mem_size);
-
- if(!mem_handle)
- {
- printf("Failed to allocate memory [Register Memory].");
+
+ if (!mem_handle)
+ mem_handle = malloc (mem_size);
+
+ if (!mem_handle) {
+ printf ("Failed to allocate memory [Register Memory].");
return -1;
- }
-
- *mr = ibv_reg_mr(pd, mem_handle, mem_size, access);
- if(!(*mr))
- {
+ }
+
+ *mr = ibv_reg_mr (pd, mem_handle, mem_size, access);
+
+ if (! (*mr)) {
// Memory Registration failed
- printf("Failed to register memory region!\n");
- free(mem_handle);
+ printf ("Failed to register memory region!\n");
+ free (mem_handle);
return -1;
}
-
+
return 0;
}
-static struct kiro_rdma_mem* kiro_create_rdma_memory (struct ibv_pd *pd, size_t mem_size, int access)
+static struct kiro_rdma_mem *
+kiro_create_rdma_memory (struct ibv_pd *pd, size_t mem_size, int access)
{
- if(mem_size == 0)
- {
- printf("Cant allocate memory of size '0'.\n");
+ if (mem_size == 0) {
+ printf ("Cant allocate memory of size '0'.\n");
return NULL;
}
-
- struct kiro_rdma_mem *krm = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
- if(!krm)
- {
- printf("Failed to create new KIRO RDMA Memory.\n");
+
+ struct kiro_rdma_mem *krm = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
+
+ if (!krm) {
+ printf ("Failed to create new KIRO RDMA Memory.\n");
return NULL;
}
-
- if(kiro_register_rdma_memory(pd, &(krm->mr), krm->mem, mem_size, access))
- {
- free(krm);
+
+ if (kiro_register_rdma_memory (pd, & (krm->mr), krm->mem, mem_size, access)) {
+ free (krm);
return NULL;
}
-
- if(!krm->mem)
+
+ if (!krm->mem)
krm->mem = krm->mr->addr;
-
-
+
return krm;
-
}
-static void kiro_destroy_rdma_memory (struct kiro_rdma_mem *krm)
+static void
+kiro_destroy_rdma_memory (struct kiro_rdma_mem *krm)
{
- if(!krm)
+ if (!krm)
return;
-
- if(krm->mr)
- ibv_dereg_mr(krm->mr);
-
- if(krm->mem)
- free(krm->mem);
-
- free(krm);
+
+ if (krm->mr)
+ ibv_dereg_mr (krm->mr);
+
+ if (krm->mem)
+ free (krm->mem);
+
+ free (krm);
krm = NULL;
}
-static void kiro_destroy_connection_context (struct kiro_connection_context **ctx)
+static void
+kiro_destroy_connection_context (struct kiro_connection_context **ctx)
{
- if(!ctx)
+ if (!ctx)
return;
-
- if(!(*ctx))
+
+ if (! (*ctx))
return;
-
- if((*ctx)->cf_mr_recv)
- kiro_destroy_rdma_memory((*ctx)->cf_mr_recv);
- if((*ctx)->cf_mr_send)
- kiro_destroy_rdma_memory((*ctx)->cf_mr_send);
-
+
+ if ((*ctx)->cf_mr_recv)
+ kiro_destroy_rdma_memory ((*ctx)->cf_mr_recv);
+
+ if ((*ctx)->cf_mr_send)
+ kiro_destroy_rdma_memory ((*ctx)->cf_mr_send);
+
//The RDMA-Memory Region normally contains allocated memory from the USER that has
//just been 'registered' for RDMA. DON'T free it! Just deregister it. The user is
- //responsible for freeing this memory.
- if((*ctx)->rdma_mr)
- {
- if((*ctx)->rdma_mr->mr)
- ibv_dereg_mr((*ctx)->rdma_mr->mr);
-
- free((*ctx)->rdma_mr);
+ //responsible for freeing this memory.
+ if ((*ctx)->rdma_mr) {
+ if ((*ctx)->rdma_mr->mr)
+ ibv_dereg_mr ((*ctx)->rdma_mr->mr);
+
+ free ((*ctx)->rdma_mr);
(*ctx)->rdma_mr = NULL;
}
- free(*ctx);
+ free (*ctx);
*ctx = NULL;
}
-static void kiro_destroy_connection (struct rdma_cm_id **conn)
+static void
+kiro_destroy_connection (struct rdma_cm_id **conn)
{
- if(!(*conn))
+ if (! (*conn))
return;
-
- rdma_disconnect(*conn);
- struct kiro_connection_context *ctx = (struct kiro_connection_context *)((*conn)->context);
- if(ctx)
- kiro_destroy_connection_context(&ctx);
-
- rdma_destroy_ep(*conn);
+
+ rdma_disconnect (*conn);
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *) ((*conn)->context);
+
+ if (ctx)
+ kiro_destroy_connection_context (&ctx);
+
+ rdma_destroy_ep (*conn);
*conn = NULL;
}
diff --git a/src/kiro-server.c b/src/kiro-server.c
index 15a8ccb..c69b6e7 100644
--- a/src/kiro-server.c
+++ b/src/kiro-server.c
@@ -65,265 +65,261 @@ struct _KiroServerPrivate {
G_DEFINE_TYPE (KiroServer, kiro_server, G_TYPE_OBJECT);
-KiroServer*
-kiro_server_new (void) {
+KiroServer *
+kiro_server_new (void)
+{
return g_object_new (KIRO_TYPE_SERVER, NULL);
}
-static void kiro_server_init (KiroServer *self)
+static void
+kiro_server_init (KiroServer *self)
{
- KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE(self);
- memset(priv, 0, sizeof(&priv));
+ KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE (self);
+ memset (priv, 0, sizeof (&priv));
}
static void
kiro_server_finalize (GObject *object)
{
- KiroServer *self = KIRO_SERVER(object);
-
+ KiroServer *self = KIRO_SERVER (object);
//Clean up the server
- kiro_server_stop(self);
+ kiro_server_stop (self);
}
static void
kiro_server_class_init (KiroServerClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = kiro_server_finalize;
- g_type_class_add_private(klass, sizeof(KiroServerPrivate));
+ g_type_class_add_private (klass, sizeof (KiroServerPrivate));
}
-static int connect_client (struct rdma_cm_id *client)
+static int
+connect_client (struct rdma_cm_id *client)
{
- if(!client)
+ if (!client)
return -1;
-
- if( -1 == kiro_attach_qp(client))
- {
- printf("Could not create a QP for the new connection.\n");
- rdma_destroy_id(client);
+
+ if ( -1 == kiro_attach_qp (client)) {
+ printf ("Could not create a QP for the new connection.\n");
+ rdma_destroy_id (client);
return -1;
}
-
- struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc(1,sizeof(struct kiro_connection_context));
- if(!ctx)
- {
- printf("Failed to create connection context.\n");
- rdma_destroy_id(client);
+
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc (1, sizeof (struct kiro_connection_context));
+
+ if (!ctx) {
+ printf ("Failed to create connection context.\n");
+ rdma_destroy_id (client);
return -1;
}
-
- ctx->cf_mr_send = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
- ctx->cf_mr_recv = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
- if(!ctx->cf_mr_recv || !ctx->cf_mr_send)
- {
- printf("Failed to allocate Control Flow Memory Container.\n");
+
+ ctx->cf_mr_send = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
+ ctx->cf_mr_recv = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
+
+ if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
+ printf ("Failed to allocate Control Flow Memory Container.\n");
goto error;
}
-
- ctx->cf_mr_recv = kiro_create_rdma_memory(client->pd, sizeof(struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
- ctx->cf_mr_send = kiro_create_rdma_memory(client->pd, sizeof(struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
- if(!ctx->cf_mr_recv || !ctx->cf_mr_send)
- {
- printf("Failed to register control message memory.\n");
+
+ ctx->cf_mr_recv = kiro_create_rdma_memory (client->pd, sizeof (struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
+ ctx->cf_mr_send = kiro_create_rdma_memory (client->pd, sizeof (struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
+
+ if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
+ printf ("Failed to register control message memory.\n");
goto error;
}
- ctx->cf_mr_recv->size = ctx->cf_mr_send->size = sizeof(struct kiro_ctrl_msg);
+
+ ctx->cf_mr_recv->size = ctx->cf_mr_send->size = sizeof (struct kiro_ctrl_msg);
client->context = ctx;
-
- if(rdma_post_recv(client, client, ctx->cf_mr_recv->mem, ctx->cf_mr_recv->size, ctx->cf_mr_recv->mr))
- {
- printf("Posting preemtive receive for connection failed.\n");
+
+ if (rdma_post_recv (client, client, ctx->cf_mr_recv->mem, ctx->cf_mr_recv->size, ctx->cf_mr_recv->mr)) {
+ printf ("Posting preemtive receive for connection failed.\n");
goto error;
}
-
- if(rdma_accept(client, NULL))
- {
- printf("Failed to establish connection to the client with error: %i.\n", errno);
+
+ if (rdma_accept (client, NULL)) {
+ printf ("Failed to establish connection to the client with error: %i.\n", errno);
goto error;
}
- printf("Client Connected.\n");
- return 0;
-
+ printf ("Client Connected.\n");
+ return 0;
error:
- rdma_reject(client, NULL, 0);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_id(client);
+ rdma_reject (client, NULL, 0);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_id (client);
return -1;
}
-static int welcome_client (struct rdma_cm_id *client, void *mem, size_t mem_size)
+static int
+welcome_client (struct rdma_cm_id *client, void *mem, size_t mem_size)
{
- struct kiro_connection_context *ctx = (struct kiro_connection_context *)(client->context);
- ctx->rdma_mr = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
- if(!ctx->rdma_mr)
- {
- printf("Failed to allocate RDMA Memory Container.\n");
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *) (client->context);
+ ctx->rdma_mr = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
+
+ if (!ctx->rdma_mr) {
+ printf ("Failed to allocate RDMA Memory Container.\n");
return -1;
}
-
+
ctx->rdma_mr->mem = mem;
ctx->rdma_mr->size = mem_size;
- ctx->rdma_mr->mr = rdma_reg_read(client, ctx->rdma_mr->mem, ctx->rdma_mr->size);
- if(!ctx->rdma_mr->mr)
- {
- printf("Failed to register RDMA Memory Region.\n");
- kiro_destroy_rdma_memory(ctx->rdma_mr);
+ ctx->rdma_mr->mr = rdma_reg_read (client, ctx->rdma_mr->mem, ctx->rdma_mr->size);
+
+ if (!ctx->rdma_mr->mr) {
+ printf ("Failed to register RDMA Memory Region.\n");
+ kiro_destroy_rdma_memory (ctx->rdma_mr);
return -1;
}
-
- struct kiro_ctrl_msg *msg = (struct kiro_ctrl_msg *)(ctx->cf_mr_send->mem);
+
+ struct kiro_ctrl_msg *msg = (struct kiro_ctrl_msg *) (ctx->cf_mr_send->mem);
+
msg->msg_type = KIRO_ACK_RDMA;
- msg->peer_mri = *(ctx->rdma_mr->mr);
-
- if(rdma_post_send(client, client, ctx->cf_mr_send->mem, ctx->cf_mr_send->size, ctx->cf_mr_send->mr, IBV_SEND_SIGNALED))
- {
- printf("Failure while trying to post SEND.\n");
- kiro_destroy_rdma_memory(ctx->rdma_mr);
+
+ msg->peer_mri = * (ctx->rdma_mr->mr);
+
+ if (rdma_post_send (client, client, ctx->cf_mr_send->mem, ctx->cf_mr_send->size, ctx->cf_mr_send->mr, IBV_SEND_SIGNALED)) {
+ printf ("Failure while trying to post SEND.\n");
+ kiro_destroy_rdma_memory (ctx->rdma_mr);
return -1;
}
-
+
struct ibv_wc wc;
-
- if(rdma_get_send_comp(client, &wc) < 0)
- {
- printf("Failed to post RDMA MRI to client.\n");
- kiro_destroy_rdma_memory(ctx->rdma_mr);
+
+ if (rdma_get_send_comp (client, &wc) < 0) {
+ printf ("Failed to post RDMA MRI to client.\n");
+ kiro_destroy_rdma_memory (ctx->rdma_mr);
return -1;
}
- printf("RDMA MRI sent to client.\n");
+ printf ("RDMA MRI sent to client.\n");
return 0;
}
-void * event_loop (void *self)
+void *
+event_loop (void *self)
{
- KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE((KiroServer *)self);
+ KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE ((KiroServer *)self);
struct rdma_cm_event *active_event;
- while(0 == priv->close_signal) {
- if(0 <= rdma_get_cm_event(priv->ec, &active_event))
- {
+ while (0 == priv->close_signal) {
+ if (0 <= rdma_get_cm_event (priv->ec, &active_event)) {
//Disable cancellation to prevent undefined states during shutdown
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
-
- struct rdma_cm_event *ev = malloc(sizeof(*active_event));
- if(!ev)
- {
- printf("Unable to allocate memory for Event handling!\n");
- rdma_ack_cm_event(active_event);
+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
+ struct rdma_cm_event *ev = malloc (sizeof (*active_event));
+
+ if (!ev) {
+ printf ("Unable to allocate memory for Event handling!\n");
+ rdma_ack_cm_event (active_event);
continue;
}
- memcpy(ev, active_event, sizeof(*active_event));
- rdma_ack_cm_event(active_event);
-
- if (ev->event == RDMA_CM_EVENT_CONNECT_REQUEST)
- {
-
- if (0 != priv->close_signal)
- {
+
+ memcpy (ev, active_event, sizeof (*active_event));
+ rdma_ack_cm_event (active_event);
+
+ if (ev->event == RDMA_CM_EVENT_CONNECT_REQUEST) {
+ if (0 != priv->close_signal) {
//Main thread has signalled shutdown!
- //Don't connect this client any more
+ //Don't connect this client any more.
//Sorry mate!
- rdma_reject(ev->id, NULL, 0);
+ rdma_reject (ev->id, NULL, 0);
}
-
- if(0 == connect_client(ev->id)) {
+
+ if (0 == connect_client (ev->id)) {
// Post a welcoming "Recieve" for handshaking
- if (0 == welcome_client(ev->id, priv->mem, priv->mem_size)) {
+ if (0 == welcome_client (ev->id, priv->mem, priv->mem_size)) {
// Connection set-up successfully! (Server)
- struct kiro_connection_context *ctx = (struct kiro_connection_context *)(ev->id->context);
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *) (ev->id->context);
ctx->identifier = priv->next_client_id++;
priv->clients = g_list_append (priv->clients, (gpointer)ev->id);
- printf("Client id %u connected\n", ctx->identifier);
- printf("Currently %u clients in total are connected.\n", g_list_length (priv->clients));
+ printf ("Client id %u connected\n", ctx->identifier);
+ printf ("Currently %u clients in total are connected.\n", g_list_length (priv->clients));
}
}
}
- else if(ev->event == RDMA_CM_EVENT_DISCONNECTED)
- {
+ else if (ev->event == RDMA_CM_EVENT_DISCONNECTED) {
GList *client = g_list_find (priv->clients, (gconstpointer) ev->id);
+
if (client) {
- struct kiro_connection_context *ctx = (struct kiro_connection_context *)(ev->id->context);
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *) (ev->id->context);
printf ("Got disconnect request from client %u.\n", ctx->identifier);
priv->clients = g_list_delete_link (priv->clients, client);
}
else
- printf("Got disconnect request from unknown client.\n");
+ printf ("Got disconnect request from unknown client.\n");
- kiro_destroy_connection(&(ev->id));
- printf("Connection closed successfully. %u connected clients remaining.\n", g_list_length (priv->clients));
- }
- free(ev);
+ kiro_destroy_connection (& (ev->id));
+ printf ("Connection closed successfully. %u connected clients remaining.\n", g_list_length (priv->clients));
+ }
+
+ free (ev);
}
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+
+ pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
}
- printf("Closing Event Listener Thread\n");
+ printf ("Closing Event Listener Thread\n");
return NULL;
}
-int kiro_server_start (KiroServer *self, char *address, char *port, void* mem, size_t mem_size)
+int
+kiro_server_start (KiroServer *self, char *address, char *port, void *mem, size_t mem_size)
{
- KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE(self);
+ KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE (self);
- if(priv->base)
- {
- printf("Server already started.\n");
+ if (priv->base) {
+ printf ("Server already started.\n");
return -1;
}
-
- if(!mem || mem_size == 0)
- {
- printf("Invalid memory given to provide.\n");
+
+ if (!mem || mem_size == 0) {
+ printf ("Invalid memory given to provide.\n");
return -1;
}
-
+
struct rdma_addrinfo hints, *res_addrinfo;
- memset(&hints, 0, sizeof(hints));
+ memset (&hints, 0, sizeof (hints));
hints.ai_port_space = RDMA_PS_IB;
hints.ai_flags = RAI_PASSIVE;
- if(rdma_getaddrinfo(address, port, &hints, &res_addrinfo))
- {
- printf("Failed to create address information.");
+
+ if (rdma_getaddrinfo (address, port, &hints, &res_addrinfo)) {
+ printf ("Failed to create address information.");
return -1;
}
-
+
struct ibv_qp_init_attr qp_attr;
- memset(&qp_attr, 0, sizeof(qp_attr));
+ memset (&qp_attr, 0, sizeof (qp_attr));
qp_attr.cap.max_send_wr = 10;
qp_attr.cap.max_recv_wr = 10;
qp_attr.cap.max_send_sge = 1;
qp_attr.cap.max_recv_sge = 1;
qp_attr.qp_context = priv->base;
qp_attr.sq_sig_all = 1;
-
- if(rdma_create_ep(&(priv->base), res_addrinfo, NULL, &qp_attr))
- {
- printf("Endpoint creation failed: %s.\n", strerror (errno));
+
+ if (rdma_create_ep (& (priv->base), res_addrinfo, NULL, &qp_attr)) {
+ printf ("Endpoint creation failed: %s.\n", strerror (errno));
return -1;
}
- printf("Endpoint created.\n");
-
+
+ printf ("Endpoint created.\n");
char *addr_local = NULL;
- struct sockaddr* src_addr = rdma_get_local_addr(priv->base);
- if(!src_addr)
- {
+ struct sockaddr *src_addr = rdma_get_local_addr (priv->base);
+
+ if (!src_addr) {
addr_local = "NONE";
}
- else
- {
- addr_local = inet_ntoa(((struct sockaddr_in *)src_addr)->sin_addr);
+ else {
+ addr_local = inet_ntoa (((struct sockaddr_in *)src_addr)->sin_addr);
/*
if(src_addr->sa_family == AF_INET)
addr_local = &(((struct sockaddr_in*)src_addr)->sin_addr);
@@ -331,32 +327,28 @@ int kiro_server_start (KiroServer *self, char *address, char *port, void* mem, s
addr_local = &(((struct sockaddr_in6*)src_addr)->sin6_addr);
*/
}
-
- printf("Bound to address %s:%s\n",addr_local, port);
-
- if(rdma_listen(priv->base, 0))
- {
- printf("Failed to put server into listening state.\n");
- rdma_destroy_ep(priv->base);
+
+ printf ("Bound to address %s:%s\n", addr_local, port);
+
+ if (rdma_listen (priv->base, 0)) {
+ printf ("Failed to put server into listening state.\n");
+ rdma_destroy_ep (priv->base);
return -1;
}
-
+
priv->mem = mem;
priv->mem_size = mem_size;
+ priv->ec = rdma_create_event_channel();
- priv->ec = rdma_create_event_channel();
- if(rdma_migrate_id(priv->base, priv->ec))
- {
- printf("Was unable to migrate connection to new Event Channel.\n");
- rdma_destroy_ep(priv->base);
+ if (rdma_migrate_id (priv->base, priv->ec)) {
+ printf ("Was unable to migrate connection to new Event Channel.\n");
+ rdma_destroy_ep (priv->base);
return -1;
}
- pthread_create(&(priv->event_listener), NULL, event_loop, self);
-
- printf("Enpoint listening.\n");
-
- sleep(1);
+ pthread_create (& (priv->event_listener), NULL, event_loop, self);
+ printf ("Enpoint listening.\n");
+ sleep (1);
return 0;
}
@@ -366,7 +358,7 @@ disconnect_client (gpointer data, gpointer user_data)
{
if (data) {
struct rdma_cm_id *id = (struct rdma_cm_id *)data;
- struct kiro_connection_context *ctx = (struct kiro_connection_context *)(id->context);
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *) (id->context);
printf ("Disconnecting client: %u.\n", ctx->identifier);
rdma_disconnect ((struct rdma_cm_id *) data);
}
@@ -376,30 +368,29 @@ disconnect_client (gpointer data, gpointer user_data)
void
kiro_server_stop (KiroServer *self)
{
- if(!self)
+ if (!self)
return;
-
+
KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE (self);
-
- if(!priv->base)
+
+ if (!priv->base)
return;
-
+
//Shut down the listener-thread
priv->close_signal = 1;
- pthread_cancel(priv->event_listener);
- pthread_join(priv->event_listener, NULL);
- printf("Event Listener Thread stopped.\n");
+ pthread_cancel (priv->event_listener);
+ pthread_join (priv->event_listener, NULL);
+ printf ("Event Listener Thread stopped.\n");
priv->close_signal = 0;
g_list_foreach (priv->clients, disconnect_client, NULL);
g_list_free (priv->clients);
-
- rdma_destroy_ep(priv->base);
+
+ rdma_destroy_ep (priv->base);
priv->base = NULL;
- rdma_destroy_event_channel(priv->ec);
+ rdma_destroy_event_channel (priv->ec);
priv->ec = NULL;
-
- printf("Server stopped successfully.\n");
+ printf ("Server stopped successfully.\n");
}
diff --git a/src/kiro-server.h b/src/kiro-server.h
index 9a70488..e0de71c 100644
--- a/src/kiro-server.h
+++ b/src/kiro-server.h
@@ -24,7 +24,7 @@
* KiroServer implements the server / passive / provider side of the the RDMA
* Communication Channel. It uses a KIRO-TRB to manage its data.
*/
-
+
#ifndef __KIRO_SERVER_H
#define __KIRO_SERVER_H
@@ -47,9 +47,9 @@ typedef struct _KiroServerPrivate KiroServerPrivate;
struct _KiroServer {
-
+
GObject parent;
-
+
/*< private >*/
KiroServerPrivate *priv;
};
@@ -62,9 +62,9 @@ struct _KiroServer {
*/
struct _KiroServerClass {
-
+
GObjectClass parent_class;
-
+
};
@@ -99,7 +99,7 @@ KiroServer* kiro_server_new (void);
* kiro_trb_reshape, kiro_trb_adopt,
* kiro_trb_clone
*/
-int kiro_server_start (KiroServer* server, char* bind_addr, char* bind_port, void* mem, size_t mem_size);
+int kiro_server_start (KiroServer *server, char *bind_addr, char *bind_port, void *mem, size_t mem_size);
/**
* kiro_server_stop - Stops the server
@@ -109,7 +109,7 @@ int kiro_server_start (KiroServer* server, char* bind_addr, char* bind_port, voi
* See also:
* kiro_server_start
*/
-void kiro_server_stop (KiroServer* server);
+void kiro_server_stop (KiroServer *server);
G_END_DECLS
diff --git a/src/kiro-trb.c b/src/kiro-trb.c
index bb4a769..6737f83 100644
--- a/src/kiro-trb.c
+++ b/src/kiro-trb.c
@@ -27,7 +27,7 @@
*/
#include <stdio.h>
-
+
#include <stdlib.h>
#include <string.h>
#include <glib.h>
@@ -51,10 +51,10 @@ struct _KiroTrbPrivate {
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 element_size;
uint64_t max_elements;
uint64_t iteration; // How many times the buffer has wraped around
-
+
/* easy access */
uint64_t buff_size;
};
@@ -63,8 +63,9 @@ struct _KiroTrbPrivate {
G_DEFINE_TYPE (KiroTrb, kiro_trb, G_TYPE_OBJECT);
-KiroTrb*
-kiro_trb_new (void) {
+KiroTrb *
+kiro_trb_new (void)
+{
return g_object_new (KIRO_TYPE_TRB, NULL);
}
@@ -72,111 +73,131 @@ kiro_trb_new (void) {
static
void kiro_trb_init (KiroTrb *self)
{
- KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE(self);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
priv->initialized = 0;
}
static void
kiro_trb_finalize (GObject *object)
{
- KiroTrb *self = KIRO_TRB(object);
- KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->mem)
- free(priv->mem);
+ KiroTrb *self = KIRO_TRB (object);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->mem)
+ free (priv->mem);
}
static void
kiro_trb_class_init (KiroTrbClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = kiro_trb_finalize;
- g_type_class_add_private(klass, sizeof(KiroTrbPrivate));
+ g_type_class_add_private (klass, sizeof (KiroTrbPrivate));
}
/* Privat functions */
-void write_header (KiroTrbPrivate* priv)
+void
+write_header (KiroTrbPrivate *priv)
{
- if(!priv)
+ if (!priv)
return;
- struct KiroTrbInfo* tmp_info = (struct KiroTrbInfo*)priv->mem;
+
+ struct KiroTrbInfo *tmp_info = (struct KiroTrbInfo *)priv->mem;
tmp_info->buffer_size_bytes = priv->buff_size;
tmp_info->element_size = priv->element_size;
tmp_info->offset = (priv->iteration * priv->max_elements) + ((priv->current - priv->frame_top) / priv->element_size);
- memcpy(priv->mem, tmp_info, sizeof(struct KiroTrbInfo));
+ memcpy (priv->mem, tmp_info, sizeof (struct KiroTrbInfo));
}
/* TRB functions */
-uint64_t kiro_trb_get_element_size (KiroTrb* self)
+uint64_t
+kiro_trb_get_element_size (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return 0;
+
return priv->element_size;
}
-uint64_t kiro_trb_get_max_elements (KiroTrb* self)
+uint64_t
+kiro_trb_get_max_elements (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return 0;
+
return priv->max_elements;
}
-uint64_t kiro_trb_get_raw_size (KiroTrb* self)
+uint64_t
+kiro_trb_get_raw_size (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return 0;
+
return priv->buff_size;
}
-void* kiro_trb_get_raw_buffer (KiroTrb* self)
+void *
+kiro_trb_get_raw_buffer (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return NULL;
- write_header(priv);
+
+ write_header (priv);
return priv->mem;
}
-void* kiro_trb_get_element (KiroTrb* self, uint64_t element)
+void *
+kiro_trb_get_element (KiroTrb *self, uint64_t element)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return NULL;
-
- uint64_t relative = 0;
- if(priv->iteration == 0)
+
+ uint64_t relative = 0;
+
+ if (priv->iteration == 0)
relative = element * priv->element_size;
else
- relative = ((priv->current - priv->frame_top) + (priv->element_size * element)) % (priv->buff_size - sizeof(struct KiroTrbInfo));
-
+ relative = ((priv->current - priv->frame_top) + (priv->element_size * element)) % (priv->buff_size - sizeof (struct KiroTrbInfo));
+
return priv->frame_top + relative;
}
-void kiro_trb_flush (KiroTrb *self)
+void
+kiro_trb_flush (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
priv->iteration = 0;
priv->current = priv->frame_top;
- write_header(priv);
+ write_header (priv);
}
-void kiro_trb_purge (KiroTrb* self, gboolean free_memory)
+void
+kiro_trb_purge (KiroTrb *self, gboolean free_memory)
{
- KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE(self);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
priv->iteration = 0;
priv->current = NULL;
priv->initialized = 0;
@@ -184,114 +205,143 @@ void kiro_trb_purge (KiroTrb* self, gboolean free_memory)
priv->buff_size = 0;
priv->frame_top = NULL;
priv->element_size = 0;
- if(free_memory)
- free(priv->mem);
+
+ if (free_memory)
+ free (priv->mem);
+
priv->mem = NULL;
}
-int kiro_trb_is_setup (KiroTrb *self)
+int
+kiro_trb_is_setup (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(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)
+int
+kiro_trb_reshape (KiroTrb *self, uint64_t element_size, uint64_t element_count)
{
- if(element_size < 1 || element_count < 1)
+ if (element_size < 1 || element_count < 1)
return -1;
- size_t new_size = (element_size * element_count) + sizeof(struct KiroTrbInfo);
- void* newmem = malloc(new_size);
- if(!newmem)
+
+ size_t new_size = (element_size * element_count) + sizeof (struct KiroTrbInfo);
+ void *newmem = malloc (new_size);
+
+ if (!newmem)
return -1;
+
((struct KiroTrbInfo *)newmem)->buffer_size_bytes = new_size;
((struct KiroTrbInfo *)newmem)->element_size = element_size;
((struct KiroTrbInfo *)newmem)->offset = 0;
- kiro_trb_adopt(self, newmem);
+ kiro_trb_adopt (self, newmem);
return 0;
}
-int kiro_trb_push (KiroTrb *self, void *element_in)
+int
+kiro_trb_push (KiroTrb *self, void *element_in)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return -1;
- if((priv->current + priv->element_size) > (priv->mem + priv->buff_size))
+
+ if ((priv->current + priv->element_size) > (priv->mem + priv->buff_size))
return -1;
- memcpy(priv->current, element_in, priv->element_size);
+
+ memcpy (priv->current, element_in, priv->element_size);
priv->current += priv->element_size;
- if(priv->current >= priv->frame_top + (priv->element_size * priv->max_elements))
- {
+
+ if (priv->current >= priv->frame_top + (priv->element_size * priv->max_elements)) {
priv->current = priv->frame_top;
priv->iteration++;
}
- write_header(priv);
- return 0;
+
+ write_header (priv);
+ return 0;
}
-void* kiro_trb_dma_push (KiroTrb *self)
+void *
+kiro_trb_dma_push (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return NULL;
- if((priv->current + priv->element_size) > (priv->mem + priv->buff_size))
+
+ if ((priv->current + priv->element_size) > (priv->mem + priv->buff_size))
return NULL;
+
void *mem_out = priv->current;
priv->current += priv->element_size;
- if(priv->current >= priv->frame_top + (priv->element_size * priv->max_elements))
- {
+
+ if (priv->current >= priv->frame_top + (priv->element_size * priv->max_elements)) {
priv->current = priv->frame_top;
priv->iteration++;
}
- write_header(priv);
- return mem_out;
+
+ write_header (priv);
+ return mem_out;
}
-void kiro_trb_refresh (KiroTrb *self)
+void
+kiro_trb_refresh (KiroTrb *self)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->initialized != 1)
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->initialized != 1)
return;
+
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->max_elements = (tmp->buffer_size_bytes - sizeof (struct KiroTrbInfo)) / tmp->element_size;
priv->iteration = tmp->offset / priv->max_elements;
- priv->frame_top = priv->mem + 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;
}
-void kiro_trb_adopt (KiroTrb *self, void *buff_in)
+void
+kiro_trb_adopt (KiroTrb *self, void *buff_in)
{
- if(!buff_in)
+ if (!buff_in)
return;
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
- if(priv->mem)
- free(priv->mem);
+
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
+
+ if (priv->mem)
+ free (priv->mem);
+
priv->mem = buff_in;
priv->initialized = 1;
- kiro_trb_refresh(self);
+ kiro_trb_refresh (self);
}
-int kiro_trb_clone (KiroTrb *self, void *buff_in)
+int
+kiro_trb_clone (KiroTrb *self, void *buff_in)
{
- KiroTrbPrivate* priv = KIRO_TRB_GET_PRIVATE(self);
+ KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
struct KiroTrbInfo *header = (struct KiroTrbInfo *)buff_in;
- void *newmem = malloc(header->buffer_size_bytes);
- if(!newmem)
+ void *newmem = malloc (header->buffer_size_bytes);
+
+ if (!newmem)
return -1;
- memcpy(newmem, buff_in, header->buffer_size_bytes);
- if(priv->mem)
- free(priv->mem);
+
+ memcpy (newmem, buff_in, header->buffer_size_bytes);
+
+ if (priv->mem)
+ free (priv->mem);
+
priv->mem = newmem;
priv->initialized = 1;
- kiro_trb_refresh(self);
+ kiro_trb_refresh (self);
return 0;
}
diff --git a/src/kiro-trb.h b/src/kiro-trb.h
index 3753b29..36d3b5e 100644
--- a/src/kiro-trb.h
+++ b/src/kiro-trb.h
@@ -25,7 +25,7 @@
* about its content inside itself, so its data can be exchanged between different
* instances of the KiroTrb Class and/or sent over a network.
*/
-
+
#ifndef __KIRO_TRB_H
#define __KIRO_TBR_H
@@ -48,7 +48,7 @@ typedef struct _KiroTrbPrivate KiroTrbPrivate;
struct _KiroTrb {
-
+
GObject parent;
};
@@ -61,20 +61,20 @@ struct _KiroTrb {
*/
struct _KiroTrbClass {
-
+
GObjectClass parent_class;
-
+
};
struct KiroTrbInfo {
-
+
/* internal information about the buffer */
uint64_t buffer_size_bytes; // Size in bytes INCLUDING this header
uint64_t element_size; // Size in bytes of one single element
uint64_t offset; // Current Offset to access the 'oldest' element (in element count!)
-
-} __attribute__((packed));
+
+} __attribute__ ((packed));
/* GObject and GType functions */
@@ -94,10 +94,10 @@ KiroTrb* kiro_trb_new (void);
* See also:
* kiro_trb_reshape, kiro_trb_adopt, kiro_trb_clone
*/
-uint64_t kiro_trb_get_element_size (KiroTrb* trb);
+uint64_t kiro_trb_get_element_size (KiroTrb *trb);
/**
- * kiro_trb_get_max_elements:
+ * kiro_trb_get_max_elements:
* Returns the capacity of the buffer
* @trb: #KiroTrb to perform the operation on
* Description:
@@ -107,11 +107,11 @@ uint64_t kiro_trb_get_element_size (KiroTrb* trb);
* kiro_trb_get_element_size, kiro_trb_reshape, kiro_trb_adopt,
* kiro_trb_clone
*/
-uint64_t kiro_trb_get_max_elements (KiroTrb* trb);
+uint64_t kiro_trb_get_max_elements (KiroTrb *trb);
/**
- * kiro_trb_get_raw_size:
+ * kiro_trb_get_raw_size:
* Returns the size of the buffer memory
* @trb: #KiroTrb to perform the operation on
* Description:
@@ -123,11 +123,11 @@ uint64_t kiro_trb_get_max_elements (KiroTrb* trb);
* kiro_trb_reshape, kiro_trb_adopt,
* kiro_trb_clone
*/
-uint64_t kiro_trb_get_raw_size (KiroTrb* trb);
+uint64_t kiro_trb_get_raw_size (KiroTrb *trb);
/**
- * kiro_trb_get_raw_buffer:
+ * kiro_trb_get_raw_buffer:
* @trb: #KiroTrb to perform the operation on
* Description:
* Returns a pointer to the memory structure of the given buffer.
@@ -148,11 +148,11 @@ uint64_t kiro_trb_get_raw_size (KiroTrb* trb);
* See also:
* kiro_trb_refesh, kiro_trb_reshape, kiro_trb_adopt, kiro_trb_clone
*/
-void* kiro_trb_get_raw_buffer (KiroTrb* trb);
+void* kiro_trb_get_raw_buffer (KiroTrb *trb);
/**
- * kiro_trb_get_element:
+ * kiro_trb_get_element:
* @trb: #KiroTrb to perform the operation on
* @index: Index of the element in the buffer to access
* Description:
@@ -172,11 +172,11 @@ void* kiro_trb_get_raw_buffer (KiroTrb* trb);
* See also:
* kiro_trb_get_element_size, kiro_trb_get_raw_buffer
*/
-void* kiro_trb_get_element (KiroTrb* trb, uint64_t index);
+void* kiro_trb_get_element (KiroTrb *trb, uint64_t index);
/**
- * kiro_trb_dma_push:
+ * kiro_trb_dma_push:
* Gives DMA to the next element and pushes the buffer
* @trb: #KiroTrb to perform the operation on
* Description:
@@ -198,11 +198,11 @@ void* kiro_trb_get_element (KiroTrb* trb, uint64_t index);
* See also:
* kiro_trb_push, kiro_trb_get_element_size, kiro_trb_get_raw_buffer
*/
-void* kiro_trb_dma_push (KiroTrb* trb);
+void* kiro_trb_dma_push (KiroTrb *trb);
/**
- * kiro_trb_flush:
+ * kiro_trb_flush:
* Flushes the buffer
* @trb: #KiroTrb to perform the operation on
* Description:
@@ -214,11 +214,11 @@ void* kiro_trb_dma_push (KiroTrb* trb);
* See also:
* kiro_trb_reshape, kiro_trb_adopt, kiro_trb_clone
*/
-void kiro_trb_flush (KiroTrb* trb);
+void kiro_trb_flush (KiroTrb *trb);
/**
- * kiro_trb_purge:
+ * kiro_trb_purge:
* Completely resets the Buffer
* @trb: #KiroTrb to perform the operation on
* @free_memory: True = internal memory will be free()'d,
@@ -233,11 +233,11 @@ void kiro_trb_flush (KiroTrb* trb);
* See also:
* kiro_trb_reshape, kiro_trb_adopt, kiro_trb_clone
*/
-void kiro_trb_purge (KiroTrb* trb, gboolean free_memory);
+void kiro_trb_purge (KiroTrb *trb, gboolean free_memory);
/**
- * kiro_trb_is_setup:
+ * kiro_trb_is_setup:
* Returns the setup status of the buffer
* @trb: #KiroTrb to perform the operation on
* Description:
@@ -250,11 +250,11 @@ void kiro_trb_purge (KiroTrb* trb, gboolean free_memory);
* See also:
* kiro_trb_reshape, kiro_trb_adopt, kiro_trb_clone
*/
-int kiro_trb_is_setup (KiroTrb* trb);
+int kiro_trb_is_setup (KiroTrb *trb);
/**
- * kiro_trb_reshape:
+ * kiro_trb_reshape:
* Reallocates internal memory and structures
* @trb: #KiroTrb to perform the operation on
* @element_size: Individual size of the elements to store in bytes
@@ -270,11 +270,11 @@ int kiro_trb_is_setup (KiroTrb* trb);
* See also:
* kiro_trb_is_setup, kiro_trb_reshape, kiro_trb_adopt, kiro_trb_clone
*/
-int kiro_trb_reshape (KiroTrb* trb, uint64_t element_size, uint64_t element_count);
+int kiro_trb_reshape (KiroTrb *trb, uint64_t element_size, uint64_t element_count);
/**
- * kiro_trb_clone:
+ * kiro_trb_clone:
* Clones the given memory into the internal memory
* @trb: #KiroTrb to perform the operation on
* @source: Pointer to the source memory to clone from
@@ -293,11 +293,11 @@ int kiro_trb_reshape (KiroTrb* trb, uint64_t element_size, uint64_t element_coun
* See also:
* kiro_trb_reshape, kiro_trb_adopt
*/
-int kiro_trb_clone (KiroTrb* trb, void* source);
+int kiro_trb_clone (KiroTrb *trb, void *source);
/**
- * kiro_trb_push:
+ * kiro_trb_push:
* Adds an element into the buffer
* @trb: #KiroTrb to perform the operation on
* @source: Pointer to the memory of the element to add
@@ -314,11 +314,11 @@ int kiro_trb_clone (KiroTrb* trb, void* source);
* kiro_trb_dma_push, kiro_trb_get_element_size, kiro_trb_clone,
* kiro_trb_adopt
*/
-int kiro_trb_push (KiroTrb* trb, void* source);
+int kiro_trb_push (KiroTrb *trb, void *source);
/**
- * kiro_trb_refresh:
+ * kiro_trb_refresh:
* Re-reads the TRBs memory header
* @trb: #KiroTrb to perform the operation on
* Description:
@@ -333,11 +333,11 @@ int kiro_trb_push (KiroTrb* trb, void* source);
* See also:
* kiro_trb_get_raw_buffer, kiro_trb_push_dma, kiro_trb_adopt
*/
-void kiro_trb_refresh (KiroTrb* trb);
+void kiro_trb_refresh (KiroTrb *trb);
/**
- * kiro_trb_adopt:
+ * kiro_trb_adopt:
* Adopts the given memory into the TRB
* @trb: #KiroTrb to perform the operation on
* @source: Pointer to the source memory to adopt
@@ -356,7 +356,7 @@ void kiro_trb_refresh (KiroTrb* trb);
* See also:
* kiro_trb_clone, kiro_trb_reshape
*/
-void kiro_trb_adopt (KiroTrb* trb, void* source);
+void kiro_trb_adopt (KiroTrb *trb, void *source);
G_END_DECLS
diff --git a/test/test-client.c b/test/test-client.c
index cdac3ee..45ce722 100644
--- a/test/test-client.c
+++ b/test/test-client.c
@@ -7,84 +7,85 @@
#include <assert.h>
-static _Bool init_app(const char * name, SDL_Surface * icon, uint32_t flags)
+static _Bool
+init_app (const char *name, SDL_Surface *icon, uint32_t flags)
{
- atexit(SDL_Quit);
- if(SDL_Init(flags) < 0)
- return 0;
+ atexit (SDL_Quit);
- SDL_WM_SetCaption(name, name);
- SDL_WM_SetIcon(icon, NULL);
+ if (SDL_Init (flags) < 0)
+ return 0;
+ SDL_WM_SetCaption (name, name);
+ SDL_WM_SetIcon (icon, NULL);
return 1;
}
-static void render(SDL_Surface * sf)
+static void
+render (SDL_Surface *sf)
{
- SDL_Surface * screen = SDL_GetVideoSurface();
- if(SDL_BlitSurface(sf, NULL, screen, NULL) == 0)
- SDL_UpdateRect(screen, 0, 0, 0, 0);
+ SDL_Surface *screen = SDL_GetVideoSurface();
+
+ if (SDL_BlitSurface (sf, NULL, screen, NULL) == 0)
+ SDL_UpdateRect (screen, 0, 0, 0, 0);
}
-static int filter(const SDL_Event * event)
-{ return event->type == SDL_QUIT; }
+static int
+filter (const SDL_Event *event)
+{
+ return event->type == SDL_QUIT;
+}
-int main ( int argc, char *argv[] )
+int
+main ( int argc, char *argv[] )
{
- if (argc < 3)
- {
- printf("Not enough aruments. Usage: ./client <address> <port>\n");
+ if (argc < 3) {
+ printf ("Not enough aruments. Usage: ./client <address> <port>\n");
return -1;
}
+
KiroClient *client = kiro_client_new ();
- if(-1 == kiro_client_connect(client, argv[1], argv[2]))
- {
- g_object_unref(client);
+
+ if (-1 == kiro_client_connect (client, argv[1], argv[2])) {
+ g_object_unref (client);
return -1;
}
-
- kiro_client_sync(client);
+
+ kiro_client_sync (client);
KiroTrb *trb = kiro_trb_new ();
- kiro_trb_adopt(trb, kiro_client_get_memory(client));
-
+ kiro_trb_adopt (trb, kiro_client_get_memory (client));
_Bool ok =
- init_app("UCA Images", NULL, SDL_INIT_VIDEO) &&
- SDL_SetVideoMode(512, 512, 8, SDL_HWSURFACE);
-
- assert(ok);
-
+ init_app ("UCA Images", NULL, SDL_INIT_VIDEO) &&
+ SDL_SetVideoMode (512, 512, 8, SDL_HWSURFACE);
+ assert (ok);
uint32_t mask = 0xffffffff;
- SDL_Surface * data_sf = SDL_CreateRGBSurfaceFrom(
- kiro_trb_get_element(trb, 0), 512, 512, 8, 512,
- mask, mask, mask, 0);
-
+ SDL_Surface *data_sf = SDL_CreateRGBSurfaceFrom (
+ kiro_trb_get_element (trb, 0), 512, 512, 8, 512,
+ mask, mask, mask, 0);
SDL_Color colors[256];
- for(int i=0;i<256;i++){
- colors[i].r=i;
- colors[i].g=i;
- colors[i].b=i;
- }
- SDL_SetPalette(data_sf, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);
-
- SDL_SetEventFilter(filter);
-
+
+ for (int i = 0; i < 256; i++) {
+ colors[i].r = i;
+ colors[i].g = i;
+ colors[i].b = i;
+ }
+
+ SDL_SetPalette (data_sf, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
+ SDL_SetEventFilter (filter);
int cont = 1;
-
+
//struct KiroTrbInfo *header = (struct KiroTrbInfo *)kiro_trb_get_raw_buffer(trb);
-
- while(cont)
- {
- for(SDL_Event event; SDL_PollEvent(&event);)
- if(event.type == SDL_QUIT) cont=0;
-
- kiro_client_sync(client);
- SDL_Delay(10);
- render(data_sf);
+
+ while (cont) {
+ for (SDL_Event event; SDL_PollEvent (&event);)
+ if (event.type == SDL_QUIT) cont = 0;
+
+ kiro_client_sync (client);
+ SDL_Delay (10);
+ render (data_sf);
}
-
-
- g_object_unref(client);
+
+ g_object_unref (client);
return 0;
}
diff --git a/test/test-server.c b/test/test-server.c
index 9161122..2ed895b 100644
--- a/test/test-server.c
+++ b/test/test-server.c
@@ -12,65 +12,85 @@
static const char g_digits[10][20] = {
/* 0 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00 },
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0xff, 0x00, 0x00, 0xff,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00
+ },
/* 1 */
- { 0x00, 0x00, 0xff, 0x00,
- 0x00, 0xff, 0xff, 0x00,
- 0x00, 0x00, 0xff, 0x00,
- 0x00, 0x00, 0xff, 0x00,
- 0x00, 0x00, 0xff, 0x00 },
+ {
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0xff, 0xff, 0x00,
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0x00, 0xff, 0x00
+ },
/* 2 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0x00,
- 0x00, 0xff, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff },
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0xff, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0xff
+ },
/* 3 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00 },
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00
+ },
/* 4 */
- { 0xff, 0x00, 0x00, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0x00, 0xff },
+ {
+ 0xff, 0x00, 0x00, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0xff, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0x00, 0xff
+ },
/* 5 */
- { 0xff, 0xff, 0xff, 0xff,
- 0xff, 0x00, 0x00, 0x00,
- 0x00, 0xff, 0xff, 0x00,
- 0x00, 0x00, 0x00, 0xff,
- 0xff, 0xff, 0xff, 0x00 },
+ {
+ 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x00, 0x00, 0x00,
+ 0x00, 0xff, 0xff, 0x00,
+ 0x00, 0x00, 0x00, 0xff,
+ 0xff, 0xff, 0xff, 0x00
+ },
/* 6 */
- { 0x00, 0xff, 0xff, 0xff,
- 0xff, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00 },
+ {
+ 0x00, 0xff, 0xff, 0xff,
+ 0xff, 0x00, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00
+ },
/* 7 */
- { 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0x00,
- 0x00, 0xff, 0x00, 0x00,
- 0xff, 0x00, 0x00, 0x00 },
+ {
+ 0xff, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0xff, 0x00, 0x00,
+ 0xff, 0x00, 0x00, 0x00
+ },
/* 8 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00 },
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00
+ },
/* 9 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0xff,
- 0xff, 0xff, 0xff, 0x00 }
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0xff,
+ 0xff, 0xff, 0xff, 0x00
+ }
};
static const guint DIGIT_WIDTH = 4;
@@ -81,12 +101,14 @@ print_number (gchar *buffer, guint number, guint x, guint y, guint width)
{
for (int i = 0; i < DIGIT_WIDTH; i++) {
for (int j = 0; j < DIGIT_HEIGHT; j++) {
- char val = (char) g_digits[number][j*DIGIT_WIDTH+i];
- if(val != 0x00) {
+ char val = (char) g_digits[number][j * DIGIT_WIDTH + i];
+
+ if (val != 0x00) {
//This should make the frame counter appear in a bright yellow
val = 0xBE;
}
- buffer[(y+j)*width + (x+i)] = (guint8) val;
+
+ buffer[ (y + j)*width + (x + i)] = (guint8) val;
}
}
}
@@ -98,27 +120,26 @@ print_current_frame (gchar *buffer, guint number, guint width, guint height, GRa
int x = 1;
while (divisor > 0) {
- print_number(buffer, number / divisor, x, 1, width);
+ print_number (buffer, number / divisor, x, 1, width);
number = number % divisor;
divisor = divisor / 10;
x += DIGIT_WIDTH + 1;
}
-
//Rainbow pattern is the same for every row. Just calculate one single
//Scanline, so we can reuse it and dont have to do the whole calculation
//for every row again.
char default_line[width];
+
for (int p = 0; p < width; p++) {
- default_line[p] = (char) ((p*256) / (width));
+ default_line[p] = (char) ((p * 256) / (width));
}
-
//Use memcpy to quickly fill every row with the precalculated rainbow
//pattern
for (guint y = 16; y < height; y++) {
guint index = y * width;
- memcpy(buffer+index, &default_line[0], width);
+ memcpy (buffer + index, &default_line[0], width);
}
//This block will fill a square at the center of the image with normal
@@ -126,45 +147,45 @@ print_current_frame (gchar *buffer, guint number, guint width, guint height, GRa
const double mean = 128.0;
const double std = 32.0;
- for (guint y = (height/3); y < ((height*2)/3); y++) {
+ for (guint y = (height / 3); y < ((height * 2) / 3); y++) {
guint row_start = y * width;
- for (guint i = (width/3); i < ((width*2)/3); i++) {
+
+ for (guint i = (width / 3); i < ((width * 2) / 3); i++) {
int index = row_start + i;
- double u1 = g_rand_double(rand);
- double u2 = g_rand_double(rand);
- double r = sqrt(-2 * log(u1)) * cos(2 * G_PI * u2);
+ double u1 = g_rand_double (rand);
+ double u2 = g_rand_double (rand);
+ double r = sqrt (-2 * log (u1)) * cos (2 * G_PI * u2);
buffer[index] = (guint8) (r * std + mean);
}
}
}
-int main(void)
+int
+main (void)
{
KiroServer *server = kiro_server_new ();
KiroTrb *rb = kiro_trb_new ();
- kiro_trb_reshape(rb, 512*512, 15);
+ kiro_trb_reshape (rb, 512 * 512, 15);
GRand *rand = g_rand_new();
- if(0 > kiro_server_start(server, NULL, "60010", kiro_trb_get_raw_buffer(rb), kiro_trb_get_raw_size(rb)))
- {
- printf("Failed to start server properly.\n");
+
+ if (0 > kiro_server_start (server, NULL, "60010", kiro_trb_get_raw_buffer (rb), kiro_trb_get_raw_size (rb))) {
+ printf ("Failed to start server properly.\n");
goto done;
}
guint frame = 0;
gchar *buffer = NULL;
- while(1)
- {
- buffer = kiro_trb_dma_push(rb);
- print_current_frame(buffer, frame, 512, 512, rand);
+
+ while (1) {
+ buffer = kiro_trb_dma_push (rb);
+ print_current_frame (buffer, frame, 512, 512, rand);
frame++;
}
-
-
-done:
- g_rand_free(rand);
- g_object_unref(rb);
- g_object_unref(server);
- return 0;
+done:
+ g_rand_free (rand);
+ g_object_unref (rb);
+ g_object_unref (server);
+ return 0;
} \ No newline at end of file
diff --git a/test/test.c b/test/test.c
index 4aac2f5..c3e0028 100644
--- a/test/test.c
+++ b/test/test.c
@@ -7,10 +7,10 @@
struct test {
uint32_t zahl;
uint8_t buchstabe;
-} __attribute__((packed));
+} __attribute__ ((packed));
-int main(void)
+int main (void)
{
/*
void* ptr = malloc(sizeof(struct test) + sizeof(uint64_t));
@@ -19,33 +19,31 @@ int main(void)
foo.zahl = 42;
foo.buchstabe = 'R';
memcpy(ptr, &foo, sizeof(foo));
-
+
struct test *tmp = (struct test *)ptr;
printf("Zahl = %d\n",tmp->zahl);
printf("Buchstabe = %c\n", tmp->buchstabe);
printf("Remaining = %x\n", *((uint64_t *)(ptr+sizeof(struct test))));
*/
-
- KiroTrb *rb = g_object_new(KIRO_TYPE_TRB, NULL);
- kiro_trb_reshape(rb, sizeof(uint64_t), 3);
- void *buffer = kiro_trb_get_raw_buffer(rb);
+ KiroTrb *rb = g_object_new (KIRO_TYPE_TRB, NULL);
+ kiro_trb_reshape (rb, sizeof (uint64_t), 3);
+ void *buffer = kiro_trb_get_raw_buffer (rb);
uint64_t foo = 0xAFFED00F;
uint64_t bar = 0x1337BEEF;
- memcpy(kiro_trb_dma_push(rb), &foo, sizeof(foo));
- memcpy(kiro_trb_dma_push(rb), &foo, sizeof(foo));
- memcpy(kiro_trb_dma_push(rb), &foo, sizeof(foo));
- kiro_trb_push(rb, &bar);
- kiro_trb_push(rb, &foo);
- kiro_trb_push(rb, &foo);
- uint64_t *maman = kiro_trb_get_element(rb, 3);
- printf("Stored in old: %x\n", *maman);
- KiroTrb *rb2 = g_object_new(KIRO_TYPE_TRB, NULL);
- kiro_trb_clone(rb2, kiro_trb_get_raw_buffer(rb));
- maman = kiro_trb_get_element(rb2, 3);
- printf("Stored in New: %x\n", *maman);
- sleep(1);
- g_object_unref(rb);
- g_object_unref(rb2);
-
+ memcpy (kiro_trb_dma_push (rb), &foo, sizeof (foo));
+ memcpy (kiro_trb_dma_push (rb), &foo, sizeof (foo));
+ memcpy (kiro_trb_dma_push (rb), &foo, sizeof (foo));
+ kiro_trb_push (rb, &bar);
+ kiro_trb_push (rb, &foo);
+ kiro_trb_push (rb, &foo);
+ uint64_t *maman = kiro_trb_get_element (rb, 3);
+ printf ("Stored in old: %x\n", *maman);
+ KiroTrb *rb2 = g_object_new (KIRO_TYPE_TRB, NULL);
+ kiro_trb_clone (rb2, kiro_trb_get_raw_buffer (rb));
+ maman = kiro_trb_get_element (rb2, 3);
+ 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