Skip to content

Commit

Permalink
Add manager clearing mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
seanavery authored and bazile-clyde committed Oct 17, 2023
1 parent 68092af commit 3c9fee9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/driver/camera/camera_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ func init() {

// Initialize finds and registers camera devices. This is part of an experimental API.
func Initialize() {
// Clear all registered camera devices to prevent duplicates.
// If first initalize call, this will be a noop.
manager := driver.GetManager()
for _, d := range manager.Query(driver.FilterVideoRecorder()) {
manager.Delete(d.ID())
}
discovered := make(map[string]struct{})
discover(discovered, "/dev/v4l/by-id/*")
discover(discovered, "/dev/v4l/by-path/*")
Expand Down
7 changes: 7 additions & 0 deletions pkg/driver/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,10 @@ func (m *Manager) Query(f FilterFn) []Driver {

return results
}

// Delete deletes a driver from manager given its ID
func (m *Manager) Delete(id string) {
m.mu.Lock()
defer m.mu.Unlock()
delete(m.drivers, id)
}

0 comments on commit 3c9fee9

Please sign in to comment.