id: network_socket_pdu
label: Socket PDU
category: '[Core]/Networking Tools'
flags: [ python, cpp ]

parameters:
-   id: type
    label: Type
    dtype: enum
    default: TCP_SERVER
    options: ["TCP_SERVER", "TCP_CLIENT", "UDP_SERVER", "UDP_CLIENT"]
    option_labels: [TCP Server, TCP Client, UDP Server, UDP Client]
-   id: host
    label: Host
    dtype: string
-   id: port
    label: Port
    dtype: string
    default: '52001'
-   id: mtu
    label: MTU
    dtype: int
    default: '10000'
-   id: tcp_no_delay
    label: TCP No Delay
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: [Enabled, Disabled]
    hide: ${ (( 'part' if (str(tcp_no_delay) == 'False') else 'none') if ((type == 'TCP_CLIENT') or (type == 'TCP_SERVER')) else 'all') }

inputs:
-   domain: message
    id: pdus
    optional: true

outputs:
-   domain: message
    id: pdus
    optional: true

templates:
    imports: from gnuradio import network
    make: network.socket_pdu(${repr(type)}, ${host}, ${port}, ${mtu}, ${tcp_no_delay})

cpp_templates:
    includes: ['#include <gnuradio/network/socket_pdu.h>']
    declarations: 'network::socket_pdu::sptr ${id};'
    make: 'this->${id} = network::socket_pdu::make("${type}", ${host}, ${port}, ${mtu}, ${tcp_no_delay});'

documentation: |-
    For server modes, leave Host blank to bind to all interfaces (equivalent to 0.0.0.0).

file_format: 1
