2
0
mirror of https://github.com/esiur/esiur-dart.git synced 2025-09-13 20:13:19 +00:00
This commit is contained in:
2021-07-21 12:18:01 +03:00
parent 737397da11
commit 6be04c39ed
27 changed files with 659 additions and 513 deletions

View File

@@ -22,13 +22,10 @@ SOFTWARE.
*/
import 'dart:ffi';
import 'dart:typed_data';
import 'package:esiur/esiur.dart';
import 'package:esiur/src/Resource/Template/TemplateDescriber.dart';
import 'package:esiur/src/Resource/Template/TemplateType.dart';
import 'package:esiur/src/Security/Authority/AuthenticationMethod.dart';
import '../../Resource/Template/TemplateDescriber.dart';
import '../../Resource/Template/TemplateType.dart';
import '../../Security/Authority/AuthenticationMethod.dart';
import '../../Core/AsyncBag.dart';
@@ -44,7 +41,7 @@ import '../../Core/ExceptionCode.dart';
import '../../Core/ErrorType.dart';
import '../../Resource/Warehouse.dart';
import '../Sockets/SocketState.dart';
import 'dart:math';
import '../../Resource/IStore.dart';
import '../../Resource/IResource.dart';
@@ -434,9 +431,8 @@ class DistributedConnection extends NetworkConnection with IStore {
String link(IResource resource) {
if (resource is DistributedResource) {
var r = resource as DistributedResource;
if (r.instance.store == this)
return this.instance.name + "/" + r.id.toString();
if (resource.instance.store == this)
return this.instance.name + "/" + resource.id.toString();
}
return null;
@@ -445,9 +441,9 @@ class DistributedConnection extends NetworkConnection with IStore {
void init() {
_queue.then((x) {
if (x.type == DistributedResourceQueueItemType.Event)
x.resource.emitEventByIndex(x.index, x.value);
x.resource.internal_emitEventByIndex(x.index, x.value);
else
x.resource.updatePropertyByIndex(x.index, x.value);
x.resource.internal_updatePropertyByIndex(x.index, x.value);
});
var r = new Random();
@@ -663,8 +659,7 @@ class DistributedConnection extends NetworkConnection with IStore {
case IIPPacketAction.TemplateFromClassName:
case IIPPacketAction.TemplateFromClassId:
case IIPPacketAction.TemplateFromResourceId:
iipReply(
packet.callbackId, [TypeTemplate.parse(packet.content)]);
iipReply(packet.callbackId, [TypeTemplate.parse(packet.content)]);
break;
case IIPPacketAction.QueryLink:
@@ -1285,7 +1280,7 @@ class DistributedConnection extends NetworkConnection with IStore {
.addUint16(link.length)
.addDC(link)
.addDC(Codec.composePropertyValueArray(
(r as DistributedResource).serialize(), this, true))
(r as DistributedResource).internal_serialize(), this, true))
.done();
} else {
// reply ok
@@ -1883,7 +1878,7 @@ class DistributedConnection extends NetworkConnection with IStore {
if (ft != null) {
if (r is DistributedResource) {
var rt = (r as DistributedResource)
.invokeByArrayArguments(index, arguments);
.internal_invokeByArrayArguments(index, arguments);
if (rt != null) {
rt.then((res) {
sendReply(IIPPacketAction.InvokeFunctionArrayArguments,
@@ -1922,7 +1917,7 @@ class DistributedConnection extends NetworkConnection with IStore {
if (ft != null) {
if (r is DistributedResource) {
var rt = (r as DistributedResource)
.invokeByNamedArguments(index, namedArgs);
.internal_invokeByNamedArguments(index, namedArgs);
if (rt != null) {
rt.then((res) {
sendReply(IIPPacketAction.InvokeFunctionNamedArguments,
@@ -2215,8 +2210,7 @@ class DistributedConnection extends NetworkConnection with IStore {
.done()
.then<dynamic>((rt) {
_templateRequests.remove(classId);
_templates[(rt[0] as TypeTemplate).classId] =
rt[0] as TypeTemplate;
_templates[(rt[0] as TypeTemplate).classId] = rt[0] as TypeTemplate;
Warehouse.putTemplate(rt[0] as TypeTemplate);
reply.trigger(rt[0]);
}).error((ex) {
@@ -2316,12 +2310,14 @@ class DistributedConnection extends NetworkConnection with IStore {
DistributedResource dr;
if (resource == null) {
var template = Warehouse.getTemplateByClassId(rt[0], TemplateType.Wrapper);
var template =
Warehouse.getTemplateByClassId(rt[0], TemplateType.Wrapper);
if (template?.definedType != null) {
dr = Warehouse.createInstance(template?.definedType);
dr.init(this, id, rt[1], rt[2]);
dr.internal_init(this, id, rt[1], rt[2]);
} else {
dr = new DistributedResource(this, id, rt[1], rt[2]);
dr = new DistributedResource();
dr.internal_init(this, id, rt[1], rt[2]);
}
} else
dr = resource;
@@ -2338,7 +2334,7 @@ class DistributedConnection extends NetworkConnection with IStore {
Warehouse.put(id.toString(), dr, this, null, tmp).then<dynamic>((ok) {
Codec.parsePropertyValueArray(d, 0, d.length, this).then((ar) {
//print("attached");
dr.attach(ar);
dr.internal_attach(ar);
_resourceRequests.remove(id);
reply.trigger(dr);
});
@@ -2346,7 +2342,7 @@ class DistributedConnection extends NetworkConnection with IStore {
} else {
Codec.parsePropertyValueArray(d, 0, d.length, this).then((ar) {
//print("attached");
dr.attach(ar);
dr.internal_attach(ar);
_resourceRequests.remove(id);
reply.trigger(dr);
});

View File

@@ -22,8 +22,13 @@ SOFTWARE.
*/
import 'package:esiur/esiur.dart';
import 'package:esiur/src/Data/KeyValuePair.dart';
import '../../Core/AsyncException.dart';
import '../../Core/ErrorType.dart';
import '../../Core/ExceptionCode.dart';
import '../../Resource/ResourceTrigger.dart';
import '../../Data/KeyValuePair.dart';
import '../../Resource/IResource.dart';
import '../../Core/AsyncReply.dart';
@@ -33,6 +38,9 @@ import '../../Data/Codec.dart';
import './DistributedConnection.dart';
import '../Packets/IIPPacketAction.dart';
import '../../Resource/Template/EventTemplate.dart';
class DistributedResource extends IResource {
int _instanceId;
DistributedConnection _connection;
@@ -107,32 +115,28 @@ class DistributedResource extends IResource {
/// <param name="template">Resource template.</param>
/// <param name="instanceId">Instance Id given by the other end.</param>
/// <param name="age">Resource age.</param>
DistributedResource(
DistributedConnection connection, int instanceId, int age, String link) {
this._link = link;
this._connection = connection;
this._instanceId = instanceId;
this._age = age;
}
void init(
DistributedConnection connection, int instanceId, int age, String link) {
this._link = link;
this._connection = connection;
this._instanceId = instanceId;
this._age = age;
}
//void _ready()
//{
// _isReady = true;
// DistributedResource(
// DistributedConnection connection, int instanceId, int age, String link) {
// this._link = link;
// this._connection = connection;
// this._instanceId = instanceId;
// this._age = age;
// }
void internal_init(
DistributedConnection connection, int instanceId, int age, String link) {
this._link = link;
this._connection = connection;
this._instanceId = instanceId;
this._age = age;
}
/// <summary>
/// Export all properties with ResourceProperty attributed as bytes array.
/// </summary>
/// <returns></returns>
List<PropertyValue> serialize() {
List<PropertyValue> internal_serialize() {
var props = new List<PropertyValue>(_properties.length);
for (var i = 0; i < _properties.length; i++)
@@ -142,7 +146,7 @@ class DistributedResource extends IResource {
return props;
}
bool attach(List<PropertyValue> properties) {
bool internal_attach(List<PropertyValue> properties) {
if (_attached)
return false;
else {
@@ -168,7 +172,7 @@ class DistributedResource extends IResource {
if (_queued_updates.length > 0) {
_queued_updates
.forEach((kv) => updatePropertyByIndex(kv.key, kv.value));
.forEach((kv) => internal_updatePropertyByIndex(kv.key, kv.value));
_queued_updates.clear();
}
}
@@ -207,7 +211,7 @@ class DistributedResource extends IResource {
return connection.sendUnlistenRequest(_instanceId, et.index);
}
void emitEventByIndex(int index, dynamic args) {
void internal_emitEventByIndex(int index, dynamic args) {
// neglect events when the object is not yet attached
if (!_attached) return;
@@ -217,7 +221,7 @@ class DistributedResource extends IResource {
instance.emitResourceEvent(null, null, et.name, args);
}
AsyncReply<dynamic> invokeByNamedArguments(int index, Structure namedArgs) {
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");
@@ -228,7 +232,7 @@ class DistributedResource extends IResource {
return connection.sendInvokeByNamedArguments(_instanceId, index, namedArgs);
}
AsyncReply<dynamic> invokeByArrayArguments(int index, List<dynamic> args) {
AsyncReply<dynamic> internal_invokeByArrayArguments(int index, List<dynamic> args) {
if (_destroyed) throw new Exception("Trying to access destroyed object");
if (_suspended) throw new Exception("Trying to access suspended object");
@@ -270,9 +274,9 @@ class DistributedResource extends IResource {
for (var p in invocation.namedArguments.keys)
namedArgs[_getMemberName(p)] = invocation.namedArguments[p];
return invokeByNamedArguments(ft.index, namedArgs);
return internal_invokeByNamedArguments(ft.index, namedArgs);
} else {
return invokeByArrayArguments(
return internal_invokeByArrayArguments(
ft.index, invocation.positionalArguments);
}
}
@@ -304,7 +308,7 @@ class DistributedResource extends IResource {
return _properties[index];
}
void updatePropertyByIndex(int index, dynamic value) {
void internal_updatePropertyByIndex(int index, dynamic value) {
if (!_attached) {
_queued_updates.add(KeyValuePair(index, value));
} else {

View File

@@ -1,4 +1,4 @@
import 'package:esiur/src/Resource/Template/TemplateDescriber.dart';
import '../../Resource/Template/TemplateDescriber.dart';
import '../../Resource/IResource.dart';
import '../../Core/AsyncReply.dart';

View File

@@ -23,7 +23,11 @@ SOFTWARE.
*/
import 'dart:io';
import 'package:esiur/esiur.dart';
import '../../Core/ErrorType.dart';
import '../../Core/ExceptionCode.dart';
import '../../Core/AsyncException.dart';
import 'ISocket.dart';
import '../../Data/DC.dart';