mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-05-06 04:02:57 +00:00
Annotations
This commit is contained in:
parent
0f52fec828
commit
437121f223
@ -1,14 +1,14 @@
|
|||||||
|
|
||||||
analyzer:
|
# analyzer:
|
||||||
exclude: [build/**]
|
# exclude: [build/**]
|
||||||
language:
|
# language:
|
||||||
strict-raw-types: true
|
# strict-raw-types: true
|
||||||
strict-casts: true
|
# strict-casts: true
|
||||||
strict-inference: true
|
# strict-inference: true
|
||||||
|
|
||||||
strong-mode:
|
# strong-mode:
|
||||||
implicit-casts: false
|
# implicit-casts: false
|
||||||
|
|
||||||
linter:
|
# linter:
|
||||||
rules:
|
# rules:
|
||||||
- cancel_subscriptions
|
# - cancel_subscriptions
|
||||||
|
@ -22,6 +22,8 @@ SOFTWARE.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
|
|
||||||
import '../../Data/IntType.dart';
|
import '../../Data/IntType.dart';
|
||||||
|
|
||||||
import '../../Data/DataDeserializer.dart';
|
import '../../Data/DataDeserializer.dart';
|
||||||
@ -126,7 +128,10 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
|
|
||||||
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<TypeTemplate?>> _templateByNameRequests =
|
||||||
|
new KeyList<String, AsyncReply<TypeTemplate?>>();
|
||||||
|
|
||||||
Map<Guid, TypeTemplate> _templates = new Map<Guid, TypeTemplate>();
|
Map<Guid, TypeTemplate> _templates = new Map<Guid, TypeTemplate>();
|
||||||
KeyList<int, AsyncReply<dynamic>> _requests =
|
KeyList<int, AsyncReply<dynamic>> _requests =
|
||||||
new KeyList<int, AsyncReply<dynamic>>();
|
new KeyList<int, AsyncReply<dynamic>>();
|
||||||
@ -2255,6 +2260,39 @@ class DistributedConnection extends NetworkConnection with IStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AsyncReply<TypeTemplate?> getTemplateByClassName(String className) {
|
||||||
|
var template =
|
||||||
|
_templates.values.firstWhereOrNull((x) => x.className == className);
|
||||||
|
if (template != null) return AsyncReply<TypeTemplate>.ready(template);
|
||||||
|
|
||||||
|
if (_templateByNameRequests.containsKey(className))
|
||||||
|
return _templateByNameRequests[className] as AsyncReply<TypeTemplate?>;
|
||||||
|
|
||||||
|
var reply = new AsyncReply<TypeTemplate?>();
|
||||||
|
_templateByNameRequests.add(className, reply);
|
||||||
|
|
||||||
|
var classNameBytes = DC.stringToBytes(className);
|
||||||
|
|
||||||
|
(sendRequest(IIPPacketAction.TemplateFromClassName)
|
||||||
|
..addUint8(classNameBytes.length)
|
||||||
|
..addDC(classNameBytes))
|
||||||
|
.done()
|
||||||
|
..then((rt) {
|
||||||
|
_templateByNameRequests.remove(className);
|
||||||
|
if (rt != null) {
|
||||||
|
_templates[(rt[0] as TypeTemplate).classId] = rt[0] as TypeTemplate;
|
||||||
|
Warehouse.putTemplate(rt[0] as TypeTemplate);
|
||||||
|
reply.trigger(rt[0]);
|
||||||
|
} else
|
||||||
|
reply.triggerError(Exception("Null response"));
|
||||||
|
})
|
||||||
|
..error((ex) {
|
||||||
|
reply.triggerError(ex);
|
||||||
|
});
|
||||||
|
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the TypeTemplate for a given class Id.
|
/// Get the TypeTemplate for a given class Id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -12,6 +12,56 @@ class TemplateGenerator {
|
|||||||
// static RegExp urlRegex = RegExp("^(?:([\S]*)://([^/]*)/?)");
|
// static RegExp urlRegex = RegExp("^(?:([\S]*)://([^/]*)/?)");
|
||||||
static final _urlRegex = RegExp(r'^(?:([^\s|:]*):\/\/([^\/]*)\/?(.*))');
|
static final _urlRegex = RegExp(r'^(?:([^\s|:]*):\/\/([^\/]*)\/?(.*))');
|
||||||
|
|
||||||
|
static String toLiteral(String? input) {
|
||||||
|
if (input == null) return "null";
|
||||||
|
|
||||||
|
String literal = "";
|
||||||
|
|
||||||
|
literal += "\"";
|
||||||
|
|
||||||
|
input.runes.forEach((int code) {
|
||||||
|
var c = String.fromCharCode(code);
|
||||||
|
switch (c) {
|
||||||
|
case '\"':
|
||||||
|
literal += "\\\"";
|
||||||
|
break;
|
||||||
|
case '\\':
|
||||||
|
literal += "\\\\";
|
||||||
|
break;
|
||||||
|
case '\0':
|
||||||
|
literal += "\\0";
|
||||||
|
break;
|
||||||
|
case '\a':
|
||||||
|
literal += "\\a";
|
||||||
|
break;
|
||||||
|
case '\b':
|
||||||
|
literal += "\\b";
|
||||||
|
break;
|
||||||
|
case '\f':
|
||||||
|
literal += "\\f";
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
literal += "\\n";
|
||||||
|
break;
|
||||||
|
case '\r':
|
||||||
|
literal += "\\r";
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
literal += "\\t";
|
||||||
|
break;
|
||||||
|
case '\v':
|
||||||
|
literal += "\\v";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
literal += c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
literal += "\"";
|
||||||
|
return literal;
|
||||||
|
}
|
||||||
|
|
||||||
static String generateRecord(
|
static String generateRecord(
|
||||||
TypeTemplate template, List<TypeTemplate> templates) {
|
TypeTemplate template, List<TypeTemplate> templates) {
|
||||||
var className = template.className.split('.').last;
|
var className = template.className.split('.').last;
|
||||||
@ -64,15 +114,15 @@ class TemplateGenerator {
|
|||||||
var descProps = template.properties //.where((p) => !p.inherited)
|
var descProps = template.properties //.where((p) => !p.inherited)
|
||||||
.map((p) {
|
.map((p) {
|
||||||
var ptTypeName = getTypeName(template, p.valueType, templates);
|
var ptTypeName = getTypeName(template, p.valueType, templates);
|
||||||
return "Prop('${p.name}', getTypeOf<${ptTypeName}>(), ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
|
return "Prop('${p.name}', getTypeOf<${ptTypeName}>(), ${_escape(p.readAnnotation)}, ${_escape(p.writeAnnotation)})";
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
if (parentName != null)
|
if (parentName != null)
|
||||||
rt.writeln("""@override
|
rt.writeln("""@override
|
||||||
TemplateDescriber get template => TemplateDescriber('${template.className}', parent: ${parentName}, properties: [${descProps}]);""");
|
TemplateDescriber get template => TemplateDescriber('${template.className}', parent: ${parentName}, properties: [${descProps}], annotation: ${toLiteral(template.annotation)});""");
|
||||||
else
|
else
|
||||||
rt.writeln("""@override
|
rt.writeln("""@override
|
||||||
TemplateDescriber get template => TemplateDescriber('${template.className}', properties: [${descProps}]);""");
|
TemplateDescriber get template => TemplateDescriber('${template.className}', properties: [${descProps}], annotation: ${toLiteral(template.annotation)});""");
|
||||||
|
|
||||||
rt.writeln("\r\n}");
|
rt.writeln("\r\n}");
|
||||||
|
|
||||||
@ -353,11 +403,11 @@ class TemplateGenerator {
|
|||||||
// add template
|
// add template
|
||||||
var descConsts = template.constants.map((p) {
|
var descConsts = template.constants.map((p) {
|
||||||
var ctTypeName = getTypeName(template, p.valueType, templates);
|
var ctTypeName = getTypeName(template, p.valueType, templates);
|
||||||
return "Const('${p.name}', getTypeOf<${ctTypeName}>(), ${p.value}, ${_escape(p.expansion)})";
|
return "Const('${p.name}', getTypeOf<${ctTypeName}>(), ${p.value}, ${_escape(p.annotation)})";
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
rt.writeln("""@override
|
rt.writeln("""@override
|
||||||
TemplateDescriber get template => TemplateDescriber('${template.className}', constants: [${descConsts}]);""");
|
TemplateDescriber get template => TemplateDescriber('${template.className}', constants: [${descConsts}], annotation: ${toLiteral(template.annotation)});""");
|
||||||
|
|
||||||
rt.writeln("\r\n}");
|
rt.writeln("\r\n}");
|
||||||
|
|
||||||
@ -469,7 +519,7 @@ class TemplateGenerator {
|
|||||||
var descProps = template.properties //.where((p) => !p.inherited)
|
var descProps = template.properties //.where((p) => !p.inherited)
|
||||||
.map((p) {
|
.map((p) {
|
||||||
var ptTypeName = getTypeName(template, p.valueType, templates);
|
var ptTypeName = getTypeName(template, p.valueType, templates);
|
||||||
return "Prop('${p.name}', getTypeOf<${ptTypeName}>(), ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
|
return "Prop('${p.name}', getTypeOf<${ptTypeName}>(), ${_escape(p.readAnnotation)}, ${_escape(p.writeAnnotation)})";
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
var descFuncs = template.functions //.where((f) => !f.inherited)
|
var descFuncs = template.functions //.where((f) => !f.inherited)
|
||||||
@ -481,22 +531,22 @@ class TemplateGenerator {
|
|||||||
return "Arg('${a.name}', getTypeOf<${atTypeName}>(), ${a.optional})";
|
return "Arg('${a.name}', getTypeOf<${atTypeName}>(), ${a.optional})";
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
return "Func('${f.name}', getTypeOf<${ftTypeName}>(), [${args}], ${_escape(f.expansion)})";
|
return "Func('${f.name}', getTypeOf<${ftTypeName}>(), [${args}], ${_escape(f.annotation)})";
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
var descEvents = template.events
|
var descEvents = template.events
|
||||||
//.where((e) => !e.inherited)
|
//.where((e) => !e.inherited)
|
||||||
.map((e) {
|
.map((e) {
|
||||||
var etTypeName = getTypeName(template, e.argumentType, templates);
|
var etTypeName = getTypeName(template, e.argumentType, templates);
|
||||||
return "Evt('${e.name}', getTypeOf<${etTypeName}>(), ${e.listenable}, ${_escape(e.expansion)})";
|
return "Evt('${e.name}', getTypeOf<${etTypeName}>(), ${e.listenable}, ${_escape(e.annotation)})";
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
if (parentName != null)
|
if (parentName != null)
|
||||||
rt.writeln(
|
rt.writeln(
|
||||||
"TemplateDescriber get template => TemplateDescriber('${template.className}', parent: ${parentName}, properties: [${descProps}], functions: [${descFuncs}], events: [$descEvents]);");
|
"TemplateDescriber get template => TemplateDescriber('${template.className}', parent: ${parentName}, properties: [${descProps}], functions: [${descFuncs}], events: [$descEvents], annotation: ${toLiteral(template.annotation)});");
|
||||||
else
|
else
|
||||||
rt.writeln(
|
rt.writeln(
|
||||||
"TemplateDescriber get template => TemplateDescriber('${template.className}', properties: [${descProps}], functions: [${descFuncs}], events: [$descEvents]);");
|
"TemplateDescriber get template => TemplateDescriber('${template.className}', properties: [${descProps}], functions: [${descFuncs}], events: [$descEvents], annotation: ${toLiteral(template.annotation)});");
|
||||||
|
|
||||||
rt.writeln("\r\n}");
|
rt.writeln("\r\n}");
|
||||||
|
|
||||||
|
@ -8,19 +8,19 @@ import 'TypeTemplate.dart';
|
|||||||
|
|
||||||
class ConstantTemplate extends MemberTemplate {
|
class ConstantTemplate extends MemberTemplate {
|
||||||
final dynamic value;
|
final dynamic value;
|
||||||
final String? expansion;
|
final String? annotation;
|
||||||
final RepresentationType valueType;
|
final RepresentationType valueType;
|
||||||
|
|
||||||
ConstantTemplate(TypeTemplate template, int index, String name,
|
ConstantTemplate(TypeTemplate template, int index, String name,
|
||||||
bool inherited, this.valueType, this.value, this.expansion)
|
bool inherited, this.valueType, this.value, this.annotation)
|
||||||
: super(template, index, name, inherited) {}
|
: super(template, index, name, inherited) {}
|
||||||
|
|
||||||
DC compose() {
|
DC compose() {
|
||||||
var name = super.compose();
|
var name = super.compose();
|
||||||
var hdr = inherited ? 0x80 : 0;
|
var hdr = inherited ? 0x80 : 0;
|
||||||
|
|
||||||
if (expansion != null) {
|
if (annotation != null) {
|
||||||
var exp = DC.stringToBytes(expansion!);
|
var exp = DC.stringToBytes(annotation!);
|
||||||
hdr |= 0x70;
|
hdr |= 0x70;
|
||||||
return (BinaryList()
|
return (BinaryList()
|
||||||
..addUint8(hdr)
|
..addUint8(hdr)
|
||||||
|
@ -6,7 +6,7 @@ import 'MemberType.dart';
|
|||||||
import '../../Data/RepresentationType.dart';
|
import '../../Data/RepresentationType.dart';
|
||||||
|
|
||||||
class EventTemplate extends MemberTemplate {
|
class EventTemplate extends MemberTemplate {
|
||||||
final String? expansion;
|
final String? annotation;
|
||||||
final bool listenable;
|
final bool listenable;
|
||||||
final RepresentationType argumentType;
|
final RepresentationType argumentType;
|
||||||
|
|
||||||
@ -17,8 +17,8 @@ class EventTemplate extends MemberTemplate {
|
|||||||
|
|
||||||
if (listenable) hdr |= 0x8;
|
if (listenable) hdr |= 0x8;
|
||||||
|
|
||||||
if (expansion != null) {
|
if (annotation != null) {
|
||||||
var exp = DC.stringToBytes(expansion as String);
|
var exp = DC.stringToBytes(annotation as String);
|
||||||
hdr |= 0x50;
|
hdr |= 0x50;
|
||||||
return (BinaryList()
|
return (BinaryList()
|
||||||
..addUint8(hdr)
|
..addUint8(hdr)
|
||||||
@ -41,6 +41,6 @@ class EventTemplate extends MemberTemplate {
|
|||||||
|
|
||||||
EventTemplate(TypeTemplate template, int index, String name, bool inherited,
|
EventTemplate(TypeTemplate template, int index, String name, bool inherited,
|
||||||
this.argumentType,
|
this.argumentType,
|
||||||
[this.expansion = null, this.listenable = false])
|
[this.annotation = null, this.listenable = false])
|
||||||
: super(template, index, name, inherited) {}
|
: super(template, index, name, inherited) {}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import 'ArgumentTemplate.dart';
|
|||||||
import '../../Data/RepresentationType.dart';
|
import '../../Data/RepresentationType.dart';
|
||||||
|
|
||||||
class FunctionTemplate extends MemberTemplate {
|
class FunctionTemplate extends MemberTemplate {
|
||||||
String? expansion;
|
String? annotation;
|
||||||
// bool isVoid;
|
// bool isVoid;
|
||||||
|
|
||||||
List<ArgumentTemplate> arguments;
|
List<ArgumentTemplate> arguments;
|
||||||
@ -24,8 +24,8 @@ class FunctionTemplate extends MemberTemplate {
|
|||||||
|
|
||||||
for (var i = 0; i < arguments.length; i++) bl.addDC(arguments[i].compose());
|
for (var i = 0; i < arguments.length; i++) bl.addDC(arguments[i].compose());
|
||||||
|
|
||||||
if (expansion != null) {
|
if (annotation != null) {
|
||||||
var exp = DC.stringToBytes(expansion as String);
|
var exp = DC.stringToBytes(annotation as String);
|
||||||
bl
|
bl
|
||||||
..addInt32(exp.length)
|
..addInt32(exp.length)
|
||||||
..addDC(exp);
|
..addDC(exp);
|
||||||
@ -38,6 +38,6 @@ class FunctionTemplate extends MemberTemplate {
|
|||||||
|
|
||||||
FunctionTemplate(TypeTemplate template, int index, String name,
|
FunctionTemplate(TypeTemplate template, int index, String name,
|
||||||
bool inherited, this.arguments, this.returnType,
|
bool inherited, this.arguments, this.returnType,
|
||||||
[this.expansion = null])
|
[this.annotation = null])
|
||||||
: super(template, index, name, inherited) {}
|
: super(template, index, name, inherited) {}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ class PropertyTemplate extends MemberTemplate {
|
|||||||
|
|
||||||
bool recordable;
|
bool recordable;
|
||||||
|
|
||||||
String? readExpansion;
|
String? readAnnotation;
|
||||||
|
|
||||||
String? writeExpansion;
|
String? writeAnnotation;
|
||||||
|
|
||||||
DC compose() {
|
DC compose() {
|
||||||
var name = super.compose();
|
var name = super.compose();
|
||||||
@ -23,9 +23,9 @@ class PropertyTemplate extends MemberTemplate {
|
|||||||
|
|
||||||
if (inherited) pv |= 0x80;
|
if (inherited) pv |= 0x80;
|
||||||
|
|
||||||
if (writeExpansion != null && readExpansion != null) {
|
if (writeAnnotation != null && readAnnotation != null) {
|
||||||
var rexp = DC.stringToBytes(readExpansion as String);
|
var rexp = DC.stringToBytes(readAnnotation as String);
|
||||||
var wexp = DC.stringToBytes(writeExpansion as String);
|
var wexp = DC.stringToBytes(writeAnnotation as String);
|
||||||
return (BinaryList()
|
return (BinaryList()
|
||||||
..addUint8(0x38 | pv)
|
..addUint8(0x38 | pv)
|
||||||
..addUint8(name.length)
|
..addUint8(name.length)
|
||||||
@ -36,8 +36,8 @@ class PropertyTemplate extends MemberTemplate {
|
|||||||
..addInt32(rexp.length)
|
..addInt32(rexp.length)
|
||||||
..addDC(rexp))
|
..addDC(rexp))
|
||||||
.toDC();
|
.toDC();
|
||||||
} else if (writeExpansion != null) {
|
} else if (writeAnnotation != null) {
|
||||||
var wexp = DC.stringToBytes(writeExpansion as String);
|
var wexp = DC.stringToBytes(writeAnnotation as String);
|
||||||
return (BinaryList()
|
return (BinaryList()
|
||||||
..addUint8(0x30 | pv)
|
..addUint8(0x30 | pv)
|
||||||
..addUint8(name.length)
|
..addUint8(name.length)
|
||||||
@ -46,8 +46,8 @@ class PropertyTemplate extends MemberTemplate {
|
|||||||
..addInt32(wexp.length)
|
..addInt32(wexp.length)
|
||||||
..addDC(wexp))
|
..addDC(wexp))
|
||||||
.toDC();
|
.toDC();
|
||||||
} else if (readExpansion != null) {
|
} else if (readAnnotation != null) {
|
||||||
var rexp = DC.stringToBytes(readExpansion as String);
|
var rexp = DC.stringToBytes(readAnnotation as String);
|
||||||
return (BinaryList()
|
return (BinaryList()
|
||||||
..addUint8(0x28 | pv)
|
..addUint8(0x28 | pv)
|
||||||
..addUint8(name.length)
|
..addUint8(name.length)
|
||||||
@ -67,8 +67,8 @@ class PropertyTemplate extends MemberTemplate {
|
|||||||
|
|
||||||
PropertyTemplate(TypeTemplate template, int index, String name,
|
PropertyTemplate(TypeTemplate template, int index, String name,
|
||||||
bool inherited, this.valueType,
|
bool inherited, this.valueType,
|
||||||
[this.readExpansion = null,
|
[this.readAnnotation = null,
|
||||||
this.writeExpansion = null,
|
this.writeAnnotation = null,
|
||||||
this.recordable = false])
|
this.recordable = false])
|
||||||
: super(template, index, name, inherited) {}
|
: super(template, index, name, inherited) {}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
class TemplateDescriber {
|
class TemplateDescriber {
|
||||||
final List<Prop>? properties;
|
final List<Prop>? properties;
|
||||||
final List<Evt>? events;
|
final List<Evt>? events;
|
||||||
@ -8,6 +7,7 @@ class TemplateDescriber {
|
|||||||
final String nameSpace;
|
final String nameSpace;
|
||||||
final int version;
|
final int version;
|
||||||
final Type? parent;
|
final Type? parent;
|
||||||
|
final String? annotation;
|
||||||
|
|
||||||
const TemplateDescriber(this.nameSpace,
|
const TemplateDescriber(this.nameSpace,
|
||||||
{this.parent,
|
{this.parent,
|
||||||
@ -15,7 +15,8 @@ class TemplateDescriber {
|
|||||||
this.functions,
|
this.functions,
|
||||||
this.events,
|
this.events,
|
||||||
this.constants,
|
this.constants,
|
||||||
this.version = 0});
|
this.version = 0,
|
||||||
|
this.annotation = null});
|
||||||
}
|
}
|
||||||
|
|
||||||
// class Property<T> {
|
// class Property<T> {
|
||||||
|
@ -26,6 +26,8 @@ class TypeTemplate {
|
|||||||
late Guid _classId;
|
late Guid _classId;
|
||||||
Guid? _parentId = null;
|
Guid? _parentId = null;
|
||||||
|
|
||||||
|
String? _annotation;
|
||||||
|
|
||||||
late String _className;
|
late String _className;
|
||||||
List<MemberTemplate> _members = [];
|
List<MemberTemplate> _members = [];
|
||||||
List<FunctionTemplate> _functions = [];
|
List<FunctionTemplate> _functions = [];
|
||||||
@ -40,6 +42,8 @@ class TypeTemplate {
|
|||||||
|
|
||||||
late DC _content;
|
late DC _content;
|
||||||
|
|
||||||
|
String? get annotation => _annotation;
|
||||||
|
|
||||||
DC get content => _content;
|
DC get content => _content;
|
||||||
|
|
||||||
TemplateType get type => _templateType;
|
TemplateType get type => _templateType;
|
||||||
@ -155,6 +159,8 @@ class TypeTemplate {
|
|||||||
|
|
||||||
_version = describer.version;
|
_version = describer.version;
|
||||||
|
|
||||||
|
_annotation = describer.annotation;
|
||||||
|
|
||||||
if (addToWarehouse) Warehouse.putTemplate(this);
|
if (addToWarehouse) Warehouse.putTemplate(this);
|
||||||
// _templates.add(template.classId, template);
|
// _templates.add(template.classId, template);
|
||||||
|
|
||||||
@ -253,10 +259,19 @@ class TypeTemplate {
|
|||||||
|
|
||||||
// bake it binarily
|
// bake it binarily
|
||||||
var b = BinaryList()
|
var b = BinaryList()
|
||||||
..addUint8(_templateType.index)
|
..addUint8((_annotation != null ? 0x40 : 0x0) | _templateType.index)
|
||||||
..addGuid(classId)
|
..addGuid(classId)
|
||||||
..addUint8(className.length)
|
..addUint8(className.length)
|
||||||
..addString(className)
|
..addString(className);
|
||||||
|
|
||||||
|
if (_annotation != null) {
|
||||||
|
var classAnnotationBytes = DC.stringToBytes(_annotation!);
|
||||||
|
b
|
||||||
|
..addUint16(classAnnotationBytes.length)
|
||||||
|
..addDC(classAnnotationBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
b
|
||||||
..addInt32(_version)
|
..addInt32(_version)
|
||||||
..addUint16(_members.length);
|
..addUint16(_members.length);
|
||||||
|
|
||||||
@ -267,219 +282,6 @@ class TypeTemplate {
|
|||||||
_content = b.toDC();
|
_content = b.toDC();
|
||||||
}
|
}
|
||||||
|
|
||||||
// static Guid getTypeGuid(Type type) => getTypeGuid(type.toString());
|
|
||||||
|
|
||||||
// static Guid getTypeGuid(String typeName)
|
|
||||||
// {
|
|
||||||
// var tn = Encoding.UTF8.GetBytes(typeName);
|
|
||||||
// var hash = SHA256.Create().ComputeHash(tn).Clip(0, 16);
|
|
||||||
|
|
||||||
// return new Guid(hash);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// static Type GetElementType(Type type) => type switch
|
|
||||||
// {
|
|
||||||
// { IsArray: true } => type.GetElementType(),
|
|
||||||
// { IsEnum: true } => type.GetEnumUnderlyingType(),
|
|
||||||
// (_) => type
|
|
||||||
// };
|
|
||||||
|
|
||||||
// static TypeTemplate[] GetRuntimeTypes(TypeTemplate template)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// List<TypeTemplate> list = [];
|
|
||||||
|
|
||||||
// list.add(template);
|
|
||||||
|
|
||||||
// var getRuntimeTypes = null;
|
|
||||||
|
|
||||||
// getRuntimeTypes = (TypeTemplate tmp, List<TypeTemplate> bag)
|
|
||||||
// {
|
|
||||||
// if (template.resourceType == null)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// // functions
|
|
||||||
// tmp.functions.foreach((f){
|
|
||||||
|
|
||||||
// var frtt = Warehouse.GetTemplate(getElementType(f.MethodInfo.ReturnType));
|
|
||||||
// if (frtt != null)
|
|
||||||
// {
|
|
||||||
// if (!bag.Contains(frtt))
|
|
||||||
// {
|
|
||||||
// list.Add(frtt);
|
|
||||||
// getRuntimeTypes(frtt, bag);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var args = f.MethodInfo.GetParameters();
|
|
||||||
|
|
||||||
// for(var i = 0; i < args.Length - 1; i++)
|
|
||||||
// {
|
|
||||||
// var fpt = Warehouse.GetTemplate(GetElementType(args[i].ParameterType));
|
|
||||||
// if (fpt != null)
|
|
||||||
// {
|
|
||||||
// if (!bag.Contains(fpt))
|
|
||||||
// {
|
|
||||||
// bag.Add(fpt);
|
|
||||||
// getRuntimeTypes(fpt, bag);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // skip DistributedConnection argument
|
|
||||||
// if (args.Length > 0)
|
|
||||||
// {
|
|
||||||
// var last = args.Last();
|
|
||||||
// if (last.ParameterType != typeof(DistributedConnection))
|
|
||||||
// {
|
|
||||||
// var fpt = Warehouse.GetTemplate(GetElementType(last.ParameterType));
|
|
||||||
// if (fpt != null)
|
|
||||||
// {
|
|
||||||
// if (!bag.Contains(fpt))
|
|
||||||
// {
|
|
||||||
// bag.Add(fpt);
|
|
||||||
// getRuntimeTypes(fpt, bag);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // properties
|
|
||||||
// foreach (var p in tmp.properties)
|
|
||||||
// {
|
|
||||||
// var pt = Warehouse.GetTemplate(GetElementType(p.PropertyInfo.PropertyType));
|
|
||||||
// if (pt != null)
|
|
||||||
// {
|
|
||||||
// if (!bag.Contains(pt))
|
|
||||||
// {
|
|
||||||
// bag.Add(pt);
|
|
||||||
// getRuntimeTypes(pt, bag);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // events
|
|
||||||
// foreach (var e in tmp.events)
|
|
||||||
// {
|
|
||||||
// var et = Warehouse.GetTemplate(GetElementType(e.EventInfo.EventHandlerType.GenericTypeArguments[0]));
|
|
||||||
|
|
||||||
// if (et != null)
|
|
||||||
// {
|
|
||||||
// if (!bag.Contains(et))
|
|
||||||
// {
|
|
||||||
// bag.Add(et);
|
|
||||||
// getRuntimeTypes(et, bag);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// getRuntimeTypes(template, list);
|
|
||||||
// return list.ToArray();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @TODO Create template from type
|
|
||||||
// TypeTemplate.fromType(Type type) {
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
/*
|
|
||||||
TypeTemplate(Type type)
|
|
||||||
{
|
|
||||||
|
|
||||||
type = ResourceProxy.GetBaseType(type);
|
|
||||||
|
|
||||||
// set guid
|
|
||||||
|
|
||||||
var typeName = Encoding.UTF8.GetBytes(type.FullName);
|
|
||||||
var hash = SHA256.Create().ComputeHash(typeName).Clip(0, 16);
|
|
||||||
|
|
||||||
classId = new Guid(hash);
|
|
||||||
className = type.FullName;
|
|
||||||
|
|
||||||
|
|
||||||
#if NETSTANDARD1_5
|
|
||||||
PropertyInfo[] propsInfo = type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
|
||||||
EventInfo[] eventsInfo = type.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
|
||||||
MethodInfo[] methodsInfo = type.GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
|
||||||
|
|
||||||
#else
|
|
||||||
PropertyInfo[] propsInfo = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
|
||||||
EventInfo[] eventsInfo = type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
|
||||||
MethodInfo[] methodsInfo = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//byte currentIndex = 0;
|
|
||||||
|
|
||||||
byte i = 0;
|
|
||||||
|
|
||||||
foreach (var pi in propsInfo)
|
|
||||||
{
|
|
||||||
var ps = (ResourceProperty[])pi.GetCustomAttributes(typeof(ResourceProperty), true);
|
|
||||||
if (ps.Length > 0)
|
|
||||||
{
|
|
||||||
var pt = new PropertyTemplate(this, i++, pi.Name, ps[0].ReadExpansion, ps[0].WriteExpansion, ps[0].Storage);
|
|
||||||
pt.Info = pi;
|
|
||||||
properties.Add(pt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
foreach (var ei in eventsInfo)
|
|
||||||
{
|
|
||||||
var es = (ResourceEvent[])ei.GetCustomAttributes(typeof(ResourceEvent), true);
|
|
||||||
if (es.Length > 0)
|
|
||||||
{
|
|
||||||
var et = new EventTemplate(this, i++, ei.Name, es[0].Expansion);
|
|
||||||
events.Add(et);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
foreach (MethodInfo mi in methodsInfo)
|
|
||||||
{
|
|
||||||
var fs = (ResourceFunction[])mi.GetCustomAttributes(typeof(ResourceFunction), true);
|
|
||||||
if (fs.Length > 0)
|
|
||||||
{
|
|
||||||
var ft = new FunctionTemplate(this, i++, mi.Name, mi.ReturnType == typeof(void), fs[0].Expansion);
|
|
||||||
functions.Add(ft);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// append signals
|
|
||||||
for (i = 0; i < events.Count; i++)
|
|
||||||
members.Add(events[i]);
|
|
||||||
// append slots
|
|
||||||
for (i = 0; i < functions.Count; i++)
|
|
||||||
members.Add(functions[i]);
|
|
||||||
// append properties
|
|
||||||
for (i = 0; i < properties.Count; i++)
|
|
||||||
members.Add(properties[i]);
|
|
||||||
|
|
||||||
// bake it binarily
|
|
||||||
var b = new BinaryList();
|
|
||||||
b.AddGuid(classId)
|
|
||||||
.AddUInt8((byte)className.Length)
|
|
||||||
.AddString(className)
|
|
||||||
.AddInt32(version)
|
|
||||||
.AddUInt16((ushort)members.Count);
|
|
||||||
|
|
||||||
|
|
||||||
foreach (var ft in functions)
|
|
||||||
b.AddUInt8Array(ft.Compose());
|
|
||||||
foreach (var pt in properties)
|
|
||||||
b.AddUInt8Array(pt.Compose());
|
|
||||||
foreach (var et in events)
|
|
||||||
b.AddUInt8Array(et.Compose());
|
|
||||||
|
|
||||||
content = b.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
TypeTemplate.parse(DC data, [int offset = 0, int? contentLength]) {
|
TypeTemplate.parse(DC data, [int offset = 0, int? contentLength]) {
|
||||||
// cool Dart feature
|
// cool Dart feature
|
||||||
contentLength ??= data.length;
|
contentLength ??= data.length;
|
||||||
@ -494,6 +296,7 @@ class TypeTemplate {
|
|||||||
_content = data.clip(offset, contentLength);
|
_content = data.clip(offset, contentLength);
|
||||||
|
|
||||||
var hasParent = (data.getUint8(offset) & 0x80) > 0;
|
var hasParent = (data.getUint8(offset) & 0x80) > 0;
|
||||||
|
var hasClassAnnotation = (data.getUint8(offset) & 0x40) > 0;
|
||||||
|
|
||||||
_templateType = TemplateType.values[data.getUint8(offset++) & 0xF];
|
_templateType = TemplateType.values[data.getUint8(offset++) & 0xF];
|
||||||
|
|
||||||
@ -502,11 +305,22 @@ class TypeTemplate {
|
|||||||
_className = data.getString(offset + 1, data[offset]);
|
_className = data.getString(offset + 1, data[offset]);
|
||||||
offset += data[offset] + 1;
|
offset += data[offset] + 1;
|
||||||
|
|
||||||
|
//print(" annotation : ${_className} ${hasAnnotation}");
|
||||||
|
|
||||||
if (hasParent) {
|
if (hasParent) {
|
||||||
_parentId = data.getGuid(offset);
|
_parentId = data.getGuid(offset);
|
||||||
offset += 16;
|
offset += 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasClassAnnotation) {
|
||||||
|
var len = data.getUint16(offset);
|
||||||
|
offset += 2;
|
||||||
|
_annotation = data.getString(offset, len);
|
||||||
|
offset += len;
|
||||||
|
|
||||||
|
//print("Has annotation ${_annotation}");
|
||||||
|
}
|
||||||
|
|
||||||
_version = data.getInt32(offset);
|
_version = data.getInt32(offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
@ -524,8 +338,8 @@ class TypeTemplate {
|
|||||||
|
|
||||||
if (type == 0) // function
|
if (type == 0) // function
|
||||||
{
|
{
|
||||||
String? expansion = null;
|
String? annotation = null;
|
||||||
var hasExpansion = ((data[offset++] & 0x10) == 0x10);
|
var hasAnnotation = ((data[offset++] & 0x10) == 0x10);
|
||||||
|
|
||||||
var name = data.getString(offset + 1, data[offset]);
|
var name = data.getString(offset + 1, data[offset]);
|
||||||
offset += data[offset] + 1;
|
offset += data[offset] + 1;
|
||||||
@ -543,24 +357,24 @@ class TypeTemplate {
|
|||||||
offset += art.size;
|
offset += art.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasExpansion) // expansion ?
|
if (hasAnnotation) // annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.getUint32(offset);
|
var cs = data.getUint32(offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
expansion = data.getString(offset, cs);
|
annotation = data.getString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ft = new FunctionTemplate(this, functionIndex++, name, inherited,
|
var ft = new FunctionTemplate(this, functionIndex++, name, inherited,
|
||||||
arguments, dt.type, expansion);
|
arguments, dt.type, annotation);
|
||||||
|
|
||||||
_functions.add(ft);
|
_functions.add(ft);
|
||||||
} else if (type == 1) // property
|
} else if (type == 1) // property
|
||||||
{
|
{
|
||||||
String? readExpansion = null, writeExpansion = null;
|
String? readAnnotation = null, writeAnnotation = null;
|
||||||
|
|
||||||
var hasReadExpansion = ((data[offset] & 0x8) == 0x8);
|
var hasReadAnnotation = ((data[offset] & 0x8) == 0x8);
|
||||||
var hasWriteExpansion = ((data[offset] & 0x10) == 0x10);
|
var hasWriteAnnotation = ((data[offset] & 0x10) == 0x10);
|
||||||
var recordable = ((data[offset] & 1) == 1);
|
var recordable = ((data[offset] & 1) == 1);
|
||||||
var permission = (data[offset++] >> 1) & 0x3;
|
var permission = (data[offset++] >> 1) & 0x3;
|
||||||
var name = data.getString(offset + 1, data[offset]);
|
var name = data.getString(offset + 1, data[offset]);
|
||||||
@ -571,30 +385,30 @@ class TypeTemplate {
|
|||||||
|
|
||||||
offset += dt.size;
|
offset += dt.size;
|
||||||
|
|
||||||
if (hasReadExpansion) // expansion ?
|
if (hasReadAnnotation) // annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.getUint32(offset);
|
var cs = data.getUint32(offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
readExpansion = data.getString(offset, cs);
|
readAnnotation = data.getString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasWriteExpansion) // expansion ?
|
if (hasWriteAnnotation) // annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.getUint32(offset);
|
var cs = data.getUint32(offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
writeExpansion = data.getString(offset, cs);
|
writeAnnotation = data.getString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pt = new PropertyTemplate(this, propertyIndex++, name, inherited,
|
var pt = new PropertyTemplate(this, propertyIndex++, name, inherited,
|
||||||
dt.type, readExpansion, writeExpansion, recordable);
|
dt.type, readAnnotation, writeAnnotation, recordable);
|
||||||
|
|
||||||
_properties.add(pt);
|
_properties.add(pt);
|
||||||
} else if (type == 2) // Event
|
} else if (type == 2) // Event
|
||||||
{
|
{
|
||||||
String? expansion = null;
|
String? annotation = null;
|
||||||
var hasExpansion = ((data[offset] & 0x10) == 0x10);
|
var hasAnnotation = ((data[offset] & 0x10) == 0x10);
|
||||||
var listenable = ((data[offset++] & 0x8) == 0x8);
|
var listenable = ((data[offset++] & 0x8) == 0x8);
|
||||||
|
|
||||||
var name = data.getString(offset + 1, data[offset]);
|
var name = data.getString(offset + 1, data[offset]);
|
||||||
@ -604,21 +418,21 @@ class TypeTemplate {
|
|||||||
|
|
||||||
offset += dt.size;
|
offset += dt.size;
|
||||||
|
|
||||||
if (hasExpansion) // expansion ?
|
if (hasAnnotation) // annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.getUint32(offset);
|
var cs = data.getUint32(offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
expansion = data.getString(offset, cs);
|
annotation = data.getString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var et = new EventTemplate(this, eventIndex++, name, inherited, dt.type,
|
var et = new EventTemplate(this, eventIndex++, name, inherited, dt.type,
|
||||||
expansion, listenable);
|
annotation, listenable);
|
||||||
|
|
||||||
_events.add(et);
|
_events.add(et);
|
||||||
} else if (type == 3) {
|
} else if (type == 3) {
|
||||||
String? expansion = null;
|
String? annotation = null;
|
||||||
var hasExpansion = ((data[offset++] & 0x10) == 0x10);
|
var hasAnnotation = ((data[offset++] & 0x10) == 0x10);
|
||||||
|
|
||||||
var name = data.getString(offset + 1, data[offset]);
|
var name = data.getString(offset + 1, data[offset]);
|
||||||
offset += data[offset] + 1;
|
offset += data[offset] + 1;
|
||||||
@ -631,16 +445,16 @@ class TypeTemplate {
|
|||||||
|
|
||||||
offset += parsed.size;
|
offset += parsed.size;
|
||||||
|
|
||||||
if (hasExpansion) // expansion ?
|
if (hasAnnotation) // annotation ?
|
||||||
{
|
{
|
||||||
var cs = data.getUint32(offset);
|
var cs = data.getUint32(offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
expansion = data.getString(offset, cs);
|
annotation = data.getString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ct = new ConstantTemplate(this, constantIndex++, name, inherited,
|
var ct = new ConstantTemplate(this, constantIndex++, name, inherited,
|
||||||
dt.type, parsed.reply.result, expansion);
|
dt.type, parsed.reply.result, annotation);
|
||||||
|
|
||||||
_constants.add(ct);
|
_constants.add(ct);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: esiur
|
name: esiur
|
||||||
description: Distributed Object Framework.
|
description: Distributed Object Framework.
|
||||||
version: 2.0.2
|
version: 2.0.3
|
||||||
#author: Ahmed Zamil <ahmed@esiur.com>
|
#author: Ahmed Zamil <ahmed@esiur.com>
|
||||||
homepage: https://github.com/esiur/esiur-dart
|
homepage: https://github.com/esiur/esiur-dart
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user