| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 10 | * included LICENSE.LGPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #include <climits> | ||
| 18 | #include <ctime> | ||
| 19 | #include <list> | ||
| 20 | #include <map> | ||
| 21 | #include <memory> | ||
| 22 | #include <mutex> | ||
| 23 | #include <stdio.h> | ||
| 24 | #include <stdlib.h> | ||
| 25 | #include <string.h> | ||
| 26 | #include <string> | ||
| 27 | #include <thread> | ||
| 28 | #include <chrono> | ||
| 29 | #include <condition_variable> | ||
| 30 | #include <time.h> | ||
| 31 | #include <utility> | ||
| 32 | #include <vector> | ||
| 33 | |||
| 34 | #include "Player.h" | ||
| 35 | #include "Warnings.h" | ||
| 36 | #include "common.h" | ||
| 37 | #include "log.h" | ||
| 38 | #include "settings.h" | ||
| 39 | #include "commands/Commands.h" | ||
| 40 | #include "mediaoutput/mediaoutput.h" | ||
| 41 | #include "playlist/Playlist.h" | ||
| 42 | |||
| 43 | #include "Scheduler.h" | ||
| 44 | |||
| 45 | Scheduler* scheduler = NULL; | ||
| 46 | |||
| 47 | ///////////////////////////////////////////////////////////////////////////// | ||
| 48 | |||
| 49 | // Test assumptions | ||
| 50 | static_assert(std::is_move_constructible_v<ScheduledItem>); | ||
| 51 | |||
| 52 | // Warning 23 is removed by an exact match on its text, so every site that adds | ||
| 53 | // or removes it for an entry has to produce the identical string. | ||
| 54 | // strftime() into a fixed buffer. The time and date formats come from | ||
| 55 | // settings; when a result doesn't fit, strftime() returns 0 and leaves the | ||
| 56 | // buffer's contents undefined, and the callers then read an unterminated | ||
| 57 | // string. Leave it empty instead. | ||
| 58 | 192840 | static void FormatTime(char* buf, size_t size, const char* fmt, const struct tm* t) { | |
| 59 |
2/2✓ Branch 0 taken 63 times.
✓ Branch 1 taken 192777 times.
|
192840 | if (strftime(buf, size, fmt, t) == 0) |
| 60 | 63 | buf[0] = '\0'; | |
| 61 | 192840 | } | |
| 62 | |||
| 63 | 834 | static std::string missingEntryWarning(const ScheduleEntry& entry) { | |
| 64 |
2/6✓ Branch 0 taken 834 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 834 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2502 | return std::string("Scheduled ") + (entry.sequence ? "Sequence" : "Playlist") + |
| 65 |
5/8✓ Branch 0 taken 3 times.
✓ Branch 1 taken 831 times.
✓ Branch 2 taken 834 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 834 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 834 times.
✗ Branch 7 not taken.
|
2502 | " '" + entry.playlist + "' does not exist"; |
| 66 | } | ||
| 67 | |||
| 68 | ///////////////////////////////////////////////////////////////////////////// | ||
| 69 | |||
| 70 | // A schedule entry's args are stored as given, and the command layer accepts | ||
| 71 | // objects and arrays among them (an If command's condition), so asString() | ||
| 72 | // and operator[] can't be used on them blindly: either throws LogicError, and | ||
| 73 | // on the main loop nothing catches it - fppd aborted at every countdown to | ||
| 74 | // such an entry. | ||
| 75 | 2606 | static std::string ScheduleArgToString(const Json::Value& v) { | |
| 76 |
5/6✓ Branch 0 taken 2594 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2594 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 2594 times.
|
2606 | if (v.isObject() || v.isArray()) { |
| 77 |
2/4✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
24 | return SaveJsonToString(v); |
| 78 | } | ||
| 79 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2594 times.
|
2594 | if (v.isNull()) { |
| 80 | ✗ | return ""; | |
| 81 | } | ||
| 82 | 2594 | return v.asString(); | |
| 83 | } | ||
| 84 | |||
| 85 | // Whether two items carry the same first argument (how a ran item is matched). | ||
| 86 | 39 | static bool SameFirstScheduleArg(const Json::Value& a, const Json::Value& b) { | |
| 87 |
3/6✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 39 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 39 times.
|
39 | if (!a.isArray() || !b.isArray()) { |
| 88 | ✗ | return a == b; | |
| 89 | } | ||
| 90 |
3/6✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 39 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 39 times.
|
39 | if (a.empty() || b.empty()) { |
| 91 | ✗ | return a.empty() && b.empty(); | |
| 92 | } | ||
| 93 | 39 | return a[0] == b[0]; | |
| 94 | } | ||
| 95 | |||
| 96 | 2652 | Scheduler::Scheduler() : | |
| 97 | 2652 | m_schedulerDisabled(false), | |
| 98 | 2652 | m_loadSchedule(true), | |
| 99 | 2652 | m_lastLoadDate(0), | |
| 100 | 2652 | m_lastProcTime(0), | |
| 101 | 2652 | m_lastCommandCheckTime(0), | |
| 102 | 2652 | m_timeDelta(0), | |
| 103 | 2652 | m_timeDeltaThreshold(0), | |
| 104 | 2652 | m_forcedNextPlaylist(SCHEDULE_INDEX_INVALID), | |
| 105 | 2652 | m_lastBlockedTime(0), | |
| 106 | 2652 | m_schedulesExtendBeyondDistance(false) { | |
| 107 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | RegisterCommands(); |
| 108 | |||
| 109 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | m_schedulerDisabled = getSettingInt("DisableScheduler") == 1; |
| 110 | |||
| 111 |
7/8✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2640 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 11 times.
✓ Branch 7 taken 2641 times.
|
2652 | if ((m_schedulerDisabled) && (getFPPmode() == PLAYER_MODE)) { |
| 112 |
2/4✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
33 | WarningHolder::AddWarning(19, "FPP Scheduler is disabled"); |
| 113 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | LogWarn(VB_SCHEDULE, "Scheduler is disabled!\n"); |
| 114 | } | ||
| 115 | |||
| 116 | 2652 | m_lastProcTime = time(NULL); | |
| 117 | // Seed the FPP-command catch-up window to now rather than leaving it at the | ||
| 118 | // epoch. CheckScheduledItems() fires any command whose second falls in | ||
| 119 | // (m_lastCommandCheckTime, now], which exists so a second this process | ||
| 120 | // MISSED -- a slow midnight reload, an NTP step -- still runs. A second | ||
| 121 | // that passed before this process existed was never missed by it, and the | ||
| 122 | // 60s catch-up cap is not a substitute: from 0 every start would replay the | ||
| 123 | // preceding minute of commands, so a scheduled "Outputs Off" or a restart | ||
| 124 | // would run a second time on every restart, and repeatedly in a restart | ||
| 125 | // loop. | ||
| 126 | 2652 | m_lastCommandCheckTime = m_lastProcTime; | |
| 127 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | LoadScheduleFromFile(); |
| 128 | |||
| 129 | // Sun-relative times and the coordinates warning come from these, and | ||
| 130 | // are only worked out when the schedule is loaded. | ||
| 131 |
2/2✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 2652 times.
|
7956 | for (const char* s : { "Latitude", "Longitude" }) { |
| 132 |
3/6✓ Branch 0 taken 5304 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5304 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5304 times.
✗ Branch 5 not taken.
|
25930 | registerSettingsListener("Scheduler", s, [this](const std::string&) { |
| 133 | 2 | ReloadScheduleFile(); | |
| 134 | 2 | }); | |
| 135 | } | ||
| 136 | 2652 | } | |
| 137 | |||
| 138 | 2620 | Scheduler::~Scheduler() { | |
| 139 | 10480 | unregisterSettingsListener("Scheduler", "Latitude"); | |
| 140 | 7860 | unregisterSettingsListener("Scheduler", "Longitude"); | |
| 141 | 2620 | } | |
| 142 | |||
| 143 | 592789 | void Scheduler::ScheduleProc(void) { | |
| 144 | 592789 | time_t procTime = time(NULL); | |
| 145 | |||
| 146 | // Only check schedule once per second at most | ||
| 147 |
2/2✓ Branch 0 taken 579969 times.
✓ Branch 1 taken 12820 times.
|
592789 | if (m_lastProcTime == procTime) |
| 148 | 579969 | return; | |
| 149 | |||
| 150 | 12820 | int timeDelta = (int)(procTime - m_lastProcTime); | |
| 151 | 12820 | m_lastProcTime = procTime; | |
| 152 | |||
| 153 | // reload the schedule file once per day or if 5 seconds has elapsed | ||
| 154 | // since the last process time in case the time jumps | ||
| 155 |
4/6✓ Branch 0 taken 12820 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12820 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 50 times.
✓ Branch 5 taken 12770 times.
|
25640 | if ((m_lastLoadDate != GetCurrentDateInt()) || |
| 156 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12770 times.
|
12820 | (abs(timeDelta) > 5)) { |
| 157 | 50 | m_loadSchedule = true; | |
| 158 | |||
| 159 | // Cleanup any ran items older than 2 days. SetItemRan mutates m_ranItems | ||
| 160 | // under m_scheduleLock from HTTP/MQTT/detached command threads, so this | ||
| 161 | // prune has to hold the lock too. | ||
| 162 | 50 | const time_t twoDaysAgo = time(NULL) - (2 * 24 * 60 * 60); | |
| 163 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
50 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 164 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 49 times.
|
50 | for (auto it = m_ranItems.begin(); it != m_ranItems.end(); /* in loop */) { |
| 165 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (it->first >= twoDaysAgo) |
| 166 | 1 | break; | |
| 167 | ✗ | it = m_ranItems.erase(it); | |
| 168 | } | ||
| 169 | |||
| 170 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 27 times.
|
50 | if (timeDelta < -SCHEDULE_COMMAND_CATCHUP_S) { |
| 171 | // The clock stepped back (an RTC that was ahead, corrected by | ||
| 172 | // NTP). Whatever "ran" at the wrong, later time hasn't really run | ||
| 173 | // yet: forget it so the reload below schedules it again, and pull | ||
| 174 | // the command check window back so commands in the stepped-over | ||
| 175 | // span fire when their second actually comes instead of being | ||
| 176 | // treated as already examined. | ||
| 177 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | LogWarn(VB_SCHEDULE, "Clock stepped back %d seconds; re-arming schedule items after now\n", -timeDelta); |
| 178 |
2/4✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
|
23 | m_ranItems.erase(m_ranItems.upper_bound(procTime), m_ranItems.end()); |
| 179 | 23 | m_lastCommandCheckTime = procTime; | |
| 180 | } | ||
| 181 | 50 | } | |
| 182 | |||
| 183 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 12732 times.
|
12820 | if (m_loadSchedule) |
| 184 |
1/2✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
|
88 | LoadScheduleFromFile(); |
| 185 | |||
| 186 |
1/2✓ Branch 0 taken 12820 times.
✗ Branch 1 not taken.
|
12820 | CheckScheduledItems(); |
| 187 | |||
| 188 | 12820 | return; | |
| 189 | } | ||
| 190 | |||
| 191 | 3485 | void Scheduler::CheckIfShouldBePlayingNow(int ignoreRepeat, int forceStopped) { | |
| 192 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3474 times.
|
3485 | if (m_schedulerDisabled) |
| 193 | 11 | return; | |
| 194 | |||
| 195 | 3474 | LogDebug(VB_SCHEDULE, "CheckIfShouldBePlayingNow(%d, %d)\n", ignoreRepeat, forceStopped); | |
| 196 | |||
| 197 | // A reload asked for (the API's, after saving the schedule) waits for | ||
| 198 | // ScheduleProc's next pass, up to a second away. A decision made in that | ||
| 199 | // gap -- a playlist stopped just after the save -- started what the new | ||
| 200 | // schedule had removed. | ||
| 201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3474 times.
|
3474 | if (m_loadSchedule) |
| 202 | ✗ | LoadScheduleFromFile(); | |
| 203 | |||
| 204 | 3474 | std::time_t now = time(nullptr); | |
| 205 | { | ||
| 206 |
1/2✓ Branch 0 taken 3474 times.
✗ Branch 1 not taken.
|
3474 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 207 | |||
| 208 | // Idle in a switch is no stop (see Player::SwitchScope): re-armed | ||
| 209 | // then, the next pass pre-empts the playlist being switched to. | ||
| 210 | // Read after the status, as in the main loop. | ||
| 211 |
1/2✓ Branch 0 taken 3474 times.
✗ Branch 1 not taken.
|
3474 | bool idle = Player::INSTANCE.GetStatus() == FPP_STATUS_IDLE; |
| 212 |
1/2✓ Branch 0 taken 3474 times.
✗ Branch 1 not taken.
|
3474 | bool switching = Player::Switching(); |
| 213 | |||
| 214 |
2/2✓ Branch 0 taken 296 times.
✓ Branch 1 taken 3326 times.
|
3622 | for (auto& itemTime : m_scheduledItems) { |
| 215 |
2/2✓ Branch 0 taken 148 times.
✓ Branch 1 taken 148 times.
|
296 | if (itemTime.first > now) { |
| 216 | 148 | break; // no need to look at items that are further in the future | |
| 217 | } | ||
| 218 | |||
| 219 |
1/2✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
|
148 | LogExcess(VB_SCHEDULE, "Checking scheduled items:\n"); |
| 220 |
2/2✓ Branch 0 taken 154 times.
✓ Branch 1 taken 148 times.
|
302 | for (auto& item : itemTime.second) { |
| 221 |
2/4✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 154 times.
|
154 | if (WillLog(LOG_EXCESSIVE, VB_SCHEDULE)) |
| 222 | ✗ | DumpScheduledItem(item.startTime, item); | |
| 223 |
2/2✓ Branch 0 taken 150 times.
✓ Branch 1 taken 4 times.
|
154 | if (item.isPlaylist) { |
| 224 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 141 times.
|
150 | if (item.endTime <= now) { |
| 225 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | LogExcess(VB_SCHEDULE, "End time is in the past, skipping item\n"); |
| 226 | 9 | continue; | |
| 227 | } | ||
| 228 | |||
| 229 | 141 | bool ir = ignoreRepeat; | |
| 230 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 138 times.
|
141 | if ((m_forcedNextPlaylist == item.entryIndex) && |
| 231 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | (m_forcedNextPlaylistStart == item.startTime)) { |
| 232 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | LogExcess(VB_SCHEDULE, "This item entry index == m_forcedNextPlaylist\n"); |
| 233 | 3 | ir = true; | |
| 234 | } | ||
| 235 | |||
| 236 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 141 times.
|
141 | if (!switching && |
| 237 |
2/8✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 99 times.
✓ Branch 5 taken 42 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
141 | (idle || (Player::INSTANCE.GetPlaylistName() != item.entry->playlist)) && |
| 238 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 21 times.
|
141 | (forceStopped != item.entryIndex) && |
| 239 |
5/6✓ Branch 0 taken 141 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 97 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 21 times.
|
381 | (item.entry->repeat || ir) && |
| 240 |
3/6✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 141 times.
|
240 | !m_startsInFlight.count({ item.startTime, item.entryIndex })) { |
| 241 |
1/2✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
|
99 | LogExcess(VB_SCHEDULE, "Item run status reset\n"); |
| 242 | 99 | item.ran = false; | |
| 243 | } | ||
| 244 | } | ||
| 245 | } | ||
| 246 | } | ||
| 247 | 3474 | } | |
| 248 | 3474 | LogExcess(VB_SCHEDULE, "Done checking list, proceeding to call CheckScheduledItems()\n"); | |
| 249 | |||
| 250 | 3474 | CheckScheduledItems(getSettingInt("restarted") == 1); | |
| 251 | } | ||
| 252 | |||
| 253 | 41 | std::string Scheduler::GetPlaylistThatShouldBePlaying(int& repeat) { | |
| 254 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
|
41 | if (m_schedulerDisabled) |
| 255 | ✗ | return ""; | |
| 256 | |||
| 257 | // As in CheckIfShouldBePlayingNow(): answer from the schedule asked for. | ||
| 258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
|
41 | if (m_loadSchedule) |
| 259 | ✗ | LoadScheduleFromFile(); | |
| 260 | |||
| 261 | 41 | std::time_t now = time(nullptr); | |
| 262 |
1/2✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
|
41 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 263 | |||
| 264 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 39 times.
|
41 | for (auto& itemTime : m_scheduledItems) { |
| 265 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (itemTime.first > now) { |
| 266 | ✗ | break; // no need to look at items that are further in the future | |
| 267 | } | ||
| 268 | |||
| 269 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | for (auto& item : itemTime.second) { |
| 270 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (item.isPlaylist) { |
| 271 | // Skip things that should have ended in the past | ||
| 272 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (item.endTime <= now) { |
| 273 | ✗ | continue; | |
| 274 | } | ||
| 275 | |||
| 276 | 2 | repeat = item.entry->repeat; | |
| 277 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | return item.entry->playlist; |
| 278 | } | ||
| 279 | } | ||
| 280 | } | ||
| 281 | |||
| 282 | 39 | repeat = 0; | |
| 283 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
78 | return ""; |
| 284 | 41 | } | |
| 285 | |||
| 286 | 253 | void Scheduler::ReloadScheduleFile(void) { | |
| 287 | 253 | m_loadSchedule = true; | |
| 288 | 253 | } | |
| 289 | |||
| 290 | 428 | void Scheduler::AddScheduledItems(ScheduleEntry* entry, int index, std::time_t loadTime) { | |
| 291 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 426 times.
|
428 | if (!entry->enabled) |
| 292 | 3 | return; | |
| 293 | |||
| 294 |
2/2✓ Branch 0 taken 404 times.
✓ Branch 1 taken 22 times.
|
426 | if (!entry->playlist.empty()) { |
| 295 | 404 | std::string playlistFile; | |
| 296 |
1/2✓ Branch 0 taken 404 times.
✗ Branch 1 not taken.
|
404 | std::string warning = missingEntryWarning(*entry); |
| 297 | |||
| 298 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 403 times.
|
404 | if (entry->sequence) { |
| 299 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
3 | playlistFile = FPP_DIR_SEQUENCE("/" + entry->playlist); |
| 300 | } else { | ||
| 301 |
5/10✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 403 times.
✗ Branch 9 not taken.
|
1209 | playlistFile = FPP_DIR_PLAYLIST("/" + entry->playlist + ".json"); |
| 302 | } | ||
| 303 | |||
| 304 |
3/4✓ Branch 0 taken 404 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✓ Branch 3 taken 1 times.
|
404 | if (FileExists(playlistFile)) { |
| 305 |
2/4✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
|
806 | WarningHolder::RemoveWarning(23, warning); |
| 306 | } else { | ||
| 307 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ScheduleLoadWarning(23, warning); |
| 308 | 1 | entry->enabled = false; | |
| 309 | 1 | return; | |
| 310 | } | ||
| 311 |
4/4✓ Branch 0 taken 403 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 403 times.
✓ Branch 3 taken 1 times.
|
405 | } |
| 312 | |||
| 313 | 425 | int dayIndex = entry->dayIndex; | |
| 314 | 425 | std::time_t currTime = loadTime; | |
| 315 | struct tm now; | ||
| 316 | 425 | localtime_r(&currTime, &now); | |
| 317 |
1/2✓ Branch 0 taken 425 times.
✗ Branch 1 not taken.
|
425 | int scheduleDistance = getSettingInt("ScheduleDistance"); |
| 318 | |||
| 319 | // Check if this schedule's end date extends beyond the schedule distance | ||
| 320 | // Track this for warning display but respect the user's ScheduleDistance setting | ||
| 321 |
3/4✓ Branch 0 taken 425 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 119 times.
✓ Branch 3 taken 306 times.
|
425 | if (entry->endDate > 0 && entry->endDate < 10000000) { |
| 322 | // This is a yearless date (< 10000000), calculate actual end date | ||
| 323 | 119 | int currentDate = (now.tm_year + 1900) * 10000 + (now.tm_mon + 1) * 100 + now.tm_mday; | |
| 324 | 119 | int endMD = entry->endDate; | |
| 325 | |||
| 326 | // Reconstruct the full end date for the current or next year | ||
| 327 | 119 | int endYear = now.tm_year + 1900; | |
| 328 | 119 | int calculatedEndDate = endYear * 10000 + endMD; | |
| 329 | |||
| 330 | // If calculated end date is before today, use next year | ||
| 331 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 109 times.
|
119 | if (calculatedEndDate < currentDate) { |
| 332 | 10 | calculatedEndDate = (endYear + 1) * 10000 + endMD; | |
| 333 | } | ||
| 334 | |||
| 335 | // Calculate days from now to end date | ||
| 336 | 119 | int daysToEnd = (calculatedEndDate / 10000 - currentDate / 10000) * 365 + | |
| 337 | 119 | ((calculatedEndDate / 100 % 100) - (currentDate / 100 % 100)) * 30 + | |
| 338 | 119 | (calculatedEndDate % 100 - currentDate % 100); | |
| 339 | |||
| 340 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 110 times.
|
119 | if (daysToEnd > scheduleDistance) { |
| 341 | 9 | m_schedulesExtendBeyondDistance = true; | |
| 342 | } | ||
| 343 |
1/2✓ Branch 0 taken 306 times.
✗ Branch 1 not taken.
|
425 | } else if (entry->endDate >= 10000000) { |
| 344 | // Full date specified | ||
| 345 | 306 | int currentDate = (now.tm_year + 1900) * 10000 + (now.tm_mon + 1) * 100 + now.tm_mday; | |
| 346 | 306 | int daysDiff = ((entry->endDate / 10000) - (currentDate / 10000)) * 365 + | |
| 347 | 306 | ((entry->endDate / 100 % 100) - (currentDate / 100 % 100)) * 30 + | |
| 348 | 306 | (entry->endDate % 100 - currentDate % 100); | |
| 349 | |||
| 350 |
2/2✓ Branch 0 taken 155 times.
✓ Branch 1 taken 151 times.
|
306 | if (daysDiff > scheduleDistance) { |
| 351 | 155 | m_schedulesExtendBeyondDistance = true; | |
| 352 | } | ||
| 353 | } | ||
| 354 | |||
| 355 | // Convert everything to a day mask to simplify code below. Odd/even is | ||
| 356 | // not a fixed set of weekdays, so it schedules its own occurrences here | ||
| 357 | // rather than through the mask; dayIndex is left as INX_ODD_DAY/EVEN_DAY. | ||
| 358 |
4/4✓ Branch 0 taken 416 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 411 times.
|
425 | if ((dayIndex == INX_ODD_DAY) || (dayIndex == INX_EVEN_DAY)) { |
| 359 | // dayOffset is 0 when today already matches this entry's parity, 1 | ||
| 360 | // when it does not (so the next - and previous - matching day is one | ||
| 361 | // day away, since odd/even parity alternates daily). | ||
| 362 |
3/4✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 7 times.
|
14 | int dayOffset = entry->IsOddEvenMatch(currTime) ? 0 : 1; |
| 363 | |||
| 364 | // Schedule yesterday if needed to handle midnight crossovers | ||
| 365 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
14 | if (dayOffset) |
| 366 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | entry->pushStartEndTimes(now.tm_wday - 1, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 367 | |||
| 368 |
2/2✓ Branch 0 taken 190 times.
✓ Branch 1 taken 14 times.
|
204 | for (int i = now.tm_wday + dayOffset; i <= scheduleDistance; i += 2) { |
| 369 |
1/2✓ Branch 0 taken 190 times.
✗ Branch 1 not taken.
|
190 | entry->pushStartEndTimes(i, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 370 | } | ||
| 371 | 14 | } else { | |
| 372 |
1/2✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
|
411 | dayIndex = ScheduleEntry::DayIndexToMask(dayIndex); |
| 373 | } | ||
| 374 | |||
| 375 | // Special case: if today is Sunday, a Saturday-night start that crosses | ||
| 376 | // midnight (e.g. 22:00->02:00) bleeds into Sunday morning. Push it only | ||
| 377 | // for entries that actually run on Saturday - hence the Saturday-mask | ||
| 378 | // test - so a Monday-only crossover entry no longer plays early Sunday. | ||
| 379 | // Odd/even entries are excluded because the block above already pushes | ||
| 380 | // yesterday (Saturday, when today is Sunday) whenever today's parity does | ||
| 381 | // not match; firing here too would double-push or push the wrong parity. | ||
| 382 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 413 times.
|
425 | if ((now.tm_wday == 0) && |
| 383 |
3/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
12 | (entry->dayIndex != INX_ODD_DAY) && (entry->dayIndex != INX_EVEN_DAY) && |
| 384 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
|
11 | (dayIndex & INX_DAY_MASK_SATURDAY)) |
| 385 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | entry->pushStartEndTimes(-1, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 386 | |||
| 387 |
4/4✓ Branch 0 taken 416 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 411 times.
✓ Branch 3 taken 5 times.
|
425 | if ((entry->dayIndex != INX_ODD_DAY) && (entry->dayIndex != INX_EVEN_DAY)) { |
| 388 |
2/2✓ Branch 0 taken 4695 times.
✓ Branch 1 taken 411 times.
|
5106 | for (int weekOffset = 0; weekOffset <= scheduleDistance; weekOffset += 7) { |
| 389 |
2/2✓ Branch 0 taken 4535 times.
✓ Branch 1 taken 160 times.
|
4695 | if (dayIndex & INX_DAY_MASK_SUNDAY) |
| 390 |
1/2✓ Branch 0 taken 4535 times.
✗ Branch 1 not taken.
|
4535 | entry->pushStartEndTimes(INX_SUN + weekOffset, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 391 | |||
| 392 |
2/2✓ Branch 0 taken 4560 times.
✓ Branch 1 taken 135 times.
|
4695 | if (dayIndex & INX_DAY_MASK_MONDAY) |
| 393 |
1/2✓ Branch 0 taken 4560 times.
✗ Branch 1 not taken.
|
4560 | entry->pushStartEndTimes(INX_MON + weekOffset, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 394 | |||
| 395 |
2/2✓ Branch 0 taken 4580 times.
✓ Branch 1 taken 115 times.
|
4695 | if (dayIndex & INX_DAY_MASK_TUESDAY) |
| 396 |
1/2✓ Branch 0 taken 4580 times.
✗ Branch 1 not taken.
|
4580 | entry->pushStartEndTimes(INX_TUE + weekOffset, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 397 | |||
| 398 |
2/2✓ Branch 0 taken 4580 times.
✓ Branch 1 taken 115 times.
|
4695 | if (dayIndex & INX_DAY_MASK_WEDNESDAY) |
| 399 |
1/2✓ Branch 0 taken 4580 times.
✗ Branch 1 not taken.
|
4580 | entry->pushStartEndTimes(INX_WED + weekOffset, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 400 | |||
| 401 |
2/2✓ Branch 0 taken 4555 times.
✓ Branch 1 taken 140 times.
|
4695 | if (dayIndex & INX_DAY_MASK_THURSDAY) |
| 402 |
1/2✓ Branch 0 taken 4555 times.
✗ Branch 1 not taken.
|
4555 | entry->pushStartEndTimes(INX_THU + weekOffset, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 403 | |||
| 404 |
2/2✓ Branch 0 taken 4555 times.
✓ Branch 1 taken 140 times.
|
4695 | if (dayIndex & INX_DAY_MASK_FRIDAY) |
| 405 |
1/2✓ Branch 0 taken 4555 times.
✗ Branch 1 not taken.
|
4555 | entry->pushStartEndTimes(INX_FRI + weekOffset, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 406 | |||
| 407 |
2/2✓ Branch 0 taken 4560 times.
✓ Branch 1 taken 135 times.
|
4695 | if (dayIndex & INX_DAY_MASK_SATURDAY) |
| 408 |
1/2✓ Branch 0 taken 4560 times.
✗ Branch 1 not taken.
|
4560 | entry->pushStartEndTimes(INX_SAT + weekOffset, m_timeDelta, m_timeDeltaThreshold, currTime); |
| 409 | } | ||
| 410 | } | ||
| 411 | |||
| 412 | // loop through entry->startEndTimes and add to m_scheduledItems | ||
| 413 | 425 | time_t startTime = 0; | |
| 414 | 425 | time_t endTime = 0; | |
| 415 |
2/2✓ Branch 0 taken 4379 times.
✓ Branch 1 taken 425 times.
|
4804 | for (auto& startEnd : entry->startEndTimes) { |
| 416 | 4379 | startTime = startEnd.first; | |
| 417 | 4379 | endTime = startEnd.second; | |
| 418 | |||
| 419 | // Check to see if this occurrence is within the date range | ||
| 420 | struct tm later; | ||
| 421 | 4379 | localtime_r(&startTime, &later); | |
| 422 | 4379 | int dateInt = 0; | |
| 423 | 4379 | dateInt += (later.tm_year + 1900) * 10000; | |
| 424 | 4379 | dateInt += (later.tm_mon + 1) * 100; | |
| 425 | 4379 | dateInt += (later.tm_mday); | |
| 426 | |||
| 427 | // Skip if occurrence is outside the date range | ||
| 428 |
2/4✓ Branch 0 taken 4379 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4379 times.
|
4379 | if (!DateInRange(dateInt, entry->startDate, entry->endDate)) { |
| 429 | ✗ | continue; | |
| 430 | } | ||
| 431 | |||
| 432 |
1/2✓ Branch 0 taken 4379 times.
✗ Branch 1 not taken.
|
4379 | auto& vec = m_scheduledItems[startTime]; |
| 433 | 4379 | vec.push_back({ .entry = entry, | |
| 434 | .priority = index, // change this if we add a priority field | ||
| 435 | .entryIndex = index, | ||
| 436 | .ran = false, | ||
| 437 | .startTime = startTime, | ||
| 438 | .endTime = startTime }); | ||
| 439 | 4379 | ScheduledItem& newItem = vec.back(); | |
| 440 | |||
| 441 |
2/2✓ Branch 0 taken 3327 times.
✓ Branch 1 taken 1052 times.
|
4379 | if (!entry->playlist.empty()) { |
| 442 | // Old style schedule entry without a FPP Command | ||
| 443 |
1/2✓ Branch 0 taken 3327 times.
✗ Branch 1 not taken.
|
3327 | Json::Value args(Json::arrayValue); |
| 444 |
2/4✓ Branch 0 taken 3327 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3327 times.
✗ Branch 3 not taken.
|
3327 | args.append(entry->playlist); |
| 445 |
4/6✓ Branch 0 taken 1964 times.
✓ Branch 1 taken 1363 times.
✓ Branch 2 taken 3327 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3327 times.
✗ Branch 5 not taken.
|
3327 | args.append(entry->repeat ? "true" : "false"); |
| 446 |
2/4✓ Branch 0 taken 3327 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3327 times.
✗ Branch 3 not taken.
|
3327 | args.append("false"); |
| 447 | |||
| 448 |
1/2✓ Branch 0 taken 3327 times.
✗ Branch 1 not taken.
|
3327 | newItem.command = "Start Playlist"; |
| 449 | 3327 | newItem.isPlaylist = true; | |
| 450 | 3327 | newItem.args = std::move(args); | |
| 451 | 3327 | newItem.endTime = endTime; | |
| 452 | |||
| 453 | // Check to see if this item already ran | ||
| 454 |
3/4✓ Branch 0 taken 3327 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 3322 times.
|
3327 | if (auto it = m_ranItems.find(newItem.startTime); it != m_ranItems.end()) { |
| 455 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
10 | for (auto& item : it->second) { |
| 456 | 5 | if ((newItem.command == item.command) && | |
| 457 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | (newItem.isPlaylist == item.isPlaylist) && |
| 458 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | (newItem.startTime == item.startTime) && |
| 459 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
|
5 | (newItem.endTime == item.endTime) && |
| 460 |
6/10✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 3 times.
|
12 | (newItem.args.size() == item.args.size()) && |
| 461 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | SameFirstScheduleArg(newItem.args, item.args)) { |
| 462 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogDebug(VB_SCHEDULE, "Marking playlist item as already ran:\n"); |
| 463 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | DumpScheduledItem(newItem.startTime, newItem); |
| 464 | 2 | newItem.ran = true; | |
| 465 | } | ||
| 466 | } | ||
| 467 | } | ||
| 468 | 3327 | } else { | |
| 469 | // New style schedule entry with a FPP Command | ||
| 470 |
1/2✓ Branch 0 taken 1052 times.
✗ Branch 1 not taken.
|
1052 | newItem.command = entry->command; |
| 471 |
1/2✓ Branch 0 taken 1052 times.
✗ Branch 1 not taken.
|
1052 | newItem.args = entry->args; |
| 472 | } | ||
| 473 | } | ||
| 474 |
2/8✓ Branch 0 taken 4379 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4379 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
4379 | } |
| 475 | |||
| 476 | 794 | void Scheduler::DumpScheduledItem(const std::time_t itemTime, const ScheduledItem& item) { | |
| 477 | char timeBuf[32]; | ||
| 478 |
1/2✓ Branch 0 taken 794 times.
✗ Branch 1 not taken.
|
794 | std::string timeStr = ctime_r(&itemTime, timeBuf); |
| 479 | |||
| 480 | 794 | std::string argStr; | |
| 481 |
2/4✓ Branch 0 taken 794 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 794 times.
✗ Branch 3 not taken.
|
794 | if (item.args.isArray()) { |
| 482 |
7/12✓ Branch 0 taken 794 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 794 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2606 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2606 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3400 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2606 times.
✓ Branch 11 taken 794 times.
|
3400 | for (const auto& a : item.args) { |
| 483 |
1/2✓ Branch 0 taken 2606 times.
✗ Branch 1 not taken.
|
2606 | argStr += "\""; |
| 484 |
2/4✓ Branch 0 taken 2606 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2606 times.
✗ Branch 3 not taken.
|
2606 | argStr += ScheduleArgToString(a); |
| 485 |
1/2✓ Branch 0 taken 2606 times.
✗ Branch 1 not taken.
|
2606 | argStr += "\" "; |
| 486 | } | ||
| 487 | } else { | ||
| 488 | ✗ | argStr = ScheduleArgToString(item.args); | |
| 489 | } | ||
| 490 | |||
| 491 |
2/4✓ Branch 0 taken 794 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 794 times.
✗ Branch 3 not taken.
|
794 | LogDebug(VB_SCHEDULE, "%s: %2d '%s' - '%s'\n", |
| 492 | timeStr.substr(0, timeStr.length() - 1).c_str(), | ||
| 493 | item.priority, | ||
| 494 | item.command.c_str(), | ||
| 495 | argStr.c_str()); | ||
| 496 | 794 | } | |
| 497 | |||
| 498 | ✗ | void Scheduler::DumpScheduledItems() { | |
| 499 | ✗ | LogDebug(VB_SCHEDULE, "DumpScheduledItems()\n"); | |
| 500 | |||
| 501 | ✗ | for (const auto& itemTime : m_scheduledItems) { | |
| 502 | ✗ | for (const auto& item : itemTime.second) { | |
| 503 | ✗ | DumpScheduledItem(itemTime.first, item); | |
| 504 | } | ||
| 505 | } | ||
| 506 | ✗ | } | |
| 507 | |||
| 508 | 636 | void Scheduler::doCountdown(const std::time_t now, const std::time_t itemTime, const std::vector<ScheduledItem>& items, | |
| 509 | std::vector<CountdownPreset>& presets) { | ||
| 510 | // Check to see if we should be counting down to the next item | ||
| 511 | 636 | bool logItems = false; | |
| 512 | 636 | int diff = itemTime - now; | |
| 513 | |||
| 514 | // Print the countdown more frequently as we get closer | ||
| 515 |
6/6✓ Branch 0 taken 222 times.
✓ Branch 1 taken 414 times.
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 108 times.
✓ Branch 4 taken 157 times.
✓ Branch 5 taken 371 times.
|
636 | if (((diff > 300) && ((diff % 300) == 0)) || |
| 516 |
6/6✓ Branch 0 taken 43 times.
✓ Branch 1 taken 114 times.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 325 times.
✓ Branch 5 taken 195 times.
|
528 | ((diff > 60) && (diff <= 300) && ((diff % 60) == 0)) || |
| 517 |
6/6✓ Branch 0 taken 176 times.
✓ Branch 1 taken 149 times.
✓ Branch 2 taken 156 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 195 times.
✓ Branch 5 taken 305 times.
|
520 | ((diff > 10) && (diff <= 60) && ((diff % 10) == 0)) || |
| 518 | ((diff <= 10))) { | ||
| 519 | 331 | logItems = true; | |
| 520 | } | ||
| 521 | |||
| 522 |
2/2✓ Branch 0 taken 331 times.
✓ Branch 1 taken 305 times.
|
636 | if (logItems) { |
| 523 |
4/4✓ Branch 0 taken 22 times.
✓ Branch 1 taken 309 times.
✓ Branch 2 taken 330 times.
✓ Branch 3 taken 1 times.
|
331 | LogDebug(VB_SCHEDULE, "Scheduled Item%s running in %d second%s:\n", |
| 524 | items.size() == 1 ? "" : "s", | ||
| 525 | diff, | ||
| 526 | diff == 1 ? "" : "s"); | ||
| 527 | |||
| 528 |
2/2✓ Branch 0 taken 338 times.
✓ Branch 1 taken 331 times.
|
669 | for (auto& item : items) { |
| 529 |
4/4✓ Branch 0 taken 238 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 135 times.
✓ Branch 3 taken 103 times.
|
338 | if (item.isPlaylist && |
| 530 | (diff < 1000)) { | ||
| 531 | char tmpStr[27]; | ||
| 532 | 135 | snprintf(tmpStr, 26, "PLAYLIST_START_TMINUS_%03d", diff); | |
| 533 | 270 | presets.push_back({ .name = tmpStr, .playlist = item.entry->playlist }); | |
| 534 | } | ||
| 535 | |||
| 536 |
1/2✓ Branch 0 taken 338 times.
✗ Branch 1 not taken.
|
338 | DumpScheduledItem(itemTime, item); |
| 537 | } | ||
| 538 | } | ||
| 539 |
3/8✓ Branch 0 taken 135 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 135 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
771 | } |
| 540 | |||
| 541 | 16386 | void Scheduler::RunCountdownPresets(const std::vector<CountdownPreset>& presets) { | |
| 542 |
2/2✓ Branch 0 taken 135 times.
✓ Branch 1 taken 16386 times.
|
16521 | for (const auto& preset : presets) { |
| 543 | 135 | std::map<std::string, std::string> keywords; | |
| 544 |
3/6✓ Branch 0 taken 135 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 135 times.
✗ Branch 5 not taken.
|
270 | keywords["PLAYLIST_NAME"] = preset.playlist; |
| 545 |
2/4✓ Branch 0 taken 135 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135 times.
✗ Branch 3 not taken.
|
135 | CommandManager::INSTANCE.TriggerPreset(preset.name, keywords); |
| 546 | 135 | } | |
| 547 | 16386 | } | |
| 548 | |||
| 549 | 16390 | void Scheduler::RunPlayerActions(const std::vector<PlayerAction>& actions) { | |
| 550 |
2/2✓ Branch 0 taken 117 times.
✓ Branch 1 taken 16390 times.
|
16507 | for (const auto& action : actions) { |
| 551 |
3/6✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 111 times.
✗ Branch 5 not taken.
|
117 | switch (action.type) { |
| 552 | 4 | case PlayerAction::Type::StopUntilIdle: | |
| 553 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | Player::INSTANCE.StopNowAllLevels(action.forceStop); |
| 554 | 4 | break; | |
| 555 | ✗ | case PlayerAction::Type::StopNow: | |
| 556 | ✗ | Player::INSTANCE.StopNow(action.forceStop); | |
| 557 | ✗ | break; | |
| 558 | 2 | case PlayerAction::Type::StopGracefully: | |
| 559 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | Player::INSTANCE.StopGracefully(action.forceStop); |
| 560 | 2 | break; | |
| 561 | ✗ | case PlayerAction::Type::StopGracefullyAfterLoop: | |
| 562 | ✗ | Player::INSTANCE.StopGracefully(action.forceStop, 1); | |
| 563 | ✗ | break; | |
| 564 | 111 | case PlayerAction::Type::StartPlaylist: | |
| 565 | 111 | Player::INSTANCE.StartScheduledPlaylist(action.playlist, action.position, | |
| 566 | 111 | action.repeat, action.entryIndex, | |
| 567 | 111 | action.priority, | |
| 568 |
1/2✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
|
111 | action.startTime, action.endTime, action.stopType); |
| 569 | 111 | break; | |
| 570 | } | ||
| 571 | } | ||
| 572 | 16390 | } | |
| 573 | |||
| 574 | static std::mutex s_commandThreadsLock; | ||
| 575 | static std::condition_variable s_commandThreadsDone; | ||
| 576 | static int s_commandThreads = 0; | ||
| 577 | |||
| 578 | 2620 | void Scheduler::WaitForCommandThreads(int timeoutMS) { | |
| 579 |
1/2✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
|
2620 | std::unique_lock<std::mutex> l(s_commandThreadsLock); |
| 580 |
3/4✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2619 times.
|
5242 | if (!s_commandThreadsDone.wait_for(l, std::chrono::milliseconds(timeoutMS), []() { return s_commandThreads == 0; })) { |
| 581 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogWarn(VB_SCHEDULE, "%d scheduled command(s) still running at shutdown\n", s_commandThreads); |
| 582 | } | ||
| 583 | 2620 | } | |
| 584 | |||
| 585 | 10 | void Scheduler::doScheduledCommand(const std::time_t itemTime, const ScheduledItem& item) { | |
| 586 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | LogDebug(VB_SCHEDULE, "Running scheduled item:\n"); |
| 587 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | DumpScheduledItem(itemTime, item); |
| 588 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | Json::Value cmd; |
| 589 |
2/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | cmd["command"] = item.command; |
| 590 |
2/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | cmd["args"] = item.args; |
| 591 |
2/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | cmd["multisyncCommand"] = item.entry->multisyncCommand; |
| 592 |
2/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | cmd["multisyncHosts"] = item.entry->multisyncHosts; |
| 593 | |||
| 594 | 10 | int entryIndex = item.entryIndex; | |
| 595 | { | ||
| 596 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | std::lock_guard<std::mutex> l(s_commandThreadsLock); |
| 597 | 10 | s_commandThreads++; | |
| 598 | 10 | } | |
| 599 | 10 | std::thread th([entryIndex](Json::Value cmd) { | |
| 600 |
2/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | SetThreadName("FPP-RunCmd"); |
| 601 | // "id" rather than a row number: entryIndex is the 0-based index into | ||
| 602 | // the schedule vector, and that is exactly what the API reports as an | ||
| 603 | // entry's "id" (see BuildScheduleRangeItem / the scheduledItem["id"] | ||
| 604 | // below), so this is the value to cross-reference against. | ||
| 605 |
3/6✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | LogDebug(VB_COMMAND, "Scheduler entry id %d running command \"%s\"\n", entryIndex, cmd["command"].asString().c_str()); |
| 606 | // This thread is detached, so an exception escaping the command is not | ||
| 607 | // a failed command - it is std::terminate and the whole daemon goes | ||
| 608 | // down at whatever second the schedule fires. Commands parse | ||
| 609 | // user-supplied arguments (and plugins supply their own), so catch | ||
| 610 | // everything here and let the show keep running. | ||
| 611 | try { | ||
| 612 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | CommandManager::INSTANCE.run(cmd); |
| 613 | ✗ | } catch (const std::exception& e) { | |
| 614 | ✗ | LogErr(VB_COMMAND, "Scheduler entry id %d command \"%s\" threw: %s\n", | |
| 615 | entryIndex, cmd["command"].asString().c_str(), e.what()); | ||
| 616 | ✗ | WarningHolder::AddWarningTimeout(60, 47, "Schedule: command '" + cmd["command"].asString() + "' failed: " + e.what()); | |
| 617 | ✗ | } catch (...) { | |
| 618 | ✗ | LogErr(VB_COMMAND, "Scheduler entry id %d command \"%s\" threw an unknown exception\n", | |
| 619 | entryIndex, cmd["command"].asString().c_str()); | ||
| 620 | ✗ | WarningHolder::AddWarningTimeout(60, 47, "Schedule: command '" + cmd["command"].asString() + "' failed"); | |
| 621 | ✗ | } | |
| 622 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | std::lock_guard<std::mutex> l(s_commandThreadsLock); |
| 623 | 10 | s_commandThreads--; | |
| 624 | 10 | s_commandThreadsDone.notify_all(); | |
| 625 | 10 | }, | |
| 626 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | std::move(cmd)); |
| 627 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | th.detach(); |
| 628 | 10 | } | |
| 629 | |||
| 630 | 333 | bool Scheduler::doScheduledPlaylist(const std::time_t now, const std::time_t itemTime, ScheduledItem& item, bool restarted, | |
| 631 | std::vector<PlayerAction>& actions) { | ||
| 632 | 333 | LogDebug(VB_SCHEDULE, "Checking scheduled 'Start Playlist'\n"); | |
| 633 | 333 | DumpScheduledItem(itemTime, item); | |
| 634 | |||
| 635 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 333 times.
|
333 | if (item.endTime <= now) { |
| 636 | ✗ | SetItemRan(item, true); | |
| 637 | |||
| 638 | // don't try to start if scheduled end has passed | ||
| 639 | ✗ | return false; | |
| 640 | } | ||
| 641 | |||
| 642 | // Don't restart a playlist if it was just force stopped | ||
| 643 | 1032 | if ((Player::INSTANCE.GetForceStopped()) && | |
| 644 |
7/10✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 300 times.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 32 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 32 times.
|
365 | (Player::INSTANCE.GetOrigStartTime() == item.startTime) && |
| 645 |
4/8✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 301 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 333 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
365 | (Player::INSTANCE.GetForceStoppedPlaylist() == item.entry->playlist)) { |
| 646 | ✗ | SetItemRan(item, true); | |
| 647 | ✗ | return false; | |
| 648 | } | ||
| 649 | |||
| 650 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 170 times.
|
333 | if (Player::INSTANCE.GetStatus() == FPP_STATUS_PLAYLIST_PLAYING) { |
| 651 | // If we are playing, check to see if we should be playing something else | ||
| 652 | |||
| 653 | // Check to see if we are already playing this item, for | ||
| 654 | // instance if we reloaded the schedule while a scheduled | ||
| 655 | // playlist was playing. | ||
| 656 |
2/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
163 | if ((Player::INSTANCE.GetPlaylistName() == item.entry->playlist) && |
| 657 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | (Player::INSTANCE.WasScheduled()) && |
| 658 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | (Player::INSTANCE.GetRepeat() == item.entry->repeat) && |
| 659 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | ((Player::INSTANCE.GetOrigStopTime() == item.endTime) || |
| 660 |
6/10✓ Branch 0 taken 163 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 160 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 163 times.
✗ Branch 9 not taken.
|
169 | (Player::INSTANCE.GetStopTime() == item.endTime)) && |
| 661 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | (Player::INSTANCE.GetStopMethod() == item.entry->stopType)) { |
| 662 | 3 | SetItemRan(item, true); | |
| 663 | 3 | return false; | |
| 664 | } | ||
| 665 | |||
| 666 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 140 times.
|
160 | if (!Player::INSTANCE.WasScheduled()) { |
| 667 | // Manually started playlist is running | ||
| 668 | |||
| 669 | // Check if playlist is protected from schedule override | ||
| 670 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 11 times.
|
20 | if (!Player::INSTANCE.GetAllowScheduleOverride()) { |
| 671 |
2/4✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | LogInfo(VB_SCHEDULE, "Manual playlist '%s' is protected from schedule override, not starting scheduled playlist '%s'\n", |
| 672 | Player::INSTANCE.GetPlaylistName().c_str(), item.entry->playlist.c_str()); | ||
| 673 | // Track this blocked scheduled item | ||
| 674 | 9 | m_lastBlockedPlaylist = item.entry->playlist; | |
| 675 | 9 | m_lastBlockedTime = now; | |
| 676 | 9 | return false; | |
| 677 | } | ||
| 678 | |||
| 679 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
|
11 | if (item.startTime < Player::INSTANCE.GetStartTime()) { |
| 680 | // Due before the playlist was started by hand: waiting behind | ||
| 681 | // the scheduled one it replaced, or a repeating entry owed a | ||
| 682 | // restart. It plays once that playlist ends. Only an entry | ||
| 683 | // that comes due while it plays can pre-empt it. | ||
| 684 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | LogDebug(VB_SCHEDULE, "Scheduled playlist '%s' was due before manual playlist '%s' started, waiting for it to end\n", |
| 685 | item.entry->playlist.c_str(), Player::INSTANCE.GetPlaylistName().c_str()); | ||
| 686 | 4 | return false; | |
| 687 | } | ||
| 688 | |||
| 689 | // Check priority | ||
| 690 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
|
7 | if (Player::INSTANCE.GetPriority() > item.priority) { |
| 691 | // Scheduled playlist has higher priority, stop the manual one | ||
| 692 |
2/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1 | LogInfo(VB_SCHEDULE, "Stopping manual playlist '%s' (priority %d) for scheduled playlist '%s' (priority %d)\n", |
| 693 | Player::INSTANCE.GetPlaylistName().c_str(), Player::INSTANCE.GetPriority(), | ||
| 694 | item.entry->playlist.c_str(), item.priority); | ||
| 695 | 1 | actions.push_back({ .type = PlayerAction::Type::StopUntilIdle, | |
| 696 | .forceStop = 1 }); | ||
| 697 | } else { | ||
| 698 | // Manual playlist has higher or equal priority, let it continue | ||
| 699 |
2/6✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
6 | LogDebug(VB_SCHEDULE, "Manual playlist '%s' (priority %d) has higher priority than scheduled playlist '%s' (priority %d), not overriding\n", |
| 700 | Player::INSTANCE.GetPlaylistName().c_str(), Player::INSTANCE.GetPriority(), | ||
| 701 | item.entry->playlist.c_str(), item.priority); | ||
| 702 | 6 | return false; | |
| 703 | } | ||
| 704 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 137 times.
|
140 | } else if (Player::INSTANCE.GetPriority() > item.priority) { |
| 705 | // Lower priority (higher number) playlist is running | ||
| 706 | // Reset the ran status on the schedule entry for the | ||
| 707 | // running playlist to false so it shows as 'next' again | ||
| 708 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | std::time_t oldStartTime = Player::INSTANCE.GetOrigStartTime(); |
| 709 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | std::string playlistName = Player::INSTANCE.GetPlaylistName(); |
| 710 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | if (auto it = m_scheduledItems.find(oldStartTime); it != m_scheduledItems.end()) { |
| 711 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | for (auto& oldItem : it->second) { |
| 712 |
5/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
|
6 | if (oldItem.isPlaylist && |
| 713 | 3 | (oldItem.entry->playlist == playlistName)) { | |
| 714 | 2 | oldItem.ran = false; | |
| 715 | 2 | m_forcedNextPlaylist = oldItem.entryIndex; | |
| 716 | 2 | m_forcedNextPlaylistStart = oldItem.startTime; | |
| 717 | } | ||
| 718 | } | ||
| 719 | } | ||
| 720 | |||
| 721 | 3 | int forceStop = 0; | |
| 722 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
3 | if (Player::INSTANCE.GetStopTime() < Player::INSTANCE.GetOrigStopTime()) { |
| 723 | ✗ | forceStop = 1; | |
| 724 | } | ||
| 725 | |||
| 726 | // Stop whatever is playing the way its entry says to, and start | ||
| 727 | // this item once the player is idle: a hard stop is idle by the | ||
| 728 | // rescan this pass does after its actions, a graceful one when the | ||
| 729 | // running playlist finishes. This item is deliberately not marked | ||
| 730 | // ran. It used to queue its start straight after the stop, and | ||
| 731 | // the start cut the stopping playlist off - every pre-emption was a | ||
| 732 | // hard stop whatever stop type the running entry had. | ||
| 733 |
3/5✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
3 | switch (Player::INSTANCE.GetStopMethod()) { |
| 734 | 2 | case 0: | |
| 735 | 2 | actions.push_back({ .type = PlayerAction::Type::StopGracefully, | |
| 736 | .forceStop = forceStop }); | ||
| 737 | 2 | break; | |
| 738 | ✗ | case 2: | |
| 739 | ✗ | actions.push_back({ .type = PlayerAction::Type::StopGracefullyAfterLoop, | |
| 740 | .forceStop = forceStop }); | ||
| 741 | ✗ | break; | |
| 742 | 1 | case 1: | |
| 743 | default: | ||
| 744 | // Every level: a single StopNow ends only a playlist inserted | ||
| 745 | // into the running one, which then resumes. | ||
| 746 | 1 | actions.push_back({ .type = PlayerAction::Type::StopUntilIdle, | |
| 747 | .forceStop = forceStop }); | ||
| 748 | 1 | break; | |
| 749 | } | ||
| 750 | 3 | return false; | |
| 751 | 3 | } else { | |
| 752 | // Need to wait for current Scheduled Higher-Priority | ||
| 753 | // item to end until we can play multiple playlists | ||
| 754 | // concurrently | ||
| 755 | 137 | return false; | |
| 756 | } | ||
| 757 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 106 times.
|
170 | } else if (Player::INSTANCE.GetStatus() != FPP_STATUS_IDLE) { |
| 758 | // We are either paused or stopping already so do nothing | ||
| 759 | 64 | return false; | |
| 760 | } | ||
| 761 | |||
| 762 | 107 | LogDebug(VB_SCHEDULE, "Starting Scheduled Playlist:\n"); | |
| 763 | 107 | DumpScheduledItem(itemTime, item); | |
| 764 | |||
| 765 | 107 | int position = 0; | |
| 766 |
8/12✓ Branch 0 taken 6 times.
✓ Branch 1 taken 101 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 101 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 101 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
107 | if (restarted && (getSetting("resumePlaylist") == item.entry->playlist)) { |
| 767 | 6 | position = getSettingInt("resumePosition"); | |
| 768 | |||
| 769 |
3/6✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
24 | SetSetting("resumePlaylist", ""); |
| 770 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | SetSetting("resumePosition", 0); |
| 771 | } | ||
| 772 | |||
| 773 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 106 times.
|
107 | if ((m_forcedNextPlaylist == item.entryIndex) && |
| 774 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | (m_forcedNextPlaylistStart == item.startTime)) { |
| 775 | // The pre-empted occurrence is getting its restart; that was the | ||
| 776 | // whole of what the force was for. | ||
| 777 | 1 | m_forcedNextPlaylist = SCHEDULE_INDEX_INVALID; | |
| 778 | } | ||
| 779 | |||
| 780 |
1/2✓ Branch 0 taken 107 times.
✗ Branch 1 not taken.
|
107 | m_startsInFlight.insert({ item.startTime, item.entryIndex }); |
| 781 | 107 | actions.push_back({ .type = PlayerAction::Type::StartPlaylist, | |
| 782 | 107 | .playlist = item.entry->playlist, | |
| 783 | .position = position, | ||
| 784 | 107 | .repeat = item.entry->repeat, | |
| 785 | 107 | .entryIndex = item.entryIndex, | |
| 786 | 107 | .priority = item.entryIndex, // priority is entry index for now | |
| 787 | 107 | .startTime = item.startTime, | |
| 788 | 107 | .endTime = item.endTime, | |
| 789 | 107 | .stopType = item.entry->stopType }); | |
| 790 | 107 | return true; | |
| 791 |
5/22✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 107 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 107 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
111 | } |
| 792 | |||
| 793 | // How far ahead of a scheduled playlist the audio output is brought up. | ||
| 794 | static constexpr std::time_t MEDIA_PREWARM_LEAD_S = 5; | ||
| 795 | |||
| 796 | 16294 | void Scheduler::CheckScheduledItems(bool restarted) { | |
| 797 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 16276 times.
|
16294 | if (m_schedulerDisabled) |
| 798 | 18 | return; | |
| 799 | |||
| 800 | 16276 | std::time_t now = time(nullptr); | |
| 801 | 16276 | std::vector<PlayerAction> actions; | |
| 802 | 16276 | std::vector<CountdownPreset> presets; | |
| 803 | // How long to hold the audio output up for a playlist about to start (0 = | ||
| 804 | // none due). Opening it takes most of a second on slow boards, so do it | ||
| 805 | // ahead of time rather than when the first track starts. | ||
| 806 | 16276 | int prewarmMs = 0; | |
| 807 | |||
| 808 | // Longest a scheduled FPP command may fire after its second passed. Bounds | ||
| 809 | // the (m_lastCommandCheckTime, now] catch-up window so a forward clock step | ||
| 810 | // does not replay a batch of stale commands; anything older is logged and | ||
| 811 | // marked ran instead of run. | ||
| 812 | 16276 | constexpr std::time_t maxCommandCatchup = SCHEDULE_COMMAND_CATCHUP_S; | |
| 813 | |||
| 814 | // Each pass decides what to do while holding m_scheduleLock and runs it | ||
| 815 | // after releasing the lock, since starting or stopping a playlist takes | ||
| 816 | // m_playlistMutex in the opposite order (see Scheduler.h). A pass stops | ||
| 817 | // scanning as soon as it has an action so that the item after it is still | ||
| 818 | // judged against the player's real state rather than the state the player | ||
| 819 | // had before the action ran, which is what deciding for every item up | ||
| 820 | // front would do. | ||
| 821 | do { | ||
| 822 | 16386 | actions.clear(); | |
| 823 | 16386 | presets.clear(); | |
| 824 | |||
| 825 | { | ||
| 826 |
1/2✓ Branch 0 taken 16386 times.
✗ Branch 1 not taken.
|
16386 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 827 | |||
| 828 | // With the player idle and several playlists due, start the | ||
| 829 | // highest-priority one (lowest entry index) rather than whichever | ||
| 830 | // started earliest. Starting the earlier, lower-priority one | ||
| 831 | // played the wrong show until the next pass pre-empted it; and | ||
| 832 | // after a graceful pre-emption the stopped entry is due again (it | ||
| 833 | // is owed a restart) and would win again, pre-empting forever. | ||
| 834 | 16386 | int bestIdlePriority = INT_MAX; | |
| 835 |
3/4✓ Branch 0 taken 16386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12521 times.
✓ Branch 3 taken 3865 times.
|
16386 | if (Player::INSTANCE.GetStatus() == FPP_STATUS_IDLE) { |
| 836 |
2/2✓ Branch 0 taken 615 times.
✓ Branch 1 taken 12173 times.
|
12788 | for (auto& due : m_scheduledItems) { |
| 837 |
2/2✓ Branch 0 taken 348 times.
✓ Branch 1 taken 267 times.
|
615 | if (due.first > now) |
| 838 | 348 | break; | |
| 839 |
2/2✓ Branch 0 taken 273 times.
✓ Branch 1 taken 267 times.
|
540 | for (auto& c : due.second) { |
| 840 |
3/4✓ Branch 0 taken 120 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 120 times.
✗ Branch 3 not taken.
|
133 | if (!c.ran && c.isPlaylist && (c.endTime > now) && |
| 841 |
4/4✓ Branch 0 taken 133 times.
✓ Branch 1 taken 140 times.
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 6 times.
|
520 | (c.priority < bestIdlePriority) && |
| 842 |
4/6✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 114 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 114 times.
✓ Branch 5 taken 159 times.
|
387 | !m_startsInFlight.count({ c.startTime, c.entryIndex })) { |
| 843 | 114 | bestIdlePriority = c.priority; | |
| 844 | } | ||
| 845 | } | ||
| 846 | } | ||
| 847 | } | ||
| 848 | |||
| 849 |
2/2✓ Branch 0 taken 1755 times.
✓ Branch 1 taken 15640 times.
|
17395 | for (auto& itemTime : m_scheduledItems) { |
| 850 |
2/2✓ Branch 0 taken 636 times.
✓ Branch 1 taken 1119 times.
|
1755 | if (itemTime.first > now) { |
| 851 |
1/2✓ Branch 0 taken 636 times.
✗ Branch 1 not taken.
|
636 | doCountdown(now, itemTime.first, itemTime.second, presets); |
| 852 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 524 times.
|
636 | if (itemTime.first - now <= MEDIA_PREWARM_LEAD_S) { |
| 853 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 51 times.
|
163 | for (auto& item : itemTime.second) { |
| 854 |
3/4✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✓ Branch 3 taken 51 times.
|
112 | if (!item.ran && item.isPlaylist) { |
| 855 | // Through the start, plus the usual linger in | ||
| 856 | // case the playlist opens with no media. | ||
| 857 | 61 | prewarmMs = (int)((itemTime.first - now + MEDIA_PREWARM_LEAD_S) * 1000); | |
| 858 | 61 | break; | |
| 859 | } | ||
| 860 | } | ||
| 861 | } | ||
| 862 | 636 | break; // no need to look at items that are further in the future | |
| 863 | } | ||
| 864 | |||
| 865 |
2/2✓ Branch 0 taken 1140 times.
✓ Branch 1 taken 1012 times.
|
2152 | for (auto& item : itemTime.second) { |
| 866 |
2/2✓ Branch 0 taken 785 times.
✓ Branch 1 taken 355 times.
|
1140 | if (item.ran) |
| 867 | 785 | continue; // skip over any items that ran already | |
| 868 | |||
| 869 |
2/2✓ Branch 0 taken 341 times.
✓ Branch 1 taken 14 times.
|
355 | if (item.isPlaylist) { |
| 870 | // While any scheduled start is still being carried | ||
| 871 | // out the player is busy, whatever its status says: | ||
| 872 | // it reads idle until that playlist has loaded. | ||
| 873 | // Guarding only the in-flight item let a concurrent | ||
| 874 | // pass start the next, lower-priority item into the | ||
| 875 | // same player and lose the higher one. Skipped items | ||
| 876 | // keep their ran flag clear, and the pass doing the | ||
| 877 | // start rescans once it has finished. | ||
| 878 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 341 times.
|
341 | if (!m_startsInFlight.empty()) |
| 879 | ✗ | continue; | |
| 880 | // Nor while one playlist is being replaced by another | ||
| 881 | // (see Player::SwitchScope). | ||
| 882 |
2/4✓ Branch 0 taken 341 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 341 times.
|
341 | if (Player::Switching()) |
| 883 | ✗ | continue; | |
| 884 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 333 times.
|
341 | if (item.priority > bestIdlePriority) |
| 885 | 8 | continue; // a higher-priority playlist is due; it goes first | |
| 886 |
3/4✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 226 times.
✓ Branch 3 taken 107 times.
|
333 | if (!doScheduledPlaylist(now, itemTime.first, item, restarted, actions)) { |
| 887 | 226 | continue; | |
| 888 | } | ||
| 889 | } else { | ||
| 890 | // An FPP Command has no duration to catch up to, so a | ||
| 891 | // missed second would silently drop it. Fire any | ||
| 892 | // command whose second falls in the (lastCheck, now] | ||
| 893 | // window this run has not examined yet, but never one | ||
| 894 | // more than maxCommandCatchup seconds late so a large | ||
| 895 | // clock step cannot replay a batch of stale commands. | ||
| 896 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10 times.
|
14 | if (itemTime.first <= m_lastCommandCheckTime) { |
| 897 | // A prior run already had its chance at this second. | ||
| 898 | // A reload can reset item.ran (FPP-command ran-state | ||
| 899 | // is not restored from m_ranItems), so gate on the | ||
| 900 | // check window, not on item.ran, to avoid re-firing. | ||
| 901 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | SetItemRan(item, true); |
| 902 | 4 | continue; | |
| 903 | } | ||
| 904 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if ((now - itemTime.first) > maxCommandCatchup) { |
| 905 | ✗ | LogWarn(VB_SCHEDULE, | |
| 906 | "Scheduled command '%s' skipped, %ld seconds late (catch-up cap is %ld s)\n", | ||
| 907 | item.command.c_str(), (long)(now - itemTime.first), | ||
| 908 | (long)maxCommandCatchup); | ||
| 909 | ✗ | SetItemRan(item, true); | |
| 910 | ✗ | continue; | |
| 911 | } | ||
| 912 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | doScheduledCommand(itemTime.first, item); |
| 913 | } | ||
| 914 | |||
| 915 |
1/2✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
|
117 | SetItemRan(item, true); |
| 916 | |||
| 917 |
2/2✓ Branch 0 taken 107 times.
✓ Branch 1 taken 10 times.
|
117 | if (!actions.empty()) |
| 918 | 107 | break; | |
| 919 | } | ||
| 920 | |||
| 921 |
2/2✓ Branch 0 taken 110 times.
✓ Branch 1 taken 1009 times.
|
1119 | if (!actions.empty()) |
| 922 | 110 | break; | |
| 923 | } | ||
| 924 | |||
| 925 | // A switch that began after the checks above read the player | ||
| 926 | // idle: a start now would replace the playlist being switched to. | ||
| 927 | // Drop this pass's actions, and leave its start to a later one. | ||
| 928 |
5/8✓ Branch 0 taken 110 times.
✓ Branch 1 taken 16276 times.
✓ Branch 2 taken 110 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 110 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 16386 times.
|
16386 | if (!actions.empty() && Player::Switching()) { |
| 929 | ✗ | LogDebug(VB_SCHEDULE, "A playlist switch began, dropping this pass's scheduled actions\n"); | |
| 930 | ✗ | for (const auto& action : actions) { | |
| 931 | ✗ | if (action.type != PlayerAction::Type::StartPlaylist) | |
| 932 | ✗ | continue; | |
| 933 | ✗ | m_startsInFlight.erase({ action.startTime, action.entryIndex }); | |
| 934 | ✗ | if (auto it = m_scheduledItems.find(action.startTime); it != m_scheduledItems.end()) { | |
| 935 | ✗ | for (auto& item : it->second) { | |
| 936 | ✗ | if (item.isPlaylist && (item.entryIndex == action.entryIndex)) | |
| 937 | ✗ | SetItemRan(item, false); | |
| 938 | } | ||
| 939 | } | ||
| 940 | } | ||
| 941 | ✗ | actions.clear(); | |
| 942 | } | ||
| 943 | 16386 | } | |
| 944 | |||
| 945 | { | ||
| 946 | // Clear this pass's in-flight marks however RunPlayerActions() | ||
| 947 | // leaves: every scheduled playlist start waits while any mark is | ||
| 948 | // set, so one leaked by an exception would stop the schedule. | ||
| 949 | struct InFlightGuard { | ||
| 950 | Scheduler* s; | ||
| 951 | const std::vector<PlayerAction>& actions; | ||
| 952 | 16386 | ~InFlightGuard() { | |
| 953 | 16386 | std::unique_lock<std::recursive_mutex> lock(s->m_scheduleLock); | |
| 954 |
2/2✓ Branch 0 taken 111 times.
✓ Branch 1 taken 16386 times.
|
16497 | for (const auto& action : actions) { |
| 955 |
2/2✓ Branch 0 taken 107 times.
✓ Branch 1 taken 4 times.
|
111 | if (action.type == PlayerAction::Type::StartPlaylist) |
| 956 | 107 | s->m_startsInFlight.erase({ action.startTime, action.entryIndex }); | |
| 957 | } | ||
| 958 | 16386 | } | |
| 959 | 16386 | } inFlightGuard{ this, actions }; | |
| 960 |
1/2✓ Branch 0 taken 16386 times.
✗ Branch 1 not taken.
|
16386 | RunPlayerActions(actions); |
| 961 | 16386 | } | |
| 962 |
1/2✓ Branch 0 taken 16386 times.
✗ Branch 1 not taken.
|
16386 | RunCountdownPresets(presets); |
| 963 |
2/2✓ Branch 0 taken 110 times.
✓ Branch 1 taken 16276 times.
|
16386 | } while (!actions.empty()); |
| 964 | |||
| 965 |
2/2✓ Branch 0 taken 61 times.
✓ Branch 1 taken 16215 times.
|
16276 | if (prewarmMs > 0) { |
| 966 |
1/2✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
|
61 | PrewarmMediaOutput(prewarmMs); |
| 967 | } | ||
| 968 | |||
| 969 | // Advance the command catch-up window past every second this call examined. | ||
| 970 | // Done once, after all rescans, so each rescan judges commands against the | ||
| 971 | // same window; within a call the item.ran flag prevents a second firing. | ||
| 972 | // Left unchanged if the clock ran backwards so the window never moves ahead | ||
| 973 | // of the wall clock. | ||
| 974 | // Under the lock: this runs on the main loop and on API threads, and an | ||
| 975 | // unlocked read-compare-write could move the window backwards. | ||
| 976 |
1/2✓ Branch 0 taken 16276 times.
✗ Branch 1 not taken.
|
16276 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 977 |
2/2✓ Branch 0 taken 12773 times.
✓ Branch 1 taken 3503 times.
|
16276 | if (now > m_lastCommandCheckTime) |
| 978 | 12773 | m_lastCommandCheckTime = now; | |
| 979 | 16276 | } | |
| 980 | |||
| 981 | 2740 | void Scheduler::ClearScheduledItems() { | |
| 982 | 2740 | m_scheduledItems.clear(); | |
| 983 | 2740 | } | |
| 984 | |||
| 985 | 124 | void Scheduler::SetItemRan(ScheduledItem& item, bool ran) { | |
| 986 | 124 | item.ran = ran; | |
| 987 | |||
| 988 |
1/2✓ Branch 0 taken 124 times.
✗ Branch 1 not taken.
|
124 | auto& vec = m_ranItems[item.startTime]; |
| 989 |
1/2✓ Branch 0 taken 124 times.
✗ Branch 1 not taken.
|
124 | auto it = std::find_if(vec.begin(), vec.end(), [&](const ScheduledItem& ranItem) { |
| 990 | 40 | return item.command == ranItem.command && | |
| 991 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | item.isPlaylist == ranItem.isPlaylist && |
| 992 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | item.startTime == ranItem.startTime && |
| 993 |
2/2✓ Branch 0 taken 37 times.
✓ Branch 1 taken 3 times.
|
40 | item.endTime == ranItem.endTime && |
| 994 |
2/4✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
|
117 | item.args.size() == ranItem.args.size() && |
| 995 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
77 | SameFirstScheduleArg(item.args, ranItem.args); |
| 996 | }); | ||
| 997 |
2/2✓ Branch 0 taken 37 times.
✓ Branch 1 taken 87 times.
|
124 | if (it != vec.end()) { |
| 998 | 37 | it->ran = ran; | |
| 999 | } else { | ||
| 1000 | // Without the entry pointer: it points into m_Schedule, which the next | ||
| 1001 | // reload frees, while ran-state outlives reloads. | ||
| 1002 | 87 | vec.push_back({ .entry = nullptr, | |
| 1003 | 87 | .priority = item.priority, | |
| 1004 | 87 | .entryIndex = item.entryIndex, | |
| 1005 | .ran = ran, | ||
| 1006 | 87 | .startTime = item.startTime, | |
| 1007 | 87 | .endTime = item.endTime, | |
| 1008 | 87 | .command = item.command, | |
| 1009 | 87 | .args = item.args, | |
| 1010 | 87 | .isPlaylist = item.isPlaylist }); | |
| 1011 | } | ||
| 1012 |
3/10✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 87 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
211 | } |
| 1013 | |||
| 1014 | 2740 | void Scheduler::LoadScheduleFromFile(void) { | |
| 1015 |
3/6✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2740 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2740 times.
✗ Branch 5 not taken.
|
2740 | std::string SCHEDULE_FILE = FPP_DIR_CONFIG("/schedule.json"); |
| 1016 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | LogDebug(VB_SCHEDULE, "Loading Schedule from %s\n", SCHEDULE_FILE.c_str()); |
| 1017 | |||
| 1018 | 2740 | m_loadSchedule = false; | |
| 1019 | // One clock reading for the whole load: every entry and every occurrence | ||
| 1020 | // is placed relative to it, so a load that runs across midnight cannot | ||
| 1021 | // anchor some of them to the old day (or week) and some to the new one. | ||
| 1022 | // The load date comes from the same reading, so a load anchored to the | ||
| 1023 | // old day is redone once the new day is seen. | ||
| 1024 | 2740 | const std::time_t loadTime = std::time(nullptr); | |
| 1025 | { | ||
| 1026 | struct tm lt; | ||
| 1027 | 2740 | localtime_r(&loadTime, <); | |
| 1028 | 2740 | m_lastLoadDate = (lt.tm_year + 1900) * 10000 + (lt.tm_mon + 1) * 100 + lt.tm_mday; | |
| 1029 | } | ||
| 1030 | // Under the lock, like the AddScheduledItems() writes below and the read | ||
| 1031 | // in GetSchedule(), which an API thread makes while this reloads. | ||
| 1032 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 1033 | 2740 | m_schedulesExtendBeyondDistance = false; | |
| 1034 | 2740 | m_Schedule.clear(); | |
| 1035 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | ClearScheduledItems(); |
| 1036 | |||
| 1037 | 2740 | std::string playlistFile; | |
| 1038 | |||
| 1039 | // A player that has never had a schedule has no schedule.json, which is a | ||
| 1040 | // normal state and not worth reading a file for -- an absent file and an | ||
| 1041 | // empty schedule are the same thing to everything below. | ||
| 1042 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | Json::Value sch; |
| 1043 |
3/4✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 244 times.
✓ Branch 3 taken 2496 times.
|
2740 | if (FileExists(SCHEDULE_FILE)) { |
| 1044 |
1/2✓ Branch 0 taken 244 times.
✗ Branch 1 not taken.
|
244 | sch = LoadJsonFromFile(SCHEDULE_FILE, JsonRoot::Array); |
| 1045 | } | ||
| 1046 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | ClearScheduleLoadWarnings(); |
| 1047 |
3/4✓ Branch 0 taken 3172 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 432 times.
✓ Branch 3 taken 2740 times.
|
3172 | for (int i = 0; i < sch.size(); i++) { |
| 1048 |
1/2✓ Branch 0 taken 432 times.
✗ Branch 1 not taken.
|
432 | ScheduleEntry scheduleEntry; |
| 1049 | // jsoncpp throws on a wrong-typed field ("day":"7", an entry that is | ||
| 1050 | // not an object). This runs from the Scheduler constructor and from | ||
| 1051 | // the main loop's reloads with nothing above it to catch, so one bad | ||
| 1052 | // entry took fppd down -- and again on every restart. Skip the entry. | ||
| 1053 | try { | ||
| 1054 |
4/6✓ Branch 0 taken 432 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 430 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 430 times.
|
432 | if (!scheduleEntry.LoadFromJson(sch[i])) |
| 1055 | ✗ | continue; | |
| 1056 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | } catch (const std::exception& ex) { |
| 1057 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | std::string warning = "Schedule entry " + std::to_string(i + 1) + " is invalid and was skipped: " + ex.what(); |
| 1058 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogErr(VB_SCHEDULE, "%s\n", warning.c_str()); |
| 1059 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | ScheduleLoadWarning(47, warning); |
| 1060 | 2 | continue; | |
| 1061 | 2 | } | |
| 1062 | |||
| 1063 |
1/2✓ Branch 0 taken 430 times.
✗ Branch 1 not taken.
|
430 | std::string warning = missingEntryWarning(scheduleEntry); |
| 1064 | |||
| 1065 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 428 times.
|
430 | if (scheduleEntry.sequence) { |
| 1066 |
4/8✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
4 | playlistFile = FPP_DIR_SEQUENCE("/" + scheduleEntry.playlist); |
| 1067 | } else { | ||
| 1068 |
5/10✓ Branch 0 taken 428 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 428 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 428 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 428 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 428 times.
✗ Branch 9 not taken.
|
856 | playlistFile = FPP_DIR_PLAYLIST("/" + scheduleEntry.playlist + ".json"); |
| 1069 | } | ||
| 1070 | |||
| 1071 |
1/2✓ Branch 0 taken 430 times.
✗ Branch 1 not taken.
|
430 | if ((getFPPmode() != PLAYER_MODE) && |
| 1072 |
5/6✓ Branch 0 taken 1 times.
✓ Branch 1 taken 429 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 429 times.
|
431 | (scheduleEntry.enabled) && |
| 1073 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | (!scheduleEntry.playlist.empty())) { |
| 1074 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | std::string warning = std::string("Playlist '") + scheduleEntry.playlist + |
| 1075 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | "' was scheduled but system is running in Remote mode."; |
| 1076 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogWarn(VB_SCHEDULE, "%s\n", warning.c_str()); |
| 1077 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ScheduleLoadWarning(29, warning); |
| 1078 | 1 | continue; | |
| 1079 | 1 | } | |
| 1080 | |||
| 1081 | 1286 | if ((scheduleEntry.enabled) && | |
| 1082 |
6/6✓ Branch 0 taken 427 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 405 times.
✓ Branch 3 taken 22 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 428 times.
|
834 | (!scheduleEntry.playlist.empty()) && |
| 1083 |
3/4✓ Branch 0 taken 405 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 404 times.
|
405 | (!FileExists(playlistFile))) { |
| 1084 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | LogErr(VB_SCHEDULE, "ERROR: Scheduled %s '%s' does not exist\n", |
| 1085 | scheduleEntry.sequence ? "Sequence" : "Playlist", | ||
| 1086 | scheduleEntry.playlist.c_str()); | ||
| 1087 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ScheduleLoadWarning(23, warning); |
| 1088 | 1 | continue; | |
| 1089 | } else { | ||
| 1090 |
2/4✓ Branch 0 taken 428 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 428 times.
✗ Branch 3 not taken.
|
428 | WarningHolder::RemoveWarning(23, warning); |
| 1091 | } | ||
| 1092 | |||
| 1093 |
1/2✓ Branch 0 taken 428 times.
✗ Branch 1 not taken.
|
428 | m_Schedule.push_back(scheduleEntry); |
| 1094 |
4/4✓ Branch 0 taken 428 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 428 times.
✓ Branch 3 taken 4 times.
|
434 | } |
| 1095 | |||
| 1096 |
2/2✓ Branch 0 taken 428 times.
✓ Branch 1 taken 2740 times.
|
3168 | for (int i = 0; i < m_Schedule.size(); i++) { |
| 1097 |
1/2✓ Branch 0 taken 428 times.
✗ Branch 1 not taken.
|
428 | AddScheduledItems(&m_Schedule[i], i, loadTime); |
| 1098 | } | ||
| 1099 | |||
| 1100 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | SchedulePrint(); |
| 1101 | |||
| 1102 |
2/4✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2740 times.
|
2740 | if (WillLog(LOG_EXCESSIVE, VB_SCHEDULE)) |
| 1103 | ✗ | DumpScheduledItems(); | |
| 1104 | |||
| 1105 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | lock.unlock(); |
| 1106 | |||
| 1107 | 5480 | return; | |
| 1108 | 2740 | } | |
| 1109 | |||
| 1110 | 2740 | void Scheduler::SchedulePrint(void) { | |
| 1111 | 2740 | int i = 0; | |
| 1112 | 2740 | char stopTypes[4] = "GHL"; | |
| 1113 | 2740 | std::string dayStr; | |
| 1114 | |||
| 1115 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2728 times.
|
2740 | if (m_schedulerDisabled) |
| 1116 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | LogInfo(VB_SCHEDULE, "WARNING: Scheduler is currently disabled\n"); |
| 1117 | |||
| 1118 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | LogInfo(VB_SCHEDULE, "Current Schedule: (Status: '+' = Enabled, '-' = Disabled, '!' = Outside Date Range, '*' = Repeat, Stop (G)raceful/(L)oop/(H)ard\n"); |
| 1119 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | LogInfo(VB_SCHEDULE, "Stat Start & End Dates Days Start & End Times Playlist/Command\n"); |
| 1120 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | LogInfo(VB_SCHEDULE, "---- ----------------------- ------------- ------------------- ---------------------------------------------\n"); |
| 1121 |
2/2✓ Branch 0 taken 428 times.
✓ Branch 1 taken 2740 times.
|
3168 | for (i = 0; i < m_Schedule.size(); i++) { |
| 1122 |
1/2✓ Branch 0 taken 428 times.
✗ Branch 1 not taken.
|
428 | dayStr = GetDayTextFromDayIndex(m_Schedule[i].dayIndex); |
| 1123 |
14/16✓ Branch 0 taken 22 times.
✓ Branch 1 taken 406 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 406 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 406 times.
✓ Branch 6 taken 281 times.
✓ Branch 7 taken 147 times.
✓ Branch 8 taken 428 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 250 times.
✓ Branch 11 taken 178 times.
✓ Branch 12 taken 425 times.
✓ Branch 13 taken 3 times.
✓ Branch 14 taken 428 times.
✗ Branch 15 not taken.
|
428 | LogInfo(VB_SCHEDULE, "%c%c%c%c %04d-%02d-%02d - %04d-%02d-%02d %-13.13s %-8.8s %c %-8.8s %s\n", |
| 1124 | m_Schedule[i].enabled ? '+' : '-', | ||
| 1125 | CurrentDateInRange(m_Schedule[i].startDate, m_Schedule[i].endDate) ? ' ' : '!', | ||
| 1126 | m_Schedule[i].repeat ? '*' : ' ', | ||
| 1127 | stopTypes[m_Schedule[i].stopType], | ||
| 1128 | (int)(m_Schedule[i].startDate / 10000), | ||
| 1129 | (int)(m_Schedule[i].startDate % 10000 / 100), | ||
| 1130 | (int)(m_Schedule[i].startDate % 100), | ||
| 1131 | (int)(m_Schedule[i].endDate / 10000), | ||
| 1132 | (int)(m_Schedule[i].endDate % 10000 / 100), | ||
| 1133 | (int)(m_Schedule[i].endDate % 100), | ||
| 1134 | dayStr.c_str(), | ||
| 1135 | m_Schedule[i].startTimeStr.c_str(), | ||
| 1136 | m_Schedule[i].playlist.empty() ? ' ' : '-', | ||
| 1137 | m_Schedule[i].playlist.empty() ? "" : m_Schedule[i].endTimeStr.c_str(), | ||
| 1138 | m_Schedule[i].playlist.empty() ? m_Schedule[i].command.c_str() : m_Schedule[i].playlist.c_str()); | ||
| 1139 | } | ||
| 1140 | |||
| 1141 |
1/2✓ Branch 0 taken 2740 times.
✗ Branch 1 not taken.
|
2740 | LogDebug(VB_SCHEDULE, "//////////////////////////////////////////////////\n"); |
| 1142 | 2740 | } | |
| 1143 | |||
| 1144 | 333856 | ScheduledItem* Scheduler::GetNextScheduledPlaylist() { | |
| 1145 | 333856 | std::time_t now = time(nullptr); | |
| 1146 |
1/2✓ Branch 0 taken 333856 times.
✗ Branch 1 not taken.
|
333856 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 1147 | |||
| 1148 |
2/2✓ Branch 0 taken 16520 times.
✓ Branch 1 taken 333297 times.
|
349817 | for (auto& itemTime : m_scheduledItems) { |
| 1149 |
2/2✓ Branch 0 taken 16576 times.
✓ Branch 1 taken 15961 times.
|
32537 | for (auto& item : itemTime.second) { |
| 1150 |
2/2✓ Branch 0 taken 10708 times.
✓ Branch 1 taken 5868 times.
|
16576 | if (item.ran) |
| 1151 | 10708 | continue; // skip over any items that ran already | |
| 1152 | |||
| 1153 |
2/2✓ Branch 0 taken 559 times.
✓ Branch 1 taken 5309 times.
|
5868 | if (item.isPlaylist) |
| 1154 | 559 | return &item; | |
| 1155 | } | ||
| 1156 | } | ||
| 1157 | |||
| 1158 | 333297 | return nullptr; | |
| 1159 | 333856 | } | |
| 1160 | |||
| 1161 | 110812 | std::string Scheduler::GetNextPlaylistName() { | |
| 1162 |
1/2✓ Branch 0 taken 110812 times.
✗ Branch 1 not taken.
|
110812 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 1163 |
2/4✓ Branch 0 taken 110812 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 110812 times.
✗ Branch 3 not taken.
|
221624 | return NextPlaylistNameFor(GetNextScheduledPlaylist()); |
| 1164 | 110812 | } | |
| 1165 | |||
| 1166 | 110812 | std::string Scheduler::GetNextPlaylistStartStr() { | |
| 1167 |
4/8✓ Branch 0 taken 110812 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 110812 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 110812 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 110812 times.
✗ Branch 7 not taken.
|
110812 | std::string timeFmt = getSetting("DateFormat") + " @ " + getSetting("TimeFormat"); |
| 1168 |
1/2✓ Branch 0 taken 110812 times.
✗ Branch 1 not taken.
|
110812 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 1169 |
2/4✓ Branch 0 taken 110812 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 110812 times.
✗ Branch 3 not taken.
|
221624 | return NextPlaylistStartStrFor(GetNextScheduledPlaylist(), timeFmt); |
| 1170 | 110812 | } | |
| 1171 | |||
| 1172 | // The two below take the item GetNextScheduledPlaylist() found, so a caller | ||
| 1173 | // that needs both (GetInfo, polled by every status request) walks the | ||
| 1174 | // scheduled-item list once. Call with m_scheduleLock held. | ||
| 1175 | 223040 | std::string Scheduler::NextPlaylistNameFor(ScheduledItem* item) { | |
| 1176 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 223021 times.
|
223040 | if (m_schedulerDisabled) |
| 1177 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
38 | return "Scheduler is disabled."; |
| 1178 | |||
| 1179 |
2/2✓ Branch 0 taken 222470 times.
✓ Branch 1 taken 551 times.
|
223021 | if (!item) |
| 1180 |
1/2✓ Branch 0 taken 222470 times.
✗ Branch 1 not taken.
|
444940 | return "No playlist scheduled."; |
| 1181 | |||
| 1182 | 551 | return item->entry->playlist; | |
| 1183 | } | ||
| 1184 | |||
| 1185 | 223040 | std::string Scheduler::NextPlaylistStartStrFor(ScheduledItem* item, const std::string& timeFmt) { | |
| 1186 | 223040 | std::string result; | |
| 1187 |
4/4✓ Branch 0 taken 223021 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 222470 times.
✓ Branch 3 taken 551 times.
|
223040 | if (m_schedulerDisabled || !item) |
| 1188 | 222489 | return result; | |
| 1189 | |||
| 1190 | char timeStr[32]; | ||
| 1191 | struct tm timeStruct; | ||
| 1192 | |||
| 1193 | 551 | localtime_r(&item->startTime, &timeStruct); | |
| 1194 | 551 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1195 | |||
| 1196 | // Thursday @ 11:00:00 - (Everyday) | ||
| 1197 |
1/2✓ Branch 0 taken 551 times.
✗ Branch 1 not taken.
|
551 | result = timeStr; |
| 1198 |
1/2✓ Branch 0 taken 551 times.
✗ Branch 1 not taken.
|
551 | result += " - ("; |
| 1199 |
2/4✓ Branch 0 taken 551 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 551 times.
✗ Branch 3 not taken.
|
551 | result += GetDayTextFromDayIndex(item->entry->dayIndex); |
| 1200 |
1/2✓ Branch 0 taken 551 times.
✗ Branch 1 not taken.
|
551 | result += ")"; |
| 1201 | |||
| 1202 | 551 | return result; | |
| 1203 | ✗ | } | |
| 1204 | |||
| 1205 | 47401 | std::string Scheduler::GetDayTextFromDayIndex(const int index) { | |
| 1206 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 47392 times.
|
47401 | if (index & INX_DAY_MASK) { |
| 1207 | char tmpStr[15]; | ||
| 1208 | 9 | strcpy(tmpStr, "Mask: "); | |
| 1209 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | strcat(tmpStr, (index & INX_DAY_MASK_SUNDAY) ? "S" : "-"); |
| 1210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | strcat(tmpStr, (index & INX_DAY_MASK_MONDAY) ? "M" : "-"); |
| 1211 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | strcat(tmpStr, (index & INX_DAY_MASK_TUESDAY) ? "T" : "-"); |
| 1212 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | strcat(tmpStr, (index & INX_DAY_MASK_WEDNESDAY) ? "W" : "-"); |
| 1213 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | strcat(tmpStr, (index & INX_DAY_MASK_THURSDAY) ? "T" : "-"); |
| 1214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | strcat(tmpStr, (index & INX_DAY_MASK_FRIDAY) ? "F" : "-"); |
| 1215 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | strcat(tmpStr, (index & INX_DAY_MASK_SATURDAY) ? "S" : "-"); |
| 1216 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
18 | return tmpStr; |
| 1217 | } | ||
| 1218 | |||
| 1219 |
13/17✓ Branch 0 taken 3 times.
✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 47257 times.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 11 taken 9 times.
✓ Branch 12 taken 9 times.
✓ Branch 13 taken 9 times.
✓ Branch 14 taken 21 times.
✓ Branch 15 taken 9 times.
✗ Branch 16 not taken.
|
47392 | switch (index) { |
| 1220 | 3 | case INX_SUN: | |
| 1221 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
6 | return "Sunday"; |
| 1222 | 35 | case INX_MON: | |
| 1223 |
1/2✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
|
70 | return "Monday"; |
| 1224 | ✗ | case INX_TUE: | |
| 1225 | ✗ | return "Tuesday"; | |
| 1226 | 9 | case INX_WED: | |
| 1227 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
18 | return "Wednesday"; |
| 1228 | ✗ | case INX_THU: | |
| 1229 | ✗ | return "Thursday"; | |
| 1230 | ✗ | case INX_FRI: | |
| 1231 | ✗ | return "Friday"; | |
| 1232 | 4 | case INX_SAT: | |
| 1233 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
8 | return "Saturday"; |
| 1234 | 47257 | case INX_EVERYDAY: | |
| 1235 |
1/2✓ Branch 0 taken 47257 times.
✗ Branch 1 not taken.
|
94514 | return "Everyday"; |
| 1236 | 9 | case INX_WKDAYS: | |
| 1237 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
18 | return "Weekdays"; |
| 1238 | 9 | case INX_WKEND: | |
| 1239 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
18 | return "Weekends"; |
| 1240 | 9 | case INX_M_W_F: | |
| 1241 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
18 | return "Mon/Wed/Fri"; |
| 1242 | 9 | case INX_T_TH: | |
| 1243 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
18 | return "Tues-Thurs"; |
| 1244 | 9 | case INX_SUN_TO_THURS: | |
| 1245 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
18 | return "Sun-Thurs"; |
| 1246 | 9 | case INX_FRI_SAT: | |
| 1247 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
18 | return "Fri/Sat"; |
| 1248 | 21 | case INX_ODD_DAY: | |
| 1249 |
1/2✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
|
42 | return "Odd Days"; |
| 1250 | 9 | case INX_EVEN_DAY: | |
| 1251 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
18 | return "Even Days"; |
| 1252 | } | ||
| 1253 | |||
| 1254 | ✗ | return "Error"; | |
| 1255 | } | ||
| 1256 | |||
| 1257 | 112228 | Json::Value Scheduler::GetInfo(void) { | |
| 1258 |
1/2✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
|
112228 | Json::Value result; |
| 1259 | |||
| 1260 |
4/8✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 112228 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 112228 times.
✗ Branch 7 not taken.
|
112228 | std::string timeFmt = getSetting("DateFormat") + " @ " + getSetting("TimeFormat"); |
| 1261 |
1/2✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
|
112228 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 1262 |
1/2✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
|
112228 | Json::Value np; |
| 1263 |
1/2✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
|
112228 | ScheduledItem* nextItem = GetNextScheduledPlaylist(); |
| 1264 |
3/6✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 112228 times.
✗ Branch 5 not taken.
|
112228 | np["playlistName"] = NextPlaylistNameFor(nextItem); |
| 1265 |
4/6✓ Branch 0 taken 555 times.
✓ Branch 1 taken 111673 times.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 112228 times.
✗ Branch 5 not taken.
|
112228 | np["scheduledStartTime"] = nextItem ? (Json::UInt64)(nextItem->startTime) : 0; |
| 1266 |
3/6✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 112228 times.
✗ Branch 5 not taken.
|
112228 | np["scheduledStartTimeStr"] = NextPlaylistStartStrFor(nextItem, timeFmt); |
| 1267 | |||
| 1268 |
4/6✓ Branch 0 taken 19 times.
✓ Branch 1 taken 112209 times.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 112228 times.
✗ Branch 5 not taken.
|
112228 | result["enabled"] = m_schedulerDisabled ? 0 : 1; |
| 1269 |
2/4✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 112228 times.
✗ Branch 3 not taken.
|
112228 | result["nextPlaylist"] = np; |
| 1270 | |||
| 1271 |
1/2✓ Branch 0 taken 112228 times.
✗ Branch 1 not taken.
|
112228 | if ((Player::INSTANCE.GetStatus() == FPP_STATUS_PLAYLIST_PLAYING) || |
| 1272 |
7/8✓ Branch 0 taken 41228 times.
✓ Branch 1 taken 71000 times.
✓ Branch 2 taken 41228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41067 times.
✓ Branch 5 taken 161 times.
✓ Branch 6 taken 71209 times.
✓ Branch 7 taken 41019 times.
|
153295 | (Player::INSTANCE.GetStatus() == FPP_STATUS_STOPPING_GRACEFULLY) || |
| 1273 |
3/4✓ Branch 0 taken 41067 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 41019 times.
|
41067 | (Player::INSTANCE.GetStatus() == FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP)) { |
| 1274 |
1/2✓ Branch 0 taken 71209 times.
✗ Branch 1 not taken.
|
71209 | Json::Value cp; |
| 1275 | |||
| 1276 |
3/4✓ Branch 0 taken 71209 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✓ Branch 3 taken 68116 times.
|
71209 | if (Player::INSTANCE.WasScheduled()) { |
| 1277 | char timeStr[32]; | ||
| 1278 | 3093 | std::time_t timeT = 0; | |
| 1279 | struct tm timeStruct; | ||
| 1280 | 3093 | time_t currTime = time(NULL); | |
| 1281 | |||
| 1282 | 3093 | localtime_r(&currTime, &timeStruct); | |
| 1283 | 3093 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1284 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["currentTime"] = (Json::UInt64)currTime; |
| 1285 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["currentTimeStr"] = timeStr; |
| 1286 | |||
| 1287 |
1/2✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
|
3093 | timeT = Player::INSTANCE.GetOrigStartTime(); |
| 1288 | 3093 | localtime_r(&timeT, &timeStruct); | |
| 1289 | 3093 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1290 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["scheduledStartTime"] = (Json::UInt64)timeT; |
| 1291 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["scheduledStartTimeStr"] = timeStr; |
| 1292 | |||
| 1293 |
1/2✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
|
3093 | timeT = Player::INSTANCE.GetStartTime(); |
| 1294 | 3093 | localtime_r(&timeT, &timeStruct); | |
| 1295 | 3093 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1296 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["actualStartTime"] = (Json::UInt64)timeT; |
| 1297 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["actualStartTimeStr"] = timeStr; |
| 1298 | |||
| 1299 |
1/2✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
|
3093 | timeT = Player::INSTANCE.GetOrigStopTime(); |
| 1300 | 3093 | localtime_r(&timeT, &timeStruct); | |
| 1301 | 3093 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1302 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["scheduledEndTime"] = (Json::UInt64)timeT; |
| 1303 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["scheduledEndTimeStr"] = timeStr; |
| 1304 | |||
| 1305 |
1/2✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
|
3093 | timeT = Player::INSTANCE.GetStopTime(); |
| 1306 | 3093 | localtime_r(&timeT, &timeStruct); | |
| 1307 | 3093 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1308 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["actualEndTime"] = (Json::UInt64)timeT; |
| 1309 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["actualEndTimeStr"] = timeStr; |
| 1310 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["secondsRemaining"] = (int)(timeT - currTime); |
| 1311 | |||
| 1312 |
1/2✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
|
3093 | int stopType = Player::INSTANCE.GetStopMethod(); |
| 1313 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | cp["stopType"] = stopType; |
| 1314 |
3/4✓ Branch 0 taken 604 times.
✓ Branch 1 taken 2485 times.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
6182 | cp["stopTypeStr"] = stopType == 2 ? "Graceful Loop" : stopType == 1 ? "Hard" |
| 1315 |
3/4✓ Branch 0 taken 3089 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
9275 | : "Graceful"; |
| 1316 | |||
| 1317 |
2/4✓ Branch 0 taken 3093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3093 times.
✗ Branch 3 not taken.
|
3093 | result["status"] = "playing"; |
| 1318 | } else { | ||
| 1319 |
2/4✓ Branch 0 taken 68116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68116 times.
✗ Branch 3 not taken.
|
68116 | result["status"] = "manual"; |
| 1320 | } | ||
| 1321 | |||
| 1322 |
3/6✓ Branch 0 taken 71209 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71209 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 71209 times.
✗ Branch 5 not taken.
|
71209 | cp["playlistName"] = Player::INSTANCE.GetPlaylistName(); |
| 1323 | |||
| 1324 |
2/4✓ Branch 0 taken 71209 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71209 times.
✗ Branch 3 not taken.
|
71209 | result["currentPlaylist"] = cp; |
| 1325 | 71209 | } else { | |
| 1326 |
2/4✓ Branch 0 taken 41019 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41019 times.
✗ Branch 3 not taken.
|
41019 | result["status"] = "idle"; |
| 1327 | } | ||
| 1328 | |||
| 1329 | // Add blocked schedule information | ||
| 1330 |
2/2✓ Branch 0 taken 61 times.
✓ Branch 1 taken 112167 times.
|
112228 | if (m_lastBlockedTime > 0) { |
| 1331 | 61 | time_t now = time(NULL); | |
| 1332 | // Only report if blocked within last 5 minutes | ||
| 1333 |
1/2✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
|
61 | if ((now - m_lastBlockedTime) < 300) { |
| 1334 |
3/6✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 61 times.
✗ Branch 5 not taken.
|
61 | result["blockedSchedule"]["playlistName"] = m_lastBlockedPlaylist; |
| 1335 |
3/6✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 61 times.
✗ Branch 5 not taken.
|
61 | result["blockedSchedule"]["blockedTime"] = (Json::UInt64)m_lastBlockedTime; |
| 1336 | } | ||
| 1337 | } | ||
| 1338 | |||
| 1339 | 112228 | return result; | |
| 1340 | 112228 | } | |
| 1341 | |||
| 1342 | 47264 | Json::Value Scheduler::GetSchedule() { | |
| 1343 |
4/8✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47264 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47264 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 47264 times.
✗ Branch 7 not taken.
|
47264 | std::string timeFmt = getSetting("DateFormat") + " @ " + getSetting("TimeFormat"); |
| 1344 |
1/2✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
|
47264 | Json::Value result; |
| 1345 |
1/2✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
|
47264 | Json::Value entries(Json::arrayValue); |
| 1346 |
1/2✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
|
47264 | Json::Value entry; |
| 1347 |
1/2✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
|
47264 | Json::Value items(Json::arrayValue); |
| 1348 |
1/2✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
|
47264 | Json::Value scheduledItem; |
| 1349 | 47264 | std::time_t now = time(nullptr); | |
| 1350 |
1/2✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
|
47264 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 1351 | |||
| 1352 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 47264 times.
✓ Branch 2 taken 47264 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47264 times.
✗ Branch 5 not taken.
|
47264 | result["enabled"] = m_schedulerDisabled ? 0 : 1; |
| 1353 | |||
| 1354 |
2/2✓ Branch 0 taken 46290 times.
✓ Branch 1 taken 47264 times.
|
93554 | for (int i = 0; i < m_Schedule.size(); i++) { |
| 1355 |
1/2✓ Branch 0 taken 46290 times.
✗ Branch 1 not taken.
|
46290 | entry = m_Schedule[i].GetJson(); |
| 1356 |
2/4✓ Branch 0 taken 46290 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46290 times.
✗ Branch 3 not taken.
|
46290 | entry["id"] = i; |
| 1357 |
4/6✓ Branch 0 taken 4 times.
✓ Branch 1 taken 46286 times.
✓ Branch 2 taken 46290 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46290 times.
✗ Branch 5 not taken.
|
46290 | entry["type"] = m_Schedule[i].playlist.empty() ? "command" : "playlist"; |
| 1358 |
3/6✓ Branch 0 taken 46290 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46290 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46290 times.
✗ Branch 5 not taken.
|
46290 | entry["dayStr"] = GetDayTextFromDayIndex(m_Schedule[i].dayIndex); |
| 1359 | |||
| 1360 |
1/2✓ Branch 0 taken 46290 times.
✗ Branch 1 not taken.
|
46290 | entries.append(entry); |
| 1361 | } | ||
| 1362 |
2/4✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47264 times.
✗ Branch 3 not taken.
|
47264 | result["entries"] = entries; |
| 1363 | |||
| 1364 | struct tm timeStruct; | ||
| 1365 | char timeStr[32]; | ||
| 1366 | time_t tmpTime; | ||
| 1367 | |||
| 1368 |
5/6✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5457 times.
✓ Branch 3 taken 41807 times.
✓ Branch 4 taken 2184 times.
✓ Branch 5 taken 45080 times.
|
52721 | if ((Player::INSTANCE.GetStatus() != FPP_STATUS_IDLE) && |
| 1369 |
3/4✓ Branch 0 taken 5457 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✓ Branch 3 taken 3273 times.
|
5457 | (Player::INSTANCE.WasScheduled())) { |
| 1370 | // If we are playing a scheduled playlist, then insert an item for | ||
| 1371 | // it since it is already marked as ran and will get skipped by. | ||
| 1372 | // We do this here instead of just using a more complicated if continue | ||
| 1373 | // statement below because the player may have more up to date info | ||
| 1374 | // on the end time than our old schedule entry if the end time has | ||
| 1375 | // been extended or shortened. | ||
| 1376 |
3/6✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2184 times.
✗ Branch 5 not taken.
|
2184 | scheduledItem["priority"] = Player::INSTANCE.GetPriority(); |
| 1377 |
3/6✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2184 times.
✗ Branch 5 not taken.
|
2184 | scheduledItem["id"] = Player::INSTANCE.GetScheduleEntry(); |
| 1378 | |||
| 1379 |
1/2✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
|
2184 | tmpTime = Player::INSTANCE.GetOrigStartTime(); |
| 1380 | 2184 | localtime_r(&tmpTime, &timeStruct); | |
| 1381 | 2184 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1382 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["startTimeStr"] = timeStr; |
| 1383 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["startTime"] = (Json::UInt64)tmpTime; |
| 1384 | |||
| 1385 | 2184 | FormatTime(timeStr, sizeof(timeStr), "%Y%m%d", &timeStruct); | |
| 1386 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["startDateStr"] = timeStr; |
| 1387 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["startDateInt"] = atoi(timeStr); |
| 1388 | |||
| 1389 |
1/2✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
|
2184 | tmpTime = Player::INSTANCE.GetStopTime(); |
| 1390 | 2184 | localtime_r(&tmpTime, &timeStruct); | |
| 1391 | 2184 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1392 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["endTimeStr"] = timeStr; |
| 1393 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["endTime"] = (Json::UInt64)tmpTime; |
| 1394 | |||
| 1395 | 2184 | FormatTime(timeStr, sizeof(timeStr), "%Y%m%d", &timeStruct); | |
| 1396 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["endDateStr"] = timeStr; |
| 1397 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["endDateInt"] = atoi(timeStr); |
| 1398 | |||
| 1399 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["command"] = "Start Playlist"; |
| 1400 | |||
| 1401 |
1/2✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
|
2184 | Json::Value args(Json::arrayValue); |
| 1402 |
3/6✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2184 times.
✗ Branch 5 not taken.
|
2184 | args.append(Player::INSTANCE.GetPlaylistName()); |
| 1403 |
2/4✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2184 times.
✗ Branch 3 not taken.
|
2184 | scheduledItem["args"] = args; |
| 1404 | |||
| 1405 |
1/2✓ Branch 0 taken 2184 times.
✗ Branch 1 not taken.
|
2184 | items.append(scheduledItem); |
| 1406 | 2184 | } | |
| 1407 | |||
| 1408 |
2/2✓ Branch 0 taken 50495 times.
✓ Branch 1 taken 47264 times.
|
97759 | for (auto& itemTime : m_scheduledItems) { |
| 1409 |
2/2✓ Branch 0 taken 50563 times.
✓ Branch 1 taken 50495 times.
|
101058 | for (auto& item : itemTime.second) { |
| 1410 |
2/2✓ Branch 0 taken 8747 times.
✓ Branch 1 taken 41816 times.
|
50563 | if (item.ran) |
| 1411 | 8747 | continue; | |
| 1412 | |||
| 1413 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["priority"] = item.priority; |
| 1414 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["id"] = item.entryIndex; |
| 1415 | |||
| 1416 | 41816 | localtime_r(&item.startTime, &timeStruct); | |
| 1417 | 41816 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1418 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["startTimeStr"] = timeStr; |
| 1419 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["startTime"] = (Json::UInt64)item.startTime; |
| 1420 | |||
| 1421 | 41816 | FormatTime(timeStr, sizeof(timeStr), "%Y%m%d", &timeStruct); | |
| 1422 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["startDateStr"] = timeStr; |
| 1423 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["startDateInt"] = atoi(timeStr); |
| 1424 | |||
| 1425 | 41816 | localtime_r(&item.endTime, &timeStruct); | |
| 1426 | 41816 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1427 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["endTimeStr"] = timeStr; |
| 1428 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["endTime"] = (Json::UInt64)item.endTime; |
| 1429 | |||
| 1430 | 41816 | FormatTime(timeStr, sizeof(timeStr), "%Y%m%d", &timeStruct); | |
| 1431 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["endDateStr"] = timeStr; |
| 1432 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["endDateInt"] = atoi(timeStr); |
| 1433 | |||
| 1434 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["command"] = item.command; |
| 1435 | |||
| 1436 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["args"] = item.args; |
| 1437 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["multisyncCommand"] = item.entry->multisyncCommand; |
| 1438 |
2/4✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41816 times.
✗ Branch 3 not taken.
|
41816 | scheduledItem["multisyncHosts"] = item.entry->multisyncHosts; |
| 1439 | |||
| 1440 |
1/2✓ Branch 0 taken 41816 times.
✗ Branch 1 not taken.
|
41816 | items.append(scheduledItem); |
| 1441 | } | ||
| 1442 | } | ||
| 1443 |
2/4✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47264 times.
✗ Branch 3 not taken.
|
47264 | result["items"] = items; |
| 1444 |
2/4✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47264 times.
✗ Branch 3 not taken.
|
47264 | result["schedulesExtendBeyondDistance"] = m_schedulesExtendBeyondDistance; |
| 1445 |
3/6✓ Branch 0 taken 47264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47264 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47264 times.
✗ Branch 5 not taken.
|
47264 | result["scheduleDistance"] = getSettingInt("ScheduleDistance"); |
| 1446 | |||
| 1447 | 47264 | return result; | |
| 1448 | 47264 | } | |
| 1449 | |||
| 1450 | /* | ||
| 1451 | * Expand the configured schedule across an arbitrary date range. | ||
| 1452 | * | ||
| 1453 | * GetSchedule() can only report the rolling window fppd actually schedules out | ||
| 1454 | * (ScheduleDistance days, minus anything already run), which is enough for the | ||
| 1455 | * list preview but not for a calendar the user can page through. This walks | ||
| 1456 | * the range a day at a time and asks each entry which occurrences land on it, | ||
| 1457 | * so any month - past or future - can be rendered from the real schedule rules. | ||
| 1458 | * | ||
| 1459 | * Occurrences are advisory: they describe what the schedule says should happen, | ||
| 1460 | * not what fppd has committed to running. | ||
| 1461 | */ | ||
| 1462 | 206 | Json::Value Scheduler::BuildScheduleRangeItem(const ScheduleEntry& entry, | |
| 1463 | const Occurrence& occurrence, | ||
| 1464 | const std::string& timeFmt) { | ||
| 1465 | struct tm timeStruct; | ||
| 1466 | char timeStr[32]; | ||
| 1467 |
1/2✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
|
206 | Json::Value item; |
| 1468 | |||
| 1469 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["id"] = occurrence.entryIndex; |
| 1470 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["priority"] = occurrence.entryIndex; // priority is entry index for now |
| 1471 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["enabled"] = entry.enabled; |
| 1472 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["overridden"] = occurrence.overridden; |
| 1473 |
5/8✓ Branch 0 taken 38 times.
✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 168 times.
✓ Branch 4 taken 206 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 206 times.
✗ Branch 7 not taken.
|
206 | item["type"] = entry.playlist.empty() ? "command" : (entry.sequence ? "sequence" : "playlist"); |
| 1474 | |||
| 1475 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["startTime"] = (Json::UInt64)occurrence.start; |
| 1476 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["endTime"] = (Json::UInt64)occurrence.end; |
| 1477 | |||
| 1478 | 206 | localtime_r(&occurrence.start, &timeStruct); | |
| 1479 | 206 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1480 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["startTimeStr"] = timeStr; |
| 1481 | 206 | FormatTime(timeStr, sizeof(timeStr), "%Y%m%d", &timeStruct); | |
| 1482 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["startDateStr"] = timeStr; |
| 1483 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["startDateInt"] = atoi(timeStr); |
| 1484 | |||
| 1485 | 206 | localtime_r(&occurrence.end, &timeStruct); | |
| 1486 | 206 | FormatTime(timeStr, sizeof(timeStr), timeFmt.c_str(), &timeStruct); | |
| 1487 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["endTimeStr"] = timeStr; |
| 1488 | 206 | FormatTime(timeStr, sizeof(timeStr), "%Y%m%d", &timeStruct); | |
| 1489 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["endDateStr"] = timeStr; |
| 1490 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["endDateInt"] = atoi(timeStr); |
| 1491 | |||
| 1492 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 168 times.
|
206 | if (entry.playlist.empty()) { |
| 1493 |
2/4✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
|
38 | item["command"] = entry.command; |
| 1494 |
2/4✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
|
38 | item["args"] = entry.args; |
| 1495 | } else { | ||
| 1496 |
1/2✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
|
168 | Json::Value args(Json::arrayValue); |
| 1497 |
2/4✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
|
168 | args.append(entry.playlist); |
| 1498 |
4/6✓ Branch 0 taken 91 times.
✓ Branch 1 taken 77 times.
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 168 times.
✗ Branch 5 not taken.
|
168 | args.append(entry.repeat ? "true" : "false"); |
| 1499 |
2/4✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
|
168 | args.append("false"); |
| 1500 | |||
| 1501 |
2/4✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
|
168 | item["command"] = "Start Playlist"; |
| 1502 |
2/4✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
|
168 | item["args"] = args; |
| 1503 |
2/4✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
|
168 | item["playlist"] = entry.playlist; |
| 1504 | 168 | } | |
| 1505 | |||
| 1506 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["multisyncCommand"] = entry.multisyncCommand; |
| 1507 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["multisyncHosts"] = entry.multisyncHosts; |
| 1508 |
6/8✓ Branch 0 taken 2 times.
✓ Branch 1 taken 204 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 206 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 206 times.
✗ Branch 7 not taken.
|
206 | item["stopTypeStr"] = entry.stopType == 0 ? "Graceful" : (entry.stopType == 1 ? "Hard" : "Graceful Loop"); |
| 1509 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["repeat"] = entry.repeat; |
| 1510 |
2/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 3 not taken.
|
206 | item["repeatInterval"] = entry.repeatInterval; |
| 1511 | |||
| 1512 | 206 | return item; | |
| 1513 | ✗ | } | |
| 1514 | |||
| 1515 | 24 | Json::Value Scheduler::GetScheduleRange(time_t rangeStart, time_t rangeEnd, | |
| 1516 | bool includeDisabled, bool daySummary) { | ||
| 1517 |
4/8✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24 times.
✗ Branch 7 not taken.
|
24 | std::string timeFmt = getSetting("DateFormat") + " @ " + getSetting("TimeFormat"); |
| 1518 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | Json::Value result; |
| 1519 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | Json::Value entries(Json::arrayValue); |
| 1520 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | Json::Value items(Json::arrayValue); |
| 1521 | 24 | std::vector<Occurrence> expanded; | |
| 1522 | 24 | std::vector<Occurrence> playlistWindows; | |
| 1523 | |||
| 1524 | // The walk below steps a day at a time from rangeStart; a start whose | ||
| 1525 | // year doesn't fit in a struct tm makes localtime_r fail and leaves the | ||
| 1526 | // cursor at -1, i.e. trillions of steps. Keep both ends in 1970..9999 | ||
| 1527 | // here rather than trusting every caller to. | ||
| 1528 | static constexpr time_t MAX_RANGE_TIME = 253402300799; // 9999-12-31 23:59:59 UTC | ||
| 1529 |
4/6✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 22 times.
|
24 | if (rangeStart < 0 || rangeEnd < rangeStart || rangeEnd > MAX_RANGE_TIME) { |
| 1530 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | result["entries"] = entries; |
| 1531 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | result["items"] = items; |
| 1532 | 2 | return result; | |
| 1533 | } | ||
| 1534 | |||
| 1535 | // Work from a copy of the schedule so the expansion below never holds the | ||
| 1536 | // scheduler lock. ScheduleProc() takes the same lock to start and stop | ||
| 1537 | // playlists, and expanding a large range takes long enough that holding it | ||
| 1538 | // throughout would delay a show. Copying a handful of entries is cheap. | ||
| 1539 | 22 | std::vector<ScheduleEntry> schedule; | |
| 1540 | { | ||
| 1541 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 1542 | |||
| 1543 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 | result["enabled"] = m_schedulerDisabled ? 0 : 1; |
| 1544 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | schedule = m_Schedule; |
| 1545 | 22 | } | |
| 1546 | |||
| 1547 |
2/2✓ Branch 0 taken 132 times.
✓ Branch 1 taken 22 times.
|
154 | for (int i = 0; i < schedule.size(); i++) { |
| 1548 |
1/2✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
|
132 | Json::Value entry = schedule[i].GetJson(); |
| 1549 |
2/4✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
|
132 | entry["id"] = i; |
| 1550 |
4/6✓ Branch 0 taken 4 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✗ Branch 5 not taken.
|
132 | entry["type"] = schedule[i].playlist.empty() ? "command" : "playlist"; |
| 1551 |
3/6✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✗ Branch 5 not taken.
|
132 | entry["dayStr"] = GetDayTextFromDayIndex(schedule[i].dayIndex); |
| 1552 |
1/2✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
|
132 | entries.append(entry); |
| 1553 | 132 | } | |
| 1554 |
2/4✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
|
22 | result["entries"] = entries; |
| 1555 | |||
| 1556 | struct tm timeStruct; | ||
| 1557 | char timeStr[32]; | ||
| 1558 | |||
| 1559 | // An entry starting late in the day can run past midnight, so start a day | ||
| 1560 | // early to catch occurrences that overlap into the requested range. Walk | ||
| 1561 | // the range from midday to midday: a 23 or 25 hour DST day would otherwise | ||
| 1562 | // let a fixed 86400s step skip or repeat a calendar date. | ||
| 1563 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | if (!localtime_r(&rangeStart, &timeStruct)) { |
| 1564 | ✗ | result["items"] = items; | |
| 1565 | ✗ | return result; | |
| 1566 | } | ||
| 1567 | 22 | timeStruct.tm_hour = 12; | |
| 1568 | 22 | timeStruct.tm_min = 0; | |
| 1569 | 22 | timeStruct.tm_sec = 0; | |
| 1570 | 22 | timeStruct.tm_isdst = -1; | |
| 1571 | 22 | timeStruct.tm_mday -= 1; | |
| 1572 | 22 | time_t cursor = mktime(&timeStruct); | |
| 1573 | |||
| 1574 | // This runs on an API thread for whatever range the calendar asks for; | ||
| 1575 | // what the expansion finds wrong (a year past a lunar table) belongs in | ||
| 1576 | // this response, not in the scheduler's load warnings. | ||
| 1577 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | SchedulePreviewScope previewScope; |
| 1578 |
2/2✓ Branch 0 taken 2380 times.
✓ Branch 1 taken 22 times.
|
2402 | for (; cursor <= (rangeEnd + SECONDS_PER_DAY); cursor += SECONDS_PER_DAY) { |
| 1579 | 2380 | localtime_r(&cursor, &timeStruct); | |
| 1580 | 2380 | int year = timeStruct.tm_year + 1900; | |
| 1581 | 2380 | int month = timeStruct.tm_mon + 1; | |
| 1582 | 2380 | int mday = timeStruct.tm_mday; | |
| 1583 | |||
| 1584 |
2/2✓ Branch 0 taken 23916 times.
✓ Branch 1 taken 2380 times.
|
26296 | for (int i = 0; i < schedule.size(); i++) { |
| 1585 | 23916 | ScheduleEntry& entry = schedule[i]; | |
| 1586 | |||
| 1587 |
4/4✓ Branch 0 taken 9 times.
✓ Branch 1 taken 23907 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 6 times.
|
23916 | if (!entry.enabled && !includeDisabled) |
| 1588 | 3 | continue; | |
| 1589 | |||
| 1590 | 23913 | std::vector<std::pair<time_t, time_t>> occurrences; | |
| 1591 |
1/2✓ Branch 0 taken 23913 times.
✗ Branch 1 not taken.
|
23913 | entry.GetOccurrencesOnDate(year, month, mday, occurrences); |
| 1592 | |||
| 1593 | 23913 | int dayKey = (year * 10000) + (month * 100) + mday; | |
| 1594 | |||
| 1595 |
2/2✓ Branch 0 taken 345 times.
✓ Branch 1 taken 23913 times.
|
24258 | for (auto& occurrence : occurrences) { |
| 1596 | // A command fires at a point in time - only playlists occupy the | ||
| 1597 | // window up to their end time. AddScheduledItems() makes the | ||
| 1598 | // same distinction, so match it or the calendar would draw a | ||
| 1599 | // repeating command as a block instead of a marker. | ||
| 1600 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 278 times.
|
345 | if (entry.playlist.empty()) |
| 1601 | 67 | occurrence.second = occurrence.first; | |
| 1602 | |||
| 1603 | // A playlist's end is exclusive, as everywhere else: one that | ||
| 1604 | // ends at the start of the range (an entry ending at midnight) | ||
| 1605 | // belongs to the previous day, not this range. | ||
| 1606 | 345 | bool span = occurrence.second > occurrence.first; | |
| 1607 | 345 | Occurrence o{ .entryIndex = i, | |
| 1608 | .dayKey = dayKey, | ||
| 1609 | 345 | .start = occurrence.first, | |
| 1610 | 345 | .end = occurrence.second, | |
| 1611 | 345 | .overridden = false }; | |
| 1612 | |||
| 1613 | // Only playlists can override, and a schedule of repeating | ||
| 1614 | // commands can run to tens of thousands of occurrences, so | ||
| 1615 | // collect the playlist windows once rather than rescanning | ||
| 1616 | // everything for every occurrence. Collect them before the | ||
| 1617 | // range test: one from before the range (the day-early walk | ||
| 1618 | // finds it) can still override an occurrence inside it. A | ||
| 1619 | // disabled entry is only here to be shown: the scheduler never | ||
| 1620 | // runs it (AddScheduledItems()), so it overrides nothing. | ||
| 1621 |
6/6✓ Branch 0 taken 278 times.
✓ Branch 1 taken 67 times.
✓ Branch 2 taken 272 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 272 times.
✓ Branch 5 taken 73 times.
|
345 | if (!entry.playlist.empty() && entry.enabled) |
| 1622 |
1/2✓ Branch 0 taken 272 times.
✗ Branch 1 not taken.
|
272 | playlistWindows.push_back(o); |
| 1623 | |||
| 1624 |
6/6✓ Branch 0 taken 278 times.
✓ Branch 1 taken 67 times.
✓ Branch 2 taken 226 times.
✓ Branch 3 taken 52 times.
✓ Branch 4 taken 54 times.
✓ Branch 5 taken 13 times.
|
345 | if ((span ? (occurrence.second <= rangeStart) : (occurrence.second < rangeStart)) || |
| 1625 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 210 times.
|
280 | (occurrence.first > rangeEnd)) |
| 1626 | 135 | continue; | |
| 1627 | |||
| 1628 |
1/2✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
|
210 | expanded.push_back(o); |
| 1629 | } | ||
| 1630 | 23913 | } | |
| 1631 | } | ||
| 1632 | |||
| 1633 | // Flag playlist occurrences the scheduler would skip because a | ||
| 1634 | // higher-priority (lower index) playlist is already running at that point. | ||
| 1635 | |||
| 1636 |
2/2✓ Branch 0 taken 210 times.
✓ Branch 1 taken 22 times.
|
232 | for (auto& occurrence : expanded) { |
| 1637 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 169 times.
|
210 | if (schedule[occurrence.entryIndex].playlist.empty()) |
| 1638 | 41 | continue; | |
| 1639 | |||
| 1640 |
2/2✓ Branch 0 taken 3940 times.
✓ Branch 1 taken 155 times.
|
4095 | for (const auto& window : playlistWindows) { |
| 1641 |
2/2✓ Branch 0 taken 2259 times.
✓ Branch 1 taken 1681 times.
|
3940 | if (window.entryIndex >= occurrence.entryIndex) |
| 1642 | 2259 | continue; | |
| 1643 | |||
| 1644 |
4/4✓ Branch 0 taken 880 times.
✓ Branch 1 taken 801 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 866 times.
|
1681 | if ((window.start <= occurrence.start) && (window.end > occurrence.start)) { |
| 1645 | 14 | occurrence.overridden = true; | |
| 1646 | 14 | break; | |
| 1647 | } | ||
| 1648 | } | ||
| 1649 | } | ||
| 1650 | |||
| 1651 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 19 times.
|
22 | if (daySummary) { |
| 1652 | // Coarse views cannot show hundreds of occurrences per cell and do not | ||
| 1653 | // need to: what matters there is which entries are active on a day. | ||
| 1654 | // Collapse to one item per entry per day and carry the occurrence count | ||
| 1655 | // so the caller can label it; the detail views ask for the full list. | ||
| 1656 | 3 | std::map<std::pair<int, int>, Occurrence> byDay; | |
| 1657 | 3 | std::map<std::pair<int, int>, int> counts; | |
| 1658 | |||
| 1659 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
|
21 | for (const auto& occurrence : expanded) { |
| 1660 | 18 | auto key = std::make_pair(occurrence.dayKey, occurrence.entryIndex); | |
| 1661 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | counts[key]++; |
| 1662 | |||
| 1663 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | auto it = byDay.find(key); |
| 1664 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 4 times.
|
18 | if (it == byDay.end()) { |
| 1665 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | byDay[key] = occurrence; |
| 1666 | } else { | ||
| 1667 | // Span the whole day's activity for this entry | ||
| 1668 | 4 | it->second.start = std::min(it->second.start, occurrence.start); | |
| 1669 | 4 | it->second.end = std::max(it->second.end, occurrence.end); | |
| 1670 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4 | it->second.overridden = it->second.overridden && occurrence.overridden; |
| 1671 | } | ||
| 1672 | } | ||
| 1673 | |||
| 1674 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 3 times.
|
17 | for (const auto& [key, occurrence] : byDay) { |
| 1675 | 14 | Json::Value item = BuildScheduleRangeItem(schedule[occurrence.entryIndex], | |
| 1676 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | occurrence, timeFmt); |
| 1677 |
3/6✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
|
14 | item["count"] = counts[key]; |
| 1678 |
2/4✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
14 | item["summary"] = true; |
| 1679 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | items.append(item); |
| 1680 | 14 | } | |
| 1681 | 3 | } else { | |
| 1682 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 19 times.
|
211 | for (const auto& occurrence : expanded) { |
| 1683 | 192 | Json::Value item = BuildScheduleRangeItem(schedule[occurrence.entryIndex], | |
| 1684 |
1/2✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
|
192 | occurrence, timeFmt); |
| 1685 |
2/4✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
|
192 | item["count"] = 1; |
| 1686 |
2/4✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
|
192 | item["summary"] = false; |
| 1687 |
1/2✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
|
192 | items.append(item); |
| 1688 | 192 | } | |
| 1689 | } | ||
| 1690 | |||
| 1691 |
2/4✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
|
22 | result["items"] = items; |
| 1692 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | if (!previewScope.warnings().empty()) { |
| 1693 | ✗ | Json::Value warnings(Json::arrayValue); | |
| 1694 | ✗ | for (const auto& w : previewScope.warnings()) | |
| 1695 | ✗ | warnings.append(w.second); | |
| 1696 | ✗ | result["warnings"] = warnings; | |
| 1697 | ✗ | } | |
| 1698 |
2/4✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
|
22 | result["rangeStart"] = (Json::UInt64)rangeStart; |
| 1699 |
2/4✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
|
22 | result["rangeEnd"] = (Json::UInt64)rangeEnd; |
| 1700 |
2/4✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
|
22 | result["daySummary"] = daySummary; |
| 1701 |
3/6✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
22 | result["scheduleDistance"] = getSettingInt("ScheduleDistance"); |
| 1702 | |||
| 1703 | 22 | return result; | |
| 1704 | 24 | } | |
| 1705 | |||
| 1706 | 3 | void Scheduler::SetTimeDelta(int delta, int timeLimit) { | |
| 1707 | // Under the schedule lock: the load path reads and resets m_timeDelta | ||
| 1708 | // there, and this runs on the command's thread. | ||
| 1709 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 1710 | 3 | m_timeDelta = m_timeDelta + delta; | |
| 1711 | 3 | m_timeDeltaThreshold = time(NULL) + timeLimit; | |
| 1712 | // Trigger a reload the next time Scheduler::ScheduleProc() is called | ||
| 1713 | 3 | m_loadSchedule = true; | |
| 1714 | 3 | } | |
| 1715 | |||
| 1716 | 4 | bool Scheduler::StartNextScheduledItemNow() { | |
| 1717 | // Decide under the lock and copy everything the player calls need, then | ||
| 1718 | // release it before calling the player. See Scheduler.h for why. | ||
| 1719 | 4 | std::vector<PlayerAction> actions; | |
| 1720 | |||
| 1721 | { | ||
| 1722 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | std::unique_lock<std::recursive_mutex> lock(m_scheduleLock); |
| 1723 | |||
| 1724 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | ScheduledItem* item = GetNextScheduledPlaylist(); |
| 1725 | |||
| 1726 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!item) |
| 1727 | ✗ | return false; | |
| 1728 | |||
| 1729 |
3/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
|
4 | if (Player::INSTANCE.GetStatus() != FPP_STATUS_IDLE) { |
| 1730 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogDebug(VB_SCHEDULE, "Force-Stopping running playlist\n"); |
| 1731 | 2 | actions.push_back({ .type = PlayerAction::Type::StopUntilIdle, | |
| 1732 | .forceStop = 1 }); | ||
| 1733 | } | ||
| 1734 | |||
| 1735 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | LogDebug(VB_SCHEDULE, "Force-Starting next scheduled playlist now:\n"); |
| 1736 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | DumpScheduledItem(item->startTime, *item); |
| 1737 | |||
| 1738 | 4 | actions.push_back({ .type = PlayerAction::Type::StartPlaylist, | |
| 1739 | 4 | .playlist = item->entry->playlist, | |
| 1740 | .position = 0, | ||
| 1741 | 4 | .repeat = item->entry->repeat, | |
| 1742 | 4 | .entryIndex = item->entryIndex, | |
| 1743 | 4 | .priority = item->entryIndex, // priority is entry index for now | |
| 1744 | 4 | .startTime = time(NULL), | |
| 1745 | 4 | .endTime = item->endTime, | |
| 1746 | 4 | .stopType = item->entry->stopType }); | |
| 1747 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | } |
| 1748 | |||
| 1749 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | RunPlayerActions(actions); |
| 1750 | |||
| 1751 | 4 | return true; | |
| 1752 |
3/10✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
10 | } |
| 1753 | |||
| 1754 | class ScheduleCommand : public Command { | ||
| 1755 | public: | ||
| 1756 | 5304 | ScheduleCommand(const std::string& str, Scheduler* s) : | |
| 1757 | Command(str), | ||
| 1758 | 5304 | sched(s) {} | |
| 1759 | 10480 | virtual ~ScheduleCommand() {} | |
| 1760 | |||
| 1761 | Scheduler* sched; | ||
| 1762 | }; | ||
| 1763 | |||
| 1764 | class StartNextItemCommand : public ScheduleCommand { | ||
| 1765 | public: | ||
| 1766 | 2652 | StartNextItemCommand(Scheduler* s) : | |
| 1767 |
2/4✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
|
5304 | ScheduleCommand("Start Next Scheduled Item", s) { |
| 1768 | 2652 | } | |
| 1769 | |||
| 1770 | 4 | virtual std::unique_ptr<Command::Result> run(const std::vector<std::string>& args) override { | |
| 1771 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (sched->StartNextScheduledItemNow()) |
| 1772 | 4 | return std::make_unique<Command::Result>("Next scheduled item started"); | |
| 1773 | else | ||
| 1774 | ✗ | return std::make_unique<Command::Result>("Unable to start next scheduled item"); | |
| 1775 | } | ||
| 1776 | }; | ||
| 1777 | |||
| 1778 | // Command arguments arrive as strings after %VAR% replacement, so an unset | ||
| 1779 | // variable hands us "" and a typo hands us anything at all. std::stoi() throws | ||
| 1780 | // on both, and these commands run on a detached scheduler thread. | ||
| 1781 | 21 | static bool ParseIntArg(const std::string& str, int& out) { | |
| 1782 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
|
21 | if (str.empty()) { |
| 1783 | 1 | return false; | |
| 1784 | } | ||
| 1785 | |||
| 1786 | 20 | const char* start = str.c_str(); | |
| 1787 | 20 | char* end = nullptr; | |
| 1788 | 20 | errno = 0; | |
| 1789 | 20 | long v = strtol(start, &end, 10); | |
| 1790 | |||
| 1791 | // "Consumed nothing" has to be decided BEFORE the trailing-whitespace skip | ||
| 1792 | // below moves `end`: strtol() skips leading whitespace itself, so an | ||
| 1793 | // all-whitespace argument leaves end == start with v == 0, and skipping | ||
| 1794 | // first walks end to the terminator and makes the test pass -- reporting a | ||
| 1795 | // successful parse of 0 for an argument that held no number at all. | ||
| 1796 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
|
20 | if (end == start) { |
| 1797 | 2 | return false; | |
| 1798 | } | ||
| 1799 | |||
| 1800 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
|
18 | while ((*end == ' ') || (*end == '\t')) { |
| 1801 | ✗ | end++; | |
| 1802 | } | ||
| 1803 | |||
| 1804 |
4/6✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✗ Branch 5 not taken.
|
18 | if ((*end != '\0') || (errno == ERANGE) || |
| 1805 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | (v < INT_MIN) || (v > INT_MAX)) { |
| 1806 | 1 | return false; | |
| 1807 | } | ||
| 1808 | |||
| 1809 | 17 | out = (int)v; | |
| 1810 | 17 | return true; | |
| 1811 | } | ||
| 1812 | |||
| 1813 | class ExtendScheduleCommand : public ScheduleCommand { | ||
| 1814 | public: | ||
| 1815 | 2652 | ExtendScheduleCommand(Scheduler* s) : | |
| 1816 |
2/4✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
|
5304 | ScheduleCommand("Extend Schedule", s) { |
| 1817 |
6/12✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
|
15912 | args.push_back(CommandArg("Seconds", "int", "Extend for Seconds").setRange(-12 * 60 * 60, 12 * 60 * 60).setDefaultValue("300").setAdjustable()); |
| 1818 |
6/12✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
|
15912 | args.push_back(CommandArg("Limit", "int", "For schedule events occurring in the next x Seconds").setRange(-12 * 60 * 60, 12 * 60 * 60).setDefaultValue("0").setAdjustable()); |
| 1819 | 2652 | } | |
| 1820 | |||
| 1821 | 13 | virtual std::unique_ptr<Command::Result> run(const std::vector<std::string>& args) override { | |
| 1822 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (args.size() < 1) { |
| 1823 | ✗ | return std::make_unique<Command::ErrorResult>("Command needs at least 1 argument, found " + std::to_string(args.size())); | |
| 1824 | } | ||
| 1825 | 13 | int seconds = 0; | |
| 1826 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9 times.
|
13 | if (!ParseIntArg(args[0], seconds)) { |
| 1827 |
3/6✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | return std::make_unique<Command::ErrorResult>("Seconds argument '" + args[0] + "' is not a number"); |
| 1828 | } | ||
| 1829 | |||
| 1830 | 9 | int limit = 0; | |
| 1831 |
5/8✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 9 times.
|
9 | if ((args.size() > 1) && !args[1].empty() && !ParseIntArg(args[1], limit)) { |
| 1832 | ✗ | return std::make_unique<Command::ErrorResult>("Limit argument '" + args[1] + "' is not a number"); | |
| 1833 | } | ||
| 1834 | |||
| 1835 |
2/4✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | if (Player::INSTANCE.AdjustPlaylistStopTime(seconds)) { |
| 1836 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
|
9 | if (limit != 0) { |
| 1837 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | scheduler->SetTimeDelta(seconds, limit); |
| 1838 | } | ||
| 1839 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | return std::make_unique<Command::Result>("Schedule Updated"); |
| 1840 | } | ||
| 1841 | ✗ | return std::make_unique<Command::Result>("Error extending Schedule"); | |
| 1842 | } | ||
| 1843 | }; | ||
| 1844 | |||
| 1845 | 2652 | void Scheduler::RegisterCommands() { | |
| 1846 |
6/12✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2357 times.
✓ Branch 7 taken 295 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2357 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
5599 | CommandManager::INSTANCE.addCategorizedCommand(new StartNextItemCommand(this), "Playlist", 1); |
| 1847 |
6/12✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2357 times.
✓ Branch 7 taken 295 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2357 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
3242 | CommandManager::INSTANCE.addCategorizedCommand(new ExtendScheduleCommand(this), "Playlist", 1); |
| 1848 | 2652 | } | |
| 1849 |