pEp_utility.h
author Thomas
Wed, 02 May 2018 09:46:48 +0200
branchCOM-87
changeset 287 99abd7d70c1e
parent 269 26c8597fe860
child 302 b3444780fa9f
permissions -rw-r--r--
Rename flags
     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             int flags;
    20 
    21             pEp_identity_cpp(
    22                 string _address = string(),
    23                 string _fpr = string(),
    24                 string _user_id = string(),
    25                 string _username = string(),
    26                 pEpComType _comm_type = pEpCtUnknown,
    27                 string _lang = string()
    28             ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang)
    29             { }
    30 
    31             pEp_identity_cpp(const ::pEp_identity *_ident);
    32             pEp_identity_cpp(const pEpIdentity *_ident);
    33 
    34             pEp_identity * to_pEp_identity();
    35             pEpIdentity * to_pEp_identity_s();
    36         };
    37 
    38         void copy_identity(pEpIdentity * ident_s, const pEp_identity * ident);
    39         void free_identity_strings(pEpIdentity * ident_s);
    40         void clear_identity_s(pEpIdentity& ident);
    41         void clear_text_message(TextMessage *msg);
    42         ::pEp_identity *new_identity(const pEpIdentity * ident);
    43 
    44         void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
    45         void clear_opt_field_array(LPSAFEARRAY* pair_list);
    46         template< class T2, class T > SAFEARRAY * array_from_C(T *tl);
    47 
    48         static LPTYPELIB pTypelib = NULL;
    49 
    50         template< class UDType > static IRecordInfo *getRecordInfo()
    51         {
    52             LPTYPEINFO pTypeInfo = NULL;
    53             LPSAFEARRAY psaUDType = NULL;
    54             IRecordInfo* pRecInfo = NULL;
    55 
    56             // Fetch the IRecordInfo interface describing the UDT
    57             if (pTypelib == NULL)
    58                 LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
    59 
    60             assert(pTypelib);
    61 
    62             GUID guid = __uuidof(UDType);
    63             HRESULT hr = pTypelib->GetTypeInfoOfGuid(guid, &pTypeInfo);
    64             assert(SUCCEEDED(hr) && pTypeInfo);
    65             hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
    66             assert(SUCCEEDED(hr) && pRecInfo);
    67             pTypeInfo->Release();
    68 
    69             return pRecInfo;
    70         }
    71 
    72         template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
    73         {
    74             IRecordInfo *pRecInfo = getRecordInfo< UDType >();
    75             SAFEARRAYBOUND rgbounds = { cElements, 0 };
    76             LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
    77             pRecInfo->Release();
    78             assert(psaUDType);
    79 
    80             return psaUDType;
    81         }
    82 
    83         ::message * text_message_to_C(TextMessage *msg);
    84         void text_message_from_C(TextMessage *msg2, const ::message *msg);
    85     }
    86 }