-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_queue.cpp
58 lines (52 loc) · 1.48 KB
/
message_queue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*atomic model message_queue*/
#include "message_queue.h"
#include "message.h"
#include "mainsimu.h"
#include "strutil.h"
MessageQueue::MessageQueue (const string &name)
: Atomic (name)
, coin_controller_in( addInputPort("coin_controller_in") )
, item_selector_in ( addInputPort ( "item_selector_in" ) )
, change_request_in ( addInputPort ( "change_request_in") )
, done ( addInputPort ( "done" ) )
, message_out ( addOutputPort ("message_out") )
, preparationTime (0, 0, 5, 0)
{
string time(MainSimulator::Instance().getParameter(description(), "preparation"));
if (time!=" ")
preparationTime = time;
}
Model &MessageQueue :: initFunction()
{
this->passivate();
this->elements.erase(elements.begin(), elements.end() );
return *this;
}
Model &MessageQueue::externalFunction(const ExternalMessage &msg)
{
if (( msg.port() == coin_controller_in )||(msg.port() == item_selector_in )||(msg.port() == change_request_in))
{
elements.push_back (msg.value());
if (elements.size() == 1 )
this->holdIn ( active, preparationTime );
}
if ( msg.port() == done )
{
elements.pop_front();
if ( !elements.empty() )
{
this->holdIn ( active, preparationTime );
}
}
return *this;
}
Model &MessageQueue::internalFunction ( const InternalMessage &)
{
this->passivate();
return *this;
}
Model &MessageQueue::outputFunction( const InternalMessage &msg)
{
this->sendOutput ( msg.time(), message_out, elements.front() );
return *this;
}