Browse Source

do weird things when on sync thread... :-/

new_sync Release_2.1.0-RC3
Roker 2 years ago
parent
commit
4bdb5758fa
4 changed files with 26 additions and 4 deletions
  1. +12
    -1
      server/json-adapter.cc
  2. +5
    -2
      server/json-adapter.hh
  3. +7
    -0
      server/mini-adapter-impl.cc
  4. +2
    -1
      server/mini-adapter-impl.hh

+ 12
- 1
server/json-adapter.cc View File

@ -187,8 +187,19 @@ ServerVersion JsonAdapter::version()
PEP_STATUS JsonAdapter::messageToSend(message* msg)
{
JsonAdapter& ja = getInstance();
if( std::this_thread::get_id() == ja.get_sync_thread_id() )
{
if(msg == nullptr)
{
return pEp::PassphraseCache::config_next_passphrase();
}else{
return pEp::PassphraseCache::config_next_passphrase(true);
}
}
js::Value v{to_json(msg)};
getInstance().i->makeAndDeliverRequest("messageToSend", js::Array{ std::move(v) } );
ja.i->makeAndDeliverRequest("messageToSend", js::Array{ std::move(v) } );
return PEP_STATUS_OK;
}


+ 5
- 2
server/json-adapter.hh View File

@ -1,6 +1,7 @@
#ifndef JSON_ADAPTER_HH
#define JSON_ADAPTER_HH
#include <thread>
#include <pEp/message.h>
#include <pEp/sync_api.h>
#include "registry.hh"
@ -36,8 +37,8 @@ public:
JsonAdapter& ignore_session_errors(bool _ig);
// if called with "false" the JSON Adpapter would no longer deliver HTML and JavaScript files, only handle JSON-RPC requests
JsonAdapter& deliver_html(bool _deliver_html);
JsonAdapter& deliver_html(bool _deliver_html);
// look for a free port to listen on and set the given configuration
void prepare_run(const std::string& address, unsigned start_port, unsigned end_port, ::messageToSend_t messageToSend);
@ -69,6 +70,8 @@ public:
unsigned request_count() const;
virtual std::thread::id get_sync_thread_id() const = 0;
// returns 'true' if 's' is the security token created by the function above.
virtual bool verify_security_token(const std::string& s) const override;


+ 7
- 0
server/mini-adapter-impl.cc View File

@ -167,5 +167,12 @@ Adapter& Adapter::createInstance()
return dynamic_cast<Adapter&>(JsonAdapter::createInstance( new Adapter() ));
}
std::thread::id Adapter::get_sync_thread_id() const
{
return sync_thread ? sync_thread->get_id() : std::thread::id{} ;
}
} // end of namespace pEp::mini
} // end of namespace pEp

+ 2
- 1
server/mini-adapter-impl.hh View File

@ -33,7 +33,8 @@ namespace mini {
class Adapter : public JsonAdapter
{
public:
static Adapter& createInstance();
static Adapter& createInstance();
std::thread::id get_sync_thread_id() const override;
protected:
virtual inject_sync_event_t getInjectSyncEvent() const override


Loading…
Cancel
Save