Project

General

Profile

Statistics
| Branch: | Revision:

root / src / envir / appreg.h @ fbe00e73

History | View | Annotate | Download (2.44 KB)

1
//==========================================================================
2
//  APPREG.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Declaration of the following classes:
7
//    Registration of user interface classes
8
//
9
//  Author: Andras Varga
10
//
11
//==========================================================================
12

    
13
/*--------------------------------------------------------------*
14
  Copyright (C) 1992-2008 Andras Varga
15
  Copyright (C) 2006-2008 OpenSim Ltd.
16

17
  This file is distributed WITHOUT ANY WARRANTY. See the file
18
  `license' for details on this and other legal matters.
19
*--------------------------------------------------------------*/
20

    
21
#ifndef __APPREG_H
22
#define __APPREG_H
23

    
24
#include "envirdefs.h"
25
#include "cenvir.h"
26
#include "globals.h"
27
#include "onstartup.h"
28

    
29
NAMESPACE_BEGIN
30

    
31
//
32
// Register_OmnetApp() macro, omnetapps list, cOmnetAppRegistration class.
33
//
34
// For registering user interfaces as subclasses of cEnvir.
35
// Creating the user interface object allows us to link an envir.dll on
36
// Windows without having to know in which dll (cmdenv, tkenv) cEnvir's
37
// appropriate subclass will come from. (On Unix, this was no problem anyway...)
38
//
39
//  score:   by default, OMNeT++ will choose the user interface with the
40
//           highest score when it starts
41
//  desc:    textual description of the user interface
42
//
43

    
44

    
45
// the macro
46
#define Register_OmnetApp(UINAME,CLASSNAME,SCORE,DESCR) \
47
    static cRunnableEnvir *__FILEUNIQUENAME__() {return new CLASSNAME();} \
48
    EXECUTE_ON_STARTUP(omnetapps.getInstance()->add(new cOmnetAppRegistration(UINAME,SCORE,DESCR,__FILEUNIQUENAME__)))
49

    
50
extern ENVIR_API cGlobalRegistrationList omnetapps;
51

    
52
// registration class
53
class ENVIR_API cOmnetAppRegistration : public cOwnedObject
54
{
55
    typedef cRunnableEnvir *(*AppCreatorFunc)();
56
    AppCreatorFunc creatorfunc;
57
    std::string desc;
58
    int scor;
59
  public:
60
    cOmnetAppRegistration(const char *name, int score, const char *description, AppCreatorFunc f) :
61
      cOwnedObject(name, false), creatorfunc(f), desc(description), scor(score) {}
62
    virtual ~cOmnetAppRegistration()  {}
63

    
64
    // redefined functions
65
    virtual const char *getClassName() const {return "cOmnetAppRegistration";}
66

    
67
    // new functions
68
    cRunnableEnvir *createOne()  {return creatorfunc();}
69
    std::string info() const {return desc;}
70
    int getScore()  {return scor;}
71

    
72
    static cOmnetAppRegistration *chooseBest();
73
};
74

    
75
NAMESPACE_END
76

    
77
#endif
78