View | Details | Raw Unified | Return to bug 184
Collapse All | Expand All

(-)a/src/contrib/attribute-default-iterator.cc (-58 / +93 lines)
 Lines 1-15    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
 
1
#include "attribute-default-iterator.h"
20
#include "attribute-default-iterator.h"
2
#include "ns3/type-id.h"
3
#include "ns3/attribute.h"
21
#include "ns3/attribute.h"
4
#include "ns3/object-vector.h"
22
#include "ns3/object-vector.h"
5
#include "ns3/pointer.h"
23
#include "ns3/pointer.h"
6
#include "ns3/global-value.h"
24
#include "ns3/global-value.h"
7
#include "ns3/string.h"
25
#include "ns3/string.h"
8
26
9
namespace ns3 {
27
namespace ns3
28
{
10
29
11
AttributeDefaultIterator::~AttributeDefaultIterator ()
30
AttributeDefaultIterator::~AttributeDefaultIterator ()
12
{}
31
{
32
}
13
void 
33
void 
14
AttributeDefaultIterator::Iterate (void)
34
AttributeDefaultIterator::Iterate (void)
15
{
35
{
 Lines 17-88    Link Here 
17
    {
37
    {
18
      TypeId tid = TypeId::GetRegistered (i);
38
      TypeId tid = TypeId::GetRegistered (i);
19
      if (tid.MustHideFromDocumentation ())
39
      if (tid.MustHideFromDocumentation ())
20
	{
40
        {
21
	  continue;
41
          continue;
22
	}
42
        }
23
      bool calledStart = false;
43
      bool calledStart = false;
24
      for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
44
      for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
25
	{
45
        {
26
	  uint32_t flags = tid.GetAttributeFlags (j);
46
          uint32_t flags = tid.GetAttributeFlags (j);
27
	  if (!(flags & TypeId::ATTR_CONSTRUCT))
47
          if (!(flags & TypeId::ATTR_CONSTRUCT))
28
	    {
48
            {
29
	      // we can't construct the attribute, so, there is no
49
              // we can't construct the attribute, so, there is no
30
	      // initial value for the attribute
50
              // initial value for the attribute
31
	      continue;
51
              continue;
32
	    }
52
            }
33
	  Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (j);
53
          Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (j);
34
	  if (accessor == 0)
54
          //No accessor, go to next attribute
35
	    {
55
          if (accessor == 0)
36
	      continue;
56
            {
37
	    }
57
              continue;
38
	  if (!accessor->HasSetter ())
58
            }
39
	    {
59
          if (!accessor->HasSetter ())
40
	      continue;
60
            {
41
	    }
61
              //skip this attribute it doesn't have an setter
42
	  Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (j);
62
              continue;
43
	  if (checker == 0)
63
            }
44
	    {
64
          Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (j);
45
	      continue;
65
          if (checker == 0)
46
	    }
66
            {
47
	  Ptr<const AttributeValue> value = tid.GetAttributeInitialValue (j);
67
              //skip, it doesn't have a checker
48
	  if (value == 0)
68
              continue;
49
	    {
69
            }
50
	      continue;
70
          Ptr<const AttributeValue> value = tid.GetAttributeInitialValue (j);
51
	    }
71
          if (value == 0)
52
	  Ptr<const ObjectVectorValue> vector = DynamicCast<const ObjectVectorValue> (value);
72
            {
53
	  if (vector != 0)
73
              //No value, check next attribute
54
	    {
74
              continue;
55
	      continue;
75
            }
56
	    }
76
          Ptr<const ObjectVectorValue> vector = DynamicCast<const ObjectVectorValue> (value);
57
	  Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (value);
77
          if (vector != 0)
58
	  if (pointer != 0)
78
            {
59
	    {
79
              //a vector value, won't take it
60
	      continue;
80
              continue;
61
	    }
81
            }
62
	  if (!calledStart)
82
          Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (value);
63
	    {
83
          if (pointer != 0)
64
	      StartVisitTypeId (tid.GetName ());
84
            {
65
	    }
85
              //pointer value, won't take it
66
	  VisitAttribute (tid.GetAttributeName (j),
86
              continue;
67
			  value->SerializeToString (checker));
87
            }
68
	  calledStart = true;
88
          //We take only values, no pointers or vectors
69
	}
89
          if (!calledStart)
90
            {
91
              StartVisitTypeId (tid.GetName ());
92
            }
93
          VisitAttribute (tid, tid.GetAttributeName (j), value->SerializeToString (checker), j);
94
          calledStart = true;
95
        }
70
      if (calledStart)
96
      if (calledStart)
71
	{
97
        {
72
	  EndVisitTypeId ();
98
          EndVisitTypeId ();
73
	}
99
        }
74
    }
100
    }
75
}
101
}
76
102
77
void 
103
void 
78
AttributeDefaultIterator::StartVisitTypeId (std::string name)
104
AttributeDefaultIterator::StartVisitTypeId (std::string name)
79
{}
105
{
106
}
80
void 
107
void 
81
AttributeDefaultIterator::EndVisitTypeId (void)
108
AttributeDefaultIterator::EndVisitTypeId (void)
82
{}
109
{
110
}
111
83
void 
112
void 
84
AttributeDefaultIterator::VisitAttribute (std::string name, std::string defaultValue)
113
AttributeDefaultIterator::DoVisitAttribute (std::string name, std::string defaultValue)
85
{}
114
{
115
}
86
116
117
void 
118
AttributeDefaultIterator::VisitAttribute (TypeId tid, std::string name, std::string defaultValue, uint32_t index)
119
{
120
  DoVisitAttribute (name, defaultValue);
121
}
87
122
88
} // namespace ns3
123
} // namespace ns3
(-)a/src/contrib/attribute-default-iterator.h (-1 / +40 lines)
 Lines 1-6    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
 
1
#ifndef ATTRIBUTE_DEFAULT_ITERATOR_H
20
#ifndef ATTRIBUTE_DEFAULT_ITERATOR_H
2
#define ATTRIBUTE_DEFAULT_ITERATOR_H
21
#define ATTRIBUTE_DEFAULT_ITERATOR_H
3
22
23
#include "ns3/type-id.h"
4
#include <string>
24
#include <string>
5
25
6
namespace ns3 {
26
namespace ns3 {
 Lines 9-19    Link Here 
9
{
29
{
10
public:
30
public:
11
  virtual ~AttributeDefaultIterator () = 0;
31
  virtual ~AttributeDefaultIterator () = 0;
32
  /**
33
   * \brief This function will go through all the TypeIds and get only the attributes which are
34
   * explicit values (not vectors or pointer or arrays) and apply StartVisitTypeId
35
   * and VisitAttribute on the attributes in one TypeId. At the end of each TypeId
36
   * EndVisitTypeId is called.
37
   */
12
  void Iterate (void);
38
  void Iterate (void);
13
private:
39
private:
40
  /**
41
   * \brief Just an interface that needs to be implemented
42
   */
14
  virtual void StartVisitTypeId (std::string name);
43
  virtual void StartVisitTypeId (std::string name);
44
  /**
45
   * \brief Just an interface that needs to be implemented
46
   */
15
  virtual void EndVisitTypeId (void);
47
  virtual void EndVisitTypeId (void);
16
  virtual void VisitAttribute (std::string name, std::string defaultValue);
48
  /**
49
   * \brief This method can be implemented, otherwise, it will call DoVisitAttribute
50
   */
51
  virtual void VisitAttribute (TypeId tid, std::string name, std::string defaultValue, uint32_t index);
52
  /**
53
   * \brief This method is just an interface and needs to be implemented
54
   */
55
  virtual void DoVisitAttribute (std::string name, std::string defaultValue);
17
};
56
};
18
57
19
} // namespace ns3
58
} // namespace ns3
(-)a/src/contrib/attribute-iterator.cc (-76 / +105 lines)
 Lines 1-3    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
17
 */
18
 
1
#include "attribute-iterator.h"
19
#include "attribute-iterator.h"
2
#include "ns3/config.h"
20
#include "ns3/config.h"
3
#include "ns3/log.h"
21
#include "ns3/log.h"
 Lines 13-22    Link Here 
13
31
14
32
15
AttributeIterator::AttributeIterator ()
33
AttributeIterator::AttributeIterator ()
16
{}
34
{
35
}
17
36
18
AttributeIterator::~AttributeIterator ()
37
AttributeIterator::~AttributeIterator ()
19
{}
38
{
39
}
20
40
21
void 
41
void 
22
AttributeIterator::Iterate (void)
42
AttributeIterator::Iterate (void)
 Lines 38-46    Link Here 
