#ifndef   V_IOCTL_H
#define   V_IOCTL_H

/*  Codes for pctl_get_type */
#define PCTL_BLOCK_DEVICE   1   /* device can 'seek' */
#define PCTL_SUPPORT_MMAP   2   /* device can be mmap()'ed */

/*
 * Custom type of I/O channel must be stored in hiword
 */
#define PCTL_TYPE_MASK		0xFFFF0000

/*
 *  Generic IO port IOCTL's to pass to fileControl().
 *
 *  Note: mentioned below return values defined for inner ioctl()'s;
 *  when port->ioctl() returns zero, fileControl() returns 'true',
 *  otherwise fileControl() complains and returns 'false'.
 *  ----------------------------------------------------------------------
 *  pctl_get_name
 *  Returns name of local file / vfs node associated with data stream.
 *  IOCTL (internal) return code: 0 on success.
 *  Parameters: 'data' must be array of _MAX_PATH chars.
 *  ----------------------------------------------------------------------
 *  pctl_get_type
 *  Provides client with information about type of the data stream.
 *  IOCTL (internal) return code: 0 on success.
 *  Parameters: 'data' must be set to address of the 32-bit integer. Upon
 *  successful exit, type of stream stored in that variable.
 *	FIXME: custom types (pctl_type_regfile, pctl_type_commdev, 
 *		pctl_type_ipc_channel, pctl_type_thread_pipe, etc.) currently not
 *		implemented. TODO ?
 *  ----------------------------------------------------------------------
 *  pctl_duplicate_handle
 *  Duplicates file handle. New copy of handle have private file pointer.
 *  IOCTL (internal) return code: 0 on success.
 *  Parameters: 'data' must be set to address of the vhandle_t. Upon
 *  successful exit, new handle stored at given address.
 *  ----------------------------------------------------------------------
 *  pctl_map_ispace
 *  Returns base address of the stream data.
 *  IOCTL (internal) return code: 0 on success.
 *  Parameters: 'data' must be set to address of 'void*' pointer. Upon
 *	successful exit, base address of data stored in that variable.
 *
 *	Important note: there is no pctl_unmap_ispace - all mappings performed
 *	by default in fileOpenRead(), so 'pctl_map_ispace' is just a way for
 *	LibV client to obtain address of the map.
 *  ----------------------------------------------------------------------
 *	pctl_delete_on_close
 *	Marks file as temporary. Meaningful only for files created by
 *	fileOpenSafeOverwite().
 *  IOCTL (internal) return code: 0 on success.
 *  Parameters: 'data' must be set to address of 'vboolean' parameter.
 *  ----------------------------------------------------------------------
 *	pctl_pipe_head
 *  Returns base address of the first block of pipe data.
 *  IOCTL (internal) return code: 0 on success.
 *  Parameters: 'data' must be set to address of 'void*' pointer. Upon
 *	successful exit, base address of data stored in that variable.
 *	Note: see one for pctl_map_ispace.
 *  ----------------------------------------------------------------------
 *	pctl_pipe_tail
 *  Returns base address of the second block of pipe data.
 *  IOCTL (internal) return code: 0 on success.
 *  Parameters: 'data' must be set to address of 'void*' pointer. Upon
 *	successful exit, base address of data stored in that variable.
 *	Note: see one for pctl_map_ispace.
 *  ----------------------------------------------------------------------
 *	pctl_pipe_head_len
 *  Returns size of the first block of pipe data.
 *  IOCTL (internal) return code: 0 on success.
 *  Parameters: 'data' must be set to address of 'vsize_t' variable. Upon
 *	successful exit, length of data block stored in that variable.
 *  ----------------------------------------------------------------------
 *	pctl_pipe_tail_len
 *  Returns size of the second block of pipe data.
 *  IOCTL (internal) return code: 0 on success.
 *  Parameters: 'data' must be set to address of 'vsize_t' variable. Upon
 *	successful exit, length of data block stored in that variable.
 *  ----------------------------------------------------------------------
 *	pctl_flush
 *  Flushes file buffers.
 *  Retun value: always 0.
 *  ----------------------------------------------------------------------
 *  pctl_comm_reset (COM ports only)
 *  Cancels any pending IO request. Returns 0 on success.
 *  Parameters: not used.
 *	TODO: replace by generic pctl_flush_input | pctl_flush_output
 *  ----------------------------------------------------------------------
 *  pctl_wave_get_num_channels (WAV file I/O channels only)
 *  Returns number of audio channels.
 *  Parameters: 'data' must be pointer to 32-bit unsigned.
 *  ----------------------------------------------------------------------
 *  pctl_wave_get_sampling_frequency (WAV file I/O channels only)
 *  Returns sampling frequency.
 *  Parameters: 'data' must be pointer to 32-bit unsigned.
 *  ----------------------------------------------------------------------
 *  pctl_wave_get_bits_per_sample (WAV file I/O channels only)
 *  Returns number of bits per sample.
 *  Parameters: 'data' must be pointer to 32-bit unsigned.
 *  ----------------------------------------------------------------------
 *  pctl_wave_get_num_samples (WAV file I/O channels only)
 *  Returns number of samples in file.
 *  Parameters: 'data' must be pointer to 32-bit unsigned.
 *  ----------------------------------------------------------------------
 *  pctl_wave_loop (WAV file I/O channels only)
 *  Sets normal / circular input mode.
 *  Parameters: NULL for normal mode, any other - for loop mode.
 *  ----------------------------------------------------------------------
 *  pctl_waveout_wait (wave output I/O channels only)
 *  Suspends caller thread if there are any pending data to write.
 *  Returns: -1: wait failed, 0 - no pending data.
 *  Parameters: 'data' can be pointer to 32-bit unsigned number of
 *  maximum timeout.
 *  ----------------------------------------------------------------------
 *  pctl_waveout_pause (wave output I/O channels only)
 *  Suspends wave playback.
 *  Retuns: 0 on success.
 *  Parameters: none.
 *  ----------------------------------------------------------------------
 *  pctl_waveout_resume (wave output I/O channels only)
 *  Resumes wave playback.
 *  Retuns: 0 on success.
 *  Parameters: none.
 *  ----------------------------------------------------------------------
 *  pctl_waveout_reset (wave output I/O channels only)
 *  Purges all panding data and stops wave playback.
 *  Retuns: 0 on success.
 *  Parameters: none.
 *  ----------------------------------------------------------------------
 *  pctl_waveout_get_pending_samples
 *  Returns write queue length, in samples.
 *  Parameters: 'data' must be pointer to 32-bit unsigned integer.
 *  Retun value: 0 on success.
 */

