diff --git a/.gitignore b/.gitignore index 4b54aaaf4..bca0c02b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -.dart_tool/ -.packages -build/ -pubspec.lock -objectbox/ +**/.dart_tool/ +**/.packages +**/build/ +**/pubspec.lock misc/ -.idea/ \ No newline at end of file +.idea/ +**/*.g.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 101313ccc..67978c4ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,14 @@ +0.2.0 (2019-09-11) +------------------ +* UTF-8 support for Store and Box (thanks to [Buggaboo](https://github.com/Buggaboo) for [#14](https://github.com/objectbox/objectbox-dart/pull/14)!) +* Bulk put and get functions (getMany, getAll, putMany) +* Updated to objectbox-c 0.7 +* Basic Store options +* Minimal unit tests +* Removed reflection code, switched to model code generation instead +* Minimal Flutter Desktop example for Dart 2.5.0 + 0.1.0 (2019-09-03) ------------------ * Minimal Store setup -* Minimal Box with put and get \ No newline at end of file +* Minimal Box with put and get diff --git a/README.md b/README.md index c310559d3..106595d87 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,10 @@ Getting started --------------- To try out the demo code in this repository, follow these steps: -1. Install [objectbox-c](https://github.com/objectbox/objectbox-c) system-wide: `bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh)` (answer Y when it asks about installing to /usr/lib). -2. Back in this repository, run `pub get` to download all Dart dependencies. -3. Finally run `dart test/test.dart` to start the demo script. - Note that, as fairly recent language features are used, the minimal required Dart version is 2.2.2. +1. Install [objectbox-c](https://github.com/objectbox/objectbox-c) system-wide: `bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh) 0.7` (answer Y when it asks about installing to /usr/lib). +2. Back in this repository, run `pub get` in each of the following directories: `objectbox`, `objectbox_model_generator`, `objectbox_test`. If you just want to try out the tests, running it in `objectbox_test` is enough. +3. Move into the `objectbox_test` directory and execute `pub run build_runner build`. This regenerates the ObjectBox model to make it usable in Dart (i.e. the file `test/test.g.dart`) and is necessary each time you add or change a class annotated with `@Entity(...)`. +4. Finally run `pub run test test/test.dart` to run the unit tests. Dart integration ---------------- @@ -59,14 +59,15 @@ New (not yet persisted) objects typically have _Id_ value of `0` or `null`: call *Note:* specifying the (meta model) IDs in annotations manually is a temporary quick solution. In a later version, you won't have to do this the and e.g. `@Property(id: 2, uid: 1002)` can be dropped completely. -Technically, we need to setup [build time tools for Dart](https://github.com/objectbox/objectbox-dart/issues/3) for automatic management of the meta model IDs. +As specified in step 3 of the _Getting started_ section, Dart's _build\_runner_ and _source\_gen_ are currently used and the generator will be extended to automatically manage the meta model IDs in the future. ```dart import "../lib/objectbox.dart"; +part "test.g.dart"; @Entity(id: 1, uid: 1) class Note { - @Id(id: 1, uid: 1001, type: Type.Long) + @Id(id: 1, uid: 1001) // automatically always 'int' in Dart code and 'Long' in ObjectBox int id; @Property(id: 2, uid: 1002) @@ -74,22 +75,21 @@ class Note { Note(); // empty default constructor needed Note.construct(this.text); - toString() => "Note{id: $id, text: $text}"; } ``` -In your main function, you can then create a _store_ which needs an array of your entity classes to be constructed. +In your main function, you can then create a _store_ which needs an array of your entity classes and definitions to be constructed. If you have several entities, construct your store like `Store([[Entity1, Entity1_OBXDefs], [Entity2, Entity2_OBXDefs]])` etc. Finally, you need a _box_, representing the interface for objects of one specific entity type. ```dart -var store = Store([Note]); +var store = Store([[Note, Note_OBXDefs]]); var box = Box(store); -var note = Note("Hello"); -box.put(note); +var note = Note.construct("Hello"); +note.id = box.put(note); print("new note got id ${note.id}"); -print("refetched note: ${box.getById(note.id)}"); +print("refetched note: ${box.get(note.id)}"); store.close(); ``` diff --git a/bin/objectbox_model_generator/build.yaml b/bin/objectbox_model_generator/build.yaml new file mode 100644 index 000000000..904ccd5df --- /dev/null +++ b/bin/objectbox_model_generator/build.yaml @@ -0,0 +1,15 @@ +targets: + $default: + builders: + objectbox_model_generator|objectbox: + enabled: true + +builders: + objectbox: + target: ":objectbox_model_generator" + import: "package:objectbox_model_generator/builder.dart" + builder_factories: ["objectboxModelFactory"] + build_extensions: {".dart": [".objectbox_model.g.part"]} + auto_apply: dependents + build_to: cache + applies_builders: ["source_gen|combining_builder"] diff --git a/bin/objectbox_model_generator/lib/builder.dart b/bin/objectbox_model_generator/lib/builder.dart new file mode 100644 index 000000000..3ccfc8fb0 --- /dev/null +++ b/bin/objectbox_model_generator/lib/builder.dart @@ -0,0 +1,6 @@ +import "package:build/build.dart"; +import "package:source_gen/source_gen.dart"; +import "package:objectbox_model_generator/src/generator.dart"; + +Builder objectboxModelFactory(BuilderOptions options) => + SharedPartBuilder([EntityGenerator()], "objectbox_model"); diff --git a/bin/objectbox_model_generator/lib/src/generator.dart b/bin/objectbox_model_generator/lib/src/generator.dart new file mode 100644 index 000000000..7825122d6 --- /dev/null +++ b/bin/objectbox_model_generator/lib/src/generator.dart @@ -0,0 +1,122 @@ +import "dart:async"; +import "package:analyzer/dart/element/element.dart"; +import "package:build/src/builder/build_step.dart"; +import "package:source_gen/source_gen.dart"; + +import "package:objectbox/objectbox.dart"; +import "package:objectbox/src/bindings/constants.dart"; + +class EntityGenerator extends GeneratorForAnnotation { + @override + FutureOr generateForAnnotatedElement(Element elementBare, ConstantReader annotation, BuildStep buildStep) { + if(elementBare is! ClassElement) + throw InvalidGenerationSourceError("in target ${elementBare.name}: annotated element isn't a class"); + + // get basic entity info + var entity = Entity(id: annotation.read('id').intValue, uid: annotation.read('uid').intValue); + var element = elementBare as ClassElement; + var ret = """ + const _${element.name}_OBXModel = { + "entity": { + "name": "${element.name}", + "id": ${entity.id}, + "uid": ${entity.uid} + }, + "properties": [ + """; + + // read all suitable annotated properties + var props = []; + String idPropertyName; + for(var f in element.fields) { + if(f.metadata == null || f.metadata.length != 1) // skip unannotated fields + continue; + var annotElmt = f.metadata[0].element as ConstructorElement; + var annotType = annotElmt.returnType.toString(); + var annotVal = f.metadata[0].computeConstantValue(); + var fieldTypeObj = annotVal.getField("type"); + int fieldType = fieldTypeObj == null ? null : fieldTypeObj.toIntValue(); + + var prop = { + "name": f.name, + "id": annotVal.getField("id").toIntValue(), + "uid": annotVal.getField("uid").toIntValue(), + "flags": 0, + }; + + if(annotType == "Id") { + if(idPropertyName != null) + throw InvalidGenerationSourceError("in target ${elementBare.name}: has more than one properties annotated with @Id"); + if(fieldType != null) + throw InvalidGenerationSourceError("in target ${elementBare.name}: programming error: @Id property may not specify a type"); + if(f.type.toString() != "int") + throw InvalidGenerationSourceError("in target ${elementBare.name}: field with @Id property has type '${f.type.toString()}', but it must be 'int'"); + + fieldType = OBXPropertyType.Long; + prop["flags"] = OBXPropertyFlag.ID; + idPropertyName = f.name; + } else if(annotType == "Property") { + // nothing special here + } else { + // skip unknown annotations + continue; + } + + if(fieldType == null) { + var fieldTypeStr = f.type.toString(); + if(fieldTypeStr == "int") + fieldType = OBXPropertyType.Int; + else if(fieldTypeStr == "String") + fieldType = OBXPropertyType.String; + else { + print("warning: skipping field '${f.name}' in entity '${element.name}', as it has the unsupported type '$fieldTypeStr'"); + continue; + } + } + + prop["type"] = fieldType; + props.add(prop); + ret += """ + { + "name": "${prop['name']}", + "id": ${prop['id']}, + "uid": ${prop['uid']}, + "type": ${prop['type']}, + "flags": ${prop['flags']}, + "flatbuffers_id": ${(prop['id'] as int) - 1}, + }, + """; + } + + // some checks on the entity's integrity + if(idPropertyName == null) + throw InvalidGenerationSourceError("in target ${elementBare.name}: has no properties annotated with @Id"); + + // main code for instance builders and readers + ret += """ + ], + "idPropertyName": "${idPropertyName}", + }; + + ${element.name} _${element.name}_OBXBuilder(Map members) { + ${element.name} r = new ${element.name}(); + ${props.map((p) => "r.${p['name']} = members[\"${p['name']}\"];").join()} + return r; + } + + Map _${element.name}_OBXReader(${element.name} inst) { + Map r = {}; + ${props.map((p) => "r[\"${p['name']}\"] = inst.${p['name']};").join()} + return r; + } + + const ${element.name}_OBXDefs = { + "model": _${element.name}_OBXModel, + "builder": _${element.name}_OBXBuilder, + "reader": _${element.name}_OBXReader, + }; + """; + + return ret; + } +} diff --git a/bin/objectbox_model_generator/pubspec.yaml b/bin/objectbox_model_generator/pubspec.yaml new file mode 100644 index 000000000..97135cd83 --- /dev/null +++ b/bin/objectbox_model_generator/pubspec.yaml @@ -0,0 +1,13 @@ +name: objectbox_model_generator +version: 0.2.0 +description: >- + A preprocessor for Dart source files containing ObjectBox entity definitions. +environment: + sdk: '>=2.5.0 <3.0.0' +dependencies: + build: '>=0.12.0 <2.0.0' + source_gen: ^0.9.0 + objectbox: + path: ../objectbox +dev_dependencies: + build_runner: '>=0.9.0 <0.11.0' diff --git a/examples/flutter/objectbox_demo_desktop/.gitignore b/examples/flutter/objectbox_demo_desktop/.gitignore new file mode 100644 index 000000000..1ae16cc6f --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/.gitignore @@ -0,0 +1,17 @@ +.atom/ +.dart_tool/ +.idea +.vscode/ +.packages +.pub/ +android/ +build/ +ios/ +packages +.flutter-plugins +# Since the current expectation is that clients are using Flutter head, +# and Dart SDK changes unlock dependencies, pubspec.lock isn't useful. +# Ignore it since it just creates noise. When there's a system in place +# for versioning this project relative to Flutter, remove this. +pubspec.lock +objectbox diff --git a/examples/flutter/objectbox_demo_desktop/.metadata b/examples/flutter/objectbox_demo_desktop/.metadata new file mode 100644 index 000000000..17aca7234 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/.metadata @@ -0,0 +1,8 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: eaa9b47a4ac278a9439468911d2c361a472b114b + channel: master diff --git a/examples/flutter/objectbox_demo_desktop/README.md b/examples/flutter/objectbox_demo_desktop/README.md new file mode 100644 index 000000000..d53f63963 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/README.md @@ -0,0 +1,20 @@ +# objectbox_demo_desktop + +## Getting Started + +In this early demo version, only desktop environments are supported. Mobile platform support, i.e. Android and iOS, will be added later. The current code is based on Google's [flutter-desktop-embedding](https://github.com/google/flutter-desktop-embedding) repository. + +If you have never run Flutter on desktop before, execute the following commands (these are for Linux, adjust accordingly for your OS, see [here](https://github.com/flutter/flutter/wiki/Desktop-shells#tooling)): + + flutter channel master + flutter upgrade + flutter config --enable-linux-desktop + +When trying out this demo for the first time, you definitely need to run: + + flutter packages get + +And on first run and whenever you added or changed any classes annotated with ObjectBox's `@Entity(...)`, execute: + + flutter pub run build_runner build + flutter run diff --git a/examples/flutter/objectbox_demo_desktop/fonts/Roboto/LICENSE.txt b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/LICENSE.txt new file mode 100755 index 000000000..d64569567 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Black.ttf b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Black.ttf new file mode 100755 index 000000000..689fe5cb3 Binary files /dev/null and b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Black.ttf differ diff --git a/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Bold.ttf b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Bold.ttf new file mode 100755 index 000000000..d3f01ad24 Binary files /dev/null and b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Bold.ttf differ diff --git a/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Light.ttf b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Light.ttf new file mode 100755 index 000000000..219063a57 Binary files /dev/null and b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Light.ttf differ diff --git a/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Medium.ttf b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Medium.ttf new file mode 100755 index 000000000..1a7f3b0bb Binary files /dev/null and b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Medium.ttf differ diff --git a/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Regular.ttf b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Regular.ttf new file mode 100755 index 000000000..2c97eeadf Binary files /dev/null and b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Regular.ttf differ diff --git a/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Thin.ttf b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Thin.ttf new file mode 100755 index 000000000..b74a4fd1a Binary files /dev/null and b/examples/flutter/objectbox_demo_desktop/fonts/Roboto/Roboto-Thin.ttf differ diff --git a/examples/flutter/objectbox_demo_desktop/lib/main.dart b/examples/flutter/objectbox_demo_desktop/lib/main.dart new file mode 100644 index 000000000..37690c52d --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/lib/main.dart @@ -0,0 +1,107 @@ +import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import "package:objectbox/objectbox.dart"; +part "main.g.dart"; + +@Entity(id: 1, uid: 1) +class Note { + @Id(id: 1, uid: 1001) + int id; + + @Property(id: 2, uid: 1002) + String text; + + Note(); + Note.construct(this.text); + toString() => "Note{id: $id, text: $text}"; +} + +void main() { + // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override + debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia; + + runApp(MyApp()); +} + +class MyApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + title: "ObjectBox Demo", + theme: ThemeData(primarySwatch: Colors.blue, fontFamily: "Roboto"), + home: MyHomePage(title: "ObjectBox Demo"), + ); + } +} + +class MyHomePage extends StatefulWidget { + MyHomePage({Key key, this.title}) : super(key: key); + + final String title; + + @override + _MyHomePageState createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + String _status = ""; + Store _store; + Box _box; + int _lastPutId; + + void _testGet() { + final Note fetchedNote = _lastPutId == null ? null : _box.get(_lastPutId); + setState(() { + if(_lastPutId == null) { + _status += "cannot get, as nothing was put in this session yet\n"; + return; + } + _status += "fetched note: $fetchedNote\n"; + }); + } + + void _testPut() { + _lastPutId = _box.put(Note.construct("Hello")); + setState(() { + _status += "put new note with id $_lastPutId\n"; + }); + } + + @override + void initState() { + _store = Store([[Note, Note_OBXDefs]]); + _box = Box(_store); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text(widget.title)), + body: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + FlatButton( + onPressed: _testGet, + child: Text("get"), + color: Colors.blue, + textColor: Colors.white, + ), + FlatButton( + onPressed: _testPut, + child: Text("put"), + color: Colors.blue, + textColor: Colors.white, + ), + ], + ), + Text("$_status"), + ], + ), + ); + } +} diff --git a/examples/flutter/objectbox_demo_desktop/linux/.gitignore b/examples/flutter/objectbox_demo_desktop/linux/.gitignore new file mode 100644 index 000000000..f68e1be09 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/linux/.gitignore @@ -0,0 +1 @@ +flutter/ diff --git a/examples/flutter/objectbox_demo_desktop/linux/Makefile b/examples/flutter/objectbox_demo_desktop/linux/Makefile new file mode 100644 index 000000000..fbd5eec18 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/linux/Makefile @@ -0,0 +1,133 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Example-specific variables. +# To modify this Makefile for a different application, these are the values +# that are mostly likely to need to be changed. + +# Executable name. +BINARY_NAME=flutter_desktop_example +# The C++ code for the embedder application. +SOURCES=flutter_embedder_example.cc +# Extra flags (e.g., for library dependencies). +SYSTEM_LIBRARIES= +EXTRA_CXXFLAGS= +EXTRA_CPPFLAGS=$(patsubst -I%,-isystem%,$(shell pkg-config --cflags $(SYSTEM_LIBRARIES))) +EXTRA_LDFLAGS=$(shell pkg-config --libs $(SYSTEM_LIBRARIES)) + +# Default build type. For a release build, set BUILD=release. +# Currently this only sets NDEBUG, which is used to control the flags passed +# to the Flutter engine in the example shell, and not the complation settings +# (e.g., optimization level) of the C++ code. +BUILD=debug + +# Configuration provided via flutter tool. +include flutter/generated_config + +# Dependency locations +FLUTTER_APP_CACHE_DIR=flutter/ +FLUTTER_APP_DIR=$(CURDIR)/.. +FLUTTER_APP_BUILD_DIR=$(FLUTTER_APP_DIR)/build + +OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux + +# Libraries +FLUTTER_LIB_NAME=flutter_linux_glfw +FLUTTER_LIB=$(FLUTTER_APP_CACHE_DIR)/lib$(FLUTTER_LIB_NAME).so + +# Tools +FLUTTER_BIN=$(FLUTTER_ROOT)/bin/flutter +LINUX_BUILD=$(FLUTTER_ROOT)/packages/flutter_tools/bin/linux_backend.sh + +# Resources +ICU_DATA_NAME=icudtl.dat +ICU_DATA_SOURCE=$(FLUTTER_APP_CACHE_DIR)/$(ICU_DATA_NAME) +FLUTTER_ASSETS_NAME=flutter_assets +FLUTTER_ASSETS_SOURCE=$(FLUTTER_APP_BUILD_DIR)/$(FLUTTER_ASSETS_NAME) + +# Bundle structure +BUNDLE_OUT_DIR=$(OUT_DIR)/$(BUILD) +BUNDLE_DATA_DIR=$(BUNDLE_OUT_DIR)/data +BUNDLE_LIB_DIR=$(BUNDLE_OUT_DIR)/lib + +BIN_OUT=$(BUNDLE_OUT_DIR)/$(BINARY_NAME) +ICU_DATA_OUT=$(BUNDLE_DATA_DIR)/$(ICU_DATA_NAME) +FLUTTER_LIB_OUT=$(BUNDLE_LIB_DIR)/$(notdir $(FLUTTER_LIB)) + +# Add relevant code from the wrapper library, which is intended to be statically +# built into the client. +WRAPPER_ROOT=$(FLUTTER_APP_CACHE_DIR)/cpp_client_wrapper_glfw +WRAPPER_SOURCES= \ + $(WRAPPER_ROOT)/flutter_window_controller.cc \ + $(WRAPPER_ROOT)/plugin_registrar.cc \ + $(WRAPPER_ROOT)/engine_method_result.cc +SOURCES+=$(WRAPPER_SOURCES) + +# Headers +WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include +INCLUDE_DIRS=$(FLUTTER_APP_CACHE_DIR) $(WRAPPER_INCLUDE_DIR) + +# Build settings +CXX=g++ $(EXTRA_CXXFLAGS) +CXXFLAGS.release=-DNDEBUG +CXXFLAGS=-std=c++14 -Wall -Werror $(CXXFLAGS.$(BUILD)) +CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS)) $(EXTRA_CPPFLAGS) +LDFLAGS=-L$(BUNDLE_LIB_DIR) \ + -l$(FLUTTER_LIB_NAME) \ + $(EXTRA_LDFLAGS) \ + -Wl,-rpath=\$$ORIGIN/lib + +# Targets + +.PHONY: all +all: $(BIN_OUT) bundle + +# This is a phony target because the flutter tool cannot describe +# its inputs and outputs yet. +.PHONY: sync +sync: flutter/generated_config + $(FLUTTER_ROOT)/packages/flutter_tools/bin/tool_backend.sh linux-x64 $(BUILD) + +.PHONY: bundle +bundle: $(ICU_DATA_OUT) $(FLUTTER_LIB_OUT) bundleflutterassets + +$(BIN_OUT): $(SOURCES) $(FLUTTER_LIB_OUT) + mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(SOURCES) $(LDFLAGS) -o $@ + +$(WRAPPER_SOURCES) $(FLUTTER_LIB) $(ICU_DATA_SOURCE) $(FLUTTER_ASSETS_SOURCE): \ + | sync + +$(FLUTTER_LIB_OUT): $(FLUTTER_LIB) + mkdir -p $(BUNDLE_LIB_DIR) + cp $(FLUTTER_LIB) $(BUNDLE_LIB_DIR) + +$(ICU_DATA_OUT): $(ICU_DATA_SOURCE) + mkdir -p $(dir $(ICU_DATA_OUT)) + cp $(ICU_DATA_SOURCE) $(ICU_DATA_OUT) + +# Fully re-copy the assets directory on each build to avoid having to keep a +# comprehensive list of all asset files here, which would be fragile to changes +# in the Flutter example (e.g., adding a new font to pubspec.yaml would require +# changes here). +.PHONY: bundleflutterassets +bundleflutterassets: $(FLUTTER_ASSETS_SOURCE) + mkdir -p $(BUNDLE_DATA_DIR) + rsync -rpu --delete $(FLUTTER_ASSETS_SOURCE) $(BUNDLE_DATA_DIR) + +.PHONY: clean +clean: + rm -rf $(OUT_DIR); \ + cd $(FLUTTER_APP_DIR); \ + $(FLUTTER_BIN) clean diff --git a/examples/flutter/objectbox_demo_desktop/linux/flutter_embedder_example.cc b/examples/flutter/objectbox_demo_desktop/linux/flutter_embedder_example.cc new file mode 100644 index 000000000..1be66cdcf --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/linux/flutter_embedder_example.cc @@ -0,0 +1,76 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include +#include +#include + +#include +#include +#include +#include + +namespace { + +// Returns the path of the directory containing this executable, or an empty +// string if the directory cannot be found. +std::string GetExecutableDirectory() { + char buffer[PATH_MAX + 1]; + ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer)); + if (length > PATH_MAX) { + std::cerr << "Couldn't locate executable" << std::endl; + return ""; + } + std::string executable_path(buffer, length); + size_t last_separator_position = executable_path.find_last_of('/'); + if (last_separator_position == std::string::npos) { + std::cerr << "Unabled to find parent directory of " << executable_path + << std::endl; + return ""; + } + return executable_path.substr(0, last_separator_position); +} + +} // namespace + +int main(int argc, char **argv) { + // Resources are located relative to the executable. + std::string base_directory = GetExecutableDirectory(); + if (base_directory.empty()) { + base_directory = "."; + } + std::string data_directory = base_directory + "/data"; + std::string assets_path = data_directory + "/flutter_assets"; + std::string icu_data_path = data_directory + "/icudtl.dat"; + + // Arguments for the Flutter Engine. + std::vector arguments; + + flutter::FlutterWindowController flutter_controller(icu_data_path); + flutter::WindowProperties window_properties = {}; + window_properties.title = "Flutter Desktop Example"; + window_properties.width = 800; + window_properties.height = 600; + + // Start the engine. + if (!flutter_controller.CreateWindow(window_properties, assets_path, + arguments)) { + return EXIT_FAILURE; + } + + // Run until the window is closed. + while (flutter_controller.RunEventLoopWithTimeout( + std::chrono::milliseconds::max())) { + } + return EXIT_SUCCESS; +} diff --git a/examples/flutter/objectbox_demo_desktop/macos/.gitignore b/examples/flutter/objectbox_demo_desktop/macos/.gitignore new file mode 100644 index 000000000..7c8c39deb --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/.gitignore @@ -0,0 +1,6 @@ +xcuserdata + +# Generated by flutter tooling as needed. +Flutter/ephemeral/ +# Created by CocoaPods for plugins. +Pods/ diff --git a/examples/flutter/objectbox_demo_desktop/macos/AppDelegate.swift b/examples/flutter/objectbox_demo_desktop/macos/AppDelegate.swift new file mode 100644 index 000000000..bfe1d6fce --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/AppDelegate.swift @@ -0,0 +1,48 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Cocoa + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + @IBOutlet weak var window: NSWindow! + @IBOutlet weak var applicationMenu: NSMenu! + + func applicationWillFinishLaunching(_ notification: Notification) { + // Update UI elements to match the application name. + // TODO: Move this logic to a Flutter framework application delegate. + // See https://github.com/flutter/flutter/issues/32419. + let appName = applicationName() + window.title = appName + for menuItem in applicationMenu.items { + menuItem.title = menuItem.title.replacingOccurrences(of: "APP_NAME", with: appName) + } + } + + func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } + + /** + * Returns the name of the application as set in the Info.plist + */ + private func applicationName() -> String { + var applicationName : String? = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String + if applicationName == nil { + applicationName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String + } + return applicationName! + } +} + diff --git a/examples/flutter/objectbox_demo_desktop/macos/Assets.xcassets/AppIcon.appiconset/Contents.json b/examples/flutter/objectbox_demo_desktop/macos/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..2db2b1c7c --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/flutter/objectbox_demo_desktop/macos/Base.lproj/MainMenu.xib b/examples/flutter/objectbox_demo_desktop/macos/Base.lproj/MainMenu.xib new file mode 100644 index 000000000..9bf8c370b --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Base.lproj/MainMenu.xib @@ -0,0 +1,339 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/flutter/objectbox_demo_desktop/macos/Configs/Debug.xcconfig b/examples/flutter/objectbox_demo_desktop/macos/Configs/Debug.xcconfig new file mode 100644 index 000000000..41b749569 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Configs/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "../Flutter/Flutter-Debug.xcconfig" +#include "Warnings.xcconfig" diff --git a/examples/flutter/objectbox_demo_desktop/macos/Configs/Release.xcconfig b/examples/flutter/objectbox_demo_desktop/macos/Configs/Release.xcconfig new file mode 100644 index 000000000..2a7dc01dc --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Configs/Release.xcconfig @@ -0,0 +1,2 @@ +#include "../Flutter/Flutter-Release.xcconfig" +#include "Warnings.xcconfig" diff --git a/examples/flutter/objectbox_demo_desktop/macos/Configs/Warnings.xcconfig b/examples/flutter/objectbox_demo_desktop/macos/Configs/Warnings.xcconfig new file mode 100644 index 000000000..42bcbf478 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Configs/Warnings.xcconfig @@ -0,0 +1,13 @@ +WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES +CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_PRAGMA_PACK = YES +CLANG_WARN_STRICT_PROTOTYPES = YES +CLANG_WARN_COMMA = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_UNREACHABLE_CODE = YES diff --git a/examples/flutter/objectbox_demo_desktop/macos/Flutter/Flutter-Debug.xcconfig b/examples/flutter/objectbox_demo_desktop/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 000000000..c2efd0b60 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/examples/flutter/objectbox_demo_desktop/macos/Flutter/Flutter-Release.xcconfig b/examples/flutter/objectbox_demo_desktop/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 000000000..c2efd0b60 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/examples/flutter/objectbox_demo_desktop/macos/Flutter/GeneratedPluginRegistrant.swift b/examples/flutter/objectbox_demo_desktop/macos/Flutter/GeneratedPluginRegistrant.swift new file mode 100644 index 000000000..58425bba2 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Flutter/GeneratedPluginRegistrant.swift @@ -0,0 +1,9 @@ +// +// Generated file. Do not edit. +// +import Foundation +import FlutterMacOS + + +func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { +} diff --git a/examples/flutter/objectbox_demo_desktop/macos/Info.plist b/examples/flutter/objectbox_demo_desktop/macos/Info.plist new file mode 100644 index 000000000..d560406db --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2018 Google LLC. All rights reserved. + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/examples/flutter/objectbox_demo_desktop/macos/MainFlutterWindow.swift b/examples/flutter/objectbox_demo_desktop/macos/MainFlutterWindow.swift new file mode 100644 index 000000000..624068316 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/MainFlutterWindow.swift @@ -0,0 +1,30 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Cocoa +import FlutterMacOS + +class MainFlutterWindow: NSWindow { + override func awakeFromNib() { + let flutterViewController = FlutterViewController.init() + let windowFrame = self.frame + self.contentViewController = flutterViewController + self.setFrame(windowFrame, display: true) + + RegisterGeneratedPlugins(registry: flutterViewController) + + super.awakeFromNib() + } +} + diff --git a/examples/flutter/objectbox_demo_desktop/macos/Runner-DebugProfile.entitlements b/examples/flutter/objectbox_demo_desktop/macos/Runner-DebugProfile.entitlements new file mode 100644 index 000000000..dddb8a30c --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Runner-DebugProfile.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.cs.allow-jit + + com.apple.security.network.server + + + diff --git a/examples/flutter/objectbox_demo_desktop/macos/Runner-Release.entitlements b/examples/flutter/objectbox_demo_desktop/macos/Runner-Release.entitlements new file mode 100644 index 000000000..852fa1a47 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Runner-Release.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.security.app-sandbox + + + diff --git a/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/project.pbxproj b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/project.pbxproj new file mode 100644 index 000000000..359769173 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,573 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 48; + objects = { + +/* Begin PBXAggregateTarget section */ + 33CC111A2044C6BA0003C045 /* Flutter Assemble */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */; + buildPhases = ( + 33CC111E2044C6BF0003C045 /* ShellScript */, + ); + dependencies = ( + ); + name = "Flutter Assemble"; + productName = FLX; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; }; + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; }; + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; + 33D1A10422148B71006C7A3E /* FlutterMacOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */; }; + 33D1A10522148B93006C7A3E /* FlutterMacOS.framework in Bundle Framework */ = {isa = PBXBuildFile; fileRef = 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + D73912F022F37F9E000D13A0 /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D73912EF22F37F9E000D13A0 /* App.framework */; }; + D73912F222F3801D000D13A0 /* App.framework in Bundle Framework */ = {isa = PBXBuildFile; fileRef = D73912EF22F37F9E000D13A0 /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC111A2044C6BA0003C045; + remoteInfo = FLX; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 33CC110E2044A8840003C045 /* Bundle Framework */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + D73912F222F3801D000D13A0 /* App.framework in Bundle Framework */, + 33D1A10522148B93006C7A3E /* FlutterMacOS.framework in Bundle Framework */, + ); + name = "Bundle Framework"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Warnings.xcconfig; path = Configs/Warnings.xcconfig; sourceTree = ""; }; + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; + 33CC10ED2044A3C60003C045 /* Flutter Desktop Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Flutter Desktop Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 33CC10F72044A3C60003C045 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainFlutterWindow.swift; sourceTree = ""; }; + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; + 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FlutterMacOS.framework; path = Flutter/ephemeral/FlutterMacOS.framework; sourceTree = SOURCE_ROOT; }; + 33E51913231747F40026EE4D /* Runner-DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Runner-DebugProfile.entitlements"; sourceTree = ""; }; + 33E51914231749380026EE4D /* Runner-Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = "Runner-Release.entitlements"; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Configs/Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Configs/Debug.xcconfig; sourceTree = ""; }; + D73912EF22F37F9E000D13A0 /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/ephemeral/App.framework; sourceTree = SOURCE_ROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 33CC10EA2044A3C60003C045 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + D73912F022F37F9E000D13A0 /* App.framework in Frameworks */, + 33D1A10422148B71006C7A3E /* FlutterMacOS.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 33BA886A226E78AF003329D5 /* Configs */ = { + isa = PBXGroup; + children = ( + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */, + ); + name = Configs; + sourceTree = ""; + }; + 33CC10E42044A3C60003C045 = { + isa = PBXGroup; + children = ( + 33CC10F02044A3C60003C045 /* AppDelegate.swift */, + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, + 33CC11242044D66E0003C045 /* Resources */, + 33E51913231747F40026EE4D /* Runner-DebugProfile.entitlements */, + 33E51914231749380026EE4D /* Runner-Release.entitlements */, + 33BA886A226E78AF003329D5 /* Configs */, + 33CEB47122A05771004F2AC0 /* Flutter */, + 33CC10EE2044A3C60003C045 /* Products */, + D73912EC22F37F3D000D13A0 /* Frameworks */, + ); + sourceTree = ""; + }; + 33CC10EE2044A3C60003C045 /* Products */ = { + isa = PBXGroup; + children = ( + 33CC10ED2044A3C60003C045 /* Flutter Desktop Example.app */, + ); + name = Products; + sourceTree = ""; + }; + 33CC11242044D66E0003C045 /* Resources */ = { + isa = PBXGroup; + children = ( + 33CC10F22044A3C60003C045 /* Assets.xcassets */, + 33CC10F42044A3C60003C045 /* MainMenu.xib */, + 33CC10F72044A3C60003C045 /* Info.plist */, + ); + name = Resources; + sourceTree = ""; + }; + 33CEB47122A05771004F2AC0 /* Flutter */ = { + isa = PBXGroup; + children = ( + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, + D73912EF22F37F9E000D13A0 /* App.framework */, + 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */, + ); + path = Flutter; + sourceTree = ""; + }; + D73912EC22F37F3D000D13A0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 33CC10EC2044A3C60003C045 /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 33CC10E92044A3C60003C045 /* Sources */, + 33CC10EA2044A3C60003C045 /* Frameworks */, + 33CC10EB2044A3C60003C045 /* Resources */, + 33CC110E2044A8840003C045 /* Bundle Framework */, + 3399D490228B24CF009A79C7 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 33CC11202044C79F0003C045 /* PBXTargetDependency */, + ); + name = Runner; + productName = "Flutter Desktop Example"; + productReference = 33CC10ED2044A3C60003C045 /* Flutter Desktop Example.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33CC10E52044A3C60003C045 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0920; + LastUpgradeCheck = 0930; + ORGANIZATIONNAME = "Google LLC"; + TargetAttributes = { + 33CC10EC2044A3C60003C045 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 0920; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; + 33CC111A2044C6BA0003C045 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Manual; + }; + }; + }; + buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 8.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33CC10E42044A3C60003C045; + productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 33CC10EC2044A3C60003C045 /* Runner */, + 33CC111A2044C6BA0003C045 /* Flutter Assemble */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 33CC10EB2044A3C60003C045 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3399D490228B24CF009A79C7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename\n"; + }; + 33CC111E2044C6BF0003C045 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 33CC10E92044A3C60003C045 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 33CC11202044C79F0003C045 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC111A2044C6BA0003C045 /* Flutter Assemble */; + targetProxy = 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 33CC10F42044A3C60003C045 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 33CC10F52044A3C60003C045 /* Base */, + ); + name = MainMenu.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 338D0CE9231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + }; + name = Profile; + }; + 338D0CEA231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = "Runner-DebugProfile.entitlements"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter/ephemeral", + ); + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.google.FlutterEmbedderMacExample.FlutterDesktopExample; + PRODUCT_NAME = "Flutter Desktop Example"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 4.0; + }; + name = Profile; + }; + 338D0CEB231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 33CC10F92044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33CC10FA2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + }; + name = Release; + }; + 33CC10FC2044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = "Runner-DebugProfile.entitlements"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter/ephemeral", + ); + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.google.FlutterEmbedderMacExample.FlutterDesktopExample; + PRODUCT_NAME = "Flutter Desktop Example"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; + }; + name = Debug; + }; + 33CC10FD2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = "Runner-Release.entitlements"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter/ephemeral", + ); + INFOPLIST_FILE = Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.google.FlutterEmbedderMacExample.FlutterDesktopExample; + PRODUCT_NAME = "Flutter Desktop Example"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 4.0; + }; + name = Release; + }; + 33CC111C2044C6BA0003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 33CC111D2044C6BA0003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10F92044A3C60003C045 /* Debug */, + 33CC10FA2044A3C60003C045 /* Release */, + 338D0CE9231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10FC2044A3C60003C045 /* Debug */, + 33CC10FD2044A3C60003C045 /* Release */, + 338D0CEA231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC111C2044C6BA0003C045 /* Debug */, + 33CC111D2044C6BA0003C045 /* Release */, + 338D0CEB231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33CC10E52044A3C60003C045 /* Project object */; +} diff --git a/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..764c74b8d --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 000000000..57774f080 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/flutter/objectbox_demo_desktop/macos/Runner.xcworkspace/contents.xcworkspacedata b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..1d526a16e --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/examples/flutter/objectbox_demo_desktop/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/examples/flutter/objectbox_demo_desktop/pubspec.yaml b/examples/flutter/objectbox_demo_desktop/pubspec.yaml new file mode 100644 index 000000000..5b0ab0e3e --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/pubspec.yaml @@ -0,0 +1,44 @@ +name: objectbox_demo_desktop +description: An example project for the objectbox-dart binding. + +version: 0.2.0 + +environment: + sdk: '>=2.5.0 <3.0.0' + flutter: '>=1.9.8-pre.31' + +dependencies: + flutter: + sdk: flutter + + cupertino_icons: ^0.1.0 + + objectbox: + path: ../../../objectbox + +dev_dependencies: + flutter_test: + sdk: flutter + build_runner: 1.0.0 + objectbox_model_generator: + path: ../../../objectbox_model_generator + +flutter: + uses-material-design: true + + # See https://github.com/flutter/flutter/wiki/Desktop-shells#fonts + fonts: + - family: Roboto + fonts: + - asset: fonts/Roboto/Roboto-Thin.ttf + weight: 100 + - asset: fonts/Roboto/Roboto-Light.ttf + weight: 300 + - asset: fonts/Roboto/Roboto-Regular.ttf + weight: 400 + - asset: fonts/Roboto/Roboto-Medium.ttf + weight: 500 + - asset: fonts/Roboto/Roboto-Bold.ttf + weight: 700 + - asset: fonts/Roboto/Roboto-Black.ttf + weight: 900 diff --git a/examples/flutter/objectbox_demo_desktop/test/widget_test.dart b/examples/flutter/objectbox_demo_desktop/test/widget_test.dart new file mode 100644 index 000000000..0b6b32a3d --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/test/widget_test.dart @@ -0,0 +1,29 @@ +// This is a basic Flutter widget test. +// To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter +// provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to +// find child widgets in the widget tree, read text, and verify that the values of widget properties +// are correct. + +/*import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:objectbox_demo_desktop/main.dart';*/ + +void main() { + /*testWidgets('Counter increments smoke test', (tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(new MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + });*/ +} diff --git a/examples/flutter/objectbox_demo_desktop/windows/.gitignore b/examples/flutter/objectbox_demo_desktop/windows/.gitignore new file mode 100644 index 000000000..0f3fe5afa --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/windows/.gitignore @@ -0,0 +1,332 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# Local additions, not from the link above +flutter/ + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ diff --git a/examples/flutter/objectbox_demo_desktop/windows/Runner.sln b/examples/flutter/objectbox_demo_desktop/windows/Runner.sln new file mode 100644 index 000000000..4492e99a7 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/windows/Runner.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.645 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Runner", "Runner.vcxproj", "{5A827760-CF8B-408A-99A3-B6C0AD2271E7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Debug|x64.ActiveCfg = Debug|x64 + {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Debug|x64.Build.0 = Debug|x64 + {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Release|x64.ActiveCfg = Release|x64 + {5A827760-CF8B-408A-99A3-B6C0AD2271E7}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B8A69CB0-A974-4774-9EBD-1E5EECACD186} + EndGlobalSection +EndGlobal diff --git a/examples/flutter/objectbox_demo_desktop/windows/Runner.vcxproj b/examples/flutter/objectbox_demo_desktop/windows/Runner.vcxproj new file mode 100644 index 000000000..4abb2f36c --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/windows/Runner.vcxproj @@ -0,0 +1,163 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {5A827760-CF8B-408A-99A3-B6C0AD2271E7} + GLFWExample + 10.0.17763.0 + + + + Application + true + v141 + v142 + MultiByte + + + Application + false + v141 + v142 + true + MultiByte + + + + + + + + + + + + + + + + + $(ProjectDir)..\build\windows\$(Platform)\$(Configuration)\$(ProjectName)\ + $(ProjectDir)..\build\windows\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\ + $(ProjectDir)flutter\;$(ProjectDir)flutter\cpp_client_wrapper_glfw\include\;$(IncludePath) + $(ProjectDir)flutter;$(LibraryPath) + Flutter Desktop Example + + + $(ProjectDir)..\build\windows\$(Platform)\$(Configuration)\$(ProjectName)\ + $(ProjectDir)..\build\windows\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\ + $(ProjectDir)flutter\;$(ProjectDir)flutter\cpp_client_wrapper_glfw\include\;$(IncludePath) + $(ProjectDir)flutter;$(LibraryPath) + Flutter Desktop Example + + + + Level3 + Disabled + true + true + + + _MBCS;%(PreprocessorDefinitions) + + + flutter_windows_glfw.dll.lib;opengl32.lib;%(AdditionalDependencies) + Windows + + + "$(ProjectDir)scripts\prepare_dependencies" debug + Sync and build dependencies + + + + + + + + + + + + + + + + + "$(ProjectDir)scripts\bundle_assets_and_deps" "$(ProjectDir)flutter\" "$(OutputPath)" "$(TargetFileName)" + + + Bundling dependencies + Dummy_Run_Always + + + + + + + Level3 + MaxSpeed + true + true + true + true + + + _MBCS;%(PreprocessorDefinitions) + + + true + true + flutter_windows_glfw.dll.lib;opengl32.lib;%(AdditionalDependencies) + Windows + + + "$(ProjectDir)scripts\prepare_dependencies" release + Sync and build dependencies + + + + + + + + + + + + + + + + + "$(ProjectDir)scripts\bundle_assets_and_deps" "$(ProjectDir)flutter\" "$(OutputPath)" "$(TargetFileName)" + + + Bundling dependencies + Dummy_Run_Always + + + + + + + + + + + + + + + $(SolutionDir) + + \ No newline at end of file diff --git a/examples/flutter/objectbox_demo_desktop/windows/Runner.vcxproj.filters b/examples/flutter/objectbox_demo_desktop/windows/Runner.vcxproj.filters new file mode 100644 index 000000000..48637b305 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/windows/Runner.vcxproj.filters @@ -0,0 +1,34 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {2761a4b5-57b2-4d50-a677-d20ddc17a7f1} + + + + + Source Files + + + Source Files\Client Wrapper + + + Source Files\Client Wrapper + + + Source Files\Client Wrapper + + + diff --git a/examples/flutter/objectbox_demo_desktop/windows/flutter_embedder_example.cpp b/examples/flutter/objectbox_demo_desktop/windows/flutter_embedder_example.cpp new file mode 100644 index 000000000..0414515ec --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/windows/flutter_embedder_example.cpp @@ -0,0 +1,86 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include "flutter/flutter_window_controller.h" + +// Include windows.h last, to minimize potential conflicts. The CreateWindow +// macro needs to be undefined because it prevents calling +// FlutterWindowController's method. +#include +#undef CreateWindow + +namespace { + +// Returns the path of the directory containing this executable, or an empty +// string if the directory cannot be found. +std::string GetExecutableDirectory() { + char buffer[MAX_PATH]; + if (GetModuleFileName(nullptr, buffer, MAX_PATH) == 0) { + std::cerr << "Couldn't locate executable" << std::endl; + return ""; + } + std::string executable_path(buffer); + size_t last_separator_position = executable_path.find_last_of('\\'); + if (last_separator_position == std::string::npos) { + std::cerr << "Unabled to find parent directory of " << executable_path + << std::endl; + return ""; + } + return executable_path.substr(0, last_separator_position); +} + +} // namespace + +int APIENTRY wWinMain(HINSTANCE instance, + HINSTANCE prev, + wchar_t *command_line, + int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + ::AllocConsole(); + } + + // Resources are located relative to the executable. + std::string base_directory = GetExecutableDirectory(); + if (base_directory.empty()) { + base_directory = "."; + } + std::string data_directory = base_directory + "\\data"; + std::string assets_path = data_directory + "\\flutter_assets"; + std::string icu_data_path = data_directory + "\\icudtl.dat"; + + // Arguments for the Flutter Engine. + std::vector arguments; + + flutter::FlutterWindowController flutter_controller(icu_data_path); + flutter::WindowProperties window_properties = {}; + window_properties.title = "Flutter Desktop Example"; + window_properties.width = 800; + window_properties.height = 600; + + // Start the engine. + if (!flutter_controller.CreateWindow(window_properties, assets_path, + arguments)) { + return EXIT_FAILURE; + } + + // Run until the window is closed. + flutter_controller.RunEventLoop(); + return EXIT_SUCCESS; +} diff --git a/examples/flutter/objectbox_demo_desktop/windows/scripts/bundle_assets_and_deps.bat b/examples/flutter/objectbox_demo_desktop/windows/scripts/bundle_assets_and_deps.bat new file mode 100644 index 000000000..b795c5ae9 --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/windows/scripts/bundle_assets_and_deps.bat @@ -0,0 +1,43 @@ +:: Copyright 2018 Google LLC +:: +:: Licensed under the Apache License, Version 2.0 (the "License"); +:: you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, +:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +:: See the License for the specific language governing permissions and +:: limitations under the License. +@echo off + +set FLUTTER_CACHE_DIR=%~1 +set BUNDLE_DIR=%~2 +set EXE_NAME=%~3 + +set DATA_DIR=%BUNDLE_DIR%data + +if not exist "%DATA_DIR%" call mkdir "%DATA_DIR%" +if %errorlevel% neq 0 exit /b %errorlevel% + +:: Write the executable name to the location expected by the Flutter tool. +echo %EXE_NAME%>"%FLUTTER_CACHE_DIR%exe_filename" + +:: Copy the Flutter assets to the data directory. +set FLUTTER_APP_DIR=%~dp0..\.. +set ASSET_DIR_NAME=flutter_assets +set TARGET_ASSET_DIR=%DATA_DIR%\%ASSET_DIR_NAME% +if exist "%TARGET_ASSET_DIR%" call rmdir /s /q "%TARGET_ASSET_DIR%" +if %errorlevel% neq 0 exit /b %errorlevel% +call xcopy /s /e /i /q "%FLUTTER_APP_DIR%\build\%ASSET_DIR_NAME%" "%TARGET_ASSET_DIR%" +if %errorlevel% neq 0 exit /b %errorlevel% + +:: Copy the icudtl.dat file from the Flutter tree to the data directory. +call xcopy /y /d /q "%FLUTTER_CACHE_DIR%icudtl.dat" "%DATA_DIR%" +if %errorlevel% neq 0 exit /b %errorlevel% + +:: Copy the Flutter DLL to the target location. +call xcopy /y /d /q "%FLUTTER_CACHE_DIR%flutter_windows_glfw.dll" "%BUNDLE_DIR%" +if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/examples/flutter/objectbox_demo_desktop/windows/scripts/prepare_dependencies.bat b/examples/flutter/objectbox_demo_desktop/windows/scripts/prepare_dependencies.bat new file mode 100644 index 000000000..5ce2d74aa --- /dev/null +++ b/examples/flutter/objectbox_demo_desktop/windows/scripts/prepare_dependencies.bat @@ -0,0 +1,17 @@ +:: Copyright 2018 Google LLC +:: +:: Licensed under the Apache License, Version 2.0 (the "License"); +:: you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, +:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +:: See the License for the specific language governing permissions and +:: limitations under the License. +@echo off + +set BUILD_MODE=%~1 +"%FLUTTER_ROOT%\packages\flutter_tools\bin\tool_backend" windows-x64 %BUILD_MODE% diff --git a/lib/objectbox.dart b/lib/objectbox.dart index 7101fc8d7..24863ca3d 100644 --- a/lib/objectbox.dart +++ b/lib/objectbox.dart @@ -4,3 +4,4 @@ export "src/common.dart"; export "src/model.dart"; export "src/store.dart"; export "src/box.dart"; +export "src/bindings/constants.dart"; diff --git a/lib/src/bindings/bindings.dart b/lib/src/bindings/bindings.dart index bcdef06f6..af27d1f55 100644 --- a/lib/src/bindings/bindings.dart +++ b/lib/src/bindings/bindings.dart @@ -10,6 +10,7 @@ class _ObjectBoxBindings { // common functions void Function(Pointer major, Pointer minor, Pointer patch) obx_version; Pointer Function() obx_version_string; + void Function(Pointer array) obx_bytes_array_free; // error info int Function() obx_last_error_code; @@ -18,7 +19,7 @@ class _ObjectBoxBindings { void Function() obx_last_error_clear; // schema model creation - Pointer Function() obx_model_create; + Pointer Function() obx_model; int Function(Pointer model) obx_model_free; int Function(Pointer model, Pointer name, int entity_id, int entity_uid) obx_model_entity; int Function(Pointer model, Pointer name, int type, int property_id, int property_uid) obx_model_property; @@ -28,6 +29,10 @@ class _ObjectBoxBindings { // object store management Pointer Function() obx_opt; + int Function(Pointer opt, Pointer dir) obx_opt_directory; + void Function(Pointer opt, int size_in_kb) obx_opt_max_db_size_in_kb; + void Function(Pointer opt, int file_mode) obx_opt_file_mode; + void Function(Pointer opt, int max_readers) obx_opt_max_readers; int Function(Pointer opt, Pointer model) obx_opt_model; Pointer Function(Pointer opt) obx_store_open; int Function(Pointer store) obx_store_close; @@ -41,9 +46,15 @@ class _ObjectBoxBindings { // box management Pointer Function(Pointer store, int entity_id) obx_box; + int Function(Pointer box, int id, Pointer out_contains) obx_box_contains; + int Function(Pointer box, Pointer ids, Pointer out_contains) obx_box_contains_many; int Function(Pointer box, int id, Pointer> data, Pointer size) obx_box_get; + Pointer Function(Pointer box, Pointer ids) obx_box_get_many; + Pointer Function(Pointer box) obx_box_get_all; int Function(Pointer box, int id_or_zero) obx_box_id_for_put; + int Function(Pointer box, int count, Pointer out_first_id) obx_box_ids_for_put; int Function(Pointer box, int id, Pointer data, int size, int mode) obx_box_put; + int Function(Pointer box, Pointer objects, Pointer ids, int mode) obx_box_put_many; int Function(Pointer box, int id) obx_box_remove; _ObjectBoxBindings() { @@ -57,6 +68,7 @@ class _ObjectBoxBindings { // common functions obx_version = objectbox.lookup>("obx_version").asFunction(); obx_version_string = objectbox.lookup>("obx_version_string").asFunction(); + obx_bytes_array_free = objectbox.lookup>("obx_bytes_array_free").asFunction(); // error info obx_last_error_code = objectbox.lookup>("obx_last_error_code").asFunction(); @@ -65,7 +77,7 @@ class _ObjectBoxBindings { obx_last_error_clear = objectbox.lookup>("obx_last_error_clear").asFunction(); // schema model creation - obx_model_create = objectbox.lookup>("obx_model_create").asFunction(); + obx_model = objectbox.lookup>("obx_model").asFunction(); obx_model_free = objectbox.lookup>("obx_model_free").asFunction(); obx_model_entity = objectbox.lookup>("obx_model_entity").asFunction(); obx_model_property = objectbox.lookup>("obx_model_property").asFunction(); @@ -75,6 +87,10 @@ class _ObjectBoxBindings { // object store management obx_opt = objectbox.lookup>("obx_opt").asFunction(); + obx_opt_directory = objectbox.lookup>("obx_opt_directory").asFunction(); + obx_opt_max_db_size_in_kb = objectbox.lookup>("obx_opt_max_db_size_in_kb").asFunction(); + obx_opt_file_mode = objectbox.lookup>("obx_opt_file_mode").asFunction(); + obx_opt_max_readers = objectbox.lookup>("obx_opt_max_readers").asFunction(); obx_opt_model = objectbox.lookup>("obx_opt_model").asFunction(); obx_store_open = objectbox.lookup>("obx_store_open").asFunction(); obx_store_close = objectbox.lookup>("obx_store_close").asFunction(); @@ -88,9 +104,15 @@ class _ObjectBoxBindings { // box management obx_box = objectbox.lookup>("obx_box").asFunction(); + obx_box_contains = objectbox.lookup>("obx_box_contains").asFunction(); + obx_box_contains_many = objectbox.lookup>("obx_box_contains_many").asFunction(); obx_box_get = objectbox.lookup>("obx_box_get").asFunction(); + obx_box_get_many = objectbox.lookup>("obx_box_get_many").asFunction(); + obx_box_get_all = objectbox.lookup>("obx_box_get_all").asFunction(); obx_box_id_for_put = objectbox.lookup>("obx_box_id_for_put").asFunction(); + obx_box_ids_for_put = objectbox.lookup>("obx_box_ids_for_put").asFunction(); obx_box_put = objectbox.lookup>("obx_box_put").asFunction(); + obx_box_put_many = objectbox.lookup>("obx_box_put_many").asFunction(); obx_box_remove = objectbox.lookup>("obx_box_remove").asFunction(); } } diff --git a/lib/src/bindings/constants.dart b/lib/src/bindings/constants.dart index c1669e5ae..cfb0e8b75 100644 --- a/lib/src/bindings/constants.dart +++ b/lib/src/bindings/constants.dart @@ -15,7 +15,7 @@ class OBXPropertyType { } // see objectbox.h for more info -class OBXPropertyFlags { +class OBXPropertyFlag { static const int ID = 1; static const int NON_PRIMITIVE_TYPE = 2; static const int NOT_NULL = 4; @@ -39,7 +39,7 @@ class OBXPutMode { static const int UPDATE = 3; } -class OBXErrors { +class OBXError { /// Successful result static const int OBX_SUCCESS = 0; diff --git a/lib/src/bindings/helpers.dart b/lib/src/bindings/helpers.dart index cc595e573..dc8177f13 100644 --- a/lib/src/bindings/helpers.dart +++ b/lib/src/bindings/helpers.dart @@ -1,16 +1,15 @@ +import "dart:ffi"; +import "dart:typed_data" show Uint8List; import "constants.dart"; import "../common.dart"; -check(cond) { - if(!cond) - throw AssertionError(); +checkObx(errorCode) { + if(errorCode != OBXError.OBX_SUCCESS) + throw ObjectBoxException(Common.lastErrorString(errorCode)); } -checkObx(err) { - if(err != OBXErrors.OBX_SUCCESS) - throw ObjectBoxException(Common.lastErrorString(err)); -} - -getSymbolName(Symbol sym) { - return sym.toString().split('"')[1]; +checkObxPtr(Pointer ptr, String msg, [bool hasLastError = false]) { + if(ptr == null || ptr.address == 0) + throw ObjectBoxException("$msg: ${hasLastError ? Common.lastErrorString() : ""}"); + return ptr; } diff --git a/lib/src/bindings/signatures.dart b/lib/src/bindings/signatures.dart index 4be5aac93..e23206636 100644 --- a/lib/src/bindings/signatures.dart +++ b/lib/src/bindings/signatures.dart @@ -3,6 +3,7 @@ import "dart:ffi"; // common functions typedef obx_version_native_t = Void Function(Pointer major, Pointer minor, Pointer patch); typedef obx_version_string_native_t = Pointer Function(); +typedef obx_bytes_array_free_native_t = Void Function(Pointer array); // error info typedef obx_last_error_code_native_t = Int32 Function(); @@ -11,7 +12,7 @@ typedef obx_last_error_secondary_native_t = Int32 Function(); typedef obx_last_error_clear_native_t = Void Function(); // schema model creation -typedef obx_model_create_native_t = Pointer Function(); +typedef obx_model_native_t = Pointer Function(); typedef obx_model_free_native_t = Int32 Function(Pointer); typedef obx_model_entity_native_t = Int32 Function(Pointer model, Pointer name, Uint32 entity_id, Uint64 entity_uid); typedef obx_model_property_native_t = Int32 Function(Pointer model, Pointer name, Uint32 type, Uint64 property_id, Uint64 property_uid); @@ -21,6 +22,10 @@ typedef obx_model_last_entity_id_native_t = Int32 Function(Pointer model, // object store management typedef obx_opt_native_t = Pointer Function(); +typedef obx_opt_directory_native_t = Int32 Function(Pointer opt, Pointer dir); +typedef obx_opt_max_db_size_in_kb_native_t = Void Function(Pointer opt, Int32 size_in_kb); +typedef obx_opt_file_mode_native_t = Void Function(Pointer opt, Int32 file_mode); +typedef obx_opt_max_readers_native_t = Void Function(Pointer opt, Int32 max_readers); typedef obx_opt_model_native_t = Int32 Function(Pointer opt, Pointer model); typedef obx_store_open_native_t = Pointer Function(Pointer opt); typedef obx_store_close_native_t = Int32 Function(Pointer store); @@ -34,7 +39,13 @@ typedef obx_txn_success_native_t = Int32 Function(Pointer txn); // box management typedef obx_box_native_t = Pointer Function(Pointer store, Uint32 entity_id); +typedef obx_box_contains_native_t = Int32 Function(Pointer box, Uint64 id, Pointer out_contains); +typedef obx_box_contains_many_native_t = Int32 Function(Pointer box, Pointer ids, Pointer out_contains); typedef obx_box_get_native_t = Int32 Function(Pointer box, Uint64 id, Pointer> data, Pointer size); +typedef obx_box_get_many_native_t = Pointer Function(Pointer box, Pointer ids); +typedef obx_box_get_all_native_t = Pointer Function(Pointer box); typedef obx_box_id_for_put_native_t = Uint64 Function(Pointer box, Uint64 id_or_zero); +typedef obx_box_ids_for_put_native_t = Int32 Function(Pointer box, Uint64 count, Pointer out_first_id); typedef obx_box_put_native_t = Int32 Function(Pointer box, Uint64 id, Pointer data, Int32 size, Int32 mode); +typedef obx_box_put_many_native_t = Int32 Function(Pointer box, Pointer objects, Pointer ids, Int32 mode); typedef obx_box_remove_native_t = Int32 Function(Pointer box, Uint64 id); diff --git a/lib/src/box.dart b/lib/src/box.dart index 32e9776a1..be75218df 100644 --- a/lib/src/box.dart +++ b/lib/src/box.dart @@ -1,5 +1,4 @@ import "dart:ffi"; -import "dart:mirrors"; import "dart:typed_data" show Uint8List; import "package:flat_buffers/flat_buffers.dart" as fb; @@ -36,37 +35,130 @@ class _OBXFBEntityReader extends fb.TableReader<_OBXFBEntity> { new _OBXFBEntity._(bc, offset); } +class _IDArray { // wrapper for "struct OBX_id_array" + Pointer _idsPtr, _structPtr; + + _IDArray(List ids) { + _idsPtr = Pointer.allocate(count: ids.length); + for(int i = 0; i < ids.length; ++i) + _idsPtr.elementAt(i).store(ids[i]); + _structPtr = Pointer.allocate(count: 2); + _structPtr.store(_idsPtr.address); + _structPtr.elementAt(1).store(ids.length); + } + + get ptr => _structPtr; + + free() { + _idsPtr.free(); + _structPtr.free(); + } +} + +class _ByteBuffer { + Pointer _ptr; + int _size; + + _ByteBuffer(this._ptr, this._size); + + _ByteBuffer.allocate(Uint8List dartData, [bool align = true]) { + _ptr = Pointer.allocate(count: align ? ((dartData.length + 3.0) ~/ 4.0) * 4 : dartData.length); + for(int i = 0; i < dartData.length; ++i) + _ptr.elementAt(i).store(dartData[i]); + _size = dartData.length; + } + + _ByteBuffer.fromOBXBytes(Pointer obxPtr) { // extract fields from "struct OBX_bytes" + _ptr = Pointer.fromAddress(obxPtr.load()); + _size = obxPtr.elementAt(1).load(); + } + + get ptr => _ptr; + get voidPtr => Pointer.fromAddress(_ptr.address); + get address => _ptr.address; + get size => _size; + + Uint8List get data { + var buffer = new Uint8List(size); + for(int i = 0; i < size; ++i) + buffer[i] = _ptr.elementAt(i).load(); + return buffer; + } + + free() => _ptr.free(); +} + +class _SerializedByteBufferArray { + Pointer _outerPtr, _innerPtr; // outerPtr points to the instance itself, innerPtr points to the respective OBX_bytes_array.bytes + + _SerializedByteBufferArray(this._outerPtr, this._innerPtr); + get ptr => _outerPtr; + + free() { + _innerPtr.free(); + _outerPtr.free(); + } +} + +class _ByteBufferArray { + List<_ByteBuffer> _buffers; + + _ByteBufferArray(this._buffers); + + _ByteBufferArray.fromOBXBytesArray(Pointer bytesArray) { + _buffers = []; + Pointer bufferPtrs = Pointer.fromAddress(bytesArray.load()); // bytesArray.bytes + int numBuffers = bytesArray.elementAt(1).load(); // bytesArray.count + for(int i = 0; i < numBuffers; ++i) // loop through instances of "struct OBX_bytes" + _buffers.add(_ByteBuffer.fromOBXBytes(bufferPtrs.elementAt(2 * i))); // 2 * i, because each instance of "struct OBX_bytes" has .data and .size + } + + _SerializedByteBufferArray toOBXBytesArray() { + Pointer bufferPtrs = Pointer.allocate(count: _buffers.length * 2); + for(int i = 0; i < _buffers.length; ++i) { + bufferPtrs.elementAt(2 * i).store(_buffers[i].ptr.address); + bufferPtrs.elementAt(2 * i + 1).store(_buffers[i].size); + } + + Pointer outerPtr = Pointer.allocate(count: 2); + outerPtr.store(bufferPtrs.address); + outerPtr.elementAt(1).store(_buffers.length); + return _SerializedByteBufferArray(outerPtr, bufferPtrs); + } + + get buffers => _buffers; +} + class Box { Store _store; Pointer _objectboxBox; - var _entityDescription, _idPropIdx; + var _entityDefinition, _entityReader, _entityBuilder; Box(this._store) { - _entityDescription = _store.getEntityDescriptionFromClass(T); - check(_entityDescription != null); - _idPropIdx = _entityDescription["properties"].indexWhere((p) => (p["flags"] & OBXPropertyFlags.ID) != 0); - check(_idPropIdx != -1); + _entityDefinition = _store.getEntityModelDefinitionFromClass(T); + _entityReader = _store.getEntityReaderFromClass(); + _entityBuilder = _store.getEntityBuilderFromClass(); - _objectboxBox = bindings.obx_box(_store.ptr, _entityDescription["entity"]["id"]); - check(_objectboxBox != null); - check(_objectboxBox.address != 0); + _objectboxBox = bindings.obx_box(_store.ptr, _entityDefinition["entity"]["id"]); + checkObxPtr(_objectboxBox, "failed to create box"); } - _marshal(propVals) { + _ByteBuffer _marshal(propVals) { var builder = new fb.Builder(initialSize: 1024); // write all strings - propVals.forEach((p) { + Map offsets = {}; + _entityDefinition["properties"].forEach((p) { switch(p["type"]) { - case OBXPropertyType.String: p["offset"] = builder.writeString(p["value"]); break; + case OBXPropertyType.String: offsets[p["name"]] = builder.writeString(propVals[p["name"]]); break; } }); // create table and write actual properties // TODO: make sure that Id property has a value >= 1 builder.startTable(); - propVals.forEach((p) { - var field = p["id"] - 1, value = p["value"]; + _entityDefinition["properties"].forEach((p) { + var field = p["flatbuffers_id"], value = propVals[p["name"]]; switch(p["type"]) { case OBXPropertyType.Bool: builder.addBool(field, value); break; case OBXPropertyType.Char: builder.addInt8(field, value); break; @@ -74,20 +166,22 @@ class Box { case OBXPropertyType.Short: builder.addInt16(field, value); break; case OBXPropertyType.Int: builder.addInt32(field, value); break; case OBXPropertyType.Long: builder.addInt64(field, value); break; - case OBXPropertyType.String: builder.addOffset(field, p["offset"]); break; + case OBXPropertyType.String: builder.addOffset(field, offsets[p["name"]]); break; default: throw Exception("unsupported type: ${p['type']}"); // TODO: support more types } }); var endOffset = builder.endTable(); - return builder.finish(endOffset); + return _ByteBuffer.allocate(builder.finish(endOffset)); } - _unmarshal(buffer) { - var ret = reflectClass(T).newInstance(Symbol.empty, []); - var entity = new _OBXFBEntity(buffer); + T _unmarshal(_ByteBuffer buffer) { + if(buffer.size == 0 || buffer.address == 0) + return null; + Map propVals = {}; + var entity = new _OBXFBEntity(buffer.data); - _entityDescription["properties"].forEach((p) { + _entityDefinition["properties"].forEach((p) { var propReader; switch(p["type"]) { case OBXPropertyType.Bool: propReader = fb.BoolReader(); break; @@ -100,62 +194,138 @@ class Box { default: throw Exception("unsupported type: ${p['type']}"); // TODO: support more types } - ret.setField(Symbol(p["name"]), entity.getProp(propReader, (p["id"] + 1) * 2)); + propVals[p["name"]] = entity.getProp(propReader, (p["flatbuffers_id"] + 2) * 2); }); - return ret.reflectee; + return _entityBuilder(propVals); + } + + // expects pointer to OBX_bytes_array and manually resolves its contents (see objectbox.h) + List _unmarshalArray(Pointer bytesArray) { + return _ByteBufferArray.fromOBXBytesArray(bytesArray).buffers.map((b) => _unmarshal(b)).toList(); } - put(T inst, {PutMode mode = PutMode.Put}) { // also assigns a value to the respective ID property if it is given as null or 0 - var instRefl = reflect(inst); - var propVals = _entityDescription["properties"].map((p) => {...p, "value": instRefl.getField(Symbol(p["name"])).reflectee }).toList(); - if(propVals[_idPropIdx]["value"] == null || propVals[_idPropIdx]["value"] == 0) { + _getOBXPutMode(PutMode mode) { + switch(mode) { + case PutMode.Put: return OBXPutMode.PUT; + case PutMode.Insert: return OBXPutMode.INSERT; + case PutMode.Update: return OBXPutMode.UPDATE; + } + } + + // if the respective ID property is given as null or 0, a newly assigned ID is returned, otherwise the existing ID is returned + int put(T inst, {PutMode mode = PutMode.Put}) { + var propVals = _entityReader(inst); + var idPropName = _entityDefinition["idPropertyName"]; + if(propVals[idPropName] == null || propVals[idPropName] == 0) { final id = bindings.obx_box_id_for_put(_objectboxBox, 0); - propVals[_idPropIdx]["value"] = id; - instRefl.setField(Symbol(propVals[_idPropIdx]["name"]), id); + propVals[idPropName] = id; } - var buffer = _marshal(propVals); + + // put object into box and free the buffer + _ByteBuffer buffer = _marshal(propVals); + checkObx(bindings.obx_box_put(_objectboxBox, propVals[idPropName], buffer.voidPtr, buffer.size, _getOBXPutMode(mode))); + buffer.free(); + return propVals[idPropName]; + } + + // only instances whose ID property ot null or 0 will be given a new, valid number for that. A list of the final IDs is returned + List putMany(List insts, {PutMode mode = PutMode.Put}) { + if(insts.length == 0) + return []; - // determine internal put mode from given enum - var putMode; - switch(mode) { - case PutMode.Put: putMode = OBXPutMode.PUT; break; - case PutMode.Insert: putMode = OBXPutMode.INSERT; break; - case PutMode.Update: putMode = OBXPutMode.UPDATE; break; + // read all property values and find number of instances where ID is missing + var allPropVals = insts.map(_entityReader).toList(); + var idPropName = _entityDefinition["idPropertyName"]; + int numInstsMissingId = 0; + for(var instPropVals in allPropVals) + if(instPropVals[idPropName] == null || instPropVals[idPropName] == 0) + ++numInstsMissingId; + + // generate new IDs for these instances and set them + Pointer firstIdMemory; + if(numInstsMissingId != 0) { + firstIdMemory = Pointer.allocate(count: 1); + checkObx(bindings.obx_box_ids_for_put(_objectboxBox, numInstsMissingId, firstIdMemory)); + int nextId = firstIdMemory.load(); + firstIdMemory.free(); + for(var instPropVals in allPropVals) + if(instPropVals[idPropName] == null || instPropVals[idPropName] == 0) + instPropVals[idPropName] = nextId++; + } - // transform flatbuffers byte array into memory area for C, with a length of a multiple of four - Pointer bufferPtr = allocate(count: ((buffer.length + 3.0) / 4.0).toInt() * 4); - for(int i = 0; i < buffer.length; ++i) - bufferPtr.elementAt(i).store(buffer[i] as int); + // because obx_box_put_many also needs a list of all IDs of the elements to be put into the box, generate this list now (only needed if not all IDs have been generated) + Pointer allIdsMemory = Pointer.allocate(count: insts.length); + for(int i = 0; i < allPropVals.length; ++i) + allIdsMemory.elementAt(i).store(allPropVals[i][idPropName]); - // put object into box and free the buffer - checkObx(bindings.obx_box_put(_objectboxBox, propVals[_idPropIdx]["value"], fromAddress(bufferPtr.address), buffer.length, putMode)); - bufferPtr.free(); + // marshal all objects to be put into the box + var putObjects = _ByteBufferArray(allPropVals.map(_marshal).toList()).toOBXBytesArray(); + + checkObx(bindings.obx_box_put_many(_objectboxBox, putObjects.ptr, allIdsMemory, _getOBXPutMode(mode))); + putObjects.free(); + allIdsMemory.free(); + return allPropVals.map((p) => p[idPropName] as int).toList(); } - getById(int id) { - Pointer> dataPtr = allocate(); - Pointer sizePtr = allocate(); + _inReadTransaction(fn) { + Pointer txn = bindings.obx_txn_read(_store.ptr); + checkObxPtr(txn, "failed to created transaction"); + var ret; + try { + ret = fn(); + } finally { + checkObx(bindings.obx_txn_close(txn)); + } + return ret; + } + + get(int id) { + Pointer> dataPtr = Pointer>.allocate(); + Pointer sizePtr = Pointer.allocate(); // get element with specified id from database - Pointer txn = bindings.obx_txn_read(_store.ptr); - check(txn != null && txn.address != 0); - checkObx(bindings.obx_box_get(_objectboxBox, id, dataPtr, sizePtr)); - checkObx(bindings.obx_txn_close(txn)); - Pointer data = fromAddress(dataPtr.load>().address); + _inReadTransaction(() => checkObx(bindings.obx_box_get(_objectboxBox, id, dataPtr, sizePtr))); + Pointer data = Pointer.fromAddress(dataPtr.load>().address); var size = sizePtr.load(); // transform bytes from memory to Dart byte list - var buffer = new Uint8List(size); - for(int i = 0; i < size; ++i) // TODO: move this to a separate class - buffer[i] = data.elementAt(i).load(); + var buffer = _ByteBuffer(data, size); dataPtr.free(); sizePtr.free(); return _unmarshal(buffer); } + // returns list of ids.length objects of type T, each corresponding to the location of its ID in the ids array. Non-existant IDs become null + getMany(List ids) { + if(ids.length == 0) + return []; + + // write ids in buffer for FFI call + var idArray = new _IDArray(ids); + + // get bytes array, similar to getAll + Pointer bytesArray = _inReadTransaction( + () => checkObxPtr(bindings.obx_box_get_many(_objectboxBox, idArray.ptr), + "failed to get many objects from box", true)); + var ret = _unmarshalArray(bytesArray); + bindings.obx_bytes_array_free(bytesArray); + idArray.free(); + return ret; + } + + List getAll() { + // return value actually points to a OBX_bytes_array struct, which has two Uint64 members (data and size) + Pointer bytesArray = _inReadTransaction( + () => checkObxPtr(bindings.obx_box_get_all(_objectboxBox), + "failed to get all objects from box", true)); + var ret = _unmarshalArray(bytesArray); + bindings.obx_bytes_array_free(bytesArray); + return ret; + } + close() { if(_store != null) { _store.close(); diff --git a/lib/src/common.dart b/lib/src/common.dart index 36d2217a0..9779a61e6 100644 --- a/lib/src/common.dart +++ b/lib/src/common.dart @@ -5,7 +5,7 @@ import "ffi/cstring.dart"; class Common { static List version() { - Pointer majorPtr = allocate(), minorPtr = allocate(), patchPtr = allocate(); + Pointer majorPtr = Pointer.allocate(), minorPtr = Pointer.allocate(), patchPtr = Pointer.allocate(); bindings.obx_version(majorPtr, minorPtr, patchPtr); var ret = [majorPtr.load(), minorPtr.load(), patchPtr.load()]; majorPtr.free(); diff --git a/lib/src/ffi/cstring.dart b/lib/src/ffi/cstring.dart index 6f04cdc84..02812237e 100644 --- a/lib/src/ffi/cstring.dart +++ b/lib/src/ffi/cstring.dart @@ -1,24 +1,35 @@ import "dart:ffi"; +import "package:utf/src/utf8.dart"; +// TODO check if revamp structs are relevant (https://github.com/dart-lang/sdk/issues/37229) // wrapper for a null-terminated array of characters in memory ("c-style string") class CString { Pointer _ptr; - CString(String dartStr) { // if this constructor is used, ".free" needs to be called on this instance - _ptr = allocate(count: dartStr.length + 1); - for(int i = 0; i < dartStr.length; ++i) - _ptr.elementAt(i).store(dartStr.codeUnitAt(i)); - _ptr.elementAt(dartStr.length).store(0); + // if this constructor is used, ".free" needs to be called on this instance + CString(String dartStr) { + final ints = encodeUtf8(dartStr); + _ptr = Pointer.allocate(count: ints.length + 1); + for(int i = 0; i < ints.length; ++i) { + _ptr.elementAt(i).store(ints.elementAt(i)); + } + _ptr.elementAt(ints.length).store(0); } CString.fromPtr(this._ptr); String get val { - String ret = "", c; - int i = 0; - while((c = String.fromCharCode(_ptr.elementAt(i++).load())).codeUnitAt(0) != 0) // TODO: unicode support - ret += c; - return ret; + List utf8CodePoints = new List(); + int element, i = 0; + + while(true) { + element = _ptr.elementAt(i++).load(); + if(element == 0) + break; + utf8CodePoints.add(element); + } + + return decodeUtf8(utf8CodePoints); } String toString() => val; diff --git a/lib/src/model.dart b/lib/src/model.dart index 281d7ba33..c5413dab7 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -1,120 +1,35 @@ import "dart:ffi"; -import "dart:mirrors"; import "bindings/bindings.dart"; -import "bindings/constants.dart"; import "bindings/helpers.dart"; import "ffi/cstring.dart"; class Entity { final int id, uid; - const Entity({this.id, this.uid}); -} - -enum Type { - Bool, - Byte, - Short, - Char, - Int, - Long, - Float, - Double, - String, - Date, - Relation, - ByteVector, - StringVector, + const Entity({this.id, this.uid}) : assert(id != null && id != 0), assert(uid != null && uid != 0); } class Property { - final Type type; + final int type; final int id, uid; const Property({this.id, this.uid, this.type = null}); } class Id { - final Type type; final int id, uid; - const Id({this.id, this.uid, this.type = null}); -} - -_getClassModel(cls) { - var refl = reflectClass(cls); - var properties = []; - - if(refl.metadata.length != 1) - return null; - var entity = { - "name": getSymbolName(refl.simpleName), - "id": refl.metadata[0].reflectee.id, - "uid": refl.metadata[0].reflectee.uid - }; - - refl.declarations.forEach((k, v) { - if(v.runtimeType.toString() != "_LocalVariableMirror") - return; // current declaration is not a member variable (i.e. a constructor, function etc. instead) - if(v.metadata.length != 1) - return; // too much or no metadata given - - var annotation = v.metadata[0].reflectee; - var annotationType = annotation.runtimeType.toString(); - var flags = 0; - if(annotationType == "Id") // TODO: check that there is exactly one ID property - flags |= OBXPropertyFlags.ID; - else if(annotationType != "Property") - return; // invalid annotation - - var propertyTypeObx; - if(annotation.type == null) { - var propertyType = refl.instanceMembers[k].returnType.reflectedType.toString(); - if(propertyType == "int") propertyTypeObx = OBXPropertyType.Int; // TODO: support more types - else if(propertyType == "String") propertyTypeObx = OBXPropertyType.String; - } else { - switch(annotation.type) { - case Type.Bool: propertyTypeObx = OBXPropertyType.Bool; break; - case Type.Byte: propertyTypeObx = OBXPropertyType.Byte; break; - case Type.Short: propertyTypeObx = OBXPropertyType.Short; break; - case Type.Char: propertyTypeObx = OBXPropertyType.Char; break; - case Type.Int: propertyTypeObx = OBXPropertyType.Int; break; - case Type.Long: propertyTypeObx = OBXPropertyType.Long; break; - case Type.Float: propertyTypeObx = OBXPropertyType.Float; break; - case Type.Double: propertyTypeObx = OBXPropertyType.Double; break; - case Type.String: propertyTypeObx = OBXPropertyType.String; break; - case Type.Date: propertyTypeObx = OBXPropertyType.Date; break; - case Type.Relation: propertyTypeObx = OBXPropertyType.Relation; break; - case Type.ByteVector: propertyTypeObx = OBXPropertyType.ByteVector; break; - case Type.StringVector: propertyTypeObx = OBXPropertyType.StringVector; break; - } - } - check(propertyTypeObx != null); - - var symbolName = getSymbolName(k); - var meta = v.metadata[0].reflectee; - properties.add({ - "name": symbolName, - "type": propertyTypeObx, - "id": meta.id, // TODO: check that id is unique in this entity - "uid": meta.uid, // TODO: check that uid is globally unique - "flags": flags, - }); - }); - - return { "entity": entity, "properties": properties }; + const Id({this.id, this.uid}); // type is always long } class Model { Pointer _objectboxModel; - var _modelDescriptions; - Model(classes) { - _objectboxModel = bindings.obx_model_create(); - check(_objectboxModel.address != 0); + Model(List> modelDefinitions) { + _objectboxModel = bindings.obx_model(); + checkObxPtr(_objectboxModel, "failed to create model"); try { // transform classes into model descriptions and loop through them - _modelDescriptions = classes.map(_getClassModel).where((m) => m != null).toList(); - _modelDescriptions.forEach((m) { + modelDefinitions.forEach((m) { // start entity var entityName = CString(m["entity"]["name"]); checkObx(bindings.obx_model_entity(_objectboxModel, entityName.ptr, m["entity"]["id"], m["entity"]["uid"])); @@ -136,8 +51,8 @@ class Model { }); // set last entity id - if(_modelDescriptions.length > 0) { - var lastEntity = _modelDescriptions[_modelDescriptions.length - 1]["entity"]; + if(modelDefinitions.length > 0) { + var lastEntity = modelDefinitions[modelDefinitions.length - 1]["entity"]; bindings.obx_model_last_entity_id(_objectboxModel, lastEntity["id"], lastEntity["uid"]); } } catch(e) { @@ -148,5 +63,4 @@ class Model { } get ptr => _objectboxModel; - get desc => _modelDescriptions; } diff --git a/lib/src/store.dart b/lib/src/store.dart index a431d993b..e781c0eb7 100644 --- a/lib/src/store.dart +++ b/lib/src/store.dart @@ -1,35 +1,51 @@ import "dart:ffi"; -import "dart:mirrors"; import "bindings/bindings.dart"; import "bindings/helpers.dart"; +import "ffi/cstring.dart"; import "model.dart"; class Store { Pointer _objectboxStore; - var _modelDescriptions; + Map> _modelDefinitions = {}; - Store(var classes) { // TODO: allow setting options, e.g. database path - var model = Model(classes); - _modelDescriptions = model.desc; + Store(List> defs, {String directory, int maxDBSizeInKB, int fileMode, int maxReaders}) { // TODO: allow setting options, e.g. database path + defs.forEach((d) => _modelDefinitions[d[0]] = d[1]); + var model = Model(defs.map((d) => d[1]["model"] as Map).toList()); var opt = bindings.obx_opt(); - check(opt.address != 0); + checkObxPtr(opt, "failed to create store options"); checkObx(bindings.obx_opt_model(opt, model.ptr)); + if(directory != null && directory.length != 0) { + var cStr = new CString(directory); + checkObx(bindings.obx_opt_directory(opt, cStr.ptr)); + cStr.free(); + } + if(maxDBSizeInKB != null && maxDBSizeInKB > 0) + bindings.obx_opt_max_db_size_in_kb(opt, maxDBSizeInKB); + if(fileMode != null && fileMode >= 0) + bindings.obx_opt_file_mode(opt, fileMode); + if(maxReaders != null && maxReaders > 0) + bindings.obx_opt_max_readers(opt, maxReaders); _objectboxStore = bindings.obx_store_open(opt); - check(_objectboxStore != null); - check(_objectboxStore.address != 0); + checkObxPtr(_objectboxStore, "failed to create store"); } close() { checkObx(bindings.obx_store_close(_objectboxStore)); } - getEntityDescriptionFromClass(cls) { - final clsName = getSymbolName(reflectClass(cls).simpleName); - final idx = _modelDescriptions.indexWhere((e) => e["entity"]["name"] == clsName); - return idx == -1 ? null : _modelDescriptions[idx]; + getEntityModelDefinitionFromClass(cls) { + return _modelDefinitions[cls]["model"]; + } + + getEntityReaderFromClass() { + return _modelDefinitions[T]["reader"] as Map Function(T); + } + + getEntityBuilderFromClass() { + return _modelDefinitions[T]["builder"] as T Function(Map); } get ptr => _objectboxStore; diff --git a/pubspec.yaml b/pubspec.yaml index e53166272..c0842dc59 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,8 +1,14 @@ name: objectbox -version: 0.0.1 +version: 0.2.0 description: >- ObjectBox binding for Dart. environment: - sdk: '>=2.2.2 <3.0.0' + sdk: '>=2.5.0 <3.0.0' dependencies: flat_buffers: ^1.11.0 + utf: ^0.9.0 +dev_dependencies: + build_runner: 1.0.0 + objectbox_model_generator: + path: bin/objectbox_model_generator + test: ^1.0.0 diff --git a/test/test.dart b/test/test.dart index 70068f746..f8a1f099c 100644 --- a/test/test.dart +++ b/test/test.dart @@ -1,27 +1,107 @@ -import "../lib/objectbox.dart"; +import "dart:io"; +import "package:test/test.dart"; +import "package:objectbox/objectbox.dart"; +part "test.g.dart"; @Entity(id: 1, uid: 1) -class Note { - @Id(id: 1, uid: 1001, type: Type.Long) +class TestEntity { + @Id(id: 1, uid: 1001) int id; @Property(id: 2, uid: 1002) String text; - Note(); - Note.construct(this.text); - - toString() => "Note{id: $id, text: $text}"; + TestEntity(); + TestEntity.constructWithId(this.id, this.text); + TestEntity.construct(this.text); } main() { - var store = Store([Note]); - var box = Box(store); - - var note = Note.construct("Hello"); - box.put(note); - print("new note got id ${note.id}"); - print("refetched note: ${box.getById(note.id)}"); - - store.close(); + Store store; + Box box; + + setUp(() { + store = Store([[TestEntity, TestEntity_OBXDefs]]); + box = Box(store); + }); + + group("box", () { + test(".put() returns a valid id", () { + int putId = box.put(TestEntity.construct("Hello")); + expect(putId, greaterThan(0)); + }); + + test(".get() returns the correct item", () { + final int putId = box.put(TestEntity.construct("Hello")); + final TestEntity item = box.get(putId); + expect(item.id, equals(putId)); + expect(item.text, equals("Hello")); + }); + + test(".put() and box.get() keep Unicode characters", () { + final String text = "😄你好"; + final TestEntity inst = box.get(box.put(TestEntity.construct(text))); + expect(inst.text, equals(text)); + }); + + test(".put() can update an item", () { + final int putId1 = box.put(TestEntity.construct("One")); + final int putId2 = box.put(TestEntity.constructWithId(putId1, "Two")); + expect(putId2, equals(putId1)); + final TestEntity item = box.get(putId2); + expect(item.text, equals("Two")); + }); + + test(".getAll retrieves all items", () { + final int id1 = box.put(TestEntity.construct("One")); + final int id2 = box.put(TestEntity.construct("Two")); + final int id3 = box.put(TestEntity.construct("Three")); + final List items = box.getAll(); + expect(items.length, equals(3)); + expect(items.where((i) => i.id == id1).single.text, equals("One")); + expect(items.where((i) => i.id == id2).single.text, equals("Two")); + expect(items.where((i) => i.id == id3).single.text, equals("Three")); + }); + + test(".putMany inserts multiple items", () { + final List items = [ + TestEntity.construct("One"), + TestEntity.construct("Two"), + TestEntity.construct("Three") + ]; + box.putMany(items); + final List itemsFetched = box.getAll(); + expect(itemsFetched.length, equals(items.length)); + }); + + test(".putMany returns the new item IDs", () { + final List items = ["One", "Two", "Three", "Four", "Five", "Six", "Seven"].map((s) => TestEntity.construct(s)).toList(); + final List ids = box.putMany(items); + expect(ids.length, equals(items.length)); + for(int i = 0; i < items.length; ++i) + expect(box.get(ids[i]).text, equals(items[i].text)); + }); + + test(".getMany correctly handles non-existant items", () { + final List items = ["One", "Two"].map((s) => TestEntity.construct(s)).toList(); + final List ids = box.putMany(items); + int otherId = 1; + while(ids.indexWhere((id) => id == otherId) != -1) + ++otherId; + final List fetchedItems = box.getMany([ids[0], otherId, ids[1]]); + expect(fetchedItems.length, equals(3)); + expect(fetchedItems[0].text, equals("One")); + expect(fetchedItems[1], equals(null)); + expect(fetchedItems[2].text, equals("Two")); + }); + }); + + tearDown(() { + if(store != null) + store.close(); + store = null; + var dir = new Directory("objectbox"); + if(dir.existsSync()) + dir.deleteSync(recursive: true); + }); }