38
  for (uint32_t i = 0; i < m_examined.size (); ++i)
58
  for (uint32_t i = 0; i < m_examined.size (); ++i)
39
    {
59
    {
40
      if (object == m_examined[i])
60
      if (object == m_examined[i])
41
	{
61
        {
42
	  return true;
62
          return true;
43
	}
63
        }
44
    }
64
    }
45
  return false;
65
  return false;
46
}
66
}
 Lines 74-101    Link Here 
74
94
75
void 
95
void 
76
AttributeIterator::DoStartVisitObject (Ptr<Object> object)
96
AttributeIterator::DoStartVisitObject (Ptr<Object> object)
77
{}
97
{
98
}
78
void 
99
void 
79
AttributeIterator::DoEndVisitObject (void)
100
AttributeIterator::DoEndVisitObject (void)
80
{}
101
{
102
}
81
void 
103
void 
82
AttributeIterator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> item)
104
AttributeIterator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> item)
83
{}
105
{
106
}
84
void 
107
void 
85
AttributeIterator::DoEndVisitPointerAttribute (void)
108
AttributeIterator::DoEndVisitPointerAttribute (void)
86
{}
109
{
110
}
87
void 
111
void 
88
AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
112
AttributeIterator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
89
{}
113
{
114
}
90
void 
115
void 
91
AttributeIterator::DoEndVisitArrayAttribute (void)
116
AttributeIterator::DoEndVisitArrayAttribute (void)
92
{}
117
{
118
}
93
void 
119
void 
94
AttributeIterator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
120
AttributeIterator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
95
{}
121
{
122
}
96
void 
123
void 
97
AttributeIterator::DoEndVisitArrayItem (void)
124
AttributeIterator::DoEndVisitArrayItem (void)
98
{}
125
{
126
}
99
127
100
void 
128
void 
101
AttributeIterator::VisitAttribute (Ptr<Object> object, std::string name)
129
AttributeIterator::VisitAttribute (Ptr<Object> object, std::string name)
 Lines 174-231    Link Here 
174
    {
202
    {
175
      NS_LOG_DEBUG ("store " << tid.GetName ());
203
      NS_LOG_DEBUG ("store " << tid.GetName ());
176
      for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
204
      for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
177
	{
205
        {
178
	  Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (i);
206
          Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (i);
179
	  const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (checker));
207
          const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (checker));
180
	  if (ptrChecker != 0)
208
          if (ptrChecker != 0)
181
	    {
209
            {
182
	      NS_LOG_DEBUG ("pointer attribute " << tid.GetAttributeName (i));
210
              NS_LOG_DEBUG ("pointer attribute " << tid.GetAttributeName (i));
183
	      PointerValue ptr;
211
              PointerValue ptr;
184
	      object->GetAttribute (tid.GetAttributeName (i), ptr);
212
              object->GetAttribute (tid.GetAttributeName (i), ptr);
185
	      Ptr<Object> tmp = ptr.Get<Object> ();
213
              Ptr<Object> tmp = ptr.Get<Object> ();
186
	      if (tmp != 0)
214
              if (tmp != 0)
187
		{
215
                {
188
		  StartVisitPointerAttribute (object, tid.GetAttributeName (i), tmp);
216
                  StartVisitPointerAttribute (object, tid.GetAttributeName (i),
189
		  m_examined.push_back (object);
217
                                              tmp);
190
		  DoIterate (tmp);
218
                  m_examined.push_back (object);
191
		  m_examined.pop_back ();
219
                  DoIterate (tmp);
192
		  EndVisitPointerAttribute ();
220
                  m_examined.pop_back ();
193
		}
221
                  EndVisitPointerAttribute ();
194
	      continue;
222
                }
195
	    }
223
              continue;
196
	  // attempt to cast to an object vector.
224
            }
197
	  const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (checker));
225
          // attempt to cast to an object vector.
198
	  if (vectorChecker != 0)
226
          const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (checker));
199
	    {
227
          if (vectorChecker != 0)
200
	      NS_LOG_DEBUG ("vector attribute " << tid.GetAttributeName (i));
228
            {
201
	      ObjectVectorValue vector;
229
              NS_LOG_DEBUG ("vector attribute " << tid.GetAttributeName (i));
202
	      object->GetAttribute (tid.GetAttributeName (i), vector);
230
              ObjectVectorValue vector;
203
	      StartVisitArrayAttribute (object, tid.GetAttributeName (i), vector);
231
              object->GetAttribute (tid.GetAttributeName (i), vector);
204
	      for (uint32_t j = 0; j < vector.GetN (); ++j)
232
              StartVisitArrayAttribute (object, tid.GetAttributeName (i), vector);
205
		{
233
              for (uint32_t j = 0; j < vector.GetN (); ++j)
206
		  NS_LOG_DEBUG ("vector attribute item " << j);
234
                {
207
		  Ptr<Object> tmp = vector.Get (j);
235
                  NS_LOG_DEBUG ("vector attribute item " << j);
208
		  StartVisitArrayItem (vector, j, tmp);
236
                  Ptr<Object> tmp = vector.Get (j);
209
		  m_examined.push_back (object);
237
                  StartVisitArrayItem (vector, j, tmp);
210
		  DoIterate (tmp);
238
                  m_examined.push_back (object);
211
		  m_examined.pop_back ();
239
                  DoIterate (tmp);
212
		  EndVisitArrayItem ();
240
                  m_examined.pop_back ();
213
		}
241
                  EndVisitArrayItem ();
214
	      EndVisitArrayAttribute ();
242
                }
215
	      continue;
243
              EndVisitArrayAttribute ();
216
	    }
244
              continue;
217
	  uint32_t flags = tid.GetAttributeFlags (i);
245
            }
218
	  Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (i);
246
          uint32_t flags = tid.GetAttributeFlags (i);
219
	  if ((flags & TypeId::ATTR_GET) && accessor->HasGetter () &&
247
          Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (i);
220
	      (flags & TypeId::ATTR_SET) && accessor->HasSetter ())
248
          if ((flags & TypeId::ATTR_GET) && accessor->HasGetter () && 
221
	    {
249
              (flags & TypeId::ATTR_SET) && accessor->HasSetter ())
222
	      VisitAttribute (object, tid.GetAttributeName (i));
250
            {
223
	    }
251
              VisitAttribute (object, tid.GetAttributeName (i));
224
	  else
252
            }
225
	    {
253
          else
226
	      NS_LOG_DEBUG ("could not store " << tid.GetAttributeName (i));
254
            {
227
	    }
255
              NS_LOG_DEBUG ("could not store " << tid.GetAttributeName (i));
228
	}
256
            }
257
        }
229
    }
258
    }
230
  Object::AggregateIterator iter = object->GetAggregateIterator ();
259
  Object::AggregateIterator iter = object->GetAggregateIterator ();
231
  bool recursiveAggregate = false;
260
  bool recursiveAggregate = false;
 Lines 233-254    Link Here 
233
    {
262
    {
234
      Ptr<const Object> tmp = iter.Next ();
263
      Ptr<const Object> tmp = iter.Next ();
235
      if (IsExamined (tmp))
264
      if (IsExamined (tmp))
236
	{
265
        {
237
	  recursiveAggregate = true;
266
          recursiveAggregate = true;
238
	}
267
        }
239
    }
268
    }
240
  if (!recursiveAggregate)
269
  if (!recursiveAggregate)
241
    {
270
    {
242
      iter = object->GetAggregateIterator ();
271
      iter = object->GetAggregateIterator ();
243
      while (iter.HasNext ())
272
      while (iter.HasNext ())
244
	{
273
        {
245
	  Ptr<Object> tmp = const_cast<Object *> (PeekPointer (iter.Next ()));
274
          Ptr<Object> tmp = const_cast<Object *> (PeekPointer (iter.Next ()));
246
	  StartVisitObject (tmp);
275
          StartVisitObject (tmp);
247
	  m_examined.push_back (object);
276
          m_examined.push_back (object);
248
	  DoIterate (tmp);
277
          DoIterate (tmp);
249
	  m_examined.pop_back ();
278
          m_examined.pop_back ();
250
	  EndVisitObject ();
279
          EndVisitObject ();
251
	}
280
        }
252
    }
281
    }
