From fffce4d5953f9d479afd822ddc4e23d352a4d3a2 Mon Sep 17 00:00:00 2001 From: Esiur Project Date: Thu, 16 Jun 2022 04:51:43 +0300 Subject: [PATCH] Annotations --- src/Net/IIP/DistributedConnection.js | 31 ++++++++++ src/Net/IIP/DistributedResource.js | 4 +- src/Resource/Template/ConstantTemplate.js | 11 ++-- src/Resource/Template/EventTemplate.js | 8 +-- src/Resource/Template/FunctionTemplate.js | 8 +-- src/Resource/Template/PropertyTemplate.js | 20 +++---- src/Resource/Template/TypeTemplate.js | 73 ++++++++++++++--------- 7 files changed, 101 insertions(+), 54 deletions(-) diff --git a/src/Net/IIP/DistributedConnection.js b/src/Net/IIP/DistributedConnection.js index 59011f5..0784068 100644 --- a/src/Net/IIP/DistributedConnection.js +++ b/src/Net/IIP/DistributedConnection.js @@ -124,6 +124,7 @@ export default class DistributedConnection extends IStore { this.requests = new KeyList();// {}; //this.pathRequests = new KeyList();// {}; this.templateRequests = new KeyList(); + this.templateByNameRequests = new KeyList(); this.resourceRequests = new KeyList();// {}; this.callbackCounter = 0; @@ -2260,6 +2261,36 @@ export default class DistributedConnection extends IStore { return reply; } + getTemplateByClassName(className) { + + let template = this.templates.find((x)=>x.className == className); + if (template != null) + return new AsyncReply(template); + + else if (this.templateByNameRequests.contains(className)) + return this.templateByNameRequests.item(className); + + var reply = new AsyncReply(); + this.templateByNameRequests.add(className, reply); + + var self = this; + + let classNameBytes = DC.stringToBytes(className); + + this.sendRequest(IIPPacketAction.TemplateFromClassName) + .addUint8(classNameBytes.length) + .addUint8Array(classNameBytes) + .done() + .then(function (rt) { + self.templateByNameRequests.remove(className); + self.templates.add(rt[0].classId.valueOf(), rt[0]); + Warehouse.putTemplate(rt[0]); + reply.trigger(rt[0]); + }); + + return reply; + } + getTemplate(classId) { if (this.templates.contains(classId)) return new AsyncReply(this.templates.item(classId)); diff --git a/src/Net/IIP/DistributedResource.js b/src/Net/IIP/DistributedResource.js index 7755a8f..a42057f 100644 --- a/src/Net/IIP/DistributedResource.js +++ b/src/Net/IIP/DistributedResource.js @@ -145,8 +145,8 @@ export default class DistributedResource extends IResource } }; - // get expansion - func.help = self.instance.template.functions[ft.index].expansion; + // get annotation + func.help = self.instance.template.functions[ft.index].annotation; return func; }; diff --git a/src/Resource/Template/ConstantTemplate.js b/src/Resource/Template/ConstantTemplate.js index 0e9c545..14dbafb 100644 --- a/src/Resource/Template/ConstantTemplate.js +++ b/src/Resource/Template/ConstantTemplate.js @@ -3,24 +3,21 @@ import MemberTemplate from './MemberTemplate.js'; import Codec from '../../Data/Codec.js'; export default class ConstantTemplate extends MemberTemplate { - //final dynamic value; - //final String? expansion; - //final RepresentationType valueType; constructor(template, index, name, - inherited, valueType, value, expansion){ + inherited, valueType, value, annotation){ super(template, index, name, inherited) ; this.valueType = valueType; this.value = value; - this.expansion = expansion; + this.annotation = annotation; } compose() { var name = super.compose(); var hdr = this.inherited ? 0x80 : 0; - if (this.expansion != null) { - var exp = DC.stringToBytes(this.expansion); + if (this.annotation != null) { + var exp = DC.stringToBytes(this.annotation); hdr |= 0x70; return (BL() .addUint8(hdr) diff --git a/src/Resource/Template/EventTemplate.js b/src/Resource/Template/EventTemplate.js index 5f40edf..291a236 100644 --- a/src/Resource/Template/EventTemplate.js +++ b/src/Resource/Template/EventTemplate.js @@ -39,8 +39,8 @@ export default class EventTemplate extends MemberTemplate { if (this.listenable) hdr |= 0x8; - if (this.expansion != null) { - let exp = DC.stringToBytes(this.expansion); + if (this.annotation != null) { + let exp = DC.stringToBytes(this.annotation); hdr |= 0x50; return (BL() .addUint8(hdr) @@ -62,11 +62,11 @@ export default class EventTemplate extends MemberTemplate { } constructor(template, index, name, inherited, argumentType, - expansion = null, listenable = false) + annotation = null, listenable = false) { super(template, index, name, inherited) ; this.argumentType = argumentType; - this.expansion = expansion; + this.annotation = annotation; this.listenable = listenable; } diff --git a/src/Resource/Template/FunctionTemplate.js b/src/Resource/Template/FunctionTemplate.js index 7b8b816..ae9fd11 100644 --- a/src/Resource/Template/FunctionTemplate.js +++ b/src/Resource/Template/FunctionTemplate.js @@ -41,8 +41,8 @@ export default class FunctionTemplate extends MemberTemplate { for (var i = 0; i < this.args.length; i++) bl.addDC(this.args[i].compose()); - if (this.expansion != null) { - var exp = DC.stringToBytes(this.expansion); + if (this.annotation != null) { + var exp = DC.stringToBytes(this.annotation); bl .addInt32(exp.length) .addDC(exp); @@ -53,11 +53,11 @@ export default class FunctionTemplate extends MemberTemplate { return bl.toDC(); } - constructor(template, index, name, inherited, args, returnType, expansion = null){ + constructor(template, index, name, inherited, args, returnType, annotation = null){ super(template, index, name, inherited); this.args = args; this.returnType = returnType; - this.expansion = expansion; + this.annotation = annotation; } } diff --git a/src/Resource/Template/PropertyTemplate.js b/src/Resource/Template/PropertyTemplate.js index 79f9e2b..d175ba3 100644 --- a/src/Resource/Template/PropertyTemplate.js +++ b/src/Resource/Template/PropertyTemplate.js @@ -35,9 +35,9 @@ export default class PropertyTemplate extends MemberTemplate { if (this.inherited) pv |= 0x80; - if (this.writeExpansion != null && this.readExpansion != null) { - let rexp = DC.stringToBytes(this.readExpansion); - let wexp = DC.stringToBytes(this.writeExpansion); + if (this.writeAnnotation != null && this.readAnnotation != null) { + let rexp = DC.stringToBytes(this.readAnnotation); + let wexp = DC.stringToBytes(this.writeAnnotation); return (BL() .addUint8(0x38 | pv) .addUint8(name.length) @@ -48,8 +48,8 @@ export default class PropertyTemplate extends MemberTemplate { .addInt32(rexp.length) .addDC(rexp)) .toDC(); - } else if (this.writeExpansion != null) { - let wexp = DC.stringToBytes(this.writeExpansion); + } else if (this.writeAnnotation != null) { + let wexp = DC.stringToBytes(this.writeAnnotation); return (BL() .addUint8(0x30 | pv) .addUint8(name.length) @@ -58,8 +58,8 @@ export default class PropertyTemplate extends MemberTemplate { .addInt32(wexp.length) .addDC(wexp)) .toDC(); - } else if (this.readExpansion != null) { - let rexp = DC.stringToBytes(this.readExpansion); + } else if (this.readAnnotation != null) { + let rexp = DC.stringToBytes(this.readAnnotation); return (BL() .addUint8(0x28 | pv) .addUint8(name.length) @@ -78,12 +78,12 @@ export default class PropertyTemplate extends MemberTemplate { } constructor(template, index, name, - inherited, valueType, readExpansion = null, writeExpansion = null, recordable = false) + inherited, valueType, readAnnotation = null, writeAnnotation = null, recordable = false) { super(template, index, name, inherited); this.valueType = valueType; - this.readExpansion = readExpansion; - this.writeExpansion = writeExpansion; + this.readAnnotation = readAnnotation; + this.writeAnnotation = writeAnnotation; this.recordable = recordable; } } diff --git a/src/Resource/Template/TypeTemplate.js b/src/Resource/Template/TypeTemplate.js index 5a0dbff..098578c 100644 --- a/src/Resource/Template/TypeTemplate.js +++ b/src/Resource/Template/TypeTemplate.js @@ -344,13 +344,24 @@ export default class TypeTemplate { this.members.push(this.constants[i]); // bake it binarily - var b = BL(); + let b = BL(); + let hasClassAnnotation = template.annotation != null; + var cls = DC.stringToBytes(this.className); - b.addUint8(this.templateType) + b.addUint8( (hasClassAnnotation ? 0x40 : 0 ) | this.templateType) .addUint8Array(this.classId.value) .addUint8(cls.length) - .addUint8Array(cls) - .addUint32(template.version) + .addUint8Array(cls); + + if (hasClassAnnotation) + { + var classAnnotationBytes = DC.stringToBytes(template.annotation); + b.addUint16(classAnnotationBytes.length) + .addUint8Array(classAnnotationBytes); + this.annotation = template.annotation; + } + + b.addUint32(template.version) .addUint16(this.members.length); for (let i = 0; i < this.functions.length; i++) @@ -400,6 +411,7 @@ export default class TypeTemplate { od.content = data.clip(offset, contentLength); let hasParent = (data.getUint8(offset) & 0x80) > 0; + let hasClassAnnotation = (data.getUint8(offset) & 0x40) > 0; od.templateType = data.getUint8(offset++) & 0xF; @@ -414,6 +426,13 @@ export default class TypeTemplate { offset += 16; } + if (hasClassAnnotation) { + let len = data.getUint16(offset); + offset += 2; + od.annotation = data.getString(offset, len); + offset += len; + } + od.version = data.getInt32(offset); offset += 4; @@ -432,8 +451,8 @@ export default class TypeTemplate { if (type == 0) // function { - let expansion = null; - let hasExpansion = ((data.getUint8(offset++) & 0x10) == 0x10); + let annotation = null; + let hasAnnotation = ((data.getUint8(offset++) & 0x10) == 0x10); let len = data.getUint8(offset++); let name = data.getString(offset, len); @@ -457,25 +476,25 @@ export default class TypeTemplate { offset += argSize; } - if (hasExpansion) // expansion ? + if (hasAnnotation) // annotation ? { var cs = data.getUint32(offset); offset += 4; - expansion = data.getString(offset, cs); + annotation = data.getString(offset, cs); offset += cs; } let ft = new FunctionTemplate(od, functionIndex++, name, inherited, - args, dt.type, expansion); + args, dt.type, annotation); od.functions.push(ft); } else if (type == 1) // property { - let hasReadExpansion = ((data.getUint8(offset) & 0x8) == 0x8); - let hasWriteExpansion = ((data.getUint8(offset) & 0x10) == 0x10); - let readExpansion, writeExpansion; + let hasReadAnnotation = ((data.getUint8(offset) & 0x8) == 0x8); + let hasWriteAnnotation = ((data.getUint8(offset) & 0x10) == 0x10); + let readAnnotation, writeAnnotation; let recordable = ((data.getUint8(offset) & 1) == 1); let permission = ((data.getUint8(offset++) >> 1) & 0x3); let len = data.getUint8(offset++); @@ -486,33 +505,33 @@ export default class TypeTemplate { offset += dt.size; - if (hasReadExpansion) // expansion ? + if (hasReadAnnotation) // annotation ? { let cs = data.getUint32(offset); offset += 4; - readExpansion = data.getString(offset, cs); + readAnnotation = data.getString(offset, cs); offset += cs; } - if (hasWriteExpansion) // expansion ? + if (hasWriteAnnotation) // annotation ? { let cs = data.getUint32(offset); offset += 4; - writeExpansion = data.getString(offset, cs); + writeAnnotation = data.getString(offset, cs); offset += cs; } - let pt = new PropertyTemplate(od, propertyIndex++, name, inherited, dt.type, readExpansion, writeExpansion, recordable); + let pt = new PropertyTemplate(od, propertyIndex++, name, inherited, dt.type, readAnnotation, writeAnnotation, recordable); od.properties.push(pt); } else if (type == 2) // Event { - let hasExpansion = ((data.getUint8(offset) & 0x10) == 0x10); + let hasAnnotation = ((data.getUint8(offset) & 0x10) == 0x10); let listenable = ((data.getUint8(offset++) & 0x8) == 0x8); let len = data.getUint8(offset++); let name = data.getString(offset, len); - let expansion; + let annotation; offset += len; @@ -521,22 +540,22 @@ export default class TypeTemplate { offset += dt.size; - if (hasExpansion) // expansion ? + if (hasAnnotation) // annotation ? { let cs = data.getUint32(offset); offset += 4; - expansion = data.getString(offset, cs); + annotation = data.getString(offset, cs); offset += cs; } - let et = new EventTemplate(od, eventIndex++, name, inherited, dt.type, expansion, listenable); + let et = new EventTemplate(od, eventIndex++, name, inherited, dt.type, annotation, listenable); od.events.push(et); } else if (type == 3) // constant { - let expansion = null; - let hasExpansion = ((data[offset++] & 0x10) == 0x10); + let annotation = null; + let hasAnnotation = ((data[offset++] & 0x10) == 0x10); let name = data.getString(offset + 1, data[offset]); offset += data[offset] + 1; @@ -549,16 +568,16 @@ export default class TypeTemplate { offset += parsed.size; - if (hasExpansion) // expansion ? + if (hasAnnotation) // annotation ? { let cs = data.getUint32(offset); offset += 4; - expansion = data.getString(offset, cs); + annotation = data.getString(offset, cs); offset += cs; } let ct = new ConstantTemplate(this, constantIndex++, name, inherited, - dt.type, parsed.reply.result, expansion); + dt.type, parsed.reply.result, annotation); od.constants.push(ct); }