CriticalEventLog.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // CriticalEventLog.swift
  3. // LoopKit
  4. //
  5. // Created by Darin Krauss on 7/15/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import Foundation
  9. public protocol CriticalEventLog {
  10. /// The name for the critical event log export.
  11. var exportName: String { get }
  12. /// Calculate the progress total unit count for the critical event log export for the specified date range.
  13. ///
  14. /// - Parameters:
  15. /// - startDate: The start date for the critical events to export.
  16. /// - endDate: The end date for the critical events to export. Optional. If not specified, default to now.
  17. /// - Returns: An progress total unit count, or an error.
  18. func exportProgressTotalUnitCount(startDate: Date, endDate: Date?) -> Result<Int64, Error>
  19. /// Export the critical event log for the specified date range.
  20. ///
  21. /// - Parameters:
  22. /// - startDate: The start date for the critical events to export.
  23. /// - endDate: The end date for the critical events to export.
  24. /// - stream: The output stream to write the critical event log to. Typically writes JSON UTF-8 text.
  25. /// - progressor: The estimated duration progress to use to check if cancelled and report progress.
  26. /// - Returns: Any error that occurs during the export, or nil if successful.
  27. func export(startDate: Date, endDate: Date, to stream: OutputStream, progress: Progress) -> Error?
  28. }
  29. public enum CriticalEventLogError: Error {
  30. /// The export was cancelled either by the user or the OS.
  31. case cancelled
  32. }
  33. public let criticalEventLogExportProgressUnitCountPerFetch: Int64 = 250