swift/jni/ref: Use opts struct for init; use C99 bool
This CL replaces v23_syncbase_Bool with C99's Bool and equivalent
helpers. It also replaces the v23_syncbase_Init parameters with an
options struct, adding a verbose level option that routes to VLog,
and alphabetizes the C struct types and helper functions.
MultiPart: 2/2
Change-Id: I867d7352aa1eacdcd99e8fa0057750fc48014d28
diff --git a/SyncbaseCore/Source/Collection.swift b/SyncbaseCore/Source/Collection.swift
index 60e22dd..1ce591b 100644
--- a/SyncbaseCore/Source/Collection.swift
+++ b/SyncbaseCore/Source/Collection.swift
@@ -27,13 +27,13 @@
/// do not exist.
public func exists() throws -> Bool {
return try VError.maybeThrow { errPtr in
- var exists = v23_syncbase_Bool(false)
+ var exists = false
v23_syncbase_CollectionExists(
try encodedCollectionName.toCgoString(),
try cBatchHandle(),
&exists,
errPtr)
- return exists.toBool()
+ return exists
}
}
@@ -91,7 +91,7 @@
/// Returns true if there is a value associated with `key`.
public func exists(key: String) throws -> Bool {
- var exists = v23_syncbase_Bool(false)
+ var exists = false
try VError.maybeThrow { errPtr in
v23_syncbase_RowExists(
try encodedRowName(key),
@@ -99,7 +99,7 @@
&exists,
errPtr)
}
- return exists.toBool()
+ return exists
}
/**
diff --git a/SyncbaseCore/Source/Database.swift b/SyncbaseCore/Source/Database.swift
index 16c750d..0d50592 100644
--- a/SyncbaseCore/Source/Database.swift
+++ b/SyncbaseCore/Source/Database.swift
@@ -71,9 +71,9 @@
// cause Exists to return false instead of an error.
public func exists() throws -> Bool {
return try VError.maybeThrow { errPtr in
- var exists = v23_syncbase_Bool(false)
+ var exists = false
v23_syncbase_DbExists(try encodedDatabaseName.toCgoString(), &exists, errPtr)
- return exists.toBool()
+ return exists
}
}
diff --git a/SyncbaseCore/Source/Neighborhood.swift b/SyncbaseCore/Source/Neighborhood.swift
index 4247a58..e0f8bc8 100644
--- a/SyncbaseCore/Source/Neighborhood.swift
+++ b/SyncbaseCore/Source/Neighborhood.swift
@@ -58,9 +58,9 @@
if !Syncbase.didInit || !Syncbase.isLoggedIn {
return false
}
- var isAdvertising = v23_syncbase_Bool(false)
+ var isAdvertising = false
v23_syncbase_NeighborhoodIsAdvertising(&isAdvertising)
- return isAdvertising.toBool()
+ return isAdvertising
}
public static func startScan(handler: NeighborhoodScanHandler) throws {
diff --git a/SyncbaseCore/Source/Syncbase.swift b/SyncbaseCore/Source/Syncbase.swift
index 62ba3aa..e30345c 100644
--- a/SyncbaseCore/Source/Syncbase.swift
+++ b/SyncbaseCore/Source/Syncbase.swift
@@ -31,10 +31,12 @@
withIntermediateDirectories: true,
attributes: [NSFileProtectionKey: NSFileProtectionCompleteUntilFirstUserAuthentication])
}
- v23_syncbase_Init(
- v23_syncbase_Bool(false),
- try rootDir.toCgoString(),
- v23_syncbase_Bool(isUnitTest))
+ let opts = v23_syncbase_InitOpts(
+ clientUnderstandsVOM: false,
+ rootDir: try rootDir.toCgoString(),
+ testLogin: isUnitTest,
+ verboseLevel: 0)
+ v23_syncbase_Init(opts)
if isLoggedIn {
try serve()
}
@@ -87,9 +89,9 @@
/// Must return true before any Syncbase operation can work. Authorize using GoogleCredentials
/// created from a Google OAuth token (you should use the Google Sign In SDK to get this).
public static var isLoggedIn: Bool {
- var ret = v23_syncbase_Bool(false)
+ var ret = false
v23_syncbase_IsLoggedIn(&ret)
- return ret.toBool()
+ return ret
}
/// For debugging the current Syncbase user blessings.
diff --git a/SyncbaseCore/Source/util/Types.swift b/SyncbaseCore/Source/util/Types.swift
index 6336d23..6c7f67c 100644
--- a/SyncbaseCore/Source/util/Types.swift
+++ b/SyncbaseCore/Source/util/Types.swift
@@ -28,22 +28,6 @@
}
}
-public extension v23_syncbase_Bool {
- init(_ bool: Bool) {
- switch bool {
- case true: self = 1
- case false: self = 0
- }
- }
-
- func toBool() -> Bool {
- switch self {
- case 0: return false
- default: return true
- }
- }
-}
-
public extension v23_syncbase_Bytes {
init(_ data: NSData?) {
guard let data = data else {