void BindInput()
{
	Sqrat::Class<CInput, Sqrat::NoConstructor> def;

	def.Func("KeyUp", &CInput::KeyUp);
	def.Func("KeyPressed", &CInput::KeyPressed);
	def.Func("KeyHeld", &CInput::KeyHeld);
	def.Func("KeyReleased", &CInput::KeyReleased);
		
	Sqrat::RootTable().Bind("InputSystem", def);
	
	//Sqrat::ConstTable().Const("KEY_LEFT", KEY_LEFT);
	MAKE_KEY( KEY_LEFT );
	MAKE_KEY( KEY_RIGHT );
	MAKE_KEY( KEY_UP );
	MAKE_KEY( KEY_DOWN );
	MAKE_KEY( KEY_Q );
	MAKE_KEY( KEY_W );
	MAKE_KEY( KEY_PAGEUP );
	MAKE_KEY( KEY_PAGEDOWN );
	MAKE_KEY( KEY_HOME );

	// Push the singleton to squirrel
	sq_pushroottable( Sqrat::DefaultVM::Get() );
	sq_pushstring( Sqrat::DefaultVM::Get(), "InputSystem", -1 );
	sq_get(  Sqrat::DefaultVM::Get(), -2 );
	sq_pushstring(  Sqrat::DefaultVM::Get(), "Input", -1 );
	sq_createinstance(  Sqrat::DefaultVM::Get(), -2 );
	sq_setinstanceup(  Sqrat::DefaultVM::Get(), -1, (SQUserPointer)Input() );
	sq_newslot(  Sqrat::DefaultVM::Get(), -4, SQFalse );
	sq_pop(  Sqrat::DefaultVM::Get(), 2 );
}
iconv_t
iconv_helper_get(iconv_helper *in_helper,
                 const char *in_to_coding, const char *in_from_coding)
{
    int i;
    MAKE_KEY(key, in_to_coding, in_from_coding);
    iconv_t_list it_list =
        (iconv_t_list)g_hash_table_lookup(in_helper->convs, key);

    /* Make sure list exists */
    if (it_list == NULL)
    {
        it_list = create_iconv_t_list();
        g_hash_table_insert (in_helper->convs, COPY_KEY(key), it_list);
    }
    else
    {
        RELEASE_KEY(key);
    }

    /* Search for available */
    for (i = 0; i < it_list->len; i++)
    {
        struct iconv_t_wrapper* w =
            (struct iconv_t_wrapper*)g_ptr_array_index(it_list, i);

        if (!w->used)
        {
            w->used = TRUE;
            /* rra_debug("Returning iconv_t: %p", w->it); */
            return w->it;
        }
    }

    /* no unused available */
    struct iconv_t_wrapper* itw = g_new(struct iconv_t_wrapper, 1);
    itw->used = TRUE;
    itw->it = iconv_open(in_to_coding, in_from_coding);

    if (itw->it == (iconv_t)-1)
    {
        rra_warning(N_("Got invalid iconv_t from iconv_open"));
        return (iconv_t)-1;
    }

    g_ptr_array_add(it_list, itw);

    /* rra_debug("Returning iconv_t: %p", itw->it); */

    return itw->it;
}
void FileListModel::addFile(const AudioFileModel &file)
{
	const QString key = MAKE_KEY(file.filePath()); 
	const bool flag = (!m_blockUpdates);

	if(!m_fileStore.contains(key))
	{
		if(flag) beginInsertRows(QModelIndex(), m_fileList.count(), m_fileList.count());
		m_fileStore.insert(key, file);
		m_fileList.append(key);
		if(flag) endInsertRows();
		emit rowAppended();
	}
}
void FileListModel::addFile(const QString &filePath)
{
	QFileInfo fileInfo(filePath);
	const QString key = MAKE_KEY(fileInfo.canonicalFilePath()); 
	const bool flag = (!m_blockUpdates);

	if(!m_fileStore.contains(key))
	{
		AudioFileModel audioFile(fileInfo.canonicalFilePath());
		audioFile.metaInfo().setTitle(fileInfo.baseName());
		if(flag) beginInsertRows(QModelIndex(), m_fileList.count(), m_fileList.count());
		m_fileStore.insert(key, audioFile);
		m_fileList.append(key);
		if(flag) endInsertRows();
		emit rowAppended();
	}
}
Beispiel #5
0
/* Adds the stream <strm> to the pending connection queue of server <strm>->srv
 * or to the one of <strm>->proxy if srv is NULL. All counters and back pointers
 * are updated accordingly. Returns NULL if no memory is available, otherwise the
 * pendconn itself. If the stream was already marked as served, its flag is
 * cleared. It is illegal to call this function with a non-NULL strm->srv_conn.
 * The stream's queue position is counted with an offset of -1 because we want
 * to make sure that being at the first position in the queue reports 1.
 *
 * The queue is sorted by the composition of the priority_class, and the current
 * timestamp offset by strm->priority_offset. The timestamp is in milliseconds
 * and truncated to 20 bits, so will wrap every 17m28s575ms.
 * The offset can be positive or negative, and an offset of 0 puts it in the
 * middle of this range (~ 8 min). Note that this also means if the adjusted
 * timestamp wraps around, the request will be misinterpreted as being of
 * the highest priority for that priority class.
 *
 * This function must be called by the stream itself, so in the context of
 * process_stream.
 */
