CpEpEngine.h
branchsync
changeset 295 f55ec2fd694f
parent 294 b2fe2bac2db0
child 296 43d9e57b6561
     1.1 --- a/CpEpEngine.h	Fri Oct 05 14:32:36 2018 +0200
     1.2 +++ b/CpEpEngine.h	Mon Oct 15 22:15:24 2018 +0200
     1.3 @@ -4,11 +4,13 @@
     1.4  #include "resource.h"       // main symbols
     1.5  
     1.6  #include "pEpComServerAdapter_i.h"
     1.7 -#include "locked_queue.hh"
     1.8 +#include "..\libpEpAdapter\locked_queue.hh"
     1.9  #include "utf8_helper.h"
    1.10  #include "pEp_utility.h"
    1.11 +#include "..\libpEpAdapter\Adapter.hh"
    1.12  #include <queue>
    1.13  #include <mutex>
    1.14 +#include <vector>
    1.15  
    1.16  #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
    1.17  #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
    1.18 @@ -17,6 +19,7 @@
    1.19  using namespace ATL;
    1.20  using namespace utility;
    1.21  using namespace pEp::utility;
    1.22 +using namespace pEp::Adapter;
    1.23  
    1.24  // CpEpEngine
    1.25  
    1.26 @@ -40,12 +43,8 @@
    1.27      ~CpEpEngine()
    1.28      {
    1.29          StopKeyserverLookup();
    1.30 -        if (m_session) // may be zero when FinalConstruct failed to initialize the engine
    1.31 -        {
    1.32 -            ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
    1.33 -            std::lock_guard<std::mutex> lock(init_mutex);
    1.34 -            ::release(m_session);
    1.35 -        }
    1.36 +        ::log_event(session(), "Shutdown", "pEp COM Adapter", NULL, NULL);
    1.37 +        session(pEp::Adapter::release);
    1.38      }
    1.39  
    1.40      DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
    1.41 @@ -71,15 +70,16 @@
    1.42      HRESULT FinalConstruct()
    1.43      {
    1.44          std::lock_guard<std::mutex> lock(init_mutex);
    1.45 -        PEP_STATUS status = ::init(&m_session);
    1.46 -        assert(status == PEP_STATUS_OK);
    1.47 -        if (status != PEP_STATUS_OK) {
    1.48 -            HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & status));
    1.49 +        try {
    1.50 +            session();
    1.51 +        }
    1.52 +        catch (pEp::RuntimeError& e) {
    1.53 +            HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & e.status));
    1.54              return res;
    1.55          }
    1.56  
    1.57 -        ::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
    1.58 -        ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
    1.59 +        ::register_examine_function(session(), CpEpEngine::examine_identity, (void *)this);
    1.60 +        ::log_event(session(), "Startup", "pEp COM Adapter", NULL, NULL);
    1.61          return S_OK;
    1.62      }
    1.63  
    1.64 @@ -89,39 +89,10 @@
    1.65  
    1.66  
    1.67  protected:
    1.68 -    class session
    1.69 -    {
    1.70 -    private:
    1.71 -        CpEpEngine *me;
    1.72 -
    1.73 -    public:
    1.74 -        session(CpEpEngine *myself)
    1.75 -        {
    1.76 -            me = myself;
    1.77 -            me->session_mutex.lock();
    1.78 -        }
    1.79 -
    1.80 -        ~session()
    1.81 -        {
    1.82 -            me->session_mutex.unlock();
    1.83 -        }
    1.84 -
    1.85 -        operator PEP_SESSION const ()
    1.86 -        {
    1.87 -            return me->m_session;
    1.88 -        }
    1.89 -    };
    1.90 -
    1.91 -    session get_session()
    1.92 -    {
    1.93 -        return session(this);
    1.94 -    }
    1.95 -
    1.96      typedef locked_queue<pEp_identity_cpp> identity_queue_t;
    1.97      static ::pEp_identity * retrieve_next_identity(void *management);
    1.98 -    static PEP_STATUS messageToSend(void * obj, message *msg);
    1.99 -    static PEP_STATUS notifyHandshake(void * obj, pEp_identity *self, pEp_identity *partner, sync_handshake_signal signal);
   1.100 -
   1.101 +    static PEP_STATUS messageToSend(message *msg);
   1.102 +    static PEP_STATUS notifyHandshake(pEp_identity *self, pEp_identity *partner, sync_handshake_signal signal);
   1.103  
   1.104      HRESULT error(_bstr_t msg);
   1.105      HRESULT error(_bstr_t msg, PEP_STATUS errorcode);
   1.106 @@ -131,43 +102,22 @@
   1.107          if (verbose_mode) {
   1.108              stringstream ss;
   1.109              ss << __FILE__ << ":" << __LINE__ << " " << text;
   1.110 -            ::log_event(get_session(), "verbose", "pEp COM Server Adapter", ss.str().c_str(), NULL);
   1.111 +            ::log_event(session(), "verbose", "pEp COM Server Adapter", ss.str().c_str(), NULL);
   1.112          }
   1.113      }
   1.114  
   1.115  private:
   1.116 -    PEP_SESSION m_session;
   1.117 -    mutex session_mutex;
   1.118      atomic< identity_queue_t * > identity_queue;
   1.119      thread *keymanagement_thread;
   1.120      bool verbose_mode;
   1.121  
   1.122 -
   1.123      IpEpEngineCallbacks* client_callbacks = NULL;
   1.124 -    IpEpEngineCallbacks* client_callbacks_on_sync_thread = NULL;
   1.125      bool client_last_signalled_polling_state = true;
   1.126  
   1.127      static std::mutex init_mutex;
   1.128  
   1.129 -    std::recursive_mutex keysync_mutex;
   1.130 -    std::condition_variable_any keysync_condition;
   1.131 -    std::thread *keysync_thread = NULL;
   1.132 -    std::queue<void*> keysync_queue;
   1.133 -    bool keysync_abort_requested = false;
   1.134 -    PEP_SESSION keysync_session;
   1.135 -
   1.136 -    // Members used for handshake notification dispatch to the background thread.
   1.137 -    static void notify_handshake_background_thread(CpEpEngine* self, LPSTREAM marshaled_callbacks);
   1.138 -    void notify_handshake_deliver_result();
   1.139 -    bool notify_handshake_active = false;
   1.140 -    bool notify_handshake_finished = false;
   1.141 -    std::thread *notify_handshake_thread = NULL;
   1.142 -    pEpIdentity notify_handshake_self;
   1.143 -    pEpIdentity notify_handshake_partner;
   1.144 -    SyncHandshakeSignal notify_handshake_signal;
   1.145 -    SyncHandshakeResult notify_handshake_result;
   1.146 -    LPSTREAM notify_handshake_error_info = NULL;
   1.147 -    HRESULT notify_handshake_error;
   1.148 +    static std::list< IpEpEngineCallbacks * > all_callbacks;
   1.149 +    static std::mutex callbacks_mutex;
   1.150  
   1.151  public:
   1.152      // runtime config of the adapter
   1.153 @@ -210,9 +160,9 @@
   1.154      STDMETHOD(TrustPersonalKey)(struct pEpIdentity *ident, struct pEpIdentity *result);
   1.155      STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
   1.156  
   1.157 -    STDMETHOD(UndoLastMistrust)(); 
   1.158 +    // STDMETHOD(UndoLastMistrust)(); 
   1.159      
   1.160 -    STDMETHOD(IsPepUser)(
   1.161 +    STDMETHOD(IspEpUser)(
   1.162          /* [in] */ struct pEpIdentity *ident,
   1.163          /* [retval][out] */ VARIANT_BOOL *ispEp);
   1.164  
   1.165 @@ -265,9 +215,6 @@
   1.166  
   1.167      // Trigger an immediate update
   1.168      STDMETHOD(UpdateNow)();
   1.169 -protected:
   1.170 -    HRESULT Fire_MessageToSend(
   1.171 -        /* [in] */ struct TextMessage *msg);
   1.172  };
   1.173  
   1.174  OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)