Beispiel #1
0
int ListView_GetColumnCount(HWND listView) {
	if (!ProbeColumn(listView, 0)) return 0;
	int hi = 1;
	for (;;) {
		if (!ProbeColumn(listView, hi)) break;
		hi <<= 1;
		if (hi <= 0) {
			PFC_ASSERT(!"Shouldn't get here!");
			return -1;
		}
	}
	int lo = hi >> 1;
	//lo is the highest known valid column, hi is the lowest known invalid, let's bsearch thru
	while(lo + 1 < hi) {
		PFC_ASSERT( lo < hi );
		const int mid = lo + (hi - lo) / 2;
		PFC_ASSERT( lo < mid && mid < hi );
		if (ProbeColumn(listView, mid)) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	return hi;
}
Beispiel #2
0
bool dsp_entry_v2::show_config_popup(dsp_preset & p_data,HWND p_parent) {
	PFC_ASSERT(p_data.get_owner() == get_guid());
	dsp_preset_impl temp(p_data);
	show_config_popup_v2(p_data,p_parent,dsp_preset_edit_callback_impl(temp));
	PFC_ASSERT(temp.get_owner() == get_guid());
	if (temp == p_data) return false;
	p_data = temp;
	return true;
}
Beispiel #3
0
	bool bit_array_flatIndexList::_findNearestDown( size_t val, size_t & outIdx ) const {
		size_t idx;
		if (_find( val, idx )) { outIdx = idx; return true; }
		// we have a valid outIdx at where the bsearch gave up
		PFC_ASSERT ( idx == 0 || m_content [ idx - 1 ] < val );
		PFC_ASSERT ( idx == m_content.get_size() || m_content[ idx ] > val );
		if (idx == 0) return false;
		outIdx = idx - 1;
		return true;
	}
	t_size CTableEditHelperV2::ColumnToPosition(t_size col) const {
		PFC_ASSERT( TableEdit_IsColumnEditable(col) );
		pfc::array_t<t_size> colOrder; GrabColumnOrder(colOrder);
		t_size skipped = 0;
		for(t_size walk = 0; walk < colOrder.get_size(); ++walk) {
			const t_size curCol = colOrder[walk];
			if (TableEdit_IsColumnEditable(curCol)) {
				if (curCol == col) return skipped;
				++skipped;
			}
		}
		PFC_ASSERT( !"Should not get here." );
		return ~0;
	}
Beispiel #5
0
 void create_move_item_permutation( size_t * order, size_t count, size_t from, size_t to ) {
     PFC_ASSERT( from < count );
     PFC_ASSERT( to < count );
     for ( size_t w = 0; w < count; ++w ) {
         size_t i = w;
         if ( w == to ) i = from;
         else if ( w < to && w >= from ) {
             ++i;
         } else if ( w > to && w <= from ) {
             --i;
         }
         order[w] = i;
     }
 }
void file_info::info_set_float(const char * name,double value,unsigned precision,bool force_sign,const char * unit)
{
    PFC_ASSERT(pfc::is_valid_utf8(name));
    PFC_ASSERT(unit==0 || strlen(unit) <= 64);
    char temp[128];
    pfc::float_to_string(temp,64,value,precision,force_sign);
    temp[63] = 0;
    if (unit)
    {
        strcat_s(temp," ");
        strcat_s(temp,unit);
    }
    info_set(name,temp);
}
Beispiel #7
0
/*
 * static inline pfc_rbtree_t PFC_FATTR_ALWAYS_INLINE *
 * dmconf_order_gettree(lnc_ordtype_t type, int index)
 *	Determine the Red-Black tree which keeps daemon order.
 *
 *	The target tree is determined by the order type `type' and
 *	type index `index'. `index' is always ignored if `type' is
 *	either LNC_ORDTYPE_START or LNC_ORDTYPE_STOP.
 */
static inline pfc_rbtree_t PFC_FATTR_ALWAYS_INLINE *
dmconf_order_gettree(lnc_ordtype_t type, int index)
{
	uint32_t	idx = (uint32_t)type;

	if (LNC_ORDTYPE_HASINDEX(type)) {
		PFC_ASSERT(index >= 0);
		idx += index;
	}

	PFC_ASSERT(idx < PFC_ARRAY_CAPACITY(dmconf_order_tree));

	return &dmconf_order_tree[idx];
}
Beispiel #8
0
/*
 * int
 * uncd_stop(void)
 *	Stop the UNC daemon.
 *
 * Calling/Exit State:
 *	Upon successful completion, zero is returned.
 *	Otherwise error number which indicates the cause of error is returned.
 */
int
uncd_stop(void)
{
	pfc_extcmd_t	ecmd;
	int		err, status;

	err = pfc_extcmd_create(&ecmd, UNC_CONTROL_PATH, UNC_CONTROL);
	if (PFC_EXPECT_FALSE(err != 0)) {
		error("Failed to create command context for %s: %s",
		      UNC_CONTROL, strerror(err));

		return err;
	}

	err = pfc_extcmd_add_arguments(ecmd, "stop", "-q", NULL);
	if (PFC_EXPECT_FALSE(err != 0)) {
		error("Failed to append arguments for %s: %s",
		      UNC_CONTROL, strerror(err));
		goto out;
	}

	err = pfc_extcmd_execute(ecmd);
	if (PFC_EXPECT_FALSE(err != 0)) {
		error("Failed to execute %s: %s", UNC_CONTROL, strerror(err));
		goto out;
	}

	status = pfc_extcmd_get_status(ecmd);
	if (PFC_EXPECT_FALSE(status != 0)) {
		if (status == PFC_EXTCMD_ERR_UNSPEC) {
			int	sig = pfc_extcmd_get_signal(ecmd);

			PFC_ASSERT(sig > 0);
			error("%s was killed by signal %d.", UNC_CONTROL, sig);
		}
		else {
			PFC_ASSERT(status > 0);
			error("%s exited with status %d.", UNC_CONTROL,
			      status);
			err = EIO;
		}
	}

out:
	PFC_ASSERT_INT(pfc_extcmd_destroy(ecmd), 0);

	return err;
}
static void g_write_tags_ex(tag_write_callback & p_callback,unsigned p_flags,const service_ptr_t<file> & p_file,const file_info * p_info,abort_callback & p_abort) {
    PFC_ASSERT( p_flags == 0 || p_info != 0 );


    if (p_flags & (g_flag_id3v1 | g_flag_apev2)) {
        switch(p_flags & (g_flag_id3v1 | g_flag_apev2)) {
        case g_flag_id3v1 | g_flag_apev2:
            static_api_ptr_t<tag_processor_trailing>()->write_apev2_id3v1(p_file,*p_info,p_abort);
            break;
        case g_flag_id3v1:
            static_api_ptr_t<tag_processor_trailing>()->write_id3v1(p_file,*p_info,p_abort);
            break;
        case g_flag_apev2:
            static_api_ptr_t<tag_processor_trailing>()->write_apev2(p_file,*p_info,p_abort);
            break;
        default:
            throw exception_io_data();
        }
    } else {
        static_api_ptr_t<tag_processor_trailing>()->remove(p_file,p_abort);
    }

    if (p_flags & g_flag_id3v2)
    {
        static_api_ptr_t<tag_processor_id3v2>()->write_ex(p_callback,p_file,*p_info,p_abort);
    }
    else
    {
        t_uint64 dummy;
        tag_processor_id3v2::g_remove_ex(p_callback,p_file,dummy,p_abort);
    }
}
t_int64 file_info::info_get_int(const char * name) const
{
    PFC_ASSERT(pfc::is_valid_utf8(name));
    const char * val = info_get(name);
    if (val==0) return 0;
    return _atoi64(val);
}
Beispiel #11
0
/*
 * static int
 * cred_loadconf(void)
 *	Load the system configuration file for the given daemon process.
 *
 * Calling/Exit State:
 *	Upon successful completion, zero is returned.
 *	Otherwise error number which indicates the cause of error is returned.
 */
static int
cred_loadconf(void)
{
	pfc_refptr_t	*rpath;
	char		*path;
	int		err;

	/* Ensure that the configuration file is safe. */
	path = strdup(PFC_PFCD_CONF_PATH);
	if (PFC_EXPECT_FALSE(path == NULL)) {
		return ENOMEM;
	}

	err = pfc_is_safepath(path);
	free(path);
	if (PFC_EXPECT_FALSE(err != 0)) {
		return err;
	}

	rpath = pfc_refptr_string_create(PFC_PFCD_CONF_PATH);
	if (PFC_EXPECT_FALSE(rpath == NULL)) {
		return ENOMEM;
	}

	err = pfc_sysconf_init(rpath);
	pfc_refptr_put(rpath);
	PFC_ASSERT(err != 0 || pfc_sysconf_open() != PFC_CONF_INVALID);

	return err;
}
Beispiel #12
0
	t_size MultiWaitAbortable_MsgLoop(const HANDLE * ev, t_size evCount, abort_callback & abort) {
		pfc::array_t<HANDLE> handles; handles.set_size(evCount + 1);
		handles[0] = abort.get_abort_event();
		pfc::memcpy_t(handles.get_ptr() + 1, ev, evCount);
		for(;;) {
			SetLastError(0);
			const DWORD status = MsgWaitForMultipleObjects(handles.get_count(), handles.get_ptr(), FALSE, INFINITE, QS_ALLINPUT);
			switch(status) {
				case WAIT_TIMEOUT:
					PFC_ASSERT(!"How did we get here?");
					uBugCheck();
				case WAIT_OBJECT_0:
					throw exception_aborted();
				case WAIT_FAILED:
					WIN32_OP_FAIL();
				default:
					{
						t_size index = (t_size)(status - (WAIT_OBJECT_0 + 1));
						if (index == evCount) {
							ProcessPendingMessages();
						} else if (index < evCount) {
							return index;
						} else {
							uBugCheck();
						}
					}
			}
		}
	}
Beispiel #13
0
/*
 * static int
 * proc_buf_append(proc_buf_t *pbufp, char c)
 *	Append the specified character to the proc_buf_t.
 *
 * Calling/Exit State:
 *	Upon successful completion, zero is returned.
 *	ENOMEM is returned if no memory is available.
 */
static int
proc_buf_append(proc_buf_t *pbufp, char c)
{
	size_t	cursor = pbufp->pb_cursor;

	PFC_ASSERT(cursor <= pbufp->pb_size);

	if (cursor == pbufp->pb_size) {
		char	*newbuf;
		size_t	newsize = pbufp->pb_size + PROC_BUF_BLKSIZE;

		/* Buffer must be expanded. */
		newbuf = (char *)realloc(pbufp->pb_buffer, newsize);
		if (PFC_EXPECT_FALSE(newbuf == NULL)) {
			return ENOMEM;
		}

		pbufp->pb_size = newsize;
		pbufp->pb_buffer = newbuf;
	}

	if (c == '(') {
		if (pbufp->pb_firstlparen == (size_t)-1) {
			pbufp->pb_firstlparen = cursor;
		}
	}
	else if (c == ')') {
		pbufp->pb_lastrparen = cursor;
	}

	*(pbufp->pb_buffer + cursor) = c;
	pbufp->pb_cursor = cursor + 1;

	return 0;
}
Beispiel #14
0
metadb_handle_ptr playlist_manager::playlist_get_item_handle(t_size playlist, t_size item) {
	metadb_handle_ptr temp;
	if (!playlist_get_item_handle(temp, playlist, item)) throw pfc::exception_invalid_params();
	PFC_ASSERT( temp.is_valid() );
	return temp;

}
void metadb_handle_list_helper::sort_by_format_get_order(metadb_handle_list_cref p_list,t_size* order,const service_ptr_t<titleformat_object> & p_script,titleformat_hook * p_hook,int p_direction)
{
//	pfc::hires_timer timer; timer.start();

	const t_size count = p_list.get_count();
	pfc::array_t<custom_sort_data> data; data.set_size(count);
	
	{
		pfc::counter counter(0);
		pfc::array_t<pfc::rcptr_t<tfthread> > threads; threads.set_size(pfc::getOptimalWorkerThreadCountEx(p_list.get_count() / 128));
		PFC_ASSERT( threads.get_size() > 0 );
		for(t_size walk = 0; walk < threads.get_size(); ++walk) {
			threads[walk].new_t(&counter,p_list,data.get_ptr(),p_script,p_hook);
		}
		for(t_size walk = 1; walk < threads.get_size(); ++walk) threads[walk]->start();
		threads[0]->threadProc();
		for(t_size walk = 1; walk < threads.get_size(); ++walk) threads[walk]->waitTillDone();
	}
//	console::formatter() << "metadb_handle sort: prepared in " << pfc::format_time_ex(timer.query(),6);

	pfc::sort_t(data, p_direction > 0 ? custom_sort_compare<1> : custom_sort_compare<-1>,count);
	//qsort(data.get_ptr(),count,sizeof(custom_sort_data),p_direction > 0 ? _custom_sort_compare<1> : _custom_sort_compare<-1>);


//	console::formatter() << "metadb_handle sort: sorted in " << pfc::format_time_ex(timer.query(),6);

	for(t_size n=0;n<count;n++)
	{
		order[n]=data[n].index;
		delete[] data[n].text;
	}

//	console::formatter() << "metadb_handle sort: finished in " << pfc::format_time_ex(timer.query(),6);
}
Beispiel #16
0
	bool WaitAbortable_MsgLoop(HANDLE ev, abort_callback & abort, DWORD timeout /*must not be INFINITE*/) {
		PFC_ASSERT( timeout != INFINITE );
		const DWORD entry = GetTickCount();
		const HANDLE handles[2] = {ev, abort.get_abort_event()};
		for(;;) {
			const DWORD done = GetTickCount() - entry;
			if (done >= timeout) return false;
			SetLastError(0);
			const DWORD status = MsgWaitForMultipleObjects(2, handles, FALSE, timeout - done, QS_ALLINPUT);
			switch(status) {
				case WAIT_TIMEOUT:
					return false;
				case WAIT_OBJECT_0:
					return true;
				case WAIT_OBJECT_0 + 1:
					throw exception_aborted();
				case WAIT_OBJECT_0 + 2:
					ProcessPendingMessages();
					break;
				case WAIT_FAILED:
					WIN32_OP_FAIL();
				default:
					uBugCheck();
			}
		}
	}
	ui_element_instance::ptr instantiate(HWND parent,ui_element_config::ptr cfg,ui_element_instance_callback::ptr callback) 
	{
		PFC_ASSERT( cfg->get_guid() == get_guid() );
		service_nnptr_t<ui_element_instance_impl_helper> item = new service_impl_t<ui_element_instance_impl_helper>(cfg, callback);
		item->initialize_window(parent);
		return item;
	}
Beispiel #18
0
void SmartStrStr::ImportTwoCharMappings(const wchar_t * list, const char * replacement) {
	PFC_ASSERT(strlen(replacement) == 2);
	for (const wchar_t* ptr = list; ; ) {
		wchar_t c = *ptr++;
		if (c == 0) break;
		twoCharMappings[(uint32_t)c] = replacement;
	}
}
static double parse_time(const char * time) {
	unsigned vTotal = 0, vCur = 0;
	for(;;) {
		char c = *time++;
		if (c == 0) return (double) (vTotal + vCur);
		else if (pfc::char_is_numeric( c ) ) {
			vCur = vCur * 10 + (unsigned)(c-'0');
		} else if (c == ':') {
			if (vCur >= 60) {PFC_ASSERT(!"Invalid input"); return 0; }
			vTotal += vCur; vCur = 0; vTotal *= 60;
		} else if (c == '.') {
			return (double) (vTotal + vCur) + parseFraction(time);
		} else {
			PFC_ASSERT(!"Invalid input"); return 0;
		}
	}
}
Beispiel #20
0
	void set_item_selection(HWND p_listview,unsigned p_index,bool p_state)
	{
		PFC_ASSERT( ::IsWindow(p_listview) );
		LVITEM item = {};
		item.stateMask = LVIS_SELECTED;
		item.state = p_state ? LVIS_SELECTED : 0;
		WIN32_OP_D( SendMessage(p_listview,LVM_SETITEMSTATE,(WPARAM)p_index,(LPARAM)&item) );
	}
	void CTableEditHelperV2::_ReStart() {
		PFC_ASSERT( m_editItem < TableEdit_GetItemCount() );
		PFC_ASSERT( m_editSubItem < TableEdit_GetColumnCount() );

		TableEdit_SetItemFocus(m_editItem,m_editSubItem);
		m_editData.new_t();
		t_size lineCount = 1;
		TableEdit_GetField(m_editItem, m_editSubItem, *m_editData, lineCount);
		m_editFlags = TableEdit_GetEditFlags(m_editItem, m_editSubItem);

		RECT rc = TableEdit_GetItemRect(m_editItem, m_editSubItem);
		if (lineCount > 1) {
			rc.bottom = rc.top + (rc.bottom - rc.top) * lineCount;
			m_editFlags |= KFlagMultiLine;
		}

		InPlaceEdit::StartEx(TableEdit_GetParentWnd(), rc, m_editFlags, m_editData, create_task(KTaskID));
	}
void PlaybackTracer::unlock()
{
	lockCount--;
	PFC_ASSERT(lockCount >= 0);
	if (lockCount == 0 && cfgCoverFollowsPlayback){
		setTimer(cfgCoverFollowDelay * 1000);
		waitingForTimer = true;
	}
}
Beispiel #23
0
/*
 * void PFC_ATTR_HIDDEN
 * sysconf_init(void)
 *	Cache system configurations on library initialization.
 */
void PFC_ATTR_HIDDEN
sysconf_init(void)
{
	int	shift;

	SYSCONF_READ(_SC_PAGESIZE, pfc_pagesize, size_t);
	SYSCONF_READ(_SC_NGROUPS_MAX, pfc_ngroups_max, uint32_t);

	PFC_ASSERT(pfc_pagesize != 0 && PFC_IS_POW2(pfc_pagesize));
	PFC_ASSERT(pfc_ngroups_max != 0);

	pfc_pageoffset = pfc_pagesize - 1;
	pfc_pagemask = ~pfc_pageoffset;

	shift = pfc_highbit_ulong((pfc_ulong_t)pfc_pagesize);
	PFC_ASSERT(shift >= 0 && pfc_pagesize == (1UL << shift));
	pfc_pageshift = shift;
}
Beispiel #24
0
/*
 * static inline int
 * pfc_tpool_timedwrlock_abs(pfc_timespec_t *abstime)
 *	Try to acquire thread pool global lock in writer mode.
 *	ETIMEDOUT is returned if the current thread can't acquire the lock
 *	until the specified absolute time.
 */
static inline int
pfc_tpool_timedwrlock_abs(pfc_timespec_t *abstime)
{
	int	err = pfc_rwlock_timedwrlock_abs(&tpool_lock, abstime);

	PFC_ASSERT(err == 0 || err == ETIMEDOUT);

	return err;
}
void file_info::meta_format_entry(t_size index, pfc::string_base & out, const char * separator) const {
    out.reset();
    t_size val, count = meta_enum_value_count(index);
    PFC_ASSERT( count > 0);
    for(val=0; val<count; val++)
    {
        if (val > 0) out += separator;
        out += meta_enum_value(index,val);
    }
}
mainmenu_node::ptr history_mainmenu_commands::dynamic_instantiate(t_uint32 index) {
	TRACK_CALL_TEXT_DEBUG("history_mainmenu_commands::dynamic_instantiate");
	PFC_ASSERT(index == MENU_COMMAND_SEPARATOR);
	if(index == MENU_COMMAND_SEPARATOR) {
		DEBUG_PRINT << "Constructing separator";
		return new service_impl_t<mainmenu_node_separator>();
	} else {
		return NULL;
	}
}
Beispiel #27
0
bool archive_impl::g_parse_unpack_path(const char * path,pfc::string_base & archive,pfc::string_base & file) {
	PFC_ASSERT( g_is_unpack_path(path) );
	path  = strchr(path,'|');
	if (!path) return false;
	int delta = path_unpack_string(archive,path);
	if (delta<0) return false;
	path += delta;
	file = path;
	return true;
}
static double parseFraction(const char * fraction) {
	unsigned v = 0, d = 1;
	while(pfc::char_is_numeric( *fraction) ) {
		d *= 10;
		v *= 10;
		v += (unsigned) ( *fraction - '0' );
		++fraction;
	}
	PFC_ASSERT( *fraction == 0 );
	return (double)v / (double)d;
}
Beispiel #29
0
/*
 * int PFC_ATTR_HIDDEN
 * conf_hdlmap_put(conf_block_t *bp)
 *	Assign new handle ID for the specified configuration block, and put
 *	it into the handle map.
 *
 * Calling/Exit State:
 *	Upon successful completion, new handle ID is set into bp->cb_handle,
 *	and zero is returned.
 *	ENFILE is returned if no handle ID is available.
 *
 * Remarks:
 *	The caller must call this function with holding parser lock in
 *	writer mode.
 */
int PFC_ATTR_HIDDEN
conf_hdlmap_put(conf_block_t *bp)
{
	conf_hdlmap_t	*hdlmap = &conf_blocks;
	pfc_cfblk_t	start;

	PFC_ASSERT(bp->cb_handle == PFC_CFBLK_INVALID);

	/* Assign new handle ID. */
	start = conf_handle_next;
	PFC_ASSERT(start != PFC_CFBLK_INVALID);
	bp->cb_handle = start;

	do {
		pfc_cfblk_t	id;
		int		err;

		/* Try to put this handle into the handle map. */
		err = pfc_rbtree_put(hdlmap, &bp->cb_hdlnode);

		/* Prepare ID for next allocation. */
		id = bp->cb_handle + 1;
		if (PFC_EXPECT_TRUE(id == PFC_CFBLK_INVALID)) {
			id++;
		}
		if (PFC_EXPECT_TRUE(err == 0)) {
			conf_handle_next = id;

			return 0;
		}
		PFC_ASSERT(err == EEXIST);

		/* Handle ID may be overflowed. Try next ID. */
		bp->cb_handle = id;
	} while (bp->cb_handle != start);

	/* No handle ID is available. */
	bp->cb_handle = PFC_CFBLK_INVALID;

	return ENFILE;
}
bool cfg_window_size::on_window_creation(HWND p_wnd)
{
	bool ret = false;
	PFC_ASSERT(!m_windows.have_item(p_wnd));
	m_windows.add_item(p_wnd);

	if (g_is_enabled())
	{
		if (SetWindowSize(p_wnd,m_width,m_height)) ret = true;
	}

	return ret;
}