Browse Source

More Logging (in DEBUG build)

sync
heck 5 years ago
parent
commit
5d626151d3
  1. 2
      .hgignore
  2. 20
      Adapter.cc
  3. 9
      Adapter.hh
  4. 2
      Makefile
  5. 4
      Makefile.conf
  6. 9
      utils.hh

2
.hgignore

@ -9,3 +9,5 @@ test_adapter
lib lib
local.conf local.conf
build/ build/
# Default ignored files
.idea/

20
Adapter.cc

@ -12,6 +12,7 @@ using namespace std;
namespace pEp { namespace pEp {
void throw_status(PEP_STATUS status) void throw_status(PEP_STATUS status)
{ {
pEpLog("called");
if (status == PEP_STATUS_OK) if (status == PEP_STATUS_OK)
return; return;
if (status >= 0x400 && status <= 0x4ff) if (status >= 0x400 && status <= 0x4ff)
@ -28,7 +29,7 @@ namespace pEp {
RuntimeError::RuntimeError(const std::string& _text, PEP_STATUS _status) RuntimeError::RuntimeError(const std::string& _text, PEP_STATUS _status)
: std::runtime_error(_text.c_str()), text(_text), status(_status) : std::runtime_error(_text.c_str()), text(_text), status(_status)
{ {
pEpLog("called");
} }
namespace Adapter { namespace Adapter {
@ -36,18 +37,19 @@ namespace pEp {
notifyHandshake_t _notifyHandshake = nullptr; notifyHandshake_t _notifyHandshake = nullptr;
std::thread *_sync_thread = nullptr; std::thread *_sync_thread = nullptr;
::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > q; ::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > sync_q;
std::mutex m; std::mutex m;
int _inject_sync_event(SYNC_EVENT ev, void *management) int _inject_sync_event(SYNC_EVENT ev, void *management)
{ {
pEpLog("called");
try { try {
if (ev == nullptr) { if (ev == nullptr) {
q.clear(); sync_q.clear();
q.push_back(ev); sync_q.push_back(ev);
} }
else { else {
q.push_front(ev); sync_q.push_front(ev);
} }
} }
catch (exception&) { catch (exception&) {
@ -61,7 +63,7 @@ namespace pEp {
delete _sync_thread; delete _sync_thread;
_sync_thread = nullptr; _sync_thread = nullptr;
pEpLog("...thread joined"); pEpLog("...thread joined");
q.clear(); sync_q.clear();
} else { } else {
//FATAL //FATAL
pEpLog("FATAL: sync thread not joinable/detached"); pEpLog("FATAL: sync thread not joinable/detached");
@ -74,8 +76,9 @@ namespace pEp {
// threshold: max waiting time in seconds // threshold: max waiting time in seconds
SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold) SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold)
{ {
pEpLog("called");
SYNC_EVENT syncEvent = nullptr; SYNC_EVENT syncEvent = nullptr;
const bool success = q.try_pop_front(syncEvent, std::chrono::seconds(threshold)); const bool success = sync_q.try_pop_front(syncEvent, std::chrono::seconds(threshold));
if (!success) if (!success)
return new_sync_timeout_event(); return new_sync_timeout_event();
@ -85,6 +88,7 @@ namespace pEp {
bool on_sync_thread() bool on_sync_thread()
{ {
pEpLog("called");
if (_sync_thread && _sync_thread->get_id() == this_thread::get_id()) if (_sync_thread && _sync_thread->get_id() == this_thread::get_id())
return true; return true;
else else
@ -93,6 +97,7 @@ namespace pEp {
PEP_SESSION session(session_action action) PEP_SESSION session(session_action action)
{ {
pEpLog("called");
std::lock_guard<mutex> lock(m); std::lock_guard<mutex> lock(m);
bool in_sync = on_sync_thread(); bool in_sync = on_sync_thread();
@ -131,6 +136,7 @@ namespace pEp {
bool is_sync_running() bool is_sync_running()
{ {
pEpLog("called");
return _sync_thread != nullptr; return _sync_thread != nullptr;
} }
} }

9
Adapter.hh

@ -7,14 +7,7 @@
#include <string> #include <string>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
#include <stdexcept> #include <stdexcept>
#include "utils.hh"
// TODO: put into not yet existing libpEpAdapter_utils.h, to be across whole libpEpAdapter
#ifdef NDEBUG
#define pEpLog(msg) do{}while(0)
#else
#include <iostream>
#define pEpLog(msg) do{std::cerr << __FILE__ << "::" << __FUNCTION__ << " - " << msg << '\n';} while(0)
#endif
namespace pEp { namespace pEp {

2
Makefile

@ -17,7 +17,7 @@ ifdef BUILD_CONFIG
$(info ================================================) $(info ================================================)
endif endif
.PHONY: all, lib, test, install, uninstall, clean .PHONY: all lib test install uninstall clean
SOURCE=$(wildcard *.cc) SOURCE=$(wildcard *.cc)
HEADERS=$(wildcard *.hh *.hxx) HEADERS=$(wildcard *.hh *.hxx)

4
Makefile.conf

@ -32,11 +32,11 @@ else
CXXFLAGS+=-DNDEBUG=1 CXXFLAGS+=-DNDEBUG=1
endif endif
######### Engine ######### # Defaults
ENGINE_LIB_PATH=$(HOME)/lib ENGINE_LIB_PATH=$(HOME)/lib
ENGINE_INC_PATH=$(HOME)/include ENGINE_INC_PATH=$(HOME)/include
######### Overrides ######### # Config File
-include $(HERE)/local.conf -include $(HERE)/local.conf
# Add -L Prefixes to LIB/INC paths, # Add -L Prefixes to LIB/INC paths,

9
utils.hh

@ -0,0 +1,9 @@
#pragma once
#ifdef NDEBUG
#define pEpLog(msg) do{}while(0)
#else
#include <iostream>
#define pEpLog(msg) do{std::cerr << __FILE__ << "::" << __FUNCTION__ << " - " << msg << '\n';} while(0)
#endif
Loading…
Cancel
Save