flutter_app/lib/model.dart

98 lines
2.9 KiB
Dart
Raw Normal View History

import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'dart:async';
import 'dart:collection';
////////////////////
/// UI State ///
////////////////////
class ProfileModel {
String onion;
String nickname;
String creationDate;
HashMap<String, ContactModel> contacts;
}
class ContactModel {
String onion;
String nickname;
bool isGroup;
bool isBlocked;
String status;
ContactModel({this.onion, this.nickname, this.status});
}
/////////////
/// ACN ///
/////////////
typedef acn_events_function = Pointer<Utf8> Function();
typedef ACNEventsFn = Pointer<Utf8> Function();
class AppModel {
final DynamicLibrary library;
AppModel({this.library});
Stream<String> contactEvents() async* {
var acnEventsC = library.lookup<NativeFunction<acn_events_function>>(
"ContactEvents");
// ignore: non_constant_identifier_names
final ContactEvents = acnEventsC.asFunction<ACNEventsFn>();
while (true) {
Pointer<Utf8> result = ContactEvents();
String event = Utf8.fromUtf8(result);
if (event != "") {
print(event);
yield event;
} else {
await Future.delayed(Duration(seconds: 1));
}
}
}
Stream<String> torStatus() async* {
var acnEventsC = library.lookup<NativeFunction<acn_events_function>>(
"ACNEvents");
// ignore: non_constant_identifier_names
final ACNEvents = acnEventsC.asFunction<ACNEventsFn>();
while (true) {
Pointer<Utf8> result = ACNEvents();
String event = Utf8.fromUtf8(result);
if (event != "") {
yield event;
} else {
await Future.delayed(Duration(seconds: 1));
}
}
}
}
/////////////////////
/// Cwtch API ///
/////////////////////
typedef start_cwtch_function = Void Function(Pointer<Utf8> str, Int32 length);
typedef StartCwtchFn = void Function(Pointer<Utf8> dir, int len);
typedef access_cwtch_eventbus_function = Void Function();
typedef NextEventFn = void Function();
typedef get_json_blob_void_function = Pointer<Utf8> Function();
typedef GetJsonBlobVoidFn = Pointer<Utf8> Function();
typedef get_json_blob_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length);
typedef GetJsonBlobStringFn = Pointer<Utf8> Function(Pointer<Utf8> str,int len);
//func NumMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int) (n C.int) {
typedef get_int_from_str_str_function = Int32 Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
typedef GetIntFromStrStrFn = int Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
//func GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, message_index C.int) *C.char {
typedef get_json_blob_from_str_str_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int32);
typedef GetJsonBlobFromStrStrIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int);