#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_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 = 0,        /* name of stream */
  pctl_get_type = 1,        /* type of stream */
  pctl_duplicate_handle = 2,/* call to create another handle for stream */
  pctl_map_ispace = 3,      /* mmap() input space */
  pctl_get_size = 4,		/* returns size of file, arg must be u32_p */
  pctl_is_eof = 5,			/* returns 0/1, arg must be u32_p */
  pctl_flush = 6,			/* flush file buffers */
  /* IOCTL for COM port handle, returned by commOpen() */
  pctl_comm_reset = 7,      /* reset port */
  /* IOCTL codes for "WAV file" and - TODO !!! - "Wave capture" */
  pctl_wave_get_num_channels = 8,
  pctl_wave_get_sampling_frequency = 9,
  pctl_wave_get_bits_per_sample = 10,
  pctl_wave_get_num_samples = 11,
  pctl_wave_loop = 12,
  /* wave out channels */
  pctl_waveout_wait = 13,
  pctl_waveout_pause = 14,
  pctl_waveout_resume = 15,
  pctl_waveout_reset = 16,
  pctl_waveout_get_pending_samples = 17,
  /* video input */
  pctl_video_get_width = 17,
  pctl_video_get_height = 18,
  pctl_video_get_fps = 19,
  pctl_video_num_frames = 20,
  /* IOCTL limit - used for error detection */
  pctl_max_code
} pctl_contol_codes;

#endif  /* V_IOCTL_H */