253
}
282
}
254
283
(-)a/src/contrib/attribute-iterator.h (+18 lines)
 Lines 1-3    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
17
 */
18
 
1
#ifndef ATTRIBUTE_ITERATOR_H
19
#ifndef ATTRIBUTE_ITERATOR_H
2
#define ATTRIBUTE_ITERATOR_H
20
#define ATTRIBUTE_ITERATOR_H
3
21
(-)c85cb9b073a0 (+537 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
20
#include "model-node-creator.h"
21
#include "model-typeid-creator.h"
22
#include "ns3/config.h"
23
#include "ns3/string.h"
24
#include "ns3/pointer.h"
25
#include <gtk/gtk.h>
26
27
namespace ns3 {
28
/**
29
 * This function includes the name of the attribute or the editable value
30
 * in the second column 
31
 */
32
static void
33
cell_data_function_col_1 (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
34
                          GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
35
{
36
  ModelNode *node;
37
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
38
  if (node->type == ModelNode::NODE_ATTRIBUTE)
39
    {
40
      StringValue str;
41
      node->object->GetAttribute (node->name, str);
42
      g_object_set (renderer, "text", str.Get ().c_str (), (char*) 0);
43
      g_object_set (renderer, "editable", TRUE, (char*) 0);
44
    }
45
  else
46
    {
47
      g_object_set (renderer, "text", "", (char*) 0);
48
      g_object_set (renderer, "editable", FALSE, (char*) 0);
49
    }
50
}
51
/**
52
 * This function includes the name of the object, pointer, vector or vector item
53
 * in the first column
54
 */
55
static void
56
cell_data_function_col_0 (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model,
57
                          GtkTreeIter *iter, gpointer user_data)
58
{
59
  ModelNode *node;
60
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
61
  g_object_set (renderer, "editable", FALSE, (char*) 0);
62
  switch (node->type)
63
    {
64
    case ModelNode::NODE_OBJECT:
65
      g_object_set (renderer, "text", node->object->GetInstanceTypeId ().GetName ().c_str (), (char*) 0);
66
      break;
67
    case ModelNode::NODE_POINTER:
68
      g_object_set (renderer, "text", node->name.c_str (), (char*) 0);
69
      break;
70
    case ModelNode::NODE_VECTOR:
71
      g_object_set (renderer, "text", node->name.c_str (), (char*) 0);
72
      break;
73
    case ModelNode::NODE_VECTOR_ITEM:
74
      {
75
        std::stringstream oss;
76
        oss << node->index;
77
        g_object_set (renderer, "text", oss.str ().c_str (), (char*) 0);
78
      }
79
      break;
80
    case ModelNode::NODE_ATTRIBUTE:
81
      g_object_set (renderer, "text", node->name.c_str (), (char*) 0);
82
      break;
83
    }
84
}
85
86
/**
87
 * This is the callback called when the value of an attribute is changed
88
 */
89
static void
90
cell_edited_callback (GtkCellRendererText *cell, gchar *path_string,
91
                      gchar *new_text, gpointer user_data)
92
{
93
  GtkTreeModel *model = GTK_TREE_MODEL (user_data);
94
  GtkTreeIter iter;
95
  gtk_tree_model_get_iter_from_string (model, &iter, path_string);
96
  ModelNode *node;
97
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
98
  NS_ASSERT (node->type == ModelNode::NODE_ATTRIBUTE);
99
  node->object->SetAttribute (node->name, StringValue (new_text));
100
}
101
102
/**
103
 * This function gets the column number 0 or 1 from the mouse
104
 * click
105
 */
106
static int
107
get_col_number_from_tree_view_column (GtkTreeViewColumn *col)
108
{
109
  GList *cols;
110
  int num;
111
  g_return_val_if_fail (col != 0, -1);
112
  g_return_val_if_fail (col->tree_view != 0, -1);
113
  cols = gtk_tree_view_get_columns (GTK_TREE_VIEW (col->tree_view));
114
  num = g_list_index (cols, (gpointer) col);
115
  g_list_free (cols);
116
  return num;
117
}
118
119
/**
120
 * This function displays the tooltip for an object, pointer, vector
121
 * item or an attribute
122
 */
123
static gboolean
124
cell_tooltip_callback (GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, 
125
                       GtkTooltip *tooltip, gpointer user_data)
126
{
127
  GtkTreeModel *model;
128
  GtkTreeIter iter;
129
  GtkTreeViewColumn * column;
130
  if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), &x, &y,
131
                                          keyboard_tip, &model, 0, &iter))
132
    {
133
      return FALSE;
134
    }
135
  if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, 0, &column, 0, 0))
136
    {
137
      return FALSE;
138
    }
139
  int col = get_col_number_from_tree_view_column (column);
140
141
  ModelNode *node;
142
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
143
144
  switch (node->type)
145
    {
146
    case ModelNode::NODE_OBJECT:
147
      if (col == 0)
148
        {
149
          std::string tip = "This object is of type "
150
            + node->object->GetInstanceTypeId ().GetName ();
151
          gtk_tooltip_set_text (tooltip, tip.c_str ());
152
          return TRUE;
153
        }
154
      break;
155
    case ModelNode::NODE_POINTER:
156
      if (col == 0)
157
        {
158
          PointerValue ptr;
159
          node->object->GetAttribute (node->name, ptr);
160
          std::string tip = "This object is of type "
161
            + ptr.GetObject ()->GetInstanceTypeId ().GetName ();
162
          gtk_tooltip_set_text (tooltip, tip.c_str ());
163
          return TRUE;
164
        }
165
      break;
166
    case ModelNode::NODE_VECTOR:
167
      break;
168
    case ModelNode::NODE_VECTOR_ITEM:
169
      if (col == 0)
170
        {
171
          std::string tip = "This object is of type "
172
            + node->object->GetInstanceTypeId ().GetName ();
173
          gtk_tooltip_set_text (tooltip, tip.c_str ());
174
          return TRUE;
175
        }
176
      break;
177
    case ModelNode::NODE_ATTRIBUTE:
178
      {
179
        uint32_t attrIndex = 0;
180
        TypeId tid;
181
        for (tid = node->object->GetInstanceTypeId (); tid.HasParent (); tid
182
               = tid.GetParent ())
183
          {
184
            for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
185
              {
186
                if (tid.GetAttributeName (i) == node->name)
187
                  {
188
                    attrIndex = i;
189
                    goto out;
190
                  }
191
              }
192
          }
193
out: if (col == 0)
194
          {
195
            std::string tip = tid.GetAttributeHelp (attrIndex);
196
            gtk_tooltip_set_text (tooltip, tip.c_str ());
197
          }
198
        else
199
          {
200
            Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (
201
                attrIndex);
202
            std::string tip;
203
            tip = "This attribute is of type " + checker->GetValueTypeName ();
204
            if (checker->HasUnderlyingTypeInformation ())
205
              {
206
                tip += " " + checker->GetUnderlyingTypeInformation ();
207
              }
208
            gtk_tooltip_set_text (tooltip, tip.c_str ());
209
          }
210
        return TRUE;
211
      }
212
      break;
213
    }
214
  return FALSE;
215
}
216
217
/**
218
 * This is the main view opening the widget, getting tooltips and drawing the 
219
 * tree of attributes...
220
 */
221
static GtkWidget *
222
create_view (GtkTreeStore *model)
223
{
224
  GtkTreeViewColumn *col;
225
  GtkCellRenderer *renderer;
226
  GtkWidget *view;
227
228
  view = gtk_tree_view_new ();
229
  g_object_set (view, "has-tooltip", TRUE, (char*) 0);
230
  g_signal_connect (view, "query-tooltip", (GCallback) cell_tooltip_callback, 0);
231
232
  gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_BOTH);
233
  gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
234
235
  col = gtk_tree_view_column_new ();
236
  gtk_tree_view_column_set_title (col, "Object Attributes");
237
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
238
  renderer = gtk_cell_renderer_text_new ();
239
  gtk_tree_view_column_pack_start (col, renderer, TRUE);
240
  gtk_tree_view_column_set_cell_data_func (col, renderer, cell_data_function_col_0, 0, 0);
241
  g_object_set (renderer, "editable", FALSE, (char*) 0);
242
243
  col = gtk_tree_view_column_new ();
244
  gtk_tree_view_column_set_title (col, "Attribute Value");
245
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
246
  renderer = gtk_cell_renderer_text_new ();
