"...conf_files/enb.band7.tm1.25PRB.slave.usrpb210.conf" did not exist on "24b46f3f020ca5f59033199b1a38fd0bbc26294d"
ui_callbacks.c 26.8 KB
Newer Older
1 2 3 4
#if HAVE_CONFIG_H
# include "config.h"
#endif

Cedric Roux's avatar
 
Cedric Roux committed
5 6 7
#include <stdlib.h>
#include <stdint.h>

8 9
#define G_LOG_DOMAIN ("UI_CB")

Cedric Roux's avatar
 
Cedric Roux committed
10 11
#include <gtk/gtk.h>

12
#include "logs.h"
13
#include "rc.h"
Cedric Roux's avatar
 
Cedric Roux committed
14

Cedric Roux's avatar
Cedric Roux committed
15 16 17
#include "socket.h"

#include "ui_notif_dlg.h"
Cedric Roux's avatar
 
Cedric Roux committed
18
#include "ui_main_screen.h"
19
#include "ui_menu_bar.h"
Cedric Roux's avatar
 
Cedric Roux committed
20 21 22 23 24
#include "ui_callbacks.h"
#include "ui_interface.h"
#include "ui_notifications.h"
#include "ui_tree_view.h"
#include "ui_signal_dissect_view.h"
winckel's avatar
winckel committed
25
#include "ui_filters.h"
26
#include "ui_notebook.h"
Cedric Roux's avatar
 
Cedric Roux committed
27

Cedric Roux's avatar
Cedric Roux committed
28 29 30 31
#include "types.h"
#include "locate_root.h"
#include "xml_parse.h"

32 33 34
static gboolean refresh_message_list = TRUE;
static gboolean filters_changed = FALSE;

35
gboolean ui_callback_on_open_messages(GtkWidget *widget, gpointer data)
Cedric Roux's avatar
 
Cedric Roux committed
36
{
winckel's avatar
winckel committed
37 38
    gboolean refresh = (data != NULL) ? TRUE : FALSE;

39
    g_message("Open messages event occurred %d", refresh);
winckel's avatar
winckel committed
40 41 42 43 44 45 46 47 48

    if (refresh && (ui_main_data.messages_file_name != NULL))
    {
        CHECK_FCT(ui_messages_read (ui_main_data.messages_file_name));
    }
    else
    {
        CHECK_FCT(ui_messages_open_file_chooser());
    }
49 50 51 52

    return TRUE;
}

53
gboolean ui_callback_on_save_messages(GtkWidget *widget, gpointer data)
54
{
55
    g_message("Save messages event occurred");
56 57 58

    CHECK_FCT(ui_messages_save_file_chooser());

59 60 61
    return TRUE;
}

62
gboolean ui_callback_on_filters_enabled(GtkToolButton *button, gpointer data)
63 64 65 66
{
    gboolean enabled;
    gboolean changed;

67
    enabled = gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON(button));
68

69
    g_info("Filters enabled event occurred %d", enabled);
70

71
    changed = ui_filters_enable (enabled);
72 73 74

    if (changed)
    {
75
        /* Set the tool tip text */
76 77
        if (enabled)
        {
78
            gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM(button), "Disable messages filtering");
79 80
        }
        else
81
        {
82
            gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM(button), "Enable messages filtering");
83
        }
84
        ui_tree_view_refilter ();
85 86 87 88 89
    }

    return TRUE;
}

90
gboolean ui_callback_on_open_filters(GtkWidget *widget, gpointer data)
91
{
92 93
    gboolean refresh = (data != NULL) ? TRUE : FALSE;

94
    g_message("Open filters event occurred");
95 96 97 98 99 100 101 102 103 104

    if (refresh && (ui_main_data.filters_file_name != NULL))
    {
        CHECK_FCT(ui_filters_read (ui_main_data.filters_file_name));
    }
    else
    {
        CHECK_FCT(ui_filters_open_file_chooser());
    }

105 106 107
    return TRUE;
}

108
gboolean ui_callback_on_save_filters(GtkWidget *widget, gpointer data)
109
{
110
    g_message("Save filters event occurred");
111
    CHECK_FCT(ui_filters_save_file_chooser());
Cedric Roux's avatar
 
Cedric Roux committed
112 113 114
    return TRUE;
}

115
gboolean ui_callback_on_enable_filters(GtkWidget *widget, gpointer data)
winckel's avatar
winckel committed
116 117 118
{
    gboolean enabled;

119 120
    enabled = gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON(ui_main_data.filters_enabled));
    gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON(ui_main_data.filters_enabled), !enabled);
