CpEpEngine.h
author Volker Birk <vb@pep-project.org>
Tue, 05 May 2015 10:27:36 +0200
changeset 18 79c848166413
parent 17 3288634317bb
child 19 3cfb847e13cd
permissions -rw-r--r--
renaming, adding keylist param
vb@0
     1
// CpEpEngine.h : Declaration of the CpEpEngine
vb@0
     2
vb@0
     3
#pragma once
vb@0
     4
#include "resource.h"       // main symbols
vb@0
     5
vb@0
     6
vb@0
     7
vb@0
     8
#include "pEpComServerAdapter_i.h"
vb@0
     9
#include "_IpEpEngineEvents_CP.h"
vb@0
    10
#include "locked_queue.hh"
vb@0
    11
#include "utf8_helper.h"
vb@9
    12
#include "pEp_identity_helper.h"
vb@0
    13
vb@0
    14
vb@0
    15
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
vb@0
    16
#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."
vb@0
    17
#endif
vb@0
    18
vb@0
    19
using namespace ATL;
vb@0
    20
using namespace utility;
vb@10
    21
using namespace pEp::utility;
vb@0
    22
vb@0
    23
// CpEpEngine
vb@0
    24
vb@0
    25
class ATL_NO_VTABLE CpEpEngine :
vb@3
    26
    public CComObjectRootEx<CComObjectThreadModel>,
vb@0
    27
	public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
vb@0
    28
	public ISupportErrorInfo,
vb@0
    29
	public IConnectionPointContainerImpl<CpEpEngine>,
vb@0
    30
	public CProxy_IpEpEngineEvents<CpEpEngine>,
vb@15
    31
	public IpEpEngine
