utils/mobility-visualizer-view.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 13 Mar 2008 12:56:49 -0700
changeset 2602 d9262bff6df2
parent 1670 09ff9d07333e
permissions -rw-r--r--
add back support for introspected doxygen.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
#include <map>
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
#include <goocanvas.h>
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
#include <glib/gthread.h>
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
#include "mobility-visualizer.h"
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
#include <map>
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
#include "ns3/simulator.h"
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
#define MAX_QUEUE_LENGTH 100
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
#define MAX_EVENTS 20
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
#define LOOKAHEAD_SECONDS 10
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
GtkWidget *g_canvas;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
int model_init (int argc, char *argv[]);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
struct Node
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
{
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
  GooCanvasItem *m_item;
1665
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    23
  GooCanvasItem *m_vector;
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
  void create ()
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
  {
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
    GooCanvasItem *root = goo_canvas_get_root_item (GOO_CANVAS (g_canvas));
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
    m_item = goo_canvas_ellipse_new (root, 0, 0, 2.0, 2.0,
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
                                     "line_width", 0.5,
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
                                     "stroke_color", "black",
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
                                     "fill_color", "red",
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
                                     NULL);
1665
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    32
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    33
    m_vector = goo_canvas_polyline_new (root, FALSE, 0,
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    34
                                        "line_width", 0.3,
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    35
                                        "stroke_color", "black",
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    36
                                        "end-arrow", TRUE,
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    37
                                        "arrow-length", 10.0,
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    38
                                        "arrow-width", 10.0,
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    39
                                        NULL);
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    40
    
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
  }
1665
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    42
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    43
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
  void update (double x, double y, double vx, double vy)
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
  {
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
    g_object_set (m_item, "center_x", x, "center_y", y, NULL);
1665
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    47
    
1667
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    48
    if (vx == 0 && vy == 0)
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    49
      {
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    50
        GooCanvasPoints *points = goo_canvas_points_new (0);
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    51
        g_object_set (m_vector, "points", points, NULL);
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    52
        goo_canvas_points_unref (points);
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    53
      }
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    54
    else
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    55
      {
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    56
        GooCanvasPoints *points = goo_canvas_points_new (2);
1665
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    57
1667
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    58
        points->coords[0] = x;
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    59
        points->coords[1] = y;
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    60
        points->coords[2] = x + vx;
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    61
        points->coords[3] = y + vy;
1665
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    62
1667
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    63
        g_object_set (m_vector, "points", points, NULL);
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    64
        goo_canvas_points_unref (points);
469d3a87afa4 Hide the velocity vector if it is null.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1665
diff changeset
    65
      }
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
  }
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
};
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
std::map<void*, Node> g_nodes;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
GTimeVal initialTime = {-1, -1};
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
gboolean firstTime = TRUE;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
double g_lookaheadTime = 0;
1668
2dfe3ae77990 Use GStaticMutex instead of G_DEFINE_LOCK
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1667
diff changeset
    74
