Exemplo n.º 1
0
bool CPlayerPlaylistBar::ParseMPCPlayList(CString fn)
{
    CString str;
    CAtlMap<int, CPlaylistItem> pli;
    CAtlArray<int> idx;

    CWebTextFile f;
    if (!f.Open(fn) || !f.ReadString(str) || str != _T("MPCPLAYLIST")) {
        return false;
    }

    if (f.GetEncoding() == CTextFile::ASCII) {
        f.SetEncoding(CTextFile::ANSI);
    }

    CPath base(fn);
    base.RemoveFileSpec();

    while (f.ReadString(str)) {
        CAtlList<CString> sl;
        Explode(str, sl, ',', 3);
        if (sl.GetCount() != 3) {
            continue;
        }

        if (int i = _ttoi(sl.RemoveHead())) {
            CString key = sl.RemoveHead();
            CString value = sl.RemoveHead();

            if (key == _T("type")) {
                pli[i].m_type = (CPlaylistItem::type_t)_ttol(value);
                idx.Add(i);
            } else if (key == _T("label")) {
                pli[i].m_label = value;
            } else if (key == _T("filename")) {
                value = CombinePath(base, value);
                pli[i].m_fns.AddTail(value);
            } else if (key == _T("subtitle")) {
                value = CombinePath(base, value);
                pli[i].m_subs.AddTail(value);
            } else if (key == _T("video")) {
                while (pli[i].m_fns.GetCount() < 2) {
                    pli[i].m_fns.AddTail(_T(""));
                }
                pli[i].m_fns.GetHead() = value;
            } else if (key == _T("audio")) {
                while (pli[i].m_fns.GetCount() < 2) {
                    pli[i].m_fns.AddTail(_T(""));
                }
                pli[i].m_fns.GetTail() = value;
            } else if (key == _T("vinput")) {
                pli[i].m_vinput = _ttol(value);
            } else if (key == _T("vchannel")) {
                pli[i].m_vchannel = _ttol(value);
            } else if (key == _T("ainput")) {
                pli[i].m_ainput = _ttol(value);
            } else if (key == _T("country")) {
                pli[i].m_country = _ttol(value);
            }
        }
    }

    qsort(idx.GetData(), idx.GetCount(), sizeof(int), s_int_comp);
    for (size_t i = 0; i < idx.GetCount(); i++) {
        m_pl.AddTail(pli[idx[i]]);
    }

    return pli.GetCount() > 0;
}
void AsyncUpdateHandler::OnDataChange(COPCGroup & group, CAtlMap<COPCItem *, OPCItemData *> & changes)
{
	log_NOTICE("OnDataChange called, group [", group.getName(),"] change count [", pantheios::integer(changes.GetCount()),"] have callback [",(callbackFn != NULL?"Y":"N"),"]");
	
	for(POSITION pos = changes.GetStartPosition(); pos != NULL; )
	{
		CAtlMap<COPCItem *, OPCItemData *>::CPair* pPair = changes.GetNext(pos);

		ItemValueStruct itemValueStruct(pPair->m_value);		
		const ItemValue& itemValue = itemValueStruct.getItemValue();
		
		log_NOTICE("\t item [",pPair->m_key->getName(),"] value [", itemValueStruct.getItemValue().value,"]");

		if(callbackFn != NULL)
		{
			log_NOTICE("\t OnDataChange calling callback fn");			
			//Update* update = createUpdate(pPair->m_key->getName().GetString(), itemValue.value, itemValue.quality, itemValue.dataType, itemValue.timestamp);
			callbackFn(pPair->m_key->getName().GetString(), itemValue.value, itemValue.quality, itemValue.dataType, itemValue.timestamp);

			log_DEBUG("\t OnDataChange called callback fn");
/*			
			callbackFn(update);
			log_DEBUG("\t OnDataChange called callback fn");

			destroyUpdate(update);
			log_DEBUG("\t OnDataChange destroyed object");
*/
		}
	}
}