Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CID
mirrors
libpEpAdapter
Commits
76517126
Commit
76517126
authored
Jan 20, 2023
by
Matthias Heckmann
Browse files
create sections for separate concerns Session/Sync/Passphrase/Error
to be refactored into own modules.
parent
7d8accd9
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/Adapter.cc
View file @
76517126
...
...
@@ -15,66 +15,10 @@ thread_local pEp::Adapter::Session pEp::Adapter::session{};
namespace
pEp
{
namespace
Adapter
{
std
::
thread
_sync_thread
;
::
utility
::
locked_queue
<
SYNC_EVENT
,
::
free_Sync_event
>
sync_evt_q
;
std
::
mutex
mut
;
// private
std
::
thread
::
id
sync_thread_id
()
{
return
_sync_thread
.
get_id
();
}
// private
int
_process_sync_event
(
::
SYNC_EVENT
ev
,
void
*
management
)
{
if
(
ev
!=
nullptr
)
{
::
do_sync_protocol_step
(
session
(),
nullptr
,
ev
);
}
return
0
;
}
// public (json adapter needs it, but should use Session mgmt from libpEpAdapter eventually)
int
_inject_sync_event
(
::
SYNC_EVENT
ev
,
void
*
management
)
{
try
{
if
(
ev
==
nullptr
)
{
sync_evt_q
.
clear
();
sync_evt_q
.
push_back
(
ev
);
}
else
{
sync_evt_q
.
push_front
(
ev
);
}
}
catch
(
exception
&
)
{
return
1
;
}
return
0
;
}
// private
PEP_STATUS
_ensure_passphrase
(
::
PEP_SESSION
session
,
const
char
*
fpr
)
{
return
passphrase_cache
.
ensure_passphrase
(
session
,
fpr
);
}
// public
::
SYNC_EVENT
_retrieve_next_sync_event
(
void
*
management
,
unsigned
threshold
)
{
::
SYNC_EVENT
syncEvent
=
nullptr
;
const
bool
success
=
sync_evt_q
.
try_pop_front
(
syncEvent
,
std
::
chrono
::
seconds
(
threshold
));
if
(
!
success
)
{
return
::
new_sync_timeout_event
();
}
return
syncEvent
;
}
// public
bool
on_sync_thread
()
{
return
_sync_thread
.
get_id
()
==
this_thread
::
get_id
();
}
::
SYNC_EVENT
_cb_dequeue_next_sync_event
(
void
*
management
,
unsigned
threshold
);
// ---------------------------------------------------------------------------------------
// SESSION
// ---------------------------------------------------------------------------------------
Session
::
Session
()
:
_sync_mode
{
SyncModes
::
Async
},
_messageToSend
{
nullptr
},
_notifyHandshake
{
nullptr
},
...
...
@@ -167,6 +111,62 @@ namespace pEp {
return
_session
.
get
();
}
// ---------------------------------------------------------------------------------------
// SYNC
// ---------------------------------------------------------------------------------------
std
::
thread
_sync_thread
{};
::
utility
::
locked_queue
<
SYNC_EVENT
,
::
free_Sync_event
>
sync_evt_q
{};
// private
std
::
thread
::
id
sync_thread_id
()
{
return
_sync_thread
.
get_id
();
}
// private
int
_cb_pass_sync_event_to_engine
(
::
SYNC_EVENT
ev
,
void
*
management
)
{
if
(
ev
!=
nullptr
)
{
::
do_sync_protocol_step
(
session
(),
nullptr
,
ev
);
}
return
0
;
}
// public (json adapter needs it, but should use Session mgmt from libpEpAdapter eventually)
int
_cb_enqueue_sync_event
(
::
SYNC_EVENT
ev
,
void
*
management
)
{
try
{
if
(
ev
==
nullptr
)
{
sync_evt_q
.
clear
();
sync_evt_q
.
push_back
(
ev
);
}
else
{
sync_evt_q
.
push_front
(
ev
);
}
}
catch
(...)
{
return
1
;
}
return
0
;
}
// public
::
SYNC_EVENT
_cb_dequeue_next_sync_event
(
void
*
management
,
unsigned
threshold
)
{
::
SYNC_EVENT
syncEvent
=
nullptr
;
const
bool
success
=
sync_evt_q
.
try_pop_front
(
syncEvent
,
std
::
chrono
::
seconds
(
threshold
));
if
(
!
success
)
{
return
::
new_sync_timeout_event
();
}
return
syncEvent
;
}
// public
bool
on_sync_thread
()
{
return
_sync_thread
.
get_id
()
==
this_thread
::
get_id
();
}
// public
void
inject_sync_shutdown
()
{
...
...
@@ -214,6 +214,12 @@ namespace pEp {
}
return
!
ev
;
}
PEP_STATUS
_ensure_passphrase
(
::
PEP_SESSION
session
,
const
char
*
fpr
)
{
return
passphrase_cache
.
ensure_passphrase
(
session
,
fpr
);
}
}
// namespace Adapter
void
throw_status
(
::
PEP_STATUS
status
)
...
...
src/Adapter.hh
View file @
76517126
...
...
@@ -20,26 +20,6 @@ namespace pEp {
Async
};
int
_inject_sync_event
(
::
SYNC_EVENT
ev
,
void
*
management
);
int
_process_sync_event
(
::
SYNC_EVENT
ev
,
void
*
management
);
::
PEP_STATUS
_ensure_passphrase
(
::
PEP_SESSION
session
,
const
char
*
fpr
);
void
start_sync
();
template
<
class
T
=
void
>
void
startup
(
T
*
obj
=
nullptr
,
std
::
function
<
void
(
T
*
)
>
_startup
=
nullptr
,
std
::
function
<
void
(
T
*
)
>
_shutdown
=
nullptr
);
// returns 'true' when called from the "sync" thread, 'false' otherwise.
bool
on_sync_thread
();
// returns the thread id of the sync thread
std
::
thread
::
id
sync_thread_id
();
// The thread-local pEp-session
// CAVEAT: there is a default constructor Sesssion(),
// BUT
...
...
@@ -129,6 +109,26 @@ namespace pEp {
extern
thread_local
Session
session
;
// ---------------------------------------------------------------------------------------
// SYNC
// ---------------------------------------------------------------------------------------
int
_cb_enqueue_sync_event
(
::
SYNC_EVENT
ev
,
void
*
management
);
int
_cb_pass_sync_event_to_engine
(
::
SYNC_EVENT
ev
,
void
*
management
);
void
start_sync
();
template
<
class
T
=
void
>
void
startup
(
T
*
obj
=
nullptr
,
std
::
function
<
void
(
T
*
)
>
_startup
=
nullptr
,
std
::
function
<
void
(
T
*
)
>
_shutdown
=
nullptr
);
// returns 'true' when called from the "sync" thread, 'false' otherwise.
bool
on_sync_thread
();
// returns the thread id of the sync thread
std
::
thread
::
id
sync_thread_id
();
// only injects a NULL event into sync_event_queue
// Use this if adapter_manages_sync_thread
// Inject first, then join your thread.
...
...
@@ -140,6 +140,8 @@ namespace pEp {
bool
is_sync_running
();
bool
in_shutdown
();
::
PEP_STATUS
_ensure_passphrase
(
::
PEP_SESSION
session
,
const
char
*
fpr
);
}
// namespace Adapter
// throws std::bad_alloc if status==PEP_OUT_OF_MEMORY,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment