Skip to content

Commit

Permalink
(imp) flutter: exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Dec 17, 2024
1 parent 06d5153 commit cad9404
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 39 deletions.
40 changes: 20 additions & 20 deletions flutter/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.19.0"
cross_file:
dependency: "direct main"
description:
Expand Down Expand Up @@ -123,18 +123,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
url: "https://pub.dev"
source: hosted
version: "10.0.5"
version: "10.0.7"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
version: "3.0.8"
leak_tracker_testing:
dependency: transitive
description:
Expand All @@ -147,10 +147,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
sha256: "4a16b3f03741e1252fda5de3ce712666d010ba2122f8e912c94f9f7b90e1a4c3"
url: "https://pub.dev"
source: hosted
version: "5.0.0"
version: "5.1.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -259,7 +259,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
version: "0.0.0"
source_span:
dependency: transitive
description:
Expand All @@ -272,10 +272,10 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.12.0"
stream_channel:
dependency: transitive
description:
Expand All @@ -288,10 +288,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.3.0"
sync_http:
dependency: transitive
description:
Expand All @@ -312,10 +312,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.7.3"
uvccamera:
dependency: "direct main"
description:
Expand All @@ -335,10 +335,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
url: "https://pub.dev"
source: hosted
version: "14.2.5"
version: "14.3.0"
web:
dependency: transitive
description:
Expand All @@ -351,10 +351,10 @@ packages:
dependency: transitive
description:
name: webdriver
sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e"
sha256: "3d773670966f02a646319410766d3b5e1037efb7f07cc68f844d5e06cd4d61c8"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "3.0.4"
sdks:
dart: ">=3.5.4 <4.0.0"
dart: ">=3.6.0-0 <4.0.0"
flutter: ">=3.24.0"
38 changes: 19 additions & 19 deletions flutter/lib/src/uvccamera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import 'package:cross_file/cross_file.dart';
import 'package:flutter/widgets.dart';

