Ejemplo n.º 1
0
void PvrManager::loadTasks()
{
    STUB();
    m_tasks.clear();
    const QString str = m_profile->datasource()->get("PVR", "tasks");
    const QJsonArray arr = QJsonDocument::fromJson(str.toUtf8()).array();
    for(size_t index = 0; index< arr.size(); index++)
    {
        TaskInfo* task = TaskInfo::fromJson(m_profile, arr.at(index).toObject(), this);
        if(task)
        {
            m_tasks.insert(QString::number(task->m_id), task);
            task->scheduleStart();
        }
    }
    DEBUG() << "Tasks loaded:" << m_tasks.size();
}
Ejemplo n.º 2
0
/**
 * @brief PvrManager::CreateTask
 * Schedule channel recording task.
 *
 * @param url address of the stream that will be recorded (http://..., rtp://..., udp://...)
 * @param fileName full file name of recording (/media/USB-... or /ram/media/USB-...)
 * @param startTime recording start time
 * UTC time in "YYYYMMDDThhmmss" format or number of seconds since Epoch (1970/01/01 UTC)
 *
 * @param endTime recording end time
 * UTC time in "YYYYMMDDThhmmss" format or number of seconds since Epoch (1970/01/01 UTC)
 *
 * @return unique task identifier if operation was successful, otherwise return value is a string representing error code (<0) from error codes table
 *
 * @example
 * // number of seconds since Epoch can be obtained via Date object
 * var date = new Date();
 * var startTime = date.getTime()/1000;
 */
QString PvrManager::CreateTask(const QString &url, const QString &fileName, const QString &startTime, const QString &endTime)
{
    STUB() << url << fileName << startTime << endTime;

    if(m_tasks.size() >= m_max_record_count - 1)
    {
        DEBUG() << "Reached maximum of simultaneous records!" << m_tasks.size();
        return QString::number(TaskInfo::ERROR_MAX_SIMULTANEOUS_RECORDS);
    }

    QDateTime start_time = QDateTime::fromString(startTime, DATE_TIME_FORMAT);;
    if(!start_time.isValid())
        start_time = QDateTime::fromMSecsSinceEpoch(startTime.toLongLong() * 1000);

    QDateTime end_time = QDateTime::fromString(endTime, DATE_TIME_FORMAT);
    if(!end_time.isValid())
        end_time = QDateTime::fromMSecsSinceEpoch(endTime.toLongLong() * 1000);

    if(!start_time.isValid() || !end_time.isValid())
    {
        DEBUG() << "Start or end time is incorrect" << start_time << end_time;
        return QString::number(TaskInfo::ERROR_BAD_ARGUMENT);
    }

    if( (start_time > end_time)
        || ((end_time.currentMSecsSinceEpoch() - start_time.currentMSecsSinceEpoch()) > 24*60*60*1000) // 24 hours
        )
    {
        DEBUG() << "Incorrect time range!" << start_time << end_time;
        return QString::number(TaskInfo::ERROR_WRONG_RANGE);
    }

    if(!fileName.startsWith("/media/USB-")
            && !fileName.startsWith("/ram/media/USB-")
            && !fileName.startsWith("USB-")
            )
    {
        DEBUG() << "Wrong file name" << fileName;
        return QString::number(TaskInfo::ERROR_WRONG_FILE_NAME);
    }

    for(const TaskInfo* item: m_tasks)
    {
        if(item->m_file_name == fileName)
        {
            DEBUG() << "File" << fileName << "already exists";
            return QString::number(TaskInfo::ERROR_DUPLICATE_TASKS);
        }
    }

    TaskInfo* task = new TaskInfo(m_profile, ++m_last_task_index, url, fileName, start_time, end_time, this);

    connect(task, &TaskInfo::errorHappened, this, &PvrManager::onTaskError);

    m_tasks.insert(QString::number(task->m_id), task);

    DEBUG() << task->m_url << task->m_file_name << task->m_start_time << task->m_end_time;

    TaskInfo::ErrorCode result = task->scheduleStart();
    if(result != TaskInfo::ERROR_SUCCESSFUL)
        return QString::number(result);

    return QString::number(task->m_id);
}