Skip to content

Commit

Permalink
Refactor libusb_xxx.dart to libusb32.dart & libusb64.dart
Browse files Browse the repository at this point in the history
Signed-off-by: wangkun <[email protected]>
  • Loading branch information
wangkun committed Feb 9, 2021
1 parent afabb0f commit 48638d2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4,171 deletions.
6 changes: 1 addition & 5 deletions example/listDeviceProducts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import 'dart:ffi';
import 'dart:io';

import 'package:ffi/ffi.dart' as ffi;

// git update-index --assume-unchanged example/listdevs.dart
// import 'package:libusb/libusb_windows.dart';
// import 'package:libusb/libusb_macos.dart';
// import 'package:libusb/libusb_linux.dart';
import 'package:libusb/libusb64.dart'; // if (Platform.isMacOS) 'package:libusb/libusb32.dart

final DynamicLibrary Function() loadLibrary = () {
if (Platform.isWindows) {
Expand Down
6 changes: 1 addition & 5 deletions example/listdevs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import 'dart:io';

import 'package:ffi/ffi.dart' as ffi;
import 'package:convert/convert.dart';

// git update-index --assume-unchanged example/listdevs.dart
// import 'package:libusb/libusb_windows.dart';
// import 'package:libusb/libusb_macos.dart';
// import 'package:libusb/libusb_linux.dart';
import 'package:libusb/libusb64.dart'; // if (Platform.isMacOS) 'package:libusb/libusb32.dart

final DynamicLibrary Function() loadLibrary = () {
if (Platform.isWindows) {
Expand Down
32 changes: 16 additions & 16 deletions lib/libusb_macos.dart → lib/libusb32.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ class Libusb {

int libusb_wait_for_event(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
) {
_libusb_wait_for_event ??= _dylib.lookupFunction<_c_libusb_wait_for_event,
_dart_libusb_wait_for_event>('libusb_wait_for_event');
Expand All @@ -1636,7 +1636,7 @@ class Libusb {

int libusb_handle_events_timeout(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
) {
_libusb_handle_events_timeout ??= _dylib.lookupFunction<
_c_libusb_handle_events_timeout,
Expand All @@ -1651,7 +1651,7 @@ class Libusb {

int libusb_handle_events_timeout_completed(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
ffi.Pointer<ffi.Int32> completed,
) {
_libusb_handle_events_timeout_completed ??= _dylib.lookupFunction<
Expand Down Expand Up @@ -1697,7 +1697,7 @@ class Libusb {

int libusb_handle_events_locked(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
) {
_libusb_handle_events_locked ??= _dylib.lookupFunction<
_c_libusb_handle_events_locked,
Expand Down Expand Up @@ -1725,7 +1725,7 @@ class Libusb {

int libusb_get_next_timeout(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
) {
_libusb_get_next_timeout ??= _dylib.lookupFunction<
_c_libusb_get_next_timeout,
Expand Down Expand Up @@ -2843,7 +2843,7 @@ abstract class libusb_log_cb_mode {
static const int LIBUSB_LOG_CB_CONTEXT = 2;
}

class timeval extends ffi.Struct {
class timeval32 extends ffi.Struct {
@ffi.Int64()
int tv_sec;

Expand Down Expand Up @@ -3953,33 +3953,33 @@ typedef _dart_libusb_unlock_event_waiters = void Function(

typedef _c_libusb_wait_for_event = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
);

typedef _dart_libusb_wait_for_event = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
);

typedef _c_libusb_handle_events_timeout = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
);

typedef _dart_libusb_handle_events_timeout = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
);

typedef _c_libusb_handle_events_timeout_completed = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
ffi.Pointer<ffi.Int32> completed,
);

typedef _dart_libusb_handle_events_timeout_completed = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
ffi.Pointer<ffi.Int32> completed,
);

Expand All @@ -4003,12 +4003,12 @@ typedef _dart_libusb_handle_events_completed = int Function(

typedef _c_libusb_handle_events_locked = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
);

typedef _dart_libusb_handle_events_locked = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
);

typedef _c_libusb_pollfds_handle_timeouts = ffi.Int32 Function(
Expand All @@ -4021,12 +4021,12 @@ typedef _dart_libusb_pollfds_handle_timeouts = int Function(

typedef _c_libusb_get_next_timeout = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
);

typedef _dart_libusb_get_next_timeout = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval32> tv,
);

typedef _c_libusb_get_pollfds = ffi.Pointer<ffi.Pointer<libusb_pollfd>>
Expand Down
32 changes: 16 additions & 16 deletions lib/libusb_linux.dart → lib/libusb64.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ class Libusb {

int libusb_wait_for_event(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
) {
_libusb_wait_for_event ??= _dylib.lookupFunction<_c_libusb_wait_for_event,
_dart_libusb_wait_for_event>('libusb_wait_for_event');
Expand All @@ -1636,7 +1636,7 @@ class Libusb {

int libusb_handle_events_timeout(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
) {
_libusb_handle_events_timeout ??= _dylib.lookupFunction<
_c_libusb_handle_events_timeout,
Expand All @@ -1651,7 +1651,7 @@ class Libusb {

int libusb_handle_events_timeout_completed(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
ffi.Pointer<ffi.Int32> completed,
) {
_libusb_handle_events_timeout_completed ??= _dylib.lookupFunction<
Expand Down Expand Up @@ -1697,7 +1697,7 @@ class Libusb {

int libusb_handle_events_locked(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
) {
_libusb_handle_events_locked ??= _dylib.lookupFunction<
_c_libusb_handle_events_locked,
Expand Down Expand Up @@ -1725,7 +1725,7 @@ class Libusb {

int libusb_get_next_timeout(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
) {
_libusb_get_next_timeout ??= _dylib.lookupFunction<
_c_libusb_get_next_timeout,
Expand Down Expand Up @@ -2843,7 +2843,7 @@ abstract class libusb_log_cb_mode {
static const int LIBUSB_LOG_CB_CONTEXT = 2;
}

class timeval extends ffi.Struct {
class timeval64 extends ffi.Struct {
@ffi.Int64()
int tv_sec;

Expand Down Expand Up @@ -3953,33 +3953,33 @@ typedef _dart_libusb_unlock_event_waiters = void Function(

typedef _c_libusb_wait_for_event = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
);

typedef _dart_libusb_wait_for_event = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
);

typedef _c_libusb_handle_events_timeout = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
);

typedef _dart_libusb_handle_events_timeout = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
);

typedef _c_libusb_handle_events_timeout_completed = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
ffi.Pointer<ffi.Int32> completed,
);

typedef _dart_libusb_handle_events_timeout_completed = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
ffi.Pointer<ffi.Int32> completed,
);

Expand All @@ -4003,12 +4003,12 @@ typedef _dart_libusb_handle_events_completed = int Function(

typedef _c_libusb_handle_events_locked = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
);

typedef _dart_libusb_handle_events_locked = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
);

typedef _c_libusb_pollfds_handle_timeouts = ffi.Int32 Function(
Expand All @@ -4021,12 +4021,12 @@ typedef _dart_libusb_pollfds_handle_timeouts = int Function(

typedef _c_libusb_get_next_timeout = ffi.Int32 Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
);

typedef _dart_libusb_get_next_timeout = int Function(
ffi.Pointer<libusb_context> ctx,
ffi.Pointer<timeval> tv,
ffi.Pointer<timeval64> tv,
);

typedef _c_libusb_get_pollfds = ffi.Pointer<ffi.Pointer<libusb_pollfd>>
Expand Down
Loading

0 comments on commit 48638d2

Please sign in to comment.