Statistics
| Branch: | Revision:

root / include / eventtype.h @ 0e46fceb

History | View | Annotate | Download (2.49 KB)

1
//==========================================================================
2
//   EVENTTYPE.H  -  header for
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//  Declaration of the following classes:
8
//    EventType: identifying an event type
9
//
10
//==========================================================================
11

    
12
/*--------------------------------------------------------------*
13
 Copyright (C) 2013 Mirko Stoffers
14

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

    
19
#pragma once
20

    
21
#include "cmessage.h"
22

    
23
#include "simkerneldefs.h"
24
#include "pdf.h"
25

    
26
class SuccessorEvent
27
{
28
        private:
29
                const evType_t* type;
30
                pdf_t pdf;
31

    
32
        public:
33
                SuccessorEvent(const EventType* const type, simtime_t firstSample) : pdf(firstSample)
34
                {
35
                        this->type=type;
36
                }
37

    
38
                SuccessorEvent(const cMessage* const msg, simtime_t firstSample) : pdf(firstSample)
39
                {
40
                        cModule* mod=msg->getArrivalModule();
41
                        type=mod->getEventType(msg);
42
                }
43

    
44
                bool operator==(const EventType& type) const
45
                {
46
                        return this->type==&type;
47
                }
48

    
49
                bool operator==(const cMessage& msg) const
50
                {
51
                        cModule* mod=msg.getArrivalModule();
52
                        EventType* type=mod->getEventType(&msg);
53
                        return this->type==type;
54
                }
55

    
56
                pdf_t getProbabilityDistributionCopy()
57
                {
58
                        return pdf;
59
                }
60

    
61
                const evType_t* getEvType()
62
                {
63
                        return type;
64
                }
65

    
66
                void sample(simtime_t delay)
67
                {
68
                        pdf.sample(delay);
69
                }
70
};
71

    
72
class EventType
73
{
74
        private:
75
                succList_t succs;
76
                int modId;
77
                int kind;
78
                int sender;
79

    
80
        public:
81
                EventType(const cMessage* const msg)
82
                {
83
                        modId=msg->getArrivalModuleId();
84
                        kind=msg->getKind();
85
                        sender=msg->getSenderModuleId();
86
                }
87

    
88
                bool operator==(const cMessage& msg)
89
                {
90
                        return
91
                                msg.getArrivalModuleId()==modId
92
                                && msg.getKind()==kind
93
                                && msg.getSenderModuleId()==sender
94
                                ;
95
                }
96

    
97
                const succList_t& getSuccessors() const
98
                {
99
                        return succs;
100
                }
101

    
102
                int getModId() const
103
                {
104
                        return modId;
105
                }
106

    
107
                void newSuccEventInstance(const cMessage* const msg,simtime_t delay)
108
                {
109
                        SuccessorEvent* succ=NULL;
110
                        cModule* mod=msg->getArrivalModule();
111
                        EventType* t=mod->getEventType(msg);
112
                        for(succList_t::iterator it=succs.begin();it!=succs.end();++it)
113
                        {
114
                                if(*it==*t)
115
                                {
116
                                        succ=&(*it);
117
                                        break;
118
                                }
119
                        }
120

    
121
                        // If event type does not exist, create it:
122
                        if(succ==NULL)
123
                        {
124
                                succs.emplace_back(t,delay);
125
                                succ=&succs.back();
126
                        }
127

    
128
                        succ->sample(delay);
129
                }
130
};
131