Project

General

Profile

Statistics
| Branch: | Revision:

root / include / eventtype.h @ 8b911557

History | View | Annotate | Download (2.84 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
                evType_t* type;
30
                pdf_t pdf;
31

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

    
38

    
39
                bool operator==(const EventType& type) const
40
                {
41
                        return this->type==&type;
42
                }
43

    
44
                bool operator==(const cMessage& msg) const
45
                {
46
                        cModule* mod=msg.getArrivalModule();
47
                        EventType* type=mod->getEventType(&msg);
48
                        return this->type==type;
49
                }
50

    
51
                pdf_t getProbabilityDistributionCopy()
52
                {
53
                        return pdf;
54
                }
55

    
56
                evType_t* getEvType()
57
                {
58
                        return type;
59
                }
60

    
61
                void sample(simtime_t delay)
62
                {
63
                        pdf.sample(delay);
64
                }
65

    
66
                void setBaseLine(size_t newBaseLine)
67
                {
68
                        pdf.setBaseLine(newBaseLine);
69
                }
70
};
71

    
72
class EventType
73
{
74
        private:
75
                succList_t succs;
76
                int modId;
77
                int kind;
78
                int sender;
79
                cTTASLock succListLock;
80
                size_t callCount;
81

    
82
        public:
83
                EventType(const cMessage* const msg)
84
                {
85
                        modId=msg->getArrivalModuleId();
86
                        kind=msg->getKind();
87
                        sender=msg->getSenderModuleId();
88
                        callCount=0;
89
                }
90

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

    
100
                const succList_t& getSuccessors()
101
                {
102
                        succListLock.lock();
103
                        return succs;
104
                }
105

    
106
                void releaseSuccListLock()
107
                {
108
                        succListLock.unlock();
109
                }
110

    
111
                int getModId() const
112
                {
113
                        return modId;
114
                }
115

    
116
                void newSuccEventInstance(const cMessage* const msg,simtime_t delay)
117
                {
118
                        SuccessorEvent* succ=NULL;
119
                        cModule* mod=msg->getArrivalModule();
120
                        EventType* t=mod->getEventType(msg);
121
                        succListLock.lock();
122
                        for(succList_t::iterator it=succs.begin();it!=succs.end();++it)
123
                        {
124
                                if(*it==*t)
125
                                {
126
                                        succ=&(*it);
127
                                        break;
128
                                }
129
                        }
130

    
131
                        // If event type does not exist, create it:
132
                        if(succ==NULL)
133
                        {
134
                                succs.emplace_back(t,delay,callCount);
135
                                succ=&succs.back();
136
                        }
137
                        else
138
                        {
139
                                succ->sample(delay);
140
                        }
141
                        succListLock.unlock();
142
                }
143

    
144
                void isCalled()
145
                {
146
                        callCount++;
147
                        for(succList_t::iterator it=succs.begin();it!=succs.end();++it)
148
                        {
149
                                it->setBaseLine(callCount);
150
                        }
151
                        // XXX: Don't like that. Must iterate over all the list :(
152
                }
153
};
154