-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtupleserver.cpp
More file actions
92 lines (81 loc) · 2.58 KB
/
tupleserver.cpp
File metadata and controls
92 lines (81 loc) · 2.58 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
/*******************************************************************
*
* DESCRIPTION: class TupleServer
*
* AUTHOR: Umar Farooq
*
* EMAIL: ufarooq@sce.carleton.ca
*
* DATE: 17/10/2003
*
*******************************************************************/
/** include files **/
#include <math.h>
#include "tupleserver.h" // base header
#include "message.h" // InternalMessage ....
#include "mainsimu.h" // class MainSimulator
/*******************************************************************
* Function Name: TupleQueue
* Description: constructor
********************************************************************/
Tupleserver::Tupleserver( const string &name )
: Atomic( name )
, inSObject( addInputPort( "inSObject" ) )
, registerClient( addInputPort( "registerClient" ) )
, outSObject1( addOutputPort( "outSObject1" ) )
, outSObject2( addOutputPort( "outSObject2" ) )
, cRegistered( addOutputPort( "cRegistered" ) )
{ }
/*******************************************************************
* Function Name: initFunction
********************************************************************/
Model &Tupleserver::initFunction()
{
gatewayID = 1;
inportID = 1;
transferTime = "00:00:00:100";
return *this ;
}
/*******************************************************************
* Function Name: externalFunction
********************************************************************/
Model &Tupleserver::externalFunction( const ExternalMessage &msg )
{
if( msg.port() == inSObject ){
oid = static_cast< int >( msg.value() ) ;
inportID = 1;
holdIn( active,transferTime) ;
}
else if (msg.port() == registerClient){
gatewayID = static_cast< int >( msg.value() ) ;
inportID = 2;
holdIn(active,Time::Zero);
}
return *this ;
}
/*******************************************************************
* Function Name: internalFunction
********************************************************************/
Model &Tupleserver::internalFunction( const InternalMessage & )
{
passivate();
return *this;
}
/*******************************************************************
* Function Name: outputFunction
********************************************************************/
Model &Tupleserver::outputFunction( const InternalMessage &msg )
{
if (inportID == 1){
if(gatewayID == 1){
sendOutput( msg.time(), outSObject1, oid );
}
else{
sendOutput( msg.time(), outSObject2, oid );
}
}
else if (inportID == 2){
sendOutput(msg.time(), cRegistered, gatewayID);
}
return *this;
}