loci: inline of_wire_object into of_object
This extra layer of structs was not needed.
diff --git a/c_gen/templates/of_object.c b/c_gen/templates/of_object.c
index 6f20658..feb447a 100644
--- a/c_gen/templates/of_object.c
+++ b/c_gen/templates/of_object.c
@@ -61,11 +61,11 @@
MEMSET(obj, 0, sizeof(*obj));
if (bytes > 0) {
- if ((obj->wire_object.wbuf = of_wire_buffer_new(bytes)) == NULL) {
+ if ((obj->wbuf = of_wire_buffer_new(bytes)) == NULL) {
FREE(obj);
return NULL;
}
- obj->wire_object.owned = 1;
+ obj->owned = 1;
}
return obj;
@@ -87,8 +87,8 @@
return;
}
- if (obj->wire_object.owned) {
- of_wire_buffer_free(obj->wire_object.wbuf);
+ if (obj->owned) {
+ of_wire_buffer_free(obj->wbuf);
}
FREE(obj);
@@ -114,12 +114,12 @@
MEMSET(dst, 0, sizeof(*dst));
/* Allocate a minimal wire buffer assuming we will not write to it. */
- if ((dst->wire_object.wbuf = of_wire_buffer_new(src->length)) == NULL) {
+ if ((dst->wbuf = of_wire_buffer_new(src->length)) == NULL) {
FREE(dst);
return NULL;
}
- dst->wire_object.owned = 1;
+ dst->owned = 1;
init_fn = of_object_init_map[src->object_id];
init_fn(dst, src->version, src->length, 0);
@@ -204,7 +204,7 @@
}
obj->version = version;
- obj->wire_object.wbuf = wbuf;
+ obj->wbuf = wbuf;
wbuf->buf = msg;
wbuf->alloc_bytes = len;
wbuf->current_bytes = len;
@@ -232,23 +232,19 @@
of_object_buffer_bind(of_object_t *obj, uint8_t *buf, int bytes,
of_buffer_free_f buf_free)
{
- of_wire_object_t *wobj;
of_wire_buffer_t *wbuf;
LOCI_ASSERT(buf != NULL);
LOCI_ASSERT(bytes > 0);
- // LOCI_ASSERT(wobj is not bound);
-
- wobj = &obj->wire_object;
- MEMSET(wobj, 0, sizeof(*wobj));
wbuf = of_wire_buffer_new_bind(buf, bytes, buf_free);
if (wbuf == NULL) {
return OF_ERROR_RESOURCE;
}
- wobj->wbuf = wbuf;
- wobj->owned = 1;
+ obj->wbuf = wbuf;
+ obj->obj_offset = 0;
+ obj->owned = 1;
obj->length = bytes;
return OF_ERROR_NONE;
@@ -284,17 +280,15 @@
object_child_attach(of_object_t *parent, of_object_t *child,
int offset, int bytes)
{
- of_wire_object_t *c_wobj; /* Pointer to child's wire object */
of_wire_buffer_t *wbuf; /* Pointer to common wire buffer manager */
child->parent = parent;
- wbuf = parent->wire_object.wbuf;
+ wbuf = parent->wbuf;
/* Set up the child's wire buf to point to same as parent */
- c_wobj = &child->wire_object;
- c_wobj->wbuf = wbuf;
- c_wobj->obj_offset = parent->wire_object.obj_offset + offset;
- c_wobj->owned = 0;
+ child->wbuf = wbuf;
+ child->obj_offset = parent->obj_offset + offset;
+ child->owned = 0;
/*
* bytes determines if this is a read or write setup.
@@ -305,7 +299,7 @@
int tot_bytes; /* Total bytes to request for buffer if updated */
/* Set up space for the child in the parent's buffer */
- tot_bytes = parent->wire_object.obj_offset + offset + bytes;
+ tot_bytes = parent->obj_offset + offset + bytes;
of_wire_buffer_grow(wbuf, tot_bytes);
child->length = bytes;
@@ -324,7 +318,7 @@
of_object_can_grow(of_object_t *obj, int new_len)
{
return OF_OBJECT_ABSOLUTE_OFFSET(obj, new_len) <=
- WBUF_ALLOC_BYTES(obj->wire_object.wbuf);
+ WBUF_ALLOC_BYTES(obj->wbuf);
}
/**
@@ -398,7 +392,7 @@
of_list_append_bind(of_object_t *parent, of_object_t *child)
{
if (parent == NULL || child == NULL ||
- parent->wire_object.wbuf == NULL) {
+ parent->wbuf == NULL) {
return OF_ERROR_PARAM;
}
@@ -440,7 +434,7 @@
return OF_ERROR_RESOURCE;
}
- of_wire_buffer_grow(list->wire_object.wbuf,
+ of_wire_buffer_grow(list->wbuf,
OF_OBJECT_ABSOLUTE_OFFSET(list, new_len));
MEMCPY(OF_OBJECT_BUFFER_INDEX(list, list->length),
@@ -491,8 +485,8 @@
static int
of_list_is_last(of_object_t *parent, of_object_t *child)
{
- if (child->wire_object.obj_offset + child->length >=
- parent->wire_object.obj_offset + parent->length) {
+ if (child->obj_offset + child->length >=
+ parent->obj_offset + parent->length) {
return 1;
}
@@ -526,7 +520,7 @@
}
/* Offset is relative to parent start */
- offset = (child->wire_object.obj_offset - parent->wire_object.obj_offset) +
+ offset = (child->obj_offset - parent->obj_offset) +
child->length;
object_child_attach(parent, child, offset, 0);
@@ -537,8 +531,8 @@
of_object_wire_buffer_steal(of_object_t *obj, uint8_t **buffer)
{
LOCI_ASSERT(obj != NULL);
- of_wire_buffer_steal(obj->wire_object.wbuf, buffer);
- obj->wire_object.wbuf = NULL;
+ of_wire_buffer_steal(obj->wbuf, buffer);
+ obj->wbuf = NULL;
}
#define _MAX_PARENT_ITERATIONS 4
@@ -565,14 +559,14 @@
obj->length += delta;
of_object_wire_length_set(obj, obj->length);
#ifndef NDEBUG
- wbuf = obj->wire_object.wbuf;
+ wbuf = obj->wbuf;
#endif
/* Asserts for wire length checking */
- LOCI_ASSERT(obj->length + obj->wire_object.obj_offset <=
+ LOCI_ASSERT(obj->length + obj->obj_offset <=
WBUF_CURRENT_BYTES(wbuf));
if (obj->parent == NULL) {
- LOCI_ASSERT(obj->length + obj->wire_object.obj_offset ==
+ LOCI_ASSERT(obj->length + obj->obj_offset ==
WBUF_CURRENT_BYTES(wbuf));
}
@@ -651,8 +645,8 @@
d_wbuf = OF_OBJECT_TO_WBUF(dst);
s_wbuf = OF_OBJECT_TO_WBUF(src);
- dst_offset = dst->wire_object.obj_offset + dst_length;
- src_offset = src->wire_object.obj_offset;
+ dst_offset = dst->obj_offset + dst_length;
+ src_offset = src->obj_offset;
OF_WIRE_BUFFER_INIT_CHECK(d_wbuf, dst_offset + src->length);
MEMCPY(OF_WBUF_BUFFER_POINTER(d_wbuf, dst_offset),
OF_WBUF_BUFFER_POINTER(s_wbuf, 0), src->length);
@@ -671,7 +665,7 @@
of_packet_out_actions_length_set(of_packet_t *obj, int len)
{
if (obj == NULL || obj->object_id != OF_PACKET_IN ||
- obj->wire_object.wbuf == NULL) {
+ obj->wbuf == NULL) {
return OF_ERROR_PARAM;
}
@@ -682,7 +676,7 @@
_packet_out_data_offset_get(of_packet_t *obj)
{
if (obj == NULL || obj->object_id != OF_PACKET_IN ||
- obj->wire_object.wbuf == NULL) {
+ obj->wbuf == NULL) {
return -1;
}