winckel's avatar
winckel committed
121 122 123 124

    return TRUE;
}

125
gboolean ui_callback_on_about(GtkWidget *widget, gpointer data)
Cedric Roux's avatar
 
Cedric Roux committed
126
{
127
#if defined(PACKAGE_STRING)
winckel's avatar
winckel committed
128
    ui_notification_dialog (GTK_MESSAGE_INFO, FALSE, "about", "Eurecom %s", PACKAGE_STRING);
129
#else
winckel's avatar
winckel committed
130
    ui_notification_dialog (GTK_MESSAGE_INFO, FALSE, "about", "Eurecom itti_analyzer");
131
#endif
Cedric Roux's avatar
 
Cedric Roux committed
132 133 134 135

    return TRUE;
}

136 137
gboolean ui_callback_on_select_signal(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path,
                                      gboolean path_currently_selected, gpointer user_data)
Cedric Roux's avatar
 
Cedric Roux committed
138
{
winckel's avatar
winckel committed
139
    static gpointer buffer_current;
140
    ui_text_view_t *text_view;
Cedric Roux's avatar
 
Cedric Roux committed
141 142
    GtkTreeIter iter;

143
    g_debug("Message selected %d %p %p %s", path_currently_selected, buffer_current, path, gtk_tree_path_to_string(path));
Cedric Roux's avatar
 
Cedric Roux committed
144

winckel's avatar
winckel committed
145 146 147
    if (!path_currently_selected)
    {
        text_view = (ui_text_view_t *) user_data;
Cedric Roux's avatar
Cedric Roux committed
148

winckel's avatar
winckel committed
149
        g_assert(text_view != NULL);
Cedric Roux's avatar
 
Cedric Roux committed
150

151
        if (gtk_tree_model_get_iter (model, &iter, path))
winckel's avatar
winckel committed
152 153
        {
            gpointer buffer;
Cedric Roux's avatar
Cedric Roux committed
154

winckel's avatar
winckel committed
155
            uint32_t message_number;
156 157 158
            uint32_t message_id;
            uint32_t origin_task_id;
            uint32_t destination_task_id;
winckel's avatar
winckel committed
159
            char *instance_name;
160 161
            uint32_t instance;
            char label[100];
Cedric Roux's avatar
Cedric Roux committed
162

winckel's avatar
winckel committed
163
            gtk_tree_model_get (model, &iter, COL_MSG_NUM, &message_number, COL_MESSAGE_ID, &message_id,
winckel's avatar
winckel committed
164 165
                                COL_FROM_TASK_ID, &origin_task_id, COL_TO_TASK_ID, &destination_task_id, COL_INSTANCE, &instance_name,
                                COL_INSTANCE_ID, &instance, COL_BUFFER, &buffer, -1);
Cedric Roux's avatar
Cedric Roux committed
166

winckel's avatar
winckel committed
167
            g_debug("  Get iter %p %p", buffer_current, buffer);
Cedric Roux's avatar
Cedric Roux committed
168

169 170
            if (ui_tree_view_last_event)
            {
171
                g_debug("last_event %p %d %d", ui_tree_view_last_event, ui_tree_view_last_event->type, ui_tree_view_last_event->button);
172 173 174 175 176 177 178 179 180 181 182 183 184 185

                if (ui_tree_view_last_event->type == GDK_BUTTON_PRESS)
                {
                    /* Callback is due to a button click */
                    ui_main_data.follow_last = FALSE;

                    if (ui_tree_view_last_event->button == 3)
                    {
                        /* It was a right mouse click */
                        int item;

                        /* Clear event */
                        ui_tree_view_last_event = NULL;

186 187
                        /* Create filter menus to refers its items in the pop-up menu */
                        ui_create_filter_menus ();
188

189
                        g_info("Message selected right click %d %d %d %d", message_id, origin_task_id, destination_task_id, instance);
190

191 192 193
                        /* Message Id menu */
                        {
                            /* Invalidate associated menu item to avoid issue with call back when updating the menu item check state */
194
                            ui_tree_view_menu_enable[MENU_MESSAGE].filter_item = NULL;
195
                            item = ui_filters_search_id (&ui_filters.messages, message_id);
196
                            /* Update the menu item check state based on message ID state */
197
                            gtk_check_menu_item_set_active (
198 199 200
                                    GTK_CHECK_MENU_ITEM(ui_tree_view_menu_enable[MENU_MESSAGE].menu_enable),
                                    ui_filters.messages.items[item].enabled);
                            /* Set menu item label */
201 202 203
                            sprintf (label, "Message:  %s", message_id_to_string (message_id));
                            gtk_menu_item_set_label (GTK_MENU_ITEM(ui_tree_view_menu_enable[MENU_MESSAGE].menu_enable),
                                                     label);
204
                            /* Save menu item associated to this row */
205
                            ui_tree_view_menu_enable[MENU_MESSAGE].filter_item = &ui_filters.messages.items[item];
206 207 208 209 210
                        }

                        /* Origin task id */
                        {
                            /* Invalidate associated menu item to avoid issue with call back when updating the menu item check state */
211
                            ui_tree_view_menu_enable[MENU_FROM_TASK].filter_item = NULL;
212
                            item = ui_filters_search_id (&ui_filters.origin_tasks, origin_task_id);
213
                            /* Update the menu item check state based on message ID state */
214
                            gtk_check_menu_item_set_active (
215 216 217
                                    GTK_CHECK_MENU_ITEM(ui_tree_view_menu_enable[MENU_FROM_TASK].menu_enable),
                                    ui_filters.origin_tasks.items[item].enabled);
                            /* Set menu item label */
218 219 220
                            sprintf (label, "From:  %s", task_id_to_string (origin_task_id, origin_task_id_type));
                            gtk_menu_item_set_label (
                                    GTK_MENU_ITEM(ui_tree_view_menu_enable[MENU_FROM_TASK].menu_enable), label);
221
                            /* Save menu item associated to this row */
222
                            ui_tree_view_menu_enable[MENU_FROM_TASK].filter_item = &ui_filters.origin_tasks.items[item];
223 224 225 226 227
                        }

                        /* Destination task id */
                        {
                            /* Invalidate associated menu item to avoid issue with call back when updating the menu item check state */
228
                            ui_tree_view_menu_enable[MENU_TO_TASK].filter_item = NULL;
229
                            item = ui_filters_search_id (&ui_filters.destination_tasks, destination_task_id);
230
                            /* Update the menu item check state based on message ID state */
231
                            gtk_check_menu_item_set_active (
232 233 234
                                    GTK_CHECK_MENU_ITEM(ui_tree_view_menu_enable[MENU_TO_TASK].menu_enable),
                                    ui_filters.destination_tasks.items[item].enabled);
                            /* Set menu item label */
235 236 237 238
                            sprintf (label, "To:  %s",
                                     task_id_to_string (destination_task_id, destination_task_id_type));
                            gtk_menu_item_set_label (GTK_MENU_ITEM(ui_tree_view_menu_enable[MENU_TO_TASK].menu_enable),
                                                     label);
239
                            /* Save menu item associated to this row */
240 241
                            ui_tree_view_menu_enable[MENU_TO_TASK].filter_item =
                                    &ui_filters.destination_tasks.items[item];
242 243 244 245 246
                        }

                        /* Instance */
                        {
                            /* Invalidate associated menu item to avoid issue with call back when updating the menu item check state */
247
                            ui_tree_view_menu_enable[MENU_INSTANCE].filter_item = NULL;
248
                            item = ui_filters_search_id (&ui_filters.instances, instance);
249
                            /* Update the menu item check state based on message ID state */
250
                            gtk_check_menu_item_set_active (
251 252 253
                                    GTK_CHECK_MENU_ITEM(ui_tree_view_menu_enable[MENU_INSTANCE].menu_enable),
                                    ui_filters.instances.items[item].enabled);
                            /* Set menu item label */
winckel's avatar
winckel committed
254
                            sprintf (label, "Instance:  %s", instance_name);
255 256
                            gtk_menu_item_set_label (GTK_MENU_ITEM(ui_tree_view_menu_enable[MENU_INSTANCE].menu_enable),
                                                     label);
257
                            /* Save menu item associated to this row */
258
                            ui_tree_view_menu_enable[MENU_INSTANCE].filter_item = &ui_filters.instances.items[item];
259 260
                        }

261 262
                        gtk_menu_popup (GTK_MENU (ui_tree_view_menu), NULL, NULL, NULL, NULL, 0,
                                        gtk_get_current_event_time ());
263 264 265 266 267 268 269
                    }
                }

                /* Clear event */
                ui_tree_view_last_event = NULL;
            }

winckel's avatar
winckel committed
270
            if (buffer_current != buffer)
271
            {
winckel's avatar
winckel committed
272 273 274 275 276 277 278 279 280 281
                buffer_current = buffer;

                /* Clear the view */
                CHECK_FCT_DO(ui_signal_dissect_clear_view(text_view), return FALSE);

                if (ui_main_data.display_message_header)
                {
                    CHECK_FCT_DO(dissect_signal_header((buffer_t*)buffer, ui_signal_set_text, text_view), return FALSE);
                }

282 283 284 285 286 287
                if ((strcmp (message_id_to_string (message_id), "ERROR_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "WARNING_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "NOTICE_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "INFO_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "DEBUG_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "GENERIC_LOG") == 0))
winckel's avatar
winckel committed
288 289 290 291 292 293 294
                {
                    gchar *data;
                    gint data_size;
                    uint32_t message_header_type_size;

                    if (ui_main_data.display_message_header)
                    {
295
                        ui_signal_set_text (text_view, "\n", 1);
winckel's avatar
winckel committed
296 297
                    }

298 299 300
                    message_header_type_size = get_message_header_type_size ();
                    data = (gchar *) buffer_at_offset ((buffer_t*) buffer, message_header_type_size);
                    data_size = get_message_size ((buffer_t*) buffer);
winckel's avatar
winckel committed
301

winckel's avatar
winckel committed
302 303
                    g_info("    dump message %d: header type size: %u, data size: %u, buffer %p, follow last %d",
                           message_number, message_header_type_size, data_size, buffer, ui_main_data.follow_last);
winckel's avatar
winckel committed
304

305
                    ui_signal_set_text (text_view, data, data_size);
306 307
                }
                else
winckel's avatar
winckel committed
308
                {
winckel's avatar
winckel committed
309
                    g_info("    dissect message %d: id %d, buffer %p, follow last %d", message_number, message_id, buffer, ui_main_data.follow_last);
winckel's avatar
winckel committed
310 311 312 313

                    /* Dissect the signal */
                    CHECK_FCT_DO(dissect_signal((buffer_t*)buffer, ui_signal_set_text, text_view), return FALSE);
                }
Cedric Roux's avatar
Cedric Roux committed
314
            }
315
        }
Cedric Roux's avatar
 
Cedric Roux committed
316 317 318 319
    }
    return TRUE;
}

320
gboolean ui_callback_on_menu_enable(GtkWidget *widget, gpointer data)
321 322 323
{
    ui_tree_view_menu_enable_t *menu_enable = data;

324
    if (menu_enable->filter_item != NULL)
325
    {
326 327
        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(menu_enable->filter_item->menu_item),
                                        gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(menu_enable->menu_enable)));
328
        menu_enable->filter_item = NULL;
329 330 331 332 333
    }

    return TRUE;
}

334
gboolean ui_callback_on_menu_color(GtkWidget *widget, gpointer data)
335
{
336
    ui_tree_view_menu_color_t *menu_color = data;
337

338 339 340 341
    GdkRGBA color;
    GtkWidget *color_chooser;
    gint response;

342 343 344
    color_chooser = gtk_color_chooser_dialog_new ("Select message background color", GTK_WINDOW(ui_main_data.window));
    gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(color_chooser), FALSE);
    response = gtk_dialog_run (GTK_DIALOG (color_chooser));
345 346 347

    if (response == GTK_RESPONSE_OK)
    {
348
        int red, green, blue;
349 350 351 352 353 354
        char *color_string;

        color_string =
                menu_color->foreground ?
                        menu_color->menu_enable->filter_item->foreground :
                        menu_color->menu_enable->filter_item->background;
355

356
        gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(color_chooser), &color);
357

358 359 360 361
        red = (int) (color.red * 255);
        green = (int) (color.green * 255);
        blue = (int) (color.blue * 255);

362 363 364
        snprintf (color_string, COLOR_SIZE, "#%02x%02x%02x", red, green, blue);
        ui_tree_view_refilter ();

365
        g_info("Selected color for %s %f->%02x %f->%02x %f->%02x %s",
366
                  menu_color->menu_enable->filter_item->name, color.red, red, color.green, green, color.blue, blue, color_string);
367
    }
