Skip to content

Commit

Permalink
Removed useless m_egp_events!
Browse files Browse the repository at this point in the history
  • Loading branch information
aassif committed Dec 14, 2018
1 parent e75c5b0 commit d1c3e84
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 44 deletions.
62 changes: 23 additions & 39 deletions src/PVRFreeboxData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ bool PVRFreeboxData::ReadJSON (Document * doc, const string & url)
return false;
}

PVRFreeboxData::Event::Event (const Value & e, unsigned int channel) :
PVRFreeboxData::Event::Event (const Value & e, unsigned int channel, time_t date) :
channel (channel),
uuid (JSON<string> (e, "id")),
date (JSON<int> (e, "date")),
date (JSON<int> (e, "date", date)),
duration (JSON<int> (e, "duration")),
title (JSON<string> (e, "title")),
subtitle (JSON<string> (e, "sub_title")),
Expand Down Expand Up @@ -307,8 +307,8 @@ bool PVRFreeboxData::ProcessChannels ()

Conflict c (uuid, major, minor, i);

channels_by_uuid [uuid] .push_back (c);
channels_by_major[major].push_back (c);
conflicts_by_uuid [uuid] .push_back (c);
conflicts_by_major[major].push_back (c);
}

static const ConflictComparator comparator;
Expand Down Expand Up @@ -383,7 +383,6 @@ PVRFreeboxData::PVRFreeboxData (const string & path,
m_tv_quality (Quality (quality)),
m_epg_queries (),
m_epg_cache (),
m_epg_events (),
m_epg_days (0),
m_epg_last (0),
m_epg_extended (extended)
Expand Down Expand Up @@ -486,51 +485,31 @@ void PVRFreeboxData::ProcessEvent (const Event & e, EPG_EVENT_STATE state)
PVR->EpgEventStateChange (&tag, state);
}

void PVRFreeboxData::ProcessEvent (const Value & event, unsigned int channel, EPG_EVENT_STATE state)
void PVRFreeboxData::ProcessEvent (const Value & event, unsigned int channel, time_t date, EPG_EVENT_STATE state)
{
switch (state)
{
case EPG_EVENT_CREATED:
{
Event e (event, channel);
{
P8PLATFORM::CLockObject lock (m_mutex);
if (m_epg_extended)
{
string query = "/api/v5/tv/epg/programs/" + e.uuid;
m_epg_events.insert (make_pair (e.uuid, e));
m_epg_queries.push (Query (EVENT, URL (query), channel));
//XBMC->Log (LOG_INFO, "Queued: '%s'", query.c_str ());
}
}
ProcessEvent (e, EPG_EVENT_CREATED);
break;
}
Event e (event, channel, date);

case EPG_EVENT_UPDATED:
if (state == EPG_EVENT_CREATED)
{
P8PLATFORM::CLockObject lock (m_mutex);
if (m_epg_extended)
{
Event e (event, channel);
{
P8PLATFORM::CLockObject lock (m_mutex);
auto f = m_epg_events.find (e.uuid);
if (f != m_epg_events.end ())
{
e.date = f->second.date; // !!!
m_epg_events.erase (f);
}
}
ProcessEvent (e, EPG_EVENT_UPDATED);
break;
string query = "/api/v5/tv/epg/programs/" + e.uuid;
m_epg_queries.push (Query (EVENT, URL (query), channel, date));
}
}

ProcessEvent (e, state);
}

void PVRFreeboxData::ProcessChannel (const Value & epg, unsigned int channel)
{
for (auto i = epg.MemberBegin (); i != epg.MemberEnd (); ++i)
{
const Value & event = i->value;

string uuid = JSON<string> (event, "id");
time_t date = JSON<int> (event, "date");

static const string PREFIX = "pluri_";
if (uuid.find (PREFIX) != 0) continue;
Expand All @@ -542,7 +521,7 @@ void PVRFreeboxData::ProcessChannel (const Value & epg, unsigned int channel)
if (m_epg_cache.count (query) > 0) continue;
}

ProcessEvent (event, channel, EPG_EVENT_CREATED);
ProcessEvent (event, channel, date, EPG_EVENT_CREATED);

{
P8PLATFORM::CLockObject lock (m_mutex);
Expand Down Expand Up @@ -614,11 +593,16 @@ void * PVRFreeboxData::Process ()
{
case FULL : ProcessFull (r); break;
case CHANNEL : ProcessChannel (r, q.channel); break;
case EVENT : ProcessEvent (r, q.channel, EPG_EVENT_UPDATED); break;
case EVENT : ProcessEvent (r, q.channel, q.date, EPG_EVENT_UPDATED); break;
}
}
}
}
else
{
P8PLATFORM::CLockObject lock (m_mutex);
m_epg_cache.clear ();
}

Sleep (delay * 1000);
}
Expand Down
18 changes: 13 additions & 5 deletions src/PVRFreeboxData.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,21 @@ class PVRFreeboxData :
QueryType type;
std::string query;
unsigned int channel;
time_t date;

public:
Query () : type (NONE) {}

Query (QueryType t, const std::string & q, unsigned int c = 0) :
type (t), query (q), channel (c) {}
Query (QueryType t,
const std::string & q,
unsigned int c = 0,
time_t d = 0) :
type (t),
query (q),
channel (c),
date (d)
{
}
};

// EPG events.
Expand All @@ -119,7 +128,7 @@ class PVRFreeboxData :
std::string outline;

public:
Event (const rapidjson::Value &, unsigned int channel);
Event (const rapidjson::Value &, unsigned int channel, time_t date);
};

public:
Expand Down Expand Up @@ -154,7 +163,7 @@ class PVRFreeboxData :
// Process JSON EPG.
void ProcessFull (const rapidjson::Value & epg);
void ProcessChannel (const rapidjson::Value & epg, unsigned int channel);
void ProcessEvent (const rapidjson::Value & epg, unsigned int channel, EPG_EVENT_STATE);
void ProcessEvent (const rapidjson::Value & epg, unsigned int channel, time_t, EPG_EVENT_STATE);

// If /api/v5/tv/epg/programs/* queries had a "date", things would be *way* easier!
void ProcessEvent (const Event &, EPG_EVENT_STATE);
Expand All @@ -181,7 +190,6 @@ class PVRFreeboxData :
enum Quality m_tv_quality;
std::queue<Query> m_epg_queries;
std::set<std::string> m_epg_cache;
std::map<std::string, Event> m_epg_events;
int m_epg_days;
time_t m_epg_last;
bool m_epg_extended;
Expand Down

0 comments on commit d1c3e84

Please sign in to comment.