summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/AddonCallbacksPVR.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/AddonCallbacksPVR.cpp')
-rw-r--r--xbmc/addons/AddonCallbacksPVR.cpp324
1 files changed, 324 insertions, 0 deletions
diff --git a/xbmc/addons/AddonCallbacksPVR.cpp b/xbmc/addons/AddonCallbacksPVR.cpp
new file mode 100644
index 0000000..1d769e1
--- /dev/null
+++ b/xbmc/addons/AddonCallbacksPVR.cpp
@@ -0,0 +1,324 @@
1/*
2 * Copyright (C) 2012-2013 Team XBMC
3 * http://xbmc.org
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include "Application.h"
22#include "AddonCallbacksPVR.h"
23#include "settings/AdvancedSettings.h"
24#include "utils/log.h"
25#include "utils/StringUtils.h"
26#include "dialogs/GUIDialogKaiToast.h"
27
28#include "epg/EpgContainer.h"
29#include "pvr/PVRManager.h"
30#include "pvr/channels/PVRChannelGroupsContainer.h"
31#include "pvr/channels/PVRChannelGroupInternal.h"
32#include "pvr/addons/PVRClient.h"
33#include "pvr/recordings/PVRRecordings.h"
34#include "pvr/timers/PVRTimers.h"
35#include "pvr/timers/PVRTimerInfoTag.h"
36
37using namespace PVR;
38using namespace EPG;
39
40namespace ADDON
41{
42
43CAddonCallbacksPVR::CAddonCallbacksPVR(CAddon* addon)
44{
45 m_addon = addon;
46 m_callbacks = new CB_PVRLib;
47
48 /* write XBMC PVR specific add-on function addresses to callback table */
49 m_callbacks->TransferEpgEntry = PVRTransferEpgEntry;
50 m_callbacks->TransferChannelEntry = PVRTransferChannelEntry;
51 m_callbacks->TransferTimerEntry = PVRTransferTimerEntry;
52 m_callbacks->TransferRecordingEntry = PVRTransferRecordingEntry;
53 m_callbacks->AddMenuHook = PVRAddMenuHook;
54 m_callbacks->Recording = PVRRecording;
55 m_callbacks->TriggerChannelUpdate = PVRTriggerChannelUpdate;
56 m_callbacks->TriggerChannelGroupsUpdate = PVRTriggerChannelGroupsUpdate;
57 m_callbacks->TriggerTimerUpdate = PVRTriggerTimerUpdate;
58 m_callbacks->TriggerRecordingUpdate = PVRTriggerRecordingUpdate;
59 m_callbacks->TriggerEpgUpdate = PVRTriggerEpgUpdate;
60 m_callbacks->FreeDemuxPacket = PVRFreeDemuxPacket;
61 m_callbacks->AllocateDemuxPacket = PVRAllocateDemuxPacket;
62 m_callbacks->TransferChannelGroup = PVRTransferChannelGroup;
63 m_callbacks->TransferChannelGroupMember = PVRTransferChannelGroupMember;
64}
65
66CAddonCallbacksPVR::~CAddonCallbacksPVR()
67{
68 /* delete the callback table */
69 delete m_callbacks;
70}
71
72CPVRClient *CAddonCallbacksPVR::GetPVRClient(void *addonData)
73{
74 CAddonCallbacks *addon = static_cast<CAddonCallbacks *>(addonData);
75 if (!addon || !addon->GetHelperPVR())
76 {
77 CLog::Log(LOGERROR, "PVR - %s - called with a null pointer", __FUNCTION__);
78 return NULL;
79 }
80
81 return dynamic_cast<CPVRClient *>(addon->GetHelperPVR()->m_addon);
82}
83
84void CAddonCallbacksPVR::PVRTransferChannelGroup(void *addonData, const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP *group)
85{
86 if (!handle)
87 {
88 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
89 return;
90 }
91
92 CPVRChannelGroups *xbmcGroups = static_cast<CPVRChannelGroups *>(handle->dataAddress);
93 if (!group || !xbmcGroups)
94 {
95 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
96 return;
97 }
98
99 if (strlen(group->strGroupName) == 0)
100 {
101 CLog::Log(LOGERROR, "PVR - %s - empty group name", __FUNCTION__);
102 return;
103 }
104
105 /* transfer this entry to the groups container */
106 CPVRChannelGroup transferGroup(*group);
107 xbmcGroups->UpdateFromClient(transferGroup);
108}
109
110void CAddonCallbacksPVR::PVRTransferChannelGroupMember(void *addonData, const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER *member)
111{
112 if (!handle)
113 {
114 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
115 return;
116 }
117
118 CPVRClient *client = GetPVRClient(addonData);
119 CPVRChannelGroup *group = static_cast<CPVRChannelGroup *>(handle->dataAddress);
120 if (!member || !client || !group)
121 {
122 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
123 return;
124 }
125
126 CPVRChannelPtr channel = g_PVRChannelGroups->GetByUniqueID(member->iChannelUniqueId, client->GetID());
127 if (!channel)
128 {
129 CLog::Log(LOGERROR, "PVR - %s - cannot find group '%s' or channel '%d'", __FUNCTION__, member->strGroupName, member->iChannelUniqueId);
130 }
131 else if (group->IsRadio() == channel->IsRadio())
132 {
133 /* transfer this entry to the group */
134 group->AddToGroup(channel, member->iChannelNumber);
135 }
136}
137
138void CAddonCallbacksPVR::PVRTransferEpgEntry(void *addonData, const ADDON_HANDLE handle, const EPG_TAG *epgentry)
139{
140 if (!handle)
141 {
142 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
143 return;
144 }
145
146 CEpg *xbmcEpg = static_cast<CEpg *>(handle->dataAddress);
147 if (!xbmcEpg)
148 {
149 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
150 return;
151 }
152
153 /* transfer this entry to the epg */
154 xbmcEpg->UpdateEntry(epgentry, handle->dataIdentifier == 1 /* update db */);
155}
156
157void CAddonCallbacksPVR::PVRTransferChannelEntry(void *addonData, const ADDON_HANDLE handle, const PVR_CHANNEL *channel)
158{
159 if (!handle)
160 {
161 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
162 return;
163 }
164
165 CPVRClient *client = GetPVRClient(addonData);
166 CPVRChannelGroupInternal *xbmcChannels = static_cast<CPVRChannelGroupInternal *>(handle->dataAddress);
167 if (!channel || !client || !xbmcChannels)
168 {
169 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
170 return;
171 }
172
173 /* transfer this entry to the internal channels group */
174 CPVRChannelPtr transferChannel(new CPVRChannel(*channel, client->GetID()));
175 xbmcChannels->UpdateFromClient(transferChannel);
176}
177
178void CAddonCallbacksPVR::PVRTransferRecordingEntry(void *addonData, const ADDON_HANDLE handle, const PVR_RECORDING *recording)
179{
180 if (!handle)
181 {
182 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
183 return;
184 }
185
186 CPVRClient *client = GetPVRClient(addonData);
187 CPVRRecordings *xbmcRecordings = static_cast<CPVRRecordings *>(handle->dataAddress);
188 if (!recording || !client || !xbmcRecordings)
189 {
190 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
191 return;
192 }
193
194 /* transfer this entry to the recordings container */
195 CPVRRecordingPtr transferRecording(new CPVRRecording(*recording, client->GetID()));
196 xbmcRecordings->UpdateFromClient(transferRecording);
197}
198
199void CAddonCallbacksPVR::PVRTransferTimerEntry(void *addonData, const ADDON_HANDLE handle, const PVR_TIMER *timer)
200{
201 if (!handle)
202 {
203 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
204 return;
205 }
206
207 CPVRClient *client = GetPVRClient(addonData);
208 CPVRTimers *xbmcTimers = static_cast<CPVRTimers *>(handle->dataAddress);
209 if (!timer || !client || !xbmcTimers)
210 {
211 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
212 return;
213 }
214
215 CPVRChannelPtr channel = g_PVRChannelGroups->GetByUniqueID(timer->iClientChannelUid, client->GetID());
216 if (!channel)
217 {
218 CLog::Log(LOGERROR, "PVR - %s - cannot find channel %d on client %d", __FUNCTION__, timer->iClientChannelUid, client->GetID());
219 return;
220 }
221
222 /* transfer this entry to the timers container */
223 CPVRTimerInfoTag transferTimer(*timer, channel, client->GetID());
224 xbmcTimers->UpdateFromClient(transferTimer);
225}
226
227void CAddonCallbacksPVR::PVRAddMenuHook(void *addonData, PVR_MENUHOOK *hook)
228{
229 CPVRClient *client = GetPVRClient(addonData);
230 if (!hook || !client)
231 {
232 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
233 return;
234 }
235
236 PVR_MENUHOOKS *hooks = client->GetMenuHooks();
237 if (hooks)
238 {
239 PVR_MENUHOOK hookInt;
240 hookInt.iHookId = hook->iHookId;
241 hookInt.iLocalizedStringId = hook->iLocalizedStringId;
242 hookInt.category = hook->category;
243
244 /* add this new hook */
245 hooks->push_back(hookInt);
246 }
247}
248
249void CAddonCallbacksPVR::PVRRecording(void *addonData, const char *strName, const char *strFileName, bool bOnOff)
250{
251 CPVRClient *client = GetPVRClient(addonData);
252 if (!client || !strFileName)
253 {
254 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
255 return;
256 }
257
258 std::string strLine1;
259 if (bOnOff)
260 strLine1 = StringUtils::Format(g_localizeStrings.Get(19197).c_str(), client->Name().c_str());
261 else
262 strLine1 = StringUtils::Format(g_localizeStrings.Get(19198).c_str(), client->Name().c_str());
263
264 std::string strLine2;
265 if (strName)
266 strLine2 = strName;
267 else if (strFileName)
268 strLine2 = strFileName;
269
270 /* display a notification for 5 seconds */
271 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, strLine1, strLine2, 5000, false);
272
273 CLog::Log(LOGDEBUG, "PVR - %s - recording %s on client '%s'. name='%s' filename='%s'",
274 __FUNCTION__, bOnOff ? "started" : "finished", client->Name().c_str(), strName, strFileName);
275}
276
277void CAddonCallbacksPVR::PVRTriggerChannelUpdate(void *addonData)
278{
279 /* update the channels table in the next iteration of the pvrmanager's main loop */
280 g_PVRManager.TriggerChannelsUpdate();
281}
282
283void CAddonCallbacksPVR::PVRTriggerTimerUpdate(void *addonData)
284{
285 /* update the timers table in the next iteration of the pvrmanager's main loop */
286 g_PVRManager.TriggerTimersUpdate();
287}
288
289void CAddonCallbacksPVR::PVRTriggerRecordingUpdate(void *addonData)
290{
291 /* update the recordings table in the next iteration of the pvrmanager's main loop */
292 g_PVRManager.TriggerRecordingsUpdate();
293}
294
295void CAddonCallbacksPVR::PVRTriggerChannelGroupsUpdate(void *addonData)
296{
297 /* update all channel groups in the next iteration of the pvrmanager's main loop */
298 g_PVRManager.TriggerChannelGroupsUpdate();
299}
300
301void CAddonCallbacksPVR::PVRTriggerEpgUpdate(void *addonData, unsigned int iChannelUid)
302{
303 // get the client
304 CPVRClient *client = GetPVRClient(addonData);
305 if (!client)
306 {
307 CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
308 return;
309 }
310
311 g_EpgContainer.UpdateRequest(client->GetID(), iChannelUid);
312}
313
314void CAddonCallbacksPVR::PVRFreeDemuxPacket(void *addonData, DemuxPacket* pPacket)
315{
316 CDVDDemuxUtils::FreeDemuxPacket(pPacket);
317}
318
319DemuxPacket* CAddonCallbacksPVR::PVRAllocateDemuxPacket(void *addonData, int iDataSize)
320{
321 return CDVDDemuxUtils::AllocateDemuxPacket(iDataSize);
322}
323
324}; /* namespace ADDON */