Skip to content

Commit

Permalink
feat: upgrade to CBL C SDK 3.1.0 (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed May 2, 2023
1 parent af7f66d commit 9031f58
Show file tree
Hide file tree
Showing 29 changed files with 100 additions and 140 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/libcblitedart-release.yaml
Expand Up @@ -40,13 +40,13 @@ jobs:
uses: lukka/get-cmake@latest

- name: Download Couchbase Lite
run: ./native/tools/download_prebuilt_binaries.sh ubuntu20.04-x86_64
run: ./native/tools/download_prebuilt_binaries.sh linux-x86_64

- name: Build release
run: |
./native/couchbase-lite-dart/tools/build_release.sh \
${{ needs.create-release.outputs.release }} \
ubuntu20.04-x86_64
linux-x86_64
- name: Upload archives
uses: alexellis/upload-assets@0.2.2
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -62,7 +62,7 @@ Two native libraries are required to enable Couchbase Lite for Dart.

**Dependencies**:

- Android SDK with NDK `21.4.7075529` and CMake `3.18.1`
- Android SDK with NDK `23.1.7779620` and CMake `3.18.1`

### iOS + macOS

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/supported-platforms.mdx
Expand Up @@ -12,7 +12,7 @@ description:
| iOS | >= 10.0 |
| macOS | >= 10.14 |
| Android | >= 22 |
| Linux | == Ubuntu 20.04 x86_64 |
| Linux | >= Ubuntu 20.04 x86_64 |
| Windows | >= 10 x86_64 |

### Default database directory
Expand All @@ -27,7 +27,7 @@ locations on the various platforms.
| Platform | Version |
| -------: | :--------------------- |
| macOS | >= 10.14 |
| Linux | == Ubuntu 20.04 x86_64 |
| Linux | >= Ubuntu 20.04 x86_64 |
| Windows | >= 10 x86_64 |

### Default database directory
Expand Down
2 changes: 1 addition & 1 deletion native/CouchbaseLiteC.release
@@ -1 +1 @@
3.0.11
3.1.0
2 changes: 1 addition & 1 deletion native/couchbase-lite-dart/CMakeLists.txt
Expand Up @@ -27,7 +27,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL Android)
set(CBL_TARGET android)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
# The only currently supported Linux target.
set(CBL_TARGET ubuntu20.04-x86_64)
set(CBL_TARGET linux-x86_64)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
set(CBL_TARGET windows-x86_64)
endif()
Expand Down
4 changes: 0 additions & 4 deletions native/couchbase-lite-dart/include/Fleece+Dart.h
Expand Up @@ -52,10 +52,6 @@ struct CBLDart_LoadedFLValue {
FLValue value;
};

CBLDART_EXPORT
void CBLDart_FLValue_FromData(FLSlice data, uint8_t trust,
CBLDart_LoadedFLValue *out);

CBLDART_EXPORT
void CBLDart_GetLoadedFLValue(FLValue value, CBLDart_LoadedFLValue *out);

