2 * Copyright (C) 2011-2013 Team XBMC
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)
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.
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/>.
21 #include "HDHomeRunDirectory.h"
24 #include "utils/URIUtils.h"
25 #include "utils/StringUtils.h"
26 #include "DllHDHomeRun.h"
28 using namespace XFILE;
31 // -------------------------------------------
32 // ---------------- Directory ----------------
33 // -------------------------------------------
35 CHomeRunDirectory::CHomeRunDirectory()
37 m_pdll = new DllHdHomeRun;
41 CHomeRunDirectory::~CHomeRunDirectory()
47 bool CHomeRunDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
49 if(!m_pdll->IsLoaded())
54 if(url.GetHostName().empty())
56 // no hostname, list all available devices
58 struct hdhomerun_discover_device_t result_list[64];
59 int count = m_pdll->discover_find_devices_custom(target_ip, HDHOMERUN_DEVICE_TYPE_TUNER, HDHOMERUN_DEVICE_ID_WILDCARD, result_list, 64);
63 for(int i=0;i<count;i++)
66 unsigned int ip_addr = result_list[i].ip_addr;
68 CStdString device = StringUtils::Format("%x", result_list[i].device_id);
69 CStdString ip = StringUtils::Format("%u.%u.%u.%u",
70 (unsigned int)(ip_addr >> 24) & 0xFF, (unsigned int)(ip_addr >> 16) & 0xFF,
71 (unsigned int)(ip_addr >> 8) & 0xFF, (unsigned int)(ip_addr >> 0) & 0xFF);
73 item.reset(new CFileItem("hdhomerun://" + device + "/tuner0/", true));
74 item->SetLabel(device + "-0 On " + ip);
75 item->SetLabelPreformated(true);
78 item.reset(new CFileItem("hdhomerun://" + device + "/tuner1/", true));
79 item->SetLabel(device + "-1 On " + ip);
80 item->SetLabelPreformated(true);
87 hdhomerun_device_t* device = m_pdll->device_create_from_str(url.GetHostName().c_str(), NULL);
91 m_pdll->device_set_tuner_from_str(device, url.GetFileName().c_str());
93 hdhomerun_tuner_status_t status;
94 if(!m_pdll->device_get_tuner_status(device, NULL, &status))
96 m_pdll->device_destroy(device);
101 if(status.signal_present)
102 label = StringUtils::Format("Current Stream: N/A");
104 label = StringUtils::Format("Current Stream: Channel %s, SNR %d", status.channel, status.signal_to_noise_quality);
106 CStdString path = "hdhomerun://" + url.GetHostName() + "/" + url.GetFileName();
107 URIUtils::RemoveSlashAtEnd(path);
108 CFileItemPtr item(new CFileItem(path, false));
109 item->SetLabel(label);
110 item->SetLabelPreformated(true);
113 m_pdll->device_destroy(device);