247
  g_signal_connect (renderer, "edited", (GCallback) cell_edited_callback, model);
248
  gtk_tree_view_column_pack_start (col, renderer, TRUE);
249
  gtk_tree_view_column_set_cell_data_func (col, renderer, cell_data_function_col_1, 0, 0);
250
251
  gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (model));
252
253
  g_object_unref (model); /* destroy model automatically with view */
254
255
  return view;
256
}
257
258
/**
259
 * This is the action done when the user presses on the save button.
260
 * It will save the config to a file.
261
 */
262
static void
263
save_clicked (GtkButton *button, gpointer user_data)
264
{
265
  GtkWidget *parent_window = GTK_WIDGET (user_data);
266
  GtkWidget *dialog;
267
268
  dialog = gtk_file_chooser_dialog_new ("Save File", GTK_WINDOW (parent_window), GTK_FILE_CHOOSER_ACTION_SAVE,
269
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE,
270
                                        GTK_RESPONSE_ACCEPT, (char *) 0);
271
  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
272
                                                  TRUE);
273
274
  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "config.txt");
275
276
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
277
    {
278
      char *filename;
279
280
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
281
      RawTextConfigSave config;
282
      config.SetFilename (filename);
283
      config.Attributes ();
284
      g_free (filename);
285
    }
286
287
  gtk_widget_destroy (dialog);
288
}
289
290
/**
291
 * If the user presses the button load, it will load the config file into memory.
292
 */
293
static void
294
load_clicked (GtkButton *button, gpointer user_data)
295
{
296
  GtkWidget *parent_window = GTK_WIDGET (user_data);
297
  GtkWidget *dialog;
298
299
  dialog = gtk_file_chooser_dialog_new ("Open File", GTK_WINDOW (parent_window), GTK_FILE_CHOOSER_ACTION_OPEN,
300
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
301
                                        GTK_RESPONSE_ACCEPT, (char *) 0);
302
303
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
304
    {
305
      char *filename;
306
307
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
308
      RawTextConfigLoad config;
309
      config.SetFilename (filename);
310
      config.Attributes ();
311
    }
312
313
  gtk_widget_destroy (dialog);
314
}
315
316
/**
317
 * Exit the window when exit button is pressed
318
 */
319
static void
320
exit_clicked_callback (GtkButton *button, gpointer user_data)
321
{
322
  gtk_main_quit ();
323
  gtk_widget_hide (GTK_WIDGET (user_data));
324
}
325
326
/**
327
 * Exit the application
328
 */
329
static gboolean
330
delete_event_callback (GtkWidget *widget, GdkEvent *event, gpointer user_data)
331
{
332
  gtk_main_quit ();
333
  gtk_widget_hide (GTK_WIDGET (user_data));
334
  return TRUE;
335
}
336
337
/**
338
 * Delete the tree model contents
339
 */
340
static gboolean
341
clean_model_callback (GtkTreeModel *model, GtkTreePath *path,
342
                      GtkTreeIter *iter, gpointer data)
343
{
344
  ModelNode *node;
345
  gtk_tree_model_get (GTK_TREE_MODEL (model), iter, COL_NODE, &node, -1);
346
  delete node;
347
  gtk_tree_store_set (GTK_TREE_STORE (model), iter, COL_NODE, (ModelNode*) 0,
348
                      -1);
349
  return FALSE;
350
}
351
352
/**************************   Static display functions used by default configurator **********************/
353
/**
354
 * This function writes data in the second column, this data is going to be editable
355
 * if it is a NODE_ATTRIBUTE
356
 */
357
static void
358
cell_data_function_col_1_config_default (GtkTreeViewColumn *col, GtkCellRenderer *renderer, 
359
                                         GtkTreeModel *model, GtkTreeIter *iter,
360
                                         gpointer user_data)
361
{
362
  ModelTypeid *node;
363
  gtk_tree_model_get (model, iter, COL_TYPEID, &node, -1);
364
  if (node->type == ModelTypeid::NODE_ATTRIBUTE)
365
    {
366
      g_object_set (renderer, "text", node->defaultValue.c_str (), (char*) 0);
367
      g_object_set (renderer, "editable", TRUE, (char*) 0);
368
    }
369
  else
370
    {
371
      g_object_set (renderer, "text", "", (char*) 0);
372
      g_object_set (renderer, "editable", FALSE, (char*) 0);
373
    }
374
}
375
/**
376
 * This function writes the attribute or typeid name in the column 0
377
 */
378
static void
379
cell_data_function_col_0_config_default (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, 
380
                                         GtkTreeIter *iter, gpointer user_data)
381
{
382
  ModelTypeid *node;
383
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
384
  g_object_set (renderer, "editable", FALSE, (char*) 0);
385
  switch (node->type)
386
    {
387
    case ModelTypeid::NODE_TYPEID:
388
      g_object_set (renderer, "text", node->tid.GetName ().c_str (), (char*) 0);
389
      break;
390
    case ModelTypeid::NODE_ATTRIBUTE:
391
      g_object_set (renderer, "text", node->name.c_str (), (char*) 0);
392
      break;
393
    }
394
}
395
396
397
/**
398
 *  This functions is called whenever there is a change in the value of an attribute
399
 *  If the input value is ok, it will be updated in the default value and in the
400
 *  gui, otherwise, it won't be updated in both.
401
 */
402
static void
403
cell_edited_callback_config_default (GtkCellRendererText *cell, gchar *path_string,
404
                                     gchar *new_text, gpointer user_data)
405
{
406
  GtkTreeModel *model = GTK_TREE_MODEL (user_data);
407
  GtkTreeIter iter;
408
  gtk_tree_model_get_iter_from_string (model, &iter, path_string);
409
  ModelTypeid *node;
410
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
411
  NS_ASSERT (node->type == ModelTypeid::NODE_ATTRIBUTE);
412
  if (Config::SetDefaultFailSafe (node->tid.GetAttributeFullName (node->index),StringValue (new_text)))
413
    {
414
      node->defaultValue = new_text;
415
    }
416
}
417
418
/**
419
 * This function is used to display a tooltip whenever the user puts the mouse
420
 * over a type ID or an attribute. It will give the type and the possible values of
421
 * an attribute value and the type of the object for an attribute object or a 
422
 * typeID object 
423
 */
424
static gboolean
425
cell_tooltip_callback_config_default (GtkWidget *widget, gint x, gint y,
426
                                      gboolean keyboard_tip, GtkTooltip *tooltip, gpointer user_data)
427
{
428
  GtkTreeModel *model;
429
  GtkTreeIter iter;
430
  GtkTreeViewColumn * column;
431
  if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), &x, &y,
432
                                          keyboard_tip, &model, 0, &iter))
433
    {
434
      return FALSE;
435
    }
436
  if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, 0, &column, 0, 0))
437
    {
438
      return FALSE;
439
    }
440
  int col = get_col_number_from_tree_view_column (column);
441
442
  ModelTypeid *node;
443
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
444
445
  switch (node->type)
446
    {
447
    case ModelTypeid::NODE_TYPEID:
448
      if (col == 0)
449
        {
450
          std::string tip = "This object is of type " + node->tid.GetName ();
451
          gtk_tooltip_set_text (tooltip, tip.c_str ());
452
          return TRUE;
453
        }
454
      break;
455
    case ModelTypeid::NODE_ATTRIBUTE:
456
      {
457
        uint32_t attrIndex = node->index;
458
        if (col == 0)
459
          {
460
            std::string tip = node->tid.GetAttributeHelp (attrIndex);
461
            gtk_tooltip_set_text (tooltip, tip.c_str ());
462
          }
463
        else
464
          {
465
            Ptr<const AttributeChecker> checker = node->tid.GetAttributeChecker (attrIndex);
466
            std::string tip;
467
            tip = "This attribute is of type " + checker->GetValueTypeName ();
468
            if (checker->HasUnderlyingTypeInformation ())
469
              {
470
                tip += " " + checker->GetUnderlyingTypeInformation ();
471
              }
472
            gtk_tooltip_set_text (tooltip, tip.c_str ());
473
          }
474
        return TRUE;
475
      }
476
      break;
477
    }
478
  return FALSE;
479
}
480
481
/**
482
 * This is the main view opening the widget, getting tooltips and drawing the 
483
 * tree of attributes
484
 */
485
static GtkWidget *
486
create_view_config_default (GtkTreeStore *model)
487
{
488
  GtkTreeViewColumn *col;
489
  GtkCellRenderer *renderer;
490
  GtkWidget *view;
491
492
  view = gtk_tree_view_new ();
493
  g_object_set (view, "has-tooltip", TRUE, (char*) 0);
494
  g_signal_connect (view, "query-tooltip", (GCallback) cell_tooltip_callback_config_default, 0);
495
496
  gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_BOTH);
497
  gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
498
499
  col = gtk_tree_view_column_new ();
500
  gtk_tree_view_column_set_title (col, "Object Attributes");
501
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
502
  renderer = gtk_cell_renderer_text_new ();
503
  gtk_tree_view_column_pack_start (col, renderer, TRUE);
504
  gtk_tree_view_column_set_cell_data_func (col, renderer, cell_data_function_col_0_config_default, 0, 0);
505
  g_object_set (renderer, "editable", FALSE, (char*) 0);
506
507
  col = gtk_tree_view_column_new ();
508
  gtk_tree_view_column_set_title (col, "Attribute Value");
509
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
510
  renderer = gtk_cell_renderer_text_new ();
511
  g_signal_connect (renderer, "edited", (GCallback) cell_edited_callback_config_default, model);
512
  gtk_tree_view_column_pack_start (col, renderer, TRUE);
513
  gtk_tree_view_column_set_cell_data_func (col, renderer, cell_data_function_col_1_config_default, 0, 0);
514
515
  gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (model));
516
517
  g_object_unref (model); /* destroy model automatically with view */
518
519
  return view;
520
}
521
522
/**
523
 * Delete the tree model contents
524
 */
525
static gboolean
526
clean_model_callback_config_default (GtkTreeModel *model, GtkTreePath *path,
527
                                     GtkTreeIter *iter, gpointer data)
528
{
529
  ModelTypeid *node;
530
  gtk_tree_model_get (GTK_TREE_MODEL (model), iter, COL_TYPEID, &node, -1);
531
  delete node;
532
  gtk_tree_store_set (GTK_TREE_STORE (model), iter, COL_TYPEID, (ModelTypeid*) 0, -1);
533
  return FALSE;
534
}
535
536
537
}//end ns3 namespace
(-)a/src/contrib/gtk-config-store.cc (-470 / +72 lines)
 Lines 1-11    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
1
#include "gtk-config-store.h"
20
#include "gtk-config-store.h"
2
#include "attribute-iterator.h"
3
#include "raw-text-config.h"
21
#include "raw-text-config.h"
4
#include "ns3/config.h"
22
#include "display-functions.h"
5
#include "ns3/string.h"
6
#include "ns3/pointer.h"
7
#include "ns3/log.h"
23
#include "ns3/log.h"
8
#include <gtk/gtk.h>
9
#include <fstream>
24
#include <fstream>
10
25
11
26
 Lines 13-486    Link Here 
13
28
14
NS_LOG_COMPONENT_DEFINE ("GtkconfigStore");
29
NS_LOG_COMPONENT_DEFINE ("GtkconfigStore");
15
30
16
enum {
17
  COL_NODE = 0,
18
  COL_LAST
19
};
20
31
21
struct ModelNode
32
GtkConfigStore::GtkConfigStore ()
22
{
33
{
23
  enum {
24
    // store object + attribute name
25
    NODE_ATTRIBUTE,
26
    // store object + attribute name
27
    NODE_POINTER,
28
    // store object + attribute name
29
    NODE_VECTOR,
30
    // store index + value (object)
31
    NODE_VECTOR_ITEM,
32
    // store object
33
    NODE_OBJECT
34
  } type;
35
  std::string name;
36
  Ptr<Object> object;
37
  uint32_t index;
38
};
39
40
class ModelCreator : public AttributeIterator
41
{
42
public:
43
  ModelCreator ();
44
45
  void Build (GtkTreeStore *treestore);
46
private:
47
  virtual void DoVisitAttribute (Ptr<Object> object, std::string name);
48
  virtual void DoStartVisitObject (Ptr<Object> object);
49
  virtual void DoEndVisitObject (void);
50
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
51
  virtual void DoEndVisitPointerAttribute (void);
52
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector);
53
  virtual void DoEndVisitArrayAttribute (void);
54
  virtual void DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item);
55
  virtual void DoEndVisitArrayItem (void);
56
  void Add (ModelNode *node);
57
  void Remove (void);
58
59
  GtkTreeStore *m_treestore;
60
  std::vector<GtkTreeIter *> m_iters;
61
};
62
63
ModelCreator::ModelCreator ()
64
{}
65
void 
66
ModelCreator::Build (GtkTreeStore *treestore)
67
{
68
  m_treestore = treestore;
69
  m_iters.push_back (0);
70
  Iterate ();
71
  NS_ASSERT (m_iters.size () == 1);
72
}
34
}
73
35
36
void
37
GtkConfigStore::ConfigureDefaults (void)
38
{
39
  //this function should be called before running the script to enable the user
40
  //to configure the default values for the objects he wants to use
41
  GtkWidget *window;
42
  GtkWidget *view;
43
  GtkWidget *scroll;
74
44
75
void
45
  gtk_init (0, 0);
76
ModelCreator::Add (ModelNode *node)
46
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
77
{
47
  gtk_window_set_title (GTK_WINDOW (window), "ns-3 Default attributes.");
78
  GtkTreeIter *parent = m_iters.back ();
48
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
79
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
49
80
  gtk_tree_store_append (m_treestore, current, parent);
50
  g_signal_connect (window, "delete_event", (GCallback)delete_event_callback, window);
81
  gtk_tree_store_set (m_treestore, current,
51
  GtkTreeStore *model = gtk_tree_store_new (COL_LAST, G_TYPE_POINTER);
82
		      COL_NODE, node,
52
  ModelTypeidCreator creator;
83
                     -1);
53
  creator.Build (model);
84
  m_iters.push_back (current);
54
55
  view = create_view_config_default (model);
56
  scroll = gtk_scrolled_window_new (0, 0);
57
  gtk_container_add (GTK_CONTAINER (scroll), view);
58
59
  GtkWidget *vbox = gtk_vbox_new (FALSE, 5);
60
  gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
61
  gtk_box_pack_end (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 0);
62
  GtkWidget *hbox = gtk_hbox_new (FALSE, 5);
63
  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
64
  GtkWidget *save = gtk_button_new_with_label ("Save");
65
  g_signal_connect (save, "clicked",  (GCallback) save_clicked, window);
66
  gtk_box_pack_end (GTK_BOX (hbox), save, FALSE, FALSE, 0);
67
  GtkWidget *load = gtk_button_new_with_label ("Load");
68
  g_signal_connect (load, "clicked",  (GCallback) load_clicked, window);
69
  gtk_box_pack_end (GTK_BOX (hbox), load, FALSE, FALSE, 0);
70
  GtkWidget *exit = gtk_button_new_with_label ("Run Simulation");
71
  g_signal_connect (exit, "clicked",  (GCallback) exit_clicked_callback, window);
72
  gtk_box_pack_end (GTK_BOX (hbox), exit, FALSE, FALSE, 0);
73
74
  gtk_container_add (GTK_CONTAINER (window), vbox);
75
76
  gtk_widget_show_all (window);
77
78
  gtk_main ();
79
80
  gtk_tree_model_foreach (GTK_TREE_MODEL (model), 
81
                          clean_model_callback_config_default,
82
                          0);
83
84
  gtk_widget_destroy (window); 
85
}
85
}
86
void
87
ModelCreator::Remove (void)
88
{
89
  GtkTreeIter *iter = m_iters.back ();
90
  g_free (iter);
91
  m_iters.pop_back ();
92
}
93
94
void 
95
ModelCreator::DoVisitAttribute (Ptr<Object> object, std::string name)
96
{
97
  ModelNode *node = new ModelNode ();
98
  node->type = ModelNode::NODE_ATTRIBUTE;
99
  node->object = object;
100
  node->name = name;
101
  Add (node);
102
  Remove ();
103
}
104
void 
105
ModelCreator::DoStartVisitObject (Ptr<Object> object)
106
{
107
  ModelNode *node = new ModelNode ();
108
  node->type = ModelNode::NODE_OBJECT;
109
  node->object = object;
110
  Add (node);
111
}
112
void 
113
ModelCreator::DoEndVisitObject (void)
114
{
115
  Remove ();
116
}
117
void 
118
ModelCreator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value)
119
{
120
  ModelNode *node = new ModelNode ();
121
  node->type = ModelNode::NODE_POINTER;
122
  node->object = object;
123
  node->name = name;
124
  Add (node);
125
}
126
void 
127
ModelCreator::DoEndVisitPointerAttribute (void)
128
{
129
  Remove ();
130
}
131
void 
132
ModelCreator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
133
{
134
  ModelNode *node = new ModelNode ();
135
  node->type = ModelNode::NODE_VECTOR;
136
  node->object = object;
137
  node->name = name;
138
  Add (node);
139
}
140
void 
141
ModelCreator::DoEndVisitArrayAttribute (void)
142
{
143
  Remove ();
144
}
145
void 
146
ModelCreator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
147
{
148
  GtkTreeIter *parent = m_iters.back ();
149
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
150
  ModelNode *node = new ModelNode ();
151
  node->type = ModelNode::NODE_VECTOR_ITEM;
152
  node->object = item;
153
  node->index = index;
154
  gtk_tree_store_append (m_treestore, current, parent);
155
  gtk_tree_store_set (m_treestore, current,
156
		      COL_NODE, node,
157
                     -1);
158
  m_iters.push_back (current);
159
}
160
void 
161
ModelCreator::DoEndVisitArrayItem (void)
162
{
163
  GtkTreeIter *iter = m_iters.back ();
164
  g_free (iter);
165
  m_iters.pop_back ();  
166
}
167
168
static void
169
cell_data_function_col_1 (GtkTreeViewColumn *col,
170
			  GtkCellRenderer   *renderer,
171
			  GtkTreeModel      *model,
172
			  GtkTreeIter       *iter,
173
			  gpointer           user_data)