Expand Down
6 changes: 3 additions & 3 deletions native/couchbase-lite-dart/src/AsyncCallback.cpp
Expand Up @@ -177,7 +177,7 @@ void AsyncCallbackCall::execute(Dart_CObject &arguments) {

// The SendPort to signal the return of the callback.
// Only necessary if the caller is interested in it.
Dart_CObject responsePort;
Dart_CObject responsePort{};
if (isBlocking()) {
responsePort.type = Dart_CObject_kSendPort;
responsePort.value.as_send_port.id = receivePort_;
Expand All @@ -190,13 +190,13 @@ void AsyncCallbackCall::execute(Dart_CObject &arguments) {
// response. This is how we get a reference to this call in the response
// handler. Only necessary if the caller is waiting for the return of the
// callback.
Dart_CObject callPointer;
Dart_CObject callPointer{};
CBLDart_CObject_SetPointer(&callPointer, isBlocking() ? this : nullptr);

// The request is sent as an array.
Dart_CObject *requestValues[] = {&responsePort, &callPointer, &arguments};

Dart_CObject request;
Dart_CObject request{};
request.type = Dart_CObject_kArray;
request.value.as_array.length = 3;
request.value.as_array.values = requestValues;
Expand Down
85 changes: 40 additions & 45 deletions native/couchbase-lite-dart/src/CBL+Dart.cpp
Expand Up @@ -65,13 +65,13 @@ void CBLDart_AsyncCallback_Close(CBLDart_AsyncCallback callback) {
void CBLDart_AsyncCallback_CallForTest(CBLDart_AsyncCallback callback,
int64_t argument) {
std::thread([=]() {
Dart_CObject argument__;
Dart_CObject argument__{};
argument__.type = Dart_CObject_kInt64;
argument__.value.as_int64 = argument;

Dart_CObject *argsValues[] = {&argument__};

Dart_CObject args;
Dart_CObject args{};
args.type = Dart_CObject_kArray;
args.value.as_array.length = 1;
args.value.as_array.values = argsValues;
Expand Down Expand Up @@ -219,20 +219,20 @@ static void CBLDart_UpdateEffectiveLogCallbackLevel() {

static void CBLDart_CallDartLogCallback(CBLLogDomain domain, CBLLogLevel level,
FLString message) {
Dart_CObject domain_;
Dart_CObject domain_{};
domain_.type = Dart_CObject_kInt32;
domain_.value.as_int32 = static_cast<int32_t>(domain);

Dart_CObject level_;
Dart_CObject level_{};
level_.type = Dart_CObject_kInt32;
level_.value.as_int32 = static_cast<int32_t>(level);

Dart_CObject message_;
Dart_CObject message_{};
CBLDart_CObject_SetFLString(&message_, message);

Dart_CObject *argsValues[] = {&domain_, &level_, &message_};

Dart_CObject args;
Dart_CObject args{};
args.type = Dart_CObject_kArray;
args.value.as_array.length = 3;
args.value.as_array.values = argsValues;
Expand Down Expand Up @@ -279,7 +279,7 @@ bool CBLDart_CBLLog_SetFileConfig(CBLLogFileConfiguration *config,
std::unique_lock lock(loggingMutex);

if (!config) {
CBLLogFileConfiguration config_;
CBLLogFileConfiguration config_{};
config_.level = kCBLLogNone;
config_.directory = {nullptr, 0};
config_.maxRotateCount = 0;
Expand All @@ -295,7 +295,7 @@ bool CBLDart_CBLLog_SetFileConfig(CBLLogFileConfiguration *config,
}
return success;
} else {
CBLLogFileConfiguration config_;
CBLLogFileConfiguration config_{};
config_.level = config->level;
config_.directory = config->directory;
config_.maxRotateCount = config->maxRotateCount;
Expand All @@ -306,12 +306,12 @@ bool CBLDart_CBLLog_SetFileConfig(CBLLogFileConfiguration *config,
if (success) {
auto config_ = CBLLog_FileConfig();
if (!logFileConfig) {
logFileConfig = new CBLLogFileConfiguration;
logFileConfig = new CBLLogFileConfiguration{};
}
logFileConfig->level = config_->level;
logFileConfig->directory = config_->directory;
logFileConfig->maxRotateCount = config_->maxRotateCount;
logFileConfig->maxSize = config->maxSize;
logFileConfig->maxSize = config_->maxSize;
logFileConfig->usePlaintext = config_->usePlaintext;
}
return success;
Expand Down Expand Up @@ -483,7 +483,7 @@ static void CBLDart_DocumentChangeListenerWrapper(void *context,
FLString docID) {
auto callback = ASYNC_CALLBACK_FROM_C(context);

Dart_CObject args;
Dart_CObject args{};
CBLDart_CObject_SetEmptyArray(&args);

CBLDart::AsyncCallbackCall(*callback).execute(args);
Expand Down Expand Up @@ -515,7 +515,7 @@ static void CBLDart_DatabaseChangeListenerWrapper(void *context,

auto docIdObjectsArray = docIdObjects.data();

Dart_CObject args;
Dart_CObject args{};
args.type = Dart_CObject_kArray;
args.value.as_array.length = numDocs;
args.value.as_array.values = &docIdObjectsArray;
Expand All @@ -539,15 +539,15 @@ bool CBLDart_CBLDatabase_CreateIndex(CBLDatabase *db, FLString name,
CBLError *errorOut) {
switch (indexSpec.type) {
case kCBLDart_IndexTypeValue: {
CBLValueIndexConfiguration config;
CBLValueIndexConfiguration config{};
config.expressionLanguage = indexSpec.expressionLanguage;
config.expressions = indexSpec.expressions;

return CBLDatabase_CreateValueIndex(db, name, config, errorOut);
}
case kCBLDart_IndexTypeFullText: {
}
CBLFullTextIndexConfiguration config;
CBLFullTextIndexConfiguration config{};
config.expressionLanguage = indexSpec.expressionLanguage;
config.expressions = indexSpec.expressions;
config.ignoreAccents = static_cast<bool>(indexSpec.ignoreAccents);
Expand All @@ -566,7 +566,7 @@ static void CBLDart_QueryChangeListenerWrapper(void *context, CBLQuery *query,
CBLListenerToken *token) {
auto callback = ASYNC_CALLBACK_FROM_C(context);

Dart_CObject args;
Dart_CObject args{};
CBLDart_CObject_SetEmptyArray(&args);

CBLDart::AsyncCallbackCall(*callback).execute(args);
Expand Down Expand Up @@ -622,16 +622,16 @@ static std::mutex replicatorCallbackWrapperContextsMutex;
static bool CBLDart_ReplicatorFilterWrapper(CBLDart::AsyncCallback *callback,
CBLDocument *document,
CBLDocumentFlags flags) {
Dart_CObject document_;
Dart_CObject document_{};
CBLDart_CObject_SetPointer(&document_, document);

Dart_CObject flags_;
Dart_CObject flags_{};
flags_.type = Dart_CObject_kInt32;
flags_.value.as_int32 = flags;

Dart_CObject *argsValues[] = {&document_, &flags_};

Dart_CObject args;
Dart_CObject args{};
args.type = Dart_CObject_kArray;
args.value.as_array.length = 2;
args.value.as_array.values = argsValues;
Expand Down Expand Up @@ -672,18 +672,18 @@ static const CBLDocument *CBLDart_ReplicatorConflictResolverWrapper(
reinterpret_cast<ReplicatorCallbackWrapperContext *>(context);
auto callback = wrapperContext->conflictResolver;

Dart_CObject documentID_;
Dart_CObject documentID_{};
CBLDart_CObject_SetFLString(&documentID_, documentID);

Dart_CObject local;
Dart_CObject local{};
CBLDart_CObject_SetPointer(&local, localDocument);

Dart_CObject remote;
Dart_CObject remote{};
CBLDart_CObject_SetPointer(&remote, remoteDocument);

Dart_CObject *argsValues[] = {&documentID_, &local, &remote};

Dart_CObject args;
Dart_CObject args{};
args.type = Dart_CObject_kArray;
args.value.as_array.length = 3;
args.value.as_array.values = argsValues;
Expand Down Expand Up @@ -730,7 +730,7 @@ static const CBLDocument *CBLDart_ReplicatorConflictResolverWrapper(

CBLReplicator *CBLDart_CBLReplicator_Create(
CBLDart_ReplicatorConfiguration *config, CBLError *errorOut) {
CBLReplicatorConfiguration config_;
CBLReplicatorConfiguration config_{};
config_.database = config->database;
config_.endpoint = config->endpoint;
config_.replicatorType =
Expand Down Expand Up @@ -767,11 +767,6 @@ CBLReplicator *CBLDart_CBLReplicator_Create(
context->conflictResolver = ASYNC_CALLBACK_FROM_C(config->conflictResolver);
config_.context = context;

#ifdef COUCHBASE_ENTERPRISE
config_.propertyEncryptor = nullptr;
config_.propertyDecryptor = nullptr;
#endif

auto replicator = CBLReplicator_Create(&config_, errorOut);

if (replicator) {
Expand Down Expand Up @@ -873,14 +868,14 @@ class ReplicatorStatus_CObject_Helper {
Dart_CObject *cObject() { return &object; }

private:
Dart_CObject object;
Dart_CObject object{};
Dart_CObject *objectValues[6];
Dart_CObject activity;
Dart_CObject progressComplete;
Dart_CObject progressDocumentCount;
Dart_CObject errorDomain;
Dart_CObject errorCode;
Dart_CObject errorMessage;
Dart_CObject activity{};
Dart_CObject progressComplete{};
Dart_CObject progressDocumentCount{};
Dart_CObject errorDomain{};
Dart_CObject errorCode{};
Dart_CObject errorMessage{};

FLSliceResult errorMessageStr = {nullptr, 0};
};
Expand All @@ -895,7 +890,7 @@ static void CBLDart_Replicator_ChangeListenerWrapper(

Dart_CObject *argsValues[] = {cObjectStatus.cObject()};

Dart_CObject args;
Dart_CObject args{};
args.type = Dart_CObject_kArray;
args.value.as_array.length = 1;
args.value.as_array.values = argsValues;
Expand Down Expand Up @@ -960,13 +955,13 @@ class ReplicatedDocument_CObject_Helper {
Dart_CObject *cObject() { return &object; }

private:
Dart_CObject object;
Dart_CObject object{};
Dart_CObject *objectValues[5];
Dart_CObject id;
Dart_CObject flags;
Dart_CObject errorDomain;
Dart_CObject errorCode;
Dart_CObject errorMessage;
Dart_CObject id{};
Dart_CObject flags{};
Dart_CObject errorDomain{};
Dart_CObject errorCode{};
Dart_CObject errorMessage{};

FLSliceResult errorMessageStr = {nullptr, 0};
};
Expand All @@ -976,7 +971,7 @@ static void CBLDart_Replicator_DocumentReplicationListenerWrapper(
unsigned numDocuments, const CBLReplicatedDocument *documents) {
auto callback = ASYNC_CALLBACK_FROM_C(context);

Dart_CObject isPush_;
Dart_CObject isPush_{};
isPush_.type = Dart_CObject_kBool;
isPush_.value.as_bool = isPush;

Expand All @@ -990,14 +985,14 @@ static void CBLDart_Replicator_DocumentReplicationListenerWrapper(
documentObjects[i] = helper->cObject();
}

Dart_CObject cObjectDocumentsArray;
Dart_CObject cObjectDocumentsArray{};
cObjectDocumentsArray.type = Dart_CObject_kArray;
cObjectDocumentsArray.value.as_array.length = numDocuments;
cObjectDocumentsArray.value.as_array.values = documentObjects.data();

Dart_CObject *argsValues[] = {&isPush_, &cObjectDocumentsArray};

Dart_CObject args;
Dart_CObject args{};
args.type = Dart_CObject_kArray;
args.value.as_array.length = 2;
args.value.as_array.values = argsValues;
Expand Down
10 changes: 2 additions & 8 deletions native/couchbase-lite-dart/src/Fleece+Dart.cpp
Expand Up @@ -71,12 +71,6 @@ static void CBLDart_GetLoadedDictKey(KnownSharedKeys *knownSharedKeys,
out->stringSize = string.size;
}

void CBLDart_FLValue_FromData(FLSlice data, uint8_t trust,
CBLDart_LoadedFLValue *out) {
auto value = FLValue_FromData(data, static_cast<FLTrust>(trust));
CBLDart_GetLoadedFLValue(value, out);
}

void CBLDart_GetLoadedFLValue(FLValue value, CBLDart_LoadedFLValue *out) {
if (value) {
out->exists = true;
Expand Down Expand Up @@ -154,7 +148,7 @@ CBLDart_FLDictIterator *CBLDart_FLDictIterator_Begin(
FLDict dict, KnownSharedKeys *knownSharedKeys,
CBLDart_LoadedDictKey *keyOut, CBLDart_LoadedFLValue *valueOut,
bool deleteOnDone, bool preLoad) {
auto iterator = new CBLDart_FLDictIterator;
auto iterator = new CBLDart_FLDictIterator{};
iterator->_keyOut = keyOut;
iterator->_valueOut = valueOut;
iterator->_knownSharedKeys = knownSharedKeys;
Expand Down Expand Up @@ -211,7 +205,7 @@ struct CBLDart_FLArrayIterator {

CBLDart_FLArrayIterator *CBLDart_FLArrayIterator_Begin(
FLArray array, CBLDart_LoadedFLValue *valueOut, bool deleteOnDone) {
auto iterator = new CBLDart_FLArrayIterator;
auto iterator = new CBLDart_FLArrayIterator{};
iterator->_valueOut = valueOut;
iterator->_deleteOnDone = deleteOnDone;

Expand Down
Expand Up @@ -32,7 +32,6 @@ CBLDart_FLSliceResult_ReleaseByBuf

CBLDart_KnownSharedKeys_New
CBLDart_KnownSharedKeys_Delete
CBLDart_FLValue_FromData
CBLDart_GetLoadedFLValue
CBLDart_FLArray_GetLoadedFLValue
CBLDart_FLDict_GetLoadedFLValue
Expand Down
Expand Up @@ -28,7 +28,6 @@ CBLDart_FLSliceResult_RetainByBuf
CBLDart_FLSliceResult_ReleaseByBuf
CBLDart_KnownSharedKeys_New
CBLDart_KnownSharedKeys_Delete
CBLDart_FLValue_FromData
CBLDart_GetLoadedFLValue
CBLDart_FLArray_GetLoadedFLValue
CBLDart_FLDict_GetLoadedFLValue
Expand Down

0 comments on commit 9031f58

Please sign in to comment.