import 'uvccamera_button_event.dart';
import 'uvccamera_controller_disposed_exception.dart';
import 'uvccamera_controller_illegal_state_exception.dart';
import 'uvccamera_controller_initialized_exception.dart';
import 'uvccamera_controller_not_initialized_exception.dart';
import 'uvccamera_controller_state.dart';
import 'uvccamera_device.dart';
import 'uvccamera_mode.dart';
Expand Down Expand Up @@ -45,8 +49,11 @@ class UvcCameraController extends ValueNotifier<UvcCameraControllerState> {

/// Initializes the controller on the specified device.
Future<void> _initialize(UvcCameraDevice device) async {
if (_initializeFuture != null) {
throw UvcCameraControllerInitializedException();
}
if (_isDisposed) {
throw Exception('UvcCameraController is disposed');
throw UvcCameraControllerDisposedException();
}

final Completer<void> initializeCompleter = Completer<void>();
Expand All @@ -58,15 +65,11 @@ class UvcCameraController extends ValueNotifier<UvcCameraControllerState> {
resolutionPreset,
);

_textureId = await UvcCameraPlatformInterface.instance
.getCameraTextureId(_cameraId!);
final previewMode =
await UvcCameraPlatformInterface.instance.getPreviewMode(_cameraId!);
_textureId = await UvcCameraPlatformInterface.instance.getCameraTextureId(_cameraId!);
final previewMode = await UvcCameraPlatformInterface.instance.getPreviewMode(_cameraId!);

_cameraStatusEventStream = await UvcCameraPlatformInterface.instance
.attachToCameraStatusCallback(_cameraId!);
_cameraButtonEventStream = await UvcCameraPlatformInterface.instance
.attachToCameraButtonCallback(_cameraId!);
_cameraStatusEventStream = await UvcCameraPlatformInterface.instance.attachToCameraStatusCallback(_cameraId!);
_cameraButtonEventStream = await UvcCameraPlatformInterface.instance.attachToCameraButtonCallback(_cameraId!);

value = value.copyWith(
isInitialized: true,
Expand Down Expand Up @@ -94,16 +97,14 @@ class UvcCameraController extends ValueNotifier<UvcCameraControllerState> {

if (_cameraButtonEventStream != null) {
if (_cameraId != null) {
await UvcCameraPlatformInterface.instance
.detachFromCameraButtonCallback(_cameraId!);
await UvcCameraPlatformInterface.instance.detachFromCameraButtonCallback(_cameraId!);
}
_cameraButtonEventStream = null;
}

if (_cameraStatusEventStream != null) {
if (_cameraId != null) {
await UvcCameraPlatformInterface.instance
.detachFromCameraStatusCallback(_cameraId!);
await UvcCameraPlatformInterface.instance.detachFromCameraStatusCallback(_cameraId!);
}
_cameraStatusEventStream = null;
}
Expand Down Expand Up @@ -145,11 +146,10 @@ class UvcCameraController extends ValueNotifier<UvcCameraControllerState> {
_ensureInitializedNotDisposed();

if (value.isRecordingVideo) {
throw Exception('UvcCameraController is already recording video');
throw UvcCameraControllerIllegalStateException('UvcCameraController is already recording video');
}

final XFile videoRecordingFile =
await UvcCameraPlatformInterface.instance.startVideoRecording(
final XFile videoRecordingFile = await UvcCameraPlatformInterface.instance.startVideoRecording(
_cameraId!,
videoRecordingMode,
);
Expand All @@ -166,7 +166,7 @@ class UvcCameraController extends ValueNotifier<UvcCameraControllerState> {
_ensureInitializedNotDisposed();

if (!value.isRecordingVideo) {
throw Exception('UvcCameraController is not recording video');
throw UvcCameraControllerIllegalStateException('UvcCameraController is not recording video');
}

await UvcCameraPlatformInterface.instance.stopVideoRecording(_cameraId!);
Expand All @@ -192,10 +192,10 @@ class UvcCameraController extends ValueNotifier<UvcCameraControllerState> {
/// Ensures that the controller is initialized and not disposed.
void _ensureInitializedNotDisposed() {
if (_isDisposed) {
throw Exception('UvcCameraController is disposed');
throw UvcCameraControllerDisposedException();
}
if (_initializeFuture == null) {
throw Exception('UvcCameraController is not initialized');
throw UvcCameraControllerNotInitializedException();
}
}
}
6 changes: 6 additions & 0 deletions flutter/lib/src/uvccamera_controller_disposed_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'uvccamera_exception.dart';

/// Exception thrown when the [UvcCameraController] is disposed yet an operation is attempted.
class UvcCameraControllerDisposedException extends UvcCameraException {
const UvcCameraControllerDisposedException() : super('UvcCameraController is disposed');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'uvccamera_exception.dart';

/// Exception thrown when the [UvcCameraController] is in an illegal state.
class UvcCameraControllerIllegalStateException extends UvcCameraException {
const UvcCameraControllerIllegalStateException([
super.message,
]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'uvccamera_exception.dart';

/// Exception thrown when the [UvcCameraController] is already initialized.
class UvcCameraControllerInitializedException extends UvcCameraException {
const UvcCameraControllerInitializedException() : super('UvcCameraController is already initialized');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'uvccamera_exception.dart';

/// Exception thrown when the [UvcCameraController] is not initialized yet an operation is attempted.
class UvcCameraControllerNotInitializedException extends UvcCameraException {
const UvcCameraControllerNotInitializedException() : super('UvcCameraController is not initialized');
}
12 changes: 12 additions & 0 deletions flutter/lib/src/uvccamera_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// UVC Camera Exception
class UvcCameraException implements Exception {
final dynamic message;

const UvcCameraException([this.message]);

@override
String toString() {
if (message == null) return runtimeType.toString();
return "$runtimeType: $message";
}
}
5 changes: 5 additions & 0 deletions flutter/lib/uvccamera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ library;
export 'src/uvccamera.dart' show UvcCamera;
export 'src/uvccamera_button_event.dart' show UvcCameraButtonEvent;
export 'src/uvccamera_controller.dart' show UvcCameraController;
export 'src/uvccamera_controller_disposed_exception.dart' show UvcCameraControllerDisposedException;
export 'src/uvccamera_controller_illegal_state_exception.dart' show UvcCameraControllerIllegalStateException;
export 'src/uvccamera_controller_initialized_exception.dart' show UvcCameraControllerInitializedException;
export 'src/uvccamera_controller_not_initialized_exception.dart' show UvcCameraControllerNotInitializedException;
export 'src/uvccamera_controller_state.dart' show UvcCameraControllerState;
export 'src/uvccamera_device.dart' show UvcCameraDevice;
export 'src/uvccamera_device_event.dart' show UvcCameraDeviceEvent;
export 'src/uvccamera_device_event_type.dart' show UvcCameraDeviceEventType;
export 'src/uvccamera_exception.dart' show UvcCameraException;
export 'src/uvccamera_frame_format.dart' show UvcCameraFrameFormat;
export 'src/uvccamera_mode.dart' show UvcCameraMode;
export 'src/uvccamera_preview.dart' show UvcCameraPreview;
Expand Down

0 comments on commit cad9404

Please sign in to comment.