174
{
175
  ModelNode *node;
176
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
177
  if (node->type == ModelNode::NODE_ATTRIBUTE)
178
    {
179
      StringValue str;
180
      node->object->GetAttribute (node->name, str);
181
      g_object_set(renderer, "text", str.Get ().c_str (), (char*)0);
182
      g_object_set(renderer, "editable", TRUE, (char*)0);
183
    }
184
  else
185
    {
186
      g_object_set(renderer, "text", "", (char*)0);
187
      g_object_set(renderer, "editable", FALSE, (char*)0);
188
    }
189
}
190
191
static void
192
cell_data_function_col_0 (GtkTreeViewColumn *col,
193
			  GtkCellRenderer   *renderer,
194
			  GtkTreeModel      *model,
195
			  GtkTreeIter       *iter,
196
			  gpointer           user_data)
197
{
198
  ModelNode *node;
199
  gtk_tree_model_get (model, iter, COL_NODE, &node, -1);
200
  g_object_set (renderer, "editable", FALSE, (char*)0);
201
  switch (node->type) {
202
  case ModelNode::NODE_OBJECT:
203
    g_object_set(renderer, "text", node->object->GetInstanceTypeId ().GetName ().c_str (), (char*)0);
204
    break;
205
  case ModelNode::NODE_POINTER:
206
    g_object_set(renderer, "text", node->name.c_str (), (char*)0);
207
    break;
208
  case ModelNode::NODE_VECTOR:
209
    g_object_set(renderer, "text", node->name.c_str (), (char*)0);
210
    break;
211
  case ModelNode::NODE_VECTOR_ITEM: {
212
    std::stringstream oss;
213
    oss << node->index;
214
    g_object_set(renderer, "text", oss.str ().c_str (), (char*)0);
215
  } break;
216
  case ModelNode::NODE_ATTRIBUTE:
217
    g_object_set(renderer, "text", node->name.c_str (), (char*)0);
218
    break;
219
  }
220
}
221
222
223
static void
224
cell_edited_callback (GtkCellRendererText *cell,
225
		      gchar               *path_string,
226
		      gchar               *new_text,
227
		      gpointer             user_data)
228
{
229
  GtkTreeModel *model = GTK_TREE_MODEL (user_data);
230
  GtkTreeIter iter;
231
  gtk_tree_model_get_iter_from_string (model, &iter, path_string);
232
  ModelNode *node;
233
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
234
  NS_ASSERT (node->type == ModelNode::NODE_ATTRIBUTE);
235
  node->object->SetAttribute (node->name, StringValue (new_text));
236
}
237
238
static int
239
get_col_number_from_tree_view_column (GtkTreeViewColumn *col)
240
{
241
  GList *cols;
242
  int   num;
243
  g_return_val_if_fail ( col != 0, -1 );
244
  g_return_val_if_fail ( col->tree_view != 0, -1 );
245
  cols = gtk_tree_view_get_columns(GTK_TREE_VIEW(col->tree_view));
246
  num = g_list_index(cols, (gpointer) col);
247
  g_list_free(cols);
248
  return num;
249
}
250
251
static gboolean
252
cell_tooltip_callback (GtkWidget  *widget,
253
		       gint        x,
254
		       gint        y,
255
		       gboolean    keyboard_tip,
256
		       GtkTooltip *tooltip,
257
		       gpointer    user_data)
258
{
259
  GtkTreeModel *model;
260
  GtkTreeIter iter;
261
  GtkTreeViewColumn * column;
262
  if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), 
263
					  &x, &y, keyboard_tip,
264
					  &model, 0, &iter))
265
    {
266
      return FALSE;
267
    }
268
  if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
269
				      x, y, 0, &column, 0, 0))
270
    {
271
      return FALSE;
272
    }  
273
  int col = get_col_number_from_tree_view_column (column);
274
275
  ModelNode *node;
276
  gtk_tree_model_get (model, &iter, COL_NODE, &node, -1);
277
278
  switch (node->type) {
279
  case ModelNode::NODE_OBJECT:
280
    if (col == 0)
281
      {
282
	std::string tip = "This object is of type " + node->object->GetInstanceTypeId ().GetName ();
283
	gtk_tooltip_set_text (tooltip, tip.c_str ());
284
	return TRUE;
285
      }
286
    break;
287
  case ModelNode::NODE_POINTER:
288
    if (col == 0)
289
      {
290
	PointerValue ptr;
291
	node->object->GetAttribute (node->name, ptr);
292
	std::string tip = "This object is of type " + ptr.GetObject ()->GetInstanceTypeId ().GetName ();
293
	gtk_tooltip_set_text (tooltip, tip.c_str ());
294
	return TRUE;
295
      }
296
    break;
297
  case ModelNode::NODE_VECTOR:
298
    break;
299
  case ModelNode::NODE_VECTOR_ITEM:
300
    if (col == 0)
301
      {
302
	std::string tip = "This object is of type " + node->object->GetInstanceTypeId ().GetName ();
303
	gtk_tooltip_set_text (tooltip, tip.c_str ());
304
	return TRUE;
305
      }
306
    break;
307
  case ModelNode::NODE_ATTRIBUTE: {
308
    uint32_t attrIndex = 0;
309
    TypeId tid;
310
    for (tid = node->object->GetInstanceTypeId (); tid.HasParent (); tid = tid.GetParent ())
311
      {
312
	for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
313
	  {
314
	    if (tid.GetAttributeName (i) == node->name)
315
	      {
316
		attrIndex = i;
317
		goto out;
318
	      }
319
	  }
320
      }
321
    out:
322
    if (col == 0)
323
      {
324
	std::string tip = tid.GetAttributeHelp (attrIndex);
325
	gtk_tooltip_set_text (tooltip, tip.c_str ());
326
      }
327
    else
328
      {
329
	Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (attrIndex);
330
	std::string tip;
331
	tip = "This attribute is of type " + checker->GetValueTypeName ();
332
	if (checker->HasUnderlyingTypeInformation ())
333
	  {
334
	    tip += " " + checker->GetUnderlyingTypeInformation ();
335
	  }
336
	gtk_tooltip_set_text (tooltip, tip.c_str ());
337
      }
338
    return TRUE;
339
  } break;
340
  }
341
  return FALSE;
342
}
343
344
345
static GtkWidget *
346
create_view (GtkTreeStore *model)
347
{
348
  GtkTreeViewColumn   *col;
349
  GtkCellRenderer     *renderer;
350
  GtkWidget           *view;
351
352
  view = gtk_tree_view_new();
353
  g_object_set (view, "has-tooltip", TRUE, (char*)0);
354
  g_signal_connect (view, "query-tooltip", (GCallback) cell_tooltip_callback, 0);
355
  
356
  gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_BOTH);
357
  gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
358
359
  col = gtk_tree_view_column_new();
