Project

General

Profile

Statistics
| Branch: | Revision:

root / include / cmodelchange.h @ ffa9279f

History | View | Annotate | Download (15.4 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  CMODELCHANGE.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//==========================================================================
8
9
/*--------------------------------------------------------------*
10
  Copyright (C) 1992-2008 Andras Varga
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16
17
#ifndef __CMODELCHANGE_H
18
#define __CMODELCHANGE_H
19
20
#include "cobject.h"
21
22
NAMESPACE_BEGIN
23
24
/**
25
 * A signal which is fired before simulation model changes such as module
26
 * creation or connection creation. The signals carry data objects that
27
 * describe the type and details the change. The data objects are subclassed
28
 * from cModelChangeNotification, and begin with the prefix "cPre".
29
 *
30
 * These classes include:
31
 *    - cPreModuleAddNotification,
32
 *    - cPreModuleDeleteNotification,
33
 *    - cPreModuleReparentNotification,
34
 *    - cPreGateAddNotification,
35
 *    - cPreGateDeleteNotification,
36
 *    - cPreGateVectorResizeNotification,
37
 *    - cPreGateConnectNotification,
38
 *    - cPreGateDisconnectNotification,
39
 *    - cPrePathCreateNotification,
40
 *    - cPrePathCutNotification,
41
 *    - cPreParameterChangeNotification,
42
 *    - cPreDisplayStringChangeNotification
43
 *
44
 * In the listener, use dynamic_cast<> to figure out what notification arrived.
45
 *
46
 * This signal is fired on the module or channel affected by the change,
47
 * and NOT on the module which executes the code that causes the change.
48
 * For example, preModuleDeleted is fired on the module about to be removed,
49
 * and not on the module that contains the deleteModule() call.
50
 *
51
 * See also: cComponent::emit(), cComponent::subscribe()
52
 *
53
 * @ingroup Signals
54
 */
55
#define PRE_MODEL_CHANGE   ((simsignal_t)0)
56
57
/**
58
 * A signal which is fired after simulation model changes such as module
59
 * creation or connection creation. The signals carry data objects that
60
 * describe the type and details the change. The data objects are subclassed
61
 * from cModelChangeNotification, and begin with the prefix "cPost".
62
 *
63
 * These classes include:
64
 *    - cPostModuleAddNotification,
65
 *    - cPostModuleDeleteNotification,
66
 *    - cPostModuleReparentNotification,
67
 *    - cPostGateAddNotification,
68
 *    - cPostGateDeleteNotification,
69
 *    - cPostGateVectorResizeNotification,
70
 *    - cPostGateConnectNotification,
71
 *    - cPostGateDisconnectNotification,
72
 *    - cPostPathCreateNotification,
73
 *    - cPostPathCutNotification,
74
 *    - cPostParameterChangeNotification,
75
 *    - cPostDisplayStringChangeNotification,
76
 *    - cPostModuleAddNotification,
77
 *    - cPostModuleDeleteNotification,
78
 *    - cPostModuleReparentNotification,
79
 *    - cPostGateAddNotification,
80
 *    - cPostGateDeleteNotification,
81
 *    - cPostGateVectorResizeNotification,
82
 *    - cPostGateConnectNotification,
83
 *    - cPostGateDisconnectNotification,
84
 *    - cPostPathCreateNotification,
85
 *    - cPostPathCutNotification,
86
 *    - cPostParameterChangeNotification,
87
 *    - cPostDisplayStringChangeNotification
88
 *
89
 * In the listener, use dynamic_cast<> to figure out what notification arrived.
90
 *
91
 * This signal is fired on the module or channel affected by the change,
92
 * and NOT on the module which executes the code that causes the change.
93
 * For example, postModuleDeleted is fired on the deleted module's parent
94
 * module (because the original module no longer exists), and not on the
95
 * module that contained the deleteModule() call.
96
 *
97
 * See also: cComponent::emit(), cComponent::subscribe()
98
 *
99
 * @ingroup Signals
100
 */
101
#define POST_MODEL_CHANGE  ((simsignal_t)1)
102
103
104
/**
105
 * Common base class for data objects that accompany PRE_MODEL_CHANGE
106
 * and POST_MODEL_CHANGE notifications (signals).
107
 *
108
 * @ingroup Signals
109
 */
110
class SIM_API cModelChangeNotification : public cObject, noncopyable
111
{
112
};
113
114
/**
115
 * Fired at the top of cModuleType::create(); fields contain the cModuleType
116
 * object, and the arguments of the create() method call.
117
 *
118
 * @ingroup Signals
119
 */
120
class SIM_API cPreModuleAddNotification : public cModelChangeNotification
121
{
122
  public:
123
    cModuleType *moduleType;
124
    const char *moduleName;
125
    cModule *parentModule;
126
    int vectorSize;
127
    int index;
128
};
129
130
/**
131
 * Fired at the end of cModuleType::create(); at that stage the module is
132
 * already created, its gates and parameters are added and it is inserted
133
 * into the model, but it is not yet initialized nor its submodules
134
 * are created yet.
135
 *
136
 * @ingroup Signals
137
 */
138
class SIM_API cPostModuleAddNotification : public cModelChangeNotification
139
{
140
  public:
141
    cModule *module;
142
};
143
144
/**
145
 * Fired at the top of cModule::deleteModule(). The module still exists
146
 * at this point. Note that this notification also gets fired when the
147
 * network is being deleted after simulation completion.
148
 *
149
 * @ingroup Signals
150
 */
151
class SIM_API cPreModuleDeleteNotification : public cModelChangeNotification
152
{
153
  public:
154
    cModule *module;
155
};
156
157
/**
158
 * Fired at the end of cModule::deleteModule(). The module object no longer
159
 * exists at this point, and its submodules have also been deleted.
160
 * Fields include properties of the deleted module. It also includes the
161
 * module pointer (in case it serves as a key in some user data structure),
162
 * but it must NOT be dereferenced because it points to a deleted object.
163
 *
164
 * @ingroup Signals
165
 */
166
class SIM_API cPostModuleDeleteNotification : public cModelChangeNotification
167
{
168
  public:
169
    cModule *module;  // this is the pointer of the already deleted module -- DO NOT DEREFERENCE
170
    int moduleId;
171
    cModuleType *moduleType;
172
    const char *moduleName;
173
    cModule *parentModule;
174
    int vectorSize;
175
    int index;
176
};
177
178
/**
179
 * Fired at the top of cModule::changeParentTo(), before any changes have
180
 * been done.
181
 *
182
 * @ingroup Signals
183
 */
184
class SIM_API cPreModuleReparentNotification : public cModelChangeNotification
185
{
186
  public:
187
    cModule *module;
188
    cModule *newParentModule;
189
};
190
191
/**
192
 * Fired at the end of cModule::changeParentTo().
193
 *
194
 * @ingroup Signals
195
 */
196
class SIM_API cPostModuleReparentNotification : public cModelChangeNotification
197
{
198
  public:
199
    cModule *module;
200
    cModule *oldParentModule;
201
};
202
203
/**
204
 * This gets fired at the top of cModule::addGate(), that is, when a gate
205
 * or gate vector is added to the module.
206
 *
207
 * Note: this notification is fired for the gate or gate vector as a
208
 * whole, and not for individual gate objects in it. That is, a single
209
 * notification is fired for an inout gate (which is a gate pair) and
210
 * for gate vectors as well.
211
 *
212
 * Fields in this class carry the module object on which the gate or gate vector
213
 * being created, and the arguments of the addGate() method call.
214
 *
215
 * @ingroup Signals
216
 */
217
class SIM_API cPreGateAddNotification : public cModelChangeNotification
218
{
219
  public:
220
    cModule *module;
221
    const char *gateName;
222
    cGate::Type gateType;
223
    bool isVector;
224
};
225
226
/**
227
 * This gets fired at the bottom of cModule::addGate(), that is, when a gate
228
 * or gate vector was added to the module.
229
 *
230
 * Note: this notification is fired for the gate or gate vector as a
231
 * whole, and not for individual gate objects in it. That is, a single
232
 * notification is fired for an inout gate (which is a gate pair) and
233
 * for gate vectors as well.
234
 *
235
 * Fields in this class carry the module object on which the gate or gate vector
236
 * was created, and the name of the gate or gate vector.
237
 *
238
 * @ingroup Signals
239
 */
240
class SIM_API cPostGateAddNotification : public cModelChangeNotification
241
{
242
  public:
243
    cModule *module;
244
    const char *gateName;
245
};
246
247
/**
248
 * Fired at the top of cModule::deleteGate(). The gate or gate vector still
249
 * exists at this point.
250
 *
251
 * Note: this notification is fired for the gate or gate vector as a
252
 * whole, and not for individual gate objects in it. That is, a single
253
 * notification is fired for an inout gate (which is a gate pair) and
254
 * for gate vectors as well.
255
 *
256
 * @ingroup Signals
257
 */
258
class SIM_API cPreGateDeleteNotification : public cModelChangeNotification
259
{
260
  public:
261
    cModule *module;
262
    const char *gateName;
263
};
264
265
/**
266
 * Fired at the end of cModule::deleteGate(). The gate or gate vector
267
 * no longer exists at this point.
268
 *
269
 * Note: this notification is fired for the gate or gate vector as a
270
 * whole, and not for individual gate objects in it. That is, a single
271
 * notification is fired for an inout gate (which is a gate pair) and
272
 * for gate vectors as well.
273
 *
274
 * Fields include properties of the deleted gate or gate vector.
275
 *
276
 * @ingroup Signals
277
 */
278
class SIM_API cPostGateDeleteNotification : public cModelChangeNotification
279
{
280
  public:
281
    cModule *module;
282
    const char *gateName;
283
    cGate::Type gateType;
284
    bool isVector;
285
    int vectorSize;
286
};
287
288
/**
289
 * Fired at the top of cModule::setGateSize(). Note that other cModule methods
290
 * used for implementing the NED "gate++" syntax also expand the gate vector,
291
 * and fire this notification. These methods are getOrCreateFirstUnconnectedGate()
292
 * and getOrCreateFirstUnconnectedGatePair()).
293
 *
294
 * @ingroup Signals
295
 */
296
class SIM_API cPreGateVectorResizeNotification : public cModelChangeNotification
297
{
298
  public:
299
    cModule *module;
300
    const char *gateName;
301
    int newSize;
302
};
303
304
/**
305
 * Fired at the end of cModule::setGateSize(). Note that other cModule methods
306
 * used for implementing the NED "gate++" syntax also expand the gate vector,
307
 * and fire this notification. These methods are getOrCreateFirstUnconnectedGate()
308
 * and getOrCreateFirstUnconnectedGatePair()).
309
 *
310
 * @ingroup Signals
311
 */
312
class SIM_API cPostGateVectorResizeNotification : public cModelChangeNotification
313
{
314
  public:
315
    cModule *module;
316
    const char *gateName;
317
    int oldSize;
318
};
319
320
/**
321
 * This notification is fired at the top of cGate::connectTo().
322
 * This notification is fired on the module that contains the source gate.
323
 * of the connection. If you wish to listen on the target gate of the
324
 * connection being connected, you should add the listener to the
325
 * parent module (as notifications propagate up).
326
 *
327
 * @see cPrePathCreateNotification
328
 * @ingroup Signals
329
 */
330
class SIM_API cPreGateConnectNotification : public cModelChangeNotification
331
{
332
  public:
333
    cGate *gate;
334
    cGate *targetGate;
335
    cChannel *channel;
336
};
337
338
/**
339
 * This notification is fired at the end of cGate::connectTo(), to announce that
340
 * a connection between the given gate and its peer (gate->getNextGate())
341
 * has been created.
342
 * This notification is fired on the module that contains the source gate.
343
 * of the connection. If you wish to listen on the target gate of the
344
 * connection being connected, you should add the listener to the
345
 * parent module (as notifications propagate up).
346
 *
347
 * @see cPostPathCreateNotification
348
 */
349
class SIM_API cPostGateConnectNotification : public cModelChangeNotification
350
{
351
  public:
352
    cGate *gate;
353
};
354
355
/**
356
 * This notification is fired at the top of cGate::disconnect(), to announce
357
 * that the connection between the given gate and its peer (gate->getNextGate())
358
 * is about to be deleted.
359
 * This notification is fired on the module that contains the source gate.
360
 * of the connection. If you wish to listen on the target gate of the
361
 * connection being disconnected, you should add the listener to the
362
 * parent module (as notifications propagate up).
363
 *
364
 * @see cPrePathCutNotification
365
 * @ingroup Signals
366
 */
367
class SIM_API cPreGateDisconnectNotification : public cModelChangeNotification
368
{
369
  public:
370
    cGate *gate;
371
};
372
373
/**
374
 * This notification is fired at the end of cGate::disconnect(), to announce
375
 * that the connection between the given gates has been deleted.
376
 * This notification is fired on the module that contains the source gate.
377
 * of the connection. If you wish to listen on the target gate of the
378
 * connection being disconnected, you should add the listener to the
379
 * parent module (as notifications propagate up).
380
 *
381
 * @see cPostPathCutNotification
382
 * @ingroup Signals
383
 */
384
class SIM_API cPostGateDisconnectNotification : public cModelChangeNotification
385
{
386
  public:
387
    cGate *gate;
388
    cGate *targetGate;
389
    cChannel *channel; // points to  valid object, but will be deleted once the notification has finished
390
};
391
392
/**
393
 * Base class for path change notifications. Like gate connect/disconnect
394
 * notifications, they are fired when a gate gets connected/disconnected;
395
 * the difference is that path change notifications are fired on the owner
396
 * modules of the start AND end gates of the path that contains the connection
397
 * (two notifications!), NOT on the module of the gate being connected or
398
 * disconnected. See also cGate's getPathStartGate() and getPathEndGate()
399
 * methods.
400
 *
401
 * The purpose of this notification is to make it possible to get away with
402
 * only local listeners in simple modules. If this notification didn't exist,
403
 * users would have to listen for gate connect/disconnect notifications at the
404
 * top-level module, which is not very efficient (as ALL pre/post model change
405
 * events from all modules would then have to be propagated up to the top).
406
 *
407
 * @ingroup Signals
408
 */
409
class SIM_API cPathChangeNotification : public cModelChangeNotification
410
{
411
  public:
412
    cGate *pathStartGate;
413
    cGate *pathEndGate;
414
    cGate *changedGate; // the gate that got connected or disconnected
415
};
416
417
/**
418
 * This notification is fired at the top of cGate::connectTo() on the owner
419
 * modules of the start AND end gates of the future connection path that will
420
 * be created when the gate gets connected.
421
 * See cPathChangeNotification for more details.
422
 *
423
 * @ingroup Signals
424
 */
425
class SIM_API cPrePathCreateNotification : public cPathChangeNotification { };
426
427
/**
428
 * This notification is fired at the end of cGate::connectTo() on the owner
429
 * modules of the start AND end gates of the connection path that was formed
430
 * when the gate was connected.
431
 * See cPathChangeNotification for more details.
432
 *
433
 * @ingroup Signals
434
 */
435
class SIM_API cPostPathCreateNotification : public cPathChangeNotification { };
436
437
/**
438
 * This notification is fired at the top of cGate::disconnect() on the owner
439
 * modules of the start AND end gates of the connection path that is about to
440
 * be cut when the gate gets connected.
441
 * See cPathChangeNotification for more details.
442
 *
443
 * @ingroup Signals
444
 */
445
class SIM_API cPrePathCutNotification : public cPathChangeNotification { };
446
447
/**
448
 * This notification is fired at the end of cGate::disconnect() on the owner
449
 * modules of the start AND end gates of the connection path that was cut when
450
 * the gate got disconnected.
451
 * See cPathChangeNotification for more details.
452
 *
453
 * @ingroup Signals
454
 */
455
class SIM_API cPostPathCutNotification : public cPathChangeNotification { };
456
457
/**
458
 * This notification gets fired before a module or channel parameter value was
459
 * changed.
460
 *
461
 * @ingroup Signals
462
 */
463
class SIM_API cPreParameterChangeNotification : public cModelChangeNotification
464
{
465
  public:
466
    cPar *par;
467
};
468
469
/**
470
 * This notification gets fired after a module or channel parameter value was
471
 * changed.
472
 *
473
 * @ingroup Signals
474
 */
475
class SIM_API cPostParameterChangeNotification : public cModelChangeNotification
476
{
477
  public:
478
    cPar *par;
479
};
480
481
/**
482
 * This notification gets fired before a display string gets changed.
483
 *
484
 * @ingroup Signals
485
 */
486
class SIM_API cPreDisplayStringChangeNotification : public cModelChangeNotification
487
{
488
  public:
489
    cDisplayString *displayString;
490
};
491
492
/**
493
 * This notification gets fired after a display string gets changed.
494
 *
495
 * @ingroup Signals
496
 */
497
class SIM_API cPostDisplayStringChangeNotification : public cModelChangeNotification
498
{
499
  public:
500
    cDisplayString *displayString;
501
};
502
503
NAMESPACE_END
504
505
#endif