368
    gtk_widget_destroy (color_chooser);
369 370 371 372

    return TRUE;
}

373
void ui_signal_add_to_list(gpointer data, gpointer user_data)
Cedric Roux's avatar
Cedric Roux committed
374
{
winckel's avatar
winckel committed
375
    gboolean goto_last = user_data ? TRUE : FALSE;
Cedric Roux's avatar
Cedric Roux committed
376
    buffer_t *signal_buffer;
377 378
    GtkTreePath *path;
    GtkTreeViewColumn *focus_column;
379 380
    uint32_t lte_frame;
    uint32_t lte_slot;
381 382
    uint32_t origin_task_id;
    uint32_t destination_task_id;
winckel's avatar
winckel committed
383
    uint32_t instance;
384 385
    char lte_time[15];

386 387 388 389
    g_assert(data != NULL);
    g_assert(origin_task_id_type != NULL);
    g_assert(destination_task_id_type != NULL);

390
    gtk_tree_view_get_cursor (GTK_TREE_VIEW(ui_main_data.messages_list), &path, &focus_column);
Cedric Roux's avatar
Cedric Roux committed
391

392
    signal_buffer = (buffer_t *) data;
Cedric Roux's avatar
Cedric Roux committed
393

394 395 396
    lte_frame = get_lte_frame (signal_buffer);
    lte_slot = get_lte_slot (signal_buffer);
    sprintf (lte_time, "%d.%02d", lte_frame, lte_slot);
397

398 399 400 401
    get_message_id (root, signal_buffer, &signal_buffer->message_id);
    origin_task_id = get_task_id (signal_buffer, origin_task_id_type);
    destination_task_id = get_task_id (signal_buffer, destination_task_id_type);
    instance = get_instance (signal_buffer);
402

403 404 405 406
    ui_tree_view_new_signal_ind (signal_buffer->message_number, lte_time, signal_buffer->message_id,
                                 message_id_to_string (signal_buffer->message_id), origin_task_id,
                                 task_id_to_string (origin_task_id, origin_task_id_type), destination_task_id,
                                 task_id_to_string (destination_task_id, destination_task_id_type), instance, data);
407

408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
    if ((strcmp (message_id_to_string (signal_buffer->message_id), "ERROR_LOG") == 0)
            || (strcmp (message_id_to_string (signal_buffer->message_id), "WARNING_LOG") == 0)
            || (strcmp (message_id_to_string (signal_buffer->message_id), "NOTICE_LOG") == 0)
            || (strcmp (message_id_to_string (signal_buffer->message_id), "INFO_LOG") == 0)
            || (strcmp (message_id_to_string (signal_buffer->message_id), "DEBUG_LOG") == 0)
            || (strcmp (message_id_to_string (signal_buffer->message_id), "GENERIC_LOG") == 0))
    {
        gchar *string_terminal;
        gint string_terminal_size;
        uint32_t message_header_type_size;

        message_header_type_size = get_message_header_type_size ();
        string_terminal = (gchar *) buffer_at_offset ((buffer_t*) signal_buffer, message_header_type_size);
        string_terminal_size = get_message_size ((buffer_t*) signal_buffer);

        ui_notebook_terminal_append_data(string_terminal, string_terminal_size);
    }

426 427
    /* Increment number of messages */
    ui_main_data.nb_message_received++;
428

winckel's avatar
winckel committed
429
    if ((ui_main_data.follow_last) && (goto_last))
430 431
    {
        /* Advance to the new last signal */
432
        ui_tree_view_select_row (ui_tree_view_get_filtered_number () - 1);
433
    }
Cedric Roux's avatar
Cedric Roux committed
434 435
}

