Skip to content

Commit 1fc0ce9

Browse files
committed
Merge branch '3.1.x' into test_parameters_3.1.7
2 parents dc530d8 + b81a19f commit 1fc0ce9

File tree

148 files changed

+15594
-5293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+15594
-5293
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "couchbase_lite"
3-
version = "3.0.17-0"
3+
version = "3.1.7-0"
44
# The first three numbers correspond to the Couchbase Lite C release, the fourth number corresponds to the Doctolib release
55

66
[dependencies]

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ADD libcblite libcblite
2020
RUN strip /build/libcblite/lib/x86_64-linux-android/libcblite.so -o /build/libcblite/lib/x86_64-linux-android/libcblite.stripped.so
2121
RUN strip /build/libcblite/lib/i686-linux-android/libcblite.so -o /build/libcblite/lib/i686-linux-android/libcblite.stripped.so
2222
RUN /usr/aarch64-linux-gnu/bin/strip /build/libcblite/lib/aarch64-linux-android/libcblite.so -o /build/libcblite/lib/aarch64-linux-android/libcblite.stripped.so
23-
RUN /usr/aarch64-linux-gnu/bin/strip /build/libcblite/lib/armv7-linux-androideabi/libcblite.so -o /build/libcblite/lib/armv7-linux-androideabi/libcblite.stripped.so
23+
RUN /usr/aarch64-linux-gnu/bin/strip /build/libcblite/lib/arm-linux-androideabi/libcblite.so -o /build/libcblite/lib/arm-linux-androideabi/libcblite.stripped.so
2424
RUN strip /build/libcblite/lib/x86_64-pc-windows-gnu/cblite.dll -o /build/libcblite/lib/x86_64-pc-windows-gnu/cblite.stripped.dll
2525

2626
FROM scratch AS strip

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Install strip:
4141
Strip:
4242
``$ cd /build/libcblite-3.0.3/lib/aarch64-linux-android
4343
$ strip libcblite.so -o libcblite.stripped.so
44-
$ cd /build/libcblite-3.0.3/lib/armv7-linux-androideabi
44+
$ cd /build/libcblite-3.0.3/lib/arm-linux-androideabi
4545
$ strip libcblite.so -o libcblite.stripped.so``
4646

4747

libcblite-3.0.3/.DS_Store

0 Bytes
Binary file not shown.

libcblite-3.0.3/include/.DS_Store

0 Bytes
Binary file not shown.

