mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-06-27 06:43:13 +00:00
null-safety
This commit is contained in:
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
@ -11,12 +11,12 @@
|
||||
"type": "dart"
|
||||
},
|
||||
{
|
||||
"program": "test/template_test/.dart_tool/build/entrypoint/build.dart",
|
||||
"name": "template_test",
|
||||
"cwd": "template_test",
|
||||
|
||||
"name": "Test",
|
||||
"program": "test/template_test/bin/service.dart",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"args": ["serve"],
|
||||
"type": "dart"
|
||||
|
||||
}
|
||||
]
|
||||
}
|
@ -9,7 +9,7 @@ import 'package:yaml/yaml.dart';
|
||||
class TemplateBuilder implements Builder {
|
||||
//BuilderOptions options;
|
||||
String _fileName;
|
||||
TemplateBuilder([BuilderOptions options]) : _fileName = _get_dest(options);
|
||||
TemplateBuilder([BuilderOptions? options]) : _fileName = _get_dest(options);
|
||||
|
||||
@override
|
||||
Future build(BuildStep buildStep) async {
|
||||
@ -21,7 +21,7 @@ class TemplateBuilder implements Builder {
|
||||
await buildStep.writeAsString(id, content);
|
||||
}
|
||||
|
||||
static String _get_dest(BuilderOptions options) {
|
||||
static String _get_dest(BuilderOptions? options) {
|
||||
const defaultDestination = 'lib/src/iip_template.dart';
|
||||
if (options == null) return defaultDestination;
|
||||
if (options.config == null) return defaultDestination;
|
||||
|
@ -1,55 +1,62 @@
|
||||
import 'AsyncReply.dart';
|
||||
import '../Resource/Warehouse.dart';
|
||||
|
||||
// class ReplyIndex<T> {
|
||||
// int index;
|
||||
// AsyncReply<T> reply;
|
||||
// T
|
||||
// }
|
||||
|
||||
class AsyncBag<T> extends AsyncReply<List<T>> {
|
||||
List<AsyncReply<T>> _replies = <AsyncReply<T>>[];
|
||||
List<T> _results = <T>[];
|
||||
|
||||
//List<T?> _results = <T>[];
|
||||
|
||||
int _count = 0;
|
||||
bool _sealedBag = false;
|
||||
|
||||
Type arrayType;
|
||||
Type? arrayType;
|
||||
|
||||
seal() {
|
||||
//print("SEALED");
|
||||
|
||||
if (_sealedBag) return;
|
||||
|
||||
_sealedBag = true;
|
||||
|
||||
if (_results.length == 0) trigger(<T>[]);
|
||||
if (_replies.length == 0) trigger(<T>[]);
|
||||
|
||||
for (var i = 0; i < _results.length; i++) {
|
||||
var results = List<T?>.filled(_replies.length, null);
|
||||
|
||||
for (var i = 0; i < _replies.length; i++) {
|
||||
var k = _replies[i];
|
||||
var index = i;
|
||||
|
||||
k.then<dynamic>((r) {
|
||||
_results[index] = r;
|
||||
k..then((r) {
|
||||
results[index] = r;
|
||||
_count++;
|
||||
if (_count == _results.length) {
|
||||
if (_count == _replies.length) {
|
||||
if (arrayType != null) {
|
||||
var ar = Warehouse.createArray(arrayType);
|
||||
_results.forEach(ar.add);
|
||||
trigger(ar);
|
||||
var ar = Warehouse.createArray(arrayType as Type);
|
||||
results.forEach(ar.add);
|
||||
trigger(ar as List<T>);
|
||||
} else {
|
||||
trigger(_results);
|
||||
trigger(results.cast<T>());
|
||||
}
|
||||
}
|
||||
}).error((ex) {
|
||||
})..error((ex) {
|
||||
triggerError(ex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
add(AsyncReply<T> reply) {
|
||||
void add(AsyncReply<T> reply) {
|
||||
if (!_sealedBag) {
|
||||
_results.add(null);
|
||||
//_results.add(null);
|
||||
_replies.add(reply);
|
||||
}
|
||||
}
|
||||
|
||||
addBag(AsyncBag<T> bag) {
|
||||
void addBag(AsyncBag<T> bag) {
|
||||
bag._replies.forEach((r) {
|
||||
add(r);
|
||||
});
|
||||
|
@ -4,7 +4,7 @@ import 'ErrorType.dart';
|
||||
class AsyncException implements Exception {
|
||||
final ErrorType type;
|
||||
final int code;
|
||||
final String message;
|
||||
final String? message;
|
||||
|
||||
AsyncException(this.type, this.code, this.message) {}
|
||||
|
||||
@ -20,7 +20,7 @@ class AsyncException implements Exception {
|
||||
": " +
|
||||
(message ?? "");
|
||||
else
|
||||
return code.toString() + ": " + message;
|
||||
return code.toString() + ": " + (message ?? '');
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -2,8 +2,8 @@ library esiur;
|
||||
|
||||
import 'AsyncReply.dart';
|
||||
|
||||
class AsyncQueue<T> extends AsyncReply<T> {
|
||||
List<AsyncReply<T>> _list = <AsyncReply<T>>[];
|
||||
class AsyncQueue<T> extends AsyncReply<T?> {
|
||||
List<AsyncReply<T?>> _list = <AsyncReply<T?>>[];
|
||||
|
||||
// object queueLock = new object();
|
||||
|
||||
@ -23,7 +23,7 @@ class AsyncQueue<T> extends AsyncReply<T> {
|
||||
processQueue(null);
|
||||
}
|
||||
|
||||
void processQueue(T o) {
|
||||
void processQueue(T? o) {
|
||||
//lock (queueLock)
|
||||
for (var i = 0; i < _list.length; i++)
|
||||
if (_list[i].ready) {
|
||||
|
@ -29,9 +29,9 @@ import 'ProgressType.dart';
|
||||
class AsyncReply<T> implements Future<T> {
|
||||
List<Function(T)> _callbacks = <Function(T)>[];
|
||||
|
||||
T _result;
|
||||
late T _result;
|
||||
|
||||
List<Function(AsyncException)> _errorCallbacks = <Function(AsyncException)>[];
|
||||
List<Function> _errorCallbacks = <Function>[];
|
||||
|
||||
List<Function(ProgressType, int, int)> _progressCallbacks =
|
||||
<Function(ProgressType, int, int)>[];
|
||||
@ -39,7 +39,7 @@ class AsyncReply<T> implements Future<T> {
|
||||
List<Function(T)> _chunkCallbacks = <Function(T)>[];
|
||||
|
||||
bool _resultReady = false;
|
||||
AsyncException _exception;
|
||||
AsyncException? _exception;
|
||||
|
||||
bool get ready {
|
||||
return _resultReady;
|
||||
@ -49,7 +49,7 @@ class AsyncReply<T> implements Future<T> {
|
||||
_resultReady = value;
|
||||
}
|
||||
|
||||
T get result {
|
||||
T? get result {
|
||||
return _result;
|
||||
}
|
||||
|
||||
@ -62,26 +62,20 @@ class AsyncReply<T> implements Future<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
AsyncReply<R> then<R>(FutureOr<R> onValue(T value), {Function onError}) {
|
||||
AsyncReply<R> then<R>(FutureOr<R> onValue(T value), {Function? onError}) {
|
||||
_callbacks.add(onValue);
|
||||
|
||||
if (onError != null) {
|
||||
if (onError is Function(dynamic, dynamic)) {
|
||||
_errorCallbacks.add((ex) => onError(ex, null));
|
||||
} else if (onError is Function(dynamic)) {
|
||||
_errorCallbacks.add(onError);
|
||||
} else if (onError is Function()) {
|
||||
_errorCallbacks.add((ex) => onError());
|
||||
} else if (onError is Function(Object, StackTrace)) {
|
||||
_errorCallbacks.add((ex) => onError(ex, null));
|
||||
}
|
||||
}
|
||||
|
||||
if (_resultReady) onValue(result);
|
||||
if (_resultReady) onValue(result as T);
|
||||
|
||||
if (R == Null)
|
||||
return null;
|
||||
else
|
||||
return this as AsyncReply<R>;
|
||||
// if (R == Null)
|
||||
// return null;
|
||||
//else
|
||||
//if (R == T)
|
||||
return AsyncReply<R>();
|
||||
}
|
||||
|
||||
AsyncReply<T> whenComplete(FutureOr action()) {
|
||||
@ -90,21 +84,39 @@ class AsyncReply<T> implements Future<T> {
|
||||
}
|
||||
|
||||
Stream<T> asStream() {
|
||||
return null;
|
||||
return Stream.empty();
|
||||
//return null;
|
||||
}
|
||||
|
||||
AsyncReply<T> catchError(Function onError, {bool test(Object error)}) {
|
||||
return this.error(onError);
|
||||
// Future<T> catchError(Function onError, {bool test(Object error)?});
|
||||
|
||||
AsyncReply<T> catchError(Function onError, {bool test(Object error)?}) {
|
||||
///return this.error(onError);
|
||||
|
||||
_errorCallbacks.add(onError);
|
||||
|
||||
if (_exception != null) {
|
||||
if (onError is Function(dynamic, dynamic)) {
|
||||
onError(_exception, null);
|
||||
} else if (onError is Function(dynamic)) {
|
||||
onError(_exception);
|
||||
} else if (onError is Function()) {
|
||||
onError();
|
||||
} else if (onError is Function(Object, StackTrace)) {
|
||||
onError(_exception as Object, StackTrace.current);
|
||||
}
|
||||
}
|
||||
|
||||
AsyncReply<T> timeout(Duration timeLimit, {FutureOr<T> onTimeout()}) {
|
||||
return this;
|
||||
}
|
||||
|
||||
AsyncReply<T> error(Function(dynamic) callback) {
|
||||
_errorCallbacks.add(callback);
|
||||
AsyncReply<T> timeout(Duration timeLimit, {FutureOr<T?> onTimeout()?}) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (_exception != null) callback(_exception);
|
||||
AsyncReply<T> error(callback(AsyncException ex)) {
|
||||
_errorCallbacks.add(callback);
|
||||
if (_exception != null) callback(_exception as AsyncException);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -144,10 +156,19 @@ class AsyncReply<T> implements Future<T> {
|
||||
//{
|
||||
|
||||
if (this._errorCallbacks.length == 0)
|
||||
throw _exception;
|
||||
throw _exception as AsyncException;
|
||||
else
|
||||
_errorCallbacks.forEach((x) {
|
||||
if (x is Function(dynamic, dynamic)) {
|
||||
x(_exception, null);
|
||||
} else if (x is Function(dynamic)) {
|
||||
x(_exception);
|
||||
} else if (x is Function()) {
|
||||
x();
|
||||
} else if (x is Function(Object, StackTrace)) {
|
||||
x(_exception as Object, StackTrace.current);
|
||||
}
|
||||
//x(_exception as AsyncException);
|
||||
});
|
||||
//}
|
||||
|
||||
|
@ -1,46 +1,36 @@
|
||||
class IEventHandler
|
||||
{
|
||||
Map<String, List<Function>> _events;
|
||||
class IEventHandler {
|
||||
Map<String, List<Function>> _events = {};
|
||||
|
||||
register(String event)
|
||||
{
|
||||
register(String event) {
|
||||
_events[event.toLowerCase()] = [];
|
||||
}
|
||||
|
||||
IEventHandler()
|
||||
{
|
||||
_events = {};
|
||||
}
|
||||
IEventHandler() {}
|
||||
|
||||
emitArgs(String event, List arguments)
|
||||
{
|
||||
event = event.toLowerCase();
|
||||
if (_events.containsKey(event))
|
||||
for(var i = 0; i < _events[event].length; i++)
|
||||
if (Function.apply(_events[event][i], arguments) != null)
|
||||
return true;
|
||||
emitArgs(String event, List arguments) {
|
||||
//event = event.toLowerCase();
|
||||
|
||||
var et = _events[event.toLowerCase()];
|
||||
if (et != null) {
|
||||
for (var i = 0; i < et.length; i++)
|
||||
if (Function.apply(et[i], arguments) != null) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
on(String event, Function callback)
|
||||
{
|
||||
on(String event, Function callback) {
|
||||
event = event.toLowerCase();
|
||||
// add
|
||||
if (!_events.containsKey(event))
|
||||
register(event);
|
||||
|
||||
_events[event].add(callback);
|
||||
if (_events.containsKey(event)) register(event);
|
||||
_events[event]?.add(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
off(event, callback)
|
||||
{
|
||||
off(event, callback) {
|
||||
event = event.toString();
|
||||
if (_events.containsKey(event))
|
||||
{
|
||||
if (_events.containsKey(event)) {
|
||||
if (callback != null)
|
||||
_events[event].remove(callback);
|
||||
_events[event]?.remove(callback);
|
||||
else
|
||||
this._events[event] = [];
|
||||
}
|
||||
|
@ -2,14 +2,14 @@ import '../Core/IDestructible.dart';
|
||||
import 'Codec.dart';
|
||||
import 'dart:collection';
|
||||
|
||||
class AutoList<T, ST> extends IDestructible with IterableMixin {
|
||||
class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
|
||||
List<T> _list = <T>[];
|
||||
|
||||
ST _state;
|
||||
bool _removableList;
|
||||
ST? _state;
|
||||
late bool _removableList;
|
||||
|
||||
sort(Function comparer) {
|
||||
_list.sort(comparer);
|
||||
sort(int Function(T, T)? compare) {
|
||||
_list.sort(compare);
|
||||
}
|
||||
|
||||
Iterator<T> get iterator => _list.iterator;
|
||||
@ -26,7 +26,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin {
|
||||
|
||||
/// Create a new instance of AutoList
|
||||
/// <param name="state">State object to be included when an event is raised.</param>
|
||||
AutoList([ST state, List<T> values]) {
|
||||
AutoList([ST? state, List<T>? values]) {
|
||||
this._state = state;
|
||||
this._removableList = Codec.implementsInterface<T, IDestructible>();
|
||||
|
||||
@ -105,8 +105,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin {
|
||||
/// </summary>
|
||||
clear() {
|
||||
if (_removableList)
|
||||
_list
|
||||
.forEach((x) => (x as IDestructible)?.off("destroy", _itemDestroyed));
|
||||
_list.forEach((x) => (x as IDestructible).off("destroy", _itemDestroyed));
|
||||
|
||||
// lock (syncRoot)
|
||||
_list.clear();
|
||||
|
@ -30,81 +30,55 @@ import 'DC.dart';
|
||||
import 'DataType.dart';
|
||||
import 'Guid.dart';
|
||||
|
||||
class BinaryList
|
||||
{
|
||||
class BinaryList {
|
||||
var _list = <int>[];
|
||||
|
||||
int get length => _list.length;
|
||||
|
||||
BinaryList addDateTime(DateTime value)
|
||||
{
|
||||
void addDateTime(DateTime value) {
|
||||
_list.addAll(DC.dateTimeToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertDateTime(int position, DateTime value)
|
||||
{
|
||||
void insertDateTime(int position, DateTime value) {
|
||||
_list.insertAll(position, DC.dateTimeToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addDateTimeArray(List<DateTime> value)
|
||||
{
|
||||
void addDateTimeArray(List<DateTime> value) {
|
||||
_list.addAll(DC.dateTimeArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertDateTimeArray(int position, List<DateTime> value)
|
||||
{
|
||||
void insertDateTimeArray(int position, List<DateTime> value) {
|
||||
_list.insertAll(position, DC.dateTimeArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addGuid(Guid value)
|
||||
{
|
||||
void addGuid(Guid value) {
|
||||
_list.addAll(DC.guidToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertGuid(int position, Guid value)
|
||||
{
|
||||
void insertGuid(int position, Guid value) {
|
||||
_list.insertAll(position, DC.guidToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addGuidArray(List<Guid> value)
|
||||
{
|
||||
void addGuidArray(List<Guid> value) {
|
||||
_list.addAll(DC.guidArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertGuidArray(int position, List<Guid> value)
|
||||
{
|
||||
void insertGuidArray(int position, List<Guid> value) {
|
||||
_list.insertAll(position, DC.guidArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addUint8Array(Uint8List value)
|
||||
{
|
||||
void addUint8Array(Uint8List value) {
|
||||
_list.addAll(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addDC(DC value)
|
||||
{
|
||||
void addDC(DC value) {
|
||||
_list.addAll(value.toArray());
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint8Array(int position, Uint8List value)
|
||||
{
|
||||
void insertUint8Array(int position, Uint8List value) {
|
||||
_list.insertAll(position, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
BinaryList addHex(String value)
|
||||
{
|
||||
@ -117,434 +91,316 @@ class BinaryList
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
BinaryList addString(String value)
|
||||
{
|
||||
void addString(String value) {
|
||||
_list.addAll(DC.stringToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertString(int position, String value)
|
||||
{
|
||||
void insertString(int position, String value) {
|
||||
_list.insertAll(position, DC.stringToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addStringArray(List<String> value)
|
||||
{
|
||||
void addStringArray(List<String> value) {
|
||||
_list.addAll(DC.stringArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertStringArray(int position, List<String> value)
|
||||
{
|
||||
void insertStringArray(int position, List<String> value) {
|
||||
_list.insertAll(position, DC.stringArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint8(int position, int value)
|
||||
{
|
||||
void insertUint8(int position, int value) {
|
||||
_list.insert(position, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint8(int value)
|
||||
{
|
||||
void addUint8(int value) {
|
||||
_list.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt8(int value)
|
||||
{
|
||||
void addInt8(int value) {
|
||||
_list.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt8(int position, int value)
|
||||
{
|
||||
void insertInt8(int position, int value) {
|
||||
_list.insert(position, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt8Array(Int8List value)
|
||||
{
|
||||
void addInt8Array(Int8List value) {
|
||||
_list.addAll(DC.int8ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt8Array(int position, Int8List value)
|
||||
{
|
||||
void insertInt8Array(int position, Int8List value) {
|
||||
_list.insertAll(position, DC.int8ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addChar(int value)
|
||||
{
|
||||
void addChar(int value) {
|
||||
_list.addAll(DC.charToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList InsertChar(int position, int value)
|
||||
{
|
||||
void InsertChar(int position, int value) {
|
||||
_list.insertAll(position, DC.charToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addCharArray(Uint16List value)
|
||||
{
|
||||
void addCharArray(Uint16List value) {
|
||||
_list.addAll(DC.charArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList InsertCharArray(int position, Uint16List value)
|
||||
{
|
||||
void InsertCharArray(int position, Uint16List value) {
|
||||
_list.insertAll(position, DC.charArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addBoolean(bool value)
|
||||
{
|
||||
void addBoolean(bool value) {
|
||||
_list.addAll(DC.boolToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertBoolean(int position, bool value)
|
||||
{
|
||||
void insertBoolean(int position, bool value) {
|
||||
_list.insertAll(position, DC.boolToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addBooleanArray(List<bool> value)
|
||||
{
|
||||
void addBooleanArray(List<bool> value) {
|
||||
_list.addAll(DC.boolToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertBooleanArray(int position, List<bool> value)
|
||||
{
|
||||
void insertBooleanArray(int position, List<bool> value) {
|
||||
_list.insertAll(position, DC.boolToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint16(int value)
|
||||
{
|
||||
void addUint16(int value) {
|
||||
_list.addAll(DC.uint16ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint16(int position, int value)
|
||||
{
|
||||
void insertUint16(int position, int value) {
|
||||
_list.insertAll(position, DC.uint16ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint16Array(Uint16List value)
|
||||
{
|
||||
void addUint16Array(Uint16List value) {
|
||||
_list.addAll(DC.uint16ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint16Array(int position, Uint16List value)
|
||||
{
|
||||
void insertUint16Array(int position, Uint16List value) {
|
||||
_list.insertAll(position, DC.uint16ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addInt16(int value)
|
||||
{
|
||||
void addInt16(int value) {
|
||||
_list.addAll(DC.int16ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt16(int position, int value)
|
||||
{
|
||||
void insertInt16(int position, int value) {
|
||||
_list.insertAll(position, DC.int16ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addInt16Array(Int16List value)
|
||||
{
|
||||
void addInt16Array(Int16List value) {
|
||||
_list.addAll(DC.int16ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt16Array(int position, Int16List value)
|
||||
{
|
||||
void insertInt16Array(int position, Int16List value) {
|
||||
_list.insertAll(position, DC.int16ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint32(int value)
|
||||
{
|
||||
void addUint32(int value) {
|
||||
_list.addAll(DC.uint32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint32(int position, int value)
|
||||
{
|
||||
void insertUint32(int position, int value) {
|
||||
_list.insertAll(position, DC.uint32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint32Array(Uint32List value)
|
||||
{
|
||||
void addUint32Array(Uint32List value) {
|
||||
_list.addAll(DC.uint32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
BinaryList InsertUint32Array(int position, Uint32List value)
|
||||
{
|
||||
|
||||
void InsertUint32Array(int position, Uint32List value) {
|
||||
_list.insertAll(position, DC.uint32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addInt32(int value)
|
||||
{
|
||||
void addInt32(int value) {
|
||||
_list.addAll(DC.int32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt32(int position, int value)
|
||||
{
|
||||
void insertInt32(int position, int value) {
|
||||
_list.insertAll(position, DC.int32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt32Array(Int32List value)
|
||||
{
|
||||
void addInt32Array(Int32List value) {
|
||||
_list.addAll(DC.int32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt32Array(int position, Int32List value)
|
||||
{
|
||||
void insertInt32Array(int position, Int32List value) {
|
||||
_list.insertAll(position, DC.int32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addUint64(int value)
|
||||
{
|
||||
void addUint64(int value) {
|
||||
_list.addAll(DC.uint64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint64(int position, int value)
|
||||
{
|
||||
void insertUint64(int position, int value) {
|
||||
_list.insertAll(position, DC.uint64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint64Array(Uint64List value)
|
||||
{
|
||||
void addUint64Array(Uint64List value) {
|
||||
_list.addAll(DC.uint64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList InsertUint64Array(int position, Uint64List value)
|
||||
{
|
||||
void InsertUint64Array(int position, Uint64List value) {
|
||||
_list.insertAll(position, DC.uint64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt64(int value)
|
||||
{
|
||||
void addInt64(int value) {
|
||||
_list.addAll(DC.int64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt64(int position, int value)
|
||||
{
|
||||
void insertInt64(int position, int value) {
|
||||
_list.insertAll(position, DC.int64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt64Array(Int64List value)
|
||||
{
|
||||
void addInt64Array(Int64List value) {
|
||||
_list.addAll(DC.int64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt64Array(int position, Int64List value)
|
||||
{
|
||||
void insertInt64Array(int position, Int64List value) {
|
||||
_list.insertAll(position, DC.int64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addFloat32(double value)
|
||||
{
|
||||
void addFloat32(double value) {
|
||||
_list.addAll(DC.float32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertFloat32(int position, double value)
|
||||
{
|
||||
void insertFloat32(int position, double value) {
|
||||
_list.insertAll(position, DC.float32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addFloat32Array(Float32List value)
|
||||
{
|
||||
void addFloat32Array(Float32List value) {
|
||||
_list.addAll(DC.float32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertFloat32Array(int position, Float32List value)
|
||||
{
|
||||
void insertFloat32Array(int position, Float32List value) {
|
||||
_list.insertAll(position, DC.float32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addFloat64(double value)
|
||||
{
|
||||
void addFloat64(double value) {
|
||||
_list.addAll(DC.float64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertFloat64(int position, double value)
|
||||
{
|
||||
void insertFloat64(int position, double value) {
|
||||
_list.insertAll(position, DC.float64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addFloat64Array(Float64List value)
|
||||
{
|
||||
void addFloat64Array(Float64List value) {
|
||||
_list.addAll(DC.float64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertFloat64Array(int position, Float64List value)
|
||||
{
|
||||
void insertFloat64Array(int position, Float64List value) {
|
||||
_list.insertAll(position, DC.float64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BinaryList add(type, value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
void add(type, value) {
|
||||
switch (type) {
|
||||
case DataType.Bool:
|
||||
addBoolean(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.BoolArray:
|
||||
addBooleanArray(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.UInt8:
|
||||
addUint8(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.UInt8Array:
|
||||
addUint8Array(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Int8:
|
||||
addInt8(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Int8Array:
|
||||
addInt8Array(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Char:
|
||||
addChar(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.CharArray:
|
||||
addCharArray(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.UInt16:
|
||||
addUint16(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.UInt16Array:
|
||||
addUint16Array(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Int16:
|
||||
addInt16(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Int16Array:
|
||||
addInt16Array(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.UInt32:
|
||||
addUint32(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.UInt32Array:
|
||||
addUint32Array(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Int32:
|
||||
addInt32(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Int32Array:
|
||||
addInt32Array(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.UInt64:
|
||||
addUint64(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.UInt64Array:
|
||||
addUint64Array(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Int64:
|
||||
addInt64(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Int64Array:
|
||||
addInt64Array(value);
|
||||
return this;
|
||||
return;
|
||||
|
||||
case DataType.Float32:
|
||||
addFloat32(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Float32Array:
|
||||
addFloat32Array(value);
|
||||
return this;
|
||||
return;
|
||||
|
||||
case DataType.Float64:
|
||||
addFloat64(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.Float64Array:
|
||||
addFloat64Array(value);
|
||||
return this;
|
||||
return;
|
||||
|
||||
case DataType.String:
|
||||
addString(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.StringArray:
|
||||
addStringArray(value);
|
||||
return this;
|
||||
return;
|
||||
|
||||
case DataType.DateTime:
|
||||
addDateTime(value);
|
||||
return this;
|
||||
return;
|
||||
case DataType.DateTimeArray:
|
||||
addDateTimeArray(value);
|
||||
return this;
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new Exception("Not Implemented " + type.ToString());
|
||||
//return this;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the _list to an array of bytes
|
||||
/// </summary>
|
||||
/// <returns>Bytes array</returns>
|
||||
Uint8List toArray()
|
||||
{
|
||||
Uint8List toArray() {
|
||||
return Uint8List.fromList(_list);
|
||||
}
|
||||
|
||||
|
||||
DC toDC()
|
||||
{
|
||||
DC toDC() {
|
||||
return new DC.fromUint8Array(toArray());
|
||||
}
|
||||
|
||||
|
||||
AsyncReply<dynamic> done()
|
||||
{
|
||||
return null;
|
||||
//
|
||||
AsyncReply<dynamic> done() {
|
||||
return AsyncReply.ready(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -21,6 +21,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
import '../Core/AsyncException.dart';
|
||||
import '../Core/ErrorType.dart';
|
||||
import '../Core/ExceptionCode.dart';
|
||||
|
||||
import '../Resource/Template/TemplateType.dart';
|
||||
|
||||
import 'DataType.dart';
|
||||
@ -93,7 +98,7 @@ class Codec {
|
||||
/// <param name="next">Next structure to compare with the initial</param>
|
||||
/// <param name="connection">DistributedConnection is required in case a structure holds items at the other end</param>
|
||||
static int compareStructures(
|
||||
Structure initial, Structure next, DistributedConnection connection) {
|
||||
Structure? initial, Structure? next, DistributedConnection connection) {
|
||||
if (next == null) return StructureComparisonResult.Null;
|
||||
|
||||
if (initial == null) return StructureComparisonResult.Structure;
|
||||
@ -126,7 +131,7 @@ class Codec {
|
||||
/// <param name="initial">Initial record to compare with</param>
|
||||
/// <param name="next">Next record to compare with the initial</param>
|
||||
/// <param name="connection">DistributedConnection is required in case a structure holds items at the other end</param>
|
||||
static int compareRecords(IRecord initial, IRecord next) {
|
||||
static int compareRecords(IRecord? initial, IRecord? next) {
|
||||
if (next == null) return RecordComparisonResult.Null;
|
||||
|
||||
if (initial == null) return RecordComparisonResult.Record;
|
||||
@ -139,9 +144,9 @@ class Codec {
|
||||
return RecordComparisonResult.Record;
|
||||
}
|
||||
|
||||
static AsyncBag parseRecordArray(
|
||||
static AsyncBag<IRecord?> parseRecordArray(
|
||||
DC data, int offset, int length, DistributedConnection connection) {
|
||||
var reply = new AsyncBag();
|
||||
var reply = new AsyncBag<IRecord?>();
|
||||
|
||||
if (length == 0) {
|
||||
reply.seal();
|
||||
@ -161,12 +166,12 @@ class Codec {
|
||||
var template =
|
||||
Warehouse.getTemplateByClassId(classId, TemplateType.Record);
|
||||
|
||||
reply.arrayType = template.definedType;
|
||||
reply.arrayType = template?.definedType;
|
||||
|
||||
AsyncReply<IRecord> previous = null;
|
||||
AsyncReply<IRecord?>? previous = null;
|
||||
|
||||
if (result == RecordComparisonResult.Null)
|
||||
previous = new AsyncReply<IRecord>.ready(null);
|
||||
previous = AsyncReply<IRecord?>.ready(null);
|
||||
else if (result == RecordComparisonResult.Record ||
|
||||
result == RecordComparisonResult.RecordSameType) {
|
||||
var cs = data.getUint32(offset);
|
||||
@ -176,13 +181,13 @@ class Codec {
|
||||
offset += recordLength;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IRecord?>);
|
||||
|
||||
while (offset < end) {
|
||||
result = data[offset++];
|
||||
|
||||
if (result == RecordComparisonResult.Null)
|
||||
previous = new AsyncReply<IRecord>.ready(null);
|
||||
previous = new AsyncReply<IRecord?>.ready(null);
|
||||
else if (result == RecordComparisonResult.Record ||
|
||||
result == RecordComparisonResult.RecordSameType) {
|
||||
var cs = data.getUint32(offset);
|
||||
@ -193,14 +198,14 @@ class Codec {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IRecord?>);
|
||||
}
|
||||
} else {
|
||||
AsyncReply<IRecord> previous = null;
|
||||
Guid classId = null;
|
||||
AsyncReply<IRecord?>? previous = null;
|
||||
Guid? classId = null;
|
||||
|
||||
if (result == RecordComparisonResult.Null)
|
||||
previous = new AsyncReply<IRecord>.ready(null);
|
||||
previous = new AsyncReply<IRecord?>.ready(null);
|
||||
else if (result == RecordComparisonResult.Record) {
|
||||
var cs = data.getUint32(offset);
|
||||
var recordLength = cs - 16;
|
||||
@ -211,13 +216,13 @@ class Codec {
|
||||
offset += recordLength;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IRecord?>);
|
||||
|
||||
while (offset < end) {
|
||||
result = data[offset++];
|
||||
|
||||
if (result == RecordComparisonResult.Null)
|
||||
previous = new AsyncReply<IRecord>.ready(null);
|
||||
previous = new AsyncReply<IRecord?>.ready(null);
|
||||
else if (result == RecordComparisonResult.Record) {
|
||||
var cs = data.getUint32(offset);
|
||||
var recordLength = cs - 16;
|
||||
@ -236,7 +241,7 @@ class Codec {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IRecord?>);
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,7 +306,7 @@ class Codec {
|
||||
|
||||
static AsyncReply<IRecord> parseRecord(
|
||||
DC data, int offset, int length, DistributedConnection connection,
|
||||
[Guid classId = null]) {
|
||||
[Guid? classId = null]) {
|
||||
var reply = new AsyncReply<IRecord>();
|
||||
|
||||
if (classId == null) {
|
||||
@ -317,7 +322,7 @@ class Codec {
|
||||
parseVarArray(data, offset, length, connection).then((ar) {
|
||||
if (template.definedType != null) {
|
||||
var record =
|
||||
Warehouse.createInstance(template.definedType) as IRecord;
|
||||
Warehouse.createInstance(template.definedType as Type) as IRecord;
|
||||
|
||||
Map<String, dynamic> value = {};
|
||||
|
||||
@ -337,8 +342,11 @@ class Codec {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
connection.getTemplate(classId).then<dynamic>((tmp) {
|
||||
parseVarArray(data, offset, length, connection).then<dynamic>((ar) {
|
||||
connection.getTemplate(classId)
|
||||
..then((tmp) {
|
||||
if (tmp != null) {
|
||||
parseVarArray(data, offset, length, connection)
|
||||
..then((ar) {
|
||||
var record = new Record();
|
||||
|
||||
for (var i = 0; i < tmp.properties.length; i++)
|
||||
@ -346,7 +354,12 @@ class Codec {
|
||||
|
||||
reply.trigger(record);
|
||||
});
|
||||
}).error((x) => reply.triggerError(x));
|
||||
} else {
|
||||
reply.triggerError(AsyncException(ErrorType.Management,
|
||||
ExceptionCode.TemplateNotFound.index, null));
|
||||
}
|
||||
})
|
||||
..error((x) => reply.triggerError(x));
|
||||
}
|
||||
|
||||
return reply;
|
||||
@ -377,9 +390,9 @@ class Codec {
|
||||
}
|
||||
|
||||
static DC composeRecordArray<T extends IRecord>(
|
||||
List<T> records, DistributedConnection connection,
|
||||
List<T>? records, DistributedConnection connection,
|
||||
[bool prependLength = false]) {
|
||||
if (records == null || records?.length == 0)
|
||||
if (records == null || records.length == 0)
|
||||
return prependLength ? new DC(4) : new DC(0);
|
||||
|
||||
var rt = new BinaryList();
|
||||
@ -391,14 +404,14 @@ class Codec {
|
||||
if (isTyped) {
|
||||
var template = Warehouse.getTemplateByType(T);
|
||||
|
||||
if (template != null) {
|
||||
//if (template != null) {
|
||||
// typed array ... no need to add class id , it will be included at the first entry
|
||||
rt.addUint8(0x10 | comparsion);
|
||||
rt.addGuid(template.classId);
|
||||
} else // something wrong
|
||||
{
|
||||
throw new Exception("Template for type `${T}` not found.");
|
||||
}
|
||||
//} else // something wrong
|
||||
//{
|
||||
// throw new Exception("Template for type `${T}` not found.");
|
||||
//}
|
||||
|
||||
if (comparsion == RecordComparisonResult.Record)
|
||||
rt.addDC(composeRecord(records[0], connection, false, true));
|
||||
@ -468,17 +481,17 @@ class Codec {
|
||||
/// <param name="prependLength">If true, prepend the length as UInt32 at the beginning of the returned bytes array</param>
|
||||
/// <returns>Array of bytes in the network byte order</returns>
|
||||
static DC composeStructureArray(
|
||||
List<Structure> structures, DistributedConnection connection,
|
||||
List<Structure>? structures, DistributedConnection connection,
|
||||
[bool prependLength = false]) {
|
||||
if (structures == null || structures?.length == 0)
|
||||
if (structures == null || structures.length == 0)
|
||||
return prependLength ? new DC(4) : new DC(0);
|
||||
|
||||
var rt = new BinaryList();
|
||||
var comparsion = StructureComparisonResult.Structure;
|
||||
|
||||
rt
|
||||
.addUint8(comparsion)
|
||||
.addDC(composeStructure(structures[0], connection, true, true, true));
|
||||
..addUint8(comparsion)
|
||||
..addDC(composeStructure(structures[0], connection, true, true, true));
|
||||
|
||||
for (var i = 1; i < structures.length; i++) {
|
||||
comparsion =
|
||||
@ -508,9 +521,9 @@ class Codec {
|
||||
/// <param name="length">Number of bytes to parse</param>
|
||||
/// <param name="connection">DistributedConnection is required in case a structure in the array holds items at the other end</param>
|
||||
/// <returns>Array of structures</returns>
|
||||
static AsyncBag<Structure> parseStructureArray(
|
||||
static AsyncBag<Structure?> parseStructureArray(
|
||||
DC data, int offset, int length, DistributedConnection connection) {
|
||||
var reply = new AsyncBag<Structure>();
|
||||
var reply = new AsyncBag<Structure?>();
|
||||
if (length == 0) {
|
||||
reply.seal();
|
||||
return reply;
|
||||
@ -520,14 +533,14 @@ class Codec {
|
||||
|
||||
var result = data[offset++];
|
||||
|
||||
AsyncReply<Structure> previous = null;
|
||||
AsyncReply<Structure?>? previous = null;
|
||||
// string[] previousKeys = null;
|
||||
// DataType[] previousTypes = null;
|
||||
|
||||
StructureMetadata metadata = new StructureMetadata();
|
||||
|
||||
if (result == StructureComparisonResult.Null)
|
||||
previous = new AsyncReply<Structure>.ready(null);
|
||||
previous = new AsyncReply<Structure?>.ready(null);
|
||||
else if (result == StructureComparisonResult.Structure) {
|
||||
int cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
@ -535,13 +548,13 @@ class Codec {
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<Structure?>);
|
||||
|
||||
while (offset < end) {
|
||||
result = data[offset++];
|
||||
|
||||
if (result == StructureComparisonResult.Null)
|
||||
previous = new AsyncReply<Structure>.ready(null);
|
||||
previous = new AsyncReply<Structure?>.ready(null);
|
||||
else if (result == StructureComparisonResult.Structure) {
|
||||
int cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
@ -562,7 +575,7 @@ class Codec {
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<Structure?>);
|
||||
}
|
||||
|
||||
reply.seal();
|
||||
@ -587,7 +600,10 @@ class Codec {
|
||||
if (includeKeys) {
|
||||
for (var k in value.keys) {
|
||||
var key = DC.stringToBytes(k);
|
||||
rt.addUint8(key.length).addDC(key).addDC(compose(value[k], connection));
|
||||
rt
|
||||
..addUint8(key.length)
|
||||
..addDC(key)
|
||||
..addDC(compose(value[k], connection));
|
||||
}
|
||||
} else {
|
||||
for (var k in value.keys)
|
||||
@ -613,9 +629,9 @@ class Codec {
|
||||
/// <returns>Structure</returns>
|
||||
static AsyncReply<Structure> parseStructure(
|
||||
DC data, int offset, int length, DistributedConnection connection,
|
||||
[StructureMetadata metadata = null,
|
||||
List<String> keys = null,
|
||||
List<int> types =
|
||||
[StructureMetadata? metadata = null,
|
||||
List<String>? keys = null,
|
||||
List<int>? types =
|
||||
null]) // out string[] parsedKeys, out DataType[] parsedTypes, string[] keys = null, DataType[] types = null)
|
||||
{
|
||||
var reply = new AsyncReply<Structure>();
|
||||
@ -685,9 +701,8 @@ class Codec {
|
||||
/// <param name="connection">DistributedConnection is required in case a structure in the array holds items at the other end.</param>
|
||||
/// <param name="dataType">DataType, in case the data is not prepended with DataType</param>
|
||||
/// <returns>Value</returns>
|
||||
static AsyncReply<dynamic> parse(
|
||||
DC data, int offset, DistributedConnection connection,
|
||||
[SizeObject sizeObject, int dataType = DataType.Unspecified]) {
|
||||
static AsyncReply parse(DC data, int offset, DistributedConnection connection,
|
||||
[SizeObject? sizeObject, int dataType = DataType.Unspecified]) {
|
||||
bool isArray;
|
||||
int t;
|
||||
|
||||
@ -850,7 +865,8 @@ class Codec {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// @TODO: Throw exception
|
||||
return AsyncReply.ready(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -859,8 +875,8 @@ class Codec {
|
||||
/// <param name="data">Bytes array</param>
|
||||
/// <param name="offset">Zero-indexed offset.</param>
|
||||
/// <returns>Resource</returns>
|
||||
static AsyncReply<IResource> parseResource(DC data, int offset) {
|
||||
return Warehouse.get(data.getUint32(offset));
|
||||
static AsyncReply<IResource?> parseResource(DC data, int offset) {
|
||||
return Warehouse.getById(data.getUint32(offset));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -904,7 +920,7 @@ class Codec {
|
||||
/// <returns>Null, same, local, distributed or same class distributed.</returns>
|
||||
|
||||
static int compareResources(
|
||||
IResource initial, IResource next, DistributedConnection connection) {
|
||||
IResource? initial, IResource? next, DistributedConnection connection) {
|
||||
if (next == null)
|
||||
return ResourceComparisonResult.Null;
|
||||
else if (next == initial)
|
||||
@ -924,13 +940,12 @@ class Codec {
|
||||
static DC composeResource(
|
||||
IResource resource, DistributedConnection connection) {
|
||||
if (isLocalResource(resource, connection))
|
||||
return DC.uint32ToBytes((resource as DistributedResource).id);
|
||||
return DC.uint32ToBytes((resource as DistributedResource).id as int);
|
||||
else {
|
||||
return new BinaryList()
|
||||
.addGuid(resource.instance.template.classId)
|
||||
.addUint32(resource.instance.id)
|
||||
return (BinaryList()
|
||||
..addGuid(resource.instance?.template.classId as Guid)
|
||||
..addUint32(resource.instance?.id as int))
|
||||
.toDC();
|
||||
//return BinaryList.ToBytes(resource.Instance.Template.ClassId, resource.Instance.Id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -943,9 +958,9 @@ class Codec {
|
||||
/// <returns>Array of bytes in the network byte order.</returns>
|
||||
|
||||
static DC composeResourceArray<T extends IResource>(
|
||||
List<T> resources, DistributedConnection connection,
|
||||
List<T>? resources, DistributedConnection connection,
|
||||
[bool prependLength = false]) {
|
||||
if (resources == null || resources?.length == 0)
|
||||
if (resources == null || resources.length == 0)
|
||||
return prependLength ? new DC(4) : new DC(0);
|
||||
|
||||
var rt = new BinaryList();
|
||||
@ -971,17 +986,17 @@ class Codec {
|
||||
}
|
||||
|
||||
if (comparsion == ResourceComparisonResult.Local)
|
||||
rt.addUint32((resources[0] as DistributedResource).id);
|
||||
rt.addUint32((resources[0] as DistributedResource).id as int);
|
||||
else if (comparsion == ResourceComparisonResult.Distributed)
|
||||
rt.addUint32(resources[0].instance.id);
|
||||
rt.addUint32(resources[0].instance?.id as int);
|
||||
|
||||
for (var i = 1; i < resources.length; i++) {
|
||||
comparsion = compareResources(resources[i - 1], resources[i], connection);
|
||||
rt.addUint8(comparsion);
|
||||
if (comparsion == ResourceComparisonResult.Local)
|
||||
rt.addUint32((resources[i] as DistributedResource).id);
|
||||
rt.addUint32((resources[i] as DistributedResource).id as int);
|
||||
else if (comparsion == ResourceComparisonResult.Distributed)
|
||||
rt.addUint32(resources[i].instance.id);
|
||||
rt.addUint32(resources[i].instance?.id as int);
|
||||
}
|
||||
|
||||
if (prependLength) rt.insertInt32(0, rt.length);
|
||||
@ -997,11 +1012,11 @@ class Codec {
|
||||
/// <param name="offset">Zero-indexed offset.</param>
|
||||
/// <param name="connection">DistributedConnection is required to fetch resources.</param>
|
||||
/// <returns>Array of resources.</returns>
|
||||
static AsyncBag<IResource> parseResourceArray(
|
||||
static AsyncBag<IResource?> parseResourceArray(
|
||||
DC data, int offset, int length, DistributedConnection connection) {
|
||||
//print("parseResourceArray ${offset} ${length}");
|
||||
|
||||
var reply = new AsyncBag<IResource>();
|
||||
var reply = new AsyncBag<IResource?>();
|
||||
if (length == 0) {
|
||||
reply.seal();
|
||||
return reply;
|
||||
@ -1031,27 +1046,27 @@ class Codec {
|
||||
reply.arrayType = tmp?.definedType;
|
||||
}
|
||||
|
||||
AsyncReply<IResource> previous = null;
|
||||
AsyncReply<IResource?>? previous = null;
|
||||
|
||||
if (result == ResourceComparisonResult.Null)
|
||||
previous = new AsyncReply<IResource>.ready(null);
|
||||
previous = new AsyncReply<IResource?>.ready(null);
|
||||
else if (result == ResourceComparisonResult.Local) {
|
||||
previous = Warehouse.get(data.getUint32(offset));
|
||||
previous = Warehouse.getById(data.getUint32(offset));
|
||||
offset += 4;
|
||||
} else if (result == ResourceComparisonResult.Distributed) {
|
||||
previous = connection.fetch(data.getUint32(offset));
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IResource?>);
|
||||
|
||||
while (offset < end) {
|
||||
result = data[offset++];
|
||||
|
||||
AsyncReply<IResource> current = null;
|
||||
AsyncReply<IResource?>? current = null;
|
||||
|
||||
if (result == ResourceComparisonResult.Null) {
|
||||
current = new AsyncReply<IResource>.ready(null);
|
||||
current = new AsyncReply<IResource?>.ready(null);
|
||||
} else if (result == ResourceComparisonResult.Same) {
|
||||
current = previous;
|
||||
} else if (result == ResourceComparisonResult.Local) {
|
||||
@ -1062,7 +1077,7 @@ class Codec {
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
reply.add(current);
|
||||
reply.add(current as AsyncReply<IResource?>);
|
||||
|
||||
previous = current;
|
||||
}
|
||||
@ -1146,10 +1161,10 @@ class Codec {
|
||||
static DC composePropertyValue(PropertyValue propertyValue,
|
||||
DistributedConnection connection) //, bool includeAge = true)
|
||||
{
|
||||
return new BinaryList()
|
||||
.addUint64(propertyValue.age)
|
||||
.addDateTime(propertyValue.date)
|
||||
.addDC(compose(propertyValue.value, connection))
|
||||
return (BinaryList()
|
||||
..addUint64(propertyValue.age)
|
||||
..addDateTime(propertyValue.date)
|
||||
..addDC(compose(propertyValue.value, connection)))
|
||||
.toDC();
|
||||
}
|
||||
|
||||
@ -1194,7 +1209,8 @@ class Codec {
|
||||
static AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>
|
||||
parseHistory(DC data, int offset, int length, IResource resource,
|
||||
DistributedConnection connection) {
|
||||
var list = new KeyList<PropertyTemplate, List<PropertyValue>>();
|
||||
var list = <
|
||||
PropertyTemplate>[]; //new KeyList<PropertyTemplate, List<PropertyValue>?>();
|
||||
|
||||
var reply =
|
||||
new AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>();
|
||||
@ -1207,20 +1223,26 @@ class Codec {
|
||||
|
||||
while (offset < ends) {
|
||||
var index = data[offset++];
|
||||
var pt = resource.instance.template.getPropertyTemplateByIndex(index);
|
||||
list.add(pt, null);
|
||||
var pt = resource.instance?.template.getPropertyTemplateByIndex(index);
|
||||
if (pt != null) {
|
||||
list.add(pt); //, null);
|
||||
var cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
bagOfBags.add(parsePropertyValueArray(data, offset, cs, connection));
|
||||
offset += cs;
|
||||
}
|
||||
}
|
||||
|
||||
bagOfBags.seal();
|
||||
|
||||
bagOfBags.then((x) {
|
||||
for (var i = 0; i < list.length; i++) list[list.keys.elementAt(i)] = x[i];
|
||||
var keyList = KeyList<PropertyTemplate, List<PropertyValue>>();
|
||||
|
||||
reply.trigger(list);
|
||||
for (var i = 0; i < list.length; i++) keyList.add(list[i], x[i]);
|
||||
|
||||
//list[list.keys.elementAt(i)] = x[i];
|
||||
|
||||
reply.trigger(keyList);
|
||||
});
|
||||
|
||||
return reply;
|
||||
@ -1239,8 +1261,9 @@ class Codec {
|
||||
var rt = new BinaryList();
|
||||
|
||||
for (var i = 0; i < history.length; i++)
|
||||
rt.addUint8(history.keys.elementAt(i).index).addDC(
|
||||
composePropertyValueArray(
|
||||
rt
|
||||
..addUint8(history.keys.elementAt(i).index)
|
||||
..addDC(composePropertyValueArray(
|
||||
history.values.elementAt(i), connection, true));
|
||||
|
||||
if (prependLength) rt.insertInt32(0, rt.length);
|
||||
@ -1292,7 +1315,7 @@ class Codec {
|
||||
if (value is Function(DistributedConnection))
|
||||
value = Function.apply(value, [connection]);
|
||||
else if (value is DistributedPropertyContext)
|
||||
value = (value as DistributedPropertyContext).method(connection);
|
||||
value = value.method?.call(connection);
|
||||
|
||||
var type = getDataType(value, connection);
|
||||
var rt = new BinaryList();
|
||||
@ -1304,15 +1327,17 @@ class Codec {
|
||||
|
||||
case DataType.String:
|
||||
var st = DC.stringToBytes(value);
|
||||
rt.addInt32(st.length).addDC(st);
|
||||
rt
|
||||
..addInt32(st.length)
|
||||
..addDC(st);
|
||||
break;
|
||||
|
||||
case DataType.Resource:
|
||||
rt.addUint32((value as DistributedResource).id);
|
||||
rt.addUint32((value as DistributedResource).id as int);
|
||||
break;
|
||||
|
||||
case DataType.DistributedResource:
|
||||
rt.addUint32((value as IResource).instance.id);
|
||||
rt.addUint32((value as IResource).instance?.id as int);
|
||||
break;
|
||||
|
||||
case DataType.Structure:
|
||||
|
@ -34,8 +34,8 @@ const UNIX_EPOCH = 621355968000000000;
|
||||
const TWO_PWR_32 = (1 << 16) * (1 << 16);
|
||||
|
||||
class DC with IterableMixin<int> {
|
||||
Uint8List _data;
|
||||
ByteData _dv;
|
||||
late Uint8List _data;
|
||||
late ByteData _dv;
|
||||
|
||||
DC(int length) {
|
||||
_data = new Uint8List(length);
|
||||
@ -245,7 +245,8 @@ class DC with IterableMixin<int> {
|
||||
var list = new BinaryList();
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
var s = DC.stringToBytes(value[i]);
|
||||
list.addUint32(s.length).addUint8Array(s.toArray());
|
||||
list..addUint32(s.length)
|
||||
..addUint8Array(s.toArray());
|
||||
}
|
||||
|
||||
return list.toDC();
|
||||
@ -289,67 +290,67 @@ class DC with IterableMixin<int> {
|
||||
Uint8List.fromList(_data.getRange(offset, offset + length).toList()));
|
||||
}
|
||||
|
||||
getInt8(int offset) {
|
||||
int getInt8(int offset) {
|
||||
return _dv.getInt8(offset);
|
||||
}
|
||||
|
||||
getUint8(int offset) {
|
||||
int getUint8(int offset) {
|
||||
return _data[offset]; // this.dv.getUint8(offset);
|
||||
}
|
||||
|
||||
getInt16(int offset) {
|
||||
int getInt16(int offset) {
|
||||
return _dv.getInt16(offset);
|
||||
}
|
||||
|
||||
getUint16(int offset) {
|
||||
int getUint16(int offset) {
|
||||
return _dv.getUint16(offset);
|
||||
}
|
||||
|
||||
getInt32(int offset) {
|
||||
int getInt32(int offset) {
|
||||
return _dv.getInt32(offset);
|
||||
}
|
||||
|
||||
getUint32(int offset) {
|
||||
int getUint32(int offset) {
|
||||
return _dv.getUint32(offset);
|
||||
}
|
||||
|
||||
getFloat32(int offset) {
|
||||
double getFloat32(int offset) {
|
||||
return _dv.getFloat32(offset);
|
||||
}
|
||||
|
||||
getFloat64(int offset) {
|
||||
double getFloat64(int offset) {
|
||||
return _dv.getFloat64(offset);
|
||||
}
|
||||
|
||||
setInt8(int offset, int value) {
|
||||
void setInt8(int offset, int value) {
|
||||
return _dv.setInt8(offset, value);
|
||||
}
|
||||
|
||||
setUint8(int offset, int value) {
|
||||
void setUint8(int offset, int value) {
|
||||
return _dv.setUint8(offset, value);
|
||||
}
|
||||
|
||||
setInt16(int offset, int value) {
|
||||
void setInt16(int offset, int value) {
|
||||
return _dv.setInt16(offset, value);
|
||||
}
|
||||
|
||||
setUint16(int offset, int value) {
|
||||
void setUint16(int offset, int value) {
|
||||
return _dv.setUint16(offset, value);
|
||||
}
|
||||
|
||||
setInt32(int offset, int value) {
|
||||
void setInt32(int offset, int value) {
|
||||
return _dv.setInt32(offset, value);
|
||||
}
|
||||
|
||||
setUint32(int offset, int value) {
|
||||
void setUint32(int offset, int value) {
|
||||
return _dv.setUint32(offset, value);
|
||||
}
|
||||
|
||||
setFloat32(int offset, double value) {
|
||||
void setFloat32(int offset, double value) {
|
||||
return _dv.setFloat32(offset, value);
|
||||
}
|
||||
|
||||
setFloat64(int offset, double value) {
|
||||
void setFloat64(int offset, double value) {
|
||||
return _dv.setFloat64(offset, value);
|
||||
}
|
||||
|
||||
@ -397,7 +398,7 @@ class DC with IterableMixin<int> {
|
||||
return this.getUint8(offset) > 0;
|
||||
}
|
||||
|
||||
setBoolean(int offset, bool value) {
|
||||
void setBoolean(int offset, bool value) {
|
||||
this.setUint8(offset, value ? 1 : 0);
|
||||
}
|
||||
|
||||
@ -411,7 +412,7 @@ class DC with IterableMixin<int> {
|
||||
return String.fromCharCode(this.getUint16(offset));
|
||||
}
|
||||
|
||||
setChar(int offset, int value) {
|
||||
void setChar(int offset, int value) {
|
||||
this.setUint16(offset, value); //value.codeUnitAt(0));
|
||||
}
|
||||
|
||||
@ -462,11 +463,11 @@ class DC with IterableMixin<int> {
|
||||
return rt;
|
||||
}
|
||||
|
||||
getInt64(offset) {
|
||||
int getInt64(offset) {
|
||||
return _dv.getUint64(offset);
|
||||
}
|
||||
|
||||
getUint64(offset) {
|
||||
int getUint64(offset) {
|
||||
return _dv.getInt64(offset);
|
||||
}
|
||||
|
||||
@ -478,7 +479,7 @@ class DC with IterableMixin<int> {
|
||||
_dv.setUint64(offset, value);
|
||||
}
|
||||
|
||||
setDateTime(offset, DateTime value) {
|
||||
void setDateTime(offset, DateTime value) {
|
||||
// Unix Epoch
|
||||
var ticks = UNIX_EPOCH + (value.millisecondsSinceEpoch * 10000);
|
||||
this.setUint64(offset, ticks);
|
||||
@ -500,7 +501,7 @@ class DC with IterableMixin<int> {
|
||||
return new Guid(this.clip(offset, 16));
|
||||
}
|
||||
|
||||
setGuid(int offset, Guid guid) {
|
||||
void setGuid(int offset, Guid guid) {
|
||||
set(guid.value, offset);
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@ import 'DC.dart';
|
||||
class Guid {
|
||||
DC _data;
|
||||
|
||||
Guid(DC data) {
|
||||
_data = data;
|
||||
Guid(this._data) {
|
||||
|
||||
}
|
||||
|
||||
DC get value => _data;
|
||||
|
@ -43,9 +43,9 @@ class KeyList<KT, T> extends IEventHandler with MapMixin<KT, T> {
|
||||
|
||||
at(int index) => _map.values.elementAt(index);
|
||||
|
||||
bool _removableList;
|
||||
late bool _removableList;
|
||||
|
||||
T take(KT key) {
|
||||
T? take(KT key) {
|
||||
if (_map.containsKey(key)) {
|
||||
var v = _map[key];
|
||||
remove(key);
|
||||
@ -89,20 +89,20 @@ class KeyList<KT, T> extends IEventHandler with MapMixin<KT, T> {
|
||||
clear() {
|
||||
if (_removableList)
|
||||
for (var v in _map.values)
|
||||
(v as IDestructible)?.off("destroy", _itemDestroyed);
|
||||
(v as IDestructible).off("destroy", _itemDestroyed);
|
||||
|
||||
_map.clear();
|
||||
|
||||
emitArgs("cleared", [this]);
|
||||
}
|
||||
|
||||
T remove(key) {
|
||||
T? remove(key) {
|
||||
if (!_map.containsKey(key)) return null;
|
||||
|
||||
var value = _map[key];
|
||||
|
||||
if (_removableList)
|
||||
(value as IDestructible)?.off("destroy", _itemDestroyed);
|
||||
(value as IDestructible).off("destroy", _itemDestroyed);
|
||||
|
||||
_map.remove(key);
|
||||
|
||||
|
@ -4,7 +4,7 @@ import 'IRecord.dart';
|
||||
import 'KeyList.dart';
|
||||
|
||||
class Record extends KeyList with IRecord {
|
||||
Map<String, dynamic> _props;
|
||||
Map<String, dynamic> _props = Map<String, dynamic>();
|
||||
|
||||
@override
|
||||
Map<String, dynamic> serialize() {
|
||||
|
@ -1,4 +1,3 @@
|
||||
class SizeObject
|
||||
{
|
||||
int size;
|
||||
class SizeObject {
|
||||
int size = 0;
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
class StructureMetadata
|
||||
{
|
||||
|
||||
List<String> keys;
|
||||
List<int> types;
|
||||
class StructureMetadata {
|
||||
List<String>? keys; // = <String>[];
|
||||
List<int>? types;//
|
||||
|
||||
//const StructureMetadata(this.keys, this.types);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,18 +1,11 @@
|
||||
import 'DistributedConnection.dart';
|
||||
class DistributedPropertyContext
|
||||
{
|
||||
|
||||
class DistributedPropertyContext {
|
||||
dynamic value;
|
||||
DistributedConnection connection;
|
||||
dynamic Function(DistributedConnection) method;
|
||||
DistributedConnection? connection;
|
||||
dynamic Function(DistributedConnection)? method;
|
||||
|
||||
DistributedPropertyContext(this.method) {}
|
||||
|
||||
DistributedPropertyContext(this.method)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DistributedPropertyContext.setter(this.value, this.connection)
|
||||
{
|
||||
|
||||
}
|
||||
DistributedPropertyContext.setter(this.value, this.connection) {}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
import '../../Resource/Instance.dart';
|
||||
|
||||
import '../../Core/AsyncException.dart';
|
||||
import '../../Core/ErrorType.dart';
|
||||
import '../../Core/ExceptionCode.dart';
|
||||
@ -40,18 +43,17 @@ import '../Packets/IIPPacketAction.dart';
|
||||
|
||||
import '../../Resource/Template/EventTemplate.dart';
|
||||
|
||||
|
||||
class DistributedResource extends IResource {
|
||||
int _instanceId;
|
||||
DistributedConnection _connection;
|
||||
int? _instanceId;
|
||||
DistributedConnection? _connection;
|
||||
|
||||
bool _attached = false;
|
||||
//bool _isReady = false;
|
||||
|
||||
String _link;
|
||||
int _age;
|
||||
String? _link;
|
||||
int? _age;
|
||||
|
||||
List _properties;
|
||||
List _properties = [];
|
||||
bool _destroyed = false;
|
||||
|
||||
List<KeyValuePair<int, dynamic>> _queued_updates = [];
|
||||
@ -59,17 +61,17 @@ class DistributedResource extends IResource {
|
||||
/// <summary>
|
||||
/// Connection responsible for the distributed resource.
|
||||
/// </summary>
|
||||
DistributedConnection get connection => _connection;
|
||||
DistributedConnection? get connection => _connection;
|
||||
|
||||
/// <summary>
|
||||
/// Resource link
|
||||
/// </summary>
|
||||
String get link => _link;
|
||||
String? get link => _link;
|
||||
|
||||
/// <summary>
|
||||
/// Instance Id given by the other end.
|
||||
/// </summary>
|
||||
int get id => _instanceId;
|
||||
int? get id => _instanceId;
|
||||
|
||||
//bool get destroyed => _destroyed;
|
||||
|
||||
@ -84,7 +86,7 @@ class DistributedResource extends IResource {
|
||||
void destroy() {
|
||||
_destroyed = true;
|
||||
_attached = false;
|
||||
_connection.sendDetachRequest(_instanceId);
|
||||
_connection?.sendDetachRequest(_instanceId as int);
|
||||
emitArgs("destroy", [this]);
|
||||
}
|
||||
|
||||
@ -137,13 +139,19 @@ class DistributedResource extends IResource {
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<PropertyValue> internal_serialize() {
|
||||
var props = new List<PropertyValue>(_properties.length);
|
||||
// var props = _properties as List;
|
||||
// var rt = List<PropertyValue>(_properties.length);
|
||||
|
||||
for (var i = 0; i < _properties.length; i++)
|
||||
props[i] = new PropertyValue(
|
||||
_properties[i], instance.getAge(i), instance.getModificationDate(i));
|
||||
// for (var i = 0; i < _properties.length; i++)
|
||||
// rt[i] = new PropertyValue(_properties[i], instance?.getAge(i) as int,
|
||||
// instance?.getModificationDate(i) as DateTime);
|
||||
|
||||
return props;
|
||||
return List<PropertyValue>.generate(
|
||||
_properties.length,
|
||||
(i) => PropertyValue(_properties[i], instance?.getAge(i) as int,
|
||||
instance?.getModificationDate(i) as DateTime));
|
||||
|
||||
//return rt;
|
||||
}
|
||||
|
||||
bool internal_attach(List<PropertyValue> properties) {
|
||||
@ -152,14 +160,16 @@ class DistributedResource extends IResource {
|
||||
else {
|
||||
_suspended = false;
|
||||
|
||||
_properties = new List(properties.length); // object[properties.Length];
|
||||
//_properties = new List(properties.length); // object[properties.Length];
|
||||
|
||||
//_events = new DistributedResourceEvent[Instance.Template.Events.Length];
|
||||
|
||||
for (var i = 0; i < properties.length; i++) {
|
||||
instance.setAge(i, properties[i].age);
|
||||
instance.setModificationDate(i, properties[i].date);
|
||||
_properties[i] = properties[i].value;
|
||||
instance?.setAge(i, properties[i].age);
|
||||
instance?.setModificationDate(i, properties[i].date);
|
||||
|
||||
_properties.add(properties[i].value);
|
||||
//_properties[i] = properties[i].value;
|
||||
}
|
||||
|
||||
// trigger holded events/property updates.
|
||||
@ -180,9 +190,12 @@ class DistributedResource extends IResource {
|
||||
}
|
||||
|
||||
AsyncReply<dynamic> listen(event) {
|
||||
EventTemplate et = event is EventTemplate
|
||||
if (_destroyed) throw new Exception("Trying to access destroyed object");
|
||||
if (_suspended) throw new Exception("Trying to access suspended object");
|
||||
|
||||
EventTemplate? et = event is EventTemplate
|
||||
? event
|
||||
: instance.template.getEventTemplateByName(event);
|
||||
: instance?.template.getEventTemplateByName(event);
|
||||
|
||||
if (et == null)
|
||||
return AsyncReply<dynamic>().triggerError(new AsyncException(
|
||||
@ -192,13 +205,17 @@ class DistributedResource extends IResource {
|
||||
return AsyncReply().triggerError(new AsyncException(
|
||||
ErrorType.Management, ExceptionCode.NotListenable.index, ""));
|
||||
|
||||
return _connection.sendListenRequest(_instanceId, et.index);
|
||||
return _connection?.sendListenRequest(_instanceId as int, et.index)
|
||||
as AsyncReply;
|
||||
}
|
||||
|
||||
AsyncReply<dynamic> unlisten(event) {
|
||||
EventTemplate et = event is EventTemplate
|
||||
if (_destroyed) throw new Exception("Trying to access destroyed object");
|
||||
if (_suspended) throw new Exception("Trying to access suspended object");
|
||||
|
||||
EventTemplate? et = event is EventTemplate
|
||||
? event
|
||||
: instance.template.getEventTemplateByName(event);
|
||||
: instance?.template.getEventTemplateByName(event);
|
||||
|
||||
if (et == null)
|
||||
return AsyncReply().triggerError(new AsyncException(
|
||||
@ -208,48 +225,60 @@ class DistributedResource extends IResource {
|
||||
return AsyncReply().triggerError(new AsyncException(
|
||||
ErrorType.Management, ExceptionCode.NotListenable.index, ""));
|
||||
|
||||
return connection.sendUnlistenRequest(_instanceId, et.index);
|
||||
return connection?.sendUnlistenRequest(_instanceId as int, et.index)
|
||||
as AsyncReply;
|
||||
}
|
||||
|
||||
void internal_emitEventByIndex(int index, dynamic args) {
|
||||
// neglect events when the object is not yet attached
|
||||
if (!_attached) return;
|
||||
|
||||
var et = instance.template.getEventTemplateByIndex(index);
|
||||
var et = instance?.template.getEventTemplateByIndex(index);
|
||||
if (et != null) {
|
||||
emitArgs(et.name, [args]);
|
||||
//emitArgs(event, arguments)
|
||||
instance.emitResourceEvent(null, null, et.name, args);
|
||||
instance?.emitResourceEvent(null, null, et.name, args);
|
||||
}
|
||||
}
|
||||
|
||||
AsyncReply<dynamic> internal_invokeByNamedArguments(int index, Structure namedArgs) {
|
||||
AsyncReply<dynamic> internal_invokeByNamedArguments(
|
||||
int index, Structure namedArgs) {
|
||||
if (_destroyed) throw new Exception("Trying to access destroyed object");
|
||||
if (_suspended) throw new Exception("Trying to access suspended object");
|
||||
|
||||
if (instance == null) throw Exception("Object not initialized.");
|
||||
|
||||
var ins = instance as Instance;
|
||||
|
||||
if (index >= ins.template.functions.length)
|
||||
throw new Exception("Function index is incorrect");
|
||||
|
||||
return connection?.sendInvokeByNamedArguments(
|
||||
_instanceId as int, index, namedArgs) as AsyncReply<dynamic>;
|
||||
}
|
||||
|
||||
AsyncReply<dynamic> internal_invokeByArrayArguments(
|
||||
int index, List<dynamic> args) {
|
||||
if (_destroyed) throw new Exception("Trying to access destroyed object");
|
||||
|
||||
if (_suspended) throw new Exception("Trying to access suspended object");
|
||||
if (instance == null) throw Exception("Object not initialized.");
|
||||
|
||||
if (index >= instance.template.functions.length)
|
||||
var ins = instance as Instance;
|
||||
|
||||
if (index >= ins.template.functions.length)
|
||||
throw new Exception("Function index is incorrect");
|
||||
|
||||
return connection.sendInvokeByNamedArguments(_instanceId, index, namedArgs);
|
||||
}
|
||||
|
||||
AsyncReply<dynamic> internal_invokeByArrayArguments(int index, List<dynamic> args) {
|
||||
if (_destroyed) throw new Exception("Trying to access destroyed object");
|
||||
|
||||
if (_suspended) throw new Exception("Trying to access suspended object");
|
||||
|
||||
if (index >= instance.template.functions.length)
|
||||
throw new Exception("Function index is incorrect");
|
||||
|
||||
return connection.sendInvokeByArrayArguments(_instanceId, index, args);
|
||||
return _connection?.sendInvokeByArrayArguments(
|
||||
_instanceId as int, index, args) as AsyncReply;
|
||||
}
|
||||
|
||||
operator [](String index) {
|
||||
var pt = instance.template.getPropertyTemplateByName(index);
|
||||
var pt = instance?.template.getPropertyTemplateByName(index);
|
||||
if (pt != null) return get(pt.index);
|
||||
}
|
||||
|
||||
operator []=(String index, value) {
|
||||
var pt = instance.template.getPropertyTemplateByName(index);
|
||||
var pt = instance?.template.getPropertyTemplateByName(index);
|
||||
if (pt != null) set(pt.index, value);
|
||||
}
|
||||
|
||||
@ -266,7 +295,7 @@ class DistributedResource extends IResource {
|
||||
var memberName = _getMemberName(invocation.memberName);
|
||||
|
||||
if (invocation.isMethod) {
|
||||
var ft = instance.template.getFunctionTemplateByName(memberName);
|
||||
var ft = instance?.template.getFunctionTemplateByName(memberName);
|
||||
|
||||
if (_attached && ft != null) {
|
||||
if (invocation.namedArguments.length > 0) {
|
||||
@ -281,14 +310,14 @@ class DistributedResource extends IResource {
|
||||
}
|
||||
}
|
||||
} else if (invocation.isSetter) {
|
||||
var pt = instance.template.getPropertyTemplateByName(memberName);
|
||||
var pt = instance?.template.getPropertyTemplateByName(memberName);
|
||||
|
||||
if (pt != null) {
|
||||
set(pt.index, invocation.positionalArguments[0]);
|
||||
return true;
|
||||
}
|
||||
} else if (invocation.isGetter) {
|
||||
var pt = instance.template.getPropertyTemplateByName(memberName);
|
||||
var pt = instance?.template.getPropertyTemplateByName(memberName);
|
||||
|
||||
if (pt != null) {
|
||||
return get(pt.index);
|
||||
@ -304,7 +333,9 @@ class DistributedResource extends IResource {
|
||||
/// <param name="index">Zero-based property index.</param>
|
||||
/// <returns>Value</returns>
|
||||
get(int index) {
|
||||
if (index >= _properties.length) return null;
|
||||
//if (_properties == null) return null;
|
||||
//var props = _properties as List;
|
||||
//if (index >= props.length) return null;
|
||||
return _properties[index];
|
||||
}
|
||||
|
||||
@ -312,9 +343,12 @@ class DistributedResource extends IResource {
|
||||
if (!_attached) {
|
||||
_queued_updates.add(KeyValuePair(index, value));
|
||||
} else {
|
||||
var pt = instance.template.getPropertyTemplateByIndex(index);
|
||||
var pt = instance?.template.getPropertyTemplateByIndex(index);
|
||||
|
||||
if (pt != null) {
|
||||
_properties[index] = value;
|
||||
instance.emitModification(pt, value);
|
||||
instance?.emitModification(pt, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,18 +359,19 @@ class DistributedResource extends IResource {
|
||||
/// <param name="value">Value</param>
|
||||
/// <returns>Indicator when the property is set.</returns>
|
||||
AsyncReply<dynamic> set(int index, dynamic value) {
|
||||
if (index >= _properties.length) return null;
|
||||
if (index >= _properties.length)
|
||||
throw Exception("Property with index `${index}` not found.");
|
||||
|
||||
var reply = new AsyncReply<dynamic>();
|
||||
var con = _connection as DistributedConnection;
|
||||
|
||||
var parameters = Codec.compose(value, connection);
|
||||
connection
|
||||
.sendRequest(IIPPacketAction.SetProperty)
|
||||
.addUint32(_instanceId)
|
||||
.addUint8(index)
|
||||
.addDC(parameters)
|
||||
var parameters = Codec.compose(value, con);
|
||||
(con.sendRequest(IIPPacketAction.SetProperty)
|
||||
..addUint32(_instanceId as int)
|
||||
..addUint8(index)
|
||||
..addDC(parameters))
|
||||
.done()
|
||||
.then((res) {
|
||||
..then((res) {
|
||||
// not really needed, server will always send property modified,
|
||||
// this only happens if the programmer forgot to emit in property setter
|
||||
_properties[index] = value;
|
||||
|
@ -17,7 +17,7 @@ class DistributedServer extends IResource {
|
||||
return AsyncReply.ready(true);
|
||||
}
|
||||
|
||||
EntryPoint entryPoint;
|
||||
EntryPoint? entryPoint;
|
||||
|
||||
@override
|
||||
getProperty(String name) => null;
|
||||
|
@ -25,35 +25,25 @@ SOFTWARE.
|
||||
import '../Data/DC.dart';
|
||||
import 'dart:core';
|
||||
|
||||
class NetworkBuffer
|
||||
{
|
||||
DC _data;
|
||||
class NetworkBuffer {
|
||||
DC _data = new DC(0);
|
||||
|
||||
int _neededDataLength = 0;
|
||||
|
||||
NetworkBuffer()
|
||||
{
|
||||
_data = new DC(0);
|
||||
}
|
||||
NetworkBuffer() {}
|
||||
|
||||
bool get protected => _neededDataLength > _data.length;
|
||||
|
||||
int get available => _data.length;
|
||||
|
||||
|
||||
|
||||
void holdForNextWrite(DC src, int offset, int size)
|
||||
{
|
||||
void holdForNextWrite(DC src, int offset, int size) {
|
||||
holdFor(src, offset, size, size + 1);
|
||||
}
|
||||
|
||||
|
||||
void holdFor(DC src, int offset, int size, int needed)
|
||||
{
|
||||
void holdFor(DC src, int offset, int size, int needed) {
|
||||
//lock (syncLock)
|
||||
//{
|
||||
if (size >= needed)
|
||||
throw new Exception("Size >= Needed !");
|
||||
if (size >= needed) throw new Exception("Size >= Needed !");
|
||||
|
||||
//trim = true;
|
||||
_data = DC.combine(src, offset, size, _data, 0, _data.length);
|
||||
@ -62,68 +52,50 @@ class NetworkBuffer
|
||||
//}
|
||||
}
|
||||
|
||||
void holdForNeeded(DC src, int needed)
|
||||
{
|
||||
void holdForNeeded(DC src, int needed) {
|
||||
holdFor(src, 0, src.length, needed);
|
||||
}
|
||||
|
||||
bool protect(DC data, int offset, int needed)
|
||||
{
|
||||
bool protect(DC data, int offset, int needed) {
|
||||
int dataLength = _data.length - offset;
|
||||
|
||||
// protection
|
||||
if (dataLength < needed)
|
||||
{
|
||||
if (dataLength < needed) {
|
||||
holdFor(data, offset, dataLength, needed);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void write(DC src, int offset, int length)
|
||||
{
|
||||
void write(DC src, int offset, int length) {
|
||||
//lock(syncLock)
|
||||
_data.append(src, offset, length);
|
||||
}
|
||||
|
||||
bool get canRead
|
||||
{
|
||||
if (_data.length == 0)
|
||||
return false;
|
||||
if (_data.length < _neededDataLength)
|
||||
return false;
|
||||
bool get canRead {
|
||||
if (_data.length == 0) return false;
|
||||
if (_data.length < _neededDataLength) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DC read()
|
||||
{
|
||||
DC? read() {
|
||||
//lock (syncLock)
|
||||
//{
|
||||
if (_data.length == 0)
|
||||
return null;
|
||||
if (_data.length == 0) return null;
|
||||
|
||||
DC rt = null;
|
||||
DC? rt = null;
|
||||
|
||||
if (_neededDataLength == 0)
|
||||
{
|
||||
if (_neededDataLength == 0) {
|
||||
rt = _data;
|
||||
_data = new DC(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_data.length >= _neededDataLength)
|
||||
{
|
||||
} else {
|
||||
if (_data.length >= _neededDataLength) {
|
||||
rt = _data;
|
||||
_data = new DC(0);
|
||||
_neededDataLength = 0;
|
||||
return rt;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ import '../Data/DC.dart';
|
||||
import 'Sockets/IPEndPoint.dart';
|
||||
|
||||
class NetworkConnection extends IDestructible with INetworkReceiver<ISocket> {
|
||||
ISocket _sock;
|
||||
ISocket? _sock;
|
||||
|
||||
DateTime _lastAction;
|
||||
DateTime _lastAction = DateTime.now();
|
||||
|
||||
//public delegate void DataReceivedEvent(NetworkConnection sender, NetworkBuffer data);
|
||||
//public delegate void ConnectionClosedEvent(NetworkConnection sender);
|
||||
@ -48,7 +48,6 @@ class NetworkConnection extends IDestructible with INetworkReceiver<ISocket> {
|
||||
|
||||
bool _processing = false;
|
||||
|
||||
|
||||
void destroy() {
|
||||
// if (connected)
|
||||
close();
|
||||
@ -58,7 +57,7 @@ class NetworkConnection extends IDestructible with INetworkReceiver<ISocket> {
|
||||
|
||||
NetworkConnection() {}
|
||||
|
||||
ISocket get socket => _sock;
|
||||
ISocket? get socket => _sock;
|
||||
|
||||
void assign(ISocket socket) {
|
||||
_lastAction = DateTime.now();
|
||||
@ -71,14 +70,14 @@ class NetworkConnection extends IDestructible with INetworkReceiver<ISocket> {
|
||||
//socket.on("connect", socket_OnConnect);
|
||||
}
|
||||
|
||||
ISocket unassign() {
|
||||
ISocket? unassign() {
|
||||
if (_sock != null) {
|
||||
// connected = false;
|
||||
// _sock.off("close", socket_OnClose);
|
||||
// _sock.off("connect", socket_OnConnect);
|
||||
// _sock.off("receive", socket_OnReceive);
|
||||
|
||||
_sock.receiver = null;
|
||||
_sock?.receiver = null;
|
||||
var rt = _sock;
|
||||
_sock = null;
|
||||
|
||||
@ -92,17 +91,13 @@ class NetworkConnection extends IDestructible with INetworkReceiver<ISocket> {
|
||||
emitArgs("dataReceived", [data]);
|
||||
}
|
||||
|
||||
void connected(){
|
||||
void connected() {}
|
||||
|
||||
}
|
||||
|
||||
void disconnected(){
|
||||
|
||||
}
|
||||
void disconnected() {}
|
||||
|
||||
void close() {
|
||||
try {
|
||||
if (_sock != null) _sock.close();
|
||||
if (_sock != null) _sock?.close();
|
||||
} catch (ex) {
|
||||
//Global.Log("NetworkConenction:Close", LogType.Error, ex.ToString());
|
||||
|
||||
@ -111,17 +106,17 @@ class NetworkConnection extends IDestructible with INetworkReceiver<ISocket> {
|
||||
|
||||
DateTime get lastAction => _lastAction;
|
||||
|
||||
IPEndPoint get remoteEndPoint => _sock?.remoteEndPoint;
|
||||
IPEndPoint? get remoteEndPoint => _sock?.remoteEndPoint;
|
||||
|
||||
IPEndPoint get localEndPoint => _sock?.localEndPoint;
|
||||
IPEndPoint? get localEndPoint => _sock?.localEndPoint;
|
||||
|
||||
bool get isConnected => _sock.state == SocketState.Established;
|
||||
bool get isConnected => _sock?.state == SocketState.Established;
|
||||
|
||||
void send(DC msg) {
|
||||
try {
|
||||
if (_sock != null) {
|
||||
_lastAction = DateTime.now();
|
||||
_sock.send(msg);
|
||||
_sock?.send(msg);
|
||||
}
|
||||
} catch (ex) {
|
||||
//Console.WriteLine(ex.ToString());
|
||||
@ -151,8 +146,8 @@ class NetworkConnection extends IDestructible with INetworkReceiver<ISocket> {
|
||||
if (_sock == null) return;
|
||||
|
||||
// Closed ?
|
||||
if (_sock.state == SocketState.Closed ||
|
||||
_sock.state == SocketState.Terminated) // || !connected)
|
||||
if (_sock?.state == SocketState.Closed ||
|
||||
_sock?.state == SocketState.Terminated) // || !connected)
|
||||
return;
|
||||
|
||||
_lastAction = DateTime.now();
|
||||
|
@ -26,84 +26,73 @@ import 'IIPAuthPacketAction.dart';
|
||||
import 'IIPAuthPacketCommand.dart';
|
||||
import '../../Security/Authority/AuthenticationMethod.dart';
|
||||
|
||||
class IIPAuthPacket
|
||||
{
|
||||
class IIPAuthPacket {
|
||||
int command = 0;
|
||||
int action = 0;
|
||||
|
||||
int command;
|
||||
int action;
|
||||
int errorCode = 0;
|
||||
String errorMessage = "";
|
||||
|
||||
int errorCode;
|
||||
String errorMessage;
|
||||
AuthenticationMethod localMethod = AuthenticationMethod.None;
|
||||
|
||||
AuthenticationMethod localMethod;
|
||||
DC? sourceInfo;
|
||||
|
||||
DC sourceInfo;
|
||||
DC? hash;
|
||||
|
||||
DC hash;
|
||||
DC? sessionId;
|
||||
|
||||
DC sessionId;
|
||||
AuthenticationMethod remoteMethod = AuthenticationMethod.None;
|
||||
|
||||
AuthenticationMethod remoteMethod;
|
||||
String? domain;
|
||||
|
||||
String domain;
|
||||
int certificateId = 0;
|
||||
|
||||
int certificateId;
|
||||
String? localUsername;
|
||||
|
||||
String localUsername;
|
||||
String? remoteUsername;
|
||||
|
||||
String remoteUsername;
|
||||
DC? localPassword;
|
||||
|
||||
DC localPassword;
|
||||
DC? remotePassword;
|
||||
|
||||
DC remotePassword;
|
||||
DC? localToken;
|
||||
|
||||
DC localToken;
|
||||
DC? remoteToken;
|
||||
|
||||
DC remoteToken;
|
||||
DC? asymetricEncryptionKey;
|
||||
|
||||
DC asymetricEncryptionKey;
|
||||
DC? localNonce;
|
||||
|
||||
DC localNonce;
|
||||
DC? remoteNonce;
|
||||
|
||||
DC remoteNonce;
|
||||
int remoteTokenIndex = 0;
|
||||
|
||||
int remoteTokenIndex;
|
||||
int _dataLengthNeeded = 0;
|
||||
|
||||
int _dataLengthNeeded;
|
||||
|
||||
bool _notEnough(int offset, int ends, int needed)
|
||||
{
|
||||
if (offset + needed > ends)
|
||||
{
|
||||
bool _notEnough(int offset, int ends, int needed) {
|
||||
if (offset + needed > ends) {
|
||||
_dataLengthNeeded = needed - (ends - offset);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
toString()
|
||||
{
|
||||
toString() {
|
||||
return command.toString() + " " + action.toString();
|
||||
}
|
||||
|
||||
int parse(DC data, int offset, int ends)
|
||||
{
|
||||
int parse(DC data, int offset, int ends) {
|
||||
var oOffset = offset;
|
||||
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
|
||||
command = (data[offset] >> 6);
|
||||
|
||||
if (command == IIPAuthPacketCommand.Action)
|
||||
{
|
||||
if (command == IIPAuthPacketCommand.Action) {
|
||||
action = (data[offset++] & 0x3f);
|
||||
|
||||
if (action == IIPAuthPacketAction.AuthenticateHash)
|
||||
{
|
||||
if (_notEnough(offset, ends, 32))
|
||||
return -_dataLengthNeeded;
|
||||
if (action == IIPAuthPacketAction.AuthenticateHash) {
|
||||
if (_notEnough(offset, ends, 32)) return -_dataLengthNeeded;
|
||||
|
||||
hash = data.clip(offset, 32);
|
||||
|
||||
@ -112,18 +101,14 @@ class IIPAuthPacket
|
||||
//Hash = hash;
|
||||
|
||||
offset += 32;
|
||||
}
|
||||
else if (action == IIPAuthPacketAction.NewConnection)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPAuthPacketAction.NewConnection) {
|
||||
if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded;
|
||||
|
||||
var length = data.getUint16(offset);
|
||||
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, length))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, length)) return -_dataLengthNeeded;
|
||||
|
||||
sourceInfo = data.clip(offset, length);
|
||||
|
||||
@ -132,14 +117,11 @@ class IIPAuthPacket
|
||||
//SourceInfo = sourceInfo;
|
||||
|
||||
offset += 32;
|
||||
}
|
||||
else if (action == IIPAuthPacketAction.ResumeConnection
|
||||
|| action == IIPAuthPacketAction.ConnectionEstablished)
|
||||
{
|
||||
} else if (action == IIPAuthPacketAction.ResumeConnection ||
|
||||
action == IIPAuthPacketAction.ConnectionEstablished) {
|
||||
//var sessionId = new byte[32];
|
||||
|
||||
if (_notEnough(offset, ends, 32))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 32)) return -_dataLengthNeeded;
|
||||
|
||||
sessionId = data.clip(offset, 32);
|
||||
|
||||
@ -148,20 +130,15 @@ class IIPAuthPacket
|
||||
|
||||
offset += 32;
|
||||
}
|
||||
}
|
||||
else if (command == IIPAuthPacketCommand.Declare)
|
||||
{
|
||||
} else if (command == IIPAuthPacketCommand.Declare) {
|
||||
remoteMethod = AuthenticationMethod.values[((data[offset] >> 4) & 0x3)];
|
||||
localMethod = AuthenticationMethod.values[((data[offset] >> 2) & 0x3)];
|
||||
var encrypt = ((data[offset++] & 0x2) == 0x2);
|
||||
|
||||
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
|
||||
var domainLength = data[offset++];
|
||||
if (_notEnough(offset, ends, domainLength))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, domainLength)) return -_dataLengthNeeded;
|
||||
|
||||
var domain = data.getString(offset, domainLength);
|
||||
|
||||
@ -169,14 +146,9 @@ class IIPAuthPacket
|
||||
|
||||
offset += domainLength;
|
||||
|
||||
|
||||
if (remoteMethod == AuthenticationMethod.Credentials)
|
||||
{
|
||||
if (localMethod == AuthenticationMethod.None)
|
||||
{
|
||||
if (_notEnough(offset, ends, 33))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
if (remoteMethod == AuthenticationMethod.Credentials) {
|
||||
if (localMethod == AuthenticationMethod.None) {
|
||||
if (_notEnough(offset, ends, 33)) return -_dataLengthNeeded;
|
||||
|
||||
remoteNonce = data.clip(offset, 32);
|
||||
|
||||
@ -184,21 +156,15 @@ class IIPAuthPacket
|
||||
|
||||
var length = data[offset++];
|
||||
|
||||
if (_notEnough(offset, ends, length))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, length)) return -_dataLengthNeeded;
|
||||
|
||||
remoteUsername = data.getString(offset, length);
|
||||
|
||||
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
else if (remoteMethod == AuthenticationMethod.Token)
|
||||
{
|
||||
if (localMethod == AuthenticationMethod.None)
|
||||
{
|
||||
if (_notEnough(offset, ends, 40))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (remoteMethod == AuthenticationMethod.Token) {
|
||||
if (localMethod == AuthenticationMethod.None) {
|
||||
if (_notEnough(offset, ends, 40)) return -_dataLengthNeeded;
|
||||
|
||||
remoteNonce = data.clip(offset, 32);
|
||||
|
||||
@ -209,93 +175,66 @@ class IIPAuthPacket
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (encrypt)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
if (encrypt) {
|
||||
if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded;
|
||||
|
||||
var keyLength = data.getUint16(offset);
|
||||
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, keyLength))
|
||||
return -_dataLengthNeeded;
|
||||
|
||||
if (_notEnough(offset, ends, keyLength)) return -_dataLengthNeeded;
|
||||
|
||||
asymetricEncryptionKey = data.clip(offset, keyLength);
|
||||
|
||||
offset += keyLength;
|
||||
}
|
||||
}
|
||||
else if (command == IIPAuthPacketCommand.Acknowledge)
|
||||
{
|
||||
} else if (command == IIPAuthPacketCommand.Acknowledge) {
|
||||
remoteMethod = AuthenticationMethod.values[((data[offset] >> 4) & 0x3)];
|
||||
localMethod = AuthenticationMethod.values[((data[offset] >> 2) & 0x3)];
|
||||
var encrypt = ((data[offset++] & 0x2) == 0x2);
|
||||
|
||||
if (remoteMethod == AuthenticationMethod.None)
|
||||
{
|
||||
if (localMethod == AuthenticationMethod.None)
|
||||
{
|
||||
if (remoteMethod == AuthenticationMethod.None) {
|
||||
if (localMethod == AuthenticationMethod.None) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
else if (remoteMethod == AuthenticationMethod.Credentials
|
||||
|| remoteMethod == AuthenticationMethod.Token)
|
||||
{
|
||||
if (localMethod == AuthenticationMethod.None)
|
||||
{
|
||||
if (_notEnough(offset, ends, 32))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (remoteMethod == AuthenticationMethod.Credentials ||
|
||||
remoteMethod == AuthenticationMethod.Token) {
|
||||
if (localMethod == AuthenticationMethod.None) {
|
||||
if (_notEnough(offset, ends, 32)) return -_dataLengthNeeded;
|
||||
|
||||
remoteNonce = data.clip(offset, 32);
|
||||
offset += 32;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (encrypt)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
if (encrypt) {
|
||||
if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded;
|
||||
|
||||
var keyLength = data.getUint16(offset);
|
||||
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, keyLength))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, keyLength)) return -_dataLengthNeeded;
|
||||
|
||||
asymetricEncryptionKey = data.clip(offset, keyLength);
|
||||
|
||||
offset += keyLength;
|
||||
}
|
||||
}
|
||||
else if (command == IIPAuthPacketCommand.Error)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (command == IIPAuthPacketCommand.Error) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
offset++;
|
||||
errorCode = data[offset++];
|
||||
|
||||
|
||||
var cl = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
errorMessage = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return offset - oOffset;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -31,181 +31,136 @@ import 'IIPPacketReport.dart';
|
||||
import '../../Data/Codec.dart';
|
||||
import '../../Data/DataType.dart';
|
||||
|
||||
class IIPPacket
|
||||
{
|
||||
class IIPPacket {
|
||||
int report = 0;
|
||||
|
||||
int command = 0;
|
||||
|
||||
int action = 0;
|
||||
|
||||
int event = 0;
|
||||
|
||||
int previousCommand = 0;
|
||||
|
||||
int previousAction = 0;
|
||||
|
||||
int report;
|
||||
int previousEvent = 0;
|
||||
|
||||
int command;
|
||||
int resourceId = 0;
|
||||
int newResourceId = 0;
|
||||
|
||||
int action;
|
||||
int childId = 0;
|
||||
int storeId = 0;
|
||||
|
||||
int event;
|
||||
int resourceAge = 0;
|
||||
DC content = DC(0);
|
||||
int errorCode = 0;
|
||||
String errorMessage = "";
|
||||
String className = "";
|
||||
String resourceLink = "";
|
||||
Guid classId = Guid(DC(0));
|
||||
int methodIndex = 0;
|
||||
String methodName = "";
|
||||
int callbackId = 0;
|
||||
int progressValue = 0;
|
||||
int progressMax = 0;
|
||||
DateTime fromDate = DateTime(2000);
|
||||
DateTime toDate = DateTime(2000);
|
||||
int fromAge = 0;
|
||||
int toAge = 0;
|
||||
|
||||
int previousCommand;
|
||||
int _dataLengthNeeded = 0;
|
||||
int _originalOffset = 0;
|
||||
|
||||
|
||||
int previousAction;
|
||||
|
||||
int previousEvent;
|
||||
|
||||
|
||||
int resourceId;
|
||||
int newResourceId;
|
||||
|
||||
int childId;
|
||||
int storeId;
|
||||
|
||||
int resourceAge;
|
||||
DC content;
|
||||
int errorCode;
|
||||
String errorMessage;
|
||||
String className ;
|
||||
String resourceLink ;
|
||||
Guid classId ;
|
||||
int methodIndex ;
|
||||
String methodName;
|
||||
int callbackId ;
|
||||
int progressValue;
|
||||
int progressMax ;
|
||||
DateTime fromDate ;
|
||||
DateTime toDate;
|
||||
int fromAge;
|
||||
int toAge;
|
||||
|
||||
int _dataLengthNeeded;
|
||||
int _originalOffset;
|
||||
|
||||
|
||||
bool _notEnough(int offset, int ends, int needed)
|
||||
{
|
||||
if (offset + needed > ends)
|
||||
{
|
||||
bool _notEnough(int offset, int ends, int needed) {
|
||||
if (offset + needed > ends) {
|
||||
_dataLengthNeeded = needed - (ends - offset);
|
||||
//_dataLengthNeeded = (needed - (ends - offset)) + (offset - _originalOffset);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
int parse(DC data, int offset, int ends)
|
||||
{
|
||||
int parse(DC data, int offset, int ends) {
|
||||
_originalOffset = offset;
|
||||
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
|
||||
previousCommand = command;
|
||||
|
||||
command = (data[offset] >> 6);
|
||||
|
||||
if (command == IIPPacketCommand.Event)
|
||||
{
|
||||
if (command == IIPPacketCommand.Event) {
|
||||
event = (data[offset++] & 0x3f);
|
||||
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if (command == IIPPacketCommand.Report)
|
||||
{
|
||||
} else if (command == IIPPacketCommand.Report) {
|
||||
report = (data[offset++] & 0x3f);
|
||||
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
callbackId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
previousAction = action;
|
||||
action = (data[offset++] & 0x3f);
|
||||
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
callbackId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
if (command == IIPPacketCommand.Event)
|
||||
{
|
||||
if (event == IIPPacketEvent.ResourceReassigned)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
if (command == IIPPacketCommand.Event) {
|
||||
if (event == IIPPacketEvent.ResourceReassigned) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
newResourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
}
|
||||
else if (event == IIPPacketEvent.ResourceDestroyed)
|
||||
{
|
||||
} else if (event == IIPPacketEvent.ResourceDestroyed) {
|
||||
// nothing to parse
|
||||
}
|
||||
else if (event == IIPPacketEvent.ChildAdded
|
||||
|| event == IIPPacketEvent.ChildRemoved)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (event == IIPPacketEvent.ChildAdded ||
|
||||
event == IIPPacketEvent.ChildRemoved) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
childId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if(event == IIPPacketEvent.Renamed)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (event == IIPPacketEvent.Renamed) {
|
||||
if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
|
||||
offset += cl;
|
||||
}
|
||||
else if (event == IIPPacketEvent.PropertyUpdated
|
||||
|| event == IIPPacketEvent.EventOccurred)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (event == IIPPacketEvent.PropertyUpdated ||
|
||||
event == IIPPacketEvent.EventOccurred) {
|
||||
if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(dt);
|
||||
|
||||
if (size < 0)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
if (size < 0) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 5, cl + 5);
|
||||
offset += cl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_notEnough(offset, ends, size))
|
||||
return -_dataLengthNeeded;
|
||||
} else {
|
||||
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
@ -229,57 +184,39 @@ class IIPPacket
|
||||
|
||||
// }
|
||||
// Attribute
|
||||
else if (event == IIPPacketEvent.AttributesUpdated)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
else if (event == IIPPacketEvent.AttributesUpdated) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
|
||||
offset += cl;
|
||||
}
|
||||
}
|
||||
else if (command == IIPPacketCommand.Request)
|
||||
{
|
||||
if (action == IIPPacketAction.AttachResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (command == IIPPacketCommand.Request) {
|
||||
if (action == IIPPacketAction.AttachResource) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if (action == IIPPacketAction.ReattachResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 12))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.ReattachResource) {
|
||||
if (_notEnough(offset, ends, 12)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
resourceAge = data.getUint64(offset);
|
||||
offset += 8;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.DetachResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.DetachResource) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.CreateResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 12))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.CreateResource) {
|
||||
if (_notEnough(offset, ends, 12)) return -_dataLengthNeeded;
|
||||
|
||||
storeId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
@ -289,106 +226,72 @@ class IIPPacket
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
}
|
||||
else if (action == IIPPacketAction.DeleteResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.DeleteResource) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.AddChild
|
||||
|| action == IIPPacketAction.RemoveChild)
|
||||
{
|
||||
if (_notEnough(offset, ends, 8))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.AddChild ||
|
||||
action == IIPPacketAction.RemoveChild) {
|
||||
if (_notEnough(offset, ends, 8)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
childId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if (action == IIPPacketAction.RenameResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 6))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.RenameResource) {
|
||||
if (_notEnough(offset, ends, 6)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
var cl = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
}
|
||||
else if (action == IIPPacketAction.TemplateFromClassName)
|
||||
{
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.TemplateFromClassName) {
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data[offset++];
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
className = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.TemplateFromClassId)
|
||||
{
|
||||
if (_notEnough(offset, ends, 16))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.TemplateFromClassId) {
|
||||
if (_notEnough(offset, ends, 16)) return -_dataLengthNeeded;
|
||||
|
||||
classId = data.getGuid(offset);
|
||||
offset += 16;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.TemplateFromResourceId)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.TemplateFromResourceId) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if (action == IIPPacketAction.QueryLink
|
||||
|| action == IIPPacketAction.LinkTemplates)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.QueryLink ||
|
||||
action == IIPPacketAction.LinkTemplates) {
|
||||
if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
resourceLink = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
}
|
||||
else if (action == IIPPacketAction.ResourceChildren
|
||||
|| action == IIPPacketAction.ResourceParents)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.ResourceChildren ||
|
||||
action == IIPPacketAction.ResourceParents) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if (action == IIPPacketAction.ResourceHistory)
|
||||
{
|
||||
if (_notEnough(offset, ends, 20))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.ResourceHistory) {
|
||||
if (_notEnough(offset, ends, 20)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
@ -398,13 +301,9 @@ class IIPPacket
|
||||
|
||||
toDate = data.getDateTime(offset);
|
||||
offset += 8;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.InvokeFunctionArrayArguments
|
||||
|| action == IIPPacketAction.InvokeFunctionNamedArguments)
|
||||
{
|
||||
if (_notEnough(offset, ends, 9))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.InvokeFunctionArrayArguments ||
|
||||
action == IIPPacketAction.InvokeFunctionNamedArguments) {
|
||||
if (_notEnough(offset, ends, 9)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
@ -414,18 +313,13 @@ class IIPPacket
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.Listen
|
||||
|| action == IIPPacketAction.Unlisten)
|
||||
{
|
||||
if (_notEnough(offset, ends, 5))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.Listen ||
|
||||
action == IIPPacketAction.Unlisten) {
|
||||
if (_notEnough(offset, ends, 5)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
@ -457,72 +351,55 @@ class IIPPacket
|
||||
// offset += 8;
|
||||
|
||||
// }
|
||||
else if (action == IIPPacketAction.SetProperty)
|
||||
{
|
||||
if (_notEnough(offset, ends, 6))
|
||||
return -_dataLengthNeeded;
|
||||
else if (action == IIPPacketAction.SetProperty) {
|
||||
if (_notEnough(offset, ends, 6)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(dt);
|
||||
|
||||
if (size < 0)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
if (size < 0) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 5, cl + 5);
|
||||
offset += cl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_notEnough(offset, ends, size))
|
||||
return -_dataLengthNeeded;
|
||||
} else {
|
||||
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
}
|
||||
}
|
||||
// Attributes
|
||||
else if (action == IIPPacketAction.UpdateAllAttributes
|
||||
|| action == IIPPacketAction.GetAttributes
|
||||
|| action == IIPPacketAction.UpdateAttributes
|
||||
|| action == IIPPacketAction.ClearAttributes)
|
||||
{
|
||||
if (_notEnough(offset, ends, 8))
|
||||
return -_dataLengthNeeded;
|
||||
else if (action == IIPPacketAction.UpdateAllAttributes ||
|
||||
action == IIPPacketAction.GetAttributes ||
|
||||
action == IIPPacketAction.UpdateAttributes ||
|
||||
action == IIPPacketAction.ClearAttributes) {
|
||||
if (_notEnough(offset, ends, 8)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
}
|
||||
}
|
||||
else if (command == IIPPacketCommand.Reply)
|
||||
{
|
||||
if (action == IIPPacketAction.AttachResource
|
||||
|| action == IIPPacketAction.ReattachResource)
|
||||
{
|
||||
|
||||
if (_notEnough(offset, ends, 26))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (command == IIPPacketCommand.Reply) {
|
||||
if (action == IIPPacketAction.AttachResource ||
|
||||
action == IIPPacketAction.ReattachResource) {
|
||||
if (_notEnough(offset, ends, 26)) return -_dataLengthNeeded;
|
||||
|
||||
classId = data.getGuid(offset);
|
||||
offset += 16;
|
||||
@ -533,176 +410,132 @@ class IIPPacket
|
||||
var cl = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
resourceLink = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
}
|
||||
else if (action == IIPPacketAction.DetachResource)
|
||||
{
|
||||
} else if (action == IIPPacketAction.DetachResource) {
|
||||
// nothing to do
|
||||
}
|
||||
else if (action == IIPPacketAction.CreateResource)
|
||||
{
|
||||
if (_notEnough(offset, ends, 20))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.CreateResource) {
|
||||
if (_notEnough(offset, ends, 20)) return -_dataLengthNeeded;
|
||||
|
||||
//ClassId = data.GetGuid(offset);
|
||||
//offset += 16;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
}
|
||||
else if (action == IIPPacketAction.DetachResource)
|
||||
{
|
||||
} else if (action == IIPPacketAction.DetachResource) {
|
||||
// nothing to do
|
||||
}
|
||||
// Inquire
|
||||
else if (action == IIPPacketAction.TemplateFromClassName
|
||||
|| action == IIPPacketAction.TemplateFromClassId
|
||||
|| action == IIPPacketAction.TemplateFromResourceId
|
||||
|| action == IIPPacketAction.QueryLink
|
||||
|| action == IIPPacketAction.ResourceChildren
|
||||
|| action == IIPPacketAction.ResourceParents
|
||||
|| action == IIPPacketAction.ResourceHistory
|
||||
|| action == IIPPacketAction.LinkTemplates
|
||||
else if (action == IIPPacketAction.TemplateFromClassName ||
|
||||
action == IIPPacketAction.TemplateFromClassId ||
|
||||
action == IIPPacketAction.TemplateFromResourceId ||
|
||||
action == IIPPacketAction.QueryLink ||
|
||||
action == IIPPacketAction.ResourceChildren ||
|
||||
action == IIPPacketAction.ResourceParents ||
|
||||
action == IIPPacketAction.ResourceHistory ||
|
||||
action == IIPPacketAction.LinkTemplates
|
||||
// Attribute
|
||||
|| action == IIPPacketAction.GetAllAttributes
|
||||
|| action == IIPPacketAction.GetAttributes)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
||
|
||||
action == IIPPacketAction.GetAllAttributes ||
|
||||
action == IIPPacketAction.GetAttributes) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
}
|
||||
else if (action == IIPPacketAction.InvokeFunctionArrayArguments
|
||||
|| action == IIPPacketAction.InvokeFunctionNamedArguments)
|
||||
} else if (action == IIPPacketAction.InvokeFunctionArrayArguments ||
|
||||
action == IIPPacketAction.InvokeFunctionNamedArguments)
|
||||
//|| action == IIPPacketAction.GetProperty
|
||||
//|| action == IIPPacketAction.GetPropertyIfModified)
|
||||
{
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(dt);
|
||||
|
||||
if (size < 0)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
if (size < 0) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 5, cl + 5);
|
||||
offset += cl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_notEnough(offset, ends, size))
|
||||
return -_dataLengthNeeded;
|
||||
} else {
|
||||
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
}
|
||||
}
|
||||
else if (action == IIPPacketAction.SetProperty
|
||||
|| action == IIPPacketAction.Listen
|
||||
|| action == IIPPacketAction.Unlisten)
|
||||
{
|
||||
} else if (action == IIPPacketAction.SetProperty ||
|
||||
action == IIPPacketAction.Listen ||
|
||||
action == IIPPacketAction.Unlisten) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
else if (command == IIPPacketCommand.Report)
|
||||
{
|
||||
if (report == IIPPacketReport.ManagementError)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (command == IIPPacketCommand.Report) {
|
||||
if (report == IIPPacketReport.ManagementError) {
|
||||
if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded;
|
||||
|
||||
errorCode = data.getUint16(offset);
|
||||
offset += 2;
|
||||
}
|
||||
else if (report == IIPPacketReport.ExecutionError)
|
||||
{
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (report == IIPPacketReport.ExecutionError) {
|
||||
if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded;
|
||||
|
||||
errorCode = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, 2))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint16(offset);
|
||||
offset += 2;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
errorMessage = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
}
|
||||
else if (report == IIPPacketReport.ProgressReport)
|
||||
{
|
||||
if (_notEnough(offset, ends, 8))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (report == IIPPacketReport.ProgressReport) {
|
||||
if (_notEnough(offset, ends, 8)) return -_dataLengthNeeded;
|
||||
|
||||
progressValue = data.getInt32(offset);
|
||||
offset += 4;
|
||||
progressMax = data.getInt32(offset);
|
||||
offset += 4;
|
||||
}
|
||||
else if (report == IIPPacketReport.ChunkStream)
|
||||
{
|
||||
if (_notEnough(offset, ends, 1))
|
||||
return -_dataLengthNeeded;
|
||||
} else if (report == IIPPacketReport.ChunkStream) {
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(dt);
|
||||
|
||||
if (size < 0)
|
||||
{
|
||||
if (_notEnough(offset, ends, 4))
|
||||
return -_dataLengthNeeded;
|
||||
if (size < 0) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl))
|
||||
return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 5, cl + 5);
|
||||
offset += cl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_notEnough(offset, ends, size))
|
||||
return -_dataLengthNeeded;
|
||||
} else {
|
||||
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
@ -713,34 +546,21 @@ class IIPPacket
|
||||
return offset - _originalOffset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
toString()
|
||||
{
|
||||
toString() {
|
||||
var rt = command.toString();
|
||||
|
||||
if (command == IIPPacketCommand.Event)
|
||||
{
|
||||
if (command == IIPPacketCommand.Event) {
|
||||
rt += " " + event.toString();
|
||||
}
|
||||
else if (command == IIPPacketCommand.Request)
|
||||
{
|
||||
} else if (command == IIPPacketCommand.Request) {
|
||||
rt += " " + action.toString();
|
||||
if (action == IIPPacketAction.AttachResource)
|
||||
{
|
||||
rt += " CID: " + callbackId.toString() + " RID: " + resourceId.toString();
|
||||
if (action == IIPPacketAction.AttachResource) {
|
||||
rt +=
|
||||
" CID: " + callbackId.toString() + " RID: " + resourceId.toString();
|
||||
}
|
||||
}
|
||||
else if (command == IIPPacketCommand.Reply)
|
||||
} else if (command == IIPPacketCommand.Reply)
|
||||
rt += " " + action.toString();
|
||||
else if (command == IIPPacketCommand.Report)
|
||||
rt += " " + report.toString();
|
||||
else if (command == IIPPacketCommand.Report) rt += " " + report.toString();
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,21 +2,16 @@ import '../Data/BinaryList.dart';
|
||||
import '../Core/AsyncReply.dart';
|
||||
import 'NetworkConnection.dart';
|
||||
|
||||
class SendList extends BinaryList
|
||||
{
|
||||
class SendList extends BinaryList {
|
||||
NetworkConnection connection;
|
||||
AsyncReply<List<dynamic>> reply;
|
||||
AsyncReply<List<dynamic>>? reply;
|
||||
|
||||
SendList(NetworkConnection connection, AsyncReply<List<dynamic>> reply)
|
||||
{
|
||||
this.reply = reply;
|
||||
this.connection = connection;
|
||||
}
|
||||
SendList(this.connection, this.reply) {}
|
||||
|
||||
@override
|
||||
AsyncReply<List<dynamic>> done()
|
||||
{
|
||||
AsyncReply<List<dynamic>> done() {
|
||||
connection.send(super.toDC());
|
||||
return reply;
|
||||
|
||||
return reply ?? AsyncReply.ready([]);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ abstract class ISocket extends IDestructible {
|
||||
|
||||
//void send(DC message);
|
||||
|
||||
INetworkReceiver<ISocket> receiver;
|
||||
INetworkReceiver<ISocket>? receiver;
|
||||
|
||||
void send(DC message, [int offset, int size]);
|
||||
void close();
|
||||
@ -45,6 +45,6 @@ abstract class ISocket extends IDestructible {
|
||||
bool begin();
|
||||
|
||||
AsyncReply<ISocket> accept();
|
||||
IPEndPoint remoteEndPoint;
|
||||
IPEndPoint localEndPoint;
|
||||
IPEndPoint? remoteEndPoint;
|
||||
IPEndPoint? localEndPoint;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import 'IPEndPoint.dart';
|
||||
import '../../Core/AsyncReply.dart';
|
||||
|
||||
class TCPSocket extends ISocket {
|
||||
Socket sock;
|
||||
Socket? sock;
|
||||
NetworkBuffer receiveNetworkBuffer = new NetworkBuffer();
|
||||
|
||||
//bool asyncSending;
|
||||
@ -61,15 +61,18 @@ class TCPSocket extends ISocket {
|
||||
}
|
||||
*/
|
||||
|
||||
IPEndPoint _localEP, _remoteEP;
|
||||
IPEndPoint? _localEP, _remoteEP;
|
||||
|
||||
bool begin() {
|
||||
if (began) return false;
|
||||
|
||||
began = true;
|
||||
|
||||
_localEP = IPEndPoint(sock.address.rawAddress, sock.port);
|
||||
_remoteEP = IPEndPoint(sock.remoteAddress.rawAddress, sock.remotePort);
|
||||
if (sock != null) {
|
||||
var s = sock as Socket;
|
||||
_localEP = IPEndPoint(s.address.rawAddress, s.port);
|
||||
_remoteEP = IPEndPoint(s.remoteAddress.rawAddress, s.remotePort);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -82,7 +85,7 @@ class TCPSocket extends ISocket {
|
||||
|
||||
var dc = new DC.fromList(data);
|
||||
receiveNetworkBuffer.write(dc, 0, dc.length);
|
||||
receiver.networkReceive(this, receiveNetworkBuffer);
|
||||
receiver?.networkReceive(this, receiveNetworkBuffer);
|
||||
|
||||
//emitArgs("receive", [receiveNetworkBuffer]);
|
||||
|
||||
@ -101,7 +104,7 @@ class TCPSocket extends ISocket {
|
||||
|
||||
void doneHandler() {
|
||||
close();
|
||||
sock.destroy();
|
||||
sock?.destroy();
|
||||
}
|
||||
|
||||
AsyncReply<bool> connect(String hostname, int port) {
|
||||
@ -134,13 +137,13 @@ class TCPSocket extends ISocket {
|
||||
return rt;
|
||||
}
|
||||
|
||||
IPEndPoint get localEndPoint => _localEP;
|
||||
IPEndPoint get remoteEndPoint => _remoteEP;
|
||||
IPEndPoint? get localEndPoint => _localEP;
|
||||
IPEndPoint? get remoteEndPoint => _remoteEP;
|
||||
|
||||
SocketState get state => _state;
|
||||
|
||||
TCPSocket.fromSocket(Socket socket) {
|
||||
sock = socket;
|
||||
TCPSocket.fromSocket(this.sock) {
|
||||
//sock = socket;
|
||||
//if (socket.)
|
||||
// _state = SocketState.Established;
|
||||
}
|
||||
@ -160,8 +163,16 @@ class TCPSocket extends ISocket {
|
||||
//emitArgs("close", []);
|
||||
}
|
||||
|
||||
void send(DC message, [int offset, int size]) {
|
||||
if (state == SocketState.Established) sock.add(message.toList());
|
||||
void send(DC message, [int? offset, int? size]) {
|
||||
if (state == SocketState.Established) {
|
||||
if (offset != null && size == null) {
|
||||
sock?.add(message.clip(offset, message.length - offset).toList());
|
||||
} else if (offset != null && size != null) {
|
||||
sock?.add(message.clip(offset, size).toList());
|
||||
} else {
|
||||
sock?.add(message.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
|
@ -21,7 +21,7 @@ class TemplateGenerator {
|
||||
rt.writeln("class ${className} extends IRecord {");
|
||||
|
||||
template.properties.forEach((p) {
|
||||
var ptTypeName = getTypeName(template, p.valueType, templates);
|
||||
var ptTypeName = getTypeName(template, p.valueType, templates, false);
|
||||
rt.writeln("${ptTypeName}? ${p.name};");
|
||||
rt.writeln();
|
||||
});
|
||||
@ -53,8 +53,8 @@ class TemplateGenerator {
|
||||
var descProps = template.properties.map((p) {
|
||||
var isArray = p.valueType.type & 0x80 == 0x80;
|
||||
var ptType = p.valueType.type & 0x7F;
|
||||
var ptTypeName = getTypeName(
|
||||
template, TemplateDataType(ptType, p.valueType.typeGuid), templates);
|
||||
var ptTypeName = getTypeName(template,
|
||||
TemplateDataType(ptType, p.valueType.typeGuid), templates, false);
|
||||
// return "Prop(\"${p.name}\", ${ptTypeName}, ${isArray})";
|
||||
return "Prop('${p.name}', ${ptTypeName}, ${isArray}, ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
|
||||
}).join(', ');
|
||||
@ -67,17 +67,20 @@ class TemplateGenerator {
|
||||
return rt.toString();
|
||||
}
|
||||
|
||||
static String _translateClassName(String className) {
|
||||
static String _translateClassName(String className, bool nullable) {
|
||||
var cls = className.split('.');
|
||||
var nameSpace = cls.take(cls.length - 1).join('_').toLowerCase();
|
||||
return "$nameSpace.${cls.last}";
|
||||
return "$nameSpace.${cls.last}${nullable ? '?' : ''}";
|
||||
}
|
||||
|
||||
static String getTypeName(TypeTemplate forTemplate,
|
||||
TemplateDataType templateDataType, List<TypeTemplate> templates) {
|
||||
static String getTypeName(
|
||||
TypeTemplate forTemplate,
|
||||
TemplateDataType templateDataType,
|
||||
List<TypeTemplate> templates,
|
||||
bool nullable) {
|
||||
if (templateDataType.type == DataType.Resource) {
|
||||
if (templateDataType.typeGuid == forTemplate.classId)
|
||||
return forTemplate.className.split('.').last;
|
||||
return forTemplate.className.split('.').last + (nullable ? "?" : "");
|
||||
else {
|
||||
var tmp = templates.firstWhere((x) =>
|
||||
x.classId == templateDataType.typeGuid &&
|
||||
@ -86,11 +89,11 @@ class TemplateGenerator {
|
||||
|
||||
if (tmp == null) return "dynamic"; // something went wrong
|
||||
|
||||
return _translateClassName(tmp.className);
|
||||
return _translateClassName(tmp.className, nullable);
|
||||
}
|
||||
} else if (templateDataType.type == DataType.ResourceArray) {
|
||||
if (templateDataType.typeGuid == forTemplate.classId)
|
||||
return "List<${forTemplate.className.split('.').last}>";
|
||||
return "List<${forTemplate.className.split('.').last + (nullable ? '?' : '')}>";
|
||||
else {
|
||||
var tmp = templates.firstWhere((x) =>
|
||||
x.classId == templateDataType.typeGuid &&
|
||||
@ -99,27 +102,27 @@ class TemplateGenerator {
|
||||
|
||||
if (tmp == null) return "dynamic"; // something went wrong
|
||||
|
||||
return "List<${_translateClassName(tmp.className)}>";
|
||||
return "List<${_translateClassName(tmp.className, nullable)}>";
|
||||
}
|
||||
} else if (templateDataType.type == DataType.Record) {
|
||||
if (templateDataType.typeGuid == forTemplate.classId)
|
||||
return forTemplate.className.split('.').last;
|
||||
return forTemplate.className.split('.').last + (nullable ? '?' : '');
|
||||
else {
|
||||
var tmp = templates.firstWhere((x) =>
|
||||
x.classId == templateDataType.typeGuid &&
|
||||
x.type == TemplateType.Record);
|
||||
if (tmp == null) return "dynamic"; // something went wrong
|
||||
return _translateClassName(tmp.className);
|
||||
return _translateClassName(tmp.className, nullable);
|
||||
}
|
||||
} else if (templateDataType.type == DataType.RecordArray) {
|
||||
if (templateDataType.typeGuid == forTemplate.classId)
|
||||
return "List<${forTemplate.className.split('.').last}>";
|
||||
return "List<${forTemplate.className.split('.').last + (nullable ? '?' : '')}?>";
|
||||
else {
|
||||
var tmp = templates.firstWhere((x) =>
|
||||
x.classId == templateDataType.typeGuid &&
|
||||
x.type == TemplateType.Record);
|
||||
if (tmp == null) return "dynamic"; // something went wrong
|
||||
return "List<${_translateClassName(tmp.className)}>";
|
||||
return "List<${_translateClassName(tmp.className, nullable)}>";
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,13 +133,13 @@ class TemplateGenerator {
|
||||
case DataType.BoolArray:
|
||||
return "List<bool>";
|
||||
case DataType.Char:
|
||||
return "String";
|
||||
return "String" + (nullable ? "?" : "");
|
||||
case DataType.CharArray:
|
||||
return "List<String>";
|
||||
return "List<String${nullable ? '?' : ''}>";
|
||||
case DataType.DateTime:
|
||||
return "DateTime";
|
||||
case DataType.DateTimeArray:
|
||||
return "List<DateTime>";
|
||||
return "List<DateTime${nullable ? '?' : ''}>";
|
||||
case DataType.Decimal:
|
||||
return "double";
|
||||
case DataType.DecimalArray:
|
||||
@ -168,11 +171,11 @@ class TemplateGenerator {
|
||||
case DataType.String:
|
||||
return "String";
|
||||
case DataType.StringArray:
|
||||
return "List<String>";
|
||||
return "List<String${nullable ? '?' : ''}>";
|
||||
case DataType.Structure:
|
||||
return "Structure";
|
||||
return "Structure" + (nullable ? "?" : "");
|
||||
case DataType.StructureArray:
|
||||
return "List<Structure>";
|
||||
return "List<Structure${(nullable ? '?' : '')}>";
|
||||
case DataType.UInt16:
|
||||
return "int";
|
||||
case DataType.UInt16Array:
|
||||
@ -206,24 +209,24 @@ class TemplateGenerator {
|
||||
}
|
||||
|
||||
static Future<String> getTemplate(String url,
|
||||
[String dir = null,
|
||||
String username = null,
|
||||
String password = null]) async {
|
||||
[String? dir = null,
|
||||
String? username = null,
|
||||
String? password = null]) async {
|
||||
try {
|
||||
if (!_urlRegex.hasMatch(url)) throw Exception("Invalid IIP URL");
|
||||
|
||||
var path = _urlRegex.allMatches(url).first;
|
||||
var con = await Warehouse.get<DistributedConnection>(
|
||||
path[1] + "://" + path[2],
|
||||
(path[1] as String) + "://" + (path[2] as String),
|
||||
!isNullOrEmpty(username) && !isNullOrEmpty(password)
|
||||
? {username: username, password: password}
|
||||
: null);
|
||||
|
||||
if (con == null) throw Exception("Can't connect to server");
|
||||
|
||||
if (isNullOrEmpty(dir)) dir = path[2].replaceAll(":", "_");
|
||||
if (isNullOrEmpty(dir)) dir = (path[2] as String).replaceAll(":", "_");
|
||||
|
||||
var templates = await con.getLinkTemplates(path[3]);
|
||||
var templates = await con.getLinkTemplates(path[3] as String);
|
||||
|
||||
// no longer needed
|
||||
Warehouse.remove(con);
|
||||
@ -234,7 +237,7 @@ class TemplateGenerator {
|
||||
|
||||
//Map<String, String> namesMap = Map<String, String>();
|
||||
|
||||
var makeImports = (TypeTemplate skipTemplate) {
|
||||
var makeImports = (TypeTemplate? skipTemplate) {
|
||||
var imports = StringBuffer();
|
||||
imports.writeln("import 'dart:async';");
|
||||
imports.writeln("import 'package:esiur/esiur.dart';");
|
||||
@ -270,12 +273,12 @@ class TemplateGenerator {
|
||||
|
||||
var defineCreators = templates.map((tmp) {
|
||||
// creator
|
||||
var className = _translateClassName(tmp.className);
|
||||
return "Warehouse.defineCreator(${className}, () => ${className}(), () => <${className}>[]);";
|
||||
var className = _translateClassName(tmp.className, false);
|
||||
return "Warehouse.defineCreator(${className}, () => ${className}(), () => <${className}?>[]);";
|
||||
}).join("\r\n");
|
||||
|
||||
var putTemplates = templates.map((tmp) {
|
||||
var className = _translateClassName(tmp.className);
|
||||
var className = _translateClassName(tmp.className, false);
|
||||
return "Warehouse.putTemplate(TypeTemplate.fromType(${className}));";
|
||||
}).join("\r\n");
|
||||
|
||||
@ -291,7 +294,7 @@ class TemplateGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
static String _escape(String str) {
|
||||
static String _escape(String? str) {
|
||||
if (str == null)
|
||||
return "null";
|
||||
else
|
||||
@ -316,10 +319,11 @@ class TemplateGenerator {
|
||||
rt.writeln("}");
|
||||
|
||||
template.functions.forEach((f) {
|
||||
var rtTypeName = getTypeName(template, f.returnType, templates);
|
||||
var rtTypeName = getTypeName(template, f.returnType, templates, true);
|
||||
rt.write("AsyncReply<$rtTypeName> ${f.name}(");
|
||||
rt.write(f.arguments
|
||||
.map((x) => getTypeName(template, x.type, templates) + " " + x.name)
|
||||
.map((x) =>
|
||||
getTypeName(template, x.type, templates, true) + " " + x.name)
|
||||
.join(","));
|
||||
|
||||
rt.writeln(") {");
|
||||
@ -333,14 +337,14 @@ class TemplateGenerator {
|
||||
});
|
||||
|
||||
template.properties.forEach((p) {
|
||||
var ptTypeName = getTypeName(template, p.valueType, templates);
|
||||
var ptTypeName = getTypeName(template, p.valueType, templates, true);
|
||||
rt.writeln("${ptTypeName} get ${p.name} { return get(${p.index}); }");
|
||||
rt.writeln(
|
||||
"set ${p.name}(${ptTypeName} value) { set(${p.index}, value); }");
|
||||
});
|
||||
|
||||
template.events.forEach((e) {
|
||||
var etTypeName = getTypeName(template, e.argumentType, templates);
|
||||
var etTypeName = getTypeName(template, e.argumentType, templates, true);
|
||||
|
||||
rt.writeln(
|
||||
"final _${e.name}Controller = StreamController<$etTypeName>();");
|
||||
@ -353,22 +357,22 @@ class TemplateGenerator {
|
||||
var descProps = template.properties.map((p) {
|
||||
var isArray = p.valueType.type & 0x80 == 0x80;
|
||||
var ptType = p.valueType.type & 0x7F;
|
||||
var ptTypeName = getTypeName(
|
||||
template, TemplateDataType(ptType, p.valueType.typeGuid), templates);
|
||||
var ptTypeName = getTypeName(template,
|
||||
TemplateDataType(ptType, p.valueType.typeGuid), templates, false);
|
||||
return "Prop('${p.name}', ${ptTypeName}, ${isArray}, ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
|
||||
}).join(', ');
|
||||
|
||||
var descFuncs = template.functions.map((f) {
|
||||
var isArray = f.returnType.type & 0x80 == 0x80;
|
||||
var ftType = f.returnType.type & 0x7F;
|
||||
var ftTypeName = getTypeName(
|
||||
template, TemplateDataType(ftType, f.returnType.typeGuid), templates);
|
||||
var ftTypeName = getTypeName(template,
|
||||
TemplateDataType(ftType, f.returnType.typeGuid), templates, false);
|
||||
|
||||
var args = f.arguments.map((a) {
|
||||
var isArray = a.type.type & 0x80 == 0x80;
|
||||
var atType = a.type.type & 0x7F;
|
||||
var atTypeName = getTypeName(
|
||||
template, TemplateDataType(atType, a.type.typeGuid), templates);
|
||||
var atTypeName = getTypeName(template,
|
||||
TemplateDataType(atType, a.type.typeGuid), templates, false);
|
||||
return "Arg('${a.name}', ${atTypeName}, ${isArray})";
|
||||
}).join(', ');
|
||||
|
||||
@ -379,7 +383,7 @@ class TemplateGenerator {
|
||||
var isArray = e.argumentType.type & 0x80 == 0x80;
|
||||
var etType = e.argumentType.type & 0x7F;
|
||||
var etTypeName = getTypeName(template,
|
||||
TemplateDataType(etType, e.argumentType.typeGuid), templates);
|
||||
TemplateDataType(etType, e.argumentType.typeGuid), templates, false);
|
||||
return "Evt('${e.name}', ${etTypeName}, ${isArray}, ${e.listenable}, ${_escape(e.expansion)})";
|
||||
}).join(', ');
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
class FactoryEntry {
|
||||
final Type type;
|
||||
final Function() instanceCreator;
|
||||
final Function() arrayCreator;
|
||||
final Function instanceCreator;
|
||||
final Function arrayCreator;
|
||||
|
||||
FactoryEntry(this.type, this.instanceCreator, this.arrayCreator);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import 'Instance.dart';
|
||||
abstract class IResource extends IDestructible {
|
||||
AsyncReply<bool> trigger(ResourceTrigger trigger);
|
||||
|
||||
Instance instance;
|
||||
Instance? instance;
|
||||
|
||||
invoke(String name, List arguments);
|
||||
setProperty(String name, value);
|
||||
|
@ -31,15 +31,17 @@ import '../Data/PropertyValue.dart';
|
||||
// old
|
||||
// abstract class IStore extends IResource
|
||||
// new
|
||||
abstract class IStore implements IResource
|
||||
{
|
||||
AsyncReply<IResource> get(String path);
|
||||
AsyncReply<IResource> retrieve(int iid);
|
||||
abstract class IStore implements IResource {
|
||||
AsyncReply<IResource?> get(String path);
|
||||
AsyncReply<IResource?> retrieve(int iid);
|
||||
AsyncReply<bool> put(IResource resource);
|
||||
String link(IResource resource);
|
||||
bool record(IResource resource, String propertyName, dynamic value, int age, DateTime dateTime);
|
||||
bool modify(IResource resource, String propertyName, dynamic value, int age, DateTime dateTime);
|
||||
String? link(IResource resource);
|
||||
bool record(IResource resource, String propertyName, dynamic value, int age,
|
||||
DateTime dateTime);
|
||||
bool modify(IResource resource, String propertyName, dynamic value, int age,
|
||||
DateTime dateTime);
|
||||
bool remove(IResource resource);
|
||||
|
||||
AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>> getRecord(IResource resource, DateTime fromDate, DateTime toDate);
|
||||
AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>?> getRecord(
|
||||
IResource resource, DateTime fromDate, DateTime toDate);
|
||||
}
|
||||
|
@ -21,73 +21,61 @@ import './Template/MemberTemplate.dart';
|
||||
import '../Data/PropertyValue.dart';
|
||||
import 'Warehouse.dart';
|
||||
|
||||
class Instance extends IEventHandler
|
||||
{
|
||||
class Instance extends IEventHandler {
|
||||
String _name;
|
||||
|
||||
AutoList<IResource, Instance> _children;
|
||||
late AutoList<IResource, Instance> _children;
|
||||
IResource _resource;
|
||||
IStore _store;
|
||||
AutoList<IResource, Instance> _parents;
|
||||
IStore? _store;
|
||||
late AutoList<IResource, Instance> _parents;
|
||||
//bool inherit;
|
||||
TypeTemplate _template;
|
||||
late TypeTemplate _template;
|
||||
|
||||
AutoList<IPermissionsManager, Instance> _managers;
|
||||
late AutoList<IPermissionsManager, Instance> _managers;
|
||||
|
||||
late KeyList<String, dynamic> _attributes;
|
||||
|
||||
KeyList<String, dynamic> _attributes;
|
||||
|
||||
List<int> _ages = new List<int>();
|
||||
List<DateTime> _modificationDates = new List<DateTime>();
|
||||
List<int> _ages = <int>[];
|
||||
List<DateTime> _modificationDates = <DateTime>[];
|
||||
int _instanceAge;
|
||||
DateTime _instanceModificationDate;
|
||||
DateTime? _instanceModificationDate;
|
||||
|
||||
int _id;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Instance attributes are custom properties associated with the instance, a place to store information by IStore.
|
||||
/// </summary>
|
||||
KeyList<String, dynamic> get attributes => _attributes;
|
||||
|
||||
@override
|
||||
String toString() => _name + " (" + link + ")";
|
||||
String toString() => _name + " (" + (link ?? '') + ")";
|
||||
|
||||
|
||||
bool removeAttributes([List<String> attributes = null])
|
||||
{
|
||||
bool removeAttributes([List<String>? attributes = null]) {
|
||||
if (attributes == null)
|
||||
this._attributes.clear();
|
||||
else
|
||||
{
|
||||
for (var attr in attributes)
|
||||
this.attributes.remove(attr);
|
||||
else {
|
||||
for (var attr in attributes) this.attributes.remove(attr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Structure getAttributes([List<String> attributes = null])
|
||||
{
|
||||
Structure getAttributes([List<String>? attributes = null]) {
|
||||
var st = new Structure();
|
||||
|
||||
if (attributes == null)
|
||||
{
|
||||
if (attributes == null) {
|
||||
var clone = this.attributes.keys.toList();
|
||||
clone.add("managers");
|
||||
attributes = clone.toList();
|
||||
}
|
||||
|
||||
for(var attr in attributes)
|
||||
{
|
||||
for (var attr in attributes) {
|
||||
if (attr == "name")
|
||||
st["name"] = _name;
|
||||
else if (attr == "managers")
|
||||
{
|
||||
var mngrs = new List<Structure>();
|
||||
else if (attr == "managers") {
|
||||
var mngrs = <Structure>[];
|
||||
|
||||
for (var i = 0; i < _managers.length; i++)
|
||||
{
|
||||
for (var i = 0; i < _managers.length; i++) {
|
||||
var mst = new Structure();
|
||||
mst["type"] = _managers[i].runtimeType;
|
||||
mst["settings"] = _managers[i].settings;
|
||||
@ -96,43 +84,29 @@ class Instance extends IEventHandler
|
||||
}
|
||||
|
||||
st["managers"] = mngrs;
|
||||
}
|
||||
else if (attr == "parents")
|
||||
{
|
||||
} else if (attr == "parents") {
|
||||
st["parents"] = _parents.toList();
|
||||
}
|
||||
else if (attr == "children")
|
||||
{
|
||||
} else if (attr == "children") {
|
||||
st["children"] = _children.toList();
|
||||
}
|
||||
else if (attr == "childrenCount")
|
||||
{
|
||||
} else if (attr == "childrenCount") {
|
||||
st["childrenCount"] = _children.count;
|
||||
}
|
||||
else if (attr == "type")
|
||||
{
|
||||
} else if (attr == "type") {
|
||||
st["type"] = resource.runtimeType;
|
||||
}
|
||||
else
|
||||
} else
|
||||
st[attr] = _attributes[attr];
|
||||
}
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
bool setAttributes(Structure attributes, [bool clearAttributes = false])
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (clearAttributes)
|
||||
_attributes.clear();
|
||||
bool setAttributes(Structure attributes, [bool clearAttributes = false]) {
|
||||
try {
|
||||
if (clearAttributes) _attributes.clear();
|
||||
|
||||
for (var attrKey in attributes.keys)
|
||||
if (attrKey == "name")
|
||||
_name = attributes[attrKey];
|
||||
else if (attrKey == "managers")
|
||||
{
|
||||
_name = attributes[attrKey] as String;
|
||||
else if (attrKey == "managers") {
|
||||
_managers.clear();
|
||||
|
||||
var mngrs = attributes[attrKey] as List;
|
||||
@ -153,15 +127,10 @@ class Instance extends IEventHandler
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_attributes[attrKey] = attributes[attrKey];
|
||||
}
|
||||
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
} catch (ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -197,8 +166,7 @@ class Instance extends IEventHandler
|
||||
/// </summary>
|
||||
/// <param name="index">Zero-based property index.</param>
|
||||
/// <returns>Age.</returns>
|
||||
int getAge(int index)
|
||||
{
|
||||
int getAge(int index) {
|
||||
if (index < _ages.length)
|
||||
return _ages[index];
|
||||
else
|
||||
@ -210,13 +178,10 @@ class Instance extends IEventHandler
|
||||
/// </summary>
|
||||
/// <param name="index">Zero-based property index.</param>
|
||||
/// <param name="value">Age.</param>
|
||||
void setAge(int index, int value)
|
||||
{
|
||||
if (index < _ages.length)
|
||||
{
|
||||
void setAge(int index, int value) {
|
||||
if (index < _ages.length) {
|
||||
_ages[index] = value;
|
||||
if (value > _instanceAge)
|
||||
_instanceAge = value;
|
||||
if (value > _instanceAge) _instanceAge = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,12 +190,12 @@ class Instance extends IEventHandler
|
||||
/// </summary>
|
||||
/// <param name="index">Zero-based property index.</param>
|
||||
/// <param name="value">Modification date.</param>
|
||||
void setModificationDate(int index, DateTime value)
|
||||
{
|
||||
if (index < _modificationDates.length)
|
||||
{
|
||||
void setModificationDate(int index, DateTime value) {
|
||||
if (index < _modificationDates.length) {
|
||||
_modificationDates[index] = value;
|
||||
if (_instanceModificationDate == null || value.millisecondsSinceEpoch > _instanceModificationDate.millisecondsSinceEpoch)
|
||||
if (_instanceModificationDate == null ||
|
||||
value.millisecondsSinceEpoch >
|
||||
(_instanceModificationDate as DateTime).millisecondsSinceEpoch)
|
||||
_instanceModificationDate = value;
|
||||
}
|
||||
}
|
||||
@ -240,15 +205,13 @@ class Instance extends IEventHandler
|
||||
/// </summary>
|
||||
/// <param name="index">Zero-based property index</param>
|
||||
/// <returns>Modification date.</returns>
|
||||
DateTime getModificationDate(int index)
|
||||
{
|
||||
DateTime getModificationDate(int index) {
|
||||
if (index < _modificationDates.length)
|
||||
return _modificationDates[index];
|
||||
else
|
||||
return new DateTime(0);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Load property value (used by stores)
|
||||
/// </summary>
|
||||
@ -256,8 +219,8 @@ class Instance extends IEventHandler
|
||||
/// <param name="age">Property age</param>
|
||||
/// <param name="value">Property value</param>
|
||||
/// <returns></returns>
|
||||
bool loadProperty(String name, int age, DateTime modificationDate, dynamic value)
|
||||
{
|
||||
bool loadProperty(
|
||||
String name, int age, DateTime modificationDate, dynamic value) {
|
||||
/*
|
||||
var pt = _template.getPropertyTemplate(name);
|
||||
|
||||
@ -282,7 +245,6 @@ class Instance extends IEventHandler
|
||||
|
||||
*/
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -295,7 +257,7 @@ class Instance extends IEventHandler
|
||||
/// <summary>
|
||||
/// Last modification date.
|
||||
/// </summary>
|
||||
DateTime get modificationDate => _instanceModificationDate;
|
||||
DateTime? get modificationDate => _instanceModificationDate;
|
||||
|
||||
/// <summary>
|
||||
/// Instance Id.
|
||||
@ -307,13 +269,10 @@ class Instance extends IEventHandler
|
||||
/// </summary>
|
||||
/// <param name="properties"></param>
|
||||
/// <returns></returns>
|
||||
bool deserialize(List<PropertyValue> properties)
|
||||
{
|
||||
for (var i = 0; i < properties.length; i++)
|
||||
{
|
||||
bool deserialize(List<PropertyValue> properties) {
|
||||
for (var i = 0; i < properties.length; i++) {
|
||||
var pt = _template.getPropertyTemplateByIndex(i);
|
||||
if (pt != null)
|
||||
{
|
||||
if (pt != null) {
|
||||
var pv = properties[i];
|
||||
loadProperty(pt.name, pv.age, pv.date, pv.value);
|
||||
}
|
||||
@ -326,12 +285,10 @@ class Instance extends IEventHandler
|
||||
/// Export all properties with ResourceProperty attributed as bytes array.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<PropertyValue> serialize()
|
||||
{
|
||||
List<PropertyValue> props = new List<PropertyValue>();
|
||||
List<PropertyValue> serialize() {
|
||||
List<PropertyValue> props = <PropertyValue>[];
|
||||
|
||||
for (var pt in _template.properties)
|
||||
{
|
||||
for (var pt in _template.properties) {
|
||||
// var rt = pt.info.getValue(resource, null);
|
||||
// props.add(new PropertyValue(rt, _ages[pt.index], _modificationDates[pt.index]));
|
||||
}
|
||||
@ -409,27 +366,21 @@ class Instance extends IEventHandler
|
||||
/// If True, the instance can be stored to disk.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool isStorable()
|
||||
{
|
||||
bool isStorable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void emitModification(PropertyTemplate pt, dynamic value)
|
||||
{
|
||||
void emitModification(PropertyTemplate pt, dynamic value) {
|
||||
_instanceAge++;
|
||||
var now = DateTime.now().toUtc();
|
||||
|
||||
_ages[pt.index] = _instanceAge;
|
||||
_modificationDates[pt.index] = now;
|
||||
|
||||
if (pt.storage == StorageMode.NonVolatile)
|
||||
{
|
||||
_store.modify(_resource, pt.name, value, _ages[pt.index], now);
|
||||
}
|
||||
else if (pt.storage == StorageMode.Recordable)
|
||||
{
|
||||
_store.record(_resource, pt.name, value, _ages[pt.index], now);
|
||||
if (pt.storage == StorageMode.NonVolatile) {
|
||||
_store?.modify(_resource, pt.name, value, _ages[pt.index], now);
|
||||
} else if (pt.storage == StorageMode.Recordable) {
|
||||
_store?.record(_resource, pt.name, value, _ages[pt.index], now);
|
||||
}
|
||||
|
||||
emitArgs("resourceModified", [_resource, pt.name, value]);
|
||||
@ -443,19 +394,18 @@ class Instance extends IEventHandler
|
||||
/// <param name="propertyName"></param>
|
||||
/// <param name="newValue"></param>
|
||||
/// <param name="oldValue"></param>
|
||||
modified(String propertyName)
|
||||
{
|
||||
modified(String propertyName) {
|
||||
var valueObject = new ValueObject();
|
||||
if (getPropertyValue(propertyName, valueObject))
|
||||
{
|
||||
if (getPropertyValue(propertyName, valueObject)) {
|
||||
var pt = _template.getPropertyTemplateByName(propertyName);
|
||||
emitModification(pt, valueObject.value);
|
||||
if (pt != null) emitModification(pt, valueObject.value);
|
||||
}
|
||||
}
|
||||
|
||||
emitResourceEvent(issuer, List<Session> receivers, String name, dynamic args)
|
||||
{
|
||||
emitArgs("resourceEventOccurred", [_resource, issuer, receivers, name, args]);
|
||||
emitResourceEvent(
|
||||
issuer, List<Session>? receivers, String name, dynamic args) {
|
||||
emitArgs(
|
||||
"resourceEventOccurred", [_resource, issuer, receivers, name, args]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -464,8 +414,7 @@ class Instance extends IEventHandler
|
||||
/// <param name="name">Property name</param>
|
||||
/// <param name="value">Output value</param>
|
||||
/// <returns>True, if the resource has the property.</returns>
|
||||
bool getPropertyValue(String name, ValueObject valueObject)
|
||||
{
|
||||
bool getPropertyValue(String name, ValueObject valueObject) {
|
||||
var pt = _template.getPropertyTemplateByName(name);
|
||||
|
||||
/*
|
||||
@ -480,7 +429,6 @@ class Instance extends IEventHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public bool Inherit
|
||||
{
|
||||
@ -492,11 +440,10 @@ class Instance extends IEventHandler
|
||||
/// </summary>
|
||||
AutoList<IResource, Instance> get parents => _parents;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Store responsible for creating and keeping the resource.
|
||||
/// </summary>
|
||||
IStore get store => _store;
|
||||
IStore? get store => _store;
|
||||
|
||||
/// <summary>
|
||||
/// List of children.
|
||||
@ -506,29 +453,27 @@ class Instance extends IEventHandler
|
||||
/// <summary>
|
||||
/// The unique and permanent link to the resource.
|
||||
/// </summary>
|
||||
String get link
|
||||
{
|
||||
String? get link {
|
||||
if (_store != null)
|
||||
return _store.link(_resource);
|
||||
else
|
||||
{
|
||||
var l = new List<String>();
|
||||
return _store?.link(_resource);
|
||||
else {
|
||||
var l = <String>[];
|
||||
|
||||
var p = _resource;
|
||||
|
||||
while (true)
|
||||
{
|
||||
l.insert(0, p.instance.name);
|
||||
while (true) {
|
||||
if (p.instance != null) break;
|
||||
var pi = p.instance as Instance;
|
||||
|
||||
if (p.instance.parents.count == 0)
|
||||
break;
|
||||
l.insert(0, pi.name);
|
||||
|
||||
p = p.instance.parents.first();
|
||||
if (pi.parents.count == 0) break;
|
||||
|
||||
p = pi.parents.first;
|
||||
}
|
||||
|
||||
return l.join("/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -537,13 +482,11 @@ class Instance extends IEventHandler
|
||||
String get name => _name;
|
||||
set name(value) => name = value;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource managed by this instance.
|
||||
/// </summary>
|
||||
IResource get resource => _resource;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource template describes the properties, functions and events of the resource.
|
||||
/// </summary>
|
||||
@ -557,18 +500,15 @@ class Instance extends IEventHandler
|
||||
/// <param name="member">Function, property or event to check for permission.</param>
|
||||
/// <param name="inquirer">Permission inquirer.</param>
|
||||
/// <returns>Ruling.</returns>
|
||||
Ruling applicable(Session session, ActionType action, MemberTemplate member, [dynamic inquirer = null])
|
||||
{
|
||||
|
||||
for(var i = 0; i < _managers.length; i++)
|
||||
{
|
||||
var r = _managers[i].applicable(this.resource, session, action, member, inquirer);
|
||||
if (r != Ruling.DontCare)
|
||||
return r;
|
||||
Ruling applicable(Session session, ActionType action, MemberTemplate? member,
|
||||
[dynamic inquirer = null]) {
|
||||
for (var i = 0; i < _managers.length; i++) {
|
||||
var r = _managers[i]
|
||||
.applicable(this.resource, session, action, member, inquirer);
|
||||
if (r != Ruling.DontCare) return r;
|
||||
}
|
||||
|
||||
return Ruling.DontCare;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -583,14 +523,8 @@ class Instance extends IEventHandler
|
||||
/// <param name="name">Name of the instance.</param>
|
||||
/// <param name="resource">Resource to manage.</param>
|
||||
/// <param name="store">Store responsible for the resource.</param>
|
||||
Instance(int id, String name, IResource resource, IStore store, [TypeTemplate customTemplate = null, int age = 0])
|
||||
{
|
||||
_store = store;
|
||||
_resource = resource;
|
||||
_id = id;
|
||||
_name = name;
|
||||
_instanceAge = age;
|
||||
|
||||
Instance(this._id, this._name, this._resource, this._store,
|
||||
[TypeTemplate? customTemplate = null, this._instanceAge = 0]) {
|
||||
_attributes = new KeyList<String, dynamic>(this);
|
||||
_children = new AutoList<IResource, Instance>(this);
|
||||
_parents = new AutoList<IResource, Instance>(this);
|
||||
@ -609,8 +543,7 @@ class Instance extends IEventHandler
|
||||
_template = Warehouse.getTemplateByType(resource.runtimeType);
|
||||
|
||||
// set ages
|
||||
for (int i = 0; i < _template.properties.length; i++)
|
||||
{
|
||||
for (int i = 0; i < _template.properties.length; i++) {
|
||||
_ages.add(0);
|
||||
_modificationDates.add(new DateTime(0)); //DateTime.MinValue);
|
||||
}
|
||||
@ -652,31 +585,31 @@ class Instance extends IEventHandler
|
||||
*/
|
||||
}
|
||||
|
||||
void children_OnRemoved(Instance parent, IResource value)
|
||||
{
|
||||
value.instance.parents.remove(_resource);
|
||||
void children_OnRemoved(Instance parent, IResource value) {
|
||||
value.instance?.parents.remove(_resource);
|
||||
}
|
||||
|
||||
void children_OnAdd(Instance parent, IResource value)
|
||||
{
|
||||
if (!value.instance.parents.contains(_resource))
|
||||
value.instance.parents.add(_resource);
|
||||
void children_OnAdd(Instance parent, IResource value) {
|
||||
if (value.instance != null) {
|
||||
var ins = value.instance as Instance;
|
||||
if (ins.parents.contains(_resource))
|
||||
value.instance?.parents.add(_resource);
|
||||
}
|
||||
}
|
||||
|
||||
void parents_OnRemoved(Instance parent, IResource value)
|
||||
{
|
||||
value.instance.children.remove(_resource);
|
||||
void parents_OnRemoved(Instance parent, IResource value) {
|
||||
value.instance?.children.remove(_resource);
|
||||
}
|
||||
|
||||
void parents_OnAdd(Instance parent, IResource value)
|
||||
{
|
||||
if (!value.instance.children.contains(_resource))
|
||||
value.instance.children.add(_resource);
|
||||
void parents_OnAdd(Instance parent, IResource value) {
|
||||
if (value.instance != null) {
|
||||
var ins = value.instance as Instance;
|
||||
if (!ins.children.contains(_resource))
|
||||
value.instance?.children.add(_resource);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void resource_OnDestroy(sender)
|
||||
{
|
||||
void resource_OnDestroy(sender) {
|
||||
emitArgs("resourceDestroyed", [sender]);
|
||||
}
|
||||
}
|
||||
|
@ -3,32 +3,30 @@ import '../../Data/BinaryList.dart';
|
||||
import "../../Data/ParseResult.dart";
|
||||
import './TemplateDataType.dart';
|
||||
|
||||
class ArgumentTemplate
|
||||
{
|
||||
class ArgumentTemplate {
|
||||
String name;
|
||||
|
||||
TemplateDataType type;
|
||||
|
||||
static ParseResult<ArgumentTemplate> parse(DC data, int offset)
|
||||
{
|
||||
static ParseResult<ArgumentTemplate> parse(DC data, int offset) {
|
||||
var cs = data[offset++];
|
||||
var name = data.getString(offset, cs);
|
||||
offset += cs;
|
||||
var tdr = TemplateDataType.parse(data, offset);
|
||||
|
||||
return ParseResult<ArgumentTemplate>(cs + 1 + tdr.size, ArgumentTemplate(name, tdr.value));
|
||||
return ParseResult<ArgumentTemplate>(
|
||||
cs + 1 + tdr.size, ArgumentTemplate(name, tdr.value));
|
||||
}
|
||||
|
||||
ArgumentTemplate(this.name, this.type);
|
||||
|
||||
DC compose()
|
||||
{
|
||||
DC compose() {
|
||||
var name = DC.stringToBytes(this.name);
|
||||
|
||||
return new BinaryList()
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(type.compose())
|
||||
return (BinaryList()
|
||||
..addUint8(name.length)
|
||||
..addDC(name)
|
||||
..addDC(type.compose()))
|
||||
.toDC();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import 'MemberType.dart';
|
||||
import 'TemplateDataType.dart';
|
||||
|
||||
class EventTemplate extends MemberTemplate {
|
||||
String expansion;
|
||||
String? expansion;
|
||||
bool listenable;
|
||||
TemplateDataType argumentType;
|
||||
|
||||
@ -14,21 +14,21 @@ class EventTemplate extends MemberTemplate {
|
||||
var name = super.compose();
|
||||
|
||||
if (expansion != null) {
|
||||
var exp = DC.stringToBytes(expansion);
|
||||
return new BinaryList()
|
||||
.addUint8(listenable ? 0x58 : 0x50)
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(argumentType.compose())
|
||||
.addInt32(exp.length)
|
||||
.addDC(exp)
|
||||
var exp = DC.stringToBytes(expansion as String);
|
||||
return (BinaryList()
|
||||
..addUint8(listenable ? 0x58 : 0x50)
|
||||
..addUint8(name.length)
|
||||
..addDC(name)
|
||||
..addDC(argumentType.compose())
|
||||
..addInt32(exp.length)
|
||||
..addDC(exp))
|
||||
.toDC();
|
||||
} else {
|
||||
return new BinaryList()
|
||||
.addUint8(listenable ? 0x48 : 0x40)
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(argumentType.compose())
|
||||
return (BinaryList()
|
||||
..addUint8(listenable ? 0x48 : 0x40)
|
||||
..addUint8(name.length)
|
||||
..addDC(name)
|
||||
..addDC(argumentType.compose()))
|
||||
.toDC();
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import 'ArgumentTemplate.dart';
|
||||
import 'TemplateDataType.dart';
|
||||
|
||||
class FunctionTemplate extends MemberTemplate {
|
||||
String expansion;
|
||||
bool isVoid;
|
||||
String? expansion;
|
||||
// bool isVoid;
|
||||
|
||||
TemplateDataType returnType;
|
||||
List<ArgumentTemplate> arguments;
|
||||
@ -18,10 +18,10 @@ class FunctionTemplate extends MemberTemplate {
|
||||
var name = super.compose();
|
||||
|
||||
var bl = new BinaryList()
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(returnType.compose())
|
||||
.addUint8(arguments.length);
|
||||
..addUint8(name.length)
|
||||
..addDC(name)
|
||||
..addDC(returnType.compose())
|
||||
..addUint8(arguments.length);
|
||||
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
bl.addDC(arguments[i].compose());
|
||||
@ -29,9 +29,9 @@ class FunctionTemplate extends MemberTemplate {
|
||||
|
||||
if (expansion != null)
|
||||
{
|
||||
var exp = DC.stringToBytes(expansion);
|
||||
bl.addInt32(exp.length)
|
||||
.addDC(exp);
|
||||
var exp = DC.stringToBytes(expansion as String);
|
||||
bl..addInt32(exp.length)
|
||||
..addDC(exp);
|
||||
bl.insertUint8(0, 0x10);
|
||||
}
|
||||
else
|
||||
@ -41,9 +41,9 @@ class FunctionTemplate extends MemberTemplate {
|
||||
}
|
||||
|
||||
FunctionTemplate(TypeTemplate template, int index, String name,
|
||||
this.arguments, this.returnType, String expansion)
|
||||
this.arguments, this.returnType, this.expansion)
|
||||
: super(template, MemberType.Property, index, name) {
|
||||
this.isVoid = isVoid;
|
||||
this.expansion = expansion;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,8 @@ class MemberTemplate
|
||||
|
||||
TypeTemplate get template => _template;
|
||||
|
||||
MemberTemplate(TypeTemplate template, MemberType type, int index, String name)
|
||||
MemberTemplate(this._template, this._type, this._index, this._name)
|
||||
{
|
||||
this._template = template;
|
||||
this._type = type;
|
||||
this._index = index;
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
String get fullname => _template.className + "." + _name;
|
||||
|
@ -14,63 +14,59 @@ class PropertyTemplate extends MemberTemplate {
|
||||
|
||||
int storage;
|
||||
|
||||
String readExpansion;
|
||||
String? readExpansion;
|
||||
|
||||
String writeExpansion;
|
||||
String? writeExpansion;
|
||||
|
||||
DC compose() {
|
||||
var name = super.compose();
|
||||
var pv = ((permission) << 1) | (storage == StorageMode.Recordable ? 1 : 0);
|
||||
|
||||
if (writeExpansion != null && readExpansion != null) {
|
||||
var rexp = DC.stringToBytes(readExpansion);
|
||||
var wexp = DC.stringToBytes(writeExpansion);
|
||||
return new BinaryList()
|
||||
.addUint8(0x38 | pv)
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(valueType.compose())
|
||||
.addInt32(wexp.length)
|
||||
.addDC(wexp)
|
||||
.addInt32(rexp.length)
|
||||
.addDC(rexp)
|
||||
var rexp = DC.stringToBytes(readExpansion as String);
|
||||
var wexp = DC.stringToBytes(writeExpansion as String);
|
||||
return (BinaryList()
|
||||
..addUint8(0x38 | pv)
|
||||
..addUint8(name.length)
|
||||
..addDC(name)
|
||||
..addDC(valueType.compose())
|
||||
..addInt32(wexp.length)
|
||||
..addDC(wexp)
|
||||
..addInt32(rexp.length)
|
||||
..addDC(rexp))
|
||||
.toDC();
|
||||
} else if (writeExpansion != null) {
|
||||
var wexp = DC.stringToBytes(writeExpansion);
|
||||
return new BinaryList()
|
||||
.addUint8(0x30 | pv)
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(valueType.compose())
|
||||
.addInt32(wexp.length)
|
||||
.addDC(wexp)
|
||||
var wexp = DC.stringToBytes(writeExpansion as String);
|
||||
return (BinaryList()
|
||||
..addUint8(0x30 | pv)
|
||||
..addUint8(name.length)
|
||||
..addDC(name)
|
||||
..addDC(valueType.compose())
|
||||
..addInt32(wexp.length)
|
||||
..addDC(wexp))
|
||||
.toDC();
|
||||
} else if (readExpansion != null) {
|
||||
var rexp = DC.stringToBytes(readExpansion);
|
||||
return new BinaryList()
|
||||
.addUint8(0x28 | pv)
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(valueType.compose())
|
||||
.addInt32(rexp.length)
|
||||
.addDC(rexp)
|
||||
var rexp = DC.stringToBytes(readExpansion as String);
|
||||
return (BinaryList()
|
||||
..addUint8(0x28 | pv)
|
||||
..addUint8(name.length)
|
||||
..addDC(name)
|
||||
..addDC(valueType.compose())
|
||||
..addInt32(rexp.length)
|
||||
..addDC(rexp))
|
||||
.toDC();
|
||||
} else
|
||||
return new BinaryList()
|
||||
.addUint8(0x20 | pv)
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(valueType.compose())
|
||||
return (BinaryList()
|
||||
..addUint8(0x20 | pv)
|
||||
..addUint8(name.length)
|
||||
..addDC(name)
|
||||
..addDC(valueType.compose()))
|
||||
.toDC();
|
||||
}
|
||||
|
||||
PropertyTemplate(TypeTemplate template, int index, String name,
|
||||
TemplateDataType valueType, String read, String write, int storage)
|
||||
this.valueType, this.readExpansion, this.writeExpansion, this.storage)
|
||||
: super(template, MemberType.Property, index, name) {
|
||||
//this.Recordable = recordable;
|
||||
this.storage = storage;
|
||||
this.readExpansion = read;
|
||||
this.writeExpansion = write;
|
||||
this.valueType = valueType;
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,12 @@ import '../../Resource/Warehouse.dart';
|
||||
import 'TemplateType.dart';
|
||||
|
||||
class TemplateDataType {
|
||||
int type;
|
||||
TypeTemplate get typeTemplate =>
|
||||
typeGuid == null ? null : Warehouse.getTemplateByClassId(typeGuid);
|
||||
late int type;
|
||||
TypeTemplate? get typeTemplate => typeGuid == null
|
||||
? null
|
||||
: Warehouse.getTemplateByClassId(typeGuid as Guid);
|
||||
|
||||
Guid typeGuid;
|
||||
Guid? typeGuid;
|
||||
|
||||
// @TODO: implement fromType
|
||||
TemplateDataType.fromType(type, bool isArray) {
|
||||
@ -98,7 +99,10 @@ class TemplateDataType {
|
||||
type == DataType.ResourceArray ||
|
||||
type == DataType.Record ||
|
||||
type == DataType.RecordArray) {
|
||||
return BinaryList().addUint8(type).addDC(typeGuid.value).toDC();
|
||||
return (BinaryList()
|
||||
..addUint8(type)
|
||||
..addDC((typeGuid as Guid).value))
|
||||
.toDC();
|
||||
} else
|
||||
return DC.fromList([type]);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import '../../Data/DataType.dart';
|
||||
|
||||
class TemplateDescriber {
|
||||
final List<Prop> properties;
|
||||
final List<Evt> events;
|
||||
final List<Func> functions;
|
||||
final List<Prop>? properties;
|
||||
final List<Evt>? events;
|
||||
final List<Func>? functions;
|
||||
final String nameSpace;
|
||||
final int version;
|
||||
|
||||
@ -47,8 +47,8 @@ class Prop {
|
||||
final String name;
|
||||
final Type type;
|
||||
final bool isArray;
|
||||
final String readAnnotation;
|
||||
final String writeAnnotation;
|
||||
final String? readAnnotation;
|
||||
final String? writeAnnotation;
|
||||
Prop(this.name, this.type, this.isArray,
|
||||
[this.readAnnotation = null, this.writeAnnotation = null]);
|
||||
}
|
||||
@ -58,7 +58,7 @@ class Evt {
|
||||
final bool listenable;
|
||||
final Type type;
|
||||
final bool isArray;
|
||||
final String annotation;
|
||||
final String? annotation;
|
||||
|
||||
Evt(this.name, this.type, this.isArray,
|
||||
[this.listenable = false, this.annotation]);
|
||||
@ -69,7 +69,7 @@ class Func {
|
||||
final Type returnType;
|
||||
final List<Arg> argsType;
|
||||
final bool isArray;
|
||||
final String annotation;
|
||||
final String? annotation;
|
||||
|
||||
Func(this.name, this.returnType, this.isArray, this.argsType,
|
||||
[this.annotation = null]);
|
||||
|
@ -22,26 +22,26 @@ import 'TemplateDataType.dart';
|
||||
import 'TemplateType.dart';
|
||||
|
||||
class TypeTemplate {
|
||||
Guid _classId;
|
||||
String _className;
|
||||
late Guid _classId;
|
||||
late String _className;
|
||||
List<MemberTemplate> _members = [];
|
||||
List<FunctionTemplate> _functions = [];
|
||||
List<EventTemplate> _events = [];
|
||||
List<PropertyTemplate> _properties = [];
|
||||
int _version;
|
||||
late int _version;
|
||||
//bool isReady;
|
||||
|
||||
TemplateType _templateType;
|
||||
late TemplateType _templateType;
|
||||
|
||||
DC _content;
|
||||
late DC _content;
|
||||
|
||||
DC get content => _content;
|
||||
|
||||
TemplateType get type => _templateType;
|
||||
|
||||
Type _definedType;
|
||||
Type? _definedType;
|
||||
|
||||
Type get definedType => _definedType;
|
||||
Type? get definedType => _definedType;
|
||||
/*
|
||||
MemberTemplate getMemberTemplate(MemberInfo member)
|
||||
{
|
||||
@ -59,32 +59,32 @@ class TypeTemplate {
|
||||
//@TODO: implement
|
||||
static List<TypeTemplate> getDependencies(TypeTemplate template) => [];
|
||||
|
||||
EventTemplate getEventTemplateByName(String eventName) {
|
||||
EventTemplate? getEventTemplateByName(String eventName) {
|
||||
for (var i in _events) if (i.name == eventName) return i;
|
||||
return null;
|
||||
}
|
||||
|
||||
EventTemplate getEventTemplateByIndex(int index) {
|
||||
EventTemplate? getEventTemplateByIndex(int index) {
|
||||
for (var i in _events) if (i.index == index) return i;
|
||||
return null;
|
||||
}
|
||||
|
||||
FunctionTemplate getFunctionTemplateByName(String functionName) {
|
||||
FunctionTemplate? getFunctionTemplateByName(String functionName) {
|
||||
for (var i in _functions) if (i.name == functionName) return i;
|
||||
return null;
|
||||
}
|
||||
|
||||
FunctionTemplate getFunctionTemplateByIndex(int index) {
|
||||
FunctionTemplate? getFunctionTemplateByIndex(int index) {
|
||||
for (var i in _functions) if (i.index == index) return i;
|
||||
return null;
|
||||
}
|
||||
|
||||
PropertyTemplate getPropertyTemplateByIndex(int index) {
|
||||
PropertyTemplate? getPropertyTemplateByIndex(int index) {
|
||||
for (var i in _properties) if (i.index == index) return i;
|
||||
return null;
|
||||
}
|
||||
|
||||
PropertyTemplate getPropertyTemplateByName(String propertyName) {
|
||||
PropertyTemplate? getPropertyTemplateByName(String propertyName) {
|
||||
for (var i in _properties) if (i.name == propertyName) return i;
|
||||
return null;
|
||||
}
|
||||
@ -143,9 +143,11 @@ class TypeTemplate {
|
||||
if (addToWarehouse) Warehouse.putTemplate(this);
|
||||
// _templates.add(template.classId, template);
|
||||
|
||||
if (describer.properties != null)
|
||||
for (var i = 0; i < describer.properties.length; i++) {
|
||||
var pi = describer.properties[i];
|
||||
if (describer.properties != null) {
|
||||
var props = describer.properties as List<Prop>;
|
||||
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var pi = props[i];
|
||||
var pt = PropertyTemplate(
|
||||
this,
|
||||
i,
|
||||
@ -156,10 +158,13 @@ class TypeTemplate {
|
||||
0);
|
||||
properties.add(pt);
|
||||
}
|
||||
}
|
||||
|
||||
if (describer.functions != null)
|
||||
for (var i = 0; i < describer.functions.length; i++) {
|
||||
var fi = describer.functions[i];
|
||||
if (describer.functions != null) {
|
||||
var funcs = describer.functions as List<Func>;
|
||||
|
||||
for (var i = 0; i < funcs.length; i++) {
|
||||
var fi = funcs[i];
|
||||
|
||||
List<ArgumentTemplate> args = fi.argsType
|
||||
.map((arg) => ArgumentTemplate(
|
||||
@ -176,10 +181,12 @@ class TypeTemplate {
|
||||
|
||||
functions.add(ft);
|
||||
}
|
||||
}
|
||||
|
||||
if (describer.events != null)
|
||||
for (var i = 0; i < describer.events.length; i++) {
|
||||
var ei = describer.events[i];
|
||||
if (describer.events != null) {
|
||||
var evts = describer.events as List<Evt>;
|
||||
for (var i = 0; i < evts.length; i++) {
|
||||
var ei = evts[i];
|
||||
|
||||
var et = new EventTemplate(
|
||||
this,
|
||||
@ -191,6 +198,7 @@ class TypeTemplate {
|
||||
|
||||
events.add(et);
|
||||
}
|
||||
}
|
||||
|
||||
// append signals
|
||||
events.forEach(_members.add);
|
||||
@ -200,14 +208,13 @@ class TypeTemplate {
|
||||
properties.forEach(_members.add);
|
||||
|
||||
// bake it binarily
|
||||
var b = new BinaryList();
|
||||
b
|
||||
.addUint8(_templateType.index)
|
||||
.addGuid(classId)
|
||||
.addUint8(className.length)
|
||||
.addString(className)
|
||||
.addInt32(_version)
|
||||
.addUint16(_members.length);
|
||||
var b = BinaryList()
|
||||
..addUint8(_templateType.index)
|
||||
..addGuid(classId)
|
||||
..addUint8(className.length)
|
||||
..addString(className)
|
||||
..addInt32(_version)
|
||||
..addUint16(_members.length);
|
||||
|
||||
functions.forEach((ft) => b.addDC(ft.compose()));
|
||||
properties.forEach((pt) => b.addDC(pt.compose()));
|
||||
@ -429,7 +436,7 @@ class TypeTemplate {
|
||||
|
||||
*/
|
||||
|
||||
TypeTemplate.parse(DC data, [int offset = 0, int contentLength]) {
|
||||
TypeTemplate.parse(DC data, [int offset = 0, int? contentLength]) {
|
||||
// cool Dart feature
|
||||
contentLength ??= data.length;
|
||||
|
||||
@ -464,7 +471,7 @@ class TypeTemplate {
|
||||
|
||||
if (type == 0) // function
|
||||
{
|
||||
String expansion = null;
|
||||
String? expansion = null;
|
||||
var hasExpansion = ((data[offset++] & 0x10) == 0x10);
|
||||
|
||||
var name = data.getString(offset + 1, data[offset]);
|
||||
@ -497,7 +504,7 @@ class TypeTemplate {
|
||||
_functions.add(ft);
|
||||
} else if (type == 1) // property
|
||||
{
|
||||
String readExpansion = null, writeExpansion = null;
|
||||
String? readExpansion = null, writeExpansion = null;
|
||||
|
||||
var hasReadExpansion = ((data[offset] & 0x8) == 0x8);
|
||||
var hasWriteExpansion = ((data[offset] & 0x10) == 0x10);
|
||||
@ -539,7 +546,7 @@ class TypeTemplate {
|
||||
_properties.add(pt);
|
||||
} else if (type == 2) // Event
|
||||
{
|
||||
String expansion = null;
|
||||
String? expansion = null;
|
||||
var hasExpansion = ((data[offset] & 0x10) == 0x10);
|
||||
var listenable = ((data[offset++] & 0x8) == 0x8);
|
||||
|
||||
|
@ -22,6 +22,10 @@ SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
import '../Core/AsyncException.dart';
|
||||
import '../Core/ErrorType.dart';
|
||||
import '../Core/ExceptionCode.dart';
|
||||
|
||||
import '../Data/AutoList.dart';
|
||||
import 'FactoryEntry.dart';
|
||||
import 'Template/TemplateType.dart';
|
||||
@ -41,8 +45,7 @@ import '../Net/IIP/DistributedConnection.dart';
|
||||
|
||||
// Centeral Resource Issuer
|
||||
class Warehouse {
|
||||
static AutoList<IResource, Instance> _stores =
|
||||
new AutoList<IResource, Instance>(null);
|
||||
static AutoList<IStore, Instance> _stores = AutoList<IStore, Instance>();
|
||||
static Map<int, IResource> _resources = new Map<int, IResource>();
|
||||
static int resourceCounter = 0;
|
||||
|
||||
@ -74,8 +77,8 @@ class Warehouse {
|
||||
/// </summary>
|
||||
/// <param name="name">Store instance name</param>
|
||||
/// <returns></returns>
|
||||
static IStore getStore(String name) {
|
||||
for (var s in _stores) if (s.instance.name == name) return s;
|
||||
static IStore? getStore(String name) {
|
||||
for (var s in _stores) if (s.instance?.name == name) return s;
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -84,11 +87,11 @@ class Warehouse {
|
||||
/// </summary>
|
||||
/// <param name="id">Instance Id</param>
|
||||
/// <returns></returns>
|
||||
static AsyncReply<IResource> getById(int id) {
|
||||
static AsyncReply<IResource?> getById(int id) {
|
||||
if (_resources.containsKey(id))
|
||||
return new AsyncReply<IResource>.ready(_resources[id]);
|
||||
return new AsyncReply<IResource?>.ready(_resources[id]);
|
||||
else
|
||||
return new AsyncReply<IResource>.ready(null);
|
||||
return new AsyncReply<IResource?>.ready(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -106,20 +109,21 @@ class Warehouse {
|
||||
var rt = new AsyncReply<bool>();
|
||||
bag.then((x) {
|
||||
for (var b in x)
|
||||
if (!b) {
|
||||
if (b == null || b == false) {
|
||||
rt.trigger(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var rBag = new AsyncBag<bool>();
|
||||
for (var rk in _resources.keys)
|
||||
rBag.add(_resources[rk].trigger(ResourceTrigger.SystemInitialized));
|
||||
rBag.add((_resources[rk] as IResource)
|
||||
.trigger(ResourceTrigger.SystemInitialized));
|
||||
|
||||
rBag.seal();
|
||||
|
||||
rBag.then((y) {
|
||||
for (var b in y)
|
||||
if (!b) {
|
||||
if (b == null || b == false) {
|
||||
rt.trigger(false);
|
||||
return;
|
||||
}
|
||||
@ -158,7 +162,7 @@ class Warehouse {
|
||||
var rt = new AsyncReply<bool>();
|
||||
bag.then((x) {
|
||||
for (var b in x)
|
||||
if (!b) {
|
||||
if (b == null || b == false) {
|
||||
rt.trigger(false);
|
||||
return;
|
||||
}
|
||||
@ -178,19 +182,21 @@ class Warehouse {
|
||||
for (var child in resources) rt.add(child);
|
||||
else
|
||||
for (var child in resources)
|
||||
if (child.instance.name == path[index]) rt.add(child);
|
||||
if (child.instance?.name == path[index]) rt.add(child);
|
||||
} else
|
||||
for (var child in resources)
|
||||
if (child.instance.name == path[index])
|
||||
rt.addAll(qureyIn(path, index + 1, child.instance.children));
|
||||
if (child.instance?.name == path[index])
|
||||
rt.addAll(qureyIn(path, index + 1,
|
||||
child.instance?.children as AutoList<IResource, Instance>));
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
static AsyncReply<List<IResource>> query(String path) {
|
||||
static AsyncReply<List<IResource>?> query(String? path) {
|
||||
if (path == null || path == "") {
|
||||
var roots = _stores.where((s) => s.instance.parents.length == 0).toList();
|
||||
return new AsyncReply<List<IResource>>.ready(roots);
|
||||
var roots =
|
||||
_stores.where((s) => s.instance?.parents.length == 0).toList();
|
||||
return new AsyncReply<List<IResource>?>.ready(roots);
|
||||
} else {
|
||||
var rt = new AsyncReply<List<IResource>>();
|
||||
get(path).then((x) {
|
||||
@ -215,35 +221,41 @@ class Warehouse {
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns>Resource instance.</returns>
|
||||
static AsyncReply<T> get<T extends IResource>(String path,
|
||||
static AsyncReply<T?> get<T extends IResource>(String path,
|
||||
[attributes = null,
|
||||
IResource parent = null,
|
||||
IPermissionsManager manager = null]) {
|
||||
var rt = AsyncReply<T>();
|
||||
IResource? parent = null,
|
||||
IPermissionsManager? manager = null]) {
|
||||
var rt = AsyncReply<T?>();
|
||||
|
||||
// Should we create a new store ?
|
||||
if (_urlRegex.hasMatch(path)) {
|
||||
var url = _urlRegex.allMatches(path).first;
|
||||
|
||||
if (protocols.containsKey(url[1])) {
|
||||
var handler = protocols[url[1]];
|
||||
var handler =
|
||||
protocols[url[1]] as AsyncReply<IStore> Function(String, dynamic);
|
||||
|
||||
var getFromStore = () {
|
||||
handler(url[2], attributes).then<IStore>((store) {
|
||||
if (url[3].length > 0 && url[3] != "")
|
||||
store.get(url[3]).then<dynamic>((r) {
|
||||
rt.trigger(r);
|
||||
}).error((e) => rt.triggerError(e));
|
||||
handler(url[2] as String, attributes)
|
||||
..then((store) {
|
||||
if ((url[3] as String).length > 0 && url[3] != "")
|
||||
store.get(url[3] as String)
|
||||
..then((r) {
|
||||
rt.trigger(r as T);
|
||||
})
|
||||
..error((e) => rt.triggerError(e));
|
||||
else
|
||||
rt.trigger(store as T);
|
||||
}).error((e) {
|
||||
})
|
||||
..error((e) {
|
||||
rt.triggerError(e);
|
||||
//Warehouse.remove(store);
|
||||
});
|
||||
};
|
||||
|
||||
if (!_warehouseIsOpen)
|
||||
open().then((v) {
|
||||
open()
|
||||
..then((v) {
|
||||
if (v)
|
||||
getFromStore();
|
||||
else
|
||||
@ -258,7 +270,7 @@ class Warehouse {
|
||||
|
||||
query(path).then((rs) {
|
||||
if (rs != null && rs.length > 0)
|
||||
rt.trigger(rs[0]);
|
||||
rt.trigger(rs[0] as T);
|
||||
else
|
||||
rt.trigger(null);
|
||||
});
|
||||
@ -342,14 +354,14 @@ class Warehouse {
|
||||
/// <param name="name">Resource name.</param>
|
||||
/// <param name="store">IStore that manages the resource. Can be null if the resource is a store.</param>
|
||||
/// <param name="parent">Parent resource. if not presented the store becomes the parent for the resource.</param>
|
||||
static AsyncReply<T> put<T extends IResource>(String name, T resource,
|
||||
[IStore store = null,
|
||||
IResource parent = null,
|
||||
TypeTemplate customTemplate = null,
|
||||
static AsyncReply<T?> put<T extends IResource>(String name, T resource,
|
||||
[IStore? store = null,
|
||||
IResource? parent = null,
|
||||
TypeTemplate? customTemplate = null,
|
||||
int age = 0,
|
||||
IPermissionsManager manager = null,
|
||||
IPermissionsManager? manager = null,
|
||||
attributes = null]) {
|
||||
var rt = AsyncReply<T>();
|
||||
var rt = AsyncReply<T?>();
|
||||
|
||||
if (resource.instance != null) {
|
||||
rt.triggerError(Exception("Resource has a store."));
|
||||
@ -415,19 +427,21 @@ class Warehouse {
|
||||
resourceCounter++, name, resource, store, customTemplate, age);
|
||||
|
||||
if (attributes != null)
|
||||
resource.instance.setAttributes(Structure.fromMap(attributes));
|
||||
resource.instance?.setAttributes(Structure.fromMap(attributes));
|
||||
|
||||
if (manager != null) resource.instance.managers.add(manager);
|
||||
if (manager != null) resource.instance?.managers.add(manager);
|
||||
|
||||
if (store == parent) parent = null;
|
||||
|
||||
if (parent == null) {
|
||||
if (!(resource is IStore)) store.instance.children.add(resource);
|
||||
if (!(resource is IStore)) store?.instance?.children.add(resource);
|
||||
} else
|
||||
parent.instance.children.add(resource);
|
||||
parent.instance?.children.add(resource);
|
||||
|
||||
var initResource = () {
|
||||
_resources[resource.instance.id] = resource;
|
||||
if (resource.instance == null) return;
|
||||
|
||||
_resources[(resource.instance as Instance).id] = resource;
|
||||
|
||||
if (_warehouseIsOpen) {
|
||||
resource.trigger(ResourceTrigger.Initialize).then<dynamic>((value) {
|
||||
@ -451,7 +465,7 @@ class Warehouse {
|
||||
_stores.add(resource);
|
||||
initResource();
|
||||
} else {
|
||||
store.put(resource).then<dynamic>((value) {
|
||||
store?.put(resource).then<dynamic>((value) {
|
||||
if (value)
|
||||
initResource();
|
||||
else
|
||||
@ -468,20 +482,23 @@ class Warehouse {
|
||||
}
|
||||
|
||||
static T createInstance<T>(Type T) {
|
||||
return _factory[T].instanceCreator.call();
|
||||
return _factory[T]?.instanceCreator.call();
|
||||
}
|
||||
|
||||
static List<T> createArray<T>(Type T) {
|
||||
return _factory[T].arrayCreator.call();
|
||||
return _factory[T]?.arrayCreator.call();
|
||||
}
|
||||
|
||||
static AsyncReply<T> newResource<T extends IResource>(String name,
|
||||
[IStore store = null,
|
||||
IResource parent = null,
|
||||
IPermissionsManager manager = null,
|
||||
[IStore? store = null,
|
||||
IResource? parent = null,
|
||||
IPermissionsManager? manager = null,
|
||||
attributes = null,
|
||||
properties = null]) {
|
||||
var resource = _factory[T].instanceCreator.call();
|
||||
if (_factory[T] == null)
|
||||
throw Exception("No Instance Creator was found for type ${T}");
|
||||
|
||||
var resource = _factory[T]?.instanceCreator.call();
|
||||
|
||||
if (properties != null) {
|
||||
dynamic d = resource;
|
||||
@ -494,12 +511,16 @@ class Warehouse {
|
||||
var rt = AsyncReply<T>();
|
||||
|
||||
put<T>(name, resource, store, parent, null, 0, manager, attributes)
|
||||
.then<IResource>((value) {
|
||||
..then((value) {
|
||||
if (value != null)
|
||||
rt.trigger(resource);
|
||||
else
|
||||
rt.trigger(null);
|
||||
}).error((ex) => rt.triggerError(ex));
|
||||
rt.triggerError(AsyncException(
|
||||
ErrorType.Management,
|
||||
ExceptionCode.GeneralFailure.index,
|
||||
"Can't put the resource")); // .trigger(null);
|
||||
})
|
||||
..error((ex) => rt.triggerError(ex));
|
||||
|
||||
return rt;
|
||||
|
||||
@ -516,7 +537,7 @@ class Warehouse {
|
||||
/// </summary>
|
||||
/// <param name="template">Resource template.</param>
|
||||
static void putTemplate(TypeTemplate template) {
|
||||
_templates[template.type][template.classId] = template;
|
||||
_templates[template.type]?[template.classId] = template;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -541,22 +562,22 @@ class Warehouse {
|
||||
/// </summary>
|
||||
/// <param name="classId">Class Id.</param>
|
||||
/// <returns>Resource template.</returns>
|
||||
static TypeTemplate getTemplateByClassId(Guid classId,
|
||||
static TypeTemplate? getTemplateByClassId(Guid classId,
|
||||
[TemplateType templateType = TemplateType.Unspecified]) {
|
||||
if (templateType == TemplateType.Unspecified) {
|
||||
// look in resources
|
||||
var template = _templates[TemplateType.Resource][classId];
|
||||
var template = _templates[TemplateType.Resource]?[classId];
|
||||
if (template != null) return template;
|
||||
|
||||
// look in records
|
||||
template = _templates[TemplateType.Record][classId];
|
||||
template = _templates[TemplateType.Record]?[classId];
|
||||
if (template != null) return template;
|
||||
|
||||
// look in wrappers
|
||||
template = _templates[TemplateType.Wrapper][classId];
|
||||
template = _templates[TemplateType.Wrapper]?[classId];
|
||||
return template;
|
||||
} else {
|
||||
return _templates[templateType][classId];
|
||||
return _templates[templateType]?[classId];
|
||||
}
|
||||
}
|
||||
|
||||
@ -565,29 +586,29 @@ class Warehouse {
|
||||
/// </summary>
|
||||
/// <param name="className">Class name.</param>
|
||||
/// <returns>Resource template.</returns>
|
||||
static TypeTemplate getTemplateByClassName(String className,
|
||||
static TypeTemplate? getTemplateByClassName(String className,
|
||||
[TemplateType templateType = TemplateType.Unspecified]) {
|
||||
if (templateType == TemplateType.Unspecified) {
|
||||
// look in resources
|
||||
var template = _templates[TemplateType.Resource]
|
||||
.values
|
||||
?.values
|
||||
.firstWhere((x) => x.className == className);
|
||||
if (template != null) return template;
|
||||
|
||||
// look in records
|
||||
template = _templates[TemplateType.Record]
|
||||
.values
|
||||
?.values
|
||||
.firstWhere((x) => x.className == className);
|
||||
if (template != null) return template;
|
||||
|
||||
// look in wrappers
|
||||
template = _templates[TemplateType.Wrapper]
|
||||
.values
|
||||
?.values
|
||||
.firstWhere((x) => x.className == className);
|
||||
return template;
|
||||
} else {
|
||||
return _templates[templateType]
|
||||
.values
|
||||
?.values
|
||||
.firstWhere((x) => x.className == className);
|
||||
}
|
||||
}
|
||||
@ -595,8 +616,8 @@ class Warehouse {
|
||||
static bool remove(IResource resource) {
|
||||
if (resource.instance == null) return false;
|
||||
|
||||
if (_resources.containsKey(resource.instance.id))
|
||||
_resources.remove(resource.instance.id);
|
||||
if (_resources.containsKey(resource.instance?.id))
|
||||
_resources.remove(resource.instance?.id);
|
||||
else
|
||||
return false;
|
||||
|
||||
@ -605,14 +626,14 @@ class Warehouse {
|
||||
|
||||
// remove all objects associated with the store
|
||||
var toBeRemoved =
|
||||
_resources.values.where((x) => x.instance.store == resource);
|
||||
_resources.values.where((x) => x.instance?.store == resource);
|
||||
for (var o in toBeRemoved) remove(o);
|
||||
|
||||
// StoreDisconnected?.Invoke(resource as IStore);
|
||||
}
|
||||
|
||||
if (resource.instance.store != null)
|
||||
resource.instance.store.remove(resource);
|
||||
if (resource.instance?.store != null)
|
||||
resource.instance?.store?.remove(resource);
|
||||
|
||||
resource.destroy();
|
||||
|
||||
|
@ -27,27 +27,20 @@ import 'AuthenticationMethod.dart';
|
||||
import 'AuthenticationType.dart';
|
||||
import 'Source.dart';
|
||||
|
||||
class Authentication
|
||||
{
|
||||
class Authentication {
|
||||
int? tokenIndex;
|
||||
AuthenticationMethod method = AuthenticationMethod.None;
|
||||
|
||||
int tokenIndex;
|
||||
AuthenticationMethod method;
|
||||
|
||||
String username;
|
||||
String? username;
|
||||
//Certificate certificate;
|
||||
String domain;
|
||||
String? domain;
|
||||
|
||||
String get fullName => username + "@" + domain;
|
||||
int state;
|
||||
|
||||
Source source = new Source();
|
||||
String get fullName => (username ?? '') + '@' + (domain ?? '');
|
||||
int state = 0;
|
||||
|
||||
Source? source;
|
||||
|
||||
final AuthenticationType type;
|
||||
|
||||
Authentication(this.type)
|
||||
{
|
||||
|
||||
Authentication(this.type) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ class Session
|
||||
Authentication get remoteAuthentication => _remoteAuth;
|
||||
|
||||
// public Source Source { get; }
|
||||
DC id;
|
||||
DC? id;
|
||||
|
||||
//DateTime get creation => _creation;
|
||||
|
||||
@ -45,10 +45,8 @@ class Session
|
||||
Authentication _localAuth, _remoteAuth;
|
||||
|
||||
|
||||
Session(Authentication localAuthentication, Authentication remoteAuthentication)
|
||||
Session(this._localAuth, this._remoteAuth)
|
||||
{
|
||||
|
||||
this._localAuth = localAuthentication;
|
||||
this._remoteAuth = remoteAuthentication;
|
||||
}
|
||||
}
|
||||
|
@ -25,22 +25,12 @@ SOFTWARE.
|
||||
import '../../Data/KeyList.dart';
|
||||
import 'SourceAttributeType.dart';
|
||||
|
||||
class Source
|
||||
{
|
||||
|
||||
class Source {
|
||||
//string id;
|
||||
String id;
|
||||
|
||||
KeyList<SourceAttributeType, dynamic> attributes;
|
||||
|
||||
Source.from(this.id, this.attributes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Source()
|
||||
{
|
||||
attributes = new KeyList<SourceAttributeType, dynamic>();
|
||||
}
|
||||
KeyList<SourceAttributeType, dynamic> attributes =
|
||||
new KeyList<SourceAttributeType, dynamic>();
|
||||
|
||||
Source.from(this.id, this.attributes) {}
|
||||
}
|
||||
|
@ -2,22 +2,17 @@ import '../../Data/DC.dart';
|
||||
import '../../Data/BinaryList.dart';
|
||||
import 'dart:typed_data';
|
||||
|
||||
class SHA256
|
||||
{
|
||||
|
||||
static int RROT(int n, int d)
|
||||
{
|
||||
class SHA256 {
|
||||
static int RROT(int n, int d) {
|
||||
return ZSHIFT(n, d) | (n << (32 - d));
|
||||
}
|
||||
|
||||
// Zero-fill right shift
|
||||
static int ZSHIFT(int n, int d)
|
||||
{
|
||||
static int ZSHIFT(int n, int d) {
|
||||
return (n & 0xFFFFFFFF) >> d;
|
||||
}
|
||||
|
||||
static DC compute(DC msg)
|
||||
{
|
||||
static DC compute(DC msg) {
|
||||
/*
|
||||
Note 1: All variables are 32 bit unsigned integers and addition is calculated modulo 2^32
|
||||
Note 2: For each round, there is one round constant k[i] and one entry in the message schedule array w[i], 0 ≤ i ≤ 63
|
||||
@ -30,22 +25,85 @@ class SHA256
|
||||
// Initialize hash values:
|
||||
// (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
|
||||
|
||||
var hash = new Uint32List.fromList([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f,
|
||||
0x9b05688c, 0x1f83d9ab, 0x5be0cd19 ]);
|
||||
var hash = new Uint32List.fromList([
|
||||
0x6a09e667,
|
||||
0xbb67ae85,
|
||||
0x3c6ef372,
|
||||
0xa54ff53a,
|
||||
0x510e527f,
|
||||
0x9b05688c,
|
||||
0x1f83d9ab,
|
||||
0x5be0cd19
|
||||
]);
|
||||
|
||||
// Initialize array of round constants:
|
||||
// (first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311):
|
||||
var k = new Uint32List.fromList([
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 ]);
|
||||
|
||||
|
||||
0x428a2f98,
|
||||
0x71374491,
|
||||
0xb5c0fbcf,
|
||||
0xe9b5dba5,
|
||||
0x3956c25b,
|
||||
0x59f111f1,
|
||||
0x923f82a4,
|
||||
0xab1c5ed5,
|
||||
0xd807aa98,
|
||||
0x12835b01,
|
||||
0x243185be,
|
||||
0x550c7dc3,
|
||||
0x72be5d74,
|
||||
0x80deb1fe,
|
||||
0x9bdc06a7,
|
||||
0xc19bf174,
|
||||
0xe49b69c1,
|
||||
0xefbe4786,
|
||||
0x0fc19dc6,
|
||||
0x240ca1cc,
|
||||
0x2de92c6f,
|
||||
0x4a7484aa,
|
||||
0x5cb0a9dc,
|
||||
0x76f988da,
|
||||
0x983e5152,
|
||||
0xa831c66d,
|
||||
0xb00327c8,
|
||||
0xbf597fc7,
|
||||
0xc6e00bf3,
|
||||
0xd5a79147,
|
||||
0x06ca6351,
|
||||
0x14292967,
|
||||
0x27b70a85,
|
||||
0x2e1b2138,
|
||||
0x4d2c6dfc,
|
||||
0x53380d13,
|
||||
0x650a7354,
|
||||
0x766a0abb,
|
||||
0x81c2c92e,
|
||||
0x92722c85,
|
||||
0xa2bfe8a1,
|
||||
0xa81a664b,
|
||||
0xc24b8b70,
|
||||
0xc76c51a3,
|
||||
0xd192e819,
|
||||
0xd6990624,
|
||||
0xf40e3585,
|
||||
0x106aa070,
|
||||
0x19a4c116,
|
||||
0x1e376c08,
|
||||
0x2748774c,
|
||||
0x34b0bcb5,
|
||||
0x391c0cb3,
|
||||
0x4ed8aa4a,
|
||||
0x5b9cca4f,
|
||||
0x682e6ff3,
|
||||
0x748f82ee,
|
||||
0x78a5636f,
|
||||
0x84c87814,
|
||||
0x8cc70208,
|
||||
0x90befffa,
|
||||
0xa4506ceb,
|
||||
0xbef9a3f7,
|
||||
0xc67178f2
|
||||
]);
|
||||
|
||||
// Pre-processing:
|
||||
// begin with the original message of length L bits
|
||||
@ -56,16 +114,17 @@ class SHA256
|
||||
|
||||
var K = 512 - ((L + 1 + 64) % 512);
|
||||
|
||||
if (K == 512)
|
||||
K = 0;
|
||||
if (K == 512) K = 0;
|
||||
|
||||
var paddingLength = (K + 1) ~/ 8;
|
||||
var paddingBytes = new DC(paddingLength);
|
||||
paddingBytes[0] = 0x80;
|
||||
|
||||
var data = new BinaryList().addDC(msg).addDC(paddingBytes).addUint64(L).toDC();
|
||||
|
||||
|
||||
var data = (BinaryList()
|
||||
..addDC(msg)
|
||||
..addDC(paddingBytes)
|
||||
..addUint64(L))
|
||||
.toDC();
|
||||
|
||||
// append L as a 64-bit big-endian integer, making the total post-processed length a multiple of 512 bits
|
||||
|
||||
@ -73,15 +132,13 @@ class SHA256
|
||||
// break message into 512-bit chunks
|
||||
// for each chunk
|
||||
|
||||
for (var chunk = 0; chunk < data.length; chunk += 64)
|
||||
{
|
||||
for (var chunk = 0; chunk < data.length; chunk += 64) {
|
||||
// create a 64-entry message schedule array w[0..63] of 32-bit words
|
||||
// (The initial values in w[0..63] don't matter, so many implementations zero them here)
|
||||
// copy chunk into first 16 words w[0..15] of the message schedule array
|
||||
|
||||
var w = new Uint64List(64); // uint[64];
|
||||
for (var i = 0; i < 16; i++)
|
||||
w[i] = data.getUint32(chunk + (i * 4));
|
||||
for (var i = 0; i < 16; i++) w[i] = data.getUint32(chunk + (i * 4));
|
||||
|
||||
//for(var i = 16; i < 64; i++)
|
||||
// w[i] = 0;
|
||||
@ -92,10 +149,13 @@ class SHA256
|
||||
// s1 := (w[i-2] rightrotate 17) xor (w[i-2] rightrotate 19) xor (w[i-2] rightshift 10)
|
||||
// w[i] := w[i-16] + s0 + w[i-7] + s1
|
||||
|
||||
for (var i = 16; i < 64; i++)
|
||||
{
|
||||
var s0 = SHA256.RROT(w[i - 15], 7) ^ SHA256.RROT(w[i - 15], 18) ^ ZSHIFT(w[i - 15], 3);
|
||||
var s1 = SHA256.RROT(w[i - 2], 17) ^ SHA256.RROT(w[i - 2], 19) ^ ZSHIFT(w[i - 2], 10);
|
||||
for (var i = 16; i < 64; i++) {
|
||||
var s0 = SHA256.RROT(w[i - 15], 7) ^
|
||||
SHA256.RROT(w[i - 15], 18) ^
|
||||
ZSHIFT(w[i - 15], 3);
|
||||
var s1 = SHA256.RROT(w[i - 2], 17) ^
|
||||
SHA256.RROT(w[i - 2], 19) ^
|
||||
ZSHIFT(w[i - 2], 10);
|
||||
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
||||
}
|
||||
|
||||
@ -109,10 +169,8 @@ class SHA256
|
||||
var g = hash[6];
|
||||
var h = hash[7];
|
||||
|
||||
|
||||
// Compression function main loop:
|
||||
for (var i = 0; i < 64; i++)
|
||||
{
|
||||
for (var i = 0; i < 64; i++) {
|
||||
var S1 = SHA256.RROT(e, 6) ^ SHA256.RROT(e, 11) ^ SHA256.RROT(e, 25);
|
||||
var ch = (e & f) ^ ((~e) & g);
|
||||
var temp1 = h + S1 + ch + k[i] + w[i];
|
||||
@ -140,20 +198,13 @@ class SHA256
|
||||
hash[5] = ZSHIFT(hash[5] + f, 0);
|
||||
hash[6] = ZSHIFT(hash[6] + g, 0);
|
||||
hash[7] = ZSHIFT(hash[7] + h, 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Produce the final hash value (big-endian):
|
||||
//digest := hash := h0 append h1 append h2 append h3 append h4 append h5 append h6 append h7
|
||||
|
||||
var results = new BinaryList();
|
||||
for (var i = 0; i < 8; i++)
|
||||
results.addUint32(hash[i]);
|
||||
|
||||
for (var i = 0; i < 8; i++) results.addUint32(hash[i]);
|
||||
|
||||
return results.toDC();
|
||||
}
|
||||
|
59
pubspec.lock
59
pubspec.lock
@ -7,28 +7,28 @@ packages:
|
||||
name: _fe_analyzer_shared
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "22.0.0"
|
||||
version: "23.0.0"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.7.1"
|
||||
version: "2.0.0"
|
||||
args:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: args
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.6.0"
|
||||
version: "2.2.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.7.0"
|
||||
version: "2.8.1"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -42,7 +42,7 @@ packages:
|
||||
name: build
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
version: "2.0.3"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -63,7 +63,7 @@ packages:
|
||||
name: cli_util
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
version: "0.3.3"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -77,14 +77,14 @@ packages:
|
||||
name: convert
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
version: "3.0.1"
|
||||
coverage:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: coverage
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.15.2"
|
||||
version: "1.0.3"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -98,7 +98,7 @@ packages:
|
||||
name: dart_style
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
version: "2.0.3"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -106,6 +106,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.1.2"
|
||||
frontend_server_client:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: frontend_server_client
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -119,21 +126,21 @@ packages:
|
||||
name: http_multi_server
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
version: "3.0.1"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_parser
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.3"
|
||||
version: "4.0.0"
|
||||
io:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: io
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.3"
|
||||
version: "1.0.3"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -147,7 +154,7 @@ packages:
|
||||
name: json_annotation
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.1"
|
||||
version: "4.1.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -168,21 +175,21 @@ packages:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
version: "1.7.0"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: mime
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.6+3"
|
||||
version: "1.0.0"
|
||||
node_preamble:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: node_preamble
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.8"
|
||||
version: "2.0.1"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -231,35 +238,35 @@ packages:
|
||||
name: shelf
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.7.5"
|
||||
version: "1.2.0"
|
||||
shelf_packages_handler:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_packages_handler
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "3.0.0"
|
||||
shelf_static:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_static
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.9+2"
|
||||
version: "1.1.0"
|
||||
shelf_web_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_web_socket
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.3"
|
||||
version: "1.0.1"
|
||||
source_gen:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: source_gen
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
version: "1.0.5"
|
||||
source_map_stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -315,21 +322,21 @@ packages:
|
||||
name: test
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.16.5"
|
||||
version: "1.17.10"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.19"
|
||||
version: "0.4.2"
|
||||
test_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.15"
|
||||
version: "0.4.0"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -343,7 +350,7 @@ packages:
|
||||
name: vm_service
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
version: "7.1.1"
|
||||
watcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -357,7 +364,7 @@ packages:
|
||||
name: web_socket_channel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
version: "2.1.0"
|
||||
webkit_inspection_protocol:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1,20 +1,20 @@
|
||||
name: esiur
|
||||
description: Distributed Object Framework.
|
||||
version: 1.4.0
|
||||
version: 1.4.1
|
||||
#author: Ahmed Zamil <ahmed@esiur.com>
|
||||
homepage: https://github.com/esiur/esiur-dart
|
||||
|
||||
|
||||
environment:
|
||||
sdk: ">=2.1.0 <3.0.0"
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
source_gen: ^1.0.2
|
||||
source_gen:
|
||||
args: #
|
||||
pubspec_parse:
|
||||
|
||||
dev_dependencies:
|
||||
test: ^1.14.2
|
||||
test:
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://www.dartlang.org/tools/pub/pubspec
|
||||
|
@ -10,31 +10,31 @@ main() async {
|
||||
}
|
||||
}
|
||||
|
||||
// describe object
|
||||
desc(dynamic x) {
|
||||
if (x is List) {
|
||||
for (var i = 0; i < x.length; i++) desc(x[i]);
|
||||
} else if (x is DistributedResource) {
|
||||
var y = x.instance.template;
|
||||
print("Fucntions = ${y.functions.length}\n");
|
||||
for (var i = 0; i < y.functions.length; i++) {
|
||||
print("Function ${y.functions[i].name} ${y.functions[i].expansion}");
|
||||
}
|
||||
print("------------------------------\n");
|
||||
print("Events = ${y.events.length}\n");
|
||||
for (var i = 0; i < y.events.length; i++) {
|
||||
print("Events ${y.events[i].name} ${y.events[i].expansion}");
|
||||
}
|
||||
// // describe object
|
||||
// desc(dynamic x) {
|
||||
// if (x is List) {
|
||||
// for (var i = 0; i < x.length; i++) desc(x[i]);
|
||||
// } else if (x is DistributedResource) {
|
||||
// var y = x.instance?.template;
|
||||
// print("Fucntions = ${y.functions.length}\n");
|
||||
// for (var i = 0; i < y.functions.length; i++) {
|
||||
// print("Function ${y.functions[i].name} ${y.functions[i].expansion}");
|
||||
// }
|
||||
// print("------------------------------\n");
|
||||
// print("Events = ${y.events.length}\n");
|
||||
// for (var i = 0; i < y.events.length; i++) {
|
||||
// print("Events ${y.events[i].name} ${y.events[i].expansion}");
|
||||
// }
|
||||
|
||||
print("------------------------------\n");
|
||||
print("Properties = ${y.properties.length}\n");
|
||||
for (var i = 0; i < y.properties.length; i++) {
|
||||
print(
|
||||
"Property ${y.properties[i].name} ${y.properties[i].readExpansion}");
|
||||
// recursion
|
||||
//print("value = ${desc(x.get(y.properties[i].index))}");
|
||||
}
|
||||
} else {
|
||||
print(x.toString());
|
||||
}
|
||||
}
|
||||
// print("------------------------------\n");
|
||||
// print("Properties = ${y.properties.length}\n");
|
||||
// for (var i = 0; i < y.properties.length; i++) {
|
||||
// print(
|
||||
// "Property ${y.properties[i].name} ${y.properties[i].readExpansion}");
|
||||
// // recursion
|
||||
// //print("value = ${desc(x.get(y.properties[i].index))}");
|
||||
// }
|
||||
// } else {
|
||||
// print(x.toString());
|
||||
// }
|
||||
// }
|
||||
|
Reference in New Issue
Block a user