436
static gboolean ui_handle_update_signal_list(gint fd, void *data, size_t data_length)
Cedric Roux's avatar
Cedric Roux committed
437 438 439
{
    pipe_new_signals_list_message_t *signal_list_message;

440
    /* Enable buttons to move in the list of signals */
441
    ui_set_sensitive_move_buttons (TRUE);
442

443
    signal_list_message = (pipe_new_signals_list_message_t *) data;
Cedric Roux's avatar
Cedric Roux committed
444 445 446 447

    g_assert(signal_list_message != NULL);
    g_assert(signal_list_message->signal_list != NULL);

448
    g_list_foreach (signal_list_message->signal_list, ui_signal_add_to_list, (gpointer) TRUE);
Cedric Roux's avatar
Cedric Roux committed
449

450
    /* Free the list but not user data associated with each element */
451
    g_list_free (signal_list_message->signal_list);
452
    /* Free the message */
453
    free (signal_list_message);
Cedric Roux's avatar
Cedric Roux committed
454

455
    ui_gtk_flush_events ();
456

Cedric Roux's avatar
Cedric Roux committed
457 458 459
    return TRUE;
}

460
static gboolean ui_handle_socket_connection_failed(gint fd)
Cedric Roux's avatar
Cedric Roux committed
461 462 463
{
    GtkWidget *dialogbox;

464 465 466
    dialogbox = gtk_message_dialog_new (GTK_WINDOW(ui_main_data.window), GTK_DIALOG_DESTROY_WITH_PARENT,
                                        GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
                                        "Failed to connect to provided host/ip address");
Cedric Roux's avatar
Cedric Roux committed
467

468 469
    gtk_dialog_run (GTK_DIALOG(dialogbox));
    gtk_widget_destroy (dialogbox);
Cedric Roux's avatar
Cedric Roux committed
470 471

    /* Re-enable connect button */
472
    ui_enable_connect_button ();
Cedric Roux's avatar
Cedric Roux committed
473 474 475
    return TRUE;
}