struct pendconn *pendconn_add(struct stream *strm)
{
	struct pendconn *p;
	struct proxy    *px;
	struct server   *srv;

	p = pool_alloc(pool_head_pendconn);
	if (!p)
		return NULL;

	if (strm->flags & SF_ASSIGNED)
		srv = objt_server(strm->target);
	else
		srv = NULL;

	px            = strm->be;
	p->target     = NULL;
	p->srv        = srv;
	p->node.key   = MAKE_KEY(strm->priority_class, strm->priority_offset);
	p->px         = px;
	p->strm       = strm;
	p->strm_flags = strm->flags;

	pendconn_queue_lock(p);

	if (srv) {
		srv->nbpend++;
		if (srv->nbpend > srv->counters.nbpend_max)
			srv->counters.nbpend_max = srv->nbpend;
		p->queue_idx = srv->queue_idx - 1; // for increment
		eb32_insert(&srv->pendconns, &p->node);
	}
	else {
		px->nbpend++;
		if (px->nbpend > px->be_counters.nbpend_max)
			px->be_counters.nbpend_max = px->nbpend;
		p->queue_idx = px->queue_idx - 1; // for increment
		eb32_insert(&px->pendconns, &p->node);
	}
	strm->pend_pos = p;

	pendconn_queue_unlock(p);

	_HA_ATOMIC_ADD(&px->totpend, 1);
	return p;
}
gboolean
iconv_helper_release (iconv_helper *in_helper, iconv_t in_it,
                      const char *in_to_coding, const char *in_from_coding)
{
    int i;

    /* rra_debug("Releasing: %p", in_it); */

    /* Reset converter */
    iconv(in_it, NULL, NULL, NULL, NULL);

    MAKE_KEY(key, in_to_coding, in_from_coding);
    iconv_t_list it_list =
        (iconv_t_list)g_hash_table_lookup(in_helper->convs, key);
    RELEASE_KEY(key);

    if (it_list == NULL)
    {
        rra_warning(N_("This shouldn't happen"));
    }

    for (i = 0; i < it_list->len; i++)
    {
        struct iconv_t_wrapper* w =
            (struct iconv_t_wrapper*)g_ptr_array_index(it_list, i);

        if (w->it == in_it)
        {
            if (!w->used)
            {
                rra_warning(N_("Double release of iconv_t: %p"), w->it);
            }
            else
            {
                w->used = FALSE;
                return TRUE;
            }
        }
    }

    rra_warning(N_("Didn't find iconv_t to release"));
    return FALSE;
}
bool FileListModel::setFile(const QModelIndex &index, const AudioFileModel &audioFile)
{
	if(index.row() >= 0 && index.row() < m_fileList.count())
	{
		const QString oldKey = m_fileList.at(index.row());
		const QString newKey = MAKE_KEY(audioFile.filePath());
		
		beginResetModel();
		m_fileList.replace(index.row(), newKey);
		m_fileStore.remove(oldKey);
		m_fileStore.insert(newKey, audioFile);
		endResetModel();
		return true;
	}
	else
	{
		return false;
	}
}
/**
  * This function provides NAS-QoS Map CPS API read function
  * @Param    Standard CPS API params
  * @Return   Standard Error Code
  */
