aboutsummaryrefslogtreecommitdiffstats
path: root/library/TRXC_CodecPort.ttcn
blob: 09b29775bc488ec9a773ade217991f1491f8fde3 (plain)
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
module TRXC_CodecPort {

import from IPL4asp_PortType all;
import from IPL4asp_Types all;
import from TRXC_Types all;

type record TRXC_RecvFrom {
	ConnectionId	connId,
	HostName	remName,
	PortNumber	remPort,
	HostName	locName,
	PortNumber	locPort,
	TrxcMessage	msg
}

template TRXC_RecvFrom tr_TRXC_RecvFrom(template ConnectionId cid, template TrxcMessage msg) := {
	connId := cid,
	remName := ?,
	remPort := ?,
	locName := ?,
	locPort := ?,
	msg := msg
}

type record TRXC_Send {
	ConnectionId	connId,
	TrxcMessage	msg
}

private function IPL4_to_TRXC_RecvFrom(in ASP_RecvFrom pin, out TRXC_RecvFrom pout) {
	pout.connId := pin.connId;
	pout.remName := pin.remName;
	pout.remPort := pin.remPort;
	pout.locName := pin.locName;
	pout.locPort := pin.locPort;
	pout.msg := dec_TrxcMessage(oct2char(pin.msg));
} with { extension "prototype(fast)" };

private function TRXC_to_IPL4_Send(in TRXC_Send pin, out ASP_Send pout) {
	pout.connId := pin.connId;
	pout.proto := { udp := {} };
	pout.msg := char2oct(enc_TrxcMessage(pin.msg));
} with { extension "prototype(fast)" };

type port TRXC_CODEC_PT message {
	out	TRXC_Send;
	in	TRXC_RecvFrom,
		ASP_ConnId_ReadyToRelease,
		ASP_Event;
} with { extension "user IPL4asp_PT
	out(TRXC_Send -> ASP_Send: function(TRXC_to_IPL4_Send))
	in(ASP_RecvFrom -> TRXC_RecvFrom: function(IPL4_to_TRXC_RecvFrom);
	   ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
	   ASP_Event -> ASP_Event: simple)"
}

template (value) TRXC_Send ts_TRXC_Send(ConnectionId cid, template (value) TrxcMessage msg) := {
	connId := cid,
	msg := msg
}

function f_TRXC_transceive(TRXC_CODEC_PT pt, ConnectionId conn_id, TrxcMessage tx,
			   template TrxcMessage tr := ?) return TrxcMessage {
	var TRXC_RecvFrom rf;
	timer T := 3.0;
	/* build better default template */
	if (istemplatekind(tr, "?")) {
		tr := {
			rsp := {
				verb := tx.cmd.verb,
				status := ?,
				params := *
			}
		};
	}
	pt.send(ts_TRXC_Send(conn_id, tx));
	T.start;
	alt {
	[] pt.receive(tr_TRXC_RecvFrom(conn_id, tr)) -> value rf {
		return rf.msg;
		}
	[] T.timeout {
		setverdict(fail, "Timeout waiting for ", tr, " on ", pt);
		mtc.stop;
		}
	}
	return rf.msg;
}

}