476
static gboolean ui_handle_socket_connection_lost(gint fd)
Cedric Roux's avatar
Cedric Roux committed
477 478 479
{
    GtkWidget *dialogbox;

480 481 482
    dialogbox = gtk_message_dialog_new (GTK_WINDOW(ui_main_data.window), GTK_DIALOG_DESTROY_WITH_PARENT,
                                        GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
                                        "Connection with remote host has been lost");
Cedric Roux's avatar
Cedric Roux committed
483

484 485
    gtk_dialog_run (GTK_DIALOG(dialogbox));
    gtk_widget_destroy (dialogbox);
Cedric Roux's avatar
Cedric Roux committed
486 487

    /* Re-enable connect button */
488
    ui_enable_connect_button ();
Cedric Roux's avatar
Cedric Roux committed
489 490 491
    return TRUE;
}

492
static gboolean ui_handle_socket_xml_definition(gint fd, void *data, size_t data_length)
Cedric Roux's avatar
Cedric Roux committed
493 494 495
{
    pipe_xml_definition_message_t *xml_definition_message;

496
    xml_definition_message = (pipe_xml_definition_message_t *) data;
Cedric Roux's avatar
Cedric Roux committed
497 498 499
    g_assert(xml_definition_message != NULL);
    g_assert(data_length == sizeof(pipe_xml_definition_message_t));

500
    xml_parse_buffer (xml_definition_message->xml_definition, xml_definition_message->xml_definition_length);
Cedric Roux's avatar
Cedric Roux committed
501 502 503 504

    return TRUE;
}

