2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-05-06 12:32:58 +00:00
This commit is contained in:
Ahmed Zamil 2020-04-30 09:26:58 +03:00
parent 98877b9b85
commit 5967d6c901
19 changed files with 2102 additions and 1784 deletions

View File

@ -1,6 +1,10 @@
{ {
"presets": ["@babel/preset-env"], "presets": [
"plugins": [ [
"@babel/preset-env", { "useBuiltIns": "entry" }
]
],
"plugins": [
["@babel/transform-runtime"] ["@babel/transform-runtime"]
] ]
} }

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2017 Esi Ur Copyright (c) 2017-2020 Esyur
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

File diff suppressed because it is too large Load Diff

View File

@ -5,3 +5,4 @@ exports.printMsg = function() {
module.exports = { wh }; module.exports = { wh };
let WebSocket = require('ws') let WebSocket = require('ws')

1091
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "esyur", "name": "esyur",
"version": "1.4.0", "version": "1.4.6",
"description": "Distributed Object Framework", "description": "Distributed Object Framework",
"main": "esyur.js", "main": "esyur.js",
"scripts": { "scripts": {
@ -19,14 +19,15 @@
}, },
"homepage": "https://github.com/esyur/esyur-js#readme", "homepage": "https://github.com/esyur/esyur-js#readme",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.7.7", "@babel/polyfill": "^7.8.3",
"ws": "^6.2.0" "@babel/runtime": "^7.8.4",
"ws": "^6.2.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.7.7", "@babel/cli": "^7.8.4",
"@babel/core": "^7.7.7", "@babel/core": "^7.8.6",
"@babel/plugin-transform-runtime": "^7.7.6", "@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.7.7", "@babel/preset-env": "^7.8.6",
"babel-cli": "^6.0.0", "babel-cli": "^6.0.0",
"babelify": "^10.0.0", "babelify": "^10.0.0",
"browserify": "^16.5.0" "browserify": "^16.5.0"

View File

@ -40,12 +40,20 @@ export default class AsyncQueue extends AsyncReply
this.processQueue = function () this.processQueue = function ()
{ {
for (var i = 0; i < self.list.length; i++) for (var i = 0; i < self.list.length; i++)
if (self.list[i].ready) if (self.list[i].ready) {
{
self.trigger(self.list[i].result); self.trigger(self.list[i].result);
self.list.splice(i, 1); self.ready = false;
//self.list.splice(i, 1);
self.list.shift();
i--; i--;
} }
else if (self.list[i].failed) {
self.ready = false;
self.list.shift();
i--;
console.log("AsyncQueue (Reply Failed)");
}
else else
break; break;
@ -57,11 +65,13 @@ export default class AsyncQueue extends AsyncReply
{ {
this.list.push(reply); this.list.push(reply);
this.ready = false; this.ready = false;
reply.then(this.processQueue); reply.then(this.processQueue).error(this.processQueue);
} }
remove(reply) remove(reply)
{ {
console.log("REMOVE QUEUE");
this.list.splice(this.list.indexOf(reply), 1); this.list.splice(this.list.indexOf(reply), 1);
this.processQueue(); this.processQueue();
} }

View File

@ -72,6 +72,7 @@ export default class IEventHandler
return this; return this;
} }
off(event, fn) off(event, fn)
{ {
event = event.toLocaleString(); event = event.toLocaleString();

View File

@ -295,45 +295,64 @@ export default class DC extends Uint8Array
return new Uint8Array(this.buffer, offset, length); return new Uint8Array(this.buffer, offset, length);
} }
copy(offset, length, elementSize, func, dstType)
{
let rt = new dstType(length / elementSize);
let d = 0, end = offset + length;
for (let i = offset; i < end; i += elementSize)
rt[d++] = func.call(this, i);
return rt;
}
getInt16Array(offset, length) getInt16Array(offset, length)
{ {
return new Int16Array(this.clip(offset, length).buffer); return this.copy(offset, length, 2, this.getInt16, Int16Array);
//return new Int16Array(this.clip(offset, length).buffer);
} }
getUint16Array(offset, length) getUint16Array(offset, length)
{ {
return new Uint16Array(this.clip(offset, length).buffer); return this.copy(offset, length, 2, this.getUint16, Uint16Array);
//return new Uint16Array(this.clip(offset, length).buffer);
} }
getInt32Array(offset, length) getInt32Array(offset, length)
{ {
return new Int32Array(this.clip(offset, length).buffer); return this.copy(offset, length, 4, this.getInt32, Int32Array);
//return new Int32Array(this.clip(offset, length).buffer);
} }
getUint32Array(offset, length) getUint32Array(offset, length)
{ {
return new Uint32Array(this.clip(offset, length).buffer); return this.copy(offset, length, 4, this.getUint32, Uint32Array);
//return new Uint32Array(this.clip(offset, length).buffer);
} }
getFloat32Array(offset, length) getFloat32Array(offset, length)
{ {
return new Float32Array(this.clip(offset, length).buffer); return this.copy(offset, length, 4, this.getFloat32, Float32Array);
//return new Float32Array(this.clip(offset, length).buffer);
} }
getFloat64Array(offset, length) getFloat64Array(offset, length)
{ {
return new Float64Array(this.clip(offset, length).buffer); return this.copy(offset, length, 8, this.getFloat64, Float64Array);
// return new Float64Array(this.clip(offset, length).buffer);
} }
getInt64Array(offset, length) getInt64Array(offset, length)
{ {
return new Int64Array(this.clip(offset, length).buffer); return this.copy(offset, length, 8, this.getInt64, BigInt64Array);
//return new Int64Array(this.clip(offset, length).buffer);
} }
getUint64Array(offset, length) getUint64Array(offset, length)
{ {
return new Uint64Array(this.clip(offset, length).buffer); return this.copy(offset, length, 8, this.getUint64, BigUint64Array);
//return new Uint64Array(this.clip(offset, length).buffer);
} }
getBoolean(offset) getBoolean(offset)

View File

@ -92,6 +92,11 @@ export default class KeyList
return false; return false;
} }
containsKey(key)
{
return this.contains(key);
}
set(key, value) set(key, value)
{ {
this.remove(key); this.remove(key);

File diff suppressed because it is too large Load Diff

View File

@ -37,15 +37,24 @@ export default class DistributedResource extends IResource
destroy() destroy()
{ {
this.destroyed = true; this.destroyed = true;
this._p.attached = false;
this._p.connection.sendDetachRequest(this._p.instanceId);
this._emit("destroy", this); this._emit("destroy", this);
} }
_suspend()
{
this._p.suspended = true;
this._p.attached = false;
}
constructor(connection, instanceId, age, link) constructor(connection, instanceId, age, link)
{ {
super(); super();
this._p = { this._p = {
isAttached: false, suspended: false,
attached: false,
connection: connection, connection: connection,
instanceId: instanceId, instanceId: instanceId,
age: age, age: age,
@ -66,13 +75,16 @@ export default class DistributedResource extends IResource
return props; return props;
} }
_attached(properties) _attach(properties)
{ {
if (this._isAttached) if (this._p.attached)
return false; return false;
else else
{ {
this._p.suspended = false;
for(var i = 0; i < properties.length; i++) for(var i = 0; i < properties.length; i++)
{ {
this.instance.setAge(i, properties[i].age); this.instance.setAge(i, properties[i].age);
@ -81,7 +93,7 @@ export default class DistributedResource extends IResource
} }
this._p.isAttached = true; this._p.attached = true;
var self = this; var self = this;
@ -154,6 +166,9 @@ export default class DistributedResource extends IResource
if (this.destroyed) if (this.destroyed)
throw new Error("Trying to access destroyed object"); throw new Error("Trying to access destroyed object");
if (this._p.suspended)
throw new Error("Trying to access suspended object");
if (index >= this.instance.template.functions.length) if (index >= this.instance.template.functions.length)
throw new Error("Function index is incorrect"); throw new Error("Function index is incorrect");
@ -164,6 +179,9 @@ export default class DistributedResource extends IResource
if (this.destroyed) if (this.destroyed)
throw new Error("Trying to access destroyed object"); throw new Error("Trying to access destroyed object");
if (this._p.suspended)
throw new Error("Trying to access suspended object");
if (index >= this.instance.template.functions.length) if (index >= this.instance.template.functions.length)
throw new Error("Function index is incorrect"); throw new Error("Function index is incorrect");

View File

@ -189,6 +189,9 @@ export default class IIPPacket
var cl = data.getUint32(offset); var cl = data.getUint32(offset);
offset += 4; offset += 4;
if (this.notEnough(offset, ends, cl))
return -this.dataLengthNeeded;
this.content = data.clip(offset, cl); this.content = data.clip(offset, cl);
offset += cl; offset += cl;
} }

View File

@ -137,7 +137,8 @@ export default class Instance extends IEventHandler
this.store.record(this.resource, pt.name, value, this.ages[pt.index], now); this.store.record(this.resource, pt.name, value, this.ages[pt.index], now);
super._emit("ResourceModified", this.resource, pt.name, value); super._emit("ResourceModified", this.resource, pt.name, value);
this.resource._emit("modified", pt.name, value); //this.resource._emit("modified", pt.name, value);
this.resource._emit(":" + pt.name, value);
} }
modified(propertyName = null) modified(propertyName = null)

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2017 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.
*/
/**
* Created by Ahmed Zamil on 9/2/2017.
*/
"use strict";
export default // ActionType =
{
Attach: 0,
Delete: 1,
Execute: 2,
GetProperty: 3,
SetProperty: 4,
CreateResource: 5,
UpdateAttributes: 6,
InquireAttributes: 7,
AddParent: 8,
RemoveParent: 9,
AddChild: 10,
RemoveChild: 11,
Rename: 12,
ReceiveEvent: 13
};

View File

@ -26,30 +26,6 @@
"use strict"; "use strict";
export const ActionType =
{
Attach: 0,
Delete: 1,
Execute: 2,
GetProperty: 3,
SetProperty: 4,
CreateResource: 5,
UpdateAttributes: 6,
InquireAttributes: 7,
AddParent: 8,
RemoveParent: 9,
AddChild: 10,
RemoveChild: 11,
Rename: 12,
ReceiveEvent: 13
};
export const Ruling = {
Denied: 0,
Allowed: 1,
DontCare: 2,
};
export default class IPermissionsManager export default class IPermissionsManager
{ {
/// <summary> /// <summary>

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2017 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.
*/
/**
* Created by Ahmed Zamil on 9/2/2020.
*/
"use strict";
export default //Ruling =
{
Denied: 0,
Allowed: 1,
DontCare: 2,
};

View File

@ -2,11 +2,24 @@
import wh from './Resource/Warehouse.js'; import wh from './Resource/Warehouse.js';
import Structure from './Data/Structure.js'; import Structure from './Data/Structure.js';
import DistributedResource from './Net/IIP/DistributedResource.js' import DistributedResource from './Net/IIP/DistributedResource.js'
import MemoryStore from './Stores/MemoryStore.js';
import IResource from './Resource/IResource.js';
if (window) { if (window) {
window.wh = wh; window.wh = wh;
window.Structure = Structure; window.Structure = Structure;
window.DistributedResource = DistributedResource; window.DistributedResource = DistributedResource;
window.MemoryStore = MemoryStore;
window.IResource = IResource;
}
else if (global)
{
global.wh = wh;
global.Structure = Structure;
global.DistributedResource = DistributedResource;
global.MemoryStore = MemoryStore;
global.IResource = IResource;
} }
export default wh; export default wh;