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 dac0d9a
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 416 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
43 changes: 43 additions & 0 deletions xbmc/pvr/PVREventlogJob.cpp
@@ -0,0 +1,43 @@
/*
* 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(
EventPtr(new CNotificationEvent(event.m_label, event.m_msg, event.m_icon, event.m_bError ? EventLevel::Error : EventLevel::Information)));
}
return true;
}

} // namespace PVR
46 changes: 46 additions & 0 deletions xbmc/pvr/PVREventlogJob.h
@@ -0,0 +1,46 @@
/*
* 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
2 changes: 1 addition & 1 deletion 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
70 changes: 67 additions & 3 deletions xbmc/pvr/PVRGUIChannelNavigator.cpp
Expand Up @@ -12,15 +12,79 @@
#include "GUIInfoManager.h"
#include "ServiceBroker.h"
#include "guilib/GUIComponent.h"
#ifdef TARGET_POSIX
#include "platform/posix/XTimeUtils.h"
#endif
#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"

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 dac0d9a

Please sign in to comment.