libcblite-3.0.3/include/cbl++/Base.hh

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
//
2+
// Base.hh
3+
//
4+
// Copyright (c) 2019 Couchbase, Inc All rights reserved.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
19+
#pragma once
20+
#include "cbl/CBLBase.h"
21+
#include "fleece/slice.hh"
22+
#include <algorithm>
23+
#include <functional>
24+
#include <cassert>
25+
#include <memory>
26+
#include <utility>
27+
28+
#if DEBUG
29+
# include "cbl/CBLLog.h"
30+
#endif
31+
32+
// VOLATILE API: Couchbase Lite C++ API is not finalized, and may change in
33+
// future releases.
34+
35+
CBL_ASSUME_NONNULL_BEGIN
36+
37+
static inline bool operator== (const CBLError &e1, const CBLError &e2) {
38+
if (e1.code != 0)
39+
return e1.domain == e2.domain && e1.code == e2.code;
40+
else
41+
return e2.code == 0;
42+
}
43+
44+
namespace cbl {
45+
46+
using slice = fleece::slice;
47+
using alloc_slice = fleece::alloc_slice;
48+
49+
// Artificial base class of the C++ wrapper classes; just manages ref-counting.
50+
class RefCounted {
51+
protected:
52+
RefCounted() noexcept :_ref(nullptr) { }
53+
explicit RefCounted(CBLRefCounted* _cbl_nullable ref) noexcept :_ref(CBL_Retain(ref)) { }
54+
RefCounted(const RefCounted &other) noexcept :_ref(CBL_Retain(other._ref)) { }
55+
RefCounted(RefCounted &&other) noexcept :_ref(other._ref) {other._ref = nullptr;}
56+
~RefCounted() noexcept {CBL_Release(_ref);}
57+
58+
RefCounted& operator= (const RefCounted &other) noexcept {
59+
CBL_Retain(other._ref);
60+
CBL_Release(_ref);
61+
_ref = other._ref;
62+
return *this;
63+
}
64+
65+
RefCounted& operator= (RefCounted &&other) noexcept {
66+
if (other._ref != _ref) {
67+
CBL_Release(_ref);
68+
_ref = other._ref;
69+
other._ref = nullptr;
70+
}
71+
return *this;
72+
}
73+
74+
void clear() {CBL_Release(_ref); _ref = nullptr;}
75+
bool valid() const {return _ref != nullptr;} \
76+
explicit operator bool() const {return valid();} \
77+
78+
static std::string asString(FLSlice s) {return slice(s).asString();}
79+
static std::string asString(FLSliceResult &&s) {return alloc_slice(s).asString();}
80+
81+
static void check(bool ok, CBLError &error) {
82+
if (!ok) {
83+
#if DEBUG
84+
alloc_slice message = CBLError_Message(&error);
85+
CBL_Log(kCBLLogDomainDatabase, kCBLLogError, "API returning error %d/%d: %.*s",
86+
error.domain, error.code, (int)message.size, (char*)message.buf);
87+
#endif
88+
throw error;
89+
}
90+
}
91+
92+
CBLRefCounted* _cbl_nullable _ref;
93+
94+
friend class Transaction;
95+
};
96+
97+
// Internal use only: Copy/move ctors and assignment ops that have to be declared in subclasses
98+
#define CBL_REFCOUNTED_WITHOUT_COPY_MOVE_BOILERPLATE(CLASS, SUPER, C_TYPE) \
99+
public: \
100+
CLASS() noexcept :SUPER() { } \
101+
CLASS& operator=(std::nullptr_t) {clear(); return *this;} \
102+
bool valid() const {return RefCounted::valid();} \
103+
explicit operator bool() const {return valid();} \
104+
bool operator==(const CLASS &other) const {return _ref == other._ref;} \
105+
bool operator!=(const CLASS &other) const {return _ref != other._ref;} \
106+
C_TYPE* _cbl_nullable ref() const {return (C_TYPE*)_ref;}\
107+
protected: \
108+
explicit CLASS(C_TYPE* _cbl_nullable ref) :SUPER((CBLRefCounted*)ref) { }
109+
110+
#define CBL_REFCOUNTED_BOILERPLATE(CLASS, SUPER, C_TYPE) \
111+
CBL_REFCOUNTED_WITHOUT_COPY_MOVE_BOILERPLATE(CLASS, SUPER, C_TYPE) \
112+
public: \
113+
CLASS(const CLASS &other) noexcept :SUPER(other) { } \
114+
CLASS(CLASS &&other) noexcept :SUPER((SUPER&&)other) { } \
115+
CLASS& operator=(const CLASS &other) noexcept {SUPER::operator=(other); return *this;} \
116+
CLASS& operator=(CLASS &&other) noexcept {SUPER::operator=((SUPER&&)other); return *this;}
117+
118+
/** A token representing a registered listener; instances are returned from the various
119+
methods that register listeners, such as \ref Database::addListener.
120+
When this object goes out of scope, the listener will be unregistered.
121+
@note ListenerToken is now allowed to copy. */
122+
template <class... Args>
123+
class ListenerToken {
124+
public:
125+
using Callback = std::function<void(Args...)>;
126+
127+
ListenerToken() =default;
128+
~ListenerToken() {CBLListener_Remove(_token);}
129+
130+
ListenerToken(Callback cb)
131+
:_callback(new Callback(cb))
132+
{ }
133+
134+
ListenerToken(ListenerToken &&other)
135+
:_token(other._token),
136+
_callback(std::move(other._callback))
137+
{other._token = nullptr;}
138+
139+
ListenerToken& operator=(ListenerToken &&other) {
140+
CBLListener_Remove(_token);
141+
_token = other._token;
142+
other._token = nullptr;
143+
_callback = std::move(other._callback);
144+
return *this;
145+
}
146+
147+
/** Unregisters the listener early, before it leaves scope. */
148+
void remove() {
149+
CBLListener_Remove(_token);
150+
_token = nullptr;
151+
_callback = nullptr;
152+
}
153+
154+
void* _cbl_nullable context() const {return _callback.get();}
155+
CBLListenerToken* _cbl_nullable token() const {return _token;}
156+
void setToken(CBLListenerToken* token) {assert(!_token); _token = token;}
157+
158+
static void call(void* _cbl_nullable context, Args... args) {
159+
auto listener = (Callback*)context;
160+
(*listener)(args...);
161+
}
162+
163+
private:
164+
CBLListenerToken* _cbl_nullable _token {nullptr};
165+
std::shared_ptr<Callback> _callback; // Use shared_ptr instead of unique_ptr to allow to move
166+
167+
ListenerToken(const ListenerToken&) =delete;
168+
ListenerToken& operator=(const ListenerToken &other) =delete;
169+
};
170+
}
171+
172+
CBL_ASSUME_NONNULL_END

