mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-05-06 12:02:57 +00:00
Rename
This commit is contained in:
parent
5886cbbdac
commit
9c15b830dd
@ -1,7 +1,7 @@
|
||||
# Esiur
|
||||
# Esyur
|
||||
Distributed Object Framework
|
||||
|
||||
## Getting Started
|
||||
For help getting started with Esiur, view our
|
||||
[online documentation](https://esiur.com), which offers tutorials,
|
||||
For help getting started with Esyur, view our
|
||||
[online documentation](http://www.esyur.com), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
|
@ -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';
|
||||
|
||||
|
@ -108,17 +108,6 @@ 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>
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Generated by pub
|
||||
# See https://www.dartlang.org/tools/pub/glossary#lockfile
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
|
@ -1,8 +1,8 @@
|
||||
name: esiur
|
||||
name: esyur
|
||||
description: Distributed Object Framework.
|
||||
version: 1.0.0
|
||||
version: 1.0.5
|
||||
author: Ahmed Zamil <ahmed@dijlh.com>
|
||||
homepage: https://github.com/esiur/esiur-dart
|
||||
homepage: https://github.com/esyur/esyur-dart
|
||||
|
||||
environment:
|
||||
sdk: ">=2.1.0 <3.0.0"
|
||||
|
@ -1,13 +1,18 @@
|
||||
import "package:test/test.dart";
|
||||
import 'package:esiur/esiur.dart';
|
||||
import 'package:esyur/esyur.dart';
|
||||
import 'dart:io';
|
||||
|
||||
main()
|
||||
{
|
||||
test("Connect to server", () async {
|
||||
|
||||
|
||||
// connect to the server
|
||||
var x = await Warehouse.get("iip://localhost:5000/db/my", {"username": "demo", "password": "1234"});
|
||||
|
||||
// x.instance.store.on("close", ()=>print("Closed"));
|
||||
|
||||
|
||||
// get property
|
||||
print(x.Level);
|
||||
// listen to event
|
||||
@ -17,10 +22,54 @@ main()
|
||||
// use named arguments
|
||||
print(await x.Add(value: 20));
|
||||
// test chunks
|
||||
x.Stream(10).chunk((c)=>print(c));
|
||||
//x.Stream(10).chunk((c)=>print(c));
|
||||
// property setter
|
||||
x.Level += 900;
|
||||
//x.Level += 900;
|
||||
|
||||
|
||||
//var msg = await stdin.readLineSync();
|
||||
|
||||
print("Done");
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// describe object
|
||||
desc(dynamic x) {
|
||||
if (x is List)
|
||||
{
|
||||
for(var i = 0; i < x.length; i++)
|
||||
desc(x[i]);
|
||||
}
|
||||
else if (x is DistributedResource)
|
||||
{
|
||||
var y = x.instance.template;
|
||||
print("Fucntions = ${y.functions.length}\n");
|
||||
for (var i = 0; i < y.functions.length; i++) {
|
||||
print("name = ${y.functions[i].name}");
|
||||
print("args = ${y.functions[i].expansion}");
|
||||
}
|
||||
print("------------------------------\n");
|
||||
print("Events = ${y.events.length}\n");
|
||||
for (var i = 0; i < y.events.length; i++) {
|
||||
print("name = ${y.events[i].name}");
|
||||
print("args = ${y.events[i].expansion}");
|
||||
}
|
||||
|
||||
print("------------------------------\n");
|
||||
print("Properties = ${y.properties.length}\n");
|
||||
for (var i = 0; i < y.properties.length; i++) {
|
||||
print("name = ${y.properties[i].name}");
|
||||
// recursion
|
||||
print("value = ${desc(x.get(y.properties[i].index))}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print(x.toString());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user