Browse Source

formatting and comments only

pull/15/head
heck 2 years ago
parent
commit
7d8accd983
  1. 4
      src/Adapter.cc
  2. 12
      src/Adapter.hh
  3. 25
      src/Adapter.hxx

4
src/Adapter.cc

@ -82,6 +82,7 @@ namespace pEp {
{ {
} }
// Public/Static
void Session::initialize(SyncModes sync_mode, bool adapter_manages_sync_thread) void Session::initialize(SyncModes sync_mode, bool adapter_manages_sync_thread)
{ {
pEpLog("Initializing session with CallbackDispatcher..."); pEpLog("Initializing session with CallbackDispatcher...");
@ -92,6 +93,7 @@ namespace pEp {
adapter_manages_sync_thread); adapter_manages_sync_thread);
} }
// Public/Static
void Session::initialize( void Session::initialize(
SyncModes sync_mode, SyncModes sync_mode,
bool adapter_manages_sync_thread, bool adapter_manages_sync_thread,
@ -102,6 +104,7 @@ namespace pEp {
_init(messageToSend, notifyHandshake, sync_mode, adapter_manages_sync_thread); _init(messageToSend, notifyHandshake, sync_mode, adapter_manages_sync_thread);
} }
// Private/Static
void Session::_init( void Session::_init(
::messageToSend_t messageToSend, ::messageToSend_t messageToSend,
::notifyHandshake_t notifyHandshake, ::notifyHandshake_t notifyHandshake,
@ -201,7 +204,6 @@ namespace pEp {
} }
// public // public
// Works even if adapter is managing sync thread, BUT must be using this queue
bool in_shutdown() bool in_shutdown()
{ {
SYNC_EVENT ev{ nullptr }; SYNC_EVENT ev{ nullptr };

12
src/Adapter.hh

@ -15,9 +15,7 @@
namespace pEp { namespace pEp {
namespace Adapter { namespace Adapter {
// public enum class SyncModes {
enum class SyncModes
{
Sync, Sync,
Async Async
}; };
@ -46,6 +44,9 @@ namespace pEp {
// CAVEAT: there is a default constructor Sesssion(), // CAVEAT: there is a default constructor Sesssion(),
// BUT // BUT
// the session object needs to be initialized in order to be usable. // the session object needs to be initialized in order to be usable.
// The initialization defines the session configuration for all sessions that
// are being created in the lifetime of a process
// A Session object is not copyable/assignable
// TODO: remove initialize() and do that in the ctor's // TODO: remove initialize() and do that in the ctor's
// remove release() and do that in the destructor // remove release() and do that in the destructor
@ -58,8 +59,9 @@ namespace pEp {
Session operator=(const Session &) = delete; Session operator=(const Session &) = delete;
Session operator=(const Session &&) = delete; Session operator=(const Session &&) = delete;
~Session() = default; ~Session() = default;
// Initialize() // Initialize()
// Initializes the session and registers the CallbackDispatcher as callbacks // Initializes the session and registers the CallbackDispatcher's functions for callbacks
// //
// SyncModes sync_mode: // SyncModes sync_mode:
// * Sync: // * Sync:
@ -103,6 +105,8 @@ namespace pEp {
void refresh(); void refresh();
void release(); void release();
// returns the PEP_SESSION handle
PEP_SESSION operator()(); PEP_SESSION operator()();
SyncModes _sync_mode; SyncModes _sync_mode;

25
src/Adapter.hxx

@ -15,7 +15,6 @@ namespace pEp {
using std::function; using std::function;
extern std::thread _sync_thread; extern std::thread _sync_thread;
extern ::utility::locked_queue<::SYNC_EVENT, ::free_Sync_event> sync_evt_q; extern ::utility::locked_queue<::SYNC_EVENT, ::free_Sync_event> sync_evt_q;
extern std::mutex mut; extern std::mutex mut;
@ -28,11 +27,10 @@ namespace pEp {
* Sync Thread * Sync Thread
* 1. Execute registered startup function * 1. Execute registered startup function
* 2. Create session for the sync thread (registers: messageToSend, inject_sync_event, ensure_passphrase) * 2. Create session for the sync thread (registers: messageToSend, inject_sync_event, ensure_passphrase)
* 3. register_sync_callbacks() (registers: _notifyHandshake, _retrieve_next_sync_event) * 3. Enter Sync Event Processing Loop (do_sync_protocol())
* 4. Enter Sync Event Dispatching Loop (do_sync_protocol()) * 4. unregister_sync_callbacks()
* 5. unregister_sync_callbacks() * 5. Release the session
* 6. Release the session * 6. Execute registered shutdown function
* 7. Execute registered shutdown function
*/ */
// private // private
template<class T> template<class T>
@ -71,29 +69,22 @@ namespace pEp {
} }
pEpLog("sync protocol loop started"); pEpLog("sync protocol loop started");
// 4. Enter Sync Event Dispatching Loop (do_sync_protocol())
::do_sync_protocol(session(), (void *)obj); ::do_sync_protocol(session(), (void *)obj);
pEpLog("sync protocol loop ended"); pEpLog("sync protocol loop ended");
// 5. unregister_sync_callbacks() // 4. unregister_sync_callbacks()
unregister_sync_callbacks(session()); unregister_sync_callbacks(session());
// 6. Release the session // 5. Release the session
session.release(); session.release();
// 7. Execute registered shutdown function // 6. Execute registered shutdown function
if (obj && _shutdown) { if (obj && _shutdown) {
_shutdown(obj); _shutdown(obj);
} }
} }
/* // Sync Thread Startup
* Sync Thread Startup
* 1. throw if main thread session is not initialized
* 2. Start the sync thread
* 3. Defer execution until sync thread register_sync_callbacks() has returned
* 4. Throw pending exception from the sync thread
*/
// private // private
template<class T> template<class T>
void startup(T *obj, std::function<void(T *)> _startup, std::function<void(T *)> _shutdown) void startup(T *obj, std::function<void(T *)> _startup, std::function<void(T *)> _shutdown)

Loading…
Cancel
Save