cps_api_return_code_t nas_qos_cps_api_map_read_type (void * context,
                                            cps_api_get_params_t * param,
                                            size_t ix,
                                            nas_qos_map_type_t map_type)
{
    cps_api_object_t obj = cps_api_object_list_get(param->filters, ix);

    nas_attr_id_t obj_id;

    uint_t switch_id = 0;

    obj_id = qos_map_map_id_obj_id(map_type);
    cps_api_object_attr_t map_attr = cps_api_get_key_data(obj, obj_id);
    nas_obj_id_t map_id = (map_attr? cps_api_object_attr_data_u64(map_attr): 0);

    // check the request is on Map level or Entry level
    bool is_map_entry;
    cps_api_return_code_t rc = cps_api_ret_code_OK;
    if ((rc = qos_map_key_check(obj, map_type, &is_map_entry)) != cps_api_ret_code_OK) {
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "Key error");
        return rc;
    }

    obj_id = qos_map_entry_key_1_obj_id(map_type);
    cps_api_object_attr_t entry_attr = cps_api_get_key_data(obj, obj_id);
    if (entry_attr == NULL && is_map_entry) {
        // Inner list does not support wildcard get.
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "Key value must be specified for inner list\n");
        return NAS_QOS_E_MISSING_KEY;
    }

    nas_qos_map_entry_key_t search_key;
    if (entry_attr) {
        search_key.any = *(uint8_t *)cps_api_object_attr_data_bin(entry_attr);
    }

    if (map_type == NDI_QOS_MAP_TC_TO_QUEUE ||
        map_type == NDI_QOS_MAP_TC_COLOR_TO_DOT1P ||
        map_type == NDI_QOS_MAP_TC_COLOR_TO_DSCP ||
        map_type == NDI_QOS_MAP_PG_TO_PFC ||
        map_type == NDI_QOS_MAP_PFC_TO_QUEUE) {
        obj_id = qos_map_entry_key_2_obj_id(map_type);
        cps_api_object_attr_t entry_key2_attr = cps_api_get_key_data(obj, obj_id);
        if (entry_key2_attr == NULL && is_map_entry) {
            // Inner list does not support wildcard get.
            EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS",
                        "Secondary Key value missing for inner list\n");
            return NAS_QOS_E_MISSING_KEY;
        }

        if (entry_key2_attr) {
            uint32_t key2;

            if (map_type == NDI_QOS_MAP_PG_TO_PFC)
                key2 = *(uint8_t *)cps_api_object_attr_data_bin(entry_key2_attr);
            else
                key2 = cps_api_object_attr_data_u32(entry_key2_attr);

            // form a complex key
            uint_t comp_key = MAKE_KEY(search_key.any, key2);

            if (map_type == NDI_QOS_MAP_TC_TO_QUEUE)
                search_key.tc_queue_type = comp_key;
            else if (map_type == NDI_QOS_MAP_TC_COLOR_TO_DOT1P ||
                     map_type == NDI_QOS_MAP_TC_COLOR_TO_DSCP)
                search_key.tc_color = comp_key;
            else if (map_type == NDI_QOS_MAP_PG_TO_PFC)
                search_key.pg_prio = comp_key;
            else if (map_type == NDI_QOS_MAP_PFC_TO_QUEUE)
                search_key.prio_queue_type = comp_key;
        }
    }

    EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "Read switch id %u, map id %u\n",
                    switch_id, map_id);

    nas_qos_switch * p_switch = nas_qos_get_switch(switch_id);
    if (p_switch == NULL)
        return NAS_QOS_E_FAIL;

    nas_qos_map * map;
    if (map_id) {
        map = p_switch->get_map(map_id);
        if (map == NULL)
            return NAS_QOS_E_FAIL;

        rc = _append_one_map(param, switch_id, map, map_type, search_key, is_map_entry);
    }
    else {
        // map id is not specified
        for (map_iter_t it = p_switch->get_map_it_begin();
                it != p_switch->get_map_it_end();
                it++) {

            map = &it->second;
            rc = _append_one_map(param, switch_id, map, map_type, search_key, false);
            if (rc != cps_api_ret_code_OK)
                return rc;
        }
    }

    return rc;
}