to
authorVolker Birk <vb@pep-project.org>
Wed, 29 Apr 2015 01:11:07 +0200
changeset 13d83d94f11e62
parent 12 2f0ba9d79082
child 14 150074d8dc96
to
TextMessage.cpp
TextMessage.h
pEpCOMServerAdapter.idl
pEpCOMServerAdapter_i.c
pEpCOMServerAdapter_i.h
pEp_identity_helper.cpp
pEp_identity_helper.h
     1.1 --- a/TextMessage.cpp	Tue Apr 28 15:30:12 2015 +0200
     1.2 +++ b/TextMessage.cpp	Wed Apr 29 01:11:07 2015 +0200
     1.3 @@ -25,6 +25,8 @@
     1.4  
     1.5  STDMETHODIMP CTextMessage::get_from(pEp_identity_s* pVal)
     1.6  {
     1.7 +    assert(pVal);
     1.8 +
     1.9      try {
    1.10          copy_identity(pVal, msg->from);
    1.11      }
    1.12 @@ -41,6 +43,8 @@
    1.13  
    1.14  STDMETHODIMP CTextMessage::put_from(pEp_identity_s* newVal)
    1.15  {
    1.16 +    assert(newVal);
    1.17 +
    1.18      ::pEp_identity *_from;
    1.19      
    1.20      try {
    1.21 @@ -58,3 +62,94 @@
    1.22      msg->from = _from;
    1.23      return S_OK;
    1.24  }
    1.25 +
    1.26 +STDMETHODIMP CTextMessage::get_to(LPSAFEARRAY * pVal)
    1.27 +{
    1.28 +    assert(pVal);
    1.29 +
    1.30 +    int len = identity_list_length(msg->to);
    1.31 +
    1.32 +    LPSAFEARRAY sa = newSafeArray<pEp_identity_s>(len);
    1.33 +    if (sa == NULL)
    1.34 +        return E_OUTOFMEMORY;
    1.35 +
    1.36 +    pEp_identity_s *cs = accessData<pEp_identity_s>(sa);    
    1.37 +
    1.38 +    identity_list *il = msg->to;
    1.39 +    ULONG i;
    1.40 +    for (i = 0, il = msg->to; il && il->ident; il = il->next, i++) {
    1.41 +        try {
    1.42 +            copy_identity(&cs[i], il->ident);
    1.43 +        }
    1.44 +        catch (bad_alloc& e) {
    1.45 +            SafeArrayUnaccessData(sa);
    1.46 +            SafeArrayDestroy(sa);
    1.47 +            return E_OUTOFMEMORY;
    1.48 +        }
    1.49 +        catch (exception& e) {
    1.50 +            SafeArrayUnaccessData(sa);
    1.51 +            SafeArrayDestroy(sa);
    1.52 +            return E_FAIL;
    1.53 +        }
    1.54 +    }
    1.55 +
    1.56 +    SafeArrayUnaccessData(sa);
    1.57 +
    1.58 +    *pVal = sa;
    1.59 +    return S_OK;
    1.60 +}
    1.61 +
    1.62 +STDMETHODIMP CTextMessage::put_to(SAFEARRAY * newVal)
    1.63 +{
    1.64 +    assert(newVal);
    1.65 +
    1.66 +    if (newVal == NULL)
    1.67 +        return E_INVALIDARG;
    1.68 +
    1.69 +    identity_list *il = new_identity_list(NULL);
    1.70 +    if (il == NULL)
    1.71 +        return E_OUTOFMEMORY;
    1.72 +
    1.73 +    pEp_identity_s *cs;
    1.74 +    HRESULT hr = SafeArrayAccessData(newVal, (void **) &cs);
    1.75 +    assert(SUCCEEDED(hr) && cs);
    1.76 +    if (cs == NULL) {
    1.77 +        free_identity_list(il);
    1.78 +        return E_FAIL;
    1.79 +    }
    1.80 +
    1.81 +    identity_list *_il;
    1.82 +    LONG i, lbound, ubound;
    1.83 +    SafeArrayGetLBound(newVal, 1, &lbound);
    1.84 +    SafeArrayGetUBound(newVal, 1, &ubound);
    1.85 +
    1.86 +    for (i = lbound, _il = il; i <= ubound; i++) {
    1.87 +        pEp_identity * ident;
    1.88 +        try {
    1.89 +            ident = new_identity(&cs[i]);
    1.90 +        }
    1.91 +        catch (bad_alloc& e) {
    1.92 +            SafeArrayUnaccessData(newVal);
    1.93 +            free_identity_list(il);
    1.94 +            return E_OUTOFMEMORY;
    1.95 +        }
    1.96 +        catch (exception& e) {
    1.97 +            SafeArrayUnaccessData(newVal);
    1.98 +            free_identity_list(il);
    1.99 +            return E_FAIL;
   1.100 +        }
   1.101 +        _il = identity_list_add(_il, ident);
   1.102 +        if (_il == NULL) {
   1.103 +            SafeArrayUnaccessData(newVal);
   1.104 +            free_identity_list(il);
   1.105 +            return E_OUTOFMEMORY;
   1.106 +        }
   1.107 +    }
   1.108 +
   1.109 +    SafeArrayUnaccessData(newVal);
   1.110 +    
   1.111 +    free_identity_list(msg->to);
   1.112 +    msg->to = il;
   1.113 +
   1.114 +    return S_OK;
   1.115 +}
     2.1 --- a/TextMessage.h	Tue Apr 28 15:30:12 2015 +0200
     2.2 +++ b/TextMessage.h	Wed Apr 29 01:11:07 2015 +0200
     2.3 @@ -89,11 +89,11 @@
     2.4  	}
     2.5  
     2.6  public:
     2.7 +    STDMETHOD(get_from)(pEp_identity_s * pVal);
     2.8 +    STDMETHOD(put_from)(pEp_identity_s * newVal);
     2.9  
    2.10 -
    2.11 -
    2.12 -    STDMETHOD(get_from)(pEp_identity_s* pVal);
    2.13 -    STDMETHOD(put_from)(pEp_identity_s* newVal);
    2.14 +    STDMETHOD(get_to)(LPSAFEARRAY * pVal);
    2.15 +    STDMETHOD(put_to)(SAFEARRAY * newVal);
    2.16  };
    2.17  
    2.18  OBJECT_ENTRY_AUTO(__uuidof(TextMessage), CTextMessage)
     3.1 --- a/pEpCOMServerAdapter.idl	Tue Apr 28 15:30:12 2015 +0200
     3.2 +++ b/pEpCOMServerAdapter.idl	Wed Apr 29 01:11:07 2015 +0200
     3.3 @@ -95,7 +95,7 @@
     3.4          pEp_ct_pEp = 0xff
     3.5      } pEp_comm_type;
     3.6  
     3.7 -    struct pEp_identity_s {
     3.8 +    [uuid(CAAC4CFB-4EE6-4C27-81F7-E5B4E0A46816)] struct pEp_identity_s {
     3.9          BSTR address;
    3.10          BSTR fpr;
    3.11          BSTR user_id;
    3.12 @@ -132,8 +132,11 @@
    3.13  ]
    3.14  interface ITextMessage : IUnknown {
    3.15  
    3.16 -    [propget] HRESULT from([out, retval] struct pEp_identity_s* pVal);
    3.17 +    [propget] HRESULT from([out, retval] struct pEp_identity_s *pVal);
    3.18      [propput] HRESULT from([in] struct pEp_identity_s *newVal);
    3.19 +
    3.20 +    [propget] HRESULT to([out, retval] SAFEARRAY(struct pEp_identity_s) *pVal);
    3.21 +    [propput] HRESULT to([in] SAFEARRAY(struct pEp_identity_s) newVal);
    3.22  };
    3.23  
    3.24  [
     4.1 --- a/pEpCOMServerAdapter_i.c	Tue Apr 28 15:30:12 2015 +0200
     4.2 +++ b/pEpCOMServerAdapter_i.c	Wed Apr 29 01:11:07 2015 +0200
     4.3 @@ -6,7 +6,7 @@
     4.4  
     4.5  
     4.6   /* File created by MIDL compiler version 8.00.0603 */
     4.7 -/* at Tue Apr 28 15:22:51 2015
     4.8 +/* at Wed Apr 29 00:13:01 2015
     4.9   */
    4.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    4.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
     5.1 --- a/pEpCOMServerAdapter_i.h	Tue Apr 28 15:30:12 2015 +0200
     5.2 +++ b/pEpCOMServerAdapter_i.h	Wed Apr 29 01:11:07 2015 +0200
     5.3 @@ -4,7 +4,7 @@
     5.4  
     5.5  
     5.6   /* File created by MIDL compiler version 8.00.0603 */
     5.7 -/* at Tue Apr 28 15:22:51 2015
     5.8 +/* at Wed Apr 29 00:13:01 2015
     5.9   */
    5.10  /* Compiler settings for pEpCOMServerAdapter.idl:
    5.11      Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.00.0603 
    5.12 @@ -178,7 +178,7 @@
    5.13          pEp_ct_pEp	= 0xff
    5.14      } 	pEp_comm_type;
    5.15  
    5.16 -struct pEp_identity_s
    5.17 +/* [uuid] */ struct  DECLSPEC_UUID("CAAC4CFB-4EE6-4C27-81F7-E5B4E0A46816") pEp_identity_s
    5.18      {
    5.19      BSTR address;
    5.20      BSTR fpr;
    5.21 @@ -560,6 +560,12 @@
    5.22          virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_from( 
    5.23              /* [in] */ struct pEp_identity_s *newVal) = 0;
    5.24          
    5.25 +        virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_to( 
    5.26 +            /* [retval][out] */ SAFEARRAY * *pVal) = 0;
    5.27 +        
    5.28 +        virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_to( 
    5.29 +            /* [in] */ SAFEARRAY * newVal) = 0;
    5.30 +        
    5.31      };
    5.32      
    5.33      
    5.34 @@ -589,6 +595,14 @@
    5.35              ITextMessage * This,
    5.36              /* [in] */ struct pEp_identity_s *newVal);
    5.37          
    5.38 +        /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_to )( 
    5.39 +            ITextMessage * This,
    5.40 +            /* [retval][out] */ SAFEARRAY * *pVal);
    5.41 +        
    5.42 +        /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_to )( 
    5.43 +            ITextMessage * This,
    5.44 +            /* [in] */ SAFEARRAY * newVal);
    5.45 +        
    5.46          END_INTERFACE
    5.47      } ITextMessageVtbl;
    5.48  
    5.49 @@ -618,6 +632,12 @@
    5.50  #define ITextMessage_put_from(This,newVal)	\
    5.51      ( (This)->lpVtbl -> put_from(This,newVal) ) 
    5.52  
    5.53 +#define ITextMessage_get_to(This,pVal)	\
    5.54 +    ( (This)->lpVtbl -> get_to(This,pVal) ) 
    5.55 +
    5.56 +#define ITextMessage_put_to(This,newVal)	\
    5.57 +    ( (This)->lpVtbl -> put_to(This,newVal) ) 
    5.58 +
    5.59  #endif /* COBJMACROS */
    5.60  
    5.61  
     6.1 --- a/pEp_identity_helper.cpp	Tue Apr 28 15:30:12 2015 +0200
     6.2 +++ b/pEp_identity_helper.cpp	Wed Apr 29 01:11:07 2015 +0200
     6.3 @@ -158,6 +158,5 @@
     6.4  
     6.5              return _ident;
     6.6          }
     6.7 -
     6.8      }
     6.9  }
     7.1 --- a/pEp_identity_helper.h	Tue Apr 28 15:30:12 2015 +0200
     7.2 +++ b/pEp_identity_helper.h	Wed Apr 29 01:11:07 2015 +0200
     7.3 @@ -39,5 +39,45 @@
     7.4          void copy_identity(pEp_identity_s * ident_s, const pEp_identity * ident);
     7.5          ::pEp_identity *new_identity(const pEp_identity_s * ident);
     7.6  
     7.7 +        template< class UDType > static IRecordInfo *getRecordInfo()
     7.8 +        {
     7.9 +            LPTYPEINFO pTypeInfo = NULL;
    7.10 +            LPTYPELIB pTypelib = NULL;
    7.11 +            LPSAFEARRAY psaUDType = NULL;
    7.12 +            IRecordInfo* pRecInfo = NULL;
    7.13 +
    7.14 +            // Fetch the IRecordInfo interface describing the UDT
    7.15 +            HRESULT hr = LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
    7.16 +            assert(SUCCEEDED(hr) && pTypelib);
    7.17 +
    7.18 +            hr = pTypelib->GetTypeInfoOfGuid(__uuidof(UDType), &pTypeInfo);
    7.19 +            assert(SUCCEEDED(hr) && pTypeInfo);
    7.20 +            hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
    7.21 +            assert(SUCCEEDED(hr) && pRecInfo);
    7.22 +            pTypeInfo->Release();
    7.23 +            pTypelib->Release();
    7.24 +
    7.25 +            return pRecInfo;
    7.26 +        }
    7.27 +
    7.28 +        template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
    7.29 +        {
    7.30 +            IRecordInfo *pRecInfo = getRecordInfo< UDType >();
    7.31 +            SAFEARRAYBOUND rgbounds = { cElements, 0 };
    7.32 +            LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
    7.33 +            pRecInfo->Release();
    7.34 +            assert(psaUDType);
    7.35 +
    7.36 +            return psaUDType;
    7.37 +        }
    7.38 +
    7.39 +        template< class UDType > UDType * accessData(LPSAFEARRAY psaUDType)
    7.40 +        {
    7.41 +            UDType *pUDTypeStruct = NULL;
    7.42 +            HRESULT hr = SafeArrayAccessData(psaUDType, reinterpret_cast<PVOID*>(&pUDTypeStruct));
    7.43 +            assert(SUCCEEDED(hr) && pUDTypeStruct);
    7.44 +
    7.45 +            return pUDTypeStruct;
    7.46 +        }
    7.47      }
    7.48  }