CpEpEngine.h
changeset 269 26c8597fe860
parent 268 4d41410af9a0
child 273 30be98685afa
     1.1 --- a/CpEpEngine.h	Thu Feb 01 23:30:55 2018 +0100
     1.2 +++ b/CpEpEngine.h	Fri Feb 02 22:03:16 2018 +0100
     1.3 @@ -22,9 +22,9 @@
     1.4  
     1.5  class ATL_NO_VTABLE CpEpEngine :
     1.6      public CComObjectRootEx<CComObjectThreadModel>,
     1.7 -	public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
     1.8 -	public ISupportErrorInfo,
     1.9 -	public IpEpEngine2
    1.10 +    public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
    1.11 +    public ISupportErrorInfo,
    1.12 +    public IpEpEngine2
    1.13  {
    1.14  
    1.15  protected:
    1.16 @@ -32,62 +32,62 @@
    1.17  
    1.18  public:
    1.19      CpEpEngine() : keymanagement_thread(NULL), identity_queue(NULL), verbose_mode(false)
    1.20 -	{
    1.21 -		// See FinalConstruct() below for most initialization work, and an
    1.22 -		// explanation why it had to be moved there...
    1.23 -    }	
    1.24 +    {
    1.25 +        // See FinalConstruct() below for most initialization work, and an
    1.26 +        // explanation why it had to be moved there...
    1.27 +    }
    1.28  
    1.29      ~CpEpEngine()
    1.30      {
    1.31          stop_keysync();
    1.32          StopKeyserverLookup();
    1.33 -		if (m_session) // may be zero when FinalConstruct failed to initialize the engine
    1.34 -		{
    1.35 -			::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
    1.36 -			std::lock_guard<std::mutex> lock(init_mutex);
    1.37 -			::release(m_session);
    1.38 -		}
    1.39 +        if (m_session) // may be zero when FinalConstruct failed to initialize the engine
    1.40 +        {
    1.41 +            ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
    1.42 +            std::lock_guard<std::mutex> lock(init_mutex);
    1.43 +            ::release(m_session);
    1.44 +        }
    1.45      }
    1.46  
    1.47 -DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
    1.48 +    DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
    1.49  
    1.50 -DECLARE_NOT_AGGREGATABLE(CpEpEngine)
    1.51 +    DECLARE_NOT_AGGREGATABLE(CpEpEngine)
    1.52  
    1.53 -BEGIN_COM_MAP(CpEpEngine)
    1.54 -    COM_INTERFACE_ENTRY(IpEpEngine)
    1.55 -    COM_INTERFACE_ENTRY(IpEpEngine2)
    1.56 -    COM_INTERFACE_ENTRY(ISupportErrorInfo)
    1.57 -END_COM_MAP()
    1.58 +    BEGIN_COM_MAP(CpEpEngine)
    1.59 +        COM_INTERFACE_ENTRY(IpEpEngine)
    1.60 +        COM_INTERFACE_ENTRY(IpEpEngine2)
    1.61 +        COM_INTERFACE_ENTRY(ISupportErrorInfo)
    1.62 +    END_COM_MAP()
    1.63  
    1.64 -// ISupportsErrorInfo
    1.65 -	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    1.66 +    // ISupportsErrorInfo
    1.67 +    STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    1.68  
    1.69 -	DECLARE_PROTECT_FINAL_CONSTRUCT()
    1.70 +    DECLARE_PROTECT_FINAL_CONSTRUCT()
    1.71  
    1.72 -	// Unfortunately, neither FAIL nor error() work in the constructor, as 
    1.73 -	// CreateErrorInfo/SetErrorInfo cannot work when the instance is not constructed.
    1.74 -	// AtlThrow works, but the exception is caught in CComCreator.CreateInstance, and
    1.75 -	// unconditionally turned into E_OUTOFMEMORY. Thus, we need to do most constructor
    1.76 -	// work in FinalConstruct. CreateErrorInfo/SetErrorInfo still won't work, but at least,
    1.77 -	// we can return a meaningful HRESULT. Thus, we pack our PEP_STATUS into a custom HRESULT.	
    1.78 -	HRESULT FinalConstruct()
    1.79 -	{
    1.80 -		std::lock_guard<std::mutex> lock(init_mutex);
    1.81 -		PEP_STATUS status = ::init(&m_session);
    1.82 -		assert(status == PEP_STATUS_OK);
    1.83 -		if (status != PEP_STATUS_OK) {
    1.84 -			HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & status));
    1.85 -			return res;
    1.86 -		}
    1.87 +    // Unfortunately, neither FAIL nor error() work in the constructor, as 
    1.88 +    // CreateErrorInfo/SetErrorInfo cannot work when the instance is not constructed.
    1.89 +    // AtlThrow works, but the exception is caught in CComCreator.CreateInstance, and
    1.90 +    // unconditionally turned into E_OUTOFMEMORY. Thus, we need to do most constructor
    1.91 +    // work in FinalConstruct. CreateErrorInfo/SetErrorInfo still won't work, but at least,
    1.92 +    // we can return a meaningful HRESULT. Thus, we pack our PEP_STATUS into a custom HRESULT.	
    1.93 +    HRESULT FinalConstruct()
    1.94 +    {
    1.95 +        std::lock_guard<std::mutex> lock(init_mutex);
    1.96 +        PEP_STATUS status = ::init(&m_session);
    1.97 +        assert(status == PEP_STATUS_OK);
    1.98 +        if (status != PEP_STATUS_OK) {
    1.99 +            HRESULT res = MAKE_HRESULT(1, FACILITY_ITF, (0xFFFF & status));
   1.100 +            return res;
   1.101 +        }
   1.102  
   1.103 -		::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
   1.104 -		::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
   1.105 -		return S_OK;
   1.106 -	}
   1.107 +        ::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
   1.108 +        ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
   1.109 +        return S_OK;
   1.110 +    }
   1.111  
   1.112 -	void FinalRelease()
   1.113 -	{
   1.114 -	}
   1.115 +    void FinalRelease()
   1.116 +    {
   1.117 +    }
   1.118  
   1.119  
   1.120  protected:
   1.121 @@ -145,19 +145,19 @@
   1.122      bool verbose_mode;
   1.123  
   1.124  
   1.125 -	IpEpEngineCallbacks* client_callbacks = NULL;
   1.126 +    IpEpEngineCallbacks* client_callbacks = NULL;
   1.127      IpEpEngineCallbacks* client_callbacks_on_sync_thread = NULL;
   1.128      IpEpEngineCallbacks2* client_callbacks2_on_sync_thread = NULL;
   1.129      bool client_last_signalled_polling_state = true;
   1.130  
   1.131 -	// Keysync members
   1.132 +    // Keysync members
   1.133      static int inject_sync_msg(void *msg, void* management);
   1.134      static void* retrieve_next_sync_msg(void* management, time_t *timeout);
   1.135      void start_keysync();
   1.136      static void do_keysync_in_thread(CpEpEngine* self, LPSTREAM marshaled_callbacks);
   1.137      void stop_keysync();
   1.138  
   1.139 -	static std::mutex init_mutex;
   1.140 +    static std::mutex init_mutex;
   1.141  
   1.142      std::recursive_mutex keysync_mutex;
   1.143      std::condition_variable_any keysync_condition;
   1.144 @@ -205,8 +205,8 @@
   1.145      STDMETHOD(GetCrashdumpLog)(LONG maxlines, BSTR * log);
   1.146      STDMETHOD(GetEngineVersion)(BSTR * engineVersion);
   1.147      STDMETHOD(GetLanguageList)(BSTR * languages);
   1.148 -	STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   1.149 -	STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   1.150 +    STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   1.151 +    STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   1.152  
   1.153      // keymanagement API
   1.154  
   1.155 @@ -218,7 +218,7 @@
   1.156      STDMETHOD(KeyMistrusted)(struct pEpIdentity *ident);
   1.157      STDMETHOD(KeyResetTrust)(struct pEpIdentity *ident);
   1.158      STDMETHOD(TrustPersonalKey)(struct pEpIdentity *ident, struct pEpIdentity *result);
   1.159 -	STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
   1.160 +    STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
   1.161  
   1.162      // Blacklist API
   1.163  
   1.164 @@ -234,28 +234,28 @@
   1.165      STDMETHOD(ReEvaluateMessageRating)(TextMessage * msg, SAFEARRAY * x_KeyList, pEpRating x_EncStatus, pEpRating *rating);
   1.166      STDMETHOD(OutgoingMessageRating)(TextMessage *msg, pEpRating * pVal);
   1.167      STDMETHOD(IdentityRating)(pEpIdentity * ident, pEpRating * pVal);
   1.168 -	STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
   1.169 +    STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
   1.170  
   1.171      STDMETHOD(EncryptMessageForSelf)(
   1.172 -        pEpIdentity * targetId, 
   1.173 +        pEpIdentity * targetId,
   1.174          TextMessage* src,
   1.175          TextMessage *dst,
   1.176          pEpEncryptFlags flags
   1.177          );
   1.178  
   1.179 -	// Event callbacks
   1.180 +    // Event callbacks
   1.181  
   1.182 -	STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
   1.183 -	STDMETHOD(UnregisterCallbacks)();
   1.184 +    STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
   1.185 +    STDMETHOD(UnregisterCallbacks)();
   1.186  
   1.187      // PGP compatibility functions
   1.188      STDMETHOD(OpenPGPListKeyinfo)(BSTR search_pattern, LPSAFEARRAY* keyinfo_list);
   1.189  
   1.190 -	STDMETHOD(UndoLastMistrust)();
   1.191 +    STDMETHOD(UndoLastMistrust)();
   1.192  
   1.193  protected:
   1.194 -	HRESULT Fire_MessageToSend(
   1.195 -		/* [in] */ struct TextMessage *msg);
   1.196 +    HRESULT Fire_MessageToSend(
   1.197 +        /* [in] */ struct TextMessage *msg);
   1.198  };
   1.199  
   1.200  OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)