Closes #34 Implement MIDI peripherals
Implement device concept
Cleaning project

Reviewed-on: #35
This commit was merged in pull request #35.
This commit is contained in:
2025-12-02 18:02:17 +00:00
parent 932c288a9c
commit 4fbb75ad19
42 changed files with 1638 additions and 1564 deletions

View File

@@ -0,0 +1,37 @@
package hardware
import (
"context"
"fmt"
"github.com/rs/zerolog/log"
)
// Provider represents how compatible endpoint drivers are implemented
type Provider interface {
Initialize() error // Initializes the protocol
Create(ctx context.Context, endpointInfo EndpointInfo) (EndpointInfo, error) // Manually create a endpoint
Remove(ctx context.Context, endpoint Endpoint) error // Manually remove a endpoint
OnArrival(cb func(context.Context, Endpoint)) // Callback function when a endpoint arrives
OnRemoval(cb func(context.Context, Endpoint)) // Callback function when a endpoint goes away
Start(context.Context) error // Start the detection
WaitStop() error // Waiting for provider to close
GetName() string // Get the name of the provider
}
// GetProvider returns a register provider
func (h *Manager) GetProvider(providerName string) (Provider, error) {
provider, exists := h.providers[providerName]
if !exists {
log.Error().Str("file", "hardware").Str("providerName", providerName).Msg("unable to get the provider")
return nil, fmt.Errorf("unable to locate the '%s' provider", providerName)
}
log.Debug().Str("file", "hardware").Str("providerName", providerName).Msg("got provider")
return provider, nil
}
// RegisterProvider registers a new endpoints provider
func (h *Manager) RegisterProvider(provider Provider) {
h.providers[provider.GetName()] = provider
log.Info().Str("file", "hardware").Str("providerName", provider.GetName()).Msg("provider registered")
}