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 "fleece/FLSlice.h"
17#ifdef __cplusplus
18# include <cstdarg>
19#else
20# include <stdarg.h>
21#endif
22
23#if LITECORE_CPP_API
24# include "c4EnumUtil.hh"
25#endif
26
29
30
31// Corresponds to Couchbase Lite product version number, with 2 digits for minor and patch versions.
32// i.e. `10000 * MajorVersion + 100 * MinorVersion + PatchVersion`
33#define LITECORE_VERSION 30100
34
35// This number has no absolute meaning but is bumped whenever the LiteCore public API changes.
36#define LITECORE_API_VERSION 352
37
38
41
42
43#pragma mark - SLICES:
44
45
46// (This is just renaming stuff from FLSlice.h ... feel free to use the FL names instead.)
47
54
55static C4INLINE C4Slice c4str(const char* C4NULLABLE str) { return FLStr(str); }
56
57#define C4STR(STR) FLSTR(STR)
58#define kC4SliceNull kFLSliceNull
59
60inline bool c4SliceEqual(C4Slice a, C4Slice b) { return FLSlice_Equal(a, b); }
61
63
64#pragma mark - COMMON TYPES:
65
66
67#if LITECORE_CPP_API
68C4API_END_DECLS // GCC doesn't like this stuff inside `extern "C" {}`
69
71 enum class C4SequenceNumber : uint64_t {
72 None = 0,
73 Max = UINT64_MAX
74 };
75
76inline C4SequenceNumber operator""_seq(unsigned long long n) { return C4SequenceNumber(n); }
77DEFINE_ENUM_INC_DEC(C4SequenceNumber)
78DEFINE_ENUM_ADD_SUB_INT(C4SequenceNumber)
79
80
81
84enum class C4Timestamp : int64_t { None = 0, Error = -1 };
85DEFINE_ENUM_ADD_SUB_INT(C4Timestamp)
86
88#else
90typedef uint64_t C4SequenceNumber;
91
95typedef int64_t C4Timestamp;
96#endif
97
98
106typedef struct C4ExtraInfo {
108 void (*C4NULLABLE destructor)(void* ptr);
110
111
113typedef struct C4BlobKey C4BlobKey;
114
116typedef struct C4Address C4Address;
117
120
122typedef struct C4Cert C4Cert;
123
126
129
130#ifndef C4_STRICT_COLLECTION_API
132#endif
133
135typedef struct C4Database C4Database;
136
138typedef struct C4Document C4Document;
139
142
145
147typedef struct C4Index C4Index;
148
151
153typedef struct C4KeyPair C4KeyPair;
154
156typedef struct C4Listener C4Listener;
157
160
162typedef struct C4PeerSync C4PeerSync;
163
165typedef struct C4Query C4Query;
166
169
172
174typedef struct C4RawDocument C4RawDocument;
175
178
181
183typedef struct C4Socket C4Socket;
184
186typedef struct C4SocketFactory C4SocketFactory;
187
190
191
192#pragma mark - REFERENCE COUNTING:
193
194
195// The actual functions behind c4xxx_retain / c4xxx_release; don't call directly
198
199// These types are reference counted and have c4xxx_retain / c4xxx_release functions:
201
205
207
209
213
215
219
221
225
227
230
233
235
237
239
242
245
251
252// These types are _not_ ref-counted, but must be freed after use:
280
281
286
291
292
294
295
296#pragma mark - INFO:
297
298
301
302
306
309
310#define kC4EnvironmentTimezoneKey "tz"
311#define kC4EnvironmentSupportedLocales "supported_locales"
312
322
325
326
337
338
346CBL_CORE_API void c4_runAsyncTask(void (*task)(void*), void* C4NULLABLE context) C4API;
347
348
350
351
#define NODISCARD
Definition CompilerSupport.h:63
#define CBL_CORE_API
Definition c4Compat.h:131
#define C4NULLABLE
Definition c4Compat.h:38
#define C4API
Definition c4Compat.h:106
#define C4_ASSUME_NONNULL_BEGIN
Definition c4Compat.h:36
#define C4API_END_DECLS
Definition c4Compat.h:108
#define C4INLINE
Definition c4Compat.h:19
#define C4API_BEGIN_DECLS
Definition c4Compat.h:107
#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:177
C4Slice C4String
Definition c4Base.h:51
bool c4SliceEqual(C4Slice a, C4Slice b)
Definition c4Base.h:60
struct C4Index C4Index
Represents an existing index.
Definition c4Base.h:147
struct C4PeerSync C4PeerSync
A peer-to-peer sync session.
Definition c4Base.h:162
C4KeyPair * c4keypair_retain(C4KeyPair *r)
Definition c4Base.h:214
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.
CBL_CORE_API void c4docobs_free(C4DocumentObserver *)
C4Query * c4query_retain(C4Query *r)
Definition c4Base.h:220
struct C4BlobStore C4BlobStore
Opaque handle for an object that manages storage of blobs.
Definition c4Base.h:119
struct C4WriteStream C4WriteStream
An open stream for writing data to a blob.
Definition c4Base.h:189
C4HeapSlice C4HeapString
Definition c4Base.h:52
int64_t C4Timestamp
A date/time representation used for document expiration (and in date/time queries....
Definition c4Base.h:95
void c4index_release(C4Index *i)
Definition c4Base.h:234
void c4coll_release(C4Collection *r)
Definition c4Base.h:229
CBL_CORE_API C4Socket * c4socket_retain(C4Socket *)
struct C4DocEnumerator C4DocEnumerator
Opaque handle to a document enumerator.
Definition c4Base.h:144
struct C4Listener C4Listener
A LiteCore network listener – supports the REST API, replication, or both.
Definition c4Base.h:156
C4Index * c4index_retain(C4Index *r)
Definition c4Base.h:208
C4Database * c4db_retain(C4Database *r)
Definition c4Base.h:206
struct C4Query C4Query
Opaque handle to a compiled query.
Definition c4Base.h:165
void c4indexupdater_release(C4IndexUpdater *u)
Definition c4Base.h:236
uint64_t C4SequenceNumber
A database sequence number, representing the order in which a revision was created.
Definition c4Base.h:90
CBL_CORE_API C4QueryEnumerator * c4queryenum_retain(C4QueryEnumerator *)
struct C4CollectionObserver C4CollectionObserver
A collection-observer reference.
Definition c4Base.h:128
struct C4Replicator C4Replicator
Opaque reference to a replicator.
Definition c4Base.h:180
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 *)
void c4query_release(C4Query *r)
Definition c4Base.h:244
FLSliceResult C4SliceResult
Definition c4Base.h:50
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:171
C4Cert * c4cert_retain(C4Cert *r)
Definition c4Base.h:200
struct C4DocumentObserver C4DocumentObserver
A document-observer reference.
Definition c4Base.h:141
void c4logobserver_release(C4LogObserver *r)
Definition c4Base.h:241
struct C4LogObserver C4LogObserver
Opaque handle to a registered logging observer.
Definition c4Base.h:159
C4SliceResult C4StringResult
Definition c4Base.h:53
CBL_CORE_API void c4queryenum_release(C4QueryEnumerator *)
CBL_CORE_API void c4peersync_free(C4PeerSync *)
Disposes a C4PeerSync.
struct C4IndexUpdater C4IndexUpdater
Describes a set of index values that need to be computed by the application.
Definition c4Base.h:150
C4IndexUpdater * c4indexupdater_retain(C4IndexUpdater *r)
Definition c4Base.h:210
struct C4KeyPair C4KeyPair
An asymmetric key or key-pair (RSA, etc.) The private key may or may not be present.
Definition c4Base.h:153
CBL_CORE_API void c4queryobs_free(C4QueryObserver *)
CBL_CORE_API void c4doc_release(C4Document *)
C4Collection * c4coll_retain(C4Collection *r)
Definition c4Base.h:202
FLSlice C4Slice
Definition c4Base.h:48
CBL_CORE_API void c4enum_free(C4DocEnumerator *)
void c4slice_free(C4SliceResult s)
Definition c4Base.h:62
C4LogObserver * c4logobserver_retain(C4LogObserver *r)
Definition c4Base.h:216
void c4db_release(C4Database *r)
Definition c4Base.h:232
struct C4Collection C4Collection
Opaque handle to a namespace of documents in an opened database.
Definition c4Base.h:125
C4CollectionObserver C4DatabaseObserver
Definition c4Base.h:131
void c4keypair_release(C4KeyPair *r)
Definition c4Base.h:238
static C4INLINE C4Slice c4str(const char *str)
Definition c4Base.h:55
struct C4Database C4Database
Opaque handle to an opened database.
Definition c4Base.h:135
struct C4Socket C4Socket
Represents an open bidirectional stream of bytes or messages (typically a TCP socket....
Definition c4Base.h:183
CBL_CORE_API void c4base_release(void *obj)
CBL_CORE_API void c4repl_free(C4Replicator *)
Frees a replicator reference.
FLHeapSlice C4HeapSlice
Definition c4Base.h:49
CBL_CORE_API C4Document * c4doc_retain(C4Document *)
struct C4Cert C4Cert
An X.509 certificate, or certificate signing request (CSR).
Definition c4Base.h:122
void c4cert_release(C4Cert *r)
Definition c4Base.h:226
CBL_CORE_API void * c4base_retain(void *obj)
CBL_CORE_API void c4socket_release(C4Socket *)
FLSlice FLStr(const char *FL_NULLABLE str LIFETIMEBOUND)
Returns a slice pointing to the contents of a C string.
Definition FLSlice.h:132
FLEECE_PUBLIC bool FLSlice_Equal(FLSlice a, FLSlice b) FLPURE
Equality test of two slices.
void FLSliceResult_Release(FLSliceResult s)
Decrements the ref-count of a FLSliceResult, freeing its memory if it reached zero.
Definition FLSlice.h:189
FLSlice FLHeapSlice
A heap-allocated, reference-counted slice.
Definition FLSlice.h:93
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:57
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:106
void * pointer
Definition c4Base.h:107
void(* destructor)(void *ptr)
Client-specific pointer; can be anything.
Definition c4Base.h:108
A query result enumerator.
Definition c4QueryTypes.h:54
Contents of a raw document.
Definition c4DatabaseTypes.h:151
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:66