Changeset 54027 in vbox
- Timestamp:
- Jan 29, 2015 3:23:36 PM (10 years ago)
- Location:
- trunk/src/VBox/Main/cbinding
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/cbinding/VBoxCAPI.cpp
r50930 r54027 5 5 6 6 /* 7 * Copyright (C) 2009-201 4Oracle Corporation7 * Copyright (C) 2009-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 83 83 return vrc; 84 84 #endif /* !VBOX_WITH_XPCOM */ 85 } 86 87 static void 88 VBoxUtf8Clear(char *pszString) 89 { 90 RT_BZERO(pszString, strlen(pszString)); 91 } 92 93 static void 94 VBoxUtf16Clear(BSTR pwszString) 95 { 96 RT_BZERO(pwszString, RTUtf16Len(pwszString) * sizeof(RTUTF16)); 85 97 } 86 98 … … 760 772 VBoxInterruptEventQueueProcessing, 761 773 774 VBoxUtf8Clear, 775 VBoxUtf16Clear, 776 762 777 VBOX_CAPI_VERSION 763 778 }; … … 767 782 768 783 /* 769 * Legacy interface version 4.0.784 * Legacy interface version 3.0. 770 785 */ 771 static const struct VBOXCAPIV 4786 static const struct VBOXCAPIV3 772 787 { 773 788 /** The size of the structure. */ … … 777 792 778 793 unsigned int (*pfnGetVersion)(void); 794 779 795 unsigned int (*pfnGetAPIVersion)(void); 780 796 781 797 HRESULT (*pfnClientInitialize)(const char *pszVirtualBoxClientIID, 782 798 IVirtualBoxClient **ppVirtualBoxClient); 783 HRESULT (*pfnClientThreadInitialize)(void);784 HRESULT (*pfnClientThreadUninitialize)(void);785 799 void (*pfnClientUninitialize)(void); 786 800 787 void (*pfnComInitialize)(const char *pszVirtualBoxIID, 788 IVirtualBox **ppVirtualBox, 789 const char *pszSessionIID, 790 ISession **ppSession); 791 792 void (*pfnComUninitialize)(void); 793 794 void (*pfnComUnallocString)(BSTR pwsz); 795 796 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); 797 int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString); 798 void (*pfnUtf8Free)(char *pszString); 799 void (*pfnUtf16Free)(BSTR pwszString); 800 801 SAFEARRAY *(*pfnSafeArrayCreateVector)(VARTYPE vt, LONG lLbound, ULONG cElements); 802 SAFEARRAY *(*pfnSafeArrayOutParamAlloc)(void); 803 HRESULT (*pfnSafeArrayCopyInParamHelper)(SAFEARRAY *psa, const void *pv, ULONG cb); 804 HRESULT (*pfnSafeArrayCopyOutParamHelper)(void **ppv, ULONG *pcb, VARTYPE vt, SAFEARRAY *psa); 805 HRESULT (*pfnSafeArrayCopyOutIfaceParamHelper)(IUnknown ***ppaObj, ULONG *pcObj, SAFEARRAY *psa); 806 HRESULT (*pfnSafeArrayDestroy)(SAFEARRAY *psa); 807 808 #ifdef VBOX_WITH_XPCOM 809 void (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue); 801 void (*pfnComInitialize)(const char *pszVirtualBoxIID, 802 IVirtualBox **ppVirtualBox, 803 const char *pszSessionIID, 804 ISession **ppSession); 805 806 void (*pfnComUninitialize)(void); 807 808 void (*pfnComUnallocMem)(void *pv); 809 810 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); 811 int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString); 812 void (*pfnUtf8Free)(char *pszString); 813 void (*pfnUtf16Free)(BSTR pwszString); 814 815 #ifdef VBOX_WITH_XPCOM 816 void (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue); 810 817 #endif /* VBOX_WITH_XPCOM */ 811 818 HRESULT (*pfnGetException)(IErrorInfo **ppException); 812 819 HRESULT (*pfnClearException)(void); 813 int (*pfnProcessEventQueue)(LONG64 iTimeoutMS);814 int (*pfnInterruptEventQueueProcessing)(void);815 820 816 821 /** Tail version, same as uVersion. */ 817 822 unsigned uEndVersion; 818 } s_Functions_v 4_0 =819 { 820 sizeof(s_Functions_v 4_0),821 0x000 40000U,823 } s_Functions_v3_0 = 824 { 825 sizeof(s_Functions_v3_0), 826 0x00030000U, 822 827 823 828 VBoxVersion, … … 825 830 826 831 VBoxClientInitialize, 827 VBoxClientThreadInitialize,828 VBoxClientThreadUninitialize,829 832 VBoxClientUninitialize, 830 833 … … 832 835 VBoxComUninitialize, 833 836 834 VBoxComUnalloc String,837 VBoxComUnallocMem, 835 838 836 839 VBoxUtf16ToUtf8, … … 839 842 VBoxUtf16Free, 840 843 841 VBoxSafeArrayCreateVector,842 VBoxSafeArrayOutParamAlloc,843 VBoxSafeArrayCopyInParamHelper,844 VBoxSafeArrayCopyOutParamHelper,845 VBoxSafeArrayCopyOutIfaceParamHelper,846 VBoxSafeArrayDestroy,847 848 844 #ifdef VBOX_WITH_XPCOM 849 845 VBoxGetEventQueue, … … 851 847 VBoxGetException, 852 848 VBoxClearException, 853 VBoxProcessEventQueue, 854 VBoxInterruptEventQueueProcessing, 855 856 0x00040000U 849 850 0x00030000U 857 851 }; 858 852 859 if ((uVersion & 0xffff0000U) == 0x000 40000U)860 return (PCVBOXCAPI)&s_Functions_v 4_0;853 if ((uVersion & 0xffff0000U) == 0x00030000U) 854 return (PCVBOXCAPI)&s_Functions_v3_0; 861 855 862 856 /* 863 * Legacy interface version 3.0.857 * Legacy interface version 2.0. 864 858 */ 865 static const struct VBOXCAPIV 3859 static const struct VBOXCAPIV2 866 860 { 867 861 /** The size of the structure. */ … … 872 866 unsigned int (*pfnGetVersion)(void); 873 867 874 unsigned int (*pfnGetAPIVersion)(void); 875 876 HRESULT (*pfnClientInitialize)(const char *pszVirtualBoxClientIID, 877 IVirtualBoxClient **ppVirtualBoxClient); 878 void (*pfnClientUninitialize)(void); 879 880 void (*pfnComInitialize)(const char *pszVirtualBoxIID, 881 IVirtualBox **ppVirtualBox, 882 const char *pszSessionIID, 883 ISession **ppSession); 884 885 void (*pfnComUninitialize)(void); 886 887 void (*pfnComUnallocMem)(void *pv); 888 889 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); 890 int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString); 891 void (*pfnUtf8Free)(char *pszString); 892 void (*pfnUtf16Free)(BSTR pwszString); 893 894 #ifdef VBOX_WITH_XPCOM 895 void (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue); 896 #endif /* VBOX_WITH_XPCOM */ 897 HRESULT (*pfnGetException)(IErrorInfo **ppException); 898 HRESULT (*pfnClearException)(void); 868 void (*pfnComInitialize)(const char *pszVirtualBoxIID, 869 IVirtualBox **ppVirtualBox, 870 const char *pszSessionIID, 871 ISession **ppSession); 872 873 void (*pfnComUninitialize)(void); 874 875 void (*pfnComUnallocMem)(void *pv); 876 void (*pfnUtf16Free)(BSTR pwszString); 877 void (*pfnUtf8Free)(char *pszString); 878 879 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); 880 int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString); 881 882 #ifdef VBOX_WITH_XPCOM 883 void (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue); 884 #endif /* VBOX_WITH_XPCOM */ 899 885 900 886 /** Tail version, same as uVersion. */ 901 887 unsigned uEndVersion; 902 } s_Functions_v 3_0 =903 { 904 sizeof(s_Functions_v 3_0),905 0x000 30000U,888 } s_Functions_v2_0 = 889 { 890 sizeof(s_Functions_v2_0), 891 0x00020000U, 906 892 907 893 VBoxVersion, 908 VBoxAPIVersion,909 910 VBoxClientInitialize,911 VBoxClientUninitialize,912 894 913 895 VBoxComInitialize, … … 915 897 916 898 VBoxComUnallocMem, 899 VBoxUtf16Free, 900 VBoxUtf8Free, 917 901 918 902 VBoxUtf16ToUtf8, 919 903 VBoxUtf8ToUtf16, 920 VBoxUtf8Free,921 VBoxUtf16Free,922 904 923 905 #ifdef VBOX_WITH_XPCOM 924 906 VBoxGetEventQueue, 925 907 #endif /* VBOX_WITH_XPCOM */ 926 VBoxGetException, 927 VBoxClearException, 928 929 0x00030000U 908 909 0x00020000U 930 910 }; 931 911 932 if ((uVersion & 0xffff0000U) == 0x000 30000U)933 return (PCVBOXCAPI)&s_Functions_v 3_0;912 if ((uVersion & 0xffff0000U) == 0x00020000U) 913 return (PCVBOXCAPI)&s_Functions_v2_0; 934 914 935 915 /* 936 * Legacy interface version 2.0.916 * Legacy interface version 1.0. 937 917 */ 938 static const struct VBOXCAPIV 2918 static const struct VBOXCAPIV1 939 919 { 940 920 /** The size of the structure. */ … … 945 925 unsigned int (*pfnGetVersion)(void); 946 926 947 void (*pfnComInitialize)(const char *pszVirtualBoxIID, 948 IVirtualBox **ppVirtualBox, 949 const char *pszSessionIID, 950 ISession **ppSession); 951 952 void (*pfnComUninitialize)(void); 953 954 void (*pfnComUnallocMem)(void *pv); 955 void (*pfnUtf16Free)(BSTR pwszString); 956 void (*pfnUtf8Free)(char *pszString); 957 958 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); 959 int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString); 960 961 #ifdef VBOX_WITH_XPCOM 962 void (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue); 963 #endif /* VBOX_WITH_XPCOM */ 964 965 /** Tail version, same as uVersion. */ 966 unsigned uEndVersion; 967 } s_Functions_v2_0 = 968 { 969 sizeof(s_Functions_v2_0), 970 0x00020000U, 971 972 VBoxVersion, 973 974 VBoxComInitialize, 975 VBoxComUninitialize, 976 977 VBoxComUnallocMem, 978 VBoxUtf16Free, 979 VBoxUtf8Free, 980 981 VBoxUtf16ToUtf8, 982 VBoxUtf8ToUtf16, 983 984 #ifdef VBOX_WITH_XPCOM 985 VBoxGetEventQueue, 986 #endif /* VBOX_WITH_XPCOM */ 987 988 0x00020000U 989 }; 990 991 if ((uVersion & 0xffff0000U) == 0x00020000U) 992 return (PCVBOXCAPI)&s_Functions_v2_0; 993 994 /* 995 * Legacy interface version 1.0. 996 */ 997 static const struct VBOXCAPIV1 998 { 999 /** The size of the structure. */ 1000 unsigned cb; 1001 /** The structure version. */ 1002 unsigned uVersion; 1003 1004 unsigned int (*pfnGetVersion)(void); 1005 1006 void (*pfnComInitialize)(IVirtualBox **virtualBox, ISession **session); 1007 void (*pfnComUninitialize)(void); 1008 1009 void (*pfnComUnallocMem)(void *pv); 1010 void (*pfnUtf16Free)(BSTR pwszString); 1011 void (*pfnUtf8Free)(char *pszString); 1012 1013 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); 1014 int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString); 927 void (*pfnComInitialize)(IVirtualBox **virtualBox, ISession **session); 928 void (*pfnComUninitialize)(void); 929 930 void (*pfnComUnallocMem)(void *pv); 931 void (*pfnUtf16Free)(BSTR pwszString); 932 void (*pfnUtf8Free)(char *pszString); 933 934 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); 935 int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString); 1015 936 1016 937 /** Tail version, same as uVersion. */ -
trunk/src/VBox/Main/cbinding/VBoxCAPIGlue.c
r52846 r54027 5 5 6 6 /* 7 * Copyright (C) 2008-201 4Oracle Corporation7 * Copyright (C) 2008-2015 Oracle Corporation 8 8 * 9 9 * Permission is hereby granted, free of charge, to any person … … 164 164 #ifndef WIN32 165 165 g_hVBoxCAPI = dlopen(szName, RTLD_NOW | RTLD_LOCAL); 166 #else /* WIN32 */ 167 g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */, 0 /* dwFlags */); 168 #endif /* WIN32 */ 166 169 if (g_hVBoxCAPI) 167 170 { 168 171 PFNVBOXGETCAPIFUNCTIONS pfnGetFunctions; 172 #ifndef WIN32 169 173 pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS)(uintptr_t) 170 174 dlsym(g_hVBoxCAPI, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME); 171 # ifdef VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME175 # ifdef VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME 172 176 if (!pfnGetFunctions) 173 177 pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS)(uintptr_t) 174 178 dlsym(g_hVBoxCAPI, VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME); 175 #endif /* VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME */ 179 # endif /* VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME */ 180 #else /* WIN32 */ 181 pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS) 182 GetProcAddress(g_hVBoxCAPI, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME); 183 #endif /* WIN32 */ 176 184 if (pfnGetFunctions) 177 185 { … … 179 187 if (g_pVBoxFuncs) 180 188 { 181 g_pfnGetFunctions = pfnGetFunctions; 182 return 0; 189 if ( ( VBOX_CAPI_MAJOR(g_pVBoxFuncs->uVersion) 190 == VBOX_CAPI_MAJOR(VBOX_CAPI_VERSION)) 191 && ( VBOX_CAPI_MINOR(g_pVBoxFuncs->uVersion) 192 >= VBOX_CAPI_MINOR(VBOX_CAPI_VERSION))) 193 { 194 g_pfnGetFunctions = pfnGetFunctions; 195 return 0; 196 } 197 setErrMsg(1, "%.80s: pfnGetFunctions(%#x) returned incompatible version %#x", 198 szName, VBOX_CAPI_VERSION, g_pVBoxFuncs->uVersion); 199 g_pVBoxFuncs = NULL; 183 200 } 184 185 /* bail out */ 186 setErrMsg(1, "%.80s: pfnGetFunctions(%#x) failed", 187 szName, VBOX_CAPI_VERSION); 201 else 202 { 203 /* bail out */ 204 setErrMsg(1, "%.80s: pfnGetFunctions(%#x) failed", 205 szName, VBOX_CAPI_VERSION); 206 } 188 207 } 189 208 else 209 { 210 #ifndef WIN32 190 211 setErrMsg(1, "dlsym(%.80s/%.32s): %.128s", 191 212 szName, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME, dlerror()); 192 dlclose(g_hVBoxCAPI); 193 g_hVBoxCAPI = NULL; 194 } 195 else 196 setErrMsg(0, "dlopen(%.80s): %.160s", szName, dlerror()); 197 #else /* !WIN32 */ 198 g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */, 0 /* dwFlags */); 199 if (g_hVBoxCAPI) 200 { 201 PFNVBOXGETCAPIFUNCTIONS pfnGetFunctions; 202 pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS) 203 GetProcAddress(g_hVBoxCAPI, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME); 204 if (pfnGetFunctions) 205 { 206 g_pVBoxFuncs = pfnGetFunctions(VBOX_CAPI_VERSION); 207 if (g_pVBoxFuncs) 208 { 209 g_pfnGetFunctions = pfnGetFunctions; 210 return 0; 211 } 212 213 /* bail out */ 214 setErrMsg(1, "%.80s: pfnGetFunctions(%#x) failed", 215 szName, VBOX_CAPI_VERSION); 216 } 217 else 213 #else /* WIN32 */ 218 214 setErrMsg(1, "GetProcAddress(%.80s/%.32s): %d", 219 215 szName, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME, GetLastError()); 216 #endif /* WIN32 */ 217 } 218 219 #ifndef WIN32 220 dlclose(g_hVBoxCAPI); 221 #else /* WIN32 */ 220 222 FreeLibrary(g_hVBoxCAPI); 223 #endif /* WIN32 */ 221 224 g_hVBoxCAPI = NULL; 222 225 } 223 226 else 227 { 228 #ifndef WIN32 229 setErrMsg(0, "dlopen(%.80s): %.160s", szName, dlerror()); 230 #else /* WIN32 */ 224 231 setErrMsg(0, "LoadLibraryEx(%.80s): %d", szName, GetLastError()); 225 #endif /* !WIN32 */ 232 #endif /* WIN32 */ 233 } 226 234 227 235 return -1; -
trunk/src/VBox/Main/cbinding/capiidl.xsl
r53938 r54027 1483 1483 int (*pfnInterruptEventQueueProcessing)(void); 1484 1484 1485 /** Tail version, same as uVersion. */ 1485 /** 1486 * Clear memory used by a UTF-8 string. Must be zero terminated. 1487 * Can be used for any UTF-8 or ASCII/ANSI string. 1488 * 1489 * @param pszString input/output string 1490 */ 1491 void (*pfnUtf8Clear)(char *pszString); 1492 /** 1493 * Clear memory used by a UTF-16 string. Must be zero terminated. 1494 * Can be used for any UTF-16 or UCS-2 string. 1495 * 1496 * @param pwszString input/output string 1497 */ 1498 void (*pfnUtf16Clear)(BSTR pwszString); 1499 1500 /** Tail version, same as uVersion. 1501 * 1502 * This should only be accessed if for some reason an API client needs 1503 * exactly the version it requested, or if cb is used to calculate the 1504 * address of this field. It may move as the structure before this is 1505 * allowed to grow as long as all the data from earlier minor versions 1506 * remains at the same place. 1507 */ 1486 1508 unsigned uEndVersion; 1487 1509 } VBOXCAPI; … … 1500 1522 #endif /* !WIN32 */ 1501 1523 1524 /** Extract the C API style major version. 1525 * Useful for comparing the interface version in VBOXCAPI::uVersion. */ 1526 #define VBOX_CAPI_MAJOR(x) (((x) & 0xffff0000U) >> 16) 1527 1528 /** Extract the C API style major version. 1529 * Useful for comparing the interface version in VBOXCAPI::uVersion. */ 1530 #define VBOX_CAPI_MINOR(x) ((x) & 0x0000ffffU) 1531 1502 1532 /** The current interface version. 1503 1533 * For use with VBoxGetCAPIFunctions and to be found in VBOXCAPI::uVersion. */ 1504 #define VBOX_CAPI_VERSION 0x0004000 0U1534 #define VBOX_CAPI_VERSION 0x00040001U 1505 1535 1506 1536 #ifndef WIN32
Note:
See TracChangeset
for help on using the changeset viewer.