Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/Tizen.Multimedia.Recorder/Recorder/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

using System;
using System.Diagnostics;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Native = Interop.Recorder;
using NativeHandle = Interop.RecorderHandle;
Expand Down Expand Up @@ -110,18 +110,40 @@ protected virtual void Dispose(bool disposing)
#endregion Dispose support

#region State validation
internal void ValidateState(RecorderState required)
{
var curState = _state;
if (curState != required)
{
ThrowInvalidState(curState, required);
}
}

internal void ValidateState(RecorderState required1, RecorderState required2)
{
var curState = _state;
if (curState != required1 && curState != required2)
{
ThrowInvalidState(curState, required1, required2);
}
}

internal void ValidateState(params RecorderState[] required)
{
Debug.Assert(required.Length > 0);

var curState = _state;
if (!required.Contains(curState))
if (Array.IndexOf(required, curState) < 0)
{
throw new InvalidOperationException("The recorder is not in a valid state. " +
$"Current State : { curState }, Valid State : { string.Join(", ", required) }.");
ThrowInvalidState(curState, required);
}
}

[DoesNotReturn]
private static void ThrowInvalidState(RecorderState curState, params RecorderState[] required)
=> throw new InvalidOperationException("The recorder is not in a valid state. " +
$"Current State : { curState }, Valid State : { string.Join(", ", required) }.");

private void SetState(RecorderState state)
{
_state = state;
Expand Down
Loading