360
  gtk_tree_view_column_set_title(col, "Object Attributes");
361
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
362
  renderer = gtk_cell_renderer_text_new ();
363
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
364
  gtk_tree_view_column_set_cell_data_func(col, renderer, cell_data_function_col_0, 0, 0);
365
  g_object_set(renderer, "editable", FALSE, (char*)0);
366
367
  col = gtk_tree_view_column_new();
368
  gtk_tree_view_column_set_title(col, "Attribute Value");
369
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
370
  renderer = gtk_cell_renderer_text_new();
371
  g_signal_connect(renderer, "edited", (GCallback) cell_edited_callback, model);
372
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
373
  gtk_tree_view_column_set_cell_data_func(col, renderer, cell_data_function_col_1, 0, 0);
374
375
376
  gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL (model));
377
378
  g_object_unref(model); /* destroy model automatically with view */
379
380
381
  return view;
382
}
383
384
static void
385
save_clicked (GtkButton *button,
386
	      gpointer   user_data)
387
{
388
  GtkWidget *parent_window = GTK_WIDGET (user_data);
389
  GtkWidget *dialog;
390
391
  dialog = gtk_file_chooser_dialog_new ("Save File",
392
					GTK_WINDOW (parent_window),
393
					GTK_FILE_CHOOSER_ACTION_SAVE,
394
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
395
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
396
					(char *)0);
397
  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
398
399
  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "config.txt");
400
401
402
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
403
    {
404
      char *filename;
405
406
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
407
      RawTextConfigSave config;
408
      config.SetFilename (filename);
409
      config.Attributes ();
410
      g_free (filename);
411
    }
412
413
  gtk_widget_destroy (dialog);
414
}
415
416
static void
417
load_clicked (GtkButton *button,
418
	      gpointer   user_data)
419
{
420
  GtkWidget *parent_window = GTK_WIDGET (user_data);
421
  GtkWidget *dialog;
422
423
  dialog = gtk_file_chooser_dialog_new ("Open File",
424
					GTK_WINDOW (parent_window),
425
					GTK_FILE_CHOOSER_ACTION_OPEN,
426
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
427
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
428
					(char *)0);
429
430
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
431
    {
432
      char *filename;
433
434
      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
435
      RawTextConfigLoad config;
436
      config.SetFilename (filename);
437
      config.Attributes ();
438
    }
439
440
  gtk_widget_destroy (dialog);
441
}
442
443
static void 
444
exit_clicked_callback (GtkButton *button,
445
		       gpointer   user_data)
446
{
447
  gtk_main_quit ();
448
  gtk_widget_hide (GTK_WIDGET (user_data));
449
}
450
451
static gboolean
452
delete_event_callback (GtkWidget *widget,
453
		       GdkEvent  *event,
454
		       gpointer   user_data)
455
{
456
  gtk_main_quit ();
457
  gtk_widget_hide (GTK_WIDGET (user_data));
458
  return TRUE;
459
}
460
461
static gboolean 
462
clean_model_callback (GtkTreeModel *model,
463
		      GtkTreePath *path,
464
		      GtkTreeIter *iter,
465
		      gpointer data)
466
{
467
  ModelNode *node;
468
  gtk_tree_model_get (GTK_TREE_MODEL (model), iter, 
469
		      COL_NODE, &node, 
470
		      -1);
471
  delete node;
472
  gtk_tree_store_set (GTK_TREE_STORE (model), iter,
473
		      COL_NODE, (ModelNode*)0,
474
		      -1);
475
  return FALSE;
476
}
477
478
GtkConfigStore::GtkConfigStore ()
479
{}
480
481
void 
482
GtkConfigStore::ConfigureDefaults (void)
483
{}
484
86
485
void 
87
void 
486
GtkConfigStore::ConfigureAttributes (void)
88
GtkConfigStore::ConfigureAttributes (void)
 Lines 494-500    Link Here 
494
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
96
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
495
  gtk_window_set_title (GTK_WINDOW (window), "ns-3 Object attributes.");
97
  gtk_window_set_title (GTK_WINDOW (window), "ns-3 Object attributes.");
496
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
98
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
497
  
99
498
  g_signal_connect (window, "delete_event", (GCallback)delete_event_callback, window);
100
  g_signal_connect (window, "delete_event", (GCallback)delete_event_callback, window);
499
101
500
102
 Lines 528-535    Link Here 
528
  gtk_main ();
130
  gtk_main ();
529
131
530
  gtk_tree_model_foreach (GTK_TREE_MODEL (model), 
132
  gtk_tree_model_foreach (GTK_TREE_MODEL (model), 
531
			  clean_model_callback, 
133
                          clean_model_callback,
532
			  0);
134
                          0);
533
135
534
  gtk_widget_destroy (window);
136
  gtk_widget_destroy (window);
535
}
137
}
(-)a/src/contrib/gtk-config-store.h (+19 lines)
 Lines 1-3    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
1
#ifndef GTK_CONFIG_STORE_H
20
#ifndef GTK_CONFIG_STORE_H
2
#define GTK_CONFIG_STORE_H
21
#define GTK_CONFIG_STORE_H
3
22
(-)c85cb9b073a0 (+130 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
 
20
#include "model-node-creator.h"
21
namespace ns3 {
22
23
ModelCreator::ModelCreator ()
24
{
25
}
26
void
27
28
ModelCreator::Build (GtkTreeStore *treestore)
29
{
30
  m_treestore = treestore;
31
  m_iters.push_back (0);
32
  //this function will go through all the objects and call on them
33
  //DoStartVisitObject, DoIterate and DoEndVisitObject
34
  Iterate ();
35
  NS_ASSERT (m_iters.size () == 1);
36
}
37
38
39
void
40
ModelCreator::Add (ModelNode *node)
41
{
42
  GtkTreeIter *parent = m_iters.back ();
43
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
44
  gtk_tree_store_append (m_treestore, current, parent);
45
  gtk_tree_store_set (m_treestore, current,
46
                      COL_NODE, node, -1);
47
  m_iters.push_back (current);
48
}
49
void
50
ModelCreator::Remove (void)
51
{
52
  GtkTreeIter *iter = m_iters.back ();
53
  g_free (iter);
54
  m_iters.pop_back ();
55
}
56
57
void 
58
ModelCreator::DoVisitAttribute (Ptr<Object> object, std::string name)
59
{
60
  ModelNode *node = new ModelNode ();
61
  node->type = ModelNode::NODE_ATTRIBUTE;
62
  node->object = object;
63
  node->name = name;
64
  Add (node);
65
  Remove ();
66
}
67
void 
68
ModelCreator::DoStartVisitObject (Ptr<Object> object)
69
{
70
  ModelNode *node = new ModelNode ();
71
  node->type = ModelNode::NODE_OBJECT;
72
  node->object = object;
73
  Add (node);
74
}
75
void 
76
ModelCreator::DoEndVisitObject (void)
77
{
78
  Remove ();
79
}
80
void 
81
ModelCreator::DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value)
82
{
83
  ModelNode *node = new ModelNode ();
84
  node->type = ModelNode::NODE_POINTER;
85
  node->object = object;
86
  node->name = name;
87
  Add (node);
88
}
89
void 
90
ModelCreator::DoEndVisitPointerAttribute (void)
91
{
92
  Remove ();
93
}
94
void 
95
ModelCreator::DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector)
96
{
97
  ModelNode *node = new ModelNode ();
98
  node->type = ModelNode::NODE_VECTOR;
99
  node->object = object;
100
  node->name = name;
101
  Add (node);
102
}
103
void 
104
ModelCreator::DoEndVisitArrayAttribute (void)
105
{
106
  Remove ();
107
}
108
void 
109
ModelCreator::DoStartVisitArrayItem (const ObjectVectorValue &vector, uint32_t index, Ptr<Object> item)
110
{
111
  GtkTreeIter *parent = m_iters.back ();
112
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
113
  ModelNode *node = new ModelNode ();
114
  node->type = ModelNode::NODE_VECTOR_ITEM;
115
  node->object = item;
116
  node->index = index;
117
  gtk_tree_store_append (m_treestore, current, parent);
118
  gtk_tree_store_set (m_treestore, current,
119
              COL_NODE, node,
120
                     -1);
121
  m_iters.push_back (current);
122
}
123
void 
124
ModelCreator::DoEndVisitArrayItem (void)
125
{
126
  GtkTreeIter *iter = m_iters.back ();
127
  g_free (iter);
128
  m_iters.pop_back ();  
129
}
130
}//end namespace ns3
(-)c85cb9b073a0 (+73 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 */
19
20
#include "attribute-iterator.h"
21
#include <gtk/gtk.h>
22
23
namespace ns3
24
{
25
26
enum
27
{
28
  COL_NODE = 0, COL_LAST
29
};
30
31
struct ModelNode
32
{
33
  enum
34
  {
35
    // store object + attribute name
36
    NODE_ATTRIBUTE,
37
    // store object + attribute name
38
    NODE_POINTER,
39
    // store object + attribute name
40
    NODE_VECTOR,
41
    // store index + value (object)
42
    NODE_VECTOR_ITEM,
43
    // store object
44
    NODE_OBJECT
45
  } type;
46
  std::string name;
47
  Ptr<Object> object;
48
  uint32_t index;
49
};
50
class ModelCreator : public AttributeIterator
51
{
52
public:
53
  ModelCreator ();
54
55
  void Build (GtkTreeStore *treestore);
56
private:
57
  virtual void DoVisitAttribute (Ptr<Object> object, std::string name);
58
  virtual void DoStartVisitObject (Ptr<Object> object);
59
  virtual void DoEndVisitObject (void);
60
  virtual void DoStartVisitPointerAttribute (Ptr<Object> object, std::string name, Ptr<Object> value);
61
  virtual void DoEndVisitPointerAttribute (void);
62
  virtual void DoStartVisitArrayAttribute (Ptr<Object> object, std::string name, const ObjectVectorValue &vector);
63
  virtual void DoEndVisitArrayAttribute (void);
64
  virtual void DoStartVisitArrayItem (const ObjectVectorValue &vector,
65
                                      uint32_t index, Ptr<Object> item);
66
  virtual void DoEndVisitArrayItem (void);
67
  void Add (ModelNode *node);
68
  void Remove (void);
69
70
  GtkTreeStore *m_treestore;
71
  std::vector<GtkTreeIter *> m_iters;
72
};
73
}
(-)c85cb9b073a0 (+81 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17
 */
18
19
#include "model-typeid-creator.h"
20
21
namespace ns3 {
22
23
ModelTypeidCreator::ModelTypeidCreator ()
24
{
25
}
26
void
27
28
ModelTypeidCreator::Build (GtkTreeStore *treestore)
29
{
30
  m_treestore = treestore;
31
  m_iters.push_back (0);
32
  Iterate ();
33
  NS_ASSERT (m_iters.size () == 1);
34
}
35
36
void
37
ModelTypeidCreator::Add (ModelTypeid *node)
38
{
39
  GtkTreeIter *parent = m_iters.back ();
40
  GtkTreeIter *current = g_new (GtkTreeIter, 1);
41
  gtk_tree_store_append (m_treestore, current, parent);
42
  gtk_tree_store_set (m_treestore, current, COL_TYPEID, node, -1);
43
  m_iters.push_back (current);
44
}
45
46
void
47
ModelTypeidCreator::Remove (void)
48
{
49
  GtkTreeIter *iter = m_iters.back ();
50
  g_free (iter);
51
  m_iters.pop_back ();
52
}
53
54
void 
55
ModelTypeidCreator::VisitAttribute (TypeId tid, std::string name, std::string defaultValue, uint32_t index)
56
{
57
  ModelTypeid *node = new ModelTypeid ();
58
  node->type = ModelTypeid::NODE_ATTRIBUTE;
59
  node->tid = tid;
60
  node->name = name;
61
  node->defaultValue = defaultValue;
62
  node->index = index;
63
  Add (node);
64
  Remove ();
65
}
66
67
void 
68
ModelTypeidCreator::StartVisitTypeId (std::string name)
69
{
70
  ModelTypeid *node = new ModelTypeid ();
71
  node->type = ModelTypeid::NODE_TYPEID;
72
  node->tid = TypeId::LookupByName (name);
73
  Add (node);
74
}
75
76
void 
77
ModelTypeidCreator::EndVisitTypeId (void)
78
{
79
  Remove ();
80
}
81
}//end namespace ns3
(-)c85cb9b073a0 (+82 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *  This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 * 
16
 * Author: Moatamri Faker <faker.moatamri@sophia.inria.fr>
17
 */
18
19
#include "attribute-default-iterator.h"
20
#include "ns3/type-id.h"
21
#include <gtk/gtk.h>
22
#include <vector>
23
24
namespace ns3 {
25
26
enum
27
{
28
  COL_TYPEID = 0, COL_LASTID
29
};
30
31
struct ModelTypeid
32
{
33
  enum
34
  {
35
    // store TypeId + attribute name +defaultValue and index
36
    NODE_ATTRIBUTE,
37
    // store TypeId
38
    NODE_TYPEID
39
  } type;
40
  std::string name;
41
  std::string defaultValue;
42
  //The TypeId object and if it is an attribute, it's the TypeId object of the attribute
43
  TypeId tid;
44
  //stores the index of the attribute in list of attributes for a given TypeId
45
  uint32_t index;
46
};
47
class ModelTypeidCreator : public AttributeDefaultIterator
48
{
49
public:
50
  ModelTypeidCreator ();
51
  /**
52
   * \brief This method will iterate on typeIds having default attributes and create a model
53
   * for them, this model will be used by the view.
54
   */
55
  void Build (GtkTreeStore *treestore);
56
private:
57
  /**
58
   * \brief This method will add a ModelTypeid to the GtkTreeIterator
59
   */
60
  virtual void VisitAttribute (TypeId tid, std::string name, std::string defaultValue, uint32_t index);
61
  /**
62
   * \brief Add a node for the new TypeId object
63
   */
64
  virtual void StartVisitTypeId (std::string name);
65
  /**
66
   * \brief Remove the last gtk tree iterator
67
   */
68
  virtual void EndVisitTypeId (void);
69
  /**
70
   * \brief Adds a treestore iterator to m_treestore model
71
   */
72
  void Add (ModelTypeid *node);
73
  /**
74
   * Removes the last GtkTreeIterator from m_iters
75
   */
76
  void Remove (void);
77
  //this is the TreeStore model corresponding to the view
78
  GtkTreeStore *m_treestore;
79
  //This contains a vector of iterators used to build the TreeStore
80
  std::vector<GtkTreeIter *> m_iters;
81
};
82
}
(-)a/src/contrib/raw-text-config.cc (-1 / +1 lines)
 Lines 41-47    Link Here 
41
    virtual void StartVisitTypeId (std::string name) {
41
    virtual void StartVisitTypeId (std::string name) {
42
      m_typeId = name;
42
      m_typeId = name;
43
    }
43
    }
44
    virtual void VisitAttribute (std::string name, std::string defaultValue) {
44
    virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
45
      *m_os << "default " << m_typeId << "::" << name << " \"" << defaultValue << "\"" << std::endl;
45
      *m_os << "default " << m_typeId << "::" << name << " \"" << defaultValue << "\"" << std::endl;
46
    }
46
    }
47
    std::string m_typeId;
47
    std::string m_typeId;
(-)a/src/contrib/wscript (+2 lines)
 Lines 29-34    Link Here 
29
        'config-store.cc',
29
        'config-store.cc',
30
        'flow-id-tag.cc',
30
        'flow-id-tag.cc',
31
        'attribute-default-iterator.cc',
31
        'attribute-default-iterator.cc',
32
        'model-node-creator.cc',
33
        'model-typeid-creator.cc',
32
        'file-config.cc',
34
        'file-config.cc',
33
        'raw-text-config.cc',
35
        'raw-text-config.cc',
34
        ]
36
        ]
(-)a/src/contrib/xml-config.cc (-1 / +1 lines)
 Lines 90-96    Link Here 
90
    virtual void StartVisitTypeId (std::string name) {
90
    virtual void StartVisitTypeId (std::string name) {
91
      m_typeid = name;
91
      m_typeid = name;
92
    }
92
    }
93
    virtual void VisitAttribute (std::string name, std::string defaultValue) {
93
    virtual void DoVisitAttribute (std::string name, std::string defaultValue) {
94
      int rc;
94
      int rc;
95
      rc = xmlTextWriterStartElement(m_writer, BAD_CAST "default");
95
      rc = xmlTextWriterStartElement(m_writer, BAD_CAST "default");
96
       if (rc < 0) 
96
       if (rc < 0) 

Return to bug 184