505
gboolean ui_pipe_callback(gint source, gpointer user_data)
Cedric Roux's avatar
Cedric Roux committed
506
{
507 508 509
    void *input_data = NULL;
    size_t input_data_length = 0;
    pipe_input_header_t input_header;
Cedric Roux's avatar
Cedric Roux committed
510 511

    /* Read the header */
512
    if (read (source, &input_header, sizeof(input_header)) < 0)
513
    {
Cedric Roux's avatar
Cedric Roux committed
514 515 516 517 518 519 520
        g_warning("Failed to read from pipe %d: %s", source, g_strerror(errno));
        return FALSE;
    }

    input_data_length = input_header.message_size - sizeof(input_header);

    /* Checking for non-header part */
521 522
    if (input_data_length > 0)
    {
523
        input_data = malloc (input_data_length);
Cedric Roux's avatar
Cedric Roux committed
524

525
        if (read (source, input_data, input_data_length) < 0)
526
        {
Cedric Roux's avatar
Cedric Roux committed
527 528 529 530 531
            g_warning("Failed to read from pipe %d: %s", source, g_strerror(errno));
            return FALSE;
        }
    }

532 533
    switch (input_header.message_type)
    {
534 535
        case UI_PIPE_CONNECTION_FAILED:
            return ui_handle_socket_connection_failed (source);
winckel's avatar
winckel committed
536

537 538
        case UI_PIPE_CONNECTION_LOST:
            return ui_handle_socket_connection_lost (source);
winckel's avatar
winckel committed
539 540 541 542

        case UI_PIPE_XML_DEFINITION:
            return ui_handle_socket_xml_definition (source, input_data, input_data_length);

543 544
        case UI_PIPE_UPDATE_SIGNAL_LIST:
            return ui_handle_update_signal_list (source, input_data, input_data_length);
winckel's avatar
winckel committed
545

546 547 548
        default:
            g_warning("[gui] Unhandled message type %u", input_header.message_type);
            g_assert_not_reached();
Cedric Roux's avatar
Cedric Roux committed
549 550 551 552
    }
    return FALSE;
}

553
gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data)
Cedric Roux's avatar
 
