Skip to content

Commit 9dafd9e

Browse files
committed
0.17.0
1 parent d421856 commit 9dafd9e

File tree

13 files changed

+805
-237
lines changed

13 files changed

+805
-237
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
ObjectBox C and C++ API Changelog
22
=================================
33

4+
0.17.0 (2022-06-14)
5+
-------------------
6+
* Added a "weak store" API providing weak reference for stores (typically used by background threads)
7+
* Added Store ID API, e.g. getting a store by its ID
8+
* Various internal improvements including minor optimizations for binary size and performance
9+
10+
### C++
11+
12+
* New "OBX_CPP_FILE" define to place declarations in a single .cpp/.cc file: improves compilation time and results
13+
* New "Exception" base class for all thrown exceptions
14+
* Various internal improvements, e.g. a "internal" namespace to better distinguish from userland API
15+
416
0.16.0 (2022-05-06)
517
-------------------
618
* Allow UTF-8 for database directories on Windows (available for other platforms before)

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ else ()
3131

3232
function(defineObjectBoxLib VARIANT)
3333
# Configuration updated for each release
34-
set(DL_VERSION 0.16.0)
34+
set(DL_VERSION 0.17.0)
3535

3636
# Platform detection and other setup
3737
set(DL_URL https://github.com/objectbox/objectbox-c/releases/download)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ box.put({.text = "Buy milk"});
1717
1818
See [ObjectBox C and C++ docs](https://cpp.objectbox.io/) for API details.
1919
20-
**Latest version: 0.16.0** (2022-05-06).
20+
**Latest version: 0.17.0** (2022-06-14).
2121
See [changelog](CHANGELOG.md) for more details.
2222
2323
Feature Highlights

download.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ tty -s || quiet=true
4444

4545
# Note: optional arguments like "--quiet" shifts argument positions in the case block above
4646

47-
version=${1:-0.16.0}
47+
version=${1:-0.17.0}
4848
os=${2:-$(uname)}
4949
arch=${3:-$(uname -m)}
5050
echo "Base config: OS ${os} and architecture ${arch}"

doxygen/Changelog.md

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
ObjectBox C and C++ API Changelog
44
=================================
55

6+
0.17.0 (2022-06-14)
7+
-------------------
8+
* Added a "weak store" API providing weak reference for stores (typically used by background threads)
9+
* Added Store ID API, e.g. getting a store by its ID
10+
* Various internal improvements including minor optimizations for binary size and performance
11+
12+
### C++
13+
14+
* New "OBX_CPP_FILE" define to place declarations in a single .cpp/.cc file: improves compilation time and results
15+
* New "Exception" base class for all thrown exceptions
16+
* Various internal improvements, e.g. a "internal" namespace to better distinguish from userland API
17+
618
0.16.0 (2022-05-06)
719
-------------------
820
* Allow UTF-8 for database directories on Windows (available for other platforms before)

doxygen/Doxyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = "ObjectBox C and C++ API"
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = "0.16.0"
41+
PROJECT_NUMBER = "0.17.0"
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a

examples/c-cursor-no-gen/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void do_action_help(char* program_path) {
159159
//--------------------------------------------------------------------------------------------------------------------
160160

161161
int do_action_new(OBX_store* store, int argc, char* argv[]) {
162-
char* text = NULL;
162+
char* text = "n/a";
163163
void* buff = NULL;
164164
size_t size = 0;
165165
OBX_txn* txn = NULL;

examples/cpp-gen-sync/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17+
#define OBX_CPP_FILE
1718
#include "tasklist-example-app.hpp"
1819

19-
2020
using namespace obx;
2121

2222
int main(int argc, char* argv[]) {

examples/cpp-gen/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
#define OBX_CPP_FILE
1718
#include "tasklist-example-app.hpp"
1819

1920
int main(int argc, char* argv[]) {

include/objectbox-sync.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "objectbox.h"
3535

3636
#if defined(static_assert) || defined(__cplusplus)
37-
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 16 && OBX_VERSION_PATCH == 0,
37+
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 17 && OBX_VERSION_PATCH == 0,
3838
"Versions of objectbox.h and objectbox-sync.h files do not match, please update");
3939
#endif
4040

include/objectbox-sync.hpp

+40-34
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "objectbox-sync.h"
2020
#include "objectbox.hpp"
2121

22-
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 16 && OBX_VERSION_PATCH == 0,
22+
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 17 && OBX_VERSION_PATCH == 0,
2323
"Versions of objectbox.h and objectbox-sync.hpp files do not match, please update");
2424

2525
static_assert(sizeof(obx_id) == sizeof(OBX_id_array::ids[0]),
@@ -179,8 +179,9 @@ class SyncClient : public Closable {
179179
public:
180180
/// Creates a sync client associated with the given store and options.
181181
/// This does not initiate any connection attempts yet: call start() to do so.
182-
explicit SyncClient(Store& store, const std::string& serverUri, const SyncCredentials& creds) : store_(store) {
183-
cSync_ = checkPtrOrThrow(obx_sync(store.cPtr(), serverUri.c_str()), "can't initialize sync client");
182+
explicit SyncClient(Store& store, const std::string& serverUri, const SyncCredentials& creds)
183+
: store_(store), cSync_(obx_sync(store.cPtr(), serverUri.c_str())) {
184+
internal::checkPtrOrThrow(cSync_, "Could not initialize sync client");
184185
try {
185186
setCredentials(creds);
186187
} catch (...) {
@@ -193,8 +194,8 @@ class SyncClient : public Closable {
193194
/// This does not initiate any connection attempts yet: call start() to do so.
194195
/// @param cSync an initialized sync client. You must NOT call obx_sync_close() yourself anymore.
195196
explicit SyncClient(Store& store, OBX_sync* cSync) : store_(store), cSync_(cSync) {
196-
OBJECTBOX_VERIFY_STATE(obx_has_feature(OBXFeature_Sync));
197-
OBJECTBOX_VERIFY_ARGUMENT(cSync);
197+
OBX_VERIFY_STATE(obx_has_feature(OBXFeature_Sync));
198+
OBX_VERIFY_ARGUMENT(cSync);
198199
}
199200

200201
/// Can't be moved due to the atomic cSync_ - use shared_ptr instead of SyncClient instances directly.
@@ -230,8 +231,9 @@ class SyncClient : public Closable {
230231
/// Configure authentication credentials.
231232
/// The accepted OBXSyncCredentials type depends on your sync-server configuration.
232233
void setCredentials(const SyncCredentials& creds) {
233-
checkErrOrThrow(obx_sync_credentials(cPtr(), creds.type_, creds.data_.empty() ? nullptr : creds.data_.data(),
234-
creds.data_.size()));
234+
obx_err err = obx_sync_credentials(cPtr(), creds.type_, creds.data_.empty() ? nullptr : creds.data_.data(),
235+
creds.data_.size());
236+
internal::checkErrOrThrow(err);
235237
}
236238

237239
/// Sets the interval in which the client sends "heartbeat" messages to the server, keeping the connection alive.
@@ -241,21 +243,21 @@ class SyncClient : public Closable {
241243
/// @param interval default value is 25 minutes (1 500 000 milliseconds), which is also the allowed maximum.
242244
/// @throws if value is not in the allowed range, e.g. larger than the maximum (1 500 000).
243245
void setHeartbeatInterval(std::chrono::milliseconds interval) {
244-
checkErrOrThrow(obx_sync_heartbeat_interval(cPtr(), interval.count()));
246+
internal::checkErrOrThrow(obx_sync_heartbeat_interval(cPtr(), interval.count()));
245247
}
246248

247249
/// Triggers the heartbeat sending immediately.
248-
void sendHeartbeat() { checkErrOrThrow(obx_sync_send_heartbeat(cPtr())); }
250+
void sendHeartbeat() { internal::checkErrOrThrow(obx_sync_send_heartbeat(cPtr())); }
249251

250252
/// Configures how sync updates are received from the server.
251253
/// If automatic sync updates are turned off, they will need to be requested manually.
252254
void setRequestUpdatesMode(OBXRequestUpdatesMode mode) {
253-
checkErrOrThrow(obx_sync_request_updates_mode(cPtr(), mode));
255+
internal::checkErrOrThrow(obx_sync_request_updates_mode(cPtr(), mode));
254256
}
255257

256258
/// Configures the maximum number of outgoing TX messages that can be sent without an ACK from the server.
257259
/// @throws if value is not in the valid range 1-20
258-
void maxMessagesInFlight(int value) { checkErrOrThrow(obx_sync_max_messages_in_flight(cPtr(), value)); }
260+
void maxMessagesInFlight(int value) { internal::checkErrOrThrow(obx_sync_max_messages_in_flight(cPtr(), value)); }
259261

260262
/// Once the sync client is configured, you can "start" it to initiate synchronization.
261263
/// This method triggers communication in the background and will return immediately.
@@ -264,21 +266,21 @@ class SyncClient : public Closable {
264266
/// If the device, network or server is currently offline, connection attempts will be retried later using
265267
/// increasing backoff intervals.
266268
/// If you haven't set the credentials in the options during construction, call setCredentials() before start().
267-
void start() { checkErrOrThrow(obx_sync_start(cPtr())); }
269+
void start() { internal::checkErrOrThrow(obx_sync_start(cPtr())); }
268270

269271
/// Stops this sync client. Does nothing if it is already stopped.
270-
void stop() { checkErrOrThrow(obx_sync_stop(cPtr())); }
272+
void stop() { internal::checkErrOrThrow(obx_sync_stop(cPtr())); }
271273

272274
/// Request updates since we last synchronized our database.
273275
/// @param subscribeForFuturePushes to keep sending us future updates as they come in.
274276
/// @see updatesCancel() to stop the updates
275277
bool requestUpdates(bool subscribeForFuturePushes) {
276-
return checkSuccessOrThrow(obx_sync_updates_request(cPtr(), subscribeForFuturePushes));
278+
return internal::checkSuccessOrThrow(obx_sync_updates_request(cPtr(), subscribeForFuturePushes));
277279
}
278280

279281
/// Cancel updates from the server so that it will stop sending updates.
280282
/// @see updatesRequest()
281-
bool cancelUpdates() { return checkSuccessOrThrow(obx_sync_updates_cancel(cPtr())); }
283+
bool cancelUpdates() { return internal::checkSuccessOrThrow(obx_sync_updates_cancel(cPtr())); }
282284

283285
/// Count the number of messages in the outgoing queue, i.e. those waiting to be sent to the server.
284286
/// Note: This calls uses a (read) transaction internally: 1) it's not just a "cheap" return of a single number.
@@ -287,7 +289,7 @@ class SyncClient : public Closable {
287289
/// @return the number of messages in the outgoing queue
288290
uint64_t outgoingMessageCount(uint64_t limit = 0) {
289291
uint64_t result;
290-
checkErrOrThrow(obx_sync_outgoing_message_count(cPtr(), limit, &result));
292+
internal::checkErrOrThrow(obx_sync_outgoing_message_count(cPtr(), limit, &result));
291293
return result;
292294
}
293295

@@ -461,7 +463,7 @@ class SyncClient : public Closable {
461463
protected:
462464
OBX_sync* cPtr() const {
463465
OBX_sync* ptr = cSync_;
464-
if (ptr == nullptr) throw std::runtime_error("Sync client was already closed");
466+
if (ptr == nullptr) throw IllegalStateException("Sync client was already closed");
465467
return ptr;
466468
}
467469

@@ -473,7 +475,7 @@ class SyncClient : public Closable {
473475
std::lock_guard<std::mutex> lock(store_.syncClientMutex_);
474476
store_.syncClient_.reset();
475477
}
476-
checkErrOrThrow(obx_sync_close(ptr));
478+
internal::checkErrOrThrow(obx_sync_close(ptr));
477479
}
478480
}
479481

@@ -533,7 +535,7 @@ class Sync {
533535
static std::shared_ptr<SyncClient> client(Store& store, const std::string& serverUri,
534536
const SyncCredentials& creds) {
535537
std::lock_guard<std::mutex> lock(store.syncClientMutex_);
536-
if (store.syncClient_) throw std::runtime_error("Only one sync client can be active for a store");
538+
if (store.syncClient_) throw IllegalStateException("Only one sync client can be active for a store");
537539
store.syncClient_.reset(new SyncClient(store, serverUri, creds));
538540
return std::static_pointer_cast<SyncClient>(store.syncClient_);
539541
}
@@ -542,7 +544,7 @@ class Sync {
542544
/// @param cSync an initialized sync client. You must NOT call obx_sync_close() yourself anymore.
543545
static std::shared_ptr<SyncClient> client(Store& store, OBX_sync* cSync) {
544546
std::lock_guard<std::mutex> lock(store.syncClientMutex_);
545-
if (store.syncClient_) throw std::runtime_error("Only one sync client can be active for a store");
547+
if (store.syncClient_) throw IllegalStateException("Only one sync client can be active for a store");
546548
store.syncClient_.reset(new SyncClient(store, cSync));
547549
return std::static_pointer_cast<SyncClient>(store.syncClient_);
548550
}
@@ -591,10 +593,12 @@ class SyncServer : public Closable {
591593
/// an arbitrary port that is available. The port can be queried via obx_sync_server_port() once the server
592594
/// was started. \b Examples: "ws://0.0.0.0:9999" could be used during development (no certificate config
593595
/// needed), while in a production system, you may want to use wss and a specific IP for security reasons.
594-
explicit SyncServer(Options& storeOptions, const std::string& uri) {
595-
cPtr_ = checkPtrOrThrow(obx_sync_server(storeOptions.release(), uri.c_str()), "Could not create SyncServer");
596+
explicit SyncServer(Options& storeOptions, const std::string& uri)
597+
: cPtr_(obx_sync_server(storeOptions.release(), uri.c_str())) {
598+
internal::checkPtrOrThrow(cPtr_, "Could not create SyncServer");
596599
try {
597-
OBX_store* cStore = checkPtrOrThrow(obx_sync_server_store(cPtr_), "Can't get SyncServer's store");
600+
OBX_store* cStore = obx_sync_server_store(cPtr_);
601+
internal::checkPtrOrThrow(cStore, "Could not get SyncServer's store");
598602
store_.reset(new Store(cStore, false));
599603
} catch (...) {
600604
close();
@@ -623,7 +627,7 @@ class SyncServer : public Closable {
623627

624628
/// The store that is associated with this server.
625629
Store& store() {
626-
OBJECTBOX_VERIFY_STATE(store_);
630+
OBX_VERIFY_STATE(store_);
627631
return *store_;
628632
}
629633

@@ -634,7 +638,7 @@ class SyncServer : public Closable {
634638
cPtr_ = nullptr;
635639
store_.reset();
636640
if (ptr) {
637-
checkErrOrThrow(obx_sync_server_close(ptr));
641+
internal::checkErrOrThrow(obx_sync_server_close(ptr));
638642
}
639643
}
640644

@@ -643,34 +647,36 @@ class SyncServer : public Closable {
643647

644648
/// Sets SSL certificate for the server to use. Use before start().
645649
void setCertificatePath(const std::string& path) {
646-
checkErrOrThrow(obx_sync_server_certificate_path(cPtr(), path.c_str()));
650+
internal::checkErrOrThrow(obx_sync_server_certificate_path(cPtr(), path.c_str()));
647651
}
648652

649653
/// Sets credentials for the server to accept. Use before start().
650654
/// @param data may be NULL in combination with OBXSyncCredentialsType_NONE
651655
void setCredentials(const SyncCredentials& creds) {
652-
checkErrOrThrow(obx_sync_server_credentials(
656+
internal::checkErrOrThrow(obx_sync_server_credentials(
653657
cPtr(), creds.type_, creds.data_.empty() ? nullptr : creds.data_.data(), creds.data_.size()));
654658
}
655659

656660
/// Once the sync server is configured, you can "start" it to start accepting client connections.
657661
/// This method triggers communication in the background and will return immediately.
658-
void start() { checkErrOrThrow(obx_sync_server_start(cPtr())); }
662+
void start() { internal::checkErrOrThrow(obx_sync_server_start(cPtr())); }
659663

660664
/// Stops this sync server. Does nothing if it is already stopped.
661-
void stop() { checkErrOrThrow(obx_sync_server_stop(cPtr())); }
665+
void stop() { internal::checkErrOrThrow(obx_sync_server_stop(cPtr())); }
662666

663667
/// Returns if this sync server is running
664668
bool isRunning() { return obx_sync_server_running(cPtr()); }
665669

666670
/// Returns a URL this server is listening on, including the bound port (see port().
667-
std::string url() { return checkPtrOrThrow(obx_sync_server_url(cPtr()), "Can't get SyncServer bound URL"); }
671+
std::string url() {
672+
return internal::checkedPtrOrThrow(obx_sync_server_url(cPtr()), "Can't get SyncServer bound URL");
673+
}
668674

669675
/// Returns a port this server listens on. This is especially useful if the bindUri given to the constructor
670676
/// specified "0" port (i.e. automatic assignment).
671677
uint16_t port() {
672678
uint16_t result = obx_sync_server_port(cPtr());
673-
if (!result) throwLastError();
679+
if (!result) internal::throwLastError();
674680
return result;
675681
}
676682

@@ -679,8 +685,8 @@ class SyncServer : public Closable {
679685

680686
/// Get server runtime statistics.
681687
std::string statsString(bool includeZeroValues = true) {
682-
return checkPtrOrThrow(obx_sync_server_stats_string(cPtr(), includeZeroValues),
683-
"Can't get SyncServer stats string");
688+
const char* serverStatsString = obx_sync_server_stats_string(cPtr(), includeZeroValues);
689+
return internal::checkedPtrOrThrow(serverStatsString, "Can't get SyncServer stats string");
684690
}
685691

686692
void setChangeListener(std::shared_ptr<SyncChangeListener> listener) {
@@ -723,7 +729,7 @@ class SyncServer : public Closable {
723729
protected:
724730
OBX_sync_server* cPtr() const {
725731
OBX_sync_server* ptr = cPtr_;
726-
if (ptr == nullptr) throw std::runtime_error("Sync server was already closed");
732+
if (ptr == nullptr) throw IllegalStateException("Sync server was already closed");
727733
return ptr;
728734
}
729735
};

0 commit comments

Comments
 (0)