From e66efe0eaf25dac344b8bb085b34359eac8b27c7 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 17 Jun 2009 17:05:51 +0200 Subject: [PATCH] remove dead code --- utils/mobility-generator.cc | 66 --------- utils/mobility-visualizer-model.cc | 140 ------------------ utils/mobility-visualizer-view.cc | 218 ----------------------------- utils/mobility-visualizer.h | 23 --- utils/wscript | 15 -- wscript | 1 - 6 files changed, 463 deletions(-) delete mode 100644 utils/mobility-generator.cc delete mode 100644 utils/mobility-visualizer-model.cc delete mode 100644 utils/mobility-visualizer-view.cc delete mode 100644 utils/mobility-visualizer.h diff --git a/utils/mobility-generator.cc b/utils/mobility-generator.cc deleted file mode 100644 index 3d1651b49..000000000 --- a/utils/mobility-generator.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include "ns3/ns2-mobility-file-topology.h" -#include "ns3/object.h" -#include "ns3/simulator.h" -#include "ns3/mobility-model-notifier.h" -#include - -using namespace ns3; - -static void -CourseChange (Ptr position) -{ - Position pos = position->Get (); - std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y - << ", z=" << pos.z << std::endl; -} - -int main (int argc, char *argv[]) -{ - std::vector > objects; - while (argc > 0) - { - if (strncmp (*argv, "--n=", strlen ("--n=")) == 0) - { - uint32_t n = atoi (*argv + strlen ("--n=")); - for (uint32_t i = 0; i < n; i++) - { - Ptr notifier = CreateObject (); - notifier->RegisterListener (MakeCallback (&CourseChange)); - objects.push_back (notifier); - } - } - else if (strncmp (*argv, "--ns2-topology=", - strlen ("--ns2-topology=")) == 0) - { - const char *filename = *argv + strlen ("--ns2-topology="); - Ns2MobilityFileTopology topology (filename); - topology.Layout (objects.begin (), objects.end ()); - } - argc--; - argv++; - } - - Simulator::Run (); - Simulator::Destroy (); - return 0; -} diff --git a/utils/mobility-visualizer-model.cc b/utils/mobility-visualizer-model.cc deleted file mode 100644 index cd503da63..000000000 --- a/utils/mobility-visualizer-model.cc +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ - -#include - -#include "ns3/ptr.h" -#include "ns3/mobility-model.h" -#include "ns3/mobility-model-notifier.h" -#include "ns3/position-allocator.h" -#include "ns3/default-value.h" -#include "ns3/command-line.h" -#include "ns3/command-line.h" -#include "ns3/simulator.h" -#include "ns3/nstime.h" -#include "ns3/node.h" -#include "ns3/node-list.h" -#include "ns3/rectangle-default-value.h" -#include "ns3/type-id-default-value.h" -#include "ns3/mobility-helper.h" - -#include "mobility-visualizer.h" - -using namespace ns3; - -static Time g_sampleInterval = Seconds (SAMPLE_INTERVAL); -static uint32_t g_numNodes = 10; - -template -static const T* DefaultValueListGet (const std::string &name) -{ - for (DefaultValueList::Iterator iter = DefaultValueList::Begin (); - iter != DefaultValueList::End (); iter++) - { - const DefaultValueBase *value = *iter; - if (value->GetName () == name) - { - return dynamic_cast (value); - } - } - return NULL; -} - - - -static void -Sample () -{ - - ViewUpdateData *data = new ViewUpdateData; - for (NodeList::Iterator nodeIter = NodeList::Begin (); nodeIter != NodeList::End (); nodeIter++) - { - Ptr node = *nodeIter; - Ptr mobility = node->GetObject (); - Vector pos = mobility->GetPosition (); - Vector vel = mobility->GetVelocity (); - - NodeUpdate update; - update.node = PeekPointer (node); - update.x = pos.x; - update.y = pos.y; - update.vx = vel.x; - update.vy = vel.y; - data->updateList.push_back (update); - } - data->time = Simulator::Now ().GetSeconds (); - view_update (data); - Simulator::Schedule (g_sampleInterval, Sample); -} - - - -int model_init (int argc, char *argv[], double *x1, double *y1, double *x2, double *y2) -{ - DefaultValue::Bind ("RandomWalk2dMode", "Time"); - DefaultValue::Bind ("RandomWalk2dTime", "5s"); - DefaultValue::Bind ("RandomWalk2dSpeed", "Constant:20.0"); - DefaultValue::Bind ("RandomDirection2dSpeed", "Uniform:10.0:20.0"); - DefaultValue::Bind ("RandomWalk2dBounds", "0:400:0:300"); - DefaultValue::Bind ("RandomDirection2dArea", "0:400:0:300"); - DefaultValue::Bind ("RandomWaypointSpeed", "Uniform:10:30"); - -// DefaultValue::Bind ("RandomDiscPositionX", "100"); -// DefaultValue::Bind ("RandomDiscPositionY", "50"); -// DefaultValue::Bind ("RandomDiscPositionRho", "Uniform:0:30"); - - DefaultValue::Bind ("RandomTopologyPositionType", "RandomRectanglePosition"); - DefaultValue::Bind ("RandomTopologyMobilityType", "RandomWalkMobilityModel"); - -// CommandLine::AddArgValue ("sample-interval","sample interval", g_sampleInterval); -// CommandLine::AddArgValue ("num-nodes","number of nodes", g_numNodes); - - CommandLine::Parse (argc, argv); - - MobilityHelper mobility; - - for (uint32_t i = 0; i < g_numNodes; i++) - { - Ptr node = CreateObject (); - } - - mobility.EnableNotifier (); - mobility.Layout (NodeList::Begin (), NodeList::End ()); - - Simulator::Schedule (g_sampleInterval, Sample); - - // XXX: The following is not really going to work with the params. - - if (mobility.GetMobilityModelType () == "RandomWalk2dMobilityModel") - { - Rectangle bounds = DefaultValueListGet ("RandomWalk2dBounds")->GetValue (); - *x1 = bounds.xMin; - *y1 = bounds.yMin; - *x2 = bounds.xMax; - *y2 = bounds.yMax; - std::cout << "RECT " << bounds.xMin << " " << bounds.xMax << " " - << bounds.yMin << " " << bounds.yMax << std::endl; - } - else if (mobility.GetMobilityModelType () == "RandomDirection2dMobilityModel") - { - Rectangle bounds = DefaultValueListGet ("RandomDirection2dArea")->GetValue (); - *x1 = bounds.xMin; - *y1 = bounds.yMin; - *x2 = bounds.xMax; - *y2 = bounds.yMax; - std::cout << "RECT " << bounds.xMin << " " << bounds.xMax << " " - << bounds.yMin << " " << bounds.yMax << std::endl; - } - else if (mobility.GetMobilityModelType () == "RandomWaypointMobilityModel") - { - std::cerr << "bounds for RandomWaypointMobilityModel not implemented" << std::endl; - //ClassId posType = DefaultValueList::Get ("RandomWaypointPosition")->GetValue (); - std::cout << "?" << std::endl; // too hard to represent an abstract/probabilistic model graphically - } - else - { - NS_FATAL_ERROR ("mobility type " << mobility.GetMobilityModelType () << " not supported"); - } - - std::cerr << g_sampleInterval << std::endl; - return 0; -} diff --git a/utils/mobility-visualizer-view.cc b/utils/mobility-visualizer-view.cc deleted file mode 100644 index c1370856b..000000000 --- a/utils/mobility-visualizer-view.cc +++ /dev/null @@ -1,218 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ - -#include - -#include -#include - -#include "mobility-visualizer.h" -#include -#include "ns3/simulator.h" - -#define MAX_QUEUE_LENGTH 100 -#define MAX_EVENTS 20 -#define LOOKAHEAD_SECONDS 10 - -GtkWidget *g_canvas; - -int model_init (int argc, char *argv[]); - -struct Node -{ - GooCanvasItem *m_item; - GooCanvasItem *m_vector; - void create () - { - GooCanvasItem *root = goo_canvas_get_root_item (GOO_CANVAS (g_canvas)); - m_item = goo_canvas_ellipse_new (root, 0, 0, 2.0, 2.0, - "line_width", 0.5, - "stroke_color", "black", - "fill_color", "red", - NULL); - - m_vector = goo_canvas_polyline_new (root, FALSE, 0, - "line_width", 0.3, - "stroke_color", "black", - "end-arrow", TRUE, - "arrow-length", 10.0, - "arrow-width", 10.0, - NULL); - - } - - - void update (double x, double y, double vx, double vy) - { - g_object_set (m_item, "center_x", x, "center_y", y, NULL); - - if (vx == 0 && vy == 0) - { - GooCanvasPoints *points = goo_canvas_points_new (0); - g_object_set (m_vector, "points", points, NULL); - goo_canvas_points_unref (points); - } - else - { - GooCanvasPoints *points = goo_canvas_points_new (2); - - points->coords[0] = x; - points->coords[1] = y; - points->coords[2] = x + vx; - points->coords[3] = y + vy; - - g_object_set (m_vector, "points", points, NULL); - goo_canvas_points_unref (points); - } - } -}; - -std::map g_nodes; - -GTimeVal initialTime = {-1, -1}; -gboolean firstTime = TRUE; -double g_lookaheadTime = 0; -GStaticMutex g_lookaheadTimeMux = G_STATIC_MUTEX_INIT; -ViewUpdateData *g_nextData = NULL; - - -GAsyncQueue *queue; - -#define TIME_SCALE 1 - -double get_current_time () -{ - GTimeVal currTime; - g_get_current_time (&currTime); - GTimeVal relativeTime; - relativeTime.tv_sec = currTime.tv_sec - initialTime.tv_sec + LOOKAHEAD_SECONDS; - relativeTime.tv_usec = currTime.tv_usec; - g_time_val_add (&relativeTime, -initialTime.tv_usec); - return (relativeTime.tv_sec + 1.0e-6*relativeTime.tv_usec)*TIME_SCALE; -} - -// called from the simulation thread -void view_update (ViewUpdateData *updateData) -{ - while ((g_static_mutex_lock (&g_lookaheadTimeMux), g_lookaheadTime) != 0 and updateData->time >= g_lookaheadTime) - { - g_static_mutex_unlock (&g_lookaheadTimeMux); - g_usleep ((gulong) 10e3); - } - g_static_mutex_unlock (&g_lookaheadTimeMux); - g_async_queue_push (queue, updateData); -} - -void view_update_process (ViewUpdateData *updateData) -{ - for (std::vector::const_iterator update - = updateData->updateList.begin (); - update != updateData->updateList.end (); - update++) - { - if (g_nodes.find (update->node) == g_nodes.end ()) - { - g_nodes[update->node].create (); - } - g_nodes[update->node].update (update->x, update->y, update->vx, update->vy); - } - delete updateData; -} - -gboolean view_update_consumer () -{ - if (firstTime) - { - firstTime = FALSE; - g_get_current_time (&initialTime); - } - - double now = get_current_time (); - g_static_mutex_lock (&g_lookaheadTimeMux); - g_lookaheadTime = now + LOOKAHEAD_SECONDS; - g_static_mutex_unlock (&g_lookaheadTimeMux); - - if (!g_nextData) - g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue); - - if (!g_nextData) - return TRUE; - - if (g_nextData->time > now) - return TRUE; - - do - { - view_update_process (g_nextData); - g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue); - } - while (g_nextData && g_nextData->time <= now); - - return TRUE; -} - -void zoom_changed (GtkAdjustment *adj) -{ - goo_canvas_set_scale (GOO_CANVAS (g_canvas), gtk_adjustment_get_value (adj)); -} - -int main (int argc, char *argv[]) -{ - g_thread_init (NULL); - gtk_init (&argc, &argv); - double x1 = 0, y1 = 0, x2 = 0, y2 = 0; - - model_init (argc, argv, &x1, &y1, &x2, &y2); - - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size (GTK_WINDOW (window), 640, 600); - gtk_widget_show (window); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *scrolled_win = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN); - gtk_widget_show (scrolled_win); - - GtkWidget *vbox = gtk_vbox_new (FALSE, 4); - gtk_widget_show (vbox); - gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, 1, 1, 4); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *hbox = gtk_hbox_new (FALSE, 4); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox), hbox, false, false, 4); - - GtkObject *zoom = gtk_adjustment_new (3.0, 0.1, 10.0, 0.2, 1.0, 1.0); - gtk_box_pack_start(GTK_BOX (hbox), - GTK_WIDGET (g_object_new (GTK_TYPE_SPIN_BUTTON, "adjustment", zoom, - "visible", true, "digits", 2, NULL)), - false, false, 4); - - g_canvas = goo_canvas_new (); - gtk_widget_set_size_request (GTK_WIDGET (g_canvas), 600, 450); - goo_canvas_set_bounds (GOO_CANVAS (g_canvas), -500, -500, 500, 500); - g_signal_connect (zoom, "value-changed", G_CALLBACK (zoom_changed), NULL); - gtk_adjustment_value_changed (GTK_ADJUSTMENT (zoom)); - gtk_widget_show (g_canvas); - gtk_container_add (GTK_CONTAINER (scrolled_win), g_canvas); - - goo_canvas_scroll_to (GOO_CANVAS (g_canvas), 0, 0); - - // create the bounds rectangle - if (x1 != x2) - { - GooCanvasItem *item = - goo_canvas_rect_new (goo_canvas_get_root_item (GOO_CANVAS (g_canvas)), - x1, y1, x2-x1, y2-y1, NULL); - g_object_set (item, "line-width", 1.0, "stroke-color", "grey", NULL); - } - - queue = g_async_queue_new (); - - g_timeout_add ((guint) (SAMPLE_INTERVAL*1000), (GSourceFunc) view_update_consumer, NULL); - - g_thread_create (GThreadFunc (ns3::Simulator::Run), NULL, FALSE, NULL); - - gtk_main (); - - return 0; -} diff --git a/utils/mobility-visualizer.h b/utils/mobility-visualizer.h deleted file mode 100644 index 634847c3c..000000000 --- a/utils/mobility-visualizer.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -#include - -int model_init (int argc, char *argv[], double *x1, double *y1, double *x2, double *y2); - -struct NodeUpdate -{ - void *node; - double x; - double y; - double vx; - double vy; -}; - -struct ViewUpdateData -{ - std::vector updateList; - double time; -}; - -void view_update (ViewUpdateData *updateData); - -#define SAMPLE_INTERVAL (1.0/30) diff --git a/utils/wscript b/utils/wscript index 07e880b7c..389cc25f8 100644 --- a/utils/wscript +++ b/utils/wscript @@ -1,11 +1,6 @@ ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- import os.path -def configure(conf): - conf.env['ENABLE_MOBILITY_VISUALIZER'] = conf.pkg_check_modules( - 'MOBILITY_VISUALIZER', 'goocanvas gthread-2.0', mandatory=False) - - def build(bld): env = bld.env @@ -25,13 +20,3 @@ def build(bld): ['internet-stack', 'csma-cd', 'point-to-point']) obj.source = 'print-introspected-doxygen.cc' -# XXX: disable mobility visualizer code temporarily. - env['ENABLE_MOBILITY_VISUALIZER'] = '' - if env['ENABLE_MOBILITY_VISUALIZER']: - obj = bld.create_ns3_program('mobility-visualizer', - ['internet-stack', 'mobility']) - obj.source = ['mobility-visualizer-model.cc', 'mobility-visualizer-view.cc'] - obj.uselib = 'MOBILITY_VISUALIZER' - if os.path.basename(obj.env['CXX']).startswith("g++"): - obj.env.append_value('CXXFLAGS', '-fno-strict-aliasing') - diff --git a/wscript b/wscript index 4667ff6fd..739600784 100644 --- a/wscript +++ b/wscript @@ -273,7 +273,6 @@ def configure(conf): env['WL_SONAME_SUPPORTED'] = True conf.sub_config('src') - conf.sub_config('utils') conf.sub_config('bindings/python') if Options.options.enable_modules: