diff --git a/lib/src/Net/IIP/DistributedConnection.dart b/lib/src/Net/IIP/DistributedConnection.dart
index 513df9f..27f5f93 100644
--- a/lib/src/Net/IIP/DistributedConnection.dart
+++ b/lib/src/Net/IIP/DistributedConnection.dart
@@ -145,9 +145,11 @@ class DistributedConnection extends NetworkConnection with IStore {
DateTime? _lastKeepAliveSent;
DateTime? _lastKeepAliveReceived;
- int jitter;
+ int jitter = 0;
int keepAliveTime = 10;
+ DistributedServer? server;
+
///
/// Local username to authenticate ourselves.
///
@@ -341,9 +343,13 @@ class DistributedConnection extends NetworkConnection with IStore {
+ if (server != null){
// @TODO: check if we need this with reconnect
- // _resources.values.forEach((x) => x.suspend());
- //_unsubscribeAll();
+ _resources.values.forEach((x) => x.suspend());
+ _unsubscribeAll();
+ Warehouse.remove(this);
+ }
+
}
@@ -743,11 +749,11 @@ class DistributedConnection extends NetworkConnection with IStore {
break;
case IIPPacketAction.ProcedureCall:
- iipRequestProcedureCall(packet.callbackId, packet.procedure, (TransmissionType)packet.dataType, msg);
+ iipRequestProcedureCall(packet.callbackId, packet.procedure, packet.dataType as TransmissionType, msg);
break;
case IIPPacketAction.StaticCall:
- iipRequestStaticCall(packet.callbackId, packet.classId, packet.methodIndex, (TransmissionType)packet.dataType, msg);
+ iipRequestStaticCall(packet.callbackId, packet.classId, packet.methodIndex, packet.dataType as TransmissionType, msg);
break;
@@ -851,7 +857,7 @@ class DistributedConnection extends NetworkConnection with IStore {
break;
case IIPPacketAction.KeepAlive:
- iipReply(packet.callbackId, packet.currentTime, packet.jitter);
+ iipReply(packet.callbackId, [packet.currentTime, packet.jitter]);
break;
}
} else if (packet.command == IIPPacketCommand.Report) {
@@ -1444,7 +1450,7 @@ class DistributedConnection extends NetworkConnection with IStore {
return;
}
- _unsubscrive(r);
+ _unsubscribe(r);
var link = DC.stringToBytes(r.instance?.link ?? "");
@@ -1527,7 +1533,7 @@ class DistributedConnection extends NetworkConnection with IStore {
}
void _unsubscribeAll(){
- _subscriptions.forEach((resource, value) => {
+ _subscriptions.forEach((resource, value) {
resource.instance?.off("resourceEventOccurred", _instance_EventOccurred);
resource.instance?.off("resourceModified", _instance_PropertyModified);
resource.instance?.off("resourceDestroyed", _instance_ResourceDestroyed);
@@ -2110,7 +2116,7 @@ void _unsubscribeAll(){
// });
}
- void IIPRequestStaticCall(int callback, Guid classId, int index, TransmissionType transmissionType, DC content)
+ void iipRequestStaticCall(int callback, Guid classId, int index, TransmissionType transmissionType, DC content)
{
var template = Warehouse.getTemplateByClassId(classId);
@@ -2973,7 +2979,7 @@ void _unsubscribeAll(){
_instance_ResourceDestroyed(IResource resource) {
// compose the packet
- _unsubscrive(resource);
+ _unsubscribe(resource);
sendEvent(IIPPacketEvent.ResourceDestroyed)
..addUint32((resource.instance as Instance).id)
..done();
diff --git a/lib/src/Net/IIP/DistributedResource.dart b/lib/src/Net/IIP/DistributedResource.dart
index 317b7c7..347ae18 100644
--- a/lib/src/Net/IIP/DistributedResource.dart
+++ b/lib/src/Net/IIP/DistributedResource.dart
@@ -24,6 +24,7 @@ SOFTWARE.
import 'dart:async';
import 'dart:ffi';
+import 'dart:io';
import '../../Data/IntType.dart';
@@ -244,15 +245,17 @@ class DistributedResource extends IResource {
}
AsyncReply internal_invoke(int index, Map args) {
- if (_destroyed) throw new Exception("Trying to access destroyed object");
+ if (_destroyed) throw new Exception("Trying to access a destroyed object");
- if (_suspended) throw new Exception("Trying to access suspended object");
+ if (_suspended) throw new Exception("Trying to access a suspended object.");
if (instance == null) throw Exception("Object not initialized.");
+ if (_connection == null) throw new Exception("No connection.");
+
var ins = instance as Instance;
if (index >= ins.template.functions.length)
- throw new Exception("Function index is incorrect");
+ throw new Exception("Function index is incorrect.");
// return _connection?.sendInvoke(_instanceId as int, index, args)
// as AsyncReply;
@@ -262,9 +265,9 @@ class DistributedResource extends IResource {
if (ft == null) throw new Exception("Function template not found.");
if (ft.isStatic)
- return _connection?.staticCall(ins.template.classId, index, args);
+ return _connection!.staticCall(ins.template.classId, index, args);
else
- return _connection?.sendInvoke(_instanceId as Int, index, args);
+ return _connection!.sendInvoke(_instanceId as int, index, args);
}
operator [](String index) {
diff --git a/lib/src/Resource/Template/TemplateDescriber.dart b/lib/src/Resource/Template/TemplateDescriber.dart
index 2cf3223..ef08c9e 100644
--- a/lib/src/Resource/Template/TemplateDescriber.dart
+++ b/lib/src/Resource/Template/TemplateDescriber.dart
@@ -86,9 +86,9 @@ class Func {
final List argsType;
//final bool isNullable;
final String? annotation;
-
+ final bool isStatic;
const Func(this.name, this.returnType, this.argsType,
- [this.annotation = null]);
+ [this.annotation = null, this.isStatic = false]);
}
class Arg {
diff --git a/lib/src/Resource/Template/TypeTemplate.dart b/lib/src/Resource/Template/TypeTemplate.dart
index 48182b5..7ed3fe9 100644
--- a/lib/src/Resource/Template/TypeTemplate.dart
+++ b/lib/src/Resource/Template/TypeTemplate.dart
@@ -221,6 +221,7 @@ class TypeTemplate {
i,
fi.name,
false,
+ fi.isStatic,
args,
RepresentationType.fromType(fi.returnType) ??
RepresentationType.Void,