From 7971c836b7de6baebb1cfd090f48bffafc2d4150 Mon Sep 17 00:00:00 2001 From: Ahmed Zamil Date: Mon, 22 Feb 2021 01:59:41 +0300 Subject: [PATCH] IIP3.5 --- lib/src/Net/IIP/DistributedConnection.dart | 29 +++++++++++--------- lib/src/Net/IIP/DistributedResource.dart | 7 ++--- lib/src/Net/Packets/IIPPacket.dart | 27 +++++++++--------- lib/src/Resource/Instance.dart | 2 +- lib/src/Resource/Template/EventTemplate.dart | 4 +-- lib/src/Resource/Warehouse.dart | 2 +- 6 files changed, 37 insertions(+), 34 deletions(-) diff --git a/lib/src/Net/IIP/DistributedConnection.dart b/lib/src/Net/IIP/DistributedConnection.dart index 2ca14ae..ecc9893 100644 --- a/lib/src/Net/IIP/DistributedConnection.dart +++ b/lib/src/Net/IIP/DistributedConnection.dart @@ -1183,7 +1183,7 @@ class DistributedConnection extends NetworkConnection with IStore var item = new AsyncReply(); _queue.add(item); - Codec.parseVarArray(content, 0, content.length, this).then((arguments) + Codec.parse(content, 0, this).then((arguments) { var et = r.instance.template.getEventTemplateByIndex(index); if (et != null) @@ -1846,16 +1846,21 @@ class DistributedConnection extends NetworkConnection with IStore { Warehouse.query(resourceLink).then((r) { - //if (r != null) - //{ - var list = r.where((x) => x.instance.applicable(session, ActionType.Attach, null) != Ruling.Denied).toList(); - - if (list.length == 0) + if (r == null) + { sendError(ErrorType.Management, callback, ExceptionCode.ResourceNotFound.index); + } else - sendReply(IIPPacketAction.QueryLink, callback) - .addDC(Codec.composeResourceArray(list, this, true)) - .done(); + { + var list = r.where((x) => x.instance.applicable(session, ActionType.Attach, null) != Ruling.Denied).toList(); + + if (list.length == 0) + sendError(ErrorType.Management, callback, ExceptionCode.ResourceNotFound.index); + else + sendReply(IIPPacketAction.QueryLink, callback) + .addDC(Codec.composeResourceArray(list, this, true)) + .done(); + } }); } @@ -1895,8 +1900,6 @@ class DistributedConnection extends NetworkConnection with IStore } else { - - var fi = null ;//r.GetType().GetTypeInfo().GetMethod(ft.name); @@ -2595,7 +2598,7 @@ class DistributedConnection extends NetworkConnection with IStore // private void Instance_EventOccurred(IResource resource, string name, string[] users, DistributedConnection[] connections, object[] args) - void _instance_EventOccurred(IResource resource, issuer, List receivers, String name, List args) + void _instance_EventOccurred(IResource resource, issuer, List receivers, String name, dynamic args) { var et = resource.instance.template.getEventTemplateByName(name); @@ -2614,7 +2617,7 @@ class DistributedConnection extends NetworkConnection with IStore sendEvent(IIPPacketEvent.EventOccurred) .addUint32(resource.instance.id) .addUint8(et.index) - .addDC(Codec.composeVarArray(args, this, true)) + .addDC(Codec.compose(args, this, true)) .done(); } } diff --git a/lib/src/Net/IIP/DistributedResource.dart b/lib/src/Net/IIP/DistributedResource.dart index 4c13047..ce74a12 100644 --- a/lib/src/Net/IIP/DistributedResource.dart +++ b/lib/src/Net/IIP/DistributedResource.dart @@ -165,14 +165,13 @@ class DistributedResource extends IResource { return true; } - void emitEventByIndex(int index, List args) { + void emitEventByIndex(int index, dynamic args) { // neglect events when the object is not yet attached if (!_attached) return; var et = instance.template.getEventTemplateByIndex(index); - //events[index]?.Invoke(this, args); - emitArgs(et.name, args); - + emitArgs(et.name, [args]); + //emitArgs(event, arguments) instance.emitResourceEvent(null, null, et.name, args); } diff --git a/lib/src/Net/Packets/IIPPacket.dart b/lib/src/Net/Packets/IIPPacket.dart index edf8daf..5acbfec 100644 --- a/lib/src/Net/Packets/IIPPacket.dart +++ b/lib/src/Net/Packets/IIPPacket.dart @@ -177,7 +177,8 @@ class IIPPacket offset += cl; } - else if (event == IIPPacketEvent.PropertyUpdated) + else if (event == IIPPacketEvent.PropertyUpdated + || event == IIPPacketEvent.EventOccurred) { if (_notEnough(offset, ends, 2)) return -_dataLengthNeeded; @@ -210,23 +211,23 @@ class IIPPacket offset += size; } } - else if (event == IIPPacketEvent.EventOccurred) - { - if (_notEnough(offset, ends, 5)) - return -_dataLengthNeeded; + // else if (event == IIPPacketEvent.EventOccurred) + // { + // if (_notEnough(offset, ends, 5)) + // return -_dataLengthNeeded; - methodIndex = data[offset++]; + // methodIndex = data[offset++]; - var cl = data.getUint32( offset); - offset += 4; + // var cl = data.getUint32( offset); + // offset += 4; - if (_notEnough(offset, ends, cl)) - return -_dataLengthNeeded; + // if (_notEnough(offset, ends, cl)) + // return -_dataLengthNeeded; - content = data.clip(offset, cl); - offset += cl; + // content = data.clip(offset, cl); + // offset += cl; - } + // } // Attribute else if (event == IIPPacketEvent.AttributesUpdated) { diff --git a/lib/src/Resource/Instance.dart b/lib/src/Resource/Instance.dart index 8dbb8df..d2f3cc7 100644 --- a/lib/src/Resource/Instance.dart +++ b/lib/src/Resource/Instance.dart @@ -453,7 +453,7 @@ class Instance extends IEventHandler } } - emitResourceEvent(issuer, List receivers, String name, List args) + emitResourceEvent(issuer, List receivers, String name, dynamic args) { emitArgs("resourceEventOccurred", [_resource, issuer, receivers, name, args]); } diff --git a/lib/src/Resource/Template/EventTemplate.dart b/lib/src/Resource/Template/EventTemplate.dart index c56710b..b32eed5 100644 --- a/lib/src/Resource/Template/EventTemplate.dart +++ b/lib/src/Resource/Template/EventTemplate.dart @@ -20,10 +20,10 @@ class EventTemplate extends MemberTemplate var exp = DC.stringToBytes(expansion); return new BinaryList() .addUint8(0x50) - .addInt32(exp.length) - .addDC(exp) .addUint8(name.length) .addDC(name) + .addInt32(exp.length) + .addDC(exp) .toDC(); } else diff --git a/lib/src/Resource/Warehouse.dart b/lib/src/Resource/Warehouse.dart index 7c271f3..195bf64 100644 --- a/lib/src/Resource/Warehouse.dart +++ b/lib/src/Resource/Warehouse.dart @@ -385,7 +385,7 @@ class Warehouse { } // return new name - + return rt; }