CPPMyth
Library to interoperate with MythTV server
mythcontrol.cpp
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 #include "mythcontrol.h"
23 
24 using namespace Myth;
25 
26 Control::Control(const std::string& server, unsigned protoPort, unsigned wsapiPort, const std::string& wsapiSecurityPin)
27 : m_monitor(server, protoPort)
28 , m_wsapi(server, wsapiPort, wsapiSecurityPin)
29 {
30  Open();
31 }
32 
33 Control::Control(const std::string& server, unsigned protoPort, unsigned wsapiPort, const std::string& wsapiSecurityPin, bool frontend)
34 : m_monitor(server, protoPort, frontend)
35 , m_wsapi(server, wsapiPort, wsapiSecurityPin)
36 {
37  Open();
38 }
39 
40 Control::~Control()
41 {
42  Close();
43 }
44 
45 bool Control::Open()
46 {
47  if (m_monitor.IsOpen())
48  return true;
49  return m_monitor.Open();
50 }
51 
52 void Control::Close()
53 {
54  m_monitor.Close();
55  m_wsapi.InvalidateService();
56 }
57 
58 std::string Control::GetBackendServerIP(const std::string& hostName)
59 {
60  std::string backend_addr;
61  // Query backend server IP
62  Myth::SettingPtr settingAddr = this->GetSetting("BackendServerIP", hostName);
63  if (settingAddr && !settingAddr->value.empty())
64  backend_addr = settingAddr->value;
65  return backend_addr;
66 }
67 
68 std::string Control::GetBackendServerIP6(const std::string& hostName)
69 {
70  std::string backend_addr;
71  // Query backend server IP6
72  Myth::SettingPtr settingAddr = this->GetSetting("BackendServerIP6", hostName);
73  if (settingAddr && !settingAddr->value.empty() && settingAddr->value != "::1")
74  backend_addr = settingAddr->value;
75  return backend_addr;
76 }
77 
78 unsigned Control::GetBackendServerPort(const std::string& hostName)
79 {
80  int backend_port;
81  // Query backend server port
82  Myth::SettingPtr settingPort = this->GetSetting("BackendServerPort", hostName);
83  if (settingPort && !settingPort->value.empty() && (backend_port = Myth::StringToInt(settingPort->value)) > 0)
84  return backend_port;
85  return 0;
86 }
87 
89 {
90  program.artwork.clear();
91  if (program.inetref.empty())
92  return false;
93  ArtworkListPtr artworks(GetRecordingArtworkList(program.channel.chanId, program.recording.startTs));
94  program.artwork.reserve(artworks->size());
95  for (ArtworkList::const_iterator it = artworks->begin(); it < artworks->end(); ++it)
96  {
97  program.artwork.push_back(*(it->get()));
98  }
99  return (program.artwork.empty() ? false : true);
100 }
SettingPtr GetSetting(const std::string &key, const std::string &hostname)
Query setting by its key.
Definition: mythcontrol.h:111
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
std::string GetBackendServerIP6(const std::string &hostName)
Query backend server IP6.
Definition: mythcontrol.cpp:68
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
This is the main namespace that encloses all public classes.
Definition: mythcontrol.h:29
unsigned GetBackendServerPort(const std::string &hostName)
Query backend server port for protocol commands.
Definition: mythcontrol.cpp:78