New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PVR] Refactor PVR jobs. Get rid of PVRJobs.(h|cpp). #16698
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. |
||||||||||
{ | ||||||||||
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) {} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. |
||||||||||
~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) {} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never. |
||||||||||
~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) | ||||||||||
|
@@ -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 | ||||||||||
|
@@ -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)); | ||||||||||
} | ||||||||||
} | ||||||||||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. This looks so ugly that I will not accept this coding guideline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I already told you, if you do not like the style submit a PR that changes the docs and clang-format configuration.