mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-09-13 20:13:19 +00:00
2.0.0
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,8 @@ SOFTWARE.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import '../../Data/IntType.dart';
|
||||
|
||||
import '../../Resource/Instance.dart';
|
||||
|
||||
import '../../Core/AsyncException.dart';
|
||||
@@ -37,7 +39,6 @@ import '../../Data/KeyValuePair.dart';
|
||||
import '../../Resource/IResource.dart';
|
||||
import '../../Core/AsyncReply.dart';
|
||||
import '../../Data/PropertyValue.dart';
|
||||
import '../../Data/Structure.dart';
|
||||
import '../../Data/Codec.dart';
|
||||
import './DistributedConnection.dart';
|
||||
import '../Packets/IIPPacketAction.dart';
|
||||
@@ -196,7 +197,7 @@ class DistributedResource extends IResource {
|
||||
|
||||
EventTemplate? et = event is EventTemplate
|
||||
? event
|
||||
: instance?.template.getEventTemplateByName(event);
|
||||
: instance?.template.getEventTemplateByName(event.toString());
|
||||
|
||||
if (et == null)
|
||||
return AsyncReply<dynamic>().triggerError(new AsyncException(
|
||||
@@ -216,7 +217,7 @@ class DistributedResource extends IResource {
|
||||
|
||||
EventTemplate? et = event is EventTemplate
|
||||
? event
|
||||
: instance?.template.getEventTemplateByName(event);
|
||||
: instance?.template.getEventTemplateByName(event.toString());
|
||||
|
||||
if (et == null)
|
||||
return AsyncReply().triggerError(new AsyncException(
|
||||
@@ -237,28 +238,11 @@ class DistributedResource extends IResource {
|
||||
var et = instance?.template.getEventTemplateByIndex(index);
|
||||
if (et != null) {
|
||||
emitArgs(et.name, [args]);
|
||||
instance?.emitResourceEvent(null, null, et.name, args);
|
||||
instance?.emitResourceEvent(null, null, et, args);
|
||||
}
|
||||
}
|
||||
|
||||
AsyncReply<dynamic> internal_invokeByNamedArguments(
|
||||
int index, Structure namedArgs) {
|
||||
if (_destroyed) throw new Exception("Trying to access destroyed object");
|
||||
if (_suspended) throw new Exception("Trying to access suspended object");
|
||||
|
||||
if (instance == null) throw Exception("Object not initialized.");
|
||||
|
||||
var ins = instance as Instance;
|
||||
|
||||
if (index >= ins.template.functions.length)
|
||||
throw new Exception("Function index is incorrect");
|
||||
|
||||
return connection?.sendInvokeByNamedArguments(
|
||||
_instanceId as int, index, namedArgs) as AsyncReply<dynamic>;
|
||||
}
|
||||
|
||||
AsyncReply<dynamic> internal_invokeByArrayArguments(
|
||||
int index, List<dynamic> args) {
|
||||
AsyncReply<dynamic> internal_invoke(int index, Map<UInt8, dynamic> args) {
|
||||
if (_destroyed) throw new Exception("Trying to access destroyed object");
|
||||
|
||||
if (_suspended) throw new Exception("Trying to access suspended object");
|
||||
@@ -269,8 +253,8 @@ class DistributedResource extends IResource {
|
||||
if (index >= ins.template.functions.length)
|
||||
throw new Exception("Function index is incorrect");
|
||||
|
||||
return _connection?.sendInvokeByArrayArguments(
|
||||
_instanceId as int, index, args) as AsyncReply;
|
||||
return _connection?.sendInvoke(_instanceId as int, index, args)
|
||||
as AsyncReply;
|
||||
}
|
||||
|
||||
operator [](String index) {
|
||||
@@ -299,16 +283,24 @@ class DistributedResource extends IResource {
|
||||
var ft = instance?.template.getFunctionTemplateByName(memberName);
|
||||
|
||||
if (_attached && ft != null) {
|
||||
if (invocation.namedArguments.length > 0) {
|
||||
var namedArgs = new Structure();
|
||||
for (var p in invocation.namedArguments.keys)
|
||||
namedArgs[_getMemberName(p)] = invocation.namedArguments[p];
|
||||
var args = Map<UInt8, dynamic>();
|
||||
|
||||
return internal_invokeByNamedArguments(ft.index, namedArgs);
|
||||
} else {
|
||||
return internal_invokeByArrayArguments(
|
||||
ft.index, invocation.positionalArguments);
|
||||
for (var i = 0;
|
||||
i < invocation.positionalArguments.length &&
|
||||
i < ft.arguments.length;
|
||||
i++) args[UInt8(i)] = invocation.positionalArguments[i];
|
||||
|
||||
for (var i = invocation.positionalArguments.length;
|
||||
i < ft.arguments.length;
|
||||
i++) {
|
||||
for (var j = 0; j < invocation.namedArguments.length; j++) {
|
||||
if (ft.arguments[i].name ==
|
||||
_getMemberName(invocation.namedArguments.keys.elementAt(j))) ;
|
||||
args[UInt8(i)] = invocation.namedArguments.values.elementAt(j);
|
||||
}
|
||||
}
|
||||
|
||||
return internal_invoke(ft.index, args);
|
||||
}
|
||||
} else if (invocation.isSetter) {
|
||||
var pt = instance?.template.getPropertyTemplateByName(memberName);
|
||||
@@ -381,4 +373,9 @@ class DistributedResource extends IResource {
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "DR<${instance?.template.className ?? ''}>";
|
||||
}
|
||||
}
|
||||
|
@@ -31,5 +31,4 @@ class DistributedServer extends IResource {
|
||||
@override
|
||||
TemplateDescriber get template =>
|
||||
TemplateDescriber("Esiur.Net.IIP.DistributedServer");
|
||||
|
||||
}
|
||||
|
@@ -21,6 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
import '../../Data/TransmissionType.dart';
|
||||
|
||||
import '../../Data/DC.dart';
|
||||
import '../../Data/Guid.dart';
|
||||
|
||||
@@ -29,7 +31,6 @@ import 'IIPPacketCommand.dart';
|
||||
import 'IIPPacketEvent.dart';
|
||||
import 'IIPPacketReport.dart';
|
||||
import '../../Data/Codec.dart';
|
||||
import '../../Data/DataType.dart';
|
||||
|
||||
class IIPPacket {
|
||||
int report = 0;
|
||||
@@ -53,7 +54,7 @@ class IIPPacket {
|
||||
int storeId = 0;
|
||||
|
||||
int resourceAge = 0;
|
||||
DC content = DC(0);
|
||||
//DC content = DC(0);
|
||||
int errorCode = 0;
|
||||
String errorMessage = "";
|
||||
String className = "";
|
||||
@@ -68,6 +69,9 @@ class IIPPacket {
|
||||
DateTime toDate = DateTime(2000);
|
||||
int fromAge = 0;
|
||||
int toAge = 0;
|
||||
String resourceName = "";
|
||||
|
||||
TransmissionType? dataType;
|
||||
|
||||
int _dataLengthNeeded = 0;
|
||||
int _originalOffset = 0;
|
||||
@@ -137,7 +141,7 @@ class IIPPacket {
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
resourceName = data.getString(offset, cl);
|
||||
|
||||
offset += cl;
|
||||
} else if (event == IIPPacketEvent.PropertyUpdated ||
|
||||
@@ -146,25 +150,12 @@ class IIPPacket {
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(dt);
|
||||
var parsed = TransmissionType.parse(data, offset, ends);
|
||||
|
||||
if (size < 0) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
if (parsed.type == null) return -parsed.size;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 5, cl + 5);
|
||||
offset += cl;
|
||||
} else {
|
||||
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
}
|
||||
dataType = parsed.type;
|
||||
offset += parsed.size;
|
||||
}
|
||||
// else if (event == IIPPacketEvent.EventOccurred)
|
||||
// {
|
||||
@@ -192,7 +183,8 @@ class IIPPacket {
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
//@TODO: fix this
|
||||
//content = data.clip(offset, cl);
|
||||
|
||||
offset += cl;
|
||||
}
|
||||
@@ -228,7 +220,8 @@ class IIPPacket {
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
//@TODO: fix this
|
||||
//content = data.clip(offset, cl);
|
||||
} else if (action == IIPPacketAction.DeleteResource) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
@@ -252,7 +245,7 @@ class IIPPacket {
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
resourceName = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
} else if (action == IIPPacketAction.TemplateFromClassName) {
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
@@ -301,22 +294,20 @@ class IIPPacket {
|
||||
|
||||
toDate = data.getDateTime(offset);
|
||||
offset += 8;
|
||||
} else if (action == IIPPacketAction.InvokeFunctionArrayArguments ||
|
||||
action == IIPPacketAction.InvokeFunctionNamedArguments) {
|
||||
if (_notEnough(offset, ends, 9)) return -_dataLengthNeeded;
|
||||
} else if (action == IIPPacketAction.InvokeFunction) {
|
||||
if (_notEnough(offset, ends, 6)) return -_dataLengthNeeded;
|
||||
|
||||
resourceId = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
var parsed = TransmissionType.parse(data, offset, ends);
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
if (parsed.type == null) return -parsed.size;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
dataType = parsed.type;
|
||||
offset += parsed.size;
|
||||
} else if (action == IIPPacketAction.Listen ||
|
||||
action == IIPPacketAction.Unlisten) {
|
||||
if (_notEnough(offset, ends, 5)) return -_dataLengthNeeded;
|
||||
@@ -358,26 +349,12 @@ class IIPPacket {
|
||||
offset += 4;
|
||||
|
||||
methodIndex = data[offset++];
|
||||
var parsed = TransmissionType.parse(data, offset, ends);
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(dt);
|
||||
if (parsed.type == null) return -parsed.size;
|
||||
|
||||
if (size < 0) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 5, cl + 5);
|
||||
offset += cl;
|
||||
} else {
|
||||
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
}
|
||||
dataType = parsed.type;
|
||||
offset += parsed.size;
|
||||
}
|
||||
// Attributes
|
||||
else if (action == IIPPacketAction.UpdateAllAttributes ||
|
||||
@@ -393,7 +370,8 @@ class IIPPacket {
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
//@TODO: fix this
|
||||
//content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
}
|
||||
} else if (command == IIPPacketCommand.Reply) {
|
||||
@@ -415,15 +393,12 @@ class IIPPacket {
|
||||
resourceLink = data.getString(offset, cl);
|
||||
offset += cl;
|
||||
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
var parsed = TransmissionType.parse(data, offset, ends);
|
||||
|
||||
cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
if (parsed.type == null) return -parsed.size;
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
dataType = parsed.type;
|
||||
offset += parsed.size;
|
||||
} else if (action == IIPPacketAction.DetachResource) {
|
||||
// nothing to do
|
||||
} else if (action == IIPPacketAction.CreateResource) {
|
||||
@@ -450,41 +425,26 @@ class IIPPacket {
|
||||
||
|
||||
action == IIPPacketAction.GetAllAttributes ||
|
||||
action == IIPPacketAction.GetAttributes) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
var parsed = TransmissionType.parse(data, offset, ends);
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
if (parsed.type == null) return -parsed.size;
|
||||
|
||||
content = data.clip(offset, cl);
|
||||
offset += cl;
|
||||
} else if (action == IIPPacketAction.InvokeFunctionArrayArguments ||
|
||||
action == IIPPacketAction.InvokeFunctionNamedArguments)
|
||||
dataType = parsed.type;
|
||||
offset += parsed.size;
|
||||
} else if (action == IIPPacketAction.InvokeFunction)
|
||||
//|| action == IIPPacketAction.GetProperty
|
||||
//|| action == IIPPacketAction.GetPropertyIfModified)
|
||||
{
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(dt);
|
||||
var parsed = TransmissionType.parse(data, offset, ends);
|
||||
|
||||
if (size < 0) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
if (parsed.type == null) return -parsed.size;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 5, cl + 5);
|
||||
offset += cl;
|
||||
} else {
|
||||
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
}
|
||||
dataType = parsed.type;
|
||||
offset += parsed.size;
|
||||
} else if (action == IIPPacketAction.SetProperty ||
|
||||
action == IIPPacketAction.Listen ||
|
||||
action == IIPPacketAction.Unlisten) {
|
||||
@@ -521,25 +481,12 @@ class IIPPacket {
|
||||
} else if (report == IIPPacketReport.ChunkStream) {
|
||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||
|
||||
var dt = data[offset++];
|
||||
var size = DataType.size(dt);
|
||||
var parsed = TransmissionType.parse(data, offset, ends);
|
||||
|
||||
if (size < 0) {
|
||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||
if (parsed.type == null) return -parsed.size;
|
||||
|
||||
var cl = data.getUint32(offset);
|
||||
offset += 4;
|
||||
|
||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 5, cl + 5);
|
||||
offset += cl;
|
||||
} else {
|
||||
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
|
||||
|
||||
content = data.clip(offset - 1, size + 1);
|
||||
offset += size;
|
||||
}
|
||||
dataType = parsed.type;
|
||||
offset += parsed.size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,8 +20,8 @@ class IIPPacketAction {
|
||||
static const int LinkTemplates = 0xF;
|
||||
|
||||
// Request Invoke
|
||||
static const int InvokeFunctionArrayArguments = 0x10;
|
||||
static const int InvokeFunctionNamedArguments = 0x11;
|
||||
static const int InvokeFunction = 0x10;
|
||||
static const int Reserved = 0x11;
|
||||
static const int Listen = 0x12;
|
||||
static const int Unlisten = 0x13;
|
||||
static const int SetProperty = 0x14;
|
||||
|
@@ -71,7 +71,7 @@ class WSocket extends ISocket {
|
||||
if (_state == SocketState.Closed || _state == SocketState.Terminated)
|
||||
return;
|
||||
|
||||
var dc = new DC.fromList(data);
|
||||
var dc = new DC.fromList(data as List<int>);
|
||||
receiveNetworkBuffer.write(dc, 0, dc.length);
|
||||
receiver?.networkReceive(this, receiveNetworkBuffer);
|
||||
} catch (ex) {
|
||||
|
Reference in New Issue
Block a user