Commit ef9d164d authored by Cedric Roux's avatar Cedric Roux

- Removed UI interface structure

- Update calls to signal_set_text

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4265 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 497527fa
......@@ -10,13 +10,6 @@
extern int debug_buffers;
buffer_list_t list = {
.head = NULL,
.tail = NULL,
.count = 0,
};
pthread_mutex_t buffer_list_mutex = PTHREAD_MUTEX_INITIALIZER;
static
int buffer_fetch(buffer_t *buffer, uint32_t offset, int size, void *value);
......@@ -121,8 +114,6 @@ int buffer_new_from_data(buffer_t **buffer, uint8_t *data, const uint32_t length
new->buffer_current = NULL;
}
new->next = NULL;
*buffer = new;
return 0;
......@@ -196,49 +187,3 @@ int buffer_has_enouch_data(buffer_t *buffer, uint32_t offset, uint32_t to_get)
offset, to_get, buffer->size_bytes);
return underflow;
}
int buffer_get_from_mn(const uint32_t message_number, buffer_t **buffer)
{
buffer_t *temp_buf;
if (!buffer)
return RC_BAD_PARAM;
for (temp_buf = list.head; temp_buf; temp_buf = temp_buf->next) {
if (temp_buf->message_number == message_number) {
break;
}
}
*buffer = temp_buf;
return RC_OK;
}
int buffer_add_to_list(buffer_t *new_buf)
{
if (!new_buf)
return RC_BAD_PARAM;
pthread_mutex_lock(&buffer_list_mutex);
/* No element at tail */
if (list.tail == NULL) {
if (list.head == NULL) {
list.head = new_buf;
list.tail = list.head;
} else {
return RC_FAIL;
}
} else {
list.tail->next = new_buf;
new_buf->previous = list.tail;
list.tail = new_buf;
}
list.count++;
pthread_mutex_unlock(&buffer_list_mutex);
return RC_OK;
}
......@@ -17,18 +17,8 @@ typedef struct buffer_s {
uint32_t message_number;
uint32_t message_id;
struct buffer_s *previous;
struct buffer_s *next;
} buffer_t;
typedef struct {
buffer_t *head;
buffer_t *tail;
uint32_t count;
} buffer_list_t;
uint8_t buffer_get_uint8_t(buffer_t *buffer, uint32_t offset);
uint16_t buffer_get_uint16_t(buffer_t *buffer, uint32_t offset);
......@@ -46,8 +36,4 @@ int buffer_new_from_data(buffer_t **buffer, uint8_t *data, const uint32_t length
int buffer_has_enouch_data(buffer_t *buffer, uint32_t offset, uint32_t to_get);
int buffer_add_to_list(buffer_t *new_buf);
int buffer_get_from_mn(const uint32_t message_number, buffer_t **buffer);
#endif /* BUFFERS_H_ */
......@@ -7,8 +7,10 @@
#include "fundamental_type.h"
#include "ui_interface.h"
int array_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int array_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
struct types_s *type_child;
DISPLAY_PARSE_INFO("array", type->name, offset, parent_offset);
......@@ -47,24 +49,23 @@ int array_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t o
}
}
for (i = 0; i < (items - zero_counter); i++)
type->child->type_dissect_from_buffer (type->child, buffer, parent_offset, offset + i * type_child->size,
type->name == NULL ? indent : indent + 4);
type->child->type_dissect_from_buffer (
type->child, ui_set_signal_text_cb, user_data, buffer, parent_offset,
offset + i * type_child->size, type->name == NULL ? indent : indent + 4);
if (zero_counter > 0)
{
int length = 0;
char cbuf[50];
char *cpy = NULL;
int length = 0;
char cbuf[50];
INDENTED_STRING(cbuf, type->name == NULL ? indent : indent + 4,);
INDENTED_STRING(cbuf, type->name == NULL ? indent : indent + 4,);
length = sprintf(cbuf, "[%d .. %d] ", i, items -1);
cpy = malloc(sizeof(char) * length);
memcpy(cpy, cbuf, length);
ui_interface.ui_signal_set_text(cpy, length);
if (cpy)
free(cpy);
length = sprintf(cbuf, "[%d .. %d] ", i, items -1);
type->child->type_dissect_from_buffer (type->child, buffer, parent_offset, offset + i * type_child->size, 0);
// ui_interface.ui_signal_set_text(cpy, length);
ui_set_signal_text_cb(user_data, cbuf, length);
type->child->type_dissect_from_buffer (
type->child, ui_set_signal_text_cb, user_data,
buffer, parent_offset, offset + i * type_child->size, 0);
}
}
if (type->name) {
......
......@@ -3,8 +3,9 @@
#ifndef ARRAY_TYPE_H_
#define ARRAY_TYPE_H_
int array_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int array_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int array_type_hr_display(struct types_s *type, int indent);
......
......@@ -22,8 +22,8 @@ char *enum_type_get_name_from_value(struct types_s *type, uint32_t value)
}
int enum_type_dissect_from_buffer(
struct types_s *type, buffer_t *buffer, uint32_t offset,
uint32_t parent_offset, int indent)
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
uint32_t value = 0;
types_t *values;
......@@ -32,33 +32,22 @@ int enum_type_dissect_from_buffer(
value = buffer_get_uint32_t(buffer, parent_offset + offset);
// if (type->name) {
// INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
// }
for (values = type->child; values; values = values->next) {
if (value == values->init_value) {
values->type_dissect_from_buffer(
values, buffer, offset, parent_offset,
values, ui_set_signal_text_cb, user_data, buffer, offset, parent_offset,
type->name == NULL ? indent: indent+4);
break;
}
}
if (values == NULL) {
// INDENTED(stdout, indent+4, fprintf(stdout, "<UNKNOWN/>\n"));
int length = 0;
char cbuf[50];
char *cpy = NULL;
length = sprintf(cbuf, "(0x%08x) UNKNOWN;\n", value);
cpy = malloc(sizeof(char) * length);
memcpy(cpy, cbuf, length);
ui_interface.ui_signal_set_text(cpy, length);
if (cpy)
free(cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
}
// if (type->name) {
// INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
// }
return 0;
}
......
......@@ -6,8 +6,8 @@
char *enum_type_get_name_from_value(struct types_s *type, uint32_t value);
int enum_type_dissect_from_buffer(
struct types_s *type, buffer_t *buffer, uint32_t offset,
uint32_t parent_offset, int indent);
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int enum_type_file_print(struct types_s *type, int indent, FILE *file);
......
......@@ -7,8 +7,8 @@
#include "ui_interface.h"
int enum_value_dissect_from_buffer(
struct types_s *type, buffer_t *buffer, uint32_t offset,
uint32_t parent_offset, int indent)
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
uint32_t value = 0;
......@@ -18,15 +18,11 @@ int enum_value_dissect_from_buffer(
if (type->name) {
int length = 0;
char cbuf[50 + strlen(type->name)];
char *cpy = NULL;
sprintf(cbuf, "(0x%08x) %s;\n", value, type->name);
length = strlen(cbuf);
cpy = malloc(sizeof(char) * length);
memcpy(cpy, cbuf, length);
ui_interface.ui_signal_set_text(cpy, length);
if (cpy)
free(cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
}
return 0;
......
......@@ -4,8 +4,8 @@
#define ENUM_VALUE_TYPE_H_
int enum_value_dissect_from_buffer(
struct types_s *type, buffer_t *buffer, uint32_t offset,
uint32_t parent_offset, int indent);
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int enum_value_file_print(struct types_s *type, int indent, FILE *file);
......
......@@ -9,11 +9,12 @@
#include "buffers.h"
#include "ui_interface.h"
int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int field_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
int length = 0;
char cbuf[50];
char *cpy = NULL;
struct types_s *type_child;
char array_info[50];
int indent_child;
......@@ -47,34 +48,30 @@ int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t o
DISPLAY_TYPE("Fld");
INDENTED_STRING(cbuf, indent, sprintf(cbuf, ".%s%s = ", type->name ? type->name : "Field", array_info));
length = strlen (cbuf);
cpy = malloc (sizeof(char) * length);
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
indent_child = indent;
if (type_child->type == TYPE_ARRAY || type_child->type == TYPE_STRUCT || type_child->type == TYPE_UNION) {
DISPLAY_BRACE(ui_interface.ui_signal_set_text ("{", 1);)
ui_interface.ui_signal_set_text ("\n", 1);
DISPLAY_BRACE(ui_set_signal_text_cb(user_data, "{", 1);)
ui_set_signal_text_cb(user_data, "\n", 1);
indent_child += 4;
}
if (type_child->type == TYPE_FUNDAMENTAL || type_child->type == TYPE_POINTER) {
indent_child = 0;
}
CHECK_FCT(
type->child->type_dissect_from_buffer( type->child, buffer, parent_offset, offset + type->offset, indent_child));
CHECK_FCT(type->child->type_dissect_from_buffer(
type->child, ui_set_signal_text_cb, user_data, buffer,
parent_offset, offset + type->offset, indent_child));
DISPLAY_BRACE(
if (type_child->type == TYPE_ARRAY || type_child->type == TYPE_STRUCT || type_child->type == TYPE_UNION) {
DISPLAY_TYPE("Fld");
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n"));
length = strlen (cbuf);
cpy = malloc (sizeof(char) * length); memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
});
}
}
......@@ -90,11 +87,8 @@ int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t o
indent,
sprintf(cbuf, ".%s:%d = (0x%0*x) %d;\n", type->name ? type->name : "Field", type->bits, (type->bits + 3) / 4, value, value));
length = strlen (cbuf);
cpy = malloc (sizeof(char) * length);
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
}
return 0;
......
......@@ -3,8 +3,9 @@
#ifndef FIELD_TYPE_H_
#define FIELD_TYPE_H_
int field_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int field_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int field_type_file_print(struct types_s *type, int indent, FILE *file);
......
......@@ -30,13 +30,14 @@ uint32_t fundamental_read_from_buffer(struct types_s *type, buffer_t *buffer, ui
return value;
}
int fundamental_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int length = 0;
char cbuf[200];
char *cpy = NULL;
int type_unsigned;
uint32_t value;
int fundamental_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
int length = 0;
char cbuf[200];
int type_unsigned;
uint32_t value;
DISPLAY_PARSE_INFO("fundamental", type->name, offset, parent_offset);
......@@ -72,12 +73,8 @@ int fundamental_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
return 0;
}
......
......@@ -5,8 +5,9 @@
uint32_t fundamental_read_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset);
int fundamental_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent);
int fundamental_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int fundamental_type_file_print(struct types_s *type, int indent, FILE *file);
......
......@@ -6,20 +6,18 @@
#include "pointer_type.h"
#include "ui_interface.h"
int pointer_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int length = 0;
char cbuf[200];
char *cpy = NULL;
int pointer_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
int length = 0;
char cbuf[200];
uint32_t value;
DISPLAY_PARSE_INFO("pointer", type->name, offset, parent_offset);
memset (cbuf, 0, 200);
// int i;
// CHECK_FCT(buffer_has_enouch_data(buffer, offset, type->size / 8));
uint32_t value;
value = buffer_get_uint32_t (buffer, parent_offset + offset);
DISPLAY_TYPE("Ptr");
......@@ -39,12 +37,8 @@ int pointer_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
return 0;
}
......
......@@ -3,8 +3,9 @@
#ifndef POINTER_TYPE_H_
#define POINTER_TYPE_H_
int pointer_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int pointer_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int pointer_type_file_print(struct types_s *type, int indent, FILE *file);
......
......@@ -6,8 +6,9 @@
#include "reference_type.h"
#include "ui_interface.h"
int reference_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent)
int reference_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
DISPLAY_PARSE_INFO("reference", type->name, offset, parent_offset);
......@@ -15,7 +16,8 @@ int reference_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
INDENTED(stdout, indent, fprintf(stdout, "<%s>\n", type->name));
}
if (type->child != NULL)
type->child->type_dissect_from_buffer(type->child, buffer, offset, parent_offset,
type->child->type_dissect_from_buffer(type->child, ui_set_signal_text_cb,
user_data, buffer, offset, parent_offset,
type->name == NULL ? indent: indent+4);
if (type->name) {
INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
......
......@@ -3,8 +3,9 @@
#ifndef REFERENCE_TYPE_H_
#define REFERENCE_TYPE_H_
int reference_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int reference_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int reference_type_file_print(struct types_s *type, int indent, FILE *file);
......
......@@ -9,12 +9,13 @@
#include "buffers.h"
#include "ui_interface.h"
int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int struct_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
int i;
int length = 0;
char cbuf[200];
char *cpy = NULL;
DISPLAY_PARSE_INFO("structure", type->name, offset, parent_offset);
......@@ -26,17 +27,15 @@ int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
for (i = 0; i < type->nb_members; i++) {
if (type->members_child[i] != NULL)
type->members_child[i]->type_dissect_from_buffer (type->members_child[i], buffer, offset, parent_offset,
type->name == NULL ? indent : indent + 4);
type->members_child[i]->type_dissect_from_buffer (
type->members_child[i], ui_set_signal_text_cb, user_data,
buffer, offset, parent_offset,
type->name == NULL ? indent : indent + 4);
}
DISPLAY_BRACE(
......@@ -45,11 +44,8 @@ int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n"));
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);)
ui_set_signal_text_cb(user_data, cbuf, length);)
return 0;
}
......
......@@ -3,8 +3,9 @@
#ifndef STRUCT_TYPE_H_
#define STRUCT_TYPE_H_
int struct_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int struct_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int struct_type_hr_display(struct types_s *type, int indent);
......
......@@ -6,15 +6,16 @@
#include "typedef_type.h"
#include "ui_interface.h"
int typedef_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent)
int typedef_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
DISPLAY_PARSE_INFO("typedef", type->name, offset, parent_offset);
/* Simply call next_type */
if (type->child != NULL) {
type->child->type_dissect_from_buffer(
type->child, buffer, offset, parent_offset, indent);
type->child, ui_set_signal_text_cb, user_data, buffer, offset, parent_offset, indent);
}
return 0;
......
......@@ -7,7 +7,8 @@ int typedef_type_file_print(struct types_s *type, int indent, FILE *file);
int typedef_type_hr_display(struct types_s *type, int indent);
int typedef_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int typedef_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
#endif /* TYPEDEF_TYPE_H_ */
#include <stdio.h>
#include "buffers.h"
#include "ui_interface.h"
#ifndef TYPES_H_
#define TYPES_H_
......@@ -15,17 +16,17 @@
#define ENABLE_DISPLAY_BRACE 0
#if (ENABLE_DISPLAY_TYPE != 0)
# define DISPLAY_TYPE(tYPE) ui_interface.ui_signal_set_text(tYPE, strlen(tYPE));
# define DISPLAY_TYPE(tYPE) ui_set_signal_text_cb(user_data, tYPE, strlen(tYPE));
#else
# define DISPLAY_TYPE(tYPE)
#endif
#if (ENABLE_DISPLAY_PARSE_INFO != 0)
# define DISPLAY_PARSE_INFO(tYPE, nAME, oFFSET, pARENToFFSET) \
{ \
char buf[200]; \
# define DISPLAY_PARSE_INFO(tYPE, nAME, oFFSET, pARENToFFSET) \
{ \
char buf[200]; \
sprintf(buf, "/* %s \"%s\" %d %d */\n", tYPE, nAME, oFFSET, pARENToFFSET); \
ui_interface.ui_signal_set_text(buf, strlen(buf)); \
ui_set_signal_text_cb(user_data, buf, strlen(buf)); \
}
#else
# define DISPLAY_PARSE_INFO(tYPE, nAME, oFFSET, pARENToFFSET)
......@@ -63,12 +64,15 @@ typedef int (*type_file_print_t)(struct types_s *type, int indent, FILE *file);
/**
* type_dissect_from_buffer_t
* @param type The current type
* @param ui_set_signal_text_cb GUI display function
* @param user_data Transparent data to pass to the GUI display function
* @param buffer The buffer containing data to dissect
* @param offset offset of field from the beginning of the parent
* @param parent_offset offset of the parent from begining
**/
typedef int (*type_dissect_from_buffer_t)(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
typedef int (*type_dissect_from_buffer_t)(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
typedef struct types_s {
/* The type of the current description */
......@@ -152,7 +156,7 @@ do { \
#define INDENTED_STRING(sTR, x, y) \
do { \
int indentation = x; \
while(indentation--) ui_interface.ui_signal_set_text(" ", 1); \
while(indentation--) ui_set_signal_text_cb(user_data, " ", 1); \
y; \
} while(0)
......
......@@ -10,8 +10,10 @@
#include "ui_interface.h"
/* There is only one special case of union which is associated to an index: the message id */
int union_msg_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int union_msg_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
uint32_t message_id;
DISPLAY_PARSE_INFO("union_msg", type->name, offset, parent_offset);
......@@ -19,17 +21,19 @@ int union_msg_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32
CHECK_FCT(get_message_id(type->head, buffer, &message_id));
if (type->members_child[message_id] != NULL)
type->members_child[message_id]->type_dissect_from_buffer (type->members_child[message_id], buffer, offset,
parent_offset, indent);
type->members_child[message_id]->type_dissect_from_buffer(
type->members_child[message_id], ui_set_signal_text_cb, user_data,
buffer, offset, parent_offset, indent);
return RC_OK;
}
int union_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t offset, uint32_t parent_offset,
int indent) {
int union_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent)
{
int length = 0;
char cbuf[200];
char *cpy = NULL;
DISPLAY_PARSE_INFO("union", type->name, offset, parent_offset);
......@@ -44,31 +48,23 @@ int union_dissect_from_buffer(struct types_s *type, buffer_t *buffer, uint32_t o
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
/* Only dissect the first field present in unions */
if (type->members_child[0] != NULL)
type->members_child[0]->type_dissect_from_buffer (type->members_child[0], buffer, offset, parent_offset,
type->name == NULL ? indent : indent + 4);
type->members_child[0]->type_dissect_from_buffer(
type->members_child[0], ui_set_signal_text_cb, user_data, buffer,
offset, parent_offset, type->name == NULL ? indent : indent + 4);
if (type->name) {
// INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
DISPLAY_TYPE("Uni");
INDENTED_STRING(cbuf, indent, sprintf(cbuf, "};\n"));
}
length = strlen (cbuf);
cpy = malloc (length * sizeof(char));
memcpy (cpy, cbuf, length);
ui_interface.ui_signal_set_text (cpy, length);
if (cpy)
free (cpy);
ui_set_signal_text_cb(user_data, cbuf, length);
return 0;
}
......
......@@ -3,11 +3,13 @@
#ifndef UNION_TYPE_H_
#define UNION_TYPE_H_
int union_msg_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int union_msg_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int union_dissect_from_buffer(struct types_s *type, buffer_t *buffer,
uint32_t offset, uint32_t parent_offset, int indent);
int union_dissect_from_buffer(
struct types_s *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data,
buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent);
int union_type_file_print(struct types_s *type, int indent, FILE *file);
......
......@@ -729,22 +729,21 @@ static int xml_parse_doc(xmlDocPtr doc) {
return ret;
}
int dissect_signal(buffer_t *buffer) {
// buffer_t *buffer;
int dissect_signal(buffer_t *buffer, ui_set_signal_text_cb_t ui_set_signal_text_cb,
gpointer user_data)
{
if (root == NULL) {
// ui_notification_dialog(DIALOG_ERROR, "No message XML file provided");
return RC_FAIL;
}
// CHECK_FCT(buffer_get_from_mn(message_number, &buffer));
if (buffer == NULL) {
g_error("Failed buffer is NULL\n");
return RC_FAIL;
}
root->type_dissect_from_buffer(root, buffer, 0, 0, INDENT_START);
root->type_dissect_from_buffer(root, ui_set_signal_text_cb, user_data,
buffer, 0, 0, INDENT_START);
return RC_OK;
}
......@@ -10,6 +10,7 @@ int xml_parse_file(const char *filename);
int xml_parse_buffer(const char *xml_buffer, const int size);
int dissect_signal(buffer_t *buffer);
int dissect_signal(buffer_t *buffer, ui_set_signal_text_cb_t ui_set_signal_text_cb,
gpointer user_data);
#endif /* XML_PARSE_H_ */
......@@ -2,6 +2,7 @@ AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir)/common \
-I$(top_srcdir)/libparser \
-I$(top_srcdir)/libui \
-I$(top_srcdir)/libbuffers
noinst_LTLIBRARIES = libresolver.la
......
......@@ -43,13 +43,18 @@ ui_callback_on_select_signal(GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer userdata)
gpointer user_data)
{
ui_text_view_t *text_view;
GtkTreeIter iter;
text_view = (ui_text_view_t *)user_data;
g_assert(text_view != NULL);
if (gtk_tree_model_get_iter(model, &iter, path))
{
gchar *name;
// gchar *name;
GValue buffer_store = G_VALUE_INIT;
gpointer buffer;
......@@ -64,15 +69,17 @@ ui_callback_on_select_signal(GtkTreeSelection *selection,
if (!path_currently_selected)
{
/* Clear the view */
CHECK_FCT_DO(ui_signal_dissect_clear_view(), return FALSE);
CHECK_FCT_DO(dissect_signal((buffer_t*)buffer), return FALSE);
}
else
{
g_debug("%s is going to be unselected", name);
}
CHECK_FCT_DO(ui_signal_dissect_clear_view(text_view), return FALSE);
g_free(name);
/* Dissect the signal */
CHECK_FCT_DO(dissect_signal((buffer_t*)buffer, ui_signal_set_text, text_view), return FALSE);
}
// else
// {
// g_debug("%s is going to be unselected", name);
// }
//
// g_free(name);
}
return TRUE;
}
......@@ -92,7 +99,7 @@ void ui_signal_add_to_list(gpointer data, gpointer user_data)
data);
}
static gboolean ui_handle_update_signal_list(gint fd, const void *data,
static gboolean ui_handle_update_signal_list(gint fd, void *data,
size_t data_length)
{
pipe_new_signals_list_message_t *signal_list_message;
......@@ -145,7 +152,7 @@ static gboolean ui_handle_socket_connection_lost(gint fd)
return TRUE;
}
static gboolean ui_handle_socket_xml_definition(gint fd, const void *data,
static gboolean ui_handle_socket_xml_definition(gint fd, void *data,
size_t data_length)
{
pipe_xml_definition_message_t *xml_definition_message;
......
......@@ -13,11 +13,6 @@
#include "socket.h"
#include "xml_parse.h"
ui_interface_t ui_interface = {
.ui_signal_set_text = ui_signal_set_text,
};
static
gboolean ui_callback_on_pipe_notification(
GIOChannel *source, GIOCondition condition, gpointer user_data)
......
......@@ -3,15 +3,11 @@
#ifndef UI_INTERFACE_H_
#define UI_INTERFACE_H_
typedef int (*ui_signal_set_text_t)(char *text, int length);
typedef struct {
/** core program -> UI */
ui_signal_set_text_t ui_signal_set_text;
} ui_interface_t;
/*******************************************************************************
* Functions used between dissectors and GUI to update signal dissection
******************************************************************************/
extern ui_interface_t ui_interface;
typedef gboolean (*ui_set_signal_text_cb_t) (gpointer user_data, gchar *text, gint length);
/*******************************************************************************
* Pipe interface between GUI thread and other thread
......
#include "ui_signal_dissect_view.h"
#ifndef UI_MAIN_SCREEN_H_
#define UI_MAIN_SCREEN_H_
......@@ -6,9 +8,9 @@ typedef struct {
GtkWidget *ipentry;
GtkWidget *portentry;
GtkWidget *progressbar;
GtkWidget *signalslist;
GtkWidget *textview;
GtkWidget *progressbar;
GtkWidget *signalslist;
ui_text_view_t *text_view;
/* Buttons */
GtkToolItem *connect;
......
......@@ -8,67 +8,74 @@
#include "ui_menu_bar.h"
#include "ui_signal_dissect_view.h"
int ui_signal_dissect_new(GtkWidget *hbox)
ui_text_view_t *ui_signal_dissect_new(GtkWidget *hbox)
{
GtkWidget *scrolled_window;
ui_text_view_t *new_text_view;
ui_main_data.textview = gtk_text_view_new();
new_text_view = malloc(sizeof(ui_text_view_t));
new_text_view->text_view = gtk_text_view_new();
scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
CHECK_BUFFER(ui_main_data.textview);
/* Disable editable attribute */
gtk_text_view_set_editable(GTK_TEXT_VIEW(ui_main_data.textview), FALSE);
gtk_text_view_set_editable(GTK_TEXT_VIEW(new_text_view->text_view), FALSE);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
ui_main_data.textview);
new_text_view->text_view);
gtk_box_pack_start(GTK_BOX(hbox), scrolled_window, TRUE, TRUE, 5);
return 0;
return new_text_view;
}
int ui_signal_dissect_clear_view(void)
int ui_signal_dissect_clear_view(ui_text_view_t *text_view)
{
GtkTextBuffer *textbuffer;
GtkTextBuffer *text_buffer;
textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui_main_data.textview));
g_assert(text_view != NULL);
CHECK_BUFFER(textbuffer);
text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view->text_view));
/* If a text buffer is present for the textview remove it */
if (textbuffer) {
gtk_text_view_set_buffer(GTK_TEXT_VIEW(ui_main_data.textview), NULL);
// g_object_unref(textbuffer);
if (text_buffer != NULL) {
gtk_text_view_set_buffer(GTK_TEXT_VIEW(text_view->text_view), NULL);
}
return RC_OK;
}
int ui_signal_set_text(char *text, int length)
gboolean ui_signal_set_text(gpointer user_data, gchar *text, gint length)
{
GtkTextBuffer *textbuffer;
GtkTextBuffer *text_buffer;
ui_text_view_t *text_view;
if (length < 0)
return RC_BAD_PARAM;
return FALSE;
CHECK_BUFFER(text);
text_view = (ui_text_view_t *)user_data;
// fprintf (stdout, "%*s", length, text);
g_assert(text != NULL);
g_assert(text_view != NULL);
g_assert(text_view->text_view != NULL);
textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui_main_data.textview));
g_assert(GTK_IS_TEXT_VIEW(GTK_TEXT_VIEW(text_view->text_view)));
if (textbuffer) {
text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view->text_view));
if (text_buffer) {
/* We already have a text buffer, use it */
gtk_text_buffer_insert_at_cursor(textbuffer, text, length);
gtk_text_buffer_insert_at_cursor(text_buffer, text, length);
} else {
/* No buffer currently in use, create a new one */
textbuffer = gtk_text_buffer_new(NULL);
gtk_text_buffer_set_text(textbuffer, text, length);
gtk_text_view_set_buffer(GTK_TEXT_VIEW(ui_main_data.textview), textbuffer);
text_buffer = gtk_text_buffer_new(NULL);
gtk_text_buffer_set_text(text_buffer, text, length);
gtk_text_view_set_buffer(GTK_TEXT_VIEW(text_view->text_view),
text_buffer);
}
return RC_OK;
return TRUE;
}
#ifndef UI_SIGNAL_DISSECT_VIEW_H_
#define UI_SIGNAL_DISSECT_VIEW_H_
int ui_signal_dissect_new(GtkWidget *hbox);
typedef struct {
GtkWidget *text_view;
} ui_text_view_t;
int ui_signal_set_text(char *text, int length);
ui_text_view_t *ui_signal_dissect_new(GtkWidget *hbox);
int ui_signal_dissect_clear_view(void);
int ui_signal_dissect_clear_view(ui_text_view_t *text_view);
gboolean ui_signal_set_text(gpointer user_data, gchar *text, gint length);
#endif /*UI_SIGNAL_DISSECT_VIEW_H_ */
......@@ -50,6 +50,8 @@ ui_tree_view_init_list(GtkWidget *list)
gtk_tree_view_set_model(GTK_TREE_VIEW(list), GTK_TREE_MODEL(store));
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(list));
g_object_unref(store);
}
......@@ -117,7 +119,7 @@ int ui_tree_view_create(GtkWidget *window, GtkWidget *vbox)
// gtk_widget_get_size_request(GTK_WIDGET(ui_main_data.signalslist), &width, NULL);
gtk_widget_set_size_request(GTK_WIDGET(scrolled_window), 350, -1);
gtk_box_pack_start(GTK_BOX(hbox), scrolled_window, FALSE, FALSE, 0);
CHECK_FCT(ui_signal_dissect_new(hbox));
ui_main_data.text_view = ui_signal_dissect_new(hbox);
gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
......@@ -125,7 +127,8 @@ int ui_tree_view_create(GtkWidget *window, GtkWidget *vbox)
// G_CALLBACK(ui_callback_on_select_signal), NULL);
/* Connect callback on row selection */
gtk_tree_selection_set_select_function(selection, ui_callback_on_select_signal, NULL, NULL);
gtk_tree_selection_set_select_function(selection, ui_callback_on_select_signal,
ui_main_data.text_view, NULL);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment