Statistics
| Branch: | Revision:

root / include / ccomponenttype.h @ 01873262

History | View | Annotate | Download (11.1 KB)

1
//==========================================================================
2
//  CCOMPONENTTYPE.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//==========================================================================
7

    
8
/*--------------------------------------------------------------*
9
  Copyright (C) 1992-2008 Andras Varga
10
  Copyright (C) 2006-2008 OpenSim Ltd.
11

12
  This file is distributed WITHOUT ANY WARRANTY. See the file
13
  `license' for details on this and other legal matters.
14
*--------------------------------------------------------------*/
15

    
16
#ifndef __CCOMPONENTTYPE_H
17
#define __CCOMPONENTTYPE_H
18

    
19
#include <string>
20
#include <map>
21
#include <set>
22
#include "cpar.h"
23
#include "cgate.h"
24
#include "cownedobject.h"
25

    
26

    
27
NAMESPACE_BEGIN
28

    
29
class cModule;
30
class cChannel;
31
class cProperties;
32
class cIdealChannel;
33
class cDelayChannel;
34
class cDatarateChannel;
35

    
36

    
37
/**
38
 * Common base class for cModuleType and cChannelType.
39
 *
40
 * The getName() method returns the unqualified name (without namespace, e.g.
41
 * "Queue"), and getFullName() returns the qualified name (with namespace,
42
 * e.g. "inet.network.Queue").
43
 *
44
 * @ingroup Internals
45
 */
46
class SIM_API cComponentType : public cNoncopyableOwnedObject
47
{
48
  protected:
49
    std::string qualifiedName;
50

    
51
    typedef std::map<std::string, cParImpl *> StringToParMap;
52
    StringToParMap sharedParMap;
53

    
54
    struct Less {bool operator()(cParImpl *a, cParImpl *b) const;};
55
    typedef std::set<cParImpl *, Less> ParImplSet;
56
    ParImplSet sharedParSet;
57

    
58
  protected:
59
    friend class cComponent;
60
    friend class cModule;
61
    friend class cChannel;
62
    friend class cPar;
63
    friend class cGate;
64

    
65
    // internal: returns the properties for this component.
66
    virtual cProperties *getProperties() const = 0;
67

    
68
    // internal: returns the properties of parameter
69
    virtual cProperties *getParamProperties(const char *paramName) const = 0;
70

    
71
    // internal: returns the properties of gate
72
    virtual cProperties *getGateProperties(const char *gateName) const = 0;
73

    
74
    // internal: returns the properties of a submodule.
75
    // (Subcomponent type is needed because with the NED "like" syntax,
76
    // we need the runtime type not the NED type of the submodule.)
77
    virtual cProperties *getSubmoduleProperties(const char *submoduleName, const char *submoduleType) const = 0;
78

    
79
    // internal: returns the properties of a contained connection.
80
    // (Subcomponent type is needed because with the NED "like" syntax,
81
    // we need the runtime type not the NED type of the submodule.)
82
    virtual cProperties *getConnectionProperties(int connectionId, const char *channelType) const = 0;
83

    
84
    // internal: sharedParMap access
85
    cParImpl *getSharedParImpl(const char *key) const;
86
    void putSharedParImpl(const char *key, cParImpl *value);
87

    
88
    // internal: sharedParSet access
89
    cParImpl *getSharedParImpl(cParImpl *p) const;
90
    void putSharedParImpl(cParImpl *p);
91

    
92
  public:
93
    // internal: delegates to the similar NedTypeInfo method
94
    virtual std::string getPackageProperty(const char *name) const {return "";}
95

    
96
    // internal: delegates to the similar NedTypeInfo method
97
    virtual bool isInnerType() const {return false;}
98

    
99
  public:
100
    /** @name Constructors, destructor, assignment */
101
    //@{
102
    /**
103
     * Constructor. Takes the fully qualified component type name.
104
     */
105
    cComponentType(const char *qname=NULL);
106

    
107
    /**
108
     * Destructor.
109
     */
110
    virtual ~cComponentType();
111
    //@}
112

    
113
    /** @name Redefined cObject member functions. */
114
    //@{
115
    /**
116
     * Returns the fully qualified name (i.e. the simple name prefixed
117
     * with the package name and any existing enclosing NED type names).
118
     *
119
     * Examples:
120
     *
121
     * The fully qualified name for a module named <tt>Fifo</tt> which is
122
     * in the default package is <tt>"Fifo"</tt>.
123
     *
124
     * For a module named <tt>Host</tt> which is in the package <tt>some.package</tt>,
125
     * the fully qualified name is <tt>"some.package.Host"</tt>.
126
     *
127
     * For a channel type <tt>Ch</tt> which is defined as an inner type inside
128
     * the network <tt>Network</tt> in a package named <tt>some.package</tt>, the
129
     * fully qualified name is <tt>"some.package.Network.Ch"</tt>.
130
     */
131
    virtual const char *getFullName() const  {return qualifiedName.c_str();}
132
    //@}
133

    
134
    /**
135
     * Finds a component type by fully qualified NED type name.
136
     * Returns NULL if not found.
137
     */
138
    static cComponentType *find(const char *qname);
139

    
140
    /**
141
     * Finds a component type by fully qualified NED type name.
142
     * Throws an error if not found.
143
     */
144
    static cComponentType *get(const char *qname);
145
};
146

    
147

    
148
/**
149
 * Abstract class for creating a module of a specific type.
150
 *
151
 * A cModuleType object exist for each module type (simple or compound).
152
 *
153
 * @ingroup Internals
154
 */
155
class SIM_API cModuleType : public cComponentType
156
{
157
    friend class cModule;
158
    friend class cCompoundModule;
159
  protected:
160
    /**
161
     * Creates the module object. To be defined in subclasses.
162
     */
163
    virtual cModule *createModuleObject() = 0;
164

    
165
    /**
166
     * Adds parameters and gates to a newly created module object.
167
     * Gate vectors will be created with zero size, and a further
168
     * call to setupGateVectors() will be needed once parameter values
169
     * have been finalized.
170
     */
171
    virtual void addParametersAndGatesTo(cModule *mod) = 0;
172

    
173
    /**
174
     * Sets gate vector sizes on the module. This must be called AFTER all
175
     * parameters have been set (see finalizeParameters()) because gate
176
     * vector sizes may depend on parameter values; and it it must be
177
     * invoked before connecting the gates and calling mod->buildInside().
178
     */
179
    virtual void setupGateVectors(cModule *mod) = 0;
180

    
181
    /**
182
     * Creates and connects submodules of a newly created module object.
183
     * To be defined in subclasses. addParametersAndGatesTo() and
184
     * setupGateVectors() must have been already called at this point.
185
     *
186
     * NOTE: If you have an old simulation model that attempts to call
187
     * this method directly, it is using an API call which has been DEPRECATED
188
     * since OMNeT++ 2.3b1 -- please change the code to <tt>mod->buildInside()</tt>.
189
     */
190
    virtual void buildInside(cModule *mod) = 0;
191

    
192
    /**
193
     * Utility function: instantiates the given class, and tries to cast the
194
     * result to cModule. Raises an error if class was not found or could
195
     * not be cast.
196
     */
197
    cModule *instantiateModuleClass(const char *classname);
198

    
199
  public:
200
    /** @name Constructors, destructor, assignment */
201
    //@{
202
    /**
203
     * Constructor.
204
     */
205
    cModuleType(const char *qname=NULL);
206
    //@}
207

    
208
    /** @name Misc */
209
    //@{
210
    /**
211
     * Returns true if the module type was declared with the "network" keyword.
212
     */
213
    virtual bool isNetwork() const = 0;
214

    
215
    /**
216
     * Returns true if this object represents a simple module type.
217
     */
218
    virtual bool isSimple() const = 0;
219
    //@}
220

    
221
    /** @name Module creation */
222
    //@{
223

    
224
    /**
225
     * Creates a module which is not element of a module vector.
226
     * In addition to creating an object of the correct type,
227
     * this function inserts the module into the simulation's data structure,
228
     * and adds the parameters and gates specified in the NED declaration.
229
     */
230
    virtual cModule *create(const char *name, cModule *parentmod);
231

    
232
    /**
233
     * Creates a module to be an element of a module vector.
234
     * The last two arguments specify the vector size and the index
235
     * of the new module within the vector.
236
     */
237
    virtual cModule *create(const char *name, cModule *parentmod, int vectorsize, int index);
238

    
239
    /**
240
     * This is a convenience function to get a module up and running in one step.
241
     *
242
     * First, the module is created using create() and buildInside(), then
243
     * a starter message is created (for activity() modules only),
244
     * then initialize() is called (mod->callInitialize()).
245
     *
246
     * This method works for simple and compound modules alike. Not applicable
247
     * if the module:
248
     *  - has parameters to be set
249
     *  - gate vector sizes to be set
250
     *  - gates to be connected before initialize()
251
     */
252
    virtual cModule *createScheduleInit(const char *name, cModule *parentmod);
253
    //@}
254

    
255
    /**
256
     * Finds a module type by fully qualified NED type name.
257
     * Returns NULL if not found.
258
     */
259
    static cModuleType *find(const char *qname);
260

    
261
    /**
262
     * Finds a module type by fully qualified NED type name.
263
     * Throws an error if not found.
264
     */
265
    static cModuleType *get(const char *qname);
266
};
267

    
268

    
269
/**
270
 * Abstract base class for creating a channel of a given type.
271
 *
272
 * @ingroup Internals
273
 */
274
class SIM_API cChannelType : public cComponentType
275
{
276
  protected:
277
    static cChannelType *idealChannelType;
278
    static cChannelType *delayChannelType;
279
    static cChannelType *datarateChannelType;
280

    
281
  protected:
282
    /**
283
     * Creates the channel object. To be defined in subclasses.
284
     */
285
    virtual cChannel *createChannelObject() = 0;
286

    
287
    /**
288
     * Adds parameters to a newly created channel object.
289
     * To be defined in subclasses.
290
     */
291
    virtual void addParametersTo(cChannel *channel) = 0;
292

    
293
    /**
294
     * Utility function: instantiates the given class, and tries to cast the
295
     * result to cChannel. Raises an error if class was not found or could not be cast.
296
     */
297
    cChannel *instantiateChannelClass(const char *classname);
298

    
299
  public:
300
    /** @name Constructors, destructor, assignment */
301
    //@{
302

    
303
    /**
304
     * Constructor.
305
     */
306
    cChannelType(const char *qname=NULL);
307

    
308
    /** @name Channel object creation */
309
    //@{
310
    /**
311
     * Factory method to create a channel object.
312
     *
313
     * In addition to creating an object of the correct type,
314
     * this methods inserts it into the simulation's data structure,
315
     * and adds the parameters specified in the NED declaration.
316
     */
317
    virtual cChannel *create(const char *name);
318
    //@}
319

    
320
    /**
321
     * Finds a channel type by fully qualified NED type name.
322
     * Returns NULL if not found.
323
     */
324
    static cChannelType *find(const char *qname);
325

    
326
    /**
327
     * Finds a channel type by fully qualified NED type name.
328
     * Throws an error if not found.
329
     */
330
    static cChannelType *get(const char *qname);
331

    
332
    /**
333
     * Equivalent to <tt>cChannelType::get("ned.IdealChannel")</tt>,
334
     * but more efficient.
335
     */
336
    static cChannelType *getIdealChannelType();
337

    
338
    /**
339
     * Equivalent to <tt>cChannelType::get("ned.DelayChannel")</tt>,
340
     * but more efficient.
341
     */
342
    static cChannelType *getDelayChannelType();
343

    
344
    /**
345
     * Equivalent to <tt>cChannelType::get("ned.DatarateChannel")</tt>,
346
     * but more efficient.
347
     */
348
    static cChannelType *getDatarateChannelType();
349

    
350
    /**
351
     * DEPRECATED. Use <tt>cIdealChannel::create(name)</tt> instead.
352
     */
353
    static _OPPDEPRECATED cIdealChannel *createIdealChannel(const char *name);
354

    
355
    /**
356
     * DEPRECATED. Use <tt>cDelayChannel::create(name)</tt> instead.
357
     */
358
    static _OPPDEPRECATED cDelayChannel *createDelayChannel(const char *name);
359

    
360
    /**
361
     * DEPRECATED. Use <tt>cDatarateChannel::create(name)</tt> instead.
362
     */
363
    static _OPPDEPRECATED cDatarateChannel *createDatarateChannel(const char *name);
364
};
365

    
366
NAMESPACE_END
367

    
368

    
369
#endif
370

    
371