LiteCore
Couchbase Lite cross-platform core implementation
Loading...
Searching...
No Matches
c4Base.h
Go to the documentation of this file.
1//
2// c4Base.h
3//
4// Copyright 2015-Present Couchbase, Inc.
5//
6// Use of this software is governed by the Business Source License included
7// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
8// in that file, in accordance with the Business Source License, use of this
9// software will be governed by the Apache License, Version 2.0, included in
10// the file licenses/APL2.txt.
11//
12
13#pragma once
14#include "c4Compat.h"
15#include "c4Error.h"
16#include "c4Log.h"
17#include "fleece/FLSlice.h"
18#ifdef __cplusplus
19# include <cstdarg>
20#else
21# include <stdarg.h>
22#endif
23
24#if LITECORE_CPP_API
25# include "c4EnumUtil.hh"
26#endif
27
30
31
32// Corresponds to Couchbase Lite product version number, with 2 digits for minor and patch versions.
33// i.e. `10000 * MajorVersion + 100 * MinorVersion + PatchVersion`
34#define LITECORE_VERSION 30100
35
36// This number has no absolute meaning but is bumped whenever the LiteCore public API changes.
37#define LITECORE_API_VERSION 352
38
39
44#pragma mark - SLICES:
45
46
47// (This is just renaming stuff from FLSlice.h ... feel free to use the FL names instead.)
48
55
56static C4INLINE C4Slice c4str(const char* C4NULLABLE str) { return FLStr(str); }
57
58#define C4STR(STR) FLSTR(STR)
59#define kC4SliceNull kFLSliceNull
60
61static inline bool c4SliceEqual(C4Slice a, C4Slice b) { return FLSlice_Equal(a, b); }
62
64
65#pragma mark - COMMON TYPES:
66
67
68#if LITECORE_CPP_API
69C4API_END_DECLS // GCC doesn't like this stuff inside `extern "C" {}`
70
72 enum class C4SequenceNumber : uint64_t {
73 None = 0,
74 Max = UINT64_MAX
75 };
76
77static inline C4SequenceNumber operator"" _seq(unsigned long long n) { return C4SequenceNumber(n); }
78DEFINE_ENUM_INC_DEC(C4SequenceNumber)
79DEFINE_ENUM_ADD_SUB_INT(C4SequenceNumber)
80
81
82
85enum class C4Timestamp : int64_t { None = 0, Error = -1 };
86DEFINE_ENUM_ADD_SUB_INT(C4Timestamp)
87
89#else
91typedef uint64_t C4SequenceNumber;
92
96typedef int64_t C4Timestamp;
97#endif
98
99
107typedef struct C4ExtraInfo {
109 void (*C4NULLABLE destructor)(void* ptr);
111
112
114typedef struct C4BlobKey C4BlobKey;
115
117typedef struct C4Address C4Address;
118
121
123typedef struct C4Cert C4Cert;
124
127
130
131#ifndef C4_STRICT_COLLECTION_API
133#endif
134
136typedef struct C4Database C4Database;
137
139typedef struct C4Document C4Document;
140
143
146
148typedef struct C4Index C4Index;
149
152
154typedef struct C4KeyPair C4KeyPair;
155
157typedef struct C4Listener C4Listener;
158
160typedef struct C4Query C4Query;
161
164
167
169typedef struct C4RawDocument C4RawDocument;
170
173
176
178typedef struct C4Socket C4Socket;
179
181typedef struct C4SocketFactory C4SocketFactory;
182
185
186
187#pragma mark - REFERENCE COUNTING:
188
189
190// The actual functions behind c4xxx_retain / c4xxx_release; don't call directly
193
194// These types are reference counted and have c4xxx_retain / c4xxx_release functions:
196
200
204
206
210
214
216
220
222
225
228
230
232
234
237
243
244// These types are _not_ ref-counted, but must be freed after use:
270
271
276
281
282
286#pragma mark - INFO:
287
288
296
299
300#define kC4EnvironmentTimezoneKey "tz"
301#define kC4EnvironmentSupportedLocales "supported_locales"
302
312
315
316
327
328
336CBL_CORE_API void c4_runAsyncTask(void (*task)(void*), void* C4NULLABLE context) C4API;
337
338
#define NODISCARD
Definition CompilerSupport.h:59
#define CBL_CORE_API
Definition c4Compat.h:134
#define C4NULLABLE
Definition c4Compat.h:38
#define C4API
Definition c4Compat.h:114
#define C4_ASSUME_NONNULL_BEGIN
Definition c4Compat.h:36
#define C4API_END_DECLS
Definition c4Compat.h:116
#define C4INLINE
Definition c4Compat.h:19
#define C4API_BEGIN_DECLS
Definition c4Compat.h:115
#define C4_ASSUME_NONNULL_END
Definition c4Compat.h:37
CBL_CORE_API void c4listener_free(C4Listener *)
Closes and disposes a listener.
struct C4ReadStream C4ReadStream
An open stream for reading data from a blob.
Definition c4Base.h:172
C4Slice C4String
Definition c4Base.h:52
struct C4Index C4Index
Represents an existing index.
Definition c4Base.h:148
static void c4db_release(C4Database *r)
Definition c4Base.h:227
CBL_CORE_API void c4_dumpInstances(void)
Logs information about object in memory.
CBL_CORE_API void c4raw_free(C4RawDocument *)
Frees the storage occupied by a raw document.
static void c4index_release(C4Index *i)
Definition c4Base.h:229
CBL_CORE_API void c4docobs_free(C4DocumentObserver *)
static bool c4SliceEqual(C4Slice a, C4Slice b)
Definition c4Base.h:61
struct C4BlobStore C4BlobStore
Opaque handle for an object that manages storage of blobs.
Definition c4Base.h:120
static C4IndexUpdater * c4indexupdater_retain(C4IndexUpdater *r)
Definition c4Base.h:207
static C4Cert * c4cert_retain(C4Cert *r)
Definition c4Base.h:195
struct C4WriteStream C4WriteStream
An open stream for writing data to a blob.
Definition c4Base.h:184
static C4Collection * c4coll_retain(C4Collection *r)
Definition c4Base.h:197
C4HeapSlice C4HeapString
Definition c4Base.h:53
int64_t C4Timestamp
A date/time representation used for document expiration (and in date/time queries....
Definition c4Base.h:96
static void c4slice_free(C4SliceResult s)
Definition c4Base.h:63
CBL_CORE_API C4Socket * c4socket_retain(C4Socket *)
struct C4DocEnumerator C4DocEnumerator
Opaque handle to a document enumerator.
Definition c4Base.h:145
static void c4query_release(C4Query *r)
Definition c4Base.h:236
struct C4Listener C4Listener
A LiteCore network listener – supports the REST API, replication, or both.
Definition c4Base.h:157
struct C4Query C4Query
Opaque handle to a compiled query.
Definition c4Base.h:160
uint64_t C4SequenceNumber
A database sequence number, representing the order in which a revision was created.
Definition c4Base.h:91
CBL_CORE_API C4QueryEnumerator * c4queryenum_retain(C4QueryEnumerator *)
struct C4CollectionObserver C4CollectionObserver
A collection-observer reference.
Definition c4Base.h:129
struct C4Replicator C4Replicator
Opaque reference to a replicator.
Definition c4Base.h:175
CBL_CORE_API int c4_getObjectCount(void)
Returns the number of objects that have been created but not yet freed.
CBL_CORE_API void c4dbobs_free(C4CollectionObserver *)
FLSliceResult C4SliceResult
Definition c4Base.h:51
CBL_CORE_API void c4stream_closeWriter(C4WriteStream *)
Closes a blob write-stream.
CBL_CORE_API void c4stream_close(C4ReadStream *)
Closes a read-stream.
struct C4QueryObserver C4QueryObserver
A query-observer reference.
Definition c4Base.h:166
struct C4DocumentObserver C4DocumentObserver
A document-observer reference.
Definition c4Base.h:142
static C4Index * c4index_retain(C4Index *r)
Definition c4Base.h:205
C4SliceResult C4StringResult
Definition c4Base.h:54
static void c4coll_release(C4Collection *r)
Definition c4Base.h:224
CBL_CORE_API void c4queryenum_release(C4QueryEnumerator *)
struct C4IndexUpdater C4IndexUpdater
Describes a set of index values that need to be computed by the application.
Definition c4Base.h:151
static C4KeyPair * c4keypair_retain(C4KeyPair *r)
Definition c4Base.h:211
static void c4keypair_release(C4KeyPair *r)
Definition c4Base.h:233
struct C4KeyPair C4KeyPair
An asymmetric key or key-pair (RSA, etc.) The private key may or may not be present.
Definition c4Base.h:154
CBL_CORE_API void c4queryobs_free(C4QueryObserver *)
static void c4indexupdater_release(C4IndexUpdater *u)
Definition c4Base.h:231
CBL_CORE_API void c4doc_release(C4Document *)
static C4Database * c4db_retain(C4Database *r)
Definition c4Base.h:201
FLSlice C4Slice
Definition c4Base.h:49
CBL_CORE_API void c4enum_free(C4DocEnumerator *)
struct C4Collection C4Collection
Opaque handle to a namespace of documents in an opened database.
Definition c4Base.h:126
C4CollectionObserver C4DatabaseObserver
Definition c4Base.h:132
static C4INLINE C4Slice c4str(const char *str)
Definition c4Base.h:56
struct C4Database C4Database
Opaque handle to an opened database.
Definition c4Base.h:136
static void c4cert_release(C4Cert *r)
Definition c4Base.h:221
struct C4Socket C4Socket
Represents an open bidirectional stream of bytes or messages (typically a TCP socket....
Definition c4Base.h:178
CBL_CORE_API void c4base_release(void *obj)
CBL_CORE_API void c4repl_free(C4Replicator *)
Frees a replicator reference.
FLHeapSlice C4HeapSlice
Definition c4Base.h:50
CBL_CORE_API C4Document * c4doc_retain(C4Document *)
static C4Query * c4query_retain(C4Query *r)
Definition c4Base.h:215
struct C4Cert C4Cert
An X.509 certificate, or certificate signing request (CSR).
Definition c4Base.h:123
CBL_CORE_API void * c4base_retain(void *obj)
CBL_CORE_API void c4socket_release(C4Socket *)
static void FLSliceResult_Release(FLSliceResult s)
Decrements the ref-count of a FLSliceResult, freeing its memory if it reached zero.
Definition FLSlice.h:183
FLEECE_PUBLIC bool FLSlice_Equal(FLSlice a, FLSlice b) FLPURE
Equality test of two slices.
static FLSlice FLStr(const char *FL_NULLABLE str)
Returns a slice pointing to the contents of a C string.
Definition FLSlice.h:126
CBL_CORE_API C4Timestamp c4_now(void)
Returns the current time, in milliseconds since 1/1/1970.
CBL_CORE_API C4StringResult c4_getVersion(void)
A short version string.
C4SliceResult c4_getEnvironmentInfo(void)
Returns information about LiteCore's view of the environment in the following format:
NODISCARD CBL_CORE_API bool c4_setTempDir(C4String path, C4Error *err)
Wiring call for platforms without discoverable temporary directories.
CBL_CORE_API C4StringResult c4_getBuildInfo(void)
A string describing the version of LiteCore.
CBL_CORE_API void c4_runAsyncTask(void(*task)(void *), void *context)
Schedules a function to be called asynchronously on a background thread.
A simple parsed-URL type.
Definition c4ReplicatorTypes.h:56
A unique identifier of a blob based on a SHA-1 digest of its contents.
Definition c4BlobStoreTypes.h:33
Describes a version-controlled document.
Definition c4DocumentStruct.h:32
An error value.
Definition c4Error.h:133
Client-defined metadata that can be associated with some objects like C4Database.
Definition c4Base.h:107
void * pointer
Definition c4Base.h:108
void(* destructor)(void *ptr)
Client-specific pointer; can be anything.
Definition c4Base.h:109
A query result enumerator.
Definition c4QueryTypes.h:54
Contents of a raw document.
Definition c4DatabaseTypes.h:149
A group of callbacks that define the implementation of sockets; the client must fill this out and pas...
Definition c4SocketTypes.h:59
A simple reference to a block of memory.
Definition FLSlice.h:45
A heap-allocated block of memory returned from an API call.
Definition FLSlice.h:63