pEp_utility.h
author Volker Birk <vb@pep-project.org>
Wed, 23 Nov 2016 20:22:17 +0100
changeset 219 03531c4d3fda
parent 217 7ebb44e5bf85
child 220 92489901bb81
permissions -rw-r--r--
switch to pEpIdentityFlags data type
     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                 string _lang = string()
    29                 ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang), me(false)
    30             { }
    31 
    32             pEp_identity_cpp(const ::pEp_identity *_ident);
    33             pEp_identity_cpp(const pEpIdentity *_ident);
    34 
    35             pEp_identity * to_pEp_identity();
    36             pEpIdentity * to_pEp_identity_s();
    37         };
    38 
    39         void copy_identity(pEpIdentity * ident_s, const pEp_identity * ident);
    40         void free_identity_strings(pEpIdentity * ident_s);
    41         void clear_identity_s(pEpIdentity& ident);
    42         void clear_text_message(TextMessage *msg);
    43         ::pEp_identity *new_identity(const pEpIdentity * ident);
    44 
    45 		void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
    46 		void clear_opt_field_array(LPSAFEARRAY* pair_list);
    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 }