Cedric Roux committed
554 555 556
{
    /* We have to retrieve the ip address and port of remote host */
    const char *ip;
557 558
    uint16_t port;
    int pipe_fd[2];
Cedric Roux's avatar
 
Cedric Roux committed
559

560 561
    port = atoi (gtk_entry_get_text (GTK_ENTRY(ui_main_data.port_entry)));
    ip = gtk_entry_get_text (GTK_ENTRY(ui_main_data.ip_entry));
Cedric Roux's avatar
 
Cedric Roux committed
562

563 564
    g_message("Connect event occurred to %s:%d", ip, port);

565
    if (strlen (ip) == 0)
566
    {
winckel's avatar
winckel committed
567
        ui_notification_dialog (GTK_MESSAGE_WARNING, FALSE, "Connect", "Empty host ip address");
568 569 570 571
        return FALSE;
    }

    if (port == 0)
572
    {
winckel's avatar
winckel committed
573
        ui_notification_dialog (GTK_MESSAGE_WARNING, FALSE, "Connect", "Invalid host port value");
Cedric Roux's avatar
Cedric Roux committed
574 575 576
        return FALSE;
    }

577
    ui_pipe_new (pipe_fd, ui_pipe_callback, NULL);
Cedric Roux's avatar
Cedric Roux committed
578

579
    memcpy (ui_main_data.pipe_fd, pipe_fd, sizeof(int) * 2);
Cedric Roux's avatar
Cedric Roux committed
580 581

    /* Disable the connect button */
582
    ui_disable_connect_button ();
Cedric Roux's avatar
Cedric Roux committed
583

584
    ui_callback_signal_clear_list (widget, data);
585

586
    if (socket_connect_to_remote_host (ip, port, pipe_fd[1]) != 0)
587
    {
588
        ui_enable_connect_button ();
Cedric Roux's avatar
Cedric Roux committed
589 590
        return FALSE;
    }
591
    ui_set_title ("%s:%d", ip, port);
Cedric Roux's avatar
 
Cedric Roux committed
592 593 594 595

    return TRUE;
}

596
gboolean ui_callback_on_disconnect(GtkWidget *widget, gpointer data)
Cedric Roux's avatar
 
Cedric Roux committed
597 598 599
{
    /* We have to retrieve the ip address and port of remote host */

600
    g_message("Disconnect event occurred");
Cedric Roux's avatar
Cedric Roux committed
601

602
    ui_pipe_write_message (ui_main_data.pipe_fd[0], UI_PIPE_DISCONNECT_EVT, NULL, 0);
Cedric Roux's avatar
Cedric Roux committed
603

604
    ui_enable_connect_button ();
Cedric Roux's avatar
 
Cedric Roux committed
605 606 607
    return TRUE;
}

608
gboolean ui_callback_signal_go_to_first(GtkWidget *widget, gpointer data)
winckel's avatar
winckel committed
609
{
610
    ui_tree_view_select_row (0);
winckel's avatar
winckel committed
611 612 613 614 615
    ui_main_data.follow_last = FALSE;

    return TRUE;
}

616
gboolean ui_callback_signal_go_to(GtkWidget *widget, gpointer data)
617
{
618
    gtk_window_set_focus (GTK_WINDOW(ui_main_data.window), ui_main_data.signals_go_to_entry);
619 620 621
    return TRUE;
}

622
gboolean ui_callback_signal_go_to_entry(GtkWidget *widget, gpointer data)
623
{
winckel's avatar
winckel committed
624
    // gtk_entry_buffer_set_text(GTK_ENTRY(ui_main_data.signals_go_to_entry), "");
625
    gtk_window_set_focus (GTK_WINDOW(ui_main_data.window), ui_main_data.messages_list);
626 627 628
    return TRUE;
}

629
gboolean ui_callback_signal_go_to_last(GtkWidget *widget, gpointer data)
630
{
631
    ui_tree_view_select_row (ui_tree_view_get_filtered_number () - 1);
winckel's avatar
winckel committed
632 633 634 635
    ui_main_data.follow_last = TRUE;

    return TRUE;
}
636

637
gboolean ui_callback_display_message_header(GtkWidget *widget, gpointer data)
winckel's avatar
winckel committed
638 639 640 641 642
{
    ui_main_data.display_message_header = !ui_main_data.display_message_header;
    // TODO refresh textview.
    return TRUE;
}
643

644
gboolean ui_callback_display_brace(GtkWidget *widget, gpointer data)
winckel's avatar
winckel committed
645 646 647
{
    ui_main_data.display_brace = !ui_main_data.display_brace;
    // TODO refresh textview.
648 649 650
    return TRUE;
}

651
gboolean ui_callback_signal_clear_list(GtkWidget *widget, gpointer data)
652 653
{
    /* Disable buttons to move in the list of signals */
654 655
    ui_set_sensitive_move_buttons (FALSE);
    ui_set_title ("");
656

657
    /* Clear list of signals */
658
    ui_tree_view_destroy_list (ui_main_data.messages_list);
winckel's avatar
winckel committed
659 660 661

    if (ui_main_data.text_view != NULL)
    {
662
        ui_signal_dissect_clear_view (ui_main_data.text_view);
winckel's avatar
winckel committed
663 664 665 666 667
    }

    return TRUE;
}

