Skip to content
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

Merged
merged 1 commit into from Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: m_bNotifyUser(bNotifyUser), m_bError(bError), m_label(label), m_msg(msg), m_icon(icon) {}
: m_bNotifyUser(bNotifyUser)
, m_bError(bError)
, m_label(label)
, m_msg(msg)
, m_icon(icon)
{
}

Copy link
Member Author

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.

Copy link
Member

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.

};

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: m_channelNavigator(channelNavigator)
: m_channelNavigator(channelNavigator)

Copy link
Member Author

Choose a reason for hiding this comment

The 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) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: CPVRChannelTimeoutJobBase(channelNavigator, iTimeout) {}
: CPVRChannelTimeoutJobBase(channelNavigator, iTimeout)
{
}

Copy link
Member Author

Choose a reason for hiding this comment

The 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) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: CPVRChannelTimeoutJobBase(channelNavigator, iTimeout) {}
: CPVRChannelTimeoutJobBase(channelNavigator, iTimeout)
{
}

Copy link
Member Author

Choose a reason for hiding this comment

The 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)
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.