| 106 | // This is a copy of is_input_group_busy from channelbase.cpp. |
| 107 | static bool is_input_group_busy( |
| 108 | uint inputid, |
| 109 | uint groupid, |
| 110 | const vector<uint> &excluded_cardids, |
| 111 | QMap<uint,bool> &busygrp, |
| 112 | QMap<uint,bool> &busyrec, |
| 113 | QMap<uint,TunedInputInfo> &busyin, |
| 114 | uint &mplexid_restriction) |
| 115 | { |
| 116 | // If none are busy, we don't need to check further |
| 117 | QMap<uint,bool>::const_iterator bit = busygrp.find(groupid); |
| 118 | if ((bit != busygrp.end()) && !*bit) |
| 119 | return false; |
| 120 | |
| 121 | vector<TunedInputInfo> conflicts; |
| 122 | vector<uint> cardids = CardUtil::GetGroupCardIDs(groupid); |
| 123 | for (uint i = 0; i < cardids.size(); i++) |
| 124 | { |
| 125 | if (find(excluded_cardids.begin(), |
| 126 | excluded_cardids.end(), cardids[i]) != excluded_cardids.end()) |
| 127 | { |
| 128 | continue; |
| 129 | } |
| 130 | |
| 131 | TunedInputInfo info; |
| 132 | QMap<uint,bool>::const_iterator it = busyrec.find(cardids[i]); |
| 133 | if (it == busyrec.end()) |
| 134 | { |
| 135 | busyrec[cardids[i]] = RemoteIsBusy(cardids[i], info); |
| 136 | it = busyrec.find(cardids[i]); |
| 137 | if (*it) |
| 138 | busyin[cardids[i]] = info; |
| 139 | } |
| 140 | |
| 141 | if (*it) |
| 142 | conflicts.push_back(busyin[cardids[i]]); |
| 143 | } |
| 144 | |
| 145 | // If none are busy, we don't need to check further |
| 146 | busygrp[groupid] = !conflicts.empty(); |
| 147 | if (conflicts.empty()) |
| 148 | return false; |
| 149 | |
| 150 | InputInfo in; |
| 151 | in.inputid = inputid; |
| 152 | if (!CardUtil::GetInputInfo(in)) |
| 153 | return true; |
| 154 | |
| 155 | // If they aren't using the same source they are definately busy |
| 156 | bool is_busy_input = false; |
| 157 | |
| 158 | for (uint i = 0; i < conflicts.size() && !is_busy_input; i++) |
| 159 | is_busy_input = (in.sourceid != conflicts[i].sourceid); |
| 160 | |
| 161 | if (is_busy_input) |
| 162 | return true; |
| 163 | |
| 164 | // If the source's channels aren't digitally tuned then there is a conflict |
| 165 | is_busy_input = !SourceUtil::HasDigitalChannel(in.sourceid); |
| 166 | if (!is_busy_input && conflicts[0].chanid) |
| 167 | { |
| 168 | MSqlQuery query(MSqlQuery::InitCon()); |
| 169 | query.prepare( |
| 170 | "SELECT mplexid " |
| 171 | "FROM channel " |
| 172 | "WHERE chanid = :CHANID"); |
| 173 | query.bindValue(":CHANID", conflicts[0].chanid); |
| 174 | if (!query.exec()) |
| 175 | MythContext::DBError("is_input_group_busy", query); |
| 176 | else if (query.next()) |
| 177 | { |
| 178 | mplexid_restriction = query.value(0).toUInt(); |
| 179 | mplexid_restriction = (32767 == mplexid_restriction) ? |
| 180 | 0 : mplexid_restriction; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | return is_busy_input; |
| 185 | } |
| 186 | |
| 187 | // This is a copy of is_input_busy from channelbase.cpp. |
| 188 | static bool is_input_busy( |
| 189 | uint inputid, |
| 190 | const vector<uint> &groupids, |
| 191 | const vector<uint> &excluded_cardids, |
| 192 | QMap<uint,bool> &busygrp, |
| 193 | QMap<uint,bool> &busyrec, |
| 194 | QMap<uint,TunedInputInfo> &busyin, |
| 195 | uint &mplexid_restriction) |
| 196 | { |
| 197 | bool is_busy = false; |
| 198 | for (uint i = 0; i < groupids.size() && !is_busy; i++) |
| 199 | { |
| 200 | is_busy |= is_input_group_busy( |
| 201 | inputid, groupids[i], excluded_cardids, |
| 202 | busygrp, busyrec, busyin, mplexid_restriction); |
| 203 | } |
| 204 | return is_busy; |
| 205 | } |
| 206 | |
| 207 | static bool is_input_in_busy_group(uint inputid) |
| 208 | { |
| 209 | vector<uint> groupids = CardUtil::GetInputGroups(inputid); |
| 210 | vector<uint> excluded_cardids; |
| 211 | excluded_cardids.push_back(CardUtil::GetCardID(inputid)); |
| 212 | QMap<uint,bool> busygrp; |
| 213 | QMap<uint,bool> busyrec; |
| 214 | QMap<uint,TunedInputInfo> busyin; |
| 215 | uint mplexid_restriction = 0; |
| 216 | return is_input_busy(inputid, groupids, excluded_cardids, |
| 217 | busygrp, busyrec, busyin, mplexid_restriction); |
| 218 | } |
| 219 | |
| 220 | static bool is_card_in_busy_group(uint cardid) |
| 221 | { |
| 222 | vector<uint> inputids = CardUtil::GetInputIDs(cardid); |
| 223 | for (uint i = 0; i < inputids.size(); i++) |
| 224 | { |
| 225 | if (is_input_in_busy_group(inputids[i])) |
| 226 | return true; |
| 227 | } |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | |