Skip to content

Commit

Permalink
Refactor recordings class hierarchy (eliminate duplicate data etc.).
Browse files Browse the repository at this point in the history
  • Loading branch information
ksooo committed Sep 6, 2024
1 parent ce9ba70 commit 4eb898a
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 314 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ set(HTS_SOURCES_TVHEADEND_ENTITY
src/tvheadend/entity/Recording.h
src/tvheadend/entity/RecordingBase.h
src/tvheadend/entity/RecordingBase.cpp
src/tvheadend/entity/SeriesRecordingBase.h
src/tvheadend/entity/SeriesRecordingBase.cpp
src/tvheadend/entity/Schedule.h
src/tvheadend/entity/Schedule.cpp
src/tvheadend/entity/Tag.h
Expand Down
11 changes: 2 additions & 9 deletions src/tvheadend/entity/AutoRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@
using namespace tvheadend;
using namespace tvheadend::entity;

AutoRecording::AutoRecording(const std::string& id /*= ""*/)
: RecordingBase(id),
m_startWindowBegin(0),
m_startWindowEnd(0),
m_startExtra(0),
m_stopExtra(0),
m_dupDetect(0),
m_fulltext(0)
AutoRecording::AutoRecording(const std::string& id /*= ""*/) : SeriesRecordingBase(id)
{
}

bool AutoRecording::operator==(const AutoRecording& right)
{
return RecordingBase::operator==(right) && m_startWindowBegin == right.m_startWindowBegin &&
return SeriesRecordingBase::operator==(right) && m_startWindowBegin == right.m_startWindowBegin &&
m_startWindowEnd == right.m_startWindowEnd && m_startExtra == right.m_startExtra &&
m_stopExtra == right.m_stopExtra && m_dupDetect == right.m_dupDetect &&
m_fulltext == right.m_fulltext && m_seriesLink == right.m_seriesLink;
Expand Down
19 changes: 11 additions & 8 deletions src/tvheadend/entity/AutoRecording.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

#pragma once

#include "RecordingBase.h"
#include "SeriesRecordingBase.h"

#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <utility>

namespace tvheadend
{
Expand All @@ -19,7 +22,7 @@ class InstanceSettings;
namespace entity
{

class AutoRecording : public RecordingBase
class AutoRecording : public SeriesRecordingBase
{
public:
AutoRecording(const std::string& id = "");
Expand Down Expand Up @@ -53,12 +56,12 @@ class AutoRecording : public RecordingBase
private:
std::shared_ptr<InstanceSettings> m_settings;

int32_t m_startWindowBegin; // Begin of the starting window (minutes from midnight).
int32_t m_startWindowEnd; // End of the starting window (minutes from midnight).
int64_t m_startExtra; // Extra start minutes (pre-time).
int64_t m_stopExtra; // Extra stop minutes (post-time).
uint32_t m_dupDetect; // duplicate episode detect (numeric values: see dvr_autorec_dedup_t).
uint32_t m_fulltext; // Fulltext epg search.
int32_t m_startWindowBegin{0}; // Begin of the starting window (minutes from midnight).
int32_t m_startWindowEnd{0}; // End of the starting window (minutes from midnight).
int64_t m_startExtra{0}; // Extra start minutes (pre-time).
int64_t m_stopExtra{0}; // Extra stop minutes (post-time).
uint32_t m_dupDetect{0}; // duplicate episode detect (numeric values: see dvr_autorec_dedup_t).
uint32_t m_fulltext{0}; // Fulltext epg search.
std::string m_seriesLink; // Series link.
};

Expand Down
21 changes: 11 additions & 10 deletions src/tvheadend/entity/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

#include <cstdint>

namespace tvheadend
{
namespace entity
namespace tvheadend::entity
{

/**
Expand All @@ -20,17 +18,21 @@ namespace entity
class Entity
{
public:
Entity() : m_id(0), m_dirty(false) {}
Entity() = default;
virtual ~Entity() = default;

bool operator==(const Entity& right) { return m_id == right.m_id; }

bool operator!=(const Entity& right) { return !(*this == right); }

/**
* @return if the entity is dirty
*/
virtual bool IsDirty() const { return m_dirty; }

/**
* Marks the entity as dirty or not
* @param dirty
* @param dirty The new dirty state
*/
virtual void SetDirty(bool dirty) { m_dirty = dirty; }

Expand All @@ -41,16 +43,15 @@ class Entity

/**
* Sets the entity ID
* @param id
* @param id The entity id
*/
void SetId(uint32_t id) { m_id = id; }

protected:
uint32_t m_id;
uint32_t m_id{0};

private:
bool m_dirty;
bool m_dirty{false};
};

} // namespace entity
} // namespace tvheadend
} // namespace tvheadend::entity
128 changes: 41 additions & 87 deletions src/tvheadend/entity/Recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

#pragma once

#include "../utilities/LifetimeMapper.h"
#include "Entity.h"
#include "RecordingBase.h"

#include "kodi/addon-instance/pvr/Timers.h"

#include <algorithm>
#include <cstdint>
#include <map>
#include <string>
#include <utility>

// Timer types
#define TIMER_ONCE_MANUAL (PVR_TIMER_TYPE_NONE + 1)
Expand All @@ -25,9 +25,7 @@
#define TIMER_REPEATING_EPG (PVR_TIMER_TYPE_NONE + 6)
#define TIMER_REPEATING_SERIESLINK (PVR_TIMER_TYPE_NONE + 7)

namespace tvheadend
{
namespace entity
namespace tvheadend::entity
{

class Recording;
Expand All @@ -39,54 +37,31 @@ typedef std::map<uint32_t, Recording> Recordings;
* TODO: Create separate classes for recordings and timers since a
* recording obviously can't have a "timer type"
*/
class Recording : public Entity
class Recording : public RecordingBase
{
public:
Recording()
: m_enabled(0),
m_channel(0),
m_channelType(0),
m_eventId(0),
m_start(0),
m_stop(0),
m_startExtra(0),
m_stopExtra(0),
m_filesStart(0),
m_filesStop(0),
m_filesSize(0),
m_state(PVR_TIMER_STATE_ERROR),
m_lifetime(0),
m_priority(50), // Kodi default - "normal"
m_playCount(0),
m_playPosition(0),
m_contentType(0),
m_season(-1),
m_episode(-1),
m_part(0),
m_ageRating(0)
{
}
Recording() = default;

bool operator==(const Recording& other) const
bool operator==(const Recording& other)
{
return m_id == other.m_id && m_enabled == other.m_enabled && m_channel == other.m_channel &&
m_channelType == other.m_channelType && m_channelName == other.m_channelName &&
m_eventId == other.m_eventId && m_start == other.m_start && m_stop == other.m_stop &&
return RecordingBase::operator==(other) && m_channelType == other.m_channelType &&
m_channelName == other.m_channelName && m_eventId == other.m_eventId &&
m_start == other.m_start && m_stop == other.m_stop &&
m_startExtra == other.m_startExtra && m_stopExtra == other.m_stopExtra &&
m_filesStart == other.m_filesStart && m_filesStop == other.m_filesStop &&
m_filesSize == other.m_filesSize && m_title == other.m_title && m_path == other.m_path &&
m_description == other.m_description && m_image == other.m_image &&
m_fanartImage == other.m_fanartImage && m_timerecId == other.m_timerecId &&
m_autorecId == other.m_autorecId && m_state == other.m_state &&
m_error == other.m_error && m_lifetime == other.m_lifetime &&
m_priority == other.m_priority && m_playCount == other.m_playCount &&
m_playPosition == other.m_playPosition && m_contentType == other.m_contentType &&
m_season == other.m_season && m_episode == other.m_episode && m_part == other.m_part &&
m_filesSize == other.m_filesSize && m_subtitle == other.m_subtitle &&
m_path == other.m_path && m_description == other.m_description &&
m_image == other.m_image && m_fanartImage == other.m_fanartImage &&
m_timerecId == other.m_timerecId && m_autorecId == other.m_autorecId &&
m_state == other.m_state && m_error == other.m_error &&
m_playCount == other.m_playCount && m_playPosition == other.m_playPosition &&
m_contentType == other.m_contentType && m_season == other.m_season &&
m_episode == other.m_episode && m_part == other.m_part &&
m_ageRating == other.m_ageRating && m_ratingLabel == other.m_ratingLabel &&
m_ratingIcon == other.m_ratingIcon && m_ratingSource == other.m_ratingSource;
}

bool operator!=(const Recording& other) const { return !(*this == other); }
bool operator!=(const Recording& other) { return !(*this == other); }

bool IsRecording() const
{
Expand Down Expand Up @@ -115,12 +90,6 @@ class Recording : public Entity
return TIMER_ONCE_MANUAL;
}

bool IsEnabled() const { return m_enabled > 0; }
void SetEnabled(uint32_t enabled) { m_enabled = enabled; }

uint32_t GetChannel() const { return m_channel; }
void SetChannel(uint32_t channel) { m_channel = channel; }

uint32_t GetChannelType() const { return m_channelType; }
void SetChannelType(uint32_t channelType) { m_channelType = channelType; }

Expand All @@ -130,19 +99,19 @@ class Recording : public Entity
uint32_t GetEventId() const { return m_eventId; }
void SetEventId(uint32_t eventId) { m_eventId = eventId; }

// TODO: Change to time_t
//! @todo Change to time_t
int64_t GetStart() const { return m_start; }
void SetStart(int64_t start) { m_start = start; }

// TODO: Change to time_t
//! @todo Change to time_t
int64_t GetStop() const { return m_stop; }
void SetStop(int64_t stop) { m_stop = stop; }

// TODO: Change to time_t
//! @todo Change to time_t
int64_t GetStartExtra() const { return m_startExtra; }
void SetStartExtra(int64_t startExtra) { m_startExtra = startExtra; }

// TODO: Change to time_t
//! @todo Change to time_t
int64_t GetStopExtra() const { return m_stopExtra; }
void SetStopExtra(int64_t stopExtra) { m_stopExtra = stopExtra; }

Expand All @@ -155,9 +124,6 @@ class Recording : public Entity
int64_t GetFilesSize() const { return m_filesSize; }
void SetFilesSize(int64_t size) { m_filesSize = size; }

const std::string& GetTitle() const { return m_title; }
void SetTitle(const std::string& title) { m_title = title; }

const std::string& GetSubtitle() const { return m_subtitle; }
void SetSubtitle(const std::string& subtitle) { m_subtitle = subtitle; }

Expand Down Expand Up @@ -185,12 +151,6 @@ class Recording : public Entity
const std::string& GetError() const { return m_error; }
void SetError(const std::string& error) { m_error = error; }

int GetLifetime() const { return utilities::LifetimeMapper::TvhToKodi(m_lifetime); }
void SetLifetime(uint32_t lifetime) { m_lifetime = lifetime; }

uint32_t GetPriority() const { return m_priority; }
void SetPriority(uint32_t priority) { m_priority = priority; }

uint32_t GetPlayCount() const { return m_playCount; }
void SetPlayCount(uint32_t playCount) { m_playCount = playCount; }

Expand Down Expand Up @@ -226,41 +186,35 @@ class Recording : public Entity
void SetRatingSource(const std::string& ratingSource) { m_ratingSource = ratingSource; }

private:
uint32_t m_enabled;
uint32_t m_channel;
uint32_t m_channelType;
uint32_t m_channelType{0};
std::string m_channelName;
uint32_t m_eventId;
int64_t m_start;
int64_t m_stop;
int64_t m_startExtra;
int64_t m_stopExtra;
int64_t m_filesStart;
int64_t m_filesStop;
int64_t m_filesSize;
std::string m_title;
uint32_t m_eventId{0};
int64_t m_start{0};
int64_t m_stop{0};
int64_t m_startExtra{0};
int64_t m_stopExtra{0};
int64_t m_filesStart{0};
int64_t m_filesStop{0};
int64_t m_filesSize{0};
std::string m_subtitle;
std::string m_path;
std::string m_description;
std::string m_image;
std::string m_fanartImage;
std::string m_timerecId;
std::string m_autorecId;
PVR_TIMER_STATE m_state;
PVR_TIMER_STATE m_state{PVR_TIMER_STATE_ERROR};
std::string m_error;
uint32_t m_lifetime;
uint32_t m_priority;
uint32_t m_playCount;
uint32_t m_playPosition;
uint32_t m_contentType;
int32_t m_season;
int32_t m_episode;
uint32_t m_part;
uint32_t m_ageRating;
uint32_t m_playCount{0};
uint32_t m_playPosition{0};
uint32_t m_contentType{0};
int32_t m_season{-1};
int32_t m_episode{-1};
uint32_t m_part{0};
uint32_t m_ageRating{0};
std::string m_ratingLabel;
std::string m_ratingIcon;
std::string m_ratingSource;
};

} // namespace entity
} // namespace tvheadend
} // namespace tvheadend::entity
Loading

0 comments on commit 4eb898a

Please sign in to comment.