CPPMyth
Library to interoperate with MythTV server
mythcontrol.h
1 /*
2  * Copyright (C) 2014 Jean-Luc Barriere
3  *
4  * This Program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This Program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; see the file COPYING. If not, write to
16  * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  * http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21 
22 #ifndef MYTHCONTROL_H
23 #define MYTHCONTROL_H
24 
25 #include "proto/mythprotomonitor.h"
26 #include "mythtypes.h"
27 #include "mythwsapi.h"
28 
29 namespace Myth
30 {
31 
32  class Control
33  {
34  public:
35  Control(const std::string& server, unsigned protoPort, unsigned wsapiPort, const std::string& wsapiSecurityPin);
36  Control(const std::string& server, unsigned protoPort, unsigned wsapiPort, const std::string& wsapiSecurityPin, bool frontend);
37  ~Control();
38 
39  bool Open();
40  void Close();
41  bool IsOpen() { return m_monitor.IsOpen(); }
42  bool HasHanging() const { return m_monitor.HasHanging(); }
43  void CleanHanging() { m_monitor.CleanHanging(); }
44  ProtoBase::ERROR_t GetProtoError() const { return m_monitor.GetProtoError(); }
45 
50  unsigned CheckService()
51  {
52  return m_wsapi.CheckService();
53  }
54 
59  std::string GetServerHostName()
60  {
61  return m_wsapi.GetServerHostName();
62  }
63 
68  VersionPtr GetVersion()
69  {
70  return m_wsapi.GetVersion();
71  }
72 
79  bool QueryFreeSpaceSummary(int64_t *total, int64_t *used)
80  {
81  return m_monitor.QueryFreeSpaceSummary(total, used);
82  }
83 
89  bool QueryGenPixmap(const Program& program)
90  {
91  return m_monitor.QueryGenpixmap(program);
92  }
93 
100  bool CancelNextRecording(int rnum, bool cancel)
101  {
102  return m_monitor.CancelNextRecording(rnum, cancel);
103  }
104 
111  SettingPtr GetSetting(const std::string& key, const std::string& hostname)
112  {
113  return m_wsapi.GetSetting(key, hostname);
114  }
115 
122  SettingPtr GetSetting(const std::string& key, bool myhost)
123  {
124  return m_wsapi.GetSetting(key, myhost);
125  }
126 
132  SettingMapPtr GetSettings(const std::string& hostname)
133  {
134  return m_wsapi.GetSettings(hostname);
135  }
136 
142  SettingMapPtr GetSettings(bool myhost)
143  {
144  return m_wsapi.GetSettings(myhost);
145  }
146 
154  bool PutSetting(const std::string& key, const std::string& value, bool myhost)
155  {
156  return m_wsapi.PutSetting(key, value, myhost);
157  }
158 
164  std::string GetBackendServerIP(const std::string& hostName);
165 
171  std::string GetBackendServerIP6(const std::string& hostName);
172 
178  unsigned GetBackendServerPort(const std::string& hostName);
179 
186  ProgramListPtr GetRecordedList(unsigned n = 0, bool descending = false)
187  {
188  return m_wsapi.GetRecordedList(n, descending);
189  }
190 
197  ProgramPtr GetRecorded(uint32_t chanid, time_t recstartts)
198  {
199  return m_wsapi.GetRecorded(chanid, recstartts);
200  }
201 
207  ProgramPtr GetRecorded(uint32_t recordedid)
208  {
209  return m_wsapi.GetRecorded(recordedid);
210  }
211 
218  bool UpdateRecordedWatchedStatus(const Program& program, bool watched)
219  {
220  WSServiceVersion_t wsv = m_wsapi.CheckService(WS_Dvr);
221  if (wsv.ranking >= 0x00060000)
222  return m_wsapi.UpdateRecordedWatchedStatus(program.recording.recordedId, watched);
223  return m_wsapi.UpdateRecordedWatchedStatus(program.channel.chanId, program.recording.startTs, watched);
224  }
225 
233  bool DeleteRecording(const Program& program, bool forceDelete = false, bool allowRerecord = false)
234  {
235  WSServiceVersion_t wsv = m_wsapi.CheckService(WS_Dvr);
236  if (wsv.ranking >= 0x00060000)
237  return m_wsapi.DeleteRecording(program.recording.recordedId, forceDelete, allowRerecord);
238  if (wsv.ranking >= 0x00020001)
239  return m_wsapi.DeleteRecording(program.channel.chanId, program.recording.startTs, forceDelete, allowRerecord);
240  return m_monitor.DeleteRecording(program, forceDelete, allowRerecord);
241  }
242 
243  bool UndeleteRecording(const Program& program)
244  {
245  WSServiceVersion_t wsv = m_wsapi.CheckService(WS_Dvr);
246  if (wsv.ranking >= 0x00060000)
247  return m_wsapi.UnDeleteRecording(program.recording.recordedId);
248  if (wsv.ranking >= 0x00020001)
249  return m_wsapi.UnDeleteRecording(program.channel.chanId, program.recording.startTs);
250  return m_monitor.UndeleteRecording(program);
251  }
252 
253  bool StopRecording(const Program& program)
254  {
255  return m_monitor.StopRecording(program);
256  }
257 
262  CaptureCardListPtr GetCaptureCardList()
263  {
264  return m_wsapi.GetCaptureCardList();
265  }
266 
271  VideoSourceListPtr GetVideoSourceList()
272  {
273  return m_wsapi.GetVideoSourceList();
274  }
275 
282  ChannelListPtr GetChannelList(uint32_t sourceid, bool onlyVisible = true)
283  {
284  return m_wsapi.GetChannelList(sourceid, onlyVisible);
285  }
286 
292  ChannelPtr GetChannel(uint32_t chanid)
293  {
294  return m_wsapi.GetChannel(chanid);
295  }
296 
304  ProgramMapPtr GetProgramGuide(uint32_t chanid, time_t starttime, time_t endtime)
305  {
306  return m_wsapi.GetProgramGuide(chanid, starttime, endtime);
307  }
308 
315  std::map<uint32_t, ProgramMapPtr> GetProgramGuide(time_t starttime, time_t endtime)
316  {
317  return m_wsapi.GetProgramGuide(starttime, endtime);
318  }
319 
324  RecordScheduleListPtr GetRecordScheduleList()
325  {
326  return m_wsapi.GetRecordScheduleList();
327  }
328 
334  RecordSchedulePtr GetRecordSchedule(uint32_t recordid)
335  {
336  return m_wsapi.GetRecordSchedule(recordid);
337  }
338 
345  {
346  return m_wsapi.AddRecordSchedule(record);
347  }
348 
355  {
356  return m_wsapi.UpdateRecordSchedule(record);
357  }
358 
364  bool DisableRecordSchedule(uint32_t recordid)
365  {
366  return m_wsapi.DisableRecordSchedule(recordid);
367  }
368 
374  bool EnableRecordSchedule(uint32_t recordid)
375  {
376  return m_wsapi.EnableRecordSchedule(recordid);
377  }
378 
384  bool RemoveRecordSchedule(uint32_t recordid)
385  {
386  return m_wsapi.RemoveRecordSchedule(recordid);
387  }
388 
393  ProgramListPtr GetUpcomingList()
394  {
395  return m_wsapi.GetUpcomingList();
396  }
397 
402  ProgramListPtr GetConflictList()
403  {
404  return m_wsapi.GetConflictList();
405  }
406 
411  ProgramListPtr GetExpiringList()
412  {
413  return m_wsapi.GetExpiringList();
414  }
415 
420  StringListPtr GetRecGroupList()
421  {
422  return m_wsapi.GetRecGroupList();
423  }
424 
431  WSStreamPtr GetFile(const std::string& filename, const std::string& sgname)
432  {
433  return m_wsapi.GetFile(filename, sgname);
434  }
435 
443  WSStreamPtr GetChannelIcon(uint32_t chanid, unsigned width = 0, unsigned height = 0)
444  {
445  return m_wsapi.GetChannelIcon(chanid, width, height);
446  }
447 
455  std::string GetChannelIconUrl(uint32_t chanid, unsigned width = 0, unsigned height = 0)
456  {
457  return m_wsapi.GetChannelIconUrl(chanid, width, height);
458  }
459 
467  WSStreamPtr GetPreviewImage(const Program& program, unsigned width = 0, unsigned height = 0)
468  {
469  return m_wsapi.GetPreviewImage(program.channel.chanId, program.recording.startTs, width, height);
470  }
471 
479  std::string GetPreviewImageUrl(const Program& program, unsigned width = 0, unsigned height = 0)
480  {
481  return m_wsapi.GetPreviewImageUrl(program.channel.chanId, program.recording.startTs, width, height);
482  }
483 
492  WSStreamPtr GetRecordingArtwork(const std::string& type, const Program& program, unsigned width = 0, unsigned height = 0)
493  {
494  return m_wsapi.GetRecordingArtwork(type, program.inetref, program.season, width, height);
495  }
496 
505  std::string GetRecordingArtworkUrl(const std::string& type, const Program& program, unsigned width = 0, unsigned height = 0)
506  {
507  return m_wsapi.GetRecordingArtworkUrl(type, program.inetref, program.season, width, height);
508  }
509 
516  ArtworkListPtr GetRecordingArtworkList(uint32_t chanid, time_t recstartts)
517  {
518  return m_wsapi.GetRecordingArtworkList(chanid, recstartts);
519  }
520 
526  bool RefreshRecordedArtwork(Program& program);
527 
534  MarkListPtr GetCutList(const Program& program, int unit = 0)
535  {
536  WSServiceVersion_t wsv = m_wsapi.CheckService(WS_Dvr);
537  if (wsv.ranking >= 0x00060001)
538  return m_wsapi.GetRecordedCutList(program.recording.recordedId, unit);
539  if (unit == 0)
540  return m_monitor.GetCutList(program);
541  else
542  return MarkListPtr(new MarkList);
543  }
544 
551  MarkListPtr GetCommBreakList(const Program& program, int unit = 0)
552  {
553  WSServiceVersion_t wsv = m_wsapi.CheckService(WS_Dvr);
554  if (wsv.ranking >= 0x00060001)
555  return m_wsapi.GetRecordedCommBreak(program.recording.recordedId, unit);
556  if (unit == 0)
557  return m_monitor.GetCommBreakList(program);
558  else
559  return MarkListPtr(new MarkList);
560  }
561 
567  {
568  return m_monitor.BlockShutdown();
569  }
570 
576  {
577  return m_monitor.AllowShutdown();
578  }
579 
586  bool SetSavedBookmark(const Program& program, int unit, int64_t value)
587  {
588  return m_wsapi.SetSavedBookmark(program.recording.recordedId, unit, value);
589  }
590 
597  int64_t GetSavedBookmark(const Program& program, int unit)
598  {
599  return m_wsapi.GetSavedBookmark(program.recording.recordedId, unit);
600  }
601 
602  private:
603  ProtoMonitor m_monitor;
604  WSAPI m_wsapi;
605 
606  };
607 
608 }
609 
610 #endif /* MYTHCONTROL_H */
bool CancelNextRecording(int rnum, bool cancel)
Ask the backend to cancel/continue next recording.
Definition: mythcontrol.h:100
ProgramMapPtr GetProgramGuide(uint32_t chanid, time_t starttime, time_t endtime)
Query the guide information for a particular time period and a channel.
Definition: mythcontrol.h:304
ChannelPtr GetChannel(uint32_t chanid)
GET Channel/GetChannelInfo.
Definition: mythwsapi.h:146
WSStreamPtr GetPreviewImage(uint32_t chanid, time_t recstartts, unsigned width=0, unsigned height=0)
GET Content/GetPreviewImage.
Definition: mythwsapi.h:410
bool AddRecordSchedule(RecordSchedule &record)
POST Dvr/AddRecordSchedule.
Definition: mythwsapi.h:288
bool AllowShutdown()
Allows backend to shut down again after a previous call to BlockShutdown().
Definition: mythcontrol.h:575
SettingMapPtr GetSettings(const std::string &hostname)
GET Myth/GetSetting.
Definition: mythwsapi.h:89
CaptureCardListPtr GetCaptureCardList()
GET Capture/GetCaptureCardList.
Definition: mythwsapi.h:115
bool UpdateRecordSchedule(RecordSchedule &record)
Update a recording rule.
Definition: mythcontrol.h:354
std::string GetChannelIconUrl(uint32_t chanid, unsigned width=0, unsigned height=0)
Returns URL for channel icon.
Definition: mythwsapi.h:400
SettingPtr GetSetting(const std::string &key, bool myhost)
Query setting by its key.
Definition: mythcontrol.h:122
ProgramListPtr GetConflictList()
GET Dvr/GetConflictList.
Definition: mythwsapi.h:350
MarkListPtr GetCommBreakList(const Program &program, int unit=0)
Request a set of commercial break marks for a recording.
Definition: mythcontrol.h:551
WSStreamPtr GetPreviewImage(const Program &program, unsigned width=0, unsigned height=0)
Get, and optionally scale, an preview thumbnail for a given recording by timestamp, chanid and starttime.
Definition: mythcontrol.h:467
RecordSchedulePtr GetRecordSchedule(uint32_t recordid)
Get a single recording rule, by record id.
Definition: mythcontrol.h:334
bool RemoveRecordSchedule(uint32_t recordid)
Remove a recording rule.
Definition: mythcontrol.h:384
ChannelListPtr GetChannelList(uint32_t sourceid, bool onlyVisible=true)
GET Channel/GetChannelInfoList.
Definition: mythwsapi.h:135
ProgramListPtr GetRecordedList(unsigned n=0, bool descending=false)
Query information on all recorded programs.
Definition: mythcontrol.h:186
bool QueryFreeSpaceSummary(int64_t *total, int64_t *used)
Queries the backend for free space summary.
Definition: mythcontrol.h:79
std::string GetServerHostName()
Query server host name.
Definition: mythcontrol.h:59
CaptureCardListPtr GetCaptureCardList()
Get all configured capture devices.
Definition: mythcontrol.h:262
ChannelPtr GetChannel(uint32_t chanid)
Retrieve a single channel, by channel id.
Definition: mythcontrol.h:292
std::map< uint32_t, ProgramMapPtr > GetProgramGuide(time_t starttime, time_t endtime)
Query the guide information for a particular time period.
Definition: mythcontrol.h:315
StringListPtr GetRecGroupList()
Get list of recording group.
Definition: mythcontrol.h:420
ProgramPtr GetRecorded(uint32_t chanid, time_t recstartts)
Query information on a single item from recordings.
Definition: mythcontrol.h:197
ProgramListPtr GetExpiringList()
GET Dvr/GetExpiringList.
Definition: mythwsapi.h:360
StringListPtr GetRecGroupList()
GET Dvr/GetRecGroupList.
Definition: mythwsapi.h:370
bool DeleteRecording(const Program &program, bool forceDelete=false, bool allowRerecord=false)
Remove a Recording from the database and disk.
Definition: mythcontrol.h:233
WSStreamPtr GetRecordingArtwork(const std::string &type, const std::string &inetref, uint16_t season, unsigned width=0, unsigned height=0)
GET Content/GetRecordingArtwork.
Definition: mythwsapi.h:430
ProgramListPtr GetConflictList()
Query information on upcoming items which will not record due to conflicts.
Definition: mythcontrol.h:402
RecordScheduleListPtr GetRecordScheduleList()
Query all configured recording rules.
Definition: mythcontrol.h:324
bool DisableRecordSchedule(uint32_t recordid)
POST Dvr/DisableRecordSchedule.
Definition: mythwsapi.h:309
std::string GetRecordingArtworkUrl(const std::string &type, const std::string &inetref, uint16_t season, unsigned width=0, unsigned height=0)
Returns URL for recording artwork.
Definition: mythwsapi.h:440
SettingPtr GetSetting(const std::string &key, const std::string &hostname)
Query setting by its key.
Definition: mythcontrol.h:111
ProgramListPtr GetRecordedList(unsigned n=0, bool descending=false)
GET Dvr/GetRecordedList.
Definition: mythwsapi.h:178
RecordSchedulePtr GetRecordSchedule(uint32_t recordid)
GET Dvr/GetRecordSchedule.
Definition: mythwsapi.h:278
bool RefreshRecordedArtwork(Program &program)
Refresh artwork available for a recording.
Definition: mythcontrol.cpp:88
std::string GetBackendServerIP(const std::string &hostName)
Query backend server IP.
Definition: mythcontrol.cpp:58
bool AddRecordSchedule(RecordSchedule &record)
Add a new recording rule.
Definition: mythcontrol.h:344
bool UpdateRecordedWatchedStatus(uint32_t chanid, time_t recstartts, bool watched)
POST Dvr/UpdateRecordedWatchedStatus.
Definition: mythwsapi.h:208
ProgramListPtr GetExpiringList()
Query information on recorded programs which are set to expire.
Definition: mythcontrol.h:411
bool QueryGenPixmap(const Program &program)
Triggers preview image generation on the backend for a specified show.
Definition: mythcontrol.h:89
std::string GetPreviewImageUrl(uint32_t chanid, time_t recstartts, unsigned width=0, unsigned height=0)
Returns URL for preview image.
Definition: mythwsapi.h:420
bool SetSavedBookmark(const Program &program, int unit, int64_t value)
Set saved bookmark for a program.
Definition: mythcontrol.h:586
MarkListPtr GetRecordedCommBreak(uint32_t recordedid, int unit)
GET Dvr/GetRecordedCommBreak.
Definition: mythwsapi.h:463
VersionPtr GetVersion()
Query server version infos.
Definition: mythcontrol.h:68
VideoSourceListPtr GetVideoSourceList()
GET Channel/GetVideoSourceList.
Definition: mythwsapi.h:125
std::string GetRecordingArtworkUrl(const std::string &type, const Program &program, unsigned width=0, unsigned height=0)
Get an image URL of a given type (coverart, banner, fanart) for a given recording&#39;s inetref and seaso...
Definition: mythcontrol.h:505
ProgramPtr GetRecorded(uint32_t recordedid)
Query information on a single item from recordings.
Definition: mythcontrol.h:207
bool PutSetting(const std::string &key, const std::string &value, bool myhost)
Put setting.
Definition: mythcontrol.h:154
SettingMapPtr GetSettings(const std::string &hostname)
Query all settings.
Definition: mythcontrol.h:132
WSStreamPtr GetFile(const std::string &filename, const std::string &sgname)
Download a given file from a given storage group.
Definition: mythcontrol.h:431
MarkListPtr GetCutList(const Program &program, int unit=0)
Request a set of cut list marks for a recording.
Definition: mythcontrol.h:534
std::string GetBackendServerIP6(const std::string &hostName)
Query backend server IP6.
Definition: mythcontrol.cpp:68
WSStreamPtr GetChannelIcon(uint32_t chanid, unsigned width=0, unsigned height=0)
GET Guide/GetChannelIcon.
Definition: mythwsapi.h:390
ProgramListPtr GetUpcomingList()
Query information on all upcoming programs matching recording rules.
Definition: mythcontrol.h:393
RecordScheduleListPtr GetRecordScheduleList()
GET Dvr/GetRecordScheduleList.
Definition: mythwsapi.h:268
WSStreamPtr GetFile(const std::string &filename, const std::string &sgname)
GET Content/GetFile.
Definition: mythwsapi.h:380
std::string GetChannelIconUrl(uint32_t chanid, unsigned width=0, unsigned height=0)
Get URL of icon for a given channel.
Definition: mythcontrol.h:455
ProgramPtr GetRecorded(uint32_t chanid, time_t recstartts)
GET Dvr/GetRecorded.
Definition: mythwsapi.h:188
WSStreamPtr GetRecordingArtwork(const std::string &type, const Program &program, unsigned width=0, unsigned height=0)
Get, and optionally scale, an image file of a given type (coverart, banner, fanart) for a given recor...
Definition: mythcontrol.h:492
ArtworkListPtr GetRecordingArtworkList(uint32_t chanid, time_t recstartts)
Get a list of artwork available for a recording by start time and channel id.
Definition: mythcontrol.h:516
ArtworkListPtr GetRecordingArtworkList(uint32_t chanid, time_t recstartts)
GET Content/GetRecordingArtworkList.
Definition: mythwsapi.h:450
bool EnableRecordSchedule(uint32_t recordid)
POST Dvr/EnableRecordSchedule.
Definition: mythwsapi.h:319
unsigned CheckService()
Check availability of API services.
Definition: mythcontrol.h:50
int64_t GetSavedBookmark(const Program &program, int unit)
Retrieve saved bookmark for a program.
Definition: mythcontrol.h:597
bool UpdateRecordSchedule(RecordSchedule &record)
POST Dvr/UpdateRecordSchedule.
Definition: mythwsapi.h:299
This is the main namespace that encloses all public classes.
Definition: mythcontrol.h:29
WSStreamPtr GetChannelIcon(uint32_t chanid, unsigned width=0, unsigned height=0)
Get the icon file for a given channel.
Definition: mythcontrol.h:443
bool BlockShutdown()
Prevents backend from shutting down until a the next call to AllowShutdown().
Definition: mythcontrol.h:566
unsigned GetBackendServerPort(const std::string &hostName)
Query backend server port for protocol commands.
Definition: mythcontrol.cpp:78
ChannelListPtr GetChannelList(uint32_t sourceid, bool onlyVisible=true)
Get all configured channels for a video source.
Definition: mythcontrol.h:282
bool SetSavedBookmark(uint32_t recordedid, int unit, int64_t value)
POST Dvr/SetSavedBookmark.
Definition: mythwsapi.h:490
bool RemoveRecordSchedule(uint32_t recordid)
POST Dvr/RemoveRecordSchedule.
Definition: mythwsapi.h:329
MarkListPtr GetRecordedCutList(uint32_t recordedid, int unit)
GET Dvr/GetRecordedCutList.
Definition: mythwsapi.h:476
bool DeleteRecording(uint32_t chanid, time_t recstartts, bool forceDelete=false, bool allowRerecord=false)
POST Dvr/DeleteRecording.
Definition: mythwsapi.h:228
VideoSourceListPtr GetVideoSourceList()
Get all video sources.
Definition: mythcontrol.h:271
int64_t GetSavedBookmark(uint32_t recordedid, int unit)
GET Dvr/GetSavedBookmark.
Definition: mythwsapi.h:504
ProgramListPtr GetUpcomingList()
GET Dvr/GetUpcomingList.
Definition: mythwsapi.h:339
bool DisableRecordSchedule(uint32_t recordid)
Disable a recording rule.
Definition: mythcontrol.h:364
ProgramMapPtr GetProgramGuide(uint32_t chanid, time_t starttime, time_t endtime)
GET Guide/GetProgramGuide for the given channel.
Definition: mythwsapi.h:156
bool EnableRecordSchedule(uint32_t recordid)
Enable a recording rule.
Definition: mythcontrol.h:374
bool UpdateRecordedWatchedStatus(const Program &program, bool watched)
Update watched status for a recorded.
Definition: mythcontrol.h:218
SettingPtr GetSetting(const std::string &key, const std::string &hostname)
GET Myth/GetSetting.
Definition: mythwsapi.h:73
bool UnDeleteRecording(uint32_t chanid, time_t recstartts)
POST Dvr/UnDeleteRecording.
Definition: mythwsapi.h:248
bool PutSetting(const std::string &key, const std::string &value, bool myhost)
POST Myth/PutSetting.
Definition: mythwsapi.h:105
std::string GetPreviewImageUrl(const Program &program, unsigned width=0, unsigned height=0)
Get URL of preview thumbnail for a given recording by timestamp, chanid and starttime.
Definition: mythcontrol.h:479
SettingMapPtr GetSettings(bool myhost)
Query all settings.
Definition: mythcontrol.h:142