From e61c860a2581bf0fa1de4ce17785a84e9d26c97b Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Mon, 27 May 2019 16:29:13 +0200 Subject: [PATCH] runtime error trying to start sync if no own identities available --- Adapter.hxx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Adapter.hxx b/Adapter.hxx index fb6e51c..9780a04 100644 --- a/Adapter.hxx +++ b/Adapter.hxx @@ -2,13 +2,20 @@ #include #include "locked_queue.hh" +#include #include namespace pEp { namespace Adapter { using std::function; - + + struct CannotStartSync : std::runtime_error { + CannotStartSync() + : std::runtime_error("cannot start sync: no own identities available") + { } + }; + extern messageToSend_t _messageToSend; extern notifyHandshake_t _notifyHandshake; extern std::thread *_sync_thread; @@ -59,8 +66,18 @@ namespace pEp { { std::lock_guard lock(m); - if (!_sync_thread) - _sync_thread = new std::thread(sync_thread, obj, _startup, _shutdown); + if (!_sync_thread) { + identity_list *il = nullptr; + PEP_STATUS status = ::own_identities_retrieve(session(), &il); + throw_status(status); + bool own_identities_exist = il && il->ident; + ::free_identity_list(il); + + if (own_identities_exist) + _sync_thread = new std::thread(sync_thread, obj, _startup, _shutdown); + else + throw CannotStartSync(); + } } } }