GStaticMutex g_lookaheadTimeMux = G_STATIC_MUTEX_INIT;
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
ViewUpdateData *g_nextData = NULL;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    76
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    77
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
GAsyncQueue *queue;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
1665
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    80
#define TIME_SCALE 1
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    81
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
double get_current_time ()
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
{
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
  GTimeVal currTime;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
  g_get_current_time (&currTime);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
  GTimeVal relativeTime;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
  relativeTime.tv_sec = currTime.tv_sec - initialTime.tv_sec + LOOKAHEAD_SECONDS;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
  relativeTime.tv_usec = currTime.tv_usec;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
  g_time_val_add (&relativeTime, -initialTime.tv_usec);
1665
73844d079af9 Draw the velocity vector
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1664
diff changeset
    90
  return (relativeTime.tv_sec + 1.0e-6*relativeTime.tv_usec)*TIME_SCALE;
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
}
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    93
// called from the simulation thread
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
void view_update (ViewUpdateData *updateData)
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
{
1668
2dfe3ae77990 Use GStaticMutex instead of G_DEFINE_LOCK
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1667
diff changeset
    96
  while ((g_static_mutex_lock (&g_lookaheadTimeMux), g_lookaheadTime) != 0 and updateData->time >= g_lookaheadTime)
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
    {
1668
2dfe3ae77990 Use GStaticMutex instead of G_DEFINE_LOCK
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1667
diff changeset
    98
      g_static_mutex_unlock (&g_lookaheadTimeMux);
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
      g_usleep ((gulong) 10e3);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   100
    }
1668
2dfe3ae77990 Use GStaticMutex instead of G_DEFINE_LOCK
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1667
diff changeset
   101
  g_static_mutex_unlock (&g_lookaheadTimeMux);
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
  g_async_queue_push (queue, updateData);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
}
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
void view_update_process (ViewUpdateData *updateData)
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
{
1670
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   107
  for (std::vector<NodeUpdate>::const_iterator update
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   108
         = updateData->updateList.begin ();
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   109
       update != updateData->updateList.end ();
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   110
       update++)
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   111
    {
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   112
      if (g_nodes.find (update->node) == g_nodes.end ())
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   113
        {
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   114
          g_nodes[update->node].create ();
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   115
        }
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   116
      g_nodes[update->node].update (update->x, update->y, update->vx, update->vy);
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   117
    }
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   118
  delete updateData;
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   119
}
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   120
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   121
gboolean view_update_consumer ()
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   122
{
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
  if (firstTime)
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
    {
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
      firstTime = FALSE;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
      g_get_current_time (&initialTime);
1670
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   127
    }
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
1670
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   129
  double now = get_current_time ();
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   130
  g_static_mutex_lock (&g_lookaheadTimeMux);
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   131
  g_lookaheadTime = now + LOOKAHEAD_SECONDS;
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   132
  g_static_mutex_unlock (&g_lookaheadTimeMux);
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
  if (!g_nextData)
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
    g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
  if (!g_nextData)
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   138
    return TRUE;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
  
1670
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   140
  if (g_nextData->time > now)
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
    return TRUE;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   142
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
  do
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
    {
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
      view_update_process (g_nextData);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
      g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
    }
1670
09ff9d07333e Fix race condition in mobility-visualizer-view; reduce refresh rate to 30fps.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1668
diff changeset
   148
  while (g_nextData && g_nextData->time <= now);
1664
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
  return TRUE;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
}
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
void zoom_changed (GtkAdjustment *adj)
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   154
{
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155
  goo_canvas_set_scale (GOO_CANVAS (g_canvas), gtk_adjustment_get_value (adj));
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   156
}
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   157
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   158
int main (int argc, char *argv[])
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
{
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
  g_thread_init (NULL);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   161
  gtk_init (&argc, &argv);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   163
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   164
  model_init (argc, argv, &x1, &y1, &x2, &y2);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   165
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   166
  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   167
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   168
  gtk_widget_show (window);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   169
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   170
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   171
  GtkWidget *scrolled_win = gtk_scrolled_window_new (NULL, NULL);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   172
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   173
  gtk_widget_show (scrolled_win);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   174
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   175
  GtkWidget *vbox = gtk_vbox_new (FALSE, 4);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   176
  gtk_widget_show (vbox);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   177
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, 1, 1, 4);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   178
  gtk_container_add (GTK_CONTAINER (window), vbox);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   179
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   180
  GtkWidget *hbox = gtk_hbox_new (FALSE, 4);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   181
  gtk_widget_show (hbox);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   182
  gtk_box_pack_start (GTK_BOX (vbox), hbox, false, false, 4);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   183
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   184
  GtkObject *zoom = gtk_adjustment_new (3.0, 0.1, 10.0, 0.2, 1.0, 1.0);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   185
  gtk_box_pack_start(GTK_BOX (hbox),
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   186
                     GTK_WIDGET (g_object_new (GTK_TYPE_SPIN_BUTTON, "adjustment", zoom,
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   187
                                               "visible", true, "digits", 2, NULL)),
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   188
                     false, false, 4);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   189
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   190
  g_canvas = goo_canvas_new ();
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   191
  gtk_widget_set_size_request (GTK_WIDGET (g_canvas), 600, 450);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   192
  goo_canvas_set_bounds (GOO_CANVAS (g_canvas), -500, -500, 500, 500);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   193
  g_signal_connect (zoom, "value-changed", G_CALLBACK (zoom_changed), NULL);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   194
  gtk_adjustment_value_changed (GTK_ADJUSTMENT (zoom));
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   195
  gtk_widget_show (g_canvas);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   196
  gtk_container_add (GTK_CONTAINER (scrolled_win), g_canvas);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   197
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   198
  goo_canvas_scroll_to (GOO_CANVAS (g_canvas), 0, 0);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   199
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   200
  // create the bounds rectangle
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   201
  if (x1 != x2)
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   202
    {
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   203
      GooCanvasItem *item = 
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   204
        goo_canvas_rect_new (goo_canvas_get_root_item (GOO_CANVAS (g_canvas)),
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   205
                                                 x1, y1, x2-x1, y2-y1, NULL);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   206
        g_object_set (item, "line-width", 1.0, "stroke-color", "grey", NULL);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   207
    }
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   208
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   209
  queue = g_async_queue_new ();
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   210
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   211
  g_timeout_add ((guint) (SAMPLE_INTERVAL*1000), (GSourceFunc) view_update_consumer, NULL);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   212
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   213
  g_thread_create (GThreadFunc (ns3::Simulator::Run), NULL, FALSE, NULL);
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   214
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   215
  gtk_main ();
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   216
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   217
  return 0;
306c81333d64 Add a small mobility model visualization tool
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   218
}