зеркало из https://github.com/mozilla/toodle.git
Update Toodle iOS to work with current Mentat; use Carthage for build dependency.
This commit is contained in:
Родитель
0dc94faeb0
Коммит
e2847d75cb
|
@ -33,7 +33,13 @@ cd rust
|
|||
cargo lipo --release
|
||||
```
|
||||
|
||||
Open `ios/Toodle/Toodle.xcodeproj` in Xcode. Select the Toodle project from the project navigator, and then ensure the Toodle target is selected. Open the `General` tab. Scroll down to the `Linked Frameworks and Libraries` section. Import your `libtoodle.a` library by either dragging it in from Finder, or clicking the `+` at the bottom of the list, clicking 'Add other…' and navigating to `rust/target/universal/release/`. Select `libtoodle.a` and then click `Open`.
|
||||
We are now using [Carthage](https://github.com/Carthage/Carthage) to import external dependencies. Install Carthage using the [instructions](https://github.com/Carthage/Carthage#installing-carthage) on their site. Once installed, open a terminal and navigate to the iOS project root. To install the project dependencies, run the following command:
|
||||
|
||||
```
|
||||
carthage update
|
||||
```
|
||||
|
||||
Open `ios/Toodle/Toodle.xcodeproj` in Xcode. Select the Toodle project from the project navigator, and then ensure the Toodle target is selected. Open the `General` tab. Scroll down to the `Linked Frameworks and Libraries` section. Import your `libtoodle_ffi.a` library by either dragging it in from Finder, or clicking the `+` at the bottom of the list, clicking 'Add other…' and navigating to `rust/target/universal/release/`. Select `libtoodle_ffi.a` and then click `Open`.
|
||||
|
||||
You should now be able to build and run your iOS app.
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
github "mozilla/mentat" "grisha/sync-downloader"
|
|
@ -9,13 +9,15 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
7B1F2D701FB0D379000246C9 /* ToodleLib.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1F2D6F1FB0D379000246C9 /* ToodleLib.swift */; };
|
||||
7B2BA8C71F97B24E0093D191 /* ToDoListItemsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B2BA8C61F97B24E0093D191 /* ToDoListItemsTableViewController.swift */; };
|
||||
7B332361202BBA9700C67ABD /* libtoodle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 285DB5891FD8955E00154A8B /* libtoodle.a */; };
|
||||
7B45C8AE20CA8BCB00BC83C0 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B45C8AD20CA8BCB00BC83C0 /* libsqlite3.tbd */; };
|
||||
7B45C8B320CA8FAC00BC83C0 /* Cartfile in Resources */ = {isa = PBXBuildFile; fileRef = 7B45C8B220CA8FAC00BC83C0 /* Cartfile */; };
|
||||
7B45C8C120CA9E5500BC83C0 /* Mentat.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B45C8C020CA9E5500BC83C0 /* Mentat.framework */; };
|
||||
7B45C8C320CACA2800BC83C0 /* libtoodle_ffi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B45C8C220CACA2800BC83C0 /* libtoodle_ffi.a */; };
|
||||
7B47BBDE1F9A518D00FCA5AA /* ItemViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B47BBDD1F9A518D00FCA5AA /* ItemViewController.swift */; };
|
||||
7B89922A1FE16F9A007B0BE2 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8992291FE16F9A007B0BE2 /* Label.swift */; };
|
||||
7B8992321FE176C6007B0BE2 /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B89922F1FE176C5007B0BE2 /* UIColor+Hex.swift */; };
|
||||
7B8992331FE176C6007B0BE2 /* NSLayoutConstraint+Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8992301FE176C5007B0BE2 /* NSLayoutConstraint+Utils.swift */; };
|
||||
7B8992341FE176C6007B0BE2 /* Date+Int64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8992311FE176C5007B0BE2 /* Date+Int64.swift */; };
|
||||
7B99185420459D6700C9A842 /* TxReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B99185320459D6700C9A842 /* TxReport.swift */; };
|
||||
7B9F01101F794DB2000407E5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B9F010F1F794DB2000407E5 /* AppDelegate.swift */; };
|
||||
7B9F01151F794DB2000407E5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7B9F01131F794DB2000407E5 /* Main.storyboard */; };
|
||||
7B9F01171F794DB2000407E5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B9F01161F794DB2000407E5 /* Assets.xcassets */; };
|
||||
|
@ -23,7 +25,6 @@
|
|||
7B9F01281F794F3B000407E5 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B9F01271F794F3B000407E5 /* libresolv.tbd */; };
|
||||
7B9F013B1F827A23000407E5 /* ToDoListLabelsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B9F013A1F827A23000407E5 /* ToDoListLabelsViewController.swift */; };
|
||||
7BB2204D1F8F976C00ACD7AF /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BB2204C1F8F976C00ACD7AF /* Item.swift */; };
|
||||
7BB220541F8FA72500ACD7AF /* RustObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BB220531F8FA72500ACD7AF /* RustObject.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
|
@ -33,14 +34,15 @@
|
|||
7B2D0B802036F0F8009EB2CA /* toodle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = toodle.h; path = Toodle/Rust/toodle.h; sourceTree = SOURCE_ROOT; };
|
||||
7B2D0B812036F0F8009EB2CA /* items.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = items.h; path = Toodle/Rust/items.h; sourceTree = SOURCE_ROOT; };
|
||||
7B2D0B822036F0F8009EB2CA /* labels.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = labels.h; path = Toodle/Rust/labels.h; sourceTree = SOURCE_ROOT; };
|
||||
7B45C8AD20CA8BCB00BC83C0 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
|
||||
7B45C8B220CA8FAC00BC83C0 /* Cartfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile; sourceTree = "<group>"; };
|
||||
7B45C8C020CA9E5500BC83C0 /* Mentat.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Mentat.framework; path = Carthage/Build/iOS/Mentat.framework; sourceTree = "<group>"; };
|
||||
7B45C8C220CACA2800BC83C0 /* libtoodle_ffi.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtoodle_ffi.a; path = ../rust/target/universal/release/libtoodle_ffi.a; sourceTree = "<group>"; };
|
||||
7B47BBDD1F9A518D00FCA5AA /* ItemViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemViewController.swift; sourceTree = "<group>"; };
|
||||
7B8992291FE16F9A007B0BE2 /* Label.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
|
||||
7B89922F1FE176C5007B0BE2 /* UIColor+Hex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Hex.swift"; sourceTree = "<group>"; };
|
||||
7B8992301FE176C5007B0BE2 /* NSLayoutConstraint+Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSLayoutConstraint+Utils.swift"; sourceTree = "<group>"; };
|
||||
7B8992311FE176C5007B0BE2 /* Date+Int64.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Date+Int64.swift"; sourceTree = "<group>"; };
|
||||
7B99185220457CEC00C9A842 /* store.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = store.h; sourceTree = "<group>"; };
|
||||
7B99185320459D6700C9A842 /* TxReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TxReport.swift; sourceTree = "<group>"; };
|
||||
7B9D81B01FB0CFC30027C605 /* libtoodle.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtoodle.a; path = ../cargo/target/universal/release/libtoodle.a; sourceTree = "<group>"; };
|
||||
7B9F010C1F794DB2000407E5 /* Toodle.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Toodle.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7B9F010F1F794DB2000407E5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
7B9F01141F794DB2000407E5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
|
@ -49,10 +51,8 @@
|
|||
7B9F011B1F794DB2000407E5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
7B9F01241F794ED6000407E5 /* Toodle-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Toodle-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
7B9F01271F794F3B000407E5 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; };
|
||||
7B9F01291F794F49000407E5 /* libgreetings.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgreetings.a; path = ../cargo/target/universal/release/libgreetings.a; sourceTree = "<group>"; };
|
||||
7B9F013A1F827A23000407E5 /* ToDoListLabelsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToDoListLabelsViewController.swift; sourceTree = "<group>"; };
|
||||
7BB2204C1F8F976C00ACD7AF /* Item.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Item.swift; sourceTree = "<group>"; };
|
||||
7BB220531F8FA72500ACD7AF /* RustObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RustObject.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -60,8 +60,10 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
7B45C8C320CACA2800BC83C0 /* libtoodle_ffi.a in Frameworks */,
|
||||
7B45C8C120CA9E5500BC83C0 /* Mentat.framework in Frameworks */,
|
||||
7B45C8AE20CA8BCB00BC83C0 /* libsqlite3.tbd in Frameworks */,
|
||||
7B9F01281F794F3B000407E5 /* libresolv.tbd in Frameworks */,
|
||||
7B332361202BBA9700C67ABD /* libtoodle.a in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -83,11 +85,8 @@
|
|||
7B2BA8941F963C5C0093D191 /* Rust */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7BB220531F8FA72500ACD7AF /* RustObject.swift */,
|
||||
7B1F2D6C1FB0D318000246C9 /* List */,
|
||||
7B1F2D6F1FB0D379000246C9 /* ToodleLib.swift */,
|
||||
7B99185220457CEC00C9A842 /* store.h */,
|
||||
7B99185320459D6700C9A842 /* TxReport.swift */,
|
||||
);
|
||||
path = Rust;
|
||||
sourceTree = "<group>";
|
||||
|
@ -124,6 +123,7 @@
|
|||
7B9F01031F794DB1000407E5 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7B45C8B220CA8FAC00BC83C0 /* Cartfile */,
|
||||
7B9F010E1F794DB2000407E5 /* Toodle */,
|
||||
7B9F010D1F794DB2000407E5 /* Products */,
|
||||
7B9F01261F794F3B000407E5 /* Frameworks */,
|
||||
|
@ -156,9 +156,10 @@
|
|||
7B9F01261F794F3B000407E5 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7B9D81B01FB0CFC30027C605 /* libtoodle.a */,
|
||||
7B45C8C220CACA2800BC83C0 /* libtoodle_ffi.a */,
|
||||
7B45C8C020CA9E5500BC83C0 /* Mentat.framework */,
|
||||
7B45C8AD20CA8BCB00BC83C0 /* libsqlite3.tbd */,
|
||||
285DB5891FD8955E00154A8B /* libtoodle.a */,
|
||||
7B9F01291F794F49000407E5 /* libgreetings.a */,
|
||||
7B9F01271F794F3B000407E5 /* libresolv.tbd */,
|
||||
);
|
||||
name = Frameworks;
|
||||
|
@ -182,6 +183,7 @@
|
|||
7B9F01081F794DB1000407E5 /* Sources */,
|
||||
7B9F01091F794DB1000407E5 /* Frameworks */,
|
||||
7B9F010A1F794DB1000407E5 /* Resources */,
|
||||
7B45C8BF20CA9E2A00BC83C0 /* ShellScript */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
|
@ -199,7 +201,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0900;
|
||||
LastUpgradeCheck = 0900;
|
||||
LastUpgradeCheck = 0940;
|
||||
ORGANIZATIONNAME = Mozilla;
|
||||
TargetAttributes = {
|
||||
7B9F010B1F794DB1000407E5 = {
|
||||
|
@ -233,19 +235,36 @@
|
|||
files = (
|
||||
7B9F011A1F794DB2000407E5 /* LaunchScreen.storyboard in Resources */,
|
||||
7B9F01171F794DB2000407E5 /* Assets.xcassets in Resources */,
|
||||
7B45C8B320CA8FAC00BC83C0 /* Cartfile in Resources */,
|
||||
7B9F01151F794DB2000407E5 /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
7B45C8BF20CA9E2A00BC83C0 /* ShellScript */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
"$(SRCROOT)/Carthage/Build/iOS/Mentat.framework",
|
||||
);
|
||||
outputPaths = (
|
||||
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Mentat.framework",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "/usr/local/bin/carthage copy-frameworks";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
7B9F01081F794DB1000407E5 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
7BB220541F8FA72500ACD7AF /* RustObject.swift in Sources */,
|
||||
7B99185420459D6700C9A842 /* TxReport.swift in Sources */,
|
||||
7BB2204D1F8F976C00ACD7AF /* Item.swift in Sources */,
|
||||
7B8992331FE176C6007B0BE2 /* NSLayoutConstraint+Utils.swift in Sources */,
|
||||
7B1F2D701FB0D379000246C9 /* ToodleLib.swift in Sources */,
|
||||
|
@ -295,6 +314,7 @@
|
|||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = 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;
|
||||
|
@ -302,6 +322,7 @@
|
|||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
|
@ -352,6 +373,7 @@
|
|||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = 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;
|
||||
|
@ -359,6 +381,7 @@
|
|||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
|
@ -395,6 +418,10 @@
|
|||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = 8BHJ767F4Y;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)/Carthage/Build/iOS",
|
||||
);
|
||||
INFOPLIST_FILE = Toodle/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/../rust/target/universal/release";
|
||||
|
@ -413,6 +440,10 @@
|
|||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = 8BHJ767F4Y;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)/Carthage/Build/iOS",
|
||||
);
|
||||
INFOPLIST_FILE = Toodle/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/../rust/target/universal/release";
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
import Mentat
|
||||
|
||||
class ToDoListItemsTableViewController: UITableViewController {
|
||||
|
||||
lazy var syncToRefresh: UIRefreshControl = {
|
||||
|
@ -88,7 +90,8 @@ class ToDoListItemsTableViewController: UITableViewController {
|
|||
}
|
||||
|
||||
extension ToDoListItemsTableViewController: Observing {
|
||||
func transactionDidOccur(key: String, reports: [TxReport]) {
|
||||
|
||||
func transactionDidOccur(key: String, reports: [TxChange]) {
|
||||
print("transaction did occur \(key)")
|
||||
DispatchQueue.main.async {
|
||||
self.items = ToodleLib.sharedInstance.allItems()
|
||||
|
|
|
@ -16,7 +16,7 @@ class Item {
|
|||
}
|
||||
|
||||
deinit {
|
||||
item_c_destroy(raw)
|
||||
destroy(UnsafeMutableRawPointer(mutating: raw))
|
||||
}
|
||||
|
||||
var uuid: String? {
|
||||
|
|
|
@ -5,33 +5,26 @@
|
|||
import Foundation
|
||||
import UIKit
|
||||
|
||||
import Mentat
|
||||
|
||||
class Label: RustObject {
|
||||
var raw: OpaquePointer
|
||||
|
||||
required init(raw: OpaquePointer) {
|
||||
self.raw = raw
|
||||
}
|
||||
|
||||
func intoRaw() -> OpaquePointer {
|
||||
return self.raw
|
||||
}
|
||||
|
||||
deinit {
|
||||
label_destroy(raw)
|
||||
}
|
||||
|
||||
var name: String {
|
||||
return String(cString: label_get_name(raw))
|
||||
return String(cString: label_get_name(self.getRaw()))
|
||||
}
|
||||
|
||||
var color: UIColor {
|
||||
get {
|
||||
return UIColor(hex: String(cString: label_get_color(raw))) ?? UIColor.gray
|
||||
return UIColor(hex: String(cString: label_get_color(self.getRaw()))) ?? UIColor.gray
|
||||
}
|
||||
set {
|
||||
if let hex = newValue.toHex() {
|
||||
label_set_color(raw, hex)
|
||||
label_set_color(self.getRaw(), hex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func cleanup(pointer: OpaquePointer) {
|
||||
label_destroy(self.getRaw())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol RustObject {
|
||||
init(raw: OpaquePointer)
|
||||
func intoRaw() -> OpaquePointer
|
||||
}
|
|
@ -5,19 +5,9 @@
|
|||
import Foundation
|
||||
import UIKit
|
||||
|
||||
protocol Observing {
|
||||
// define functions for store observation
|
||||
func transactionDidOccur(key: String, reports: [TxReport])
|
||||
}
|
||||
import Mentat
|
||||
|
||||
protocol Observable {
|
||||
func register(key: String, observer: Observing, attributes: [String])
|
||||
func unregister(key: String)
|
||||
}
|
||||
|
||||
class ToodleLib {
|
||||
|
||||
var observers: [String: Observing]
|
||||
class ToodleLib: Mentat {
|
||||
|
||||
class var sharedInstance: ToodleLib {
|
||||
struct Static {
|
||||
|
@ -25,37 +15,22 @@ class ToodleLib {
|
|||
}
|
||||
return Static.instance
|
||||
}
|
||||
|
||||
var raw: OpaquePointer
|
||||
|
||||
required init(raw: OpaquePointer) {
|
||||
self.raw = raw
|
||||
self.observers = [:]
|
||||
}
|
||||
|
||||
func intoRaw() -> OpaquePointer {
|
||||
return self.raw
|
||||
}
|
||||
|
||||
|
||||
convenience init() {
|
||||
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
|
||||
let documentsURL = paths[0]
|
||||
let storeURI = documentsURL.appendingPathComponent("todolist.db", isDirectory: false).absoluteString
|
||||
|
||||
|
||||
self.init(raw: new_toodle(storeURI))
|
||||
}
|
||||
|
||||
deinit {
|
||||
toodle_destroy(raw)
|
||||
}
|
||||
|
||||
fileprivate func toPointerArray(list: [RustObject]) -> OpaquePointer {
|
||||
var pointerArray = list.map({ $0.intoRaw() })
|
||||
var pointerArray = list.map({ $0.getRaw() })
|
||||
return OpaquePointer(AutoreleasingUnsafeMutablePointer<[OpaquePointer]>(&pointerArray))
|
||||
}
|
||||
|
||||
func allItems() -> [Item] {
|
||||
let items = toodle_get_all_items(self.raw)
|
||||
let items = toodle_get_all_items(self.getRaw())
|
||||
var allItems: [Item] = []
|
||||
for index in 0..<item_list_count(items) {
|
||||
let item = Item(raw: item_list_entry_at(items, Int(index))!)
|
||||
|
@ -65,7 +40,7 @@ class ToodleLib {
|
|||
}
|
||||
|
||||
func createLabel(withName name: String, color: UIColor) -> Label {
|
||||
return Label(raw: toodle_create_label(self.raw, name, color.toHex()!))
|
||||
return Label(raw: toodle_create_label(self.getRaw(), name, color.toHex()!))
|
||||
}
|
||||
|
||||
func createItem(withName name: String, dueDate: Date?, completionDate: Date?, labels: [Label]) -> Item? {
|
||||
|
@ -75,7 +50,7 @@ class ToodleLib {
|
|||
dd = UnsafeMutablePointer<Int64>(&d)
|
||||
}
|
||||
|
||||
if let item_raw = toodle_create_item(self.raw, name, dd) {
|
||||
if let item_raw = toodle_create_item(self.getRaw(), name, dd) {
|
||||
return Item(raw: item_raw)
|
||||
}
|
||||
|
||||
|
@ -83,7 +58,7 @@ class ToodleLib {
|
|||
}
|
||||
|
||||
func item(withUuid uuid: String) -> Item? {
|
||||
guard let new_item = toodle_item_for_uuid(self.raw, uuid) else {
|
||||
guard let new_item = toodle_item_for_uuid(self.getRaw(), uuid) else {
|
||||
return nil
|
||||
}
|
||||
return Item(raw: new_item)
|
||||
|
@ -102,9 +77,9 @@ class ToodleLib {
|
|||
}
|
||||
var pointerArray = self.toPointerArray(list: labels as [RustObject])
|
||||
if let uuid = item.uuid {
|
||||
toodle_update_item_by_uuid(self.raw, uuid, name, dd, cd)
|
||||
toodle_update_item_by_uuid(self.getRaw(), uuid, name, dd, cd)
|
||||
} else {
|
||||
toodle_update_item(self.raw,
|
||||
toodle_update_item(self.getRaw(),
|
||||
item.raw,
|
||||
name,
|
||||
dd,
|
||||
|
@ -113,13 +88,9 @@ class ToodleLib {
|
|||
}
|
||||
}
|
||||
|
||||
func entidForAttribute(attribute: String) -> Int64 {
|
||||
return Int64(store_entid_for_attribute(self.raw, attribute))
|
||||
}
|
||||
|
||||
func sync_now() -> Bool {
|
||||
let err = store_sync(self.raw, "00000000-0000-0000-0000-000000000117", "http://mentat.dev.lcip.org/mentatsync/0.1")
|
||||
if let error = err.pointee.error {
|
||||
let err = toodle_sync(self.getRaw(), "00000000-0000-0000-0000-000000000117", "http://mentat.dev.lcip.org/mentatsync/0.1")
|
||||
if let error = err.pointee.err {
|
||||
let str = String(cString: error)
|
||||
print("Sync error \(str)")
|
||||
return false
|
||||
|
@ -129,56 +100,5 @@ class ToodleLib {
|
|||
}
|
||||
}
|
||||
|
||||
extension ToodleLib: Observable {
|
||||
func register(key: String, observer: Observing, attributes: [String]) {
|
||||
let attrEntIds = attributes.map({ (kw) -> Int64 in
|
||||
let entid = Int64(self.entidForAttribute(attribute: kw));
|
||||
print("entid for \(kw) is \(entid)")
|
||||
return entid
|
||||
})
|
||||
|
||||
print("registering observer for entids \(attrEntIds)")
|
||||
|
||||
let ptr = UnsafeMutablePointer<Int64>.allocate(capacity: attrEntIds.count)
|
||||
let entidPointer = UnsafeMutableBufferPointer(start: ptr, count: attrEntIds.count)
|
||||
var _ = entidPointer.initialize(from: attrEntIds)
|
||||
|
||||
guard let firstElement = entidPointer.baseAddress else {
|
||||
return
|
||||
}
|
||||
self.observers[key] = observer
|
||||
store_register_observer(self.raw, key, firstElement, Int64(attributes.count), transactionObserverCallback)
|
||||
|
||||
}
|
||||
|
||||
func unregister(key: String) {
|
||||
store_unregister_observer(self.raw, key)
|
||||
}
|
||||
|
||||
func transactionObserverCalled(key: String, reports: [TxReport]) {
|
||||
let observer = self.observers[key]
|
||||
observer?.transactionDidOccur(key: key, reports: reports)
|
||||
}
|
||||
}
|
||||
|
||||
class Singleton {
|
||||
}
|
||||
|
||||
private func transactionObserverCallback(key: UnsafePointer<CChar>, reports: UnsafePointer<TxReportList>) {
|
||||
// needs to be done in the same thread as the calling thread otherwise the TxReportList might be released before
|
||||
// we can reference it.
|
||||
let len = Int(reports.pointee.len)
|
||||
var txReports = [TxReport]()
|
||||
for i in 0..<len {
|
||||
let raw = tx_report_list_entry_at(reports, i)
|
||||
let report = TxReport(raw: raw!)
|
||||
txReports.append(report)
|
||||
}
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
ToodleLib.sharedInstance.transactionObserverCalled(key: String(cString: key), reports: txReports)
|
||||
}
|
||||
}
|
||||
|
||||
private func destroy(obj: UnsafeMutableRawPointer) {
|
||||
let _ = Unmanaged<AnyObject>.fromOpaque(UnsafeRawPointer(obj)).takeRetainedValue()
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Foundation
|
||||
|
||||
class TxReport {
|
||||
var raw: UnsafePointer<ExternTxReport>
|
||||
|
||||
required init(raw: UnsafePointer<ExternTxReport>) {
|
||||
self.raw = raw
|
||||
}
|
||||
|
||||
func intoRaw() -> UnsafePointer<ExternTxReport> {
|
||||
return self.raw
|
||||
}
|
||||
|
||||
// deinit {
|
||||
// item_c_destroy(raw)
|
||||
// }
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#ifndef items_h
|
||||
#define items_h
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#ifndef labels_h
|
||||
#define labels_h
|
||||
|
||||
#import "items.h"
|
||||
|
||||
struct Toodle;
|
||||
struct Label;
|
||||
|
||||
void label_destroy(struct Label* _Nullable obj);
|
||||
|
||||
struct Label* _Nonnull toodle_create_label(const struct Toodle* _Nonnull manager, const char* _Nonnull name, const char* _Nonnull color);
|
||||
const struct Label* _Nonnull* _Nonnull toodle_get_all_labels(const struct Toodle* _Nonnull manager);
|
||||
const size_t label_list_count(const struct Label* _Nonnull* _Nonnull list);
|
||||
|
@ -13,7 +15,6 @@ const void label_list_destroy(const struct Label* _Nonnull* _Nonnull list);
|
|||
const struct Label* _Nonnull label_list_entry_at(const struct Label* _Nonnull* _Nonnull list, size_t index);
|
||||
const void add_label(const struct Label* _Nonnull* _Nonnull list, const struct label* _Nonnull label);
|
||||
|
||||
const void label_destroy(const struct Label* _Nonnull label);
|
||||
const char* _Nonnull label_get_name(const struct Label* _Nonnull label);
|
||||
const char* _Nonnull label_get_color(const struct Label* _Nonnull label);
|
||||
const void label_set_color(struct Label* _Nonnull label, const char* _Nonnull color);
|
||||
|
|
|
@ -1,37 +1,240 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
/* Copyright 2018 Mozilla
|
||||
*
|
||||
* 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. */
|
||||
|
||||
#ifndef store_h
|
||||
#define store_h
|
||||
#include <stdint.h>
|
||||
#include <Foundation/NSObjCRuntime.h>
|
||||
|
||||
struct ExternTxReport {
|
||||
/*
|
||||
* This file contains headers for all of the structs and functions that map directly to the functions
|
||||
* defined in mentat/ffi/src/lib.rs.
|
||||
*
|
||||
* The C in this file is specifically formatted to be used with Objective C and Swift and contains
|
||||
* macros and flags that will not be recognised by other C based languages.
|
||||
*/
|
||||
|
||||
/*
|
||||
A mapping of the TxChange repr(C) Rust object.
|
||||
The memory for this is managed by Swift.
|
||||
*/
|
||||
struct TxChange {
|
||||
int64_t txid;
|
||||
int64_t*_Nonnull* _Nonnull changes;
|
||||
uint64_t len;
|
||||
};
|
||||
|
||||
struct Result {
|
||||
char* _Nullable error;
|
||||
};
|
||||
|
||||
struct Store;
|
||||
|
||||
struct TxReportList {
|
||||
struct ExternTxReport*_Nonnull* _Nonnull reports;
|
||||
/*
|
||||
A mapping of the TxChangeList repr(C) Rust object.
|
||||
The memory for this is managed by Swift.
|
||||
*/
|
||||
struct TxChangeList {
|
||||
struct TxChange*_Nonnull* _Nonnull reports;
|
||||
uint64_t len;
|
||||
};
|
||||
typedef struct TxChangeList TxChangeList;
|
||||
|
||||
struct Store*_Nonnull new_store(const char*_Nonnull uri);
|
||||
void store_destroy(struct Store*_Nonnull store);
|
||||
/*
|
||||
A mapping of the ExternResult repr(C) Rust object.
|
||||
The memory for this is managed by Swift.
|
||||
*/
|
||||
struct Result {
|
||||
void* _Nullable ok;
|
||||
char* _Nullable err;
|
||||
};
|
||||
typedef struct Result Result;
|
||||
|
||||
/*
|
||||
A mapping of the ExternOption repr(C) Rust object.
|
||||
The memory for this is managed by Swift.
|
||||
*/
|
||||
struct Option {
|
||||
void* _Nullable value;
|
||||
};
|
||||
typedef struct Option Option;
|
||||
|
||||
/*
|
||||
A mapping of the InProgressTransactResult repr(C) Rust object.
|
||||
The memory for this is managed by Swift.
|
||||
*/
|
||||
struct InProgressTransactResult {
|
||||
struct InProgress*_Nonnull inProgress;
|
||||
struct Result*_Nonnull result;
|
||||
};
|
||||
typedef struct InProgressTransactResult InProgressTransactResult;
|
||||
|
||||
/*
|
||||
A Mapping for the ValueType Rust object.
|
||||
*/
|
||||
typedef NS_ENUM(NSInteger, ValueType) {
|
||||
ValueTypeRef = 1,
|
||||
ValueTypeBoolean,
|
||||
ValueTypeInstant,
|
||||
ValueTypeLong,
|
||||
ValueTypeDouble,
|
||||
ValueTypeString,
|
||||
ValueTypeKeyword,
|
||||
ValueTypeUuid
|
||||
};
|
||||
|
||||
// Opaque Structs mapping to Rust types that are passed over the FFI boundary
|
||||
struct EntityBuilder;
|
||||
struct InProgress;
|
||||
struct InProgressBuilder;
|
||||
struct Query;
|
||||
struct QueryResultRow;
|
||||
struct QueryResultRows;
|
||||
struct QueryRowsIterator;
|
||||
struct QueryRowIterator;
|
||||
struct Store;
|
||||
struct TxReport;
|
||||
struct TypedValue;
|
||||
|
||||
// Store
|
||||
struct Store*_Nonnull store_open(const char*_Nonnull uri);
|
||||
|
||||
// Destructors.
|
||||
void destroy(void* _Nullable obj);
|
||||
void query_builder_destroy(struct Query* _Nullable obj);
|
||||
void store_destroy(struct Store* _Nonnull obj);
|
||||
void tx_report_destroy(struct TxReport* _Nonnull obj);
|
||||
void typed_value_destroy(struct TypedValue* _Nullable obj);
|
||||
void typed_value_list_destroy(struct QueryResultRow* _Nullable obj);
|
||||
void typed_value_list_iter_destroy(struct QueryRowIterator* _Nullable obj);
|
||||
void typed_value_result_set_destroy(struct QueryResultRows* _Nullable obj);
|
||||
void typed_value_result_set_iter_destroy(struct QueryRowsIterator* _Nullable obj);
|
||||
void in_progress_destroy(struct InProgress* _Nullable obj);
|
||||
void in_progress_builder_destroy(struct InProgressBuilder* _Nullable obj);
|
||||
void entity_builder_destroy(struct EntityBuilder* _Nullable obj);
|
||||
|
||||
// caching
|
||||
struct Result*_Nonnull store_cache_attribute_forward(struct Store*_Nonnull store, const char* _Nonnull attribute);
|
||||
struct Result*_Nonnull store_cache_attribute_reverse(struct Store*_Nonnull store, const char* _Nonnull attribute);
|
||||
struct Result*_Nonnull store_cache_attribute_bi_directional(struct Store*_Nonnull store, const char* _Nonnull attribute);
|
||||
|
||||
// transact
|
||||
struct Result*_Nonnull store_transact(struct Store*_Nonnull store, const char* _Nonnull transaction);
|
||||
const int64_t* _Nullable tx_report_entity_for_temp_id(const struct TxReport* _Nonnull report, const char* _Nonnull tempid);
|
||||
int64_t tx_report_get_entid(const struct TxReport* _Nonnull report);
|
||||
int64_t tx_report_get_tx_instant(const struct TxReport* _Nonnull report);
|
||||
struct Result*_Nonnull store_begin_transaction(struct Store*_Nonnull store);
|
||||
|
||||
// in progress
|
||||
struct Result*_Nonnull in_progress_transact(struct InProgress*_Nonnull in_progress, const char* _Nonnull transaction);
|
||||
struct Result*_Nonnull in_progress_commit(struct InProgress*_Nonnull in_progress);
|
||||
struct Result*_Nonnull in_progress_rollback(struct InProgress*_Nonnull in_progress);
|
||||
|
||||
// in_progress entity building
|
||||
struct Result*_Nonnull store_in_progress_builder(struct Store*_Nonnull store);
|
||||
struct InProgressBuilder*_Nonnull in_progress_builder(struct InProgress*_Nonnull in_progress);
|
||||
struct EntityBuilder*_Nonnull in_progress_entity_builder_from_temp_id(struct InProgress*_Nonnull in_progress, const char*_Nonnull temp_id);
|
||||
struct EntityBuilder*_Nonnull in_progress_entity_builder_from_entid(struct InProgress*_Nonnull in_progress, const int64_t entid);
|
||||
struct Result*_Nonnull in_progress_builder_add_string(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const char*_Nonnull value);
|
||||
struct Result*_Nonnull in_progress_builder_add_long(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull in_progress_builder_add_ref(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull in_progress_builder_add_keyword(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const char*_Nonnull value);
|
||||
struct Result*_Nonnull in_progress_builder_add_timestamp(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull in_progress_builder_add_boolean(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const int32_t value);
|
||||
struct Result*_Nonnull in_progress_builder_add_double(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const double value);
|
||||
struct Result*_Nonnull in_progress_builder_add_uuid(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const uuid_t* _Nonnull value);
|
||||
struct Result*_Nonnull in_progress_builder_retract_string(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const char*_Nonnull value);
|
||||
struct Result*_Nonnull in_progress_builder_retract_long(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull in_progress_builder_retract_ref(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull in_progress_builder_retract_keyword(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const char*_Nonnull value);
|
||||
struct Result*_Nonnull in_progress_builder_retract_timestamp(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull in_progress_builder_retract_boolean(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const int32_t value);
|
||||
struct Result*_Nonnull in_progress_builder_retract_double(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const double value);
|
||||
struct Result*_Nonnull in_progress_builder_retract_uuid(struct InProgressBuilder*_Nonnull builder, const int64_t entid, const char*_Nonnull kw, const uuid_t* _Nonnull value);
|
||||
struct InProgressTransactResult*_Nonnull in_progress_builder_transact(struct InProgressBuilder*_Nonnull builder);
|
||||
struct Result*_Nonnull in_progress_builder_commit(struct InProgressBuilder*_Nonnull builder);
|
||||
|
||||
// entity building
|
||||
struct Result*_Nonnull store_entity_builder_from_temp_id(struct Store*_Nonnull store, const char*_Nonnull temp_id);
|
||||
struct Result*_Nonnull store_entity_builder_from_entid(struct Store*_Nonnull store, const int64_t entid);
|
||||
struct Result*_Nonnull entity_builder_add_string(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const char*_Nonnull value);
|
||||
struct Result*_Nonnull entity_builder_add_long(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull entity_builder_add_ref(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull entity_builder_add_keyword(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const char*_Nonnull value);
|
||||
struct Result*_Nonnull entity_builder_add_boolean(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const int32_t value);
|
||||
struct Result*_Nonnull entity_builder_add_double(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const double value);
|
||||
struct Result*_Nonnull entity_builder_add_timestamp(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull entity_builder_add_uuid(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const uuid_t* _Nonnull value);
|
||||
struct Result*_Nonnull entity_builder_retract_string(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const char*_Nonnull value);
|
||||
struct Result*_Nonnull entity_builder_retract_long(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull entity_builder_retract_ref(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull entity_builder_retract_keyword(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const char*_Nonnull value);
|
||||
struct Result*_Nonnull entity_builder_retract_boolean(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const int32_t value);
|
||||
struct Result*_Nonnull entity_builder_retract_double(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const double value);
|
||||
struct Result*_Nonnull entity_builder_retract_timestamp(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const int64_t value);
|
||||
struct Result*_Nonnull entity_builder_retract_uuid(struct EntityBuilder*_Nonnull builder, const char*_Nonnull kw, const uuid_t* _Nonnull value);
|
||||
struct InProgressTransactResult*_Nonnull entity_builder_transact(struct InProgressBuilder*_Nonnull builder);
|
||||
struct Result*_Nonnull entity_builder_commit(struct EntityBuilder*_Nonnull builder);
|
||||
|
||||
// Sync
|
||||
struct Result*_Nonnull store_sync(struct Store*_Nonnull store, const char* _Nonnull user_uuid, const char* _Nonnull server_uri);
|
||||
|
||||
void store_register_observer(struct Store*_Nonnull store, const char* _Nonnull key, const int64_t* _Nonnull attributes, const int64_t len, void (*_Nonnull callback_fn)(const char* _Nonnull key, const struct TxReportList* _Nonnull reports));
|
||||
// Observers
|
||||
void store_register_observer(struct Store*_Nonnull store, const char* _Nonnull key, const int64_t* _Nonnull attributes, const int64_t len, void (*_Nonnull callback_fn)(const char* _Nonnull key, const struct TxChangeList* _Nonnull reports));
|
||||
void store_unregister_observer(struct Store*_Nonnull store, const char* _Nonnull key);
|
||||
int64_t store_entid_for_attribute(struct Store*_Nonnull store, const char*_Nonnull attr);
|
||||
int64_t changelist_entry_at(const struct TxChange* _Nonnull report, size_t index);
|
||||
|
||||
const struct ExternTxReport* _Nullable tx_report_list_entry_at(const struct TxReportList* _Nonnull list, size_t index);
|
||||
const struct int64_t changelist_entry_at(const struct ExternTxReport* _Nonnull report, size_t index);
|
||||
// Query
|
||||
struct Query*_Nonnull store_query(struct Store*_Nonnull store, const char* _Nonnull query);
|
||||
struct Result*_Nonnull store_value_for_attribute(struct Store*_Nonnull store, const int64_t entid, const char* _Nonnull attribute);
|
||||
|
||||
// Query Variable Binding
|
||||
void query_builder_bind_long(struct Query*_Nonnull query, const char* _Nonnull var, const int64_t value);
|
||||
void query_builder_bind_ref(struct Query*_Nonnull query, const char* _Nonnull var, const int64_t value);
|
||||
void query_builder_bind_ref_kw(struct Query*_Nonnull query, const char* _Nonnull var, const char* _Nonnull value);
|
||||
void query_builder_bind_kw(struct Query*_Nonnull query, const char* _Nonnull var, const char* _Nonnull value);
|
||||
void query_builder_bind_boolean(struct Query*_Nonnull query, const char* _Nonnull var, const int32_t value);
|
||||
void query_builder_bind_double(struct Query*_Nonnull query, const char* _Nonnull var, const double value);
|
||||
void query_builder_bind_timestamp(struct Query*_Nonnull query, const char* _Nonnull var, const int64_t value);
|
||||
void query_builder_bind_string(struct Query*_Nonnull query, const char* _Nonnull var, const char* _Nonnull value);
|
||||
void query_builder_bind_uuid(struct Query*_Nonnull query, const char* _Nonnull var, const uuid_t* _Nonnull value);
|
||||
|
||||
// Query execution
|
||||
struct Result*_Nonnull query_builder_execute(struct Query*_Nonnull query);
|
||||
struct Result*_Nonnull query_builder_execute_scalar(struct Query*_Nonnull query);
|
||||
struct Result*_Nonnull query_builder_execute_coll(struct Query*_Nonnull query);
|
||||
struct Result*_Nonnull query_builder_execute_tuple(struct Query*_Nonnull query);
|
||||
|
||||
// Query Result Processing
|
||||
int64_t typed_value_into_long(struct TypedValue*_Nonnull value);
|
||||
int64_t typed_value_into_entid(struct TypedValue*_Nonnull value);
|
||||
const char* _Nonnull typed_value_into_kw(struct TypedValue*_Nonnull value);
|
||||
int32_t typed_value_into_boolean(struct TypedValue*_Nonnull value);
|
||||
double typed_value_into_double(struct TypedValue*_Nonnull value);
|
||||
int64_t typed_value_into_timestamp(struct TypedValue*_Nonnull value);
|
||||
const char* _Nonnull typed_value_into_string(struct TypedValue*_Nonnull value);
|
||||
const uuid_t* _Nonnull typed_value_into_uuid(struct TypedValue*_Nonnull value);
|
||||
enum ValueType typed_value_value_type(struct TypedValue*_Nonnull value);
|
||||
|
||||
struct QueryResultRow* _Nullable row_at_index(struct QueryResultRows* _Nonnull rows, const int32_t index);
|
||||
struct QueryRowsIterator* _Nonnull typed_value_result_set_into_iter(struct QueryResultRows* _Nonnull rows);
|
||||
struct QueryResultRow* _Nullable typed_value_result_set_iter_next(struct QueryRowsIterator* _Nonnull iter);
|
||||
struct QueryRowIterator* _Nonnull typed_value_list_into_iter(struct QueryResultRow* _Nonnull row);
|
||||
struct TypedValue* _Nullable typed_value_list_iter_next(struct QueryRowIterator* _Nonnull iter);
|
||||
|
||||
struct TypedValue* _Nonnull value_at_index(struct QueryResultRow* _Nonnull row, const int32_t index);
|
||||
int64_t value_at_index_into_long(struct QueryResultRow* _Nonnull row, const int32_t index);
|
||||
int64_t value_at_index_into_entid(struct QueryResultRow* _Nonnull row, const int32_t index);
|
||||
const char* _Nonnull value_at_index_into_kw(struct QueryResultRow* _Nonnull row, const int32_t index);
|
||||
int32_t value_at_index_into_boolean(struct QueryResultRow* _Nonnull row, const int32_t index);
|
||||
double value_at_index_into_double(struct QueryResultRow* _Nonnull row, const int32_t index);
|
||||
int64_t value_at_index_into_timestamp(struct QueryResultRow* _Nonnull row, const int32_t index);
|
||||
const char* _Nonnull value_at_index_into_string(struct QueryResultRow* _Nonnull row, const int32_t index);
|
||||
const uuid_t* _Nonnull value_at_index_into_uuid(struct QueryResultRow* _Nonnull row, const int32_t index);
|
||||
|
||||
// Transaction change lists
|
||||
const struct TxChange* _Nullable tx_change_list_entry_at(const struct TxChangeList* _Nonnull list, size_t index);
|
||||
|
||||
#endif /* store_h */
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#include <stdint.h>
|
||||
#include "labels.h"
|
||||
#import "items.h"
|
||||
#include "store.h"
|
||||
|
||||
struct Store*_Nonnull new_toodle(const char*_Nonnull uri);
|
||||
struct Store*_Nonnull new_label(const char*_Nonnull uri);
|
||||
void toodle_destroy(struct Store*_Nonnull toodle);
|
||||
struct Result*_Nonnull toodle_sync(struct Store*_Nonnull toodle, const char*_Nonnull user_uuid, const char*_Nonnull server_uri);
|
||||
|
||||
|
|
|
@ -27,9 +27,9 @@ pub struct Label {
|
|||
impl Label {
|
||||
pub fn from_row(row: &Vec<Binding>) -> Option<Label> {
|
||||
Some(Label {
|
||||
id: None,
|
||||
name: row[0].clone().val().map(|v| v.to_inner()).expect("typed value"),
|
||||
color: row[1].clone().val().map(|v| v.to_inner()).expect("typed value")
|
||||
id: row[0].clone().val().map(|v| v.to_inner()).expect("typed value"),
|
||||
name: row[1].clone().val().map(|v| v.to_inner()).expect("typed value"),
|
||||
color: row[2].clone().val().map(|v| v.to_inner()).expect("typed value")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,8 +182,10 @@ impl Toodle for Store {
|
|||
}
|
||||
|
||||
fn item_row_to_item(&mut self, row: Vec<Binding>) -> Item {
|
||||
//println!("Toodle::item_row_to_item");
|
||||
println!("Toodle::item_row_to_item");
|
||||
let uuid = row[1].clone().val().expect("typed value").to_inner();
|
||||
let labels = self.fetch_labels_for_item(&uuid).unwrap_or(vec![]);
|
||||
println!("fetched labels {:?}", labels);
|
||||
let item;
|
||||
{
|
||||
item = Item {
|
||||
|
@ -192,7 +194,7 @@ impl Toodle for Store {
|
|||
name: row[2].clone().val().expect("typed value").to_inner(),
|
||||
due_date: self.fetch_due_date_for_item(&uuid).unwrap_or(None),
|
||||
completion_date: self.fetch_completion_date_for_item(&uuid).unwrap_or(None),
|
||||
labels: self.fetch_labels_for_item(&uuid).unwrap_or(vec![]),
|
||||
labels: labels,
|
||||
}
|
||||
}
|
||||
item
|
||||
|
@ -245,7 +247,7 @@ impl Toodle for Store {
|
|||
}
|
||||
|
||||
fn fetch_labels_for_item(&mut self, item_uuid: &Uuid) -> Result<Vec<Label>> {
|
||||
//println!("Toodle::fetch_labels_for_item");
|
||||
println!("Toodle::fetch_labels_for_item");
|
||||
let query = r#"[:find ?l ?name ?color
|
||||
:in ?item_uuid
|
||||
:where
|
||||
|
@ -380,6 +382,11 @@ impl Toodle for Store {
|
|||
log::d(&format!("create_item builder completion_date"));
|
||||
}
|
||||
|
||||
for label in item.labels.iter() {
|
||||
builder.add_kw(&kw!(:todo/label), label.id.clone().unwrap().to_typed_value())?;
|
||||
log::d(&format!("create_item builder label"));
|
||||
}
|
||||
|
||||
log::d(&format!("create_item builder pre commit"));
|
||||
builder.commit()?;
|
||||
log::d(&format!("create_item builder post commit"));
|
||||
|
@ -484,9 +491,9 @@ impl Toodle for Store {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{
|
||||
Toodle,
|
||||
Label,
|
||||
Item,
|
||||
Label,
|
||||
Toodle,
|
||||
create_uuid,
|
||||
};
|
||||
|
||||
|
@ -496,11 +503,14 @@ mod test {
|
|||
|
||||
use mentat::{
|
||||
Uuid,
|
||||
Store,
|
||||
};
|
||||
use mentat::edn;
|
||||
|
||||
fn toodle() -> Store {
|
||||
Store::open(String::new()).expect("Expected a Toodle")
|
||||
let mut store = Store::open("").expect("Expected a Toodle");
|
||||
store.initialize().expect("expected initialize to work");
|
||||
store
|
||||
}
|
||||
|
||||
fn assert_ident_present(edn: edn::Value, namespace: &str, name: &str) -> bool {
|
||||
|
@ -519,7 +529,7 @@ mod test {
|
|||
let mut found = false;
|
||||
for (key, val) in &m {
|
||||
if let edn::Value::Keyword(ref kw) = *key {
|
||||
if kw.namespace == "db" && kw.name == "ident" {
|
||||
if kw.namespace() == Some("db") && kw.name() == "ident" {
|
||||
found = assert_ident_present(val.clone(), namespace, name);
|
||||
if found { break; }
|
||||
} else {
|
||||
|
@ -529,7 +539,7 @@ mod test {
|
|||
}
|
||||
found
|
||||
},
|
||||
edn::Value::Keyword(kw) => kw.namespace == namespace && kw.name == name,
|
||||
edn::Value::Keyword(kw) => kw.namespace() == Some(namespace) && kw.name() == name,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
@ -537,7 +547,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_new_toodle() {
|
||||
let manager = toodle();
|
||||
let conn = manager.connection.conn();
|
||||
let conn = manager.conn();
|
||||
let schema = conn.current_schema().to_edn_value();
|
||||
assert_ident_present(schema.clone(), "label", "name");
|
||||
assert_ident_present(schema, "list", "name");
|
||||
|
@ -821,6 +831,7 @@ mod test {
|
|||
let label = manager.create_label("label1".to_string(), "#000000".to_string()).expect("expected a label option").unwrap();
|
||||
let label2 = manager.create_label("label2".to_string(), "#000000".to_string()).expect("expected a label option").unwrap();
|
||||
let label3 = manager.create_label("label3".to_string(), "#000000".to_string()).expect("expected a label option").unwrap();
|
||||
println!("labels created");
|
||||
|
||||
let item1 = Item {
|
||||
id: None,
|
||||
|
@ -832,8 +843,12 @@ mod test {
|
|||
};
|
||||
|
||||
let mut created_item = manager.create_and_fetch_item(&item1).expect("expected an item option").expect("expected an item");
|
||||
println!("item created");
|
||||
let mut new_labels = created_item.labels.clone();
|
||||
println!("new labels cloned");
|
||||
|
||||
new_labels.remove(2);
|
||||
println!("removed two labels");
|
||||
|
||||
match manager.update_item(&created_item, None, None, None, Some(&new_labels)) {
|
||||
Ok(()) => (),
|
||||
|
|
|
@ -19,8 +19,6 @@ use mentat::{
|
|||
Uuid,
|
||||
};
|
||||
|
||||
use mentat::errors::Error as MentatError;
|
||||
|
||||
use mentat_ffi::utils::strings::{
|
||||
c_char_to_string,
|
||||
string_to_c_char,
|
||||
|
@ -31,27 +29,6 @@ use toodle::items::{
|
|||
Items,
|
||||
};
|
||||
|
||||
pub struct ResultC {
|
||||
pub error: *const c_char,
|
||||
}
|
||||
|
||||
impl From<Result<(), MentatError>> for ResultC {
|
||||
fn from(result: Result<(), MentatError>) -> Self {
|
||||
match result {
|
||||
Ok(_) => {
|
||||
ResultC {
|
||||
error: ::std::ptr::null(),
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
ResultC {
|
||||
error: string_to_c_char(e.description())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ItemC {
|
||||
|
|
|
@ -32,6 +32,7 @@ pub use mentat::{
|
|||
};
|
||||
|
||||
pub use mentat_ffi::{
|
||||
ExternResult,
|
||||
store_destroy,
|
||||
store_entid_for_attribute,
|
||||
store_register_observer,
|
||||
|
@ -77,7 +78,7 @@ pub extern "C" fn new_toodle(uri: *const c_char) -> *mut Store {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn toodle_sync(manager: *mut Store, user_uuid: *const c_char, server_uri: *const c_char) -> *mut ctypes::ResultC {
|
||||
pub unsafe extern "C" fn toodle_sync(manager: *mut Store, user_uuid: *const c_char, server_uri: *const c_char) -> *mut ExternResult {
|
||||
let manager = &mut*manager;
|
||||
let user_uuid = c_char_to_string(user_uuid).to_string();
|
||||
let server_uri = c_char_to_string(server_uri).to_string();
|
||||
|
|
Загрузка…
Ссылка в новой задаче