From 8959f52f6ef6f9dc4d8d81d5d44c818170637708 Mon Sep 17 00:00:00 2001 From: Esiur Project Date: Tue, 30 Aug 2022 22:27:25 +0300 Subject: [PATCH] Sync/Async setters --- bin/esiur.dart | 25 ++++++++----------- lib/src/Net/IIP/DistributedConnection.dart | 6 ++++- lib/src/Proxy/TemplateGenerator.dart | 28 ++++++++++++---------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/bin/esiur.dart b/bin/esiur.dart index cb1f299..101c2a2 100644 --- a/bin/esiur.dart +++ b/bin/esiur.dart @@ -24,16 +24,12 @@ void main(List arguments) async { ..addOption('username', abbr: 'u') ..addOption('password', abbr: 'p') ..addOption('dir', abbr: 'd') + ..addFlag('sync', abbr: 's', defaultsTo: false) ..addFlag( "getx", abbr: 'x', defaultsTo: false, - help: "Generate apropriate getx bindings for resources", - ) - ..addFlag( - "namedargs", - help: - "Use named arguments instead of positional arguments for resource methods", + help: "Generate apropriate getx bindings for resources.", ); var results = parser.parse(arguments.skip(2)); @@ -45,14 +41,12 @@ void main(List arguments) async { //print("Username ${username} password ${password} dir ${dir}"); // make template - var destDir = await TemplateGenerator.getTemplate( - link, - dir: dir, - username: username, - password: password, - getx: results['getx'], - namedArgs: results["namedargs"], - ); + var destDir = await TemplateGenerator.getTemplate(link, + dir: dir, + username: username, + password: password, + getx: results['getx'], + asyncSetters: !results['sync']); print("Generated directory `${destDir}`"); @@ -72,12 +66,13 @@ void printUsage() { print(""); print("Available commands:"); print("\tget-template\tGet a template from an IIP link."); - print("\tversion: print esiur version."); + print("\tversion: Print Esiur version."); print(""); print("Global options:"); print("\t-u, --username\tAuthentication username"); print("\t-p, --password\tAuthentication password"); print("\t-d, --dir\tName of the directory to generate model inside."); + print("\t-s, --async\tSynchronous property setters."); } void printVersion() async { diff --git a/lib/src/Net/IIP/DistributedConnection.dart b/lib/src/Net/IIP/DistributedConnection.dart index ea5445d..2529f50 100644 --- a/lib/src/Net/IIP/DistributedConnection.dart +++ b/lib/src/Net/IIP/DistributedConnection.dart @@ -443,13 +443,17 @@ class DistributedConnection extends NetworkConnection with IStore { if (dataType.identifier == TransmissionTypeIdentifier.ResourceList) { + // remove from suspended. + _suspendedResources.remove(r.distributedResourceInstanceId); + // parse them as int var id = data.getUint32(8); + + // id changed ? if (id != r.distributedResourceInstanceId) r.distributedResourceInstanceId = id; _neededResources[id] = r; - _suspendedResources.remove(id); await fetch(id, null); } diff --git a/lib/src/Proxy/TemplateGenerator.dart b/lib/src/Proxy/TemplateGenerator.dart index c923d79..1e0d4f0 100644 --- a/lib/src/Proxy/TemplateGenerator.dart +++ b/lib/src/Proxy/TemplateGenerator.dart @@ -266,14 +266,12 @@ class TemplateGenerator { return v == null || v == ""; } - static Future getTemplate( - String url, { - String? dir, - String? username, - String? password, - bool getx = false, - bool namedArgs = false, - }) async { + static Future getTemplate(String url, + {String? dir, + String? username, + String? password, + bool getx = false, + bool asyncSetters = true}) async { try { if (!_urlRegex.hasMatch(url)) throw Exception("Invalid IIP URL"); @@ -328,7 +326,8 @@ class TemplateGenerator { var source = ""; if (tmp.type == TemplateType.Resource) { source = makeImports(tmp) + - generateClass(tmp, templates, getx: getx, namedArgs: namedArgs); + generateClass(tmp, templates, + getx: getx, asyncSetters: asyncSetters); } else if (tmp.type == TemplateType.Record) { source = makeImports(tmp) + generateRecord(tmp, templates); } else if (tmp.type == TemplateType.Enum) { @@ -418,7 +417,7 @@ class TemplateGenerator { TypeTemplate template, List templates, { bool getx = false, - bool namedArgs = false, + bool asyncSetters = true, }) { var className = template.className.split('.').last; @@ -520,8 +519,13 @@ class TemplateGenerator { template.properties.where((p) => !p.inherited).forEach((p) { var ptTypeName = getTypeName(template, p.valueType, templates); rt.writeln("${ptTypeName} get ${p.name} { return get(${p.index}); }"); - rt.writeln( - "set ${p.name}(${ptTypeName} value) { setSync(${p.index}, value); }"); + + if (asyncSetters) + rt.writeln( + "set ${p.name}(${ptTypeName} value) { set(${p.index}, value); }"); + else + rt.writeln( + "set ${p.name}(${ptTypeName} value) { setSync(${p.index}, value); }"); }); template.events.where((e) => !e.inherited).forEach((e) {