Ejemplo n.º 1
0
int
cmyth_mysql_get_guide(cmyth_database_t db, cmyth_program_t **prog, time_t starttime, time_t endtime) 
{
	MYSQL_RES *res= NULL;
	MYSQL_ROW row;
        const char *query_str = "SELECT program.chanid,UNIX_TIMESTAMP(program.starttime),UNIX_TIMESTAMP(program.endtime),program.title,program.description,program.subtitle,program.programid,program.seriesid,program.category,channel.channum,channel.callsign,channel.name,channel.sourceid FROM program INNER JOIN channel ON program.chanid=channel.chanid WHERE ( ( starttime>=? and starttime<? ) OR ( starttime <? and endtime > ?) ) ORDER BY (channel.channum + 0), program.starttime ASC ";
	int rows=0;
	int n=0;
	cmyth_mysql_query_t * query;
	query = cmyth_mysql_query_create(db,query_str);

	if(cmyth_mysql_query_param_unixtime(query,starttime) < 0
	    || cmyth_mysql_query_param_unixtime(query,endtime) < 0
	    || cmyth_mysql_query_param_unixtime(query,starttime) < 0
	    || cmyth_mysql_query_param_unixtime(query,starttime) < 0)
	{
	    cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query parameters failed! Maybe we're out of memory?\n", __FUNCTION__);
	    ref_release(query);
	    return -1;
 	}
	res = cmyth_mysql_query_result(query);
	ref_release(query);
	if(res == NULL)
	{
	    cmyth_dbg(CMYTH_DBG_ERROR,"%s, finalisation/execution of query failed!\n", __FUNCTION__);
	    return -1;
	}


	while((row = mysql_fetch_row(res))) {
        	if (rows >= n) {
                	n+=10;
                       	*prog=realloc(*prog,sizeof(**prog)*(n));
               	}
		(*prog)[rows].chanid = safe_atoi(row[0]);
               	(*prog)[rows].recording=0;
		(*prog)[rows].starttime= (time_t)safe_atol(row[1]);
		(*prog)[rows].endtime= (time_t)safe_atol(row[2]);
		sizeof_strncpy((*prog)[rows].title, row[3]);
		sizeof_strncpy((*prog)[rows].description, row[4]);
		sizeof_strncpy((*prog)[rows].subtitle, row[5]);
		sizeof_strncpy((*prog)[rows].programid, row[6]);
		sizeof_strncpy((*prog)[rows].seriesid, row[7]);
		sizeof_strncpy((*prog)[rows].category, row[8]);
		(*prog)[rows].channum = safe_atoi(row[9]);
		sizeof_strncpy((*prog)[rows].callsign, row[10]);
		sizeof_strncpy((*prog)[rows].name, row[11]);
		(*prog)[rows].sourceid = safe_atoi(row[12]);
		(*prog)[rows].startoffset=0;
		(*prog)[rows].endoffset=0;
          	rows++;
        }
        mysql_free_result(res);
        cmyth_dbg(CMYTH_DBG_ERROR, "%s: rows= %d\n", __FUNCTION__, rows);
	return rows;
}
Ejemplo n.º 2
0
HRESULT CMainDlg::PCSoftResumeDown(DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult)
{
	CComVariant retVal = false;

	do
	{
		LONG id = safe_atol(pDispParams->rgvarg[0].bstrVal);
		if(id == 0)
		{
			break;
		}

		CriticalSectionScoped locker(m_csPhoneNess);

		IDTManager *pDTMgr = GetDTMgrForPhone();
		if(pDTMgr != NULL)
		{
			Id2PhoneSoftIter itSoft = m_id2PhoneSoft.Lookup(id);
			if(itSoft != NULL)
			{
				pDTMgr->ResumeTask(itSoft->m_value.idDown);
				retVal = true;
			}
		}
	}
	while(FALSE);

	if(pVarResult != NULL)
	{
		retVal.Detach(pVarResult);
	}

	return S_OK;
}
Ejemplo n.º 3
0
int
cmyth_mysql_get_prev_recorded(cmyth_database_t db, cmyth_program_t **prog)
{
	MYSQL_RES *res= NULL;
	MYSQL_ROW row;
	int n=0;
	int rows=0;
        const char *query = "SELECT oldrecorded.chanid, UNIX_TIMESTAMP(starttime), UNIX_TIMESTAMP(endtime), title, subtitle, description, category, seriesid, programid, channel.channum, channel.callsign, channel.name, findid, rectype, recstatus, recordid, duplicate FROM oldrecorded LEFT JOIN channel ON oldrecorded.chanid = channel.chanid ORDER BY `starttime` ASC";
	if(cmyth_db_check_connection(db) != 0)
	{
               cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", __FUNCTION__);
               fprintf(stderr,"%s: cmyth_db_check_connection failed\n", __FUNCTION__);
	       return -1;
	}
        if(mysql_query(db->mysql,query)) {
                 cmyth_dbg(CMYTH_DBG_ERROR, "%s: mysql_query() Failed: %s\n", 
                           __FUNCTION__, mysql_error(db->mysql));
		return -1;
        }
        res = mysql_store_result(db->mysql);
	while((row = mysql_fetch_row(res))) {
        	if (rows >= n) {
                	n+=10;
                       	*prog=realloc(*prog,sizeof(**prog)*(n));
               	}
		(*prog)[rows].chanid = safe_atoi(row[0]);
               	(*prog)[rows].recording=0;
		(*prog)[rows].starttime=(time_t)safe_atol(row[1]);
		(*prog)[rows].endtime= (time_t)safe_atol(row[2]);
		sizeof_strncpy((*prog)[rows].title, row[3]);
		sizeof_strncpy((*prog)[rows].subtitle, row[4]);
		sizeof_strncpy((*prog)[rows].description, row[5]);
		sizeof_strncpy((*prog)[rows].category, row[6]);
		sizeof_strncpy((*prog)[rows].seriesid, row[7]);
		sizeof_strncpy((*prog)[rows].programid, row[8]);
		(*prog)[rows].channum = safe_atoi(row[9]);
		sizeof_strncpy((*prog)[rows].callsign, row[10]);
		sizeof_strncpy((*prog)[rows].name, row[11]);
		//sizeof_strncpy((*prog)[rows].rec_status, row[14]);
		(*prog)[rows].rec_status=safe_atoi(row[14]);
		//fprintf(stderr, "row=%s   val=%d\n",row[14],(*prog)[rows].rec_status);
          	rows++;
        }
        mysql_free_result(res);
        cmyth_dbg(CMYTH_DBG_ERROR, "%s: rows= %d\n", __FUNCTION__, rows);
	return rows;
}
Ejemplo n.º 4
0
HRESULT CMainDlg::PCSoftGetDownState(DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult)
{
	if(pVarResult == NULL) return S_OK;

	::VariantInit(pVarResult);
	pVarResult->vt = VT_BSTR;
	pVarResult->bstrVal = NULL;

	LONG id = safe_atol(pDispParams->rgvarg[0].bstrVal);
	if(id == 0)
	{
		return S_OK;
	}

	CriticalSectionScoped locker(m_csPhoneNess);		

	Id2PhoneSoftIter itSoft = m_id2PhoneSoft.Lookup(id);
	if(itSoft != NULL)
	{
		CString strState;
		strState.Format(L"{state:%d,speed:%d,recved:%d}", 
			itSoft->m_value.state, itSoft->m_value.speed, itSoft->m_value.recved);

		pVarResult->bstrVal = ::SysAllocString(strState);
	}
	else
	{
		CString strState;
		strState.Format(L"{state:%d,speed:%d,recved:%d}", 
			3, 0, 0);

		pVarResult->bstrVal = ::SysAllocString(strState);
	}

	return S_OK;
}
Ejemplo n.º 5
0
HRESULT CMainDlg::PCSoftStartDown(DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult)
{
	CComVariant retVal = false;

	do
	{
		LONG id = safe_atol(pDispParams->rgvarg[4].bstrVal);
		if(id == 0)
		{
			break;
		}

		//
		// 若文件已存在,则直接返回
		//
		CString strStore;
		BKSafeConfig::GetStoreDir(strStore);
		SHCreateDirectory(NULL, strStore);

		strStore = _PathAddBackslash(strStore) + pDispParams->rgvarg[1].bstrVal;
		if(::PathFileExists(strStore))
		{
			retVal = true;
			break;
		}

		CriticalSectionScoped locker(m_csPhoneNess);

		// 若任务已经存在,则直接返回
		{
			Id2PhoneSoftIter itSoft = m_id2PhoneSoft.Lookup(id);
			if(itSoft != NULL)
			{
				retVal = false;
				break;
			}
		}

		IDTManager *pDTMgr = GetDTMgrForPhone();
		if(pDTMgr != NULL)
		{
			int curPos = 0;
			CString strUrl = pDispParams->rgvarg[3].bstrVal;

			CString token = strUrl.Tokenize(L" ", curPos);
			if(!token.IsEmpty())
			{
				CAtlArray<CString> *pUrlArray = new CAtlArray<CString>();

				do
				{
					pUrlArray->Add(token);
					token = strUrl.Tokenize(L" ", curPos);
				}
				while(!token.IsEmpty());

				PhoneSoft ps;
				ps.speed = 0;
				ps.recved = 0;
				ps.state = PDS_INIT;
				ps.idDown = pDTMgr->NewTask(pUrlArray, pDispParams->rgvarg[2].bstrVal, strStore);

				m_id2PhoneSoft[id] = ps;
				m_dt2Id[ps.idDown] = id;

				retVal = true;
			}
		}
	}
	while(FALSE);

	if(pVarResult != NULL)
	{
		retVal.Detach(pVarResult);
	}
	return S_OK;
}