Skip to content

Commit

Permalink
[PVR] Refactor PVR jobs. Get rid of PVRJobs.(h|cpp).
Browse files Browse the repository at this point in the history
  • Loading branch information
ksooo committed Oct 2, 2019
1 parent 31c550b commit 85b817a
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 421 deletions.
4 changes: 2 additions & 2 deletions xbmc/pvr/CMakeLists.txt
Expand Up @@ -7,7 +7,7 @@ set(SOURCES PVRActionListener.cpp
PVRGUIActions.cpp
PVRItem.cpp
PVRChannelNumberInputHandler.cpp
PVRJobs.cpp
PVREventLogJob.cpp
PVRGUIChannelIconUpdater.cpp
PVRGUIChannelNavigator.cpp
PVRGUIDirectory.cpp
Expand All @@ -26,7 +26,7 @@ set(HEADERS PVRActionListener.h
PVRGUIActions.h
PVRItem.h
PVRChannelNumberInputHandler.h
PVRJobs.h
PVREventLogJob.h
PVRGUIChannelIconUpdater.h
PVRGUIChannelNavigator.h
PVRGUIDirectory.h
Expand Down
44 changes: 44 additions & 0 deletions xbmc/pvr/PVREventLogJob.cpp
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2012-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#include "PVREventlogJob.h"

#include "ServiceBroker.h"
#include "dialogs/GUIDialogKaiToast.h"
#include "events/EventLog.h"
#include "events/NotificationEvent.h"

namespace PVR
{

CPVREventLogJob::CPVREventLogJob(bool bNotifyUser, bool bError, const std::string& label, const std::string& msg, const std::string& icon)
{
AddEvent(bNotifyUser, bError, label, msg, icon);
}

void CPVREventLogJob::AddEvent(bool bNotifyUser, bool bError, const std::string& label, const std::string& msg, const std::string& icon)
{
m_events.emplace_back(Event(bNotifyUser, bError, label, msg, icon));
}

bool CPVREventLogJob::DoWork()
{
for (const auto& event : m_events)
{
if (event.m_bNotifyUser)
CGUIDialogKaiToast::QueueNotification(
event.m_bError ? CGUIDialogKaiToast::Error : CGUIDialogKaiToast::Info, event.m_label.c_str(), event.m_msg, 5000, true);

// Write event log entry.
CServiceBroker::GetEventLog().Add(
std::make_shared<CNotificationEvent>(event.m_label, event.m_msg, event.m_icon, event.m_bError ? EventLevel::Error : EventLevel::Information));
}
return true;
}

} // namespace PVR
45 changes: 45 additions & 0 deletions xbmc/pvr/PVREventLogJob.h
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2012-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#pragma once

#include "utils/Job.h"

#include <string>
#include <vector>

namespace PVR
{
class CPVREventLogJob : public CJob
{
public:
CPVREventLogJob() = default;
CPVREventLogJob(bool bNotifyUser, bool bError, const std::string& label, const std::string& msg, const std::string& icon);
~CPVREventLogJob() override = default;
const char* GetType() const override { return "pvr-eventlog-job"; }

void AddEvent(bool bNotifyUser, bool bError, const std::string& label, const std::string& msg, const std::string& icon);

bool DoWork() override;

private:
struct Event
{
bool m_bNotifyUser;
bool m_bError;
std::string m_label;
std::string m_msg;
std::string m_icon;

Event(bool bNotifyUser, bool bError, const std::string& label, const std::string& msg, const std::string& icon)
: m_bNotifyUser(bNotifyUser), m_bError(bError), m_label(label), m_msg(msg), m_icon(icon) {}
};

std::vector<Event> m_events;
};
} // namespace PVR
4 changes: 2 additions & 2 deletions xbmc/pvr/PVRGUIActions.cpp
Expand Up @@ -32,8 +32,8 @@
#include "messaging/helpers/DialogOKHelper.h"
#include "network/Network.h"
#include "pvr/PVRDatabase.h"
#include "pvr/PVREventlogJob.h"
#include "pvr/PVRItem.h"
#include "pvr/PVRJobs.h"
#include "pvr/PVRManager.h"
#include "pvr/PVRStreamProperties.h"
#include "pvr/addons/PVRClients.h"
Expand Down Expand Up @@ -1945,7 +1945,7 @@ namespace PVR
icon = "special://xbmc/media/icon256x256.png";
}

CPVREventlogJob* job = new CPVREventlogJob;
CPVREventLogJob* job = new CPVREventLogJob;
job->AddEvent(false, // do not display a toast, only log event
false, // info, no error
name,
Expand Down
70 changes: 67 additions & 3 deletions xbmc/pvr/PVRGUIChannelNavigator.cpp
Expand Up @@ -13,14 +13,78 @@
#include "ServiceBroker.h"
#include "guilib/GUIComponent.h"
#include "pvr/PVRGUIActions.h"
#include "pvr/PVRJobs.h"
#include "pvr/PVRManager.h"
#include "pvr/channels/PVRChannelGroup.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "threads/SingleLock.h"
#include "utils/Job.h"
#include "utils/JobManager.h"

#ifdef TARGET_POSIX
#include "platform/posix/XTimeUtils.h"
#endif

namespace
{
class CPVRChannelTimeoutJobBase : public CJob, public IJobCallback
{
public:
CPVRChannelTimeoutJobBase() = delete;
CPVRChannelTimeoutJobBase(PVR::CPVRGUIChannelNavigator& channelNavigator, int iTimeout)
: m_channelNavigator(channelNavigator)
{
m_delayTimer.Set(iTimeout);
}

~CPVRChannelTimeoutJobBase() override = default;

virtual void OnTimeout() = 0;

void OnJobComplete(unsigned int iJobID, bool bSuccess, CJob* job) override {}

bool DoWork() override
{
while (!ShouldCancel(0, 0))
{
if (m_delayTimer.IsTimePast())
{
OnTimeout();
return true;
}
Sleep(10);
}
return false;
}

protected:
PVR::CPVRGUIChannelNavigator& m_channelNavigator;

private:
XbmcThreads::EndTime m_delayTimer;
};

class CPVRChannelEntryTimeoutJob : public CPVRChannelTimeoutJobBase
{
public:
CPVRChannelEntryTimeoutJob(PVR::CPVRGUIChannelNavigator& channelNavigator, int iTimeout)
: CPVRChannelTimeoutJobBase(channelNavigator, iTimeout) {}
~CPVRChannelEntryTimeoutJob() override = default;
const char* GetType() const override { return "pvr-channel-entry-timeout-job"; }
void OnTimeout() override { m_channelNavigator.SwitchToCurrentChannel(); }
};

class CPVRChannelInfoTimeoutJob : public CPVRChannelTimeoutJobBase
{
public:
CPVRChannelInfoTimeoutJob(PVR::CPVRGUIChannelNavigator& channelNavigator, int iTimeout)
: CPVRChannelTimeoutJobBase(channelNavigator, iTimeout) {}
~CPVRChannelInfoTimeoutJob() override = default;
const char* GetType() const override { return "pvr-channel-info-timeout-job"; }
void OnTimeout() override { m_channelNavigator.HideInfo(); }
};
} // unnamed namespace

namespace PVR
{
void CPVRGUIChannelNavigator::SelectNextChannel(ChannelSwitchMode eSwitchMode)
Expand Down Expand Up @@ -85,7 +149,7 @@ namespace PVR
if (m_iChannelEntryJobId >= 0)
CJobManager::GetInstance().CancelJob(m_iChannelEntryJobId);

CPVRChannelEntryTimeoutJob* job = new CPVRChannelEntryTimeoutJob(iTimeout);
CPVRChannelEntryTimeoutJob* job = new CPVRChannelEntryTimeoutJob(*this, iTimeout);
m_iChannelEntryJobId = CJobManager::GetInstance().AddJob(job, dynamic_cast<IJobCallback*>(job));
}
else
Expand Down Expand Up @@ -150,7 +214,7 @@ namespace PVR

if (!bForce && iTimeout > 0)
{
CPVRChannelInfoTimeoutJob* job = new CPVRChannelInfoTimeoutJob(iTimeout * 1000);
CPVRChannelInfoTimeoutJob* job = new CPVRChannelInfoTimeoutJob(*this, iTimeout * 1000);
m_iChannelInfoJobId = CJobManager::GetInstance().AddJob(job, dynamic_cast<IJobCallback*>(job));
}
}
Expand Down
152 changes: 0 additions & 152 deletions xbmc/pvr/PVRJobs.cpp

This file was deleted.

0 comments on commit 85b817a

Please sign in to comment.