diff options
author | 2024-08-13 17:23:45 +0200 | |
---|---|---|
committer | 2024-09-10 19:52:10 +0000 | |
commit | a2dcd701777968a65d3176eaf28aa7023d97c16b (patch) | |
tree | 65a5861430a1fde81160cd116fd70fba40cd1fb3 /lib/data/data_providers/storage_client.dart | |
parent | d3ea8d7fa4518c258fca3c825ee895487fcaa8ec (diff) |
Implementation of Persistent Storage API to the flutter homescreen
Added protobuf definition of Persistent Storage API.
Generated grpc-compliant code from protobuf API definition.
Set up storage_client based on similar radio_client.
Updated app_confi_provider and app_provider to include new API features
and prepare for implementation of persistent storage of users, user
preferences.
Added unit tests for all API rpcs.
Bug-AGL: [SPEC-5227]
Change-Id: I759501bcb9de3a70a14718f8b3a87bedcf811baa
Signed-off-by: Tom Kronsbein <tom.kronsbein@d-fine.com>
Signed-off-by: Ludwig Schwiedrzik <ludwig.schwiedrzik@d-fine.com>
Diffstat (limited to 'lib/data/data_providers/storage_client.dart')
-rw-r--r-- | lib/data/data_providers/storage_client.dart | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/data/data_providers/storage_client.dart b/lib/data/data_providers/storage_client.dart new file mode 100644 index 0000000..5c72785 --- /dev/null +++ b/lib/data/data_providers/storage_client.dart @@ -0,0 +1,89 @@ +import 'package:flutter_ics_homescreen/export.dart'; +import 'package:protos/storage-api.dart' as storage_api; + +class StorageClient{ + final StorageConfig config; + final Ref ref; + late storage_api.ClientChannel channel; + late storage_api.DatabaseClient stub; + + StorageClient({required this.config, required this.ref}) { + debugPrint( + "Connecting to storage service at ${config.hostname}:${config.port}"); + storage_api.ChannelCredentials creds = const storage_api.ChannelCredentials.insecure(); + channel = storage_api.ClientChannel(config.hostname, + port: config.port, options: storage_api.ChannelOptions(credentials: creds)); + stub = storage_api.DatabaseClient(channel); + } + + + Future<storage_api.StandardResponse> destroyDB() async { + try { + var response = await stub.destroyDB(storage_api.DestroyArguments()); + return response; + } catch (e) { + print(e); + rethrow; + } + } + + Future<storage_api.StandardResponse> write(storage_api.KeyValue keyValue) async { + try { + var response = await stub.write(keyValue); + return response; + } catch (e) { + print(e); + rethrow; + } + } + + Future<storage_api.ReadResponse> read(storage_api.Key key) async{ + try{ + var response = await stub.read(key); + return response; + } catch(e) { + print(e); + rethrow; + } + } + + Future<storage_api.StandardResponse> delete(storage_api.Key key) async{ + try{ + var response = await stub.delete(key); + return response; + } catch(e) { + print(e); + rethrow; + } + } + + Future<storage_api.ListResponse> search(storage_api.Key key) async{ + try{ + var response = await stub.search(key); + return response; + } catch(e) { + print(e); + rethrow; + } + } + + Future<storage_api.StandardResponse> deleteNodes(storage_api.Key key) async{ + try{ + var response = await stub.deleteNodes(key); + return response; + } catch(e) { + print(e); + rethrow; + } + } + + Future<storage_api.ListResponse> listNodes(storage_api.SubtreeInfo subtreeInfo) async{ + try{ + var response = await stub.listNodes(subtreeInfo); + return response; + } catch(e) { + print(e); + rethrow; + } + } +}
\ No newline at end of file |