void
_vcd_tree_node_destroy (VcdTreeNode *node, bool free_data)
{
  VcdTreeNode *child, *nxt_child;
  
  vcd_assert (node != NULL);

  child = _vcd_tree_node_first_child (node);
  while(child) {
    nxt_child = _vcd_tree_node_next_sibling (child);
    _vcd_tree_node_destroy (child, free_data);
    child = nxt_child;
  }

  if (node->children)
    {
      vcd_assert (_vcd_list_length (node->children) == 0);
      _vcd_list_free (node->children, true);
      node->children = NULL;
    }

  if (free_data)
    free (_vcd_tree_node_set_data (node, NULL));

  if (node->parent)
    _vcd_list_node_free (node->listnode, true);
  else
    _vcd_tree_node_set_data (node, NULL);
}
Exemple #2
0
static void
_vcd_salloc_set_size (VcdSalloc *bitmap, uint32_t newlen)
{
  uint32_t new_alloced_chunks;

  vcd_assert (bitmap != NULL);
  vcd_assert (newlen >= bitmap->len);

  new_alloced_chunks = newlen / VCD_SALLOC_CHUNK_SIZE;
  if (newlen % VCD_SALLOC_CHUNK_SIZE)
    new_alloced_chunks++;

  if (bitmap->alloced_chunks < new_alloced_chunks)
    {
      bitmap->data =
        realloc (bitmap->data, new_alloced_chunks * VCD_SALLOC_CHUNK_SIZE);
      memset (bitmap->data + (VCD_SALLOC_CHUNK_SIZE * bitmap->alloced_chunks),
              0,
              VCD_SALLOC_CHUNK_SIZE * (new_alloced_chunks -
                                       bitmap->alloced_chunks));
      bitmap->alloced_chunks = new_alloced_chunks;
    }

  bitmap->len = newlen;
}
void _vcd_list_sort (VcdList *list, _vcd_list_cmp_func cmp_func)
{
  /* fixme -- this is bubble sort -- worst sorting algo... */

  vcd_assert (list != NULL);
  vcd_assert (cmp_func != 0);
  
  while (_bubble_sort_iteration (list, cmp_func));
}
void 
_vcd_list_foreach (VcdList *list, _vcd_list_iterfunc func, void *user_data)
{
  VcdListNode *node;

  vcd_assert (list != NULL);
  vcd_assert (func != 0);
  
  for (node = _vcd_list_begin (list);
       node != NULL;
       node = _vcd_list_node_next (node))
    func (_vcd_list_node_data (node), user_data);
}
void 
_vcd_list_node_free (VcdListNode *node, int free_data)
{
  VcdList *list;
  VcdListNode *prev_node;

  vcd_assert (node != NULL);
  
  list = node->list;

  vcd_assert (_vcd_list_length (list) > 0);

  if (free_data)
    free (_vcd_list_node_data (node));

  if (_vcd_list_length (list) == 1)
    {
      vcd_assert (list->begin == list->end);

      list->end = list->begin = NULL;
      list->length = 0;
      free (node);
      return;
    }

  vcd_assert (list->begin != list->end);

  if (list->begin == node)
    {
      list->begin = node->next;
      free (node);
      list->length--;
      return;
    }

  for (prev_node = list->begin; prev_node->next; prev_node = prev_node->next)
    if (prev_node->next == node)
      break;

  vcd_assert (prev_node->next != NULL);

  if (list->end == node)
    list->end = prev_node;

  prev_node->next = node->next;

  list->length--;

  free (node);
}
VcdTreeNode *
_vcd_tree_node_next_sibling (VcdTreeNode *node)
{
  vcd_assert (node != NULL);

  return _vcd_list_node_data (_vcd_list_node_next (node->listnode));
}
VcdListNode *
_vcd_list_end (VcdList *list)
{
  vcd_assert (list != NULL);

  return list->end;
}
VcdListNode *
_vcd_list_begin (const VcdList *list)
{
  vcd_assert (list != NULL);

  return list->begin;
}
VcdListNode *
_vcd_list_find (VcdList *list, _vcd_list_iterfunc cmp_func, void *user_data)
{
  VcdListNode *node;

  vcd_assert (list != NULL);
  vcd_assert (cmp_func != 0);
  
  for (node = _vcd_list_begin (list);
       node != NULL;
       node = _vcd_list_node_next (node))
    if (cmp_func (_vcd_list_node_data (node), user_data))
      break;

  return node;
}
static int 
handler_fmt (riff_context *ctxt)
{
  uint8_t buf[1024] = { 0, };
  const uint32_t size = read_le_u32 (ctxt);
  int i;

  vcd_assert (size < sizeof (buf));
  fread (buf, 1, (size % 2) ? size + 1 : size, ctxt->fd);

  {
    char *strbuf = _vcd_malloc (1 + size * 6);
    strbuf[0] = '\0';

    for (i = 0; i < size; i++)
      {
        char _buf[7] = { 0, };
        snprintf (_buf, sizeof (_buf) - 1, "%.2x ", buf[i]);
        strcat (strbuf, _buf);
      }

    vcd_info ("CDXA fmt[%d] = 0x%s", size, strbuf);

    free (strbuf);
  }

  return 0;
}
u32 vcd_enable_clock(struct vcd_dev_ctxt *dev_ctxt, struct vcd_clnt_ctxt *cctxt)
{
	u32 rc = VCD_S_SUCCESS;
	u32 set_perf_lvl;

	if (dev_ctxt->pwr_clk_state == VCD_PWRCLK_STATE_OFF) {
		VCD_MSG_ERROR("vcd_enable_clock(): Already in state "
			"VCD_PWRCLK_STATE_OFF\n");
		vcd_assert();
		rc = VCD_ERR_FAIL;
	} else if (dev_ctxt->pwr_clk_state == VCD_PWRCLK_STATE_ON_NOTCLOCKED) {

		set_perf_lvl = dev_ctxt->reqd_perf_lvl > 0 ?
			dev_ctxt->reqd_perf_lvl : VCD_MIN_PERF_LEVEL;

		rc = vcd_set_perf_level(dev_ctxt, set_perf_lvl, cctxt);

		if (!VCD_FAILED(rc)) {
			if (res_trk_enable_clocks()) {
				dev_ctxt->pwr_clk_state =
						VCD_PWRCLK_STATE_ON_CLOCKED;
			}
		} else {
			rc = VCD_ERR_FAIL;
		}

	}

	if (!VCD_FAILED(rc))
		dev_ctxt->active_clnts++;

	return rc;
}
unsigned
_vcd_list_length (const VcdList *list)
{
  vcd_assert (list != NULL);

  return list->length;
}
u32 vcd_disable_clock(struct vcd_dev_ctxt_type *p_dev_ctxt)
{
	u32 rc = VCD_S_SUCCESS;

	if (p_dev_ctxt->e_pwr_clk_state == VCD_PWRCLK_STATE_OFF) {
		VCD_MSG_ERROR("vcd_disable_clock(): Already in state "
			"VCD_PWRCLK_STATE_OFF\n");
		vcd_assert();
		rc = VCD_ERR_FAIL;
	} else if (p_dev_ctxt->e_pwr_clk_state == VCD_PWRCLK_STATE_ON_CLOCKED ||
		p_dev_ctxt->e_pwr_clk_state == VCD_PWRCLK_STATE_ON_CLOCKGATED) {
		p_dev_ctxt->n_active_clnts--;

		if (!p_dev_ctxt->n_active_clnts) {
			if (!res_trk_disable_clocks())
				rc = VCD_ERR_FAIL;

			p_dev_ctxt->e_pwr_clk_state =
			    VCD_PWRCLK_STATE_ON_NOTCLOCKED;
			p_dev_ctxt->n_curr_perf_lvl = 0;
		}
	}

	return rc;
}
int
vcd_recorder_reserve_track (VcdRecorder *obj, unsigned int sectors)
{
  vcd_assert (obj != NULL);

  return obj->op.reserve_track (obj->user_data, sectors);
}
int
vcd_recorder_get_size (VcdRecorder * obj, int track)
{
  vcd_assert (obj != NULL);

  return obj->op.get_size (obj->user_data, track);
}
int
vcd_recorder_send_cue_sheet (VcdRecorder * obj, const VcdList * vcd_cue_list)
{
  vcd_assert (obj != NULL);

  return obj->op.send_cue_sheet (obj->user_data, vcd_cue_list);
}
int
vcd_recorder_set_speed (VcdRecorder * obj, int read_speed, int write_speed)
{
  vcd_assert (obj != NULL);

  return obj->op.set_speed (obj->user_data, read_speed, write_speed);
}
int
vcd_recorder_get_next_track (VcdRecorder * obj)
{
  vcd_assert (obj != NULL);

  return obj->op.get_next_track (obj->user_data);
}
int
vcd_recorder_set_simulate (VcdRecorder * obj, bool simulate)
{
  vcd_assert (obj != NULL);

  return obj->op.set_simulate (obj->user_data, simulate);
}
Exemple #20
0
void
_vcd_salloc_destroy (VcdSalloc *bitmap)
{
  vcd_assert (bitmap != NULL);

  free (bitmap->data);
  free (bitmap);
}
void
_vcd_tree_node_sort_children (VcdTreeNode *node, _vcd_tree_node_cmp_func cmp_func)
{
  vcd_assert (node != NULL);

  if (node->children)
    _vcd_list_sort (node->children, (_vcd_list_cmp_func) cmp_func);
}
int
vcd_recorder_write_sectors (VcdRecorder * obj, const uint8_t * buffer,
			    int lsn, unsigned int buflen, int count)
{
  vcd_assert (obj != NULL);

  return obj->op.write_sectors (obj->user_data, buffer, lsn, buflen, count);
}
Exemple #23
0
uint32_t _vcd_salloc_get_highest (const VcdSalloc *bitmap)
{
  uint8_t last;
  unsigned n;

  vcd_assert (bitmap != NULL);

  last = bitmap->data[bitmap->len - 1];

  vcd_assert (last != 0);

  n = 8;
  while (n)
    if ((1 << --n) & last)
      break;

  return (bitmap->len - 1) * 8 + n;
}
int
vcd_recorder_set_current_track (VcdRecorder * obj, int track)
{
  int ret;

  vcd_assert (obj != NULL);
  vcd_assert (track >= 1 && track <= 99);

  ret = obj->op.get_next_writable (obj->user_data, track);

  if (ret == _VCD_ERR_NWA_INV)
    return 1;

  obj->next_writable = ret;
  obj->current_track = track;

  return 0;
}
static void
_set_sector_size (VcdRecorder * obj, int sector_size)
{
  int bufsize = 128000;	/* op.get_bufsize(obj->user_data); XXX not yet implemented */
  vcd_assert (obj->next_sector == 0);	/* no sectors to be written */
  obj->sector_size = sector_size;
  obj->max_sector = bufsize / sector_size;
  if (!obj->buffer)
    obj->buffer = _vcd_malloc (bufsize);
}
VcdTreeNode *
_vcd_tree_node_first_child (VcdTreeNode *node)
{
  vcd_assert (node != NULL);

  if (!node->children)
    return NULL;

  return _vcd_list_node_data (_vcd_list_begin (node->children));
}
Exemple #27
0
void
_vcd_salloc_free (VcdSalloc *bitmap, uint32_t sec, uint32_t size)
{
  uint32_t i;

  for (i = 0; i < size; i++) 
    {
      vcd_assert (_vcd_salloc_is_set (bitmap, sec + i));
      
      _vcd_salloc_unset (bitmap, sec + i);
    }
}
void
_vcd_tree_node_traverse (VcdTreeNode *node, 
                         _vcd_tree_node_traversal_func trav_func,
                         void *user_data) /* pre-order */
{
  VcdTreeNode *child;

  vcd_assert (node != NULL);

  trav_func (node, user_data);

  _VCD_CHILD_FOREACH (child, node)
    {
      _vcd_tree_node_traverse (child, trav_func, user_data);
    }
int
vcd_recorder_set_write_type (VcdRecorder * obj, vcd_write_type_t write_type)
{
  int ret;
  vcd_assert (obj != NULL);

  ret = obj->op.set_write_type (obj->user_data, write_type);

  if (write_type == _VCD_WT_DAO)
    obj->next_writable = obj->op.get_next_writable (obj->user_data, 1);

  if (obj->next_writable == _VCD_ERR_NWA_INV)
    return 1;

  return ret;
}
void
vcd_recorder_destroy (VcdRecorder * obj)
{
  vcd_assert (obj != NULL);

  if (!obj->closed
      && (obj->op.get_next_writable (obj->user_data, obj->current_track) > 0))
    {
      vcd_info ("closing track %d", obj->current_track);
      obj->op.close_track (obj->user_data, obj->current_track);
      vcd_info ("closing session");
      obj->op.close_track (obj->user_data, 0);
    }
  obj->op.free (obj->user_data);
  if (obj->buffer)
    free (obj->buffer);
  free (obj);
}