668
static void ui_callback_on_menu_items_selected(GtkWidget *widget, gpointer data)
winckel's avatar
winckel committed
669
{
670
    gboolean active = data != NULL;
winckel's avatar
winckel committed
671 672 673

    if (GTK_IS_CHECK_MENU_ITEM(widget))
    {
674
        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(widget), active);
winckel's avatar
winckel committed
675 676 677
    }
}

678
gboolean ui_callback_on_menu_none(GtkWidget *widget, gpointer data)
winckel's avatar
winckel committed
679 680 681
{
    GtkWidget *menu = (GtkWidget *) data;

682
    g_info("ui_callback_on_menu_none occurred %lx %lx)", (long) widget, (long) data);
winckel's avatar
winckel committed
683

684
    refresh_message_list = FALSE;
685
    gtk_container_foreach (GTK_CONTAINER(menu), ui_callback_on_menu_items_selected, (gpointer) FALSE);
686 687
    refresh_message_list = TRUE;

688
    if (filters_changed)
689
    {
690
        ui_tree_view_refilter ();
691 692
        filters_changed = FALSE;
    }
winckel's avatar
winckel committed
693 694 695 696

    return TRUE;
}

697
gboolean ui_callback_on_menu_all(GtkWidget *widget, gpointer data)
winckel's avatar
winckel committed
698 699 700
{
    GtkWidget *menu = (GtkWidget *) data;

701
    g_info("ui_callback_on_menu_all occurred %lx %lx)", (long) widget, (long) data);
winckel's avatar
winckel committed
702

703
    refresh_message_list = FALSE;
704
    gtk_container_foreach (GTK_CONTAINER(menu), ui_callback_on_menu_items_selected, (gpointer) TRUE);
705 706
    refresh_message_list = TRUE;

707
    if (filters_changed)
708
    {
709
        ui_tree_view_refilter ();
710 711
        filters_changed = FALSE;
    }
winckel's avatar
winckel committed
712

713 714 715
    return TRUE;
}

716
gboolean ui_callback_on_menu_item_selected(GtkWidget *widget, gpointer data)
717
{
winckel's avatar
winckel committed
718
    ui_filter_item_t *filter_entry = data;
winckel's avatar
winckel committed
719
    gboolean enabled;
winckel's avatar
winckel committed
720

721
    enabled = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(widget));
722 723 724
    if (filter_entry->enabled != enabled)
    {
        filter_entry->enabled = enabled;
725 726
        if (refresh_message_list)
        {
727
            ui_tree_view_refilter ();
728 729 730 731 732
        }
        else
        {
            filters_changed = TRUE;
        }
733
    }
734
    g_info("ui_callback_on_menu_item_selected occurred %p %p %s %d (%d messages to display)", widget, data, filter_entry->name, enabled, ui_tree_view_get_filtered_number());
winckel's avatar
winckel committed
735

736 737 738
    return TRUE;
}

739
gboolean ui_callback_on_tree_column_header_click(GtkWidget *widget, gpointer data)
winckel's avatar
winckel committed
740
{
741
    col_type_t col = (col_type_t) data;
winckel's avatar
winckel committed
742

743
    g_info("ui_callback_on_tree_column_header_click %d", col);
winckel's avatar
winckel committed
744 745
    switch (col)
    {
746 747 748
        case COL_MESSAGE:
            ui_show_filter_menu (&ui_main_data.menu_filter_messages, &ui_filters.messages);
            break;
winckel's avatar
winckel committed
749

750 751 752
        case COL_FROM_TASK:
            ui_show_filter_menu (&ui_main_data.menu_filter_origin_tasks, &ui_filters.origin_tasks);
            break;
winckel's avatar
winckel committed
753

754 755 756
        case COL_TO_TASK:
            ui_show_filter_menu (&ui_main_data.menu_filter_destination_tasks, &ui_filters.destination_tasks);
            break;
winckel's avatar
winckel committed
757

758 759 760
        case COL_INSTANCE:
            ui_show_filter_menu (&ui_main_data.menu_filter_instances, &ui_filters.instances);
            break;
winckel's avatar
winckel committed
761

762 763 764
        default:
            g_warning("Unknown column filter %d in call to ui_callback_on_tree_column_header_click", col);
            return FALSE;
winckel's avatar
winckel committed
765 766
    }

767 768
    return TRUE;
}