common: Implement Logger::has_recording().
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Jan 2020 14:14:13 +0000 (15:14 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Jan 2020 20:00:04 +0000 (21:00 +0100)
src/common/logger.rs

index 2154a01b7fd901fb24e2d68e900d3d44099449b2..029cc9a473466f52b346762b3568e8eda4e1a514 100644 (file)
@@ -570,6 +570,21 @@ impl<'a> Logger<'a> {
         self.write_buffer_offset += num_bytes_written;
     }
 
+    ///
+    /// Check whether or not recording @p recording_id exists.
+    pub fn has_recording(&mut self, recording_id: u16) -> bool {
+        if recording_id == 0 {
+            return false;
+        }
+
+        self.sector_header_iter().find(|&index| {
+            let sector_header = &self.sector_header[index as usize];
+
+            sector_header.recording_id == recording_id &&
+            sector_header.starts_recording()
+        }).is_some()
+    }
+
     ///
     /// Retrieve recording @p recording_id and
     /// write it to @p tx_buf in yencoded form.