module SMPP_CodecPort {

/* Simple SMPP Codec Port, translating between raw TCP octetstring payload
 * towards the IPL4asp port provider, and SMPP primitives
 * which carry the decoded SMPP data types as payload.
 *
 * (C) 2018 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */


import from IPL4asp_PortType all;
import from IPL4asp_Types all;
import from SMPP_Types all;

type record SMPP_RecvFrom {
	ConnectionId	connId,
	SMPP_PDU	msg
}

type record SMPP_Send {
	ConnectionId	connId,
	SMPP_PDU	msg
}

template (value) SMPP_Send ts_SMPP_Send(ConnectionId conn_id, template (value) SMPP_PDU msg) := {
	connId := conn_id,
	msg := msg
}

template SMPP_RecvFrom tr_SMPP_Recv(template ConnectionId conn_id, template SMPP_PDU msg) := {
	connId := conn_id,
	msg := msg
}

private function IPL4_to_SMPP_RecvFrom(in ASP_RecvFrom pin, out SMPP_RecvFrom pout) {
	var integer rc;
	pout.connId := pin.connId;
	rc := f_decode_SMPP(pin.msg, pout.msg);
} with { extension "prototype(fast)" }

private function SMPP_to_IPL4_Send(in SMPP_Send pin, out ASP_Send pout) {
	pout.connId := pin.connId;
	pout.proto := { tcp := {} };
	f_encode_SMPP(pin.msg, pout.msg);
} with { extension "prototype(fast)" }

type port SMPP_CODEC_PT message {
	out	SMPP_Send;
	in	SMPP_RecvFrom,
		ASP_ConnId_ReadyToRelease,
		ASP_Event;
} with { extension "user IPL4asp_PT
	out(SMPP_Send -> ASP_Send: function(SMPP_to_IPL4_Send))
	in(ASP_RecvFrom -> SMPP_RecvFrom: function(IPL4_to_SMPP_RecvFrom);
	   ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
	   ASP_Event -> ASP_Event: simple)"
}



}
