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