mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-05-06 12:02:57 +00:00
Nullable
This commit is contained in:
parent
9be227a65e
commit
872da0a2bf
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
// Resource
|
// Resource
|
||||||
export 'src/Resource/Warehouse.dart';
|
export 'src/Resource/Warehouse.dart';
|
||||||
export 'src/Resource/Instance.dart';
|
export 'src/Resource/Instance.dart';
|
||||||
@ -34,10 +33,11 @@ export 'src/Core/IEventHandler.dart';
|
|||||||
export 'src/Core/Tuple.dart';
|
export 'src/Core/Tuple.dart';
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// Data
|
// Data
|
||||||
|
export 'src/Data/RepresentationType.dart';
|
||||||
|
export 'src/Data/TransmissionType.dart';
|
||||||
export 'src/Data/AutoList.dart';
|
export 'src/Data/AutoList.dart';
|
||||||
export 'src/Data/BinaryList.dart';
|
export 'src/Data/BinaryList.dart';
|
||||||
export 'src/Data/Codec.dart';
|
export 'src/Data/Codec.dart';
|
||||||
export 'src/Data/RepresentationType.dart';
|
|
||||||
export 'src/Data/DC.dart';
|
export 'src/Data/DC.dart';
|
||||||
export 'src/Data/Guid.dart';
|
export 'src/Data/Guid.dart';
|
||||||
export 'src/Data/KeyList.dart';
|
export 'src/Data/KeyList.dart';
|
||||||
|
@ -65,8 +65,8 @@ import 'TransmissionType.dart';
|
|||||||
// Type get valueType => VT;
|
// Type get valueType => VT;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
typedef Parser = AsyncReply Function(
|
typedef Parser = AsyncReply Function(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection);
|
DistributedConnection? connection, List<int>? requestSequence);
|
||||||
typedef Composer = DataSerializerComposeResults Function(
|
typedef Composer = DataSerializerComposeResults Function(
|
||||||
dynamic value, DistributedConnection? connection);
|
dynamic value, DistributedConnection? connection);
|
||||||
|
|
||||||
@ -150,16 +150,20 @@ class Codec {
|
|||||||
/// <param name="connection">DistributedConnection is required in case a structure in the array holds items at the other end.</param>
|
/// <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>
|
/// <param name="dataType">DataType, in case the data is not prepended with DataType</param>
|
||||||
/// <returns>Value</returns>
|
/// <returns>Value</returns>
|
||||||
static CodecParseResults parse(
|
static CodecParseResults parse(DC data, int offset,
|
||||||
DC data, int offset, DistributedConnection? connection,
|
DistributedConnection? connection, List<int>? requestSequence,
|
||||||
[TransmissionType? dataType = null]) {
|
[TransmissionType? dataType = null]) {
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
//print("Parse ${offset} ${dataType} ${requestSequence}");
|
||||||
|
|
||||||
if (dataType == null) {
|
if (dataType == null) {
|
||||||
var parsedDataTyped = TransmissionType.parse(data, offset, data.length);
|
var parsedDataTyped = TransmissionType.parse(data, offset, data.length);
|
||||||
len = parsedDataTyped.size;
|
len = parsedDataTyped.size;
|
||||||
dataType = parsedDataTyped.type;
|
dataType = parsedDataTyped.type;
|
||||||
offset = dataType?.offset ?? 0;
|
offset = dataType?.offset ?? 0;
|
||||||
|
|
||||||
|
//print("Parse TT ${len} ${parsedDataTyped.type} ${dataType?.offset}");
|
||||||
} else
|
} else
|
||||||
len = dataType.contentLength;
|
len = dataType.contentLength;
|
||||||
|
|
||||||
@ -168,18 +172,22 @@ class Codec {
|
|||||||
return CodecParseResults(
|
return CodecParseResults(
|
||||||
len,
|
len,
|
||||||
fixedParsers[dataType.exponent][dataType.index](
|
fixedParsers[dataType.exponent][dataType.index](
|
||||||
data, dataType.offset, dataType.contentLength, connection));
|
data,
|
||||||
|
dataType.offset,
|
||||||
|
dataType.contentLength,
|
||||||
|
connection,
|
||||||
|
requestSequence));
|
||||||
} else if (dataType.classType == TransmissionTypeClass.Dynamic) {
|
} else if (dataType.classType == TransmissionTypeClass.Dynamic) {
|
||||||
return CodecParseResults(
|
return CodecParseResults(
|
||||||
len,
|
len,
|
||||||
dynamicParsers[dataType.index](
|
dynamicParsers[dataType.index](data, dataType.offset,
|
||||||
data, dataType.offset, dataType.contentLength, connection));
|
dataType.contentLength, connection, requestSequence));
|
||||||
} else //if (tt.Class == TransmissionTypeClass.Typed)
|
} else //if (tt.Class == TransmissionTypeClass.Typed)
|
||||||
{
|
{
|
||||||
return CodecParseResults(
|
return CodecParseResults(
|
||||||
len,
|
len,
|
||||||
typedParsers[dataType.index](
|
typedParsers[dataType.index](data, dataType.offset,
|
||||||
data, dataType.offset, dataType.contentLength, connection));
|
dataType.contentLength, connection, requestSequence));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
|
|
||||||
import 'IEnum.dart';
|
import 'IEnum.dart';
|
||||||
|
|
||||||
import '../Core/Tuple.dart';
|
import '../Core/Tuple.dart';
|
||||||
@ -23,136 +23,136 @@ class PropertyValueParserResults {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DataDeserializer {
|
class DataDeserializer {
|
||||||
static AsyncReply nullParser(
|
static AsyncReply nullParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply.ready(null);
|
return AsyncReply.ready(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply booleanTrueParser(
|
static AsyncReply booleanTrueParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return new AsyncReply<bool>.ready(true);
|
return new AsyncReply<bool>.ready(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply booleanFalseParser(
|
static AsyncReply booleanFalseParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return new AsyncReply<bool>.ready(false);
|
return new AsyncReply<bool>.ready(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply notModifiedParser(
|
static AsyncReply notModifiedParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return new AsyncReply<NotModified>.ready(NotModified());
|
return new AsyncReply<NotModified>.ready(NotModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply byteParser(
|
static AsyncReply byteParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return new AsyncReply<int>.ready(data[offset]);
|
return new AsyncReply<int>.ready(data[offset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply sByteParser(
|
static AsyncReply sByteParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return new AsyncReply<int>.ready(
|
return new AsyncReply<int>.ready(
|
||||||
data[offset] > 127 ? data[offset] - 256 : data[offset]);
|
data[offset] > 127 ? data[offset] - 256 : data[offset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply char16Parser(
|
static AsyncReply char16Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<String>.ready(data.getChar(offset));
|
return AsyncReply<String>.ready(data.getChar(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply char8Parser(
|
static AsyncReply char8Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return new AsyncReply<String>.ready(String.fromCharCode(data[offset]));
|
return new AsyncReply<String>.ready(String.fromCharCode(data[offset]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply int16Parser(
|
static AsyncReply int16Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<int>.ready(data.getInt16(offset));
|
return AsyncReply<int>.ready(data.getInt16(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply uInt16Parser(
|
static AsyncReply uInt16Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<int>.ready(data.getUint16(offset));
|
return AsyncReply<int>.ready(data.getUint16(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply int32Parser(
|
static AsyncReply int32Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<int>.ready(data.getInt32(offset));
|
return AsyncReply<int>.ready(data.getInt32(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply uInt32Parser(
|
static AsyncReply uInt32Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<int>.ready(data.getUint32(offset));
|
return AsyncReply<int>.ready(data.getUint32(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply float32Parser(
|
static AsyncReply float32Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<double>.ready(data.getFloat32(offset));
|
return AsyncReply<double>.ready(data.getFloat32(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply float64Parser(
|
static AsyncReply float64Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<double>.ready(data.getFloat64(offset));
|
return AsyncReply<double>.ready(data.getFloat64(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply float128Parser(
|
static AsyncReply float128Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
// @TODO
|
// @TODO
|
||||||
return AsyncReply<double>.ready(data.getFloat64(offset));
|
return AsyncReply<double>.ready(data.getFloat64(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply int128Parser(
|
static AsyncReply int128Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
// @TODO
|
// @TODO
|
||||||
return AsyncReply<int>.ready(data.getInt64(offset));
|
return AsyncReply<int>.ready(data.getInt64(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply uInt128Parser(
|
static AsyncReply uInt128Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<int>.ready(data.getUint64(offset));
|
return AsyncReply<int>.ready(data.getUint64(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply int64Parser(
|
static AsyncReply int64Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<int>.ready(data.getInt64(offset));
|
return AsyncReply<int>.ready(data.getInt64(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply uInt64Parser(
|
static AsyncReply uInt64Parser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<int>.ready(data.getUint64(offset));
|
return AsyncReply<int>.ready(data.getUint64(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply dateTimeParser(
|
static AsyncReply dateTimeParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return AsyncReply<DateTime>.ready(data.getDateTime(offset));
|
return AsyncReply<DateTime>.ready(data.getDateTime(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply resourceParser(
|
static AsyncReply resourceParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
var id = data.getUint32(offset);
|
var id = data.getUint32(offset);
|
||||||
return connection.fetch(id);
|
return connection.fetch(id, requestSequence);
|
||||||
}
|
}
|
||||||
throw Exception("Can't parse resource with no connection");
|
throw Exception("Can't parse resource with no connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply localResourceParser(
|
static AsyncReply localResourceParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
var id = data.getUint32(offset);
|
var id = data.getUint32(offset);
|
||||||
return Warehouse.getById(id);
|
return Warehouse.getById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply rawDataParser(
|
static AsyncReply rawDataParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return new AsyncReply<DC>.ready(data.clip(offset, length));
|
return new AsyncReply<DC>.ready(data.clip(offset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply stringParser(
|
static AsyncReply stringParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
return new AsyncReply<String>.ready(data.getString(offset, length));
|
return new AsyncReply<String>.ready(data.getString(offset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply recordParser(
|
static AsyncReply recordParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
var reply = new AsyncReply<IRecord>();
|
var reply = new AsyncReply<IRecord>();
|
||||||
|
|
||||||
var classId = data.getGuid(offset);
|
var classId = data.getGuid(offset);
|
||||||
@ -161,61 +161,54 @@ class DataDeserializer {
|
|||||||
|
|
||||||
var template = Warehouse.getTemplateByClassId(classId, TemplateType.Record);
|
var template = Warehouse.getTemplateByClassId(classId, TemplateType.Record);
|
||||||
|
|
||||||
|
var initRecord = (TypeTemplate template) =>
|
||||||
|
listParser(data, offset, length, connection, requestSequence).then((r) {
|
||||||
|
var ar = r as List;
|
||||||
|
IRecord record;
|
||||||
|
|
||||||
|
if (template.definedType != null) {
|
||||||
|
record = Warehouse.createInstance(template.definedType!) as IRecord;
|
||||||
|
} else {
|
||||||
|
record = Record();
|
||||||
|
}
|
||||||
|
|
||||||
|
var kv = Map<String, dynamic>();
|
||||||
|
|
||||||
|
for (var i = 0; i < template.properties.length; i++)
|
||||||
|
kv[template.properties[i].name] = ar[i];
|
||||||
|
|
||||||
|
record.deserialize(kv);
|
||||||
|
|
||||||
|
reply.trigger(record);
|
||||||
|
});
|
||||||
|
|
||||||
if (template != null) {
|
if (template != null) {
|
||||||
listParser(data, offset, length, connection).then((r) {
|
initRecord(template);
|
||||||
var ar = r as List;
|
|
||||||
IRecord record;
|
|
||||||
|
|
||||||
if (template.definedType != null) {
|
|
||||||
record = Warehouse.createInstance(template.definedType!) as IRecord;
|
|
||||||
} else {
|
|
||||||
record = Record();
|
|
||||||
}
|
|
||||||
|
|
||||||
var kv = Map<String, dynamic>();
|
|
||||||
|
|
||||||
for (var i = 0; i < template.properties.length; i++)
|
|
||||||
kv[template.properties[i].name] = ar[i];
|
|
||||||
|
|
||||||
record.deserialize(kv);
|
|
||||||
|
|
||||||
reply.trigger(record);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if (connection == null)
|
if (connection == null)
|
||||||
throw Exception("Can't parse record with no connection");
|
throw Exception("Can't parse record with no connection");
|
||||||
|
|
||||||
connection.getTemplate(classId).then((tmp) {
|
connection.getTemplate(classId).then((tmp) {
|
||||||
if (tmp == null)
|
if (tmp == null)
|
||||||
reply.triggerError(Exception("Couldn't fetch record template."));
|
reply.triggerError(AsyncException(
|
||||||
|
ErrorType.Management,
|
||||||
listParser(data, offset, length, connection).then((r) {
|
ExceptionCode.TemplateNotFound.index,
|
||||||
var ar = r as List;
|
"Template not found for record."));
|
||||||
|
else
|
||||||
var record = new Record();
|
initRecord(tmp);
|
||||||
|
|
||||||
var kv = Map<String, dynamic>();
|
|
||||||
|
|
||||||
for (var i = 0; i < tmp!.properties.length; i++)
|
|
||||||
kv[tmp.properties[i].name] = ar[i];
|
|
||||||
|
|
||||||
record.deserialize(kv);
|
|
||||||
|
|
||||||
reply.trigger(record);
|
|
||||||
});
|
|
||||||
}).error((x) => reply.triggerError(x));
|
}).error((x) => reply.triggerError(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply constantParser(
|
static AsyncReply constantParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
throw Exception("NotImplementedException");
|
throw Exception("NotImplementedException");
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply enumParser(
|
static AsyncReply enumParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
var classId = data.getGuid(offset);
|
var classId = data.getGuid(offset);
|
||||||
offset += 16;
|
offset += 16;
|
||||||
var index = data[offset++];
|
var index = data[offset++];
|
||||||
@ -258,12 +251,12 @@ class DataDeserializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply recordListParser(
|
static AsyncReply recordListParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
var rt = new AsyncBag();
|
var rt = new AsyncBag();
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
var parsed = Codec.parse(data, offset, connection);
|
var parsed = Codec.parse(data, offset, connection, requestSequence);
|
||||||
|
|
||||||
rt.add(parsed.reply);
|
rt.add(parsed.reply);
|
||||||
|
|
||||||
@ -278,12 +271,12 @@ class DataDeserializer {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply resourceListParser(
|
static AsyncReply resourceListParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
var rt = new AsyncBag();
|
var rt = new AsyncBag();
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
var parsed = Codec.parse(data, offset, connection);
|
var parsed = Codec.parse(data, offset, connection, requestSequence);
|
||||||
|
|
||||||
rt.add(parsed.reply);
|
rt.add(parsed.reply);
|
||||||
|
|
||||||
@ -298,12 +291,12 @@ class DataDeserializer {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncBag listParser(
|
static AsyncBag listParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
var rt = new AsyncBag();
|
var rt = new AsyncBag();
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
var parsed = Codec.parse(data, offset, connection);
|
var parsed = Codec.parse(data, offset, connection, requestSequence);
|
||||||
|
|
||||||
rt.add(parsed.reply);
|
rt.add(parsed.reply);
|
||||||
|
|
||||||
@ -318,8 +311,8 @@ class DataDeserializer {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply typedMapParser(
|
static AsyncReply typedMapParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
// get key type
|
// get key type
|
||||||
var keyRep = RepresentationType.parse(data, offset);
|
var keyRep = RepresentationType.parse(data, offset);
|
||||||
offset += keyRep.size;
|
offset += keyRep.size;
|
||||||
@ -329,15 +322,13 @@ class DataDeserializer {
|
|||||||
offset += valueRep.size;
|
offset += valueRep.size;
|
||||||
length -= valueRep.size;
|
length -= valueRep.size;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var map = Map();
|
var map = Map();
|
||||||
var rt = new AsyncReply();
|
var rt = new AsyncReply();
|
||||||
|
|
||||||
var results = new AsyncBag();
|
var results = new AsyncBag();
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
var parsed = Codec.parse(data, offset, connection);
|
var parsed = Codec.parse(data, offset, connection, requestSequence);
|
||||||
|
|
||||||
results.add(parsed.reply);
|
results.add(parsed.reply);
|
||||||
|
|
||||||
@ -359,8 +350,8 @@ class DataDeserializer {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply tupleParser(
|
static AsyncReply tupleParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
var results = new AsyncBag();
|
var results = new AsyncBag();
|
||||||
var rt = new AsyncReply();
|
var rt = new AsyncReply();
|
||||||
|
|
||||||
@ -377,7 +368,7 @@ class DataDeserializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
var parsed = Codec.parse(data, offset, connection);
|
var parsed = Codec.parse(data, offset, connection, requestSequence);
|
||||||
|
|
||||||
results.add(parsed.reply);
|
results.add(parsed.reply);
|
||||||
|
|
||||||
@ -397,8 +388,8 @@ class DataDeserializer {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AsyncReply typedListParser(
|
static AsyncReply typedListParser(DC data, int offset, int length,
|
||||||
DC data, int offset, int length, DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
var rt = new AsyncBag();
|
var rt = new AsyncBag();
|
||||||
|
|
||||||
// get the type
|
// get the type
|
||||||
@ -412,7 +403,7 @@ class DataDeserializer {
|
|||||||
rt.arrayType = runtimeType;
|
rt.arrayType = runtimeType;
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
var parsed = Codec.parse(data, offset, connection);
|
var parsed = Codec.parse(data, offset, connection, requestSequence);
|
||||||
|
|
||||||
rt.add(parsed.reply);
|
rt.add(parsed.reply);
|
||||||
|
|
||||||
@ -431,11 +422,12 @@ class DataDeserializer {
|
|||||||
DC data,
|
DC data,
|
||||||
int offset,
|
int offset,
|
||||||
int length,
|
int length,
|
||||||
DistributedConnection? connection) //, bool ageIncluded = true)
|
DistributedConnection? connection,
|
||||||
|
List<int>? requestSequence) //, bool ageIncluded = true)
|
||||||
{
|
{
|
||||||
var rt = new AsyncBag<PropertyValue>();
|
var rt = new AsyncBag<PropertyValue>();
|
||||||
|
|
||||||
listParser(data, offset, length, connection).then((x) {
|
listParser(data, offset, length, connection, requestSequence).then((x) {
|
||||||
var pvs = <PropertyValue>[];
|
var pvs = <PropertyValue>[];
|
||||||
|
|
||||||
for (var i = 0; i < x.length; i += 3)
|
for (var i = 0; i < x.length; i += 3)
|
||||||
@ -447,8 +439,11 @@ class DataDeserializer {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PropertyValueParserResults propertyValueParser(DC data, int offset,
|
static PropertyValueParserResults propertyValueParser(
|
||||||
DistributedConnection? connection) //, bool ageIncluded = true)
|
DC data,
|
||||||
|
int offset,
|
||||||
|
DistributedConnection? connection,
|
||||||
|
List<int>? requestSequence) //, bool ageIncluded = true)
|
||||||
{
|
{
|
||||||
var reply = new AsyncReply<PropertyValue>();
|
var reply = new AsyncReply<PropertyValue>();
|
||||||
|
|
||||||
@ -458,7 +453,7 @@ class DataDeserializer {
|
|||||||
DateTime date = data.getDateTime(offset);
|
DateTime date = data.getDateTime(offset);
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
|
||||||
var parsed = Codec.parse(data, offset, connection);
|
var parsed = Codec.parse(data, offset, connection, requestSequence);
|
||||||
|
|
||||||
parsed.reply.then((value) {
|
parsed.reply.then((value) {
|
||||||
reply.trigger(new PropertyValue(value, age, date));
|
reply.trigger(new PropertyValue(value, age, date));
|
||||||
@ -469,7 +464,7 @@ class DataDeserializer {
|
|||||||
|
|
||||||
static AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>
|
static AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>
|
||||||
historyParser(DC data, int offset, int length, IResource resource,
|
historyParser(DC data, int offset, int length, IResource resource,
|
||||||
DistributedConnection? connection) {
|
DistributedConnection? connection, List<int>? requestSequence) {
|
||||||
throw Exception("Not implemented");
|
throw Exception("Not implemented");
|
||||||
// @TODO
|
// @TODO
|
||||||
// var list = new KeyList<PropertyTemplate, List<PropertyValue>>();
|
// var list = new KeyList<PropertyTemplate, List<PropertyValue>>();
|
||||||
|
@ -69,6 +69,11 @@ class TransmissionType {
|
|||||||
this.offset, this.contentLength,
|
this.offset, this.contentLength,
|
||||||
[this.exponent = 0]);
|
[this.exponent = 0]);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return "Id: ${identifier}, Index: ${index}, Class: ${classType}, Offset: ${offset}, ContentLength: ${contentLength}, Exp: $exponent";
|
||||||
|
}
|
||||||
|
|
||||||
static DC compose(int identifier, DC data) {
|
static DC compose(int identifier, DC data) {
|
||||||
if (data.length == 0) return DC.fromList([identifier]);
|
if (data.length == 0) return DC.fromList([identifier]);
|
||||||
|
|
||||||
@ -168,7 +173,7 @@ class TransmissionType {
|
|||||||
int cl = (1 << (exp - 1));
|
int cl = (1 << (exp - 1));
|
||||||
|
|
||||||
if (ends - offset < cl)
|
if (ends - offset < cl)
|
||||||
return TransmissionTypeParseResults(ends - offset - cl, null);
|
return TransmissionTypeParseResults(cl - (ends - offset), null);
|
||||||
|
|
||||||
return TransmissionTypeParseResults(
|
return TransmissionTypeParseResults(
|
||||||
1 + cl, new TransmissionType(h, cls, h & 0x7, offset, cl, exp));
|
1 + cl, new TransmissionType(h, cls, h & 0x7, offset, cl, exp));
|
||||||
@ -176,12 +181,15 @@ class TransmissionType {
|
|||||||
int cll = (h >> 3) & 0x7;
|
int cll = (h >> 3) & 0x7;
|
||||||
|
|
||||||
if (ends - offset < cll)
|
if (ends - offset < cll)
|
||||||
return TransmissionTypeParseResults(ends - offset - cll, null);
|
return TransmissionTypeParseResults(cll - (ends - offset), null);
|
||||||
|
|
||||||
int cl = 0;
|
int cl = 0;
|
||||||
|
|
||||||
for (var i = 0; i < cll; i++) cl = cl << 8 | data[offset++];
|
for (var i = 0; i < cll; i++) cl = cl << 8 | data[offset++];
|
||||||
|
|
||||||
|
if (ends - offset < cl)
|
||||||
|
return TransmissionTypeParseResults(cl - (ends - offset), null);
|
||||||
|
|
||||||
return TransmissionTypeParseResults(
|
return TransmissionTypeParseResults(
|
||||||
1 + cl + cll, TransmissionType((h & 0xC7), cls, h & 0x7, offset, cl));
|
1 + cl + cll, TransmissionType((h & 0xC7), cls, h & 0x7, offset, cl));
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
|
|
||||||
KeyList<int, AsyncReply<DistributedResource>> _resourceRequests =
|
KeyList<int, AsyncReply<DistributedResource>> _resourceRequests =
|
||||||
new KeyList<int, AsyncReply<DistributedResource>>();
|
new KeyList<int, AsyncReply<DistributedResource>>();
|
||||||
|
|
||||||
KeyList<Guid, AsyncReply<TypeTemplate?>> _templateRequests =
|
KeyList<Guid, AsyncReply<TypeTemplate?>> _templateRequests =
|
||||||
new KeyList<Guid, AsyncReply<TypeTemplate?>>();
|
new KeyList<Guid, AsyncReply<TypeTemplate?>>();
|
||||||
//KeyList<String, AsyncReply<IResource>> _pathRequests = new KeyList<String, AsyncReply<IResource>>();
|
//KeyList<String, AsyncReply<IResource>> _pathRequests = new KeyList<String, AsyncReply<IResource>>();
|
||||||
@ -325,7 +326,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
for (var i = 0; i < _resources.keys.length; i++) {
|
for (var i = 0; i < _resources.keys.length; i++) {
|
||||||
var index = _resources.keys.elementAt(i);
|
var index = _resources.keys.elementAt(i);
|
||||||
// print("Re $i ${_resources[index].instance.template.className}");
|
// print("Re $i ${_resources[index].instance.template.className}");
|
||||||
bag.add(fetch(index));
|
bag.add(fetch(index, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
bag.seal();
|
bag.seal();
|
||||||
@ -461,7 +462,9 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
String? link(IResource resource) {
|
String? link(IResource resource) {
|
||||||
if (resource is DistributedResource) {
|
if (resource is DistributedResource) {
|
||||||
if (resource.instance?.store == this)
|
if (resource.instance?.store == this)
|
||||||
return (this.instance?.name ?? "") + "/" + resource.distributedResourceInstanceId.toString();
|
return (this.instance?.name ?? "") +
|
||||||
|
"/" +
|
||||||
|
resource.distributedResourceInstanceId.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -486,11 +489,11 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
var packet = new IIPPacket();
|
var packet = new IIPPacket();
|
||||||
|
|
||||||
if (_ready) {
|
if (_ready) {
|
||||||
print("Inc " + msg.length.toString());
|
//print("Inc " + msg.length.toString());
|
||||||
|
|
||||||
var rt = packet.parse(msg, offset, ends);
|
var rt = packet.parse(msg, offset, ends);
|
||||||
|
|
||||||
print("Packet " + packet.toString());
|
//print("Packet " + packet.toString());
|
||||||
|
|
||||||
if (rt <= 0) {
|
if (rt <= 0) {
|
||||||
// print("hold");
|
// print("hold");
|
||||||
@ -960,8 +963,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dataReceived(NetworkBuffer data) {
|
void dataReceived(NetworkBuffer data) {
|
||||||
print("dataReceived");
|
// print("dataReceived");
|
||||||
// Console.WriteLine("DR " + hostType + " " + data.Available + " " + RemoteEndPoint.ToString());
|
|
||||||
var msg = data.read();
|
var msg = data.read();
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
@ -996,7 +998,9 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
AsyncReply<bool> put(IResource resource) {
|
AsyncReply<bool> put(IResource resource) {
|
||||||
if (Codec.isLocalResource(resource, this))
|
if (Codec.isLocalResource(resource, this))
|
||||||
_resources.add(
|
_resources.add(
|
||||||
(resource as DistributedResource).distributedResourceInstanceId as int, resource);
|
(resource as DistributedResource).distributedResourceInstanceId
|
||||||
|
as int,
|
||||||
|
resource);
|
||||||
// else .. put it in the server....
|
// else .. put it in the server....
|
||||||
return AsyncReply.ready(true);
|
return AsyncReply.ready(true);
|
||||||
}
|
}
|
||||||
@ -1140,10 +1144,11 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
req?.trigger(results);
|
req?.trigger(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: check for deadlocks
|
||||||
void iipReplyInvoke(int callbackId, TransmissionType dataType, DC data) {
|
void iipReplyInvoke(int callbackId, TransmissionType dataType, DC data) {
|
||||||
var req = _requests.take(callbackId);
|
var req = _requests.take(callbackId);
|
||||||
|
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((rt) {
|
Codec.parse(data, 0, this, null, dataType).reply.then((rt) {
|
||||||
req?.trigger(rt);
|
req?.trigger(rt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1160,10 +1165,11 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
req?.triggerProgress(type, value, max);
|
req?.triggerProgress(type, value, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: Check for deadlocks
|
||||||
void iipReportChunk(int callbackId, TransmissionType dataType, DC data) {
|
void iipReportChunk(int callbackId, TransmissionType dataType, DC data) {
|
||||||
if (_requests.containsKey(callbackId)) {
|
if (_requests.containsKey(callbackId)) {
|
||||||
var req = _requests[callbackId];
|
var req = _requests[callbackId];
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((x) {
|
Codec.parse(data, 0, this, null, dataType).reply.then((x) {
|
||||||
req?.triggerChunk(x);
|
req?.triggerChunk(x);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1179,13 +1185,14 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: Check for deadlocks
|
||||||
void iipEventPropertyUpdated(
|
void iipEventPropertyUpdated(
|
||||||
int resourceId, int index, TransmissionType dataType, DC data) {
|
int resourceId, int index, TransmissionType dataType, DC data) {
|
||||||
fetch(resourceId).then((r) {
|
fetch(resourceId, null).then((r) {
|
||||||
var item = new AsyncReply<DistributedResourceQueueItem>();
|
var item = new AsyncReply<DistributedResourceQueueItem>();
|
||||||
_queue.add(item);
|
_queue.add(item);
|
||||||
|
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((arguments) {
|
Codec.parse(data, 0, this, null, dataType).reply.then((arguments) {
|
||||||
var pt = r.instance?.template.getPropertyTemplateByIndex(index);
|
var pt = r.instance?.template.getPropertyTemplateByIndex(index);
|
||||||
if (pt != null) {
|
if (pt != null) {
|
||||||
item.trigger(DistributedResourceQueueItem(
|
item.trigger(DistributedResourceQueueItem(
|
||||||
@ -1234,14 +1241,15 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: Check for deadlocks
|
||||||
void iipEventEventOccurred(
|
void iipEventEventOccurred(
|
||||||
int resourceId, int index, TransmissionType dataType, DC data) {
|
int resourceId, int index, TransmissionType dataType, DC data) {
|
||||||
fetch(resourceId).then((r) {
|
fetch(resourceId, null).then((r) {
|
||||||
// push to the queue to gaurantee serialization
|
// push to the queue to gaurantee serialization
|
||||||
var item = new AsyncReply<DistributedResourceQueueItem>();
|
var item = new AsyncReply<DistributedResourceQueueItem>();
|
||||||
_queue.add(item);
|
_queue.add(item);
|
||||||
|
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((arguments) {
|
Codec.parse(data, 0, this, null, dataType).reply.then((arguments) {
|
||||||
var et = r.instance?.template.getEventTemplateByIndex(index);
|
var et = r.instance?.template.getEventTemplateByIndex(index);
|
||||||
if (et != null) {
|
if (et != null) {
|
||||||
item.trigger(new DistributedResourceQueueItem(
|
item.trigger(new DistributedResourceQueueItem(
|
||||||
@ -1289,26 +1297,29 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: check for deadlocks
|
||||||
void iipEventChildAdded(int resourceId, int childId) {
|
void iipEventChildAdded(int resourceId, int childId) {
|
||||||
fetch(resourceId).then((parent) {
|
fetch(resourceId, null).then((parent) {
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
fetch(childId).then((child) {
|
fetch(childId, null).then((child) {
|
||||||
if (child != null) parent.instance?.children.add(child);
|
if (child != null) parent.instance?.children.add(child);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: check for deadlocks
|
||||||
void iipEventChildRemoved(int resourceId, int childId) {
|
void iipEventChildRemoved(int resourceId, int childId) {
|
||||||
fetch(resourceId).then((parent) {
|
fetch(resourceId, null).then((parent) {
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
fetch(childId).then((child) {
|
fetch(childId, null).then((child) {
|
||||||
if (child != null) parent.instance?.children.remove(child);
|
if (child != null) parent.instance?.children.remove(child);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: check for deadlocks
|
||||||
void iipEventRenamed(int resourceId, String name) {
|
void iipEventRenamed(int resourceId, String name) {
|
||||||
fetch(resourceId)
|
fetch(resourceId, null)
|
||||||
..then((resource) {
|
..then((resource) {
|
||||||
if (resource != null) {
|
if (resource != null) {
|
||||||
resource.instance?.attributes["name"] = name;
|
resource.instance?.attributes["name"] = name;
|
||||||
@ -1316,8 +1327,9 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: check for deadlocks
|
||||||
void iipEventAttributesUpdated(int resourceId, DC attributes) {
|
void iipEventAttributesUpdated(int resourceId, DC attributes) {
|
||||||
fetch(resourceId)
|
fetch(resourceId, null)
|
||||||
..then((resource) {
|
..then((resource) {
|
||||||
if (resource != null) {
|
if (resource != null) {
|
||||||
var attrs = attributes.getStringArray(0, attributes.length);
|
var attrs = attributes.getStringArray(0, attributes.length);
|
||||||
@ -1511,16 +1523,17 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataDeserializer.listParser(content, offset, cl, this)
|
// @TODO: check for deadlocks
|
||||||
|
DataDeserializer.listParser(content, offset, cl, this, null)
|
||||||
.then((parameters) {
|
.then((parameters) {
|
||||||
offset += cl;
|
offset += cl;
|
||||||
cl = content.getUint32(offset);
|
cl = content.getUint32(offset);
|
||||||
DataDeserializer.typedMapParser(content, offset, cl, this)
|
DataDeserializer.typedMapParser(content, offset, cl, this, null)
|
||||||
.then((attributes) {
|
.then((attributes) {
|
||||||
offset += cl;
|
offset += cl;
|
||||||
cl = content.length - offset;
|
cl = content.length - offset;
|
||||||
|
|
||||||
DataDeserializer.typedMapParser(content, offset, cl, this)
|
DataDeserializer.typedMapParser(content, offset, cl, this, null)
|
||||||
.then((values) {
|
.then((values) {
|
||||||
var constructors =
|
var constructors =
|
||||||
[]; //Type.GetType(className).GetTypeInfo().GetConstructors();
|
[]; //Type.GetType(className).GetTypeInfo().GetConstructors();
|
||||||
@ -1813,7 +1826,8 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataDeserializer.typedListParser(attributes, 0, attributes.length, this)
|
DataDeserializer.typedListParser(
|
||||||
|
attributes, 0, attributes.length, this, null)
|
||||||
.then((attrs) {
|
.then((attrs) {
|
||||||
if (r.instance?.setAttributes(
|
if (r.instance?.setAttributes(
|
||||||
attrs as Map<String, dynamic>, clearAttributes) ==
|
attrs as Map<String, dynamic>, clearAttributes) ==
|
||||||
@ -1947,11 +1961,12 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
|
|
||||||
void IIPRequestResourceAttribute(int callback, int resourceId) {}
|
void IIPRequestResourceAttribute(int callback, int resourceId) {}
|
||||||
|
|
||||||
|
// @TODO: Check for deadlocks
|
||||||
void iipRequestInvokeFunction(int callback, int resourceId, int index,
|
void iipRequestInvokeFunction(int callback, int resourceId, int index,
|
||||||
TransmissionType dataType, DC data) {
|
TransmissionType dataType, DC data) {
|
||||||
Warehouse.getById(resourceId).then((r) {
|
Warehouse.getById(resourceId).then((r) {
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((arguments) {
|
Codec.parse(data, 0, this, null, dataType).reply.then((arguments) {
|
||||||
var ft = r.instance?.template.getFunctionTemplateByIndex(index);
|
var ft = r.instance?.template.getFunctionTemplateByIndex(index);
|
||||||
if (ft != null) {
|
if (ft != null) {
|
||||||
if (r is DistributedResource) {
|
if (r is DistributedResource) {
|
||||||
@ -2160,13 +2175,14 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// @TODO: Check for deadlocks
|
||||||
void iipRequestSetProperty(int callback, int resourceId, int index,
|
void iipRequestSetProperty(int callback, int resourceId, int index,
|
||||||
TransmissionType dataType, DC data) {
|
TransmissionType dataType, DC data) {
|
||||||
Warehouse.getById(resourceId).then((r) {
|
Warehouse.getById(resourceId).then((r) {
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
var pt = r.instance?.template.getPropertyTemplateByIndex(index);
|
var pt = r.instance?.template.getPropertyTemplateByIndex(index);
|
||||||
if (pt != null) {
|
if (pt != null) {
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((value) {
|
Codec.parse(data, 0, this, null, dataType).reply.then((value) {
|
||||||
if (r is DistributedResource) {
|
if (r is DistributedResource) {
|
||||||
// propagation
|
// propagation
|
||||||
(r as DistributedResource).set(index, value).then<dynamic>((x) {
|
(r as DistributedResource).set(index, value).then<dynamic>((x) {
|
||||||
@ -2238,6 +2254,8 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
/// <param name="classId">Class GUID.</param>
|
/// <param name="classId">Class GUID.</param>
|
||||||
/// <returns>TypeTemplate.</returns>
|
/// <returns>TypeTemplate.</returns>
|
||||||
AsyncReply<TypeTemplate?> getTemplate(Guid classId) {
|
AsyncReply<TypeTemplate?> getTemplate(Guid classId) {
|
||||||
|
//Warehouse.getTemplateByClassId(classId)
|
||||||
|
|
||||||
if (_templates.containsKey(classId))
|
if (_templates.containsKey(classId))
|
||||||
return AsyncReply<TypeTemplate?>.ready(_templates[classId]);
|
return AsyncReply<TypeTemplate?>.ready(_templates[classId]);
|
||||||
else if (_templateRequests.containsKey(classId))
|
else if (_templateRequests.containsKey(classId))
|
||||||
@ -2338,99 +2356,110 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
/// <param name="classId">Class GUID</param>
|
/// <param name="classId">Class GUID</param>
|
||||||
/// <param name="id">Resource Id</param>Guid classId
|
/// <param name="id">Resource Id</param>Guid classId
|
||||||
/// <returns>DistributedResource</returns>
|
/// <returns>DistributedResource</returns>
|
||||||
AsyncReply<DistributedResource> fetch(int id) {
|
AsyncReply<DistributedResource> fetch(int id, List<int>? requestSequence) {
|
||||||
var resource = _resources[id];
|
var resource = _resources[id];
|
||||||
var request = _resourceRequests[id];
|
var request = _resourceRequests[id];
|
||||||
|
|
||||||
|
//print("fetch $id");
|
||||||
|
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
// dig for dead locks
|
if (resource != null && (requestSequence?.contains(id) ?? false))
|
||||||
if (resource != null) // dead lock
|
|
||||||
return AsyncReply<DistributedResource>.ready(resource);
|
return AsyncReply<DistributedResource>.ready(resource);
|
||||||
else
|
return request;
|
||||||
return request;
|
|
||||||
} else if (resource != null && !resource.distributedResourceSuspended)
|
} else if (resource != null && !resource.distributedResourceSuspended)
|
||||||
return new AsyncReply<DistributedResource>.ready(resource);
|
return new AsyncReply<DistributedResource>.ready(resource);
|
||||||
|
|
||||||
var reply = new AsyncReply<DistributedResource>();
|
var reply = new AsyncReply<DistributedResource>();
|
||||||
_resourceRequests.add(id, reply);
|
_resourceRequests.add(id, reply);
|
||||||
|
|
||||||
|
//print("AttachResource sent ${id}");
|
||||||
|
|
||||||
|
var newSequence =
|
||||||
|
requestSequence != null ? List<int>.from(requestSequence) : <int>[];
|
||||||
|
|
||||||
|
newSequence.add(id);
|
||||||
|
|
||||||
(sendRequest(IIPPacketAction.AttachResource)..addUint32(id)).done()
|
(sendRequest(IIPPacketAction.AttachResource)..addUint32(id)).done()
|
||||||
..then((rt) {
|
..then((rt) {
|
||||||
if (rt != null) {
|
//print("AttachResource rec ${id}");
|
||||||
// @TODO: Generator code
|
|
||||||
DistributedResource dr;
|
|
||||||
|
|
||||||
if (resource == null) {
|
// Resource not found (null)
|
||||||
var template = Warehouse.getTemplateByClassId(
|
if (rt == null) {
|
||||||
rt[0] as Guid, TemplateType.Wrapper);
|
//print("Null response");
|
||||||
if (template?.definedType != null) {
|
reply.triggerError(AsyncException(ErrorType.Management,
|
||||||
dr = Warehouse.createInstance(template?.definedType as Type);
|
ExceptionCode.ResourceNotFound.index, "Null response"));
|
||||||
dr.internal_init(this, id, rt[1] as int, rt[2] as String);
|
return;
|
||||||
} else {
|
}
|
||||||
dr = new DistributedResource();
|
|
||||||
dr.internal_init(this, id, rt[1] as int, rt[2] as String);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
dr = resource;
|
|
||||||
|
|
||||||
//var dr = resource ?? new DistributedResource(this, id, rt[1], rt[2]);
|
DistributedResource dr;
|
||||||
|
TypeTemplate? template;
|
||||||
|
|
||||||
TransmissionType transmissionType = rt[3] as TransmissionType;
|
Guid classId = rt[0] as Guid;
|
||||||
DC content = rt[4] as DC;
|
|
||||||
|
|
||||||
|
if (resource == null) {
|
||||||
|
template =
|
||||||
|
Warehouse.getTemplateByClassId(classId, TemplateType.Wrapper);
|
||||||
|
if (template?.definedType != null) {
|
||||||
|
dr = Warehouse.createInstance(template?.definedType as Type);
|
||||||
|
dr.internal_init(this, id, rt[1] as int, rt[2] as String);
|
||||||
|
} else {
|
||||||
|
dr = new DistributedResource();
|
||||||
|
dr.internal_init(this, id, rt[1] as int, rt[2] as String);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
dr = resource;
|
||||||
|
|
||||||
|
TransmissionType transmissionType = rt[3] as TransmissionType;
|
||||||
|
DC content = rt[4] as DC;
|
||||||
|
|
||||||
|
var initResource = (ok) {
|
||||||
|
print("parse req ${id}");
|
||||||
|
|
||||||
|
Codec.parse(content, 0, this, newSequence, transmissionType)
|
||||||
|
.reply
|
||||||
|
.then((results) {
|
||||||
|
//print("parsed ${id}");
|
||||||
|
|
||||||
|
var pvs = <PropertyValue>[];
|
||||||
|
var ar = results as List;
|
||||||
|
|
||||||
|
for (var i = 0; i < ar.length; i += 3)
|
||||||
|
pvs.add(new PropertyValue(
|
||||||
|
ar[i + 2], ar[i] as int, ar[i + 1] as DateTime));
|
||||||
|
|
||||||
|
dr.internal_attach(pvs);
|
||||||
|
|
||||||
|
_resourceRequests.remove(id);
|
||||||
|
reply.trigger(dr);
|
||||||
|
})
|
||||||
|
..error((ex) => reply.triggerError(ex));
|
||||||
|
};
|
||||||
|
|
||||||
|
if (template == null) {
|
||||||
|
//print("tmp == null");
|
||||||
getTemplate(rt[0] as Guid)
|
getTemplate(rt[0] as Guid)
|
||||||
..then((tmp) {
|
..then((tmp) {
|
||||||
//print("New template ");
|
|
||||||
|
|
||||||
// ClassId, ResourceAge, ResourceLink, Content
|
// ClassId, ResourceAge, ResourceLink, Content
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
Warehouse.put(id.toString(), dr, this, null, tmp)
|
Warehouse.put(id.toString(), dr, this, null, tmp)
|
||||||
..then((ok) {
|
..then(initResource)
|
||||||
Codec.parse(content, 0, this, transmissionType)
|
|
||||||
.reply
|
|
||||||
.then((results) {
|
|
||||||
var pvs = <PropertyValue>[];
|
|
||||||
var ar = results as List;
|
|
||||||
|
|
||||||
for (var i = 0; i < ar.length; i += 3)
|
|
||||||
pvs.add(new PropertyValue(
|
|
||||||
ar[i + 2], ar[i] as int, ar[i + 1] as DateTime));
|
|
||||||
|
|
||||||
dr.internal_attach(pvs);
|
|
||||||
|
|
||||||
_resourceRequests.remove(id);
|
|
||||||
reply.trigger(dr);
|
|
||||||
})
|
|
||||||
..error((ex) => reply.triggerError(ex));
|
|
||||||
})
|
|
||||||
..error((ex) => reply.triggerError(ex));
|
..error((ex) => reply.triggerError(ex));
|
||||||
} else {
|
} else {
|
||||||
Codec.parse(content, 0, this, transmissionType)
|
initResource(resource);
|
||||||
.reply
|
|
||||||
.then((results) {
|
|
||||||
//print("attached");
|
|
||||||
if (results != null) {
|
|
||||||
var pvs = <PropertyValue>[];
|
|
||||||
|
|
||||||
var ar = results as List;
|
|
||||||
for (var i = 0; i < ar.length; i += 3)
|
|
||||||
pvs.add(new PropertyValue(
|
|
||||||
ar[i + 2], ar[i] as int, ar[i + 1] as DateTime));
|
|
||||||
|
|
||||||
dr.internal_attach(pvs);
|
|
||||||
}
|
|
||||||
|
|
||||||
_resourceRequests.remove(id);
|
|
||||||
reply.trigger(dr);
|
|
||||||
})
|
|
||||||
..error((ex) => reply.triggerError(ex));
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
..error((ex) {
|
..error((ex) {
|
||||||
reply.triggerError(ex);
|
reply.triggerError(ex);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
reply.triggerError(Exception("Null response"));
|
//print("tmp != null");
|
||||||
|
if (resource == null) {
|
||||||
|
Warehouse.put(id.toString(), dr, this, null, template)
|
||||||
|
..then(initResource)
|
||||||
|
..error((ex) => reply.triggerError(ex));
|
||||||
|
} else {
|
||||||
|
initResource(resource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
..error((ex) {
|
..error((ex) {
|
||||||
@ -2440,6 +2469,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: Check for deadlocks
|
||||||
AsyncReply<List<IResource?>> getChildren(IResource resource) {
|
AsyncReply<List<IResource?>> getChildren(IResource resource) {
|
||||||
var rt = new AsyncReply<List<IResource?>>();
|
var rt = new AsyncReply<List<IResource?>>();
|
||||||
|
|
||||||
@ -2450,7 +2480,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
TransmissionType dataType = ar[0] as TransmissionType;
|
TransmissionType dataType = ar[0] as TransmissionType;
|
||||||
DC data = ar[1] as DC;
|
DC data = ar[1] as DC;
|
||||||
|
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((resources) {
|
Codec.parse(data, 0, this, null, dataType).reply.then((resources) {
|
||||||
rt.trigger(resources as List<IResource?>);
|
rt.trigger(resources as List<IResource?>);
|
||||||
})
|
})
|
||||||
..error((ex) => rt.triggerError(ex));
|
..error((ex) => rt.triggerError(ex));
|
||||||
@ -2462,6 +2492,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: Check for deadlocks
|
||||||
AsyncReply<List<IResource?>> getParents(IResource resource) {
|
AsyncReply<List<IResource?>> getParents(IResource resource) {
|
||||||
var rt = new AsyncReply<List<IResource?>>();
|
var rt = new AsyncReply<List<IResource?>>();
|
||||||
|
|
||||||
@ -2471,7 +2502,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
if (ar != null) {
|
if (ar != null) {
|
||||||
TransmissionType dataType = ar[0] as TransmissionType;
|
TransmissionType dataType = ar[0] as TransmissionType;
|
||||||
DC data = ar[1] as DC;
|
DC data = ar[1] as DC;
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((resources) {
|
Codec.parse(data, 0, this, null, dataType).reply.then((resources) {
|
||||||
rt.trigger(resources as List<IResource>);
|
rt.trigger(resources as List<IResource>);
|
||||||
})
|
})
|
||||||
..error((ex) => rt.triggerError(ex));
|
..error((ex) => rt.triggerError(ex));
|
||||||
@ -2524,6 +2555,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: Check for deadlocks
|
||||||
AsyncReply<Map<String, dynamic>> getAttributes(IResource resource,
|
AsyncReply<Map<String, dynamic>> getAttributes(IResource resource,
|
||||||
[List<String>? attributes = null]) {
|
[List<String>? attributes = null]) {
|
||||||
var rt = new AsyncReply<Map<String, dynamic>>();
|
var rt = new AsyncReply<Map<String, dynamic>>();
|
||||||
@ -2537,7 +2569,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
TransmissionType dataType = ar[0] as TransmissionType;
|
TransmissionType dataType = ar[0] as TransmissionType;
|
||||||
DC data = ar[1] as DC;
|
DC data = ar[1] as DC;
|
||||||
|
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((st) {
|
Codec.parse(data, 0, this, null, dataType).reply.then((st) {
|
||||||
resource.instance?.setAttributes(st as Map<String, dynamic>);
|
resource.instance?.setAttributes(st as Map<String, dynamic>);
|
||||||
rt.trigger(st as Map<String, dynamic>);
|
rt.trigger(st as Map<String, dynamic>);
|
||||||
})
|
})
|
||||||
@ -2560,7 +2592,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
TransmissionType dataType = ar[0] as TransmissionType;
|
TransmissionType dataType = ar[0] as TransmissionType;
|
||||||
DC data = ar[1] as DC;
|
DC data = ar[1] as DC;
|
||||||
|
|
||||||
Codec.parse(data, 0, this, dataType).reply
|
Codec.parse(data, 0, this, null, dataType).reply
|
||||||
..then((st) {
|
..then((st) {
|
||||||
resource.instance?.setAttributes(st as Map<String, dynamic>);
|
resource.instance?.setAttributes(st as Map<String, dynamic>);
|
||||||
|
|
||||||
@ -2606,7 +2638,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
var content = rt[0] as DC;
|
var content = rt[0] as DC;
|
||||||
|
|
||||||
DataDeserializer.historyParser(
|
DataDeserializer.historyParser(
|
||||||
content, 0, content.length, resource, this)
|
content, 0, content.length, resource, this, null)
|
||||||
.then((history) => reply.trigger(history));
|
.then((history) => reply.trigger(history));
|
||||||
} else {
|
} else {
|
||||||
reply.triggerError(Exception("Null response"));
|
reply.triggerError(Exception("Null response"));
|
||||||
@ -2624,6 +2656,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Link path.</param>
|
/// <param name="path">Link path.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
// @TODO: Check for deadlocks
|
||||||
AsyncReply<List<IResource?>> query(String path) {
|
AsyncReply<List<IResource?>> query(String path) {
|
||||||
var str = DC.stringToBytes(path);
|
var str = DC.stringToBytes(path);
|
||||||
var reply = new AsyncReply<List<IResource?>>();
|
var reply = new AsyncReply<List<IResource?>>();
|
||||||
@ -2636,7 +2669,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
TransmissionType dataType = ar[0] as TransmissionType;
|
TransmissionType dataType = ar[0] as TransmissionType;
|
||||||
DC data = ar[1] as DC;
|
DC data = ar[1] as DC;
|
||||||
|
|
||||||
Codec.parse(data, 0, this, dataType).reply.then((resources) =>
|
Codec.parse(data, 0, this, null, dataType).reply.then((resources) =>
|
||||||
reply.trigger((resources as List).cast<IResource?>()))
|
reply.trigger((resources as List).cast<IResource?>()))
|
||||||
..error((ex) => reply.triggerError(ex));
|
..error((ex) => reply.triggerError(ex));
|
||||||
} else {
|
} else {
|
||||||
@ -2680,7 +2713,7 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
if (args != null) {
|
if (args != null) {
|
||||||
var rid = args[0];
|
var rid = args[0];
|
||||||
|
|
||||||
fetch(rid as int).then((r) {
|
fetch(rid as int, null).then((r) {
|
||||||
reply.trigger(r);
|
reply.trigger(r);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -45,6 +45,8 @@ import '../Packets/IIPPacketAction.dart';
|
|||||||
|
|
||||||
import '../../Resource/Template/EventTemplate.dart';
|
import '../../Resource/Template/EventTemplate.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DistributedResource extends IResource {
|
class DistributedResource extends IResource {
|
||||||
int? _instanceId;
|
int? _instanceId;
|
||||||
DistributedConnection? _connection;
|
DistributedConnection? _connection;
|
||||||
@ -105,7 +107,7 @@ class DistributedResource extends IResource {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resource is attached when all its properties are received.
|
/// Resource is attached when all its properties are received.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool get attached => _attached;
|
bool get distributedResourceAttached => _attached;
|
||||||
|
|
||||||
// public DistributedResourceStack Stack
|
// public DistributedResourceStack Stack
|
||||||
//{
|
//{
|
||||||
|
@ -397,6 +397,13 @@ class IIPPacket {
|
|||||||
|
|
||||||
if (parsed.type == null) return -parsed.size;
|
if (parsed.type == null) return -parsed.size;
|
||||||
|
|
||||||
|
//print("Not enough ${parsed.size}");
|
||||||
|
|
||||||
|
// } else {
|
||||||
|
// print(
|
||||||
|
// "attach parsed ${parsed.size} ${cl} ${data.length} ${ends} ${offset}");
|
||||||
|
// }
|
||||||
|
|
||||||
dataType = parsed.type;
|
dataType = parsed.type;
|
||||||
offset += parsed.size;
|
offset += parsed.size;
|
||||||
} else if (action == IIPPacketAction.DetachResource) {
|
} else if (action == IIPPacketAction.DetachResource) {
|
||||||
|
@ -627,7 +627,7 @@ class TypeTemplate {
|
|||||||
|
|
||||||
offset += dt.size;
|
offset += dt.size;
|
||||||
|
|
||||||
var parsed = Codec.parse(data, offset, null);
|
var parsed = Codec.parse(data, offset, null, null);
|
||||||
|
|
||||||
offset += parsed.size;
|
offset += parsed.size;
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ class Warehouse {
|
|||||||
rt.add(TemplateType.Resource, new KeyList<Guid, TypeTemplate>());
|
rt.add(TemplateType.Resource, new KeyList<Guid, TypeTemplate>());
|
||||||
rt.add(TemplateType.Record, new KeyList<Guid, TypeTemplate>());
|
rt.add(TemplateType.Record, new KeyList<Guid, TypeTemplate>());
|
||||||
rt.add(TemplateType.Wrapper, new KeyList<Guid, TypeTemplate>());
|
rt.add(TemplateType.Wrapper, new KeyList<Guid, TypeTemplate>());
|
||||||
|
rt.add(TemplateType.Enum, new KeyList<Guid, TypeTemplate>());
|
||||||
|
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user