mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-06-27 06:43:13 +00:00
Rename
This commit is contained in:
@ -11,6 +11,8 @@ class AsyncBag<T> extends AsyncReply<List<T>>
|
||||
|
||||
seal()
|
||||
{
|
||||
//print("SEALED");
|
||||
|
||||
if (_sealedBag)
|
||||
return;
|
||||
|
||||
@ -28,8 +30,11 @@ class AsyncBag<T> extends AsyncReply<List<T>>
|
||||
{
|
||||
_results[index] = r;
|
||||
_count++;
|
||||
//print("Seal ${_count}/${_results.length}");
|
||||
if (_count == _results.length)
|
||||
trigger(_results);
|
||||
}).error((ex){
|
||||
triggerError(ex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
library esiur;
|
||||
library esyur;
|
||||
|
||||
import 'AsyncReply.dart';
|
||||
|
||||
|
@ -107,18 +107,7 @@ class AsyncReply<T> implements Future<T>
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
AsyncReply<T> _then_old(Function(T) callback)
|
||||
{
|
||||
_callbacks.add(callback);
|
||||
|
||||
if (_resultReady)
|
||||
callback(result);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AsyncReply<T> error(Function(dynamic) callback)
|
||||
{
|
||||
_errorCallbacks.add(callback);
|
||||
|
@ -1,4 +1,4 @@
|
||||
// library esiur;
|
||||
// library esyur;
|
||||
|
||||
import 'IEventHandler.dart';
|
||||
|
||||
|
@ -493,10 +493,10 @@ class Codec
|
||||
return new AsyncReply<int>.ready(data.getUint64(offset));
|
||||
|
||||
case DataType.Float32:
|
||||
return new AsyncReply<int>.ready(data.getFloat32(offset));
|
||||
return new AsyncReply<double>.ready(data.getFloat32(offset));
|
||||
|
||||
case DataType.Float64:
|
||||
return new AsyncReply<int>.ready(data.getFloat64(offset));
|
||||
return new AsyncReply<double>.ready(data.getFloat64(offset));
|
||||
|
||||
case DataType.String:
|
||||
return new AsyncReply<String>.ready(data.getString(offset, contentLength));
|
||||
@ -649,6 +649,8 @@ class Codec
|
||||
/// <returns>Array of resources.</returns>
|
||||
static AsyncBag<IResource> parseResourceArray(DC data, int offset, int length, DistributedConnection connection)
|
||||
{
|
||||
//print("parseResourceArray ${offset} ${length}");
|
||||
|
||||
var reply = new AsyncBag<IResource>();
|
||||
if (length == 0)
|
||||
{
|
||||
@ -912,6 +914,9 @@ class Codec
|
||||
/// <returns></returns>
|
||||
static AsyncBag<PropertyValue> parsePropertyValueArray(DC data, int offset, int length, DistributedConnection connection)//, bool ageIncluded = true)
|
||||
{
|
||||
|
||||
//print("parsePropertyValueArray ${offset} ${length}");
|
||||
|
||||
var rt = new AsyncBag<PropertyValue>();
|
||||
|
||||
var sizeObject = new SizeObject();
|
||||
|
@ -341,14 +341,18 @@ class DistributedConnection extends NetworkConnection with IStore
|
||||
|
||||
if (rt <= 0)
|
||||
{
|
||||
// print("hold");
|
||||
var size = ends - offset;
|
||||
data.holdFor(msg, offset, size, size - rt);
|
||||
return ends;
|
||||
}
|
||||
else
|
||||
{
|
||||
//print("CMD ${packet.command} ${offset} ${ends}");
|
||||
|
||||
offset += rt;
|
||||
|
||||
|
||||
if (packet.command == IIPPacketCommand.Event)
|
||||
{
|
||||
switch (packet.event)
|
||||
@ -2158,15 +2162,23 @@ class DistributedConnection extends NetworkConnection with IStore
|
||||
var reply = new AsyncReply<DistributedResource>();
|
||||
_resourceRequests.add(id, reply);
|
||||
|
||||
//print("fetch ${id}");
|
||||
|
||||
sendRequest(IIPPacketAction.AttachResource)
|
||||
.addUint32(id)
|
||||
.done()
|
||||
.then((rt)
|
||||
{
|
||||
|
||||
//print("fetched ${id}");
|
||||
|
||||
var dr = new DistributedResource(this, id, rt[1], rt[2]);
|
||||
|
||||
|
||||
getTemplate(rt[0] as Guid).then((tmp)
|
||||
{
|
||||
//print("New template ");
|
||||
|
||||
// ClassId, ResourceAge, ResourceLink, Content
|
||||
Warehouse.put(dr, id.toString(), this, null, tmp);
|
||||
|
||||
@ -2174,6 +2186,7 @@ class DistributedConnection extends NetworkConnection with IStore
|
||||
|
||||
Codec.parsePropertyValueArray(d, 0, d.length, this).then((ar)
|
||||
{
|
||||
//print("attached");
|
||||
dr.attached(ar);
|
||||
_resourceRequests.remove(id);
|
||||
reply.trigger(dr);
|
||||
|
@ -80,7 +80,7 @@ class DistributedResource extends IResource
|
||||
/// <summary>
|
||||
/// Resource is attached when all its properties are received.
|
||||
/// </summary>
|
||||
bool get IsAttached => _isAttached;
|
||||
bool get isAttached => _isAttached;
|
||||
|
||||
|
||||
// public DistributedResourceStack Stack
|
||||
@ -185,6 +185,19 @@ class DistributedResource extends IResource
|
||||
return connection.sendInvokeByArrayArguments(_instanceId, index, args);
|
||||
}
|
||||
|
||||
operator [](String index)
|
||||
{
|
||||
var pt = instance.template.getPropertyTemplateByName(index);
|
||||
if (pt != null)
|
||||
return get(pt.index);
|
||||
}
|
||||
|
||||
operator []=(String index, value)
|
||||
{
|
||||
var pt = instance.template.getPropertyTemplateByName(index);
|
||||
if (pt != null)
|
||||
set(pt.index, value);
|
||||
}
|
||||
|
||||
String _getMemberName(Symbol symbol)
|
||||
{
|
||||
|
@ -91,6 +91,7 @@ class NetworkConnection extends IDestructible
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
// Unassigned ?
|
||||
if (_sock == null)
|
||||
return;
|
||||
@ -121,8 +122,10 @@ class NetworkConnection extends IDestructible
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
print(ex);
|
||||
//Global.Log("NetworkConnection", LogType.Warning, ex.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ISocket unassign()
|
||||
|
@ -86,8 +86,8 @@ class IIPPacket
|
||||
{
|
||||
if (offset + needed > ends)
|
||||
{
|
||||
//dataLengthNeeded = needed - (ends - offset);
|
||||
_dataLengthNeeded = needed - (ends - _originalOffset);
|
||||
_dataLengthNeeded = needed - (ends - offset);
|
||||
//_dataLengthNeeded = (needed - (ends - offset)) + (offset - _originalOffset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ class TCPSocket extends ISocket
|
||||
if (_state == SocketState.Closed || _state == SocketState.Terminated)
|
||||
return;
|
||||
|
||||
|
||||
var dc = new DC.fromList(data);
|
||||
receiveNetworkBuffer.write(dc, 0, dc.length);
|
||||
emitArgs("receive", [receiveNetworkBuffer]);
|
||||
|
189
lib/src/Net/Sockets/Websocket.dart
Normal file
189
lib/src/Net/Sockets/Websocket.dart
Normal file
@ -0,0 +1,189 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2019 Ahmed Kh. Zamil
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
import 'dart:io';
|
||||
import 'ISocket.dart';
|
||||
import '../../Data/DC.dart';
|
||||
import '../NetworkBuffer.dart';
|
||||
import 'SocketState.dart';
|
||||
import 'IPEndPoint.dart';
|
||||
import '../../Core/AsyncReply.dart';
|
||||
|
||||
import 'package:web_socket_channel/io.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
import 'package:web_socket_channel/status.dart' as status;
|
||||
|
||||
class WSSocket extends ISocket
|
||||
{
|
||||
WebSocketChannel sock;
|
||||
|
||||
NetworkBuffer receiveNetworkBuffer = new NetworkBuffer();
|
||||
|
||||
bool began = false;
|
||||
|
||||
SocketState _state = SocketState.Initial;
|
||||
|
||||
|
||||
IPEndPoint _localEP, _remoteEP;
|
||||
|
||||
bool begin()
|
||||
{
|
||||
if (began)
|
||||
return false;
|
||||
|
||||
began = true;
|
||||
|
||||
_localEP = IPEndPoint(sock. address.rawAddress, sock.port);
|
||||
_remoteEP = IPEndPoint(sock.remoteAddress.rawAddress, sock.remotePort);
|
||||
return true;
|
||||
}
|
||||
|
||||
void dataHandler(List<int> data){
|
||||
//print(new String.fromCharCodes(data).trim());
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (_state == SocketState.Closed || _state == SocketState.Terminated)
|
||||
return;
|
||||
|
||||
|
||||
var dc = new DC.fromList(data);
|
||||
receiveNetworkBuffer.write(dc, 0, dc.length);
|
||||
emitArgs("receive", [receiveNetworkBuffer]);
|
||||
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
if (_state != SocketState.Closed)// && !sock.connected)
|
||||
{
|
||||
_state = SocketState.Terminated;
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void errorHandler(error, StackTrace trace){
|
||||
print(error);
|
||||
}
|
||||
|
||||
void doneHandler(){
|
||||
sock.destroy();
|
||||
}
|
||||
|
||||
|
||||
AsyncReply<bool> connect(String hostname, int port)
|
||||
{
|
||||
var rt = new AsyncReply<bool>();
|
||||
|
||||
try
|
||||
{
|
||||
_state = SocketState.Connecting;
|
||||
|
||||
WebSocket()
|
||||
prefix0.WebSocket(url)
|
||||
IOWebSocketChannel.
|
||||
Socket.connect(hostname, port).then((s){
|
||||
sock = s;
|
||||
s.listen(dataHandler,
|
||||
onError: errorHandler,
|
||||
onDone: doneHandler,
|
||||
cancelOnError: false);
|
||||
_state = SocketState.Established;
|
||||
emitArgs("connect", []);
|
||||
begin();
|
||||
rt.trigger(true);
|
||||
|
||||
}).catchError((ex){
|
||||
close();
|
||||
rt.triggerError(ex);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
rt.triggerError(ex);
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
IPEndPoint get localEndPoint => _localEP;
|
||||
IPEndPoint get remoteEndPoint => _remoteEP;
|
||||
|
||||
|
||||
SocketState get state => _state;
|
||||
|
||||
|
||||
TCPSocket.fromSocket(Socket socket)
|
||||
{
|
||||
sock = socket;
|
||||
//if (socket.)
|
||||
// _state = SocketState.Established;
|
||||
}
|
||||
|
||||
TCPSocket()
|
||||
{
|
||||
// default constructor
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
if (state != SocketState.Closed && state != SocketState.Terminated)
|
||||
_state = SocketState.Closed;
|
||||
|
||||
sock?.close();
|
||||
|
||||
emitArgs("close", []);
|
||||
}
|
||||
|
||||
|
||||
void send(DC message, [int offset, int size])
|
||||
{
|
||||
if (state == SocketState.Established)
|
||||
sock.add(message.toList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy()
|
||||
{
|
||||
close();
|
||||
emitArgs("destroy", [this]);
|
||||
}
|
||||
|
||||
AsyncReply<ISocket> accept()
|
||||
{
|
||||
|
||||
|
||||
var reply = new AsyncReply<ISocket>();
|
||||
return reply;
|
||||
}
|
||||
}
|
@ -433,6 +433,7 @@ class Instance extends IEventHandler
|
||||
}
|
||||
|
||||
emitArgs("resourceModified", [_resource, pt.name, value]);
|
||||
_resource.emitArgs("modified", [pt.name, value]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user