vb@0
    32
{
vb@0
    33
public:
vb@0
    34
	CpEpEngine()
vb@0
    35
	{
vb@0
    36
        PEP_STATUS status = ::init(&m_session);
vb@0
    37
        assert(status == PEP_STATUS_OK);
vb@0
    38
        ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
vb@0
    39
        identity_queue = new identity_queue_t();
vb@0
    40
        keymanagement_thread = new thread(::do_keymanagement, retrieve_next_identity, (void *) identity_queue);
vb@0
    41
        keymanagement_thread->detach();
vb@0
    42
    }
vb@0
    43
    ~CpEpEngine()
vb@0
    44
    {
vb@0
    45
        pEp_identity_cpp shutdown;
vb@0
    46
        identity_queue->push_front(shutdown);
vb@0
    47
        ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
vb@0
    48
        ::release(m_session);
vb@0
    49
    }
vb@0
    50
vb@0
    51
DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
vb@0
    52
vb@0
    53
DECLARE_NOT_AGGREGATABLE(CpEpEngine)
vb@0
    54
vb@0
    55
BEGIN_COM_MAP(CpEpEngine)
vb@5
    56
    COM_INTERFACE_ENTRY(IpEpEngine)
vb@5
    57
    COM_INTERFACE_ENTRY(ISupportErrorInfo)
vb@5
    58
    COM_INTERFACE_ENTRY(IConnectionPointContainer)
vb@0
    59
END_COM_MAP()
vb@0
    60
vb@0
    61
BEGIN_CONNECTION_POINT_MAP(CpEpEngine)
vb@0
    62
	CONNECTION_POINT_ENTRY(__uuidof(_IpEpEngineEvents))
vb@0
    63
END_CONNECTION_POINT_MAP()
vb@0
    64
// ISupportsErrorInfo
vb@0
    65
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
vb@0
    66
vb@0
    67
vb@0
    68
	DECLARE_PROTECT_FINAL_CONSTRUCT()
vb@0
    69
vb@0
    70
	HRESULT FinalConstruct()
vb@0
    71
	{
vb@0
    72
		return S_OK;
vb@0
    73
	}
vb@0
    74
vb@0
    75
	void FinalRelease()
vb@0
    76
	{
vb@0
    77
	}
vb@0
    78
vb@0
    79
vb@0
    80
protected:
vb@0
    81
    class session
vb@0
    82
    {
vb@0
    83
    private:
vb@0
    84
        CpEpEngine *me;
vb@0
    85
vb@0
    86
    public:
vb@0
    87
        session(CpEpEngine *myself)
vb@0
    88
        {
vb@0
    89
            me = myself;
vb@0
    90
            me->session_mutex.lock();
vb@0
    91
        }
vb@0
    92
vb@0
    93
        ~session()
vb@0
    94
        {
vb@0
    95
            me->session_mutex.unlock();
vb@0
    96
        }
vb@0
    97
vb@0
    98
        operator PEP_SESSION const () 
vb@0
    99
        {
vb@0
   100
            return me->m_session;
vb@0
   101
        }
vb@0
   102
    };
vb@0
   103
vb@0
   104
    session get_session()
vb@0
   105
    {
vb@0
   106
        return session(this);
vb@0
   107
    }
vb@0
   108
vb@0
   109
    typedef locked_queue<pEp_identity_cpp> identity_queue_t;
vb@0
   110
    static ::pEp_identity * retrieve_next_identity(void *management);
vb@0
   111
    HRESULT error(_bstr_t msg);
vb@0
   112
vb@0
   113
private:
vb@0
   114
    PEP_SESSION m_session;
vb@0
   115
    mutex session_mutex;
vb@0
   116
    identity_queue_t *identity_queue;
vb@0
   117
    thread *keymanagement_thread;
vb@0
   118
vb@0
   119
public:
vb@0
   120
    STDMETHOD(log)(BSTR title, BSTR entity, BSTR description, BSTR comment);
vb@0
   121
    STDMETHOD(decrypt)(BSTR ctext, BSTR * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
vb@0
   122
    STDMETHOD(decrypt_b)(BSTR ctext, LPSAFEARRAY * ptext, LPSAFEARRAY * key_list, pEp_STATUS * decrypt_status);
vb@0
   123
    STDMETHOD(encrypt)(SAFEARRAY * key_list, BSTR ptext, BSTR * ctext, pEp_STATUS * status);
vb@0
   124
    STDMETHOD(encrypt_b)(SAFEARRAY * key_list, SAFEARRAY * ptext, BSTR * ctext, pEp_STATUS * status);
vb@17
   125
    STDMETHOD(trustword)(LONG value, BSTR lang, BSTR * word);
vb@17
   126
    STDMETHOD(trustwords)(BSTR fpr, BSTR lang, LONG max_words, BSTR * words);
vb@0
   127
    STDMETHOD(get_identity)(BSTR address, pEp_identity_s * ident);
vb@0
   128
    STDMETHOD(set_identity)(pEp_identity_s * ident);
vb@0
   129
    STDMETHOD(generate_keypair)(pEp_identity_s * ident, BSTR * fpr);
vb@0
   130
    STDMETHOD(delete_keypair)(BSTR fpr);
vb@0
   131
    STDMETHOD(import_key)(BSTR key_data);
vb@0
   132
    STDMETHOD(import_key_b)(SAFEARRAY * key_data);
vb@0
   133
    STDMETHOD(export_key)(BSTR fpr, BSTR * key_data);
vb@0
   134
    STDMETHOD(recv_key)(BSTR pattern);
vb@0
   135
    STDMETHOD(find_keys)(BSTR pattern, LPSAFEARRAY * key_list);
vb@0
   136
    STDMETHOD(send_key)(BSTR pattern);
vb@11
   137
vb@11
   138
    // keymanagement API
vb@11
   139
vb@0
   140
    STDMETHOD(examine_identity)(pEp_identity_s * ident);
vb@0
   141
    STDMETHOD(examine_myself)(pEp_identity_s * myself);
vb@0
   142
    STDMETHOD(verify)(BSTR text, BSTR signature, LPSAFEARRAY * key_list, pEp_STATUS * verify_status);
vb@0
   143
    STDMETHOD(myself)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@0
   144
    STDMETHOD(update_identity)(struct pEp_identity_s *ident, struct pEp_identity_s *result);
vb@4
   145
    STDMETHOD(key_compromized)(BSTR fpr);
vb@12
   146
    
vb@12
   147
    // Message API
vb@12
   148
vb@18
   149
    STDMETHOD(encrypt_message)(ITextMessage * src, ITextMessage ** dst, SAFEARRAY * extra);
vb@18
   150
    STDMETHOD(decrypt_message)(ITextMessage * src, ITextMessage ** dst, SAFEARRAY ** keylist);
vb@15
   151
    STDMETHOD(message_color)(ITextMessage *msg, pEp_color * pVal);
vb@18
   152
    STDMETHOD(identity_color)(pEp_identity_s * ident, pEp_color * pVal);
vb@18
   153
vb@0
   154
};
vb@0
   155
vb@0
   156
OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)