Skip to content

Commit

Permalink
Resolve analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-kim committed Dec 2, 2021
1 parent 98e1012 commit c4b64e4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
56 changes: 29 additions & 27 deletions packages/shared_preferences/lib/src/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,41 @@ import 'types.dart';

class _PreferenceBindings {
_PreferenceBindings() {
_lib = DynamicLibrary.open('libcapi-appfw-preference.so.0');
final DynamicLibrary lib =
DynamicLibrary.open('libcapi-appfw-preference.so.0');

setInt = _lib.lookupFunction<preference_set_int_native_t, PreferenceSetInt>(
setInt = lib.lookupFunction<PreferenceSetIntNative, PreferenceSetInt>(
'preference_set_int');
getInt = _lib.lookupFunction<preference_get_int_native_t, PreferenceGetInt>(
getInt = lib.lookupFunction<PreferenceGetIntNative, PreferenceGetInt>(
'preference_get_int');

setDouble = _lib.lookupFunction<preference_set_double_native_t,
PreferenceSetDouble>('preference_set_double');
getDouble = _lib.lookupFunction<preference_get_double_native_t,
PreferenceGetDouble>('preference_get_double');

setString = _lib.lookupFunction<preference_set_string_native_t,
PreferenceSetString>('preference_set_string');
getString = _lib.lookupFunction<preference_get_string_native_t,
PreferenceGetString>('preference_get_string');

setBoolean = _lib.lookupFunction<preference_set_boolean_native_t,
PreferenceSetBoolean>('preference_set_boolean');
getBoolean = _lib.lookupFunction<preference_get_boolean_native_t,
PreferenceGetBoolean>('preference_get_boolean');

remove = _lib.lookupFunction<preference_remove_native_t, PreferenceRemove>(
setDouble =
lib.lookupFunction<PreferenceSetDoubleNative, PreferenceSetDouble>(
'preference_set_double');
getDouble =
lib.lookupFunction<PreferenceGetDoubleNative, PreferenceGetDouble>(
'preference_get_double');
setString =
lib.lookupFunction<PreferenceSetStringNative, PreferenceSetString>(
'preference_set_string');
getString =
lib.lookupFunction<PreferenceGetStringNative, PreferenceGetString>(
'preference_get_string');
setBoolean =
lib.lookupFunction<PreferenceSetBooleanNative, PreferenceSetBoolean>(
'preference_set_boolean');
getBoolean =
lib.lookupFunction<PreferenceGetBooleanNative, PreferenceGetBoolean>(
'preference_get_boolean');
remove = lib.lookupFunction<PreferenceRemoveNative, PreferenceRemove>(
'preference_remove');

removeAll = _lib.lookupFunction<preference_remove_all_native_t,
PreferenceRemoveAll>('preference_remove_all');

foreachItem = _lib.lookupFunction<preference_foreach_item_native_t,
PreferenceForeachItem>('preference_foreach_item');
removeAll =
lib.lookupFunction<PreferenceRemoveAllNative, PreferenceRemoveAll>(
'preference_remove_all');
foreachItem =
lib.lookupFunction<PreferenceForeachItemNative, PreferenceForeachItem>(
'preference_foreach_item');
}

late DynamicLibrary _lib;
late PreferenceSetInt setInt;
late PreferenceGetInt getInt;
late PreferenceSetDouble setDouble;
Expand Down
29 changes: 14 additions & 15 deletions packages/shared_preferences/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,65 @@ import 'dart:ffi';
import 'package:ffi/ffi.dart';

// int preference_set_int (const char *key, int value)
typedef preference_set_int_native_t = Int32 Function(
Pointer<Utf8> key, Int32 value);
typedef PreferenceSetIntNative = Int32 Function(Pointer<Utf8> key, Int32 value);
typedef PreferenceSetInt = int Function(Pointer<Utf8> key, int value);

// int preference_get_int (const char *key, int *value)
typedef preference_get_int_native_t = Int32 Function(
typedef PreferenceGetIntNative = Int32 Function(
Pointer<Utf8> key, Pointer<Int32> value);
typedef PreferenceGetInt = int Function(
Pointer<Utf8> key, Pointer<Int32> value);

// int preference_set_double (const char *key, double value)
typedef preference_set_double_native_t = Int32 Function(
typedef PreferenceSetDoubleNative = Int32 Function(
Pointer<Utf8> key, Double value);
typedef PreferenceSetDouble = int Function(Pointer<Utf8> key, double value);

// int preference_get_double (const char *key, double *value)
typedef preference_get_double_native_t = Int32 Function(
typedef PreferenceGetDoubleNative = Int32 Function(
Pointer<Utf8> key, Pointer<Double> value);
typedef PreferenceGetDouble = int Function(
Pointer<Utf8> key, Pointer<Double> value);

// int preference_set_string (const char *key, const char *value)
typedef preference_set_string_native_t = Int32 Function(
typedef PreferenceSetStringNative = Int32 Function(
Pointer<Utf8> key, Pointer<Utf8> value);
typedef PreferenceSetString = int Function(
Pointer<Utf8> key, Pointer<Utf8> value);

// int preference_get_string (const char *key, char **value)
typedef preference_get_string_native_t = Int32 Function(
typedef PreferenceGetStringNative = Int32 Function(
Pointer<Utf8> key, Pointer<Pointer<Utf8>> value);
typedef PreferenceGetString = int Function(
Pointer<Utf8> key, Pointer<Pointer<Utf8>> value);

// int preference_set_boolean (const char *key, bool value)
typedef preference_set_boolean_native_t = Int32 Function(
typedef PreferenceSetBooleanNative = Int32 Function(
Pointer<Utf8> key, Int8 value);
typedef PreferenceSetBoolean = int Function(Pointer<Utf8> key, int value);

// int preference_get_boolean (const char *key, bool *value)
typedef preference_get_boolean_native_t = Int32 Function(
typedef PreferenceGetBooleanNative = Int32 Function(
Pointer<Utf8> key, Pointer<Int8> value);
typedef PreferenceGetBoolean = int Function(
Pointer<Utf8> key, Pointer<Int8> value);

// int preference_remove (const char *key)
typedef preference_remove_native_t = Int32 Function(Pointer<Utf8> key);
typedef PreferenceRemoveNative = Int32 Function(Pointer<Utf8> key);
typedef PreferenceRemove = int Function(Pointer<Utf8> key);

// int preference_remove_all (void)
typedef preference_remove_all_native_t = Int32 Function();
typedef PreferenceRemoveAllNative = Int32 Function();
typedef PreferenceRemoveAll = int Function();

// typedef bool(* preference_item_cb )(const char *key, void *user_data)
typedef preference_item_cb_native_t = Int8 Function(
typedef PreferenceItemCallbackNative = Int8 Function(
Pointer<Utf8> key, Pointer<Void> userData);

// int preference_foreach_item (preference_item_cb callback, void *user_data)
typedef preference_foreach_item_native_t = Int32 Function(
Pointer<NativeFunction<preference_item_cb_native_t>> callback,
typedef PreferenceForeachItemNative = Int32 Function(
Pointer<NativeFunction<PreferenceItemCallbackNative>> callback,
Pointer<Void> userData);
typedef PreferenceForeachItem = int Function(
Pointer<NativeFunction<preference_item_cb_native_t>> callback,
Pointer<NativeFunction<PreferenceItemCallbackNative>> callback,
Pointer<Void> userData);

0 comments on commit c4b64e4

Please sign in to comment.