-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pollable api to get offload status from tc2-agent – which can in …
…the future give percent complete and time-remaining estimates, but for now returns zero for those fields as changes are needed to tc2-firmware.
- Loading branch information
1 parent
1f5715b
commit 49c3a9e
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
management-interface - Web based management of Raspberry Pis over WiFi | ||
Copyright (C) 2019, The Cacophony Project | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
func (api *ManagementAPI) RecordingOffloadStatus(w http.ResponseWriter, r *http.Request) { | ||
tc2AgentDbus, err := getTC2AgentDbus() | ||
if err != nil { | ||
log.Println(err) | ||
http.Error(w, "Failed to connect to DBus", http.StatusInternalServerError) | ||
return | ||
} | ||
type OffloadNotInProgress struct { | ||
InProgress bool `json:"offload-in-progress"` | ||
} | ||
type OffloadInProgress struct { | ||
InProgress bool `json:"offload-in-progress"` | ||
SecondsRemaining int `json:"seconds-remaining"` | ||
PercentComplete int `json:"percent-complete"` | ||
} | ||
|
||
var isOffloading int | ||
var percentComplete int | ||
var secondsRemaining int | ||
err = tc2AgentDbus.Call("org.cacophony.TC2Agent.offloadstatus", 0).Store(&isOffloading, &percentComplete, &secondsRemaining) | ||
if err != nil { | ||
log.Println(err) | ||
http.Error(w, "Failed to request recording offload status", http.StatusInternalServerError) | ||
return | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
if isOffloading == 1 { | ||
json.NewEncoder(w).Encode(OffloadInProgress{ | ||
InProgress: true, | ||
PercentComplete: percentComplete, | ||
SecondsRemaining: secondsRemaining, | ||
}) | ||
} else { | ||
json.NewEncoder(w).Encode(OffloadNotInProgress{ | ||
InProgress: false, | ||
}) | ||
} | ||
|
||
} |