-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgateway.cpp
More file actions
95 lines (81 loc) · 2.46 KB
/
gateway.cpp
File metadata and controls
95 lines (81 loc) · 2.46 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************
*
* DESCRIPTION: class Gateway
*
* AUTHOR: Umar Farooq
*
* EMAIL: ufarooq@sce.carleton.ca
*
* DATE: 17/10/2003
*
*******************************************************************/
/** include files **/
#include <math.h>
#include "gateway.h" // base header
#include "message.h" // InternalMessage ....
#include "mainsimu.h" // class MainSimulator
/*******************************************************************
* Function Name: Gateway
* Description: constructor
********************************************************************/
Gateway::Gateway( const string &name )
: Atomic( name )
, inCObject( addInputPort( "inCObject" ) )
, inSObject( addInputPort( "inSObject" ) )
, handoff( addInputPort( "handoff" ) )
, outCObject( addOutputPort( "outCObject" ) )
, outSObject( addOutputPort( "outSObject" ) )
, registerClient( addOutputPort( "registerClient" ) )
{ }
Model &Gateway::initFunction()
{
inportID = 1;
sendTime = "00:00:00:100";
return *this ;
}
/*******************************************************************
* Function Name: externalFunction
********************************************************************/
Model &Gateway::externalFunction( const ExternalMessage &msg )
{
if( msg.port() == inCObject ){
oid = static_cast< int >( msg.value() ) ;
inportID = 1;
holdIn( active,sendTime) ;
}
else if (msg.port() == inSObject){
oid = static_cast< int >( msg.value() ) ;
inportID = 2;
holdIn(active,sendTime);
}
else {
oid = static_cast< int >( msg.value() ) ;
inportID = 3;
holdIn(active,sendTime) ;
}
return *this ;
}
/*******************************************************************
* Function Name: internalFunction
********************************************************************/
Model &Gateway::internalFunction( const InternalMessage & )
{
passivate();
return *this;
}
/*******************************************************************
* Function Name: outputFunction
********************************************************************/
Model &Gateway::outputFunction( const InternalMessage &msg )
{
if (inportID == 1){
sendOutput( msg.time(), outCObject, oid );
}
else if (inportID == 2){
sendOutput(msg.time(), outSObject, oid);
}
else if (inportID == 3){
sendOutput(msg.time(), registerClient, oid);
}
return *this;
}