id: blocks_file_sink
label: File Sink
flags: [ python, cpp ]

parameters:
-   id: file
    label: File
    dtype: file_save
-   id: type
    label: Input Type
    dtype: enum
    options: [complex, float, int, short, byte]
    option_attributes:
        size: [gr.sizeof_gr_complex, gr.sizeof_float, gr.sizeof_int, gr.sizeof_short,
            gr.sizeof_char]
    hide: part
-   id: vlen
    label: Vector Length
    dtype: int
    default: '1'
    hide: ${ 'part' if vlen == 1 else 'none' }
-   id: unbuffered
    label: Unbuffered
    dtype: bool
    default: 'False'
    options: ['False', 'True']
    option_labels: ['Off', 'On']
-   id: append
    label: Append file
    dtype: bool
    default: 'False'
    options: ['True', 'False']
    option_labels: [Append, Overwrite]

inputs:
-   domain: stream
    dtype: ${ type }
    vlen: ${ vlen }

asserts:
- ${ vlen > 0 }

templates:
    imports: from gnuradio import blocks
    make: |-
        blocks.file_sink(${type.size}*${vlen}, ${file}, ${append})
        self.${id}.set_unbuffered(${unbuffered})
    callbacks:
    - set_unbuffered(${unbuffered})
    - open(${file})

cpp_templates:
    includes: ['#include <gnuradio/blocks/file_sink.h>']
    declarations: 'blocks::file_sink::sptr ${id};'
    make: 'this->${id} = blocks::file_sink::make(${type.size}*${vlen}, ${file}, ${append});'
    callbacks:
    - open(${file})

file_format: 1