typedef enum
{
  /* IOCTL codes for generic files returned by fileOpenXXX() */
  pctl_get_name,			/* name of stream */
  pctl_get_type,			/* type of stream */
  pctl_duplicate_handle,	/* call to create another handle for stream */
  pctl_map_ispace,			/* get base for RO data */
  pctl_delete_on_close,		/* set file as temporary */
  pctl_get_size,			/* returns size of file, arg must be u32_p */
  pctl_pipe_head,
  pctl_pipe_head_len,
  pctl_pipe_tail,
  pctl_pipe_tail_len,
  pctl_is_eof,				/* returns 0/1, arg must be u32_p */
  pctl_flush,				/* flush file buffers */
  /* IOCTL for COM port handle, returned by commOpen() */
  pctl_comm_reset,			/* reset port */
  /* IOCTL codes for "WAV file" and - TODO !!! - "Wave capture" */
  pctl_wave_get_num_channels,
  pctl_wave_get_sampling_frequency,
  pctl_wave_get_bits_per_sample,
  pctl_wave_get_num_samples,
  pctl_wave_loop,
  /* wave out channels */
  pctl_waveout_wait,
  pctl_waveout_pause,
  pctl_waveout_resume,
  pctl_waveout_reset,
  pctl_waveout_get_pending_samples,
  /* video input */
  pctl_video_get_width,
  pctl_video_get_height,
  pctl_video_get_fps,
  pctl_video_num_frames,
  /* IOCTL limit - used for error detection */
  pctl_max_code
} pctl_contol_codes;

#endif  /* V_IOCTL_H */