libcblite-3.0.3/include/cbl++/Blob.hh

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
//
2+
// Blob.hh
3+
//
4+
// Copyright (c) 2019 Couchbase, Inc All rights reserved.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
19+
#pragma once
20+
#include "cbl++/Document.hh"
21+
#include "cbl/CBLBlob.h"
22+
#include "fleece/Mutable.hh"
23+
#include <string>
24+
25+
// VOLATILE API: Couchbase Lite C++ API is not finalized, and may change in
26+
// future releases.
27+
28+
CBL_ASSUME_NONNULL_BEGIN
29+
30+
namespace cbl {
31+
class BlobReadStream;
32+
class BlobWriteStream;
33+
34+
/** A reference to a binary data blob associated with a document.
35+
A blob's persistent form is a special dictionary in the document properties.
36+
To work with a blob, you construct a Blob object with that dictionary. */
37+
class Blob : protected RefCounted {
38+
public:
39+
/** Returns true if a dictionary in a document is a blob reference.
40+
@note This method tests whether the dictionary has a `@type` property,
41+
whose value is `"blob"`. */
42+
static bool isBlob(fleece::Dict d) {return FLDict_IsBlob(d);}
43+
44+
/** Creates a new blob, given its contents as a single block of data.
45+
@note The memory pointed to by `contents` is no longer needed after this call completes
46+
(it will have been written to the database.)
47+
@param contentType The MIME type (optional).
48+
@param contents The data's address and length. */
49+
Blob(slice contentType, slice contents) {
50+
_ref = (CBLRefCounted*) CBLBlob_CreateWithData(contentType, contents);
51+
}
52+
53+
/** Creates a new blob from the data written to a \ref CBLBlobWriteStream.
54+
@param contentType The MIME type (optional).
55+
@param writer The blob-writing stream the data was written to. */
56+
inline Blob(slice contentType, BlobWriteStream& writer);
57+
58+
/** Creates a Blob instance on an existing blob reference in a document or query result.
59+
@note If the dict argument is not actually a blob reference, this Blob object will be
60+
invalid; you can check that by calling its `valid` method or testing it with its
61+
`operator bool`. */
62+
Blob(fleece::Dict d)
63+
:RefCounted((CBLRefCounted*) FLDict_GetBlob(d))
64+
{ }
65+
66+
/** Returns the length in bytes of a blob's content (from its `length` property). */
67+
uint64_t length() const {return CBLBlob_Length(ref());}
68+
69+
/** Returns a blob's MIME type, if its metadata has a `content_type` property. */
70+
std::string contentType() const {return asString(CBLBlob_ContentType(ref()));}
71+
72+
/** Returns the cryptographic digest of a blob's content (from its `digest` property). */
73+
std::string digest() const {return asString(CBLBlob_Digest(ref()));}
74+
75+
/** Returns a blob's metadata. This includes the `digest`, `length`, `content_type`,
76+
and `@type` properties, as well as any custom ones that may have been added. */
77+
fleece::Dict properties() const {return CBLBlob_Properties(ref());}
78+
79+
// Allows Blob to be assigned to mutable Dict/Array item, e.g. `dict["foo"] = blob`
80+
operator fleece::Dict() const {return properties();}
81+
82+
/** Reads the blob's content into memory and returns them. */
83+
alloc_slice loadContent() {
84+
CBLError error;
85+
fleece::alloc_slice content = CBLBlob_Content(ref(), &error);
86+
check(content.buf, error);
87+
return content;
88+
}
89+
90+
/** Opens a stream for reading a blob's content. */
91+
inline BlobReadStream* openContentStream();
92+
93+
protected:
94+
Blob(CBLRefCounted* r) :RefCounted(r) { }
95+
96+
CBL_REFCOUNTED_BOILERPLATE(Blob, RefCounted, CBLBlob)
97+
};
98+
99+
/** A stream for writing a new blob to the database. */
100+
class BlobReadStream {
101+
public:
102+
/** Opens a stream for reading a blob's content. */
103+
BlobReadStream(Blob *blob) {
104+
CBLError error;
105+
_stream = CBLBlob_OpenContentStream(blob->ref(), &error);
106+
if (!_stream) throw error;
107+
}
108+
109+
~BlobReadStream() {
110+
CBLBlobReader_Close(_stream);
111+
}
112+
113+
/** Reads data from a blob.
114+
@param dst The address to copy the read data to.
115+
@param maxLength The maximum number of bytes to read.
116+
@return The actual number of bytes read; 0 if at EOF. */
117+
size_t read(void *dst, size_t maxLength) {
118+
CBLError error;
119+
int bytesRead = CBLBlobReader_Read(_stream, dst, maxLength, &error);
120+
if (bytesRead < 0)
121+
throw error;
122+
return size_t(bytesRead);
123+
}
124+
125+
private:
126+
CBLBlobReadStream* _cbl_nullable _stream {nullptr};
127+
};
128+
129+
BlobReadStream* Blob::openContentStream() {
130+
return new BlobReadStream(this);
131+
}
132+
133+
/** A stream for writing a new blob to the database. */
134+
class BlobWriteStream {
135+
public:
136+
/** Create a stream to write a new blob to the database. */
137+
BlobWriteStream(Database db) {
138+
CBLError error;
139+
_writer = CBLBlobWriter_Create(db.ref(), &error);
140+
if (!_writer) throw error;
141+
}
142+
143+
~BlobWriteStream() {
144+
CBLBlobWriter_Close(_writer);
145+
}
146+
147+
/** Writes data to a new blob.
148+
@param data The data to write. */
149+
void write(fleece::slice data) {
150+
write(data.buf, data.size);
151+
}
152+
153+
/** Writes data to a new blob.
154+
@param src The address of the data to write.
155+
@param length The length of the data to write. */
156+
void write(const void *src, size_t length) {
157+
CBLError error;
158+
if (!CBLBlobWriter_Write(_writer, src, length, &error))
159+
throw error;
160+
}
161+
162+
private:
163+
friend class Blob;
164+
CBLBlobWriteStream* _cbl_nullable _writer {nullptr};
165+
};
166+
167+
inline Blob::Blob(slice contentType, BlobWriteStream& writer) {
168+
_ref = (CBLRefCounted*) CBLBlob_CreateWithStream(contentType, writer._writer);
169+
writer._writer = nullptr;
170+
}
171+
}
172+
173+
CBL_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)