pEp_utility.h
author Thomas
Tue, 04 Jun 2019 11:19:49 +0200
branchsync
changeset 347 ae275a12a133
parent 346 384c761a7cd9
permissions -rw-r--r--
COM-91: Use engine method to display error string
     1 #pragma once
     2 
     3 #include "stdafx.h"
     4 #include "pEpComServerAdapter_i.h"
     5 #include "utf8_helper.h"
     6 
     7 using namespace std;
     8 
     9 namespace pEp {
    10     namespace utility {
    11 
    12         struct pEp_identity_cpp {
    13             string address;
    14             string fpr;
    15             string user_id;
    16             string username;
    17             pEpComType comm_type;
    18             string lang;
    19 			bool me;
    20             int flags;
    21 
    22             pEp_identity_cpp(
    23                 string _address = string(),
    24                 string _fpr = string(),
    25                 string _user_id = string(),
    26                 string _username = string(),
    27                 pEpComType _comm_type = pEpCtUnknown,
    28 				bool _me = false,
    29                 string _lang = string()
    30             ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), me(_me), lang(_lang)
    31             { }
    32 
    33             pEp_identity_cpp(const ::pEp_identity *_ident);
    34             pEp_identity_cpp(const pEpIdentity *_ident);
    35 
    36             pEp_identity * to_pEp_identity();
    37             pEpIdentity * to_pEp_identity_s();
    38         };
    39 
    40         void copy_identity(pEpIdentity * ident_s, const pEp_identity * ident);
    41         void free_identity_strings(pEpIdentity * ident_s);
    42         void clear_identity_s(pEpIdentity& ident);
    43         void clear_text_message(TextMessage *msg);
    44         ::pEp_identity *new_identity(const pEpIdentity * ident);
    45 
    46         void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
    47         void clear_opt_field_array(LPSAFEARRAY* pair_list);
    48         template< class T2, class T > SAFEARRAY * array_from_C(T *tl);
    49 
    50         static LPTYPELIB pTypelib = NULL;
    51 
    52         template< class UDType > static IRecordInfo *getRecordInfo()
    53         {
    54             LPTYPEINFO pTypeInfo = NULL;
    55             LPSAFEARRAY psaUDType = NULL;
    56             IRecordInfo* pRecInfo = NULL;
    57             HRESULT hr;
    58 
    59             // Fetch the IRecordInfo interface describing the UDT
    60             if (pTypelib == NULL) {
    61                 hr = LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
    62                 assert(SUCCEEDED(hr));
    63                 if (!SUCCEEDED(hr))
    64                     throw runtime_error("getRecordInfo(): LoadRegTypeLib cannot load LIBID_pEpCOMServerAdapterLib");
    65             }
    66 
    67             assert(pTypelib);
    68 
    69             GUID guid = __uuidof(UDType);
    70             hr = pTypelib->GetTypeInfoOfGuid(guid, &pTypeInfo);
    71             assert(SUCCEEDED(hr) && pTypeInfo);
    72             hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
    73             assert(SUCCEEDED(hr) && pRecInfo);
    74             pTypeInfo->Release();
    75 
    76             return pRecInfo;
    77         }
    78 
    79         template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
    80         {
    81             IRecordInfo *pRecInfo = getRecordInfo< UDType >();
    82             SAFEARRAYBOUND rgbounds = { cElements, 0 };
    83             LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
    84             pRecInfo->Release();
    85             assert(psaUDType);
    86 
    87             return psaUDType;
    88         }
    89 
    90 		identity_list *identities(SAFEARRAY * sa);
    91         ::message * text_message_to_C(TextMessage *msg);
    92         void text_message_from_C(TextMessage *msg2, const ::message *msg);
    93     }
    94 }