Changeset 16497 in vbox
- Timestamp:
- Feb 4, 2009 7:56:07 AM (16 years ago)
- Location:
- trunk/src/VBox/Main/cbinding
- Files:
-
- 3 edited
- 1 moved
-
Makefile.kmk (modified) (1 diff)
-
VBoxXPCOMC.cpp (moved) (moved from trunk/src/VBox/Main/cbinding/libXPCOMtoC.cpp ) (4 diffs)
-
cbinding.h (modified) (2 diffs)
-
tstLinuxC.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/cbinding/Makefile.kmk
r16483 r16497 59 59 VBoxXPCOMC_DEFS = MOZ_UNICODE IN_VBOXXPCOMC 60 60 VBoxXPCOMC_SOURCES = \ 61 libXPCOMtoC.cpp61 VBoxXPCOMC.cpp 62 62 63 63 ifdef VBOX_WITH_TESTCASES -
trunk/src/VBox/Main/cbinding/VBoxXPCOMC.cpp
r16494 r16497 1 1 /* $Id$ */ 2 /** @file libXPCOMtoC.cpp2 /** @file VBoxXPCOMC.cpp 3 3 * Utility functions to use with the C binding for XPCOM. 4 4 */ … … 24 24 25 25 #include <nsMemory.h> 26 #include <nsString.h>27 26 #include <nsIServiceManager.h> 28 27 #include <nsEventQueueUtils.h> … … 41 40 42 41 VBOXXPCOMC_DECL(int) 43 VBoxUtf16ToUtf8(const PRUnichar *p szString, char **ppwszString)42 VBoxUtf16ToUtf8(const PRUnichar *pwszString, char **ppszString) 44 43 { 45 return RTUtf16ToUtf8(p szString, ppwszString);44 return RTUtf16ToUtf8(pwszString, ppszString); 46 45 } 47 46 48 47 VBOXXPCOMC_DECL(int) 49 VBox StrToUtf16(const char *pszString, PRUnichar **ppwszString)48 VBoxUtf8ToUtf16(const char *pszString, PRUnichar **ppwszString) 50 49 { 51 50 return RTStrToUtf16(pszString, ppwszString); … … 59 58 60 59 VBOXXPCOMC_DECL(void) 61 VBox StrFree(char *pszString)60 VBoxUtf8Free(char *pszString) 62 61 { 63 62 RTStrFree(pszString); 64 63 } 65 64 66 VBOXXPCOMC_DECL( const PRUnichar *)67 VBoxCo nvertUTF8toPRUnichar(char *src)65 VBOXXPCOMC_DECL(void) 66 VBoxComUnallocMem(void *ptr) 68 67 { 69 return NS_ConvertUTF8toUTF16(src).get(); 70 } 71 72 VBOXXPCOMC_DECL(const char *) 73 VBoxConvertPRUnichartoUTF8(PRUnichar *src) 74 { 75 return NS_ConvertUTF16toUTF8(src).get(); 76 } 77 78 VBOXXPCOMC_DECL(const PRUnichar *) 79 VBoxConvertAsciitoPRUnichar(char *src) 80 { 81 return NS_ConvertASCIItoUTF16(src).get(); 82 } 83 84 VBOXXPCOMC_DECL(const char *) 85 VBoxConvertPRUnichartoAscii(PRUnichar *src) 86 { 87 return NS_LossyConvertUTF16toASCII(src).get(); 88 } 89 90 VBOXXPCOMC_DECL(void) 91 VBoxComUnallocStr(PRUnichar *str_dealloc) 92 { 93 if (str_dealloc) 68 if (ptr) 94 69 { 95 nsMemory::Free(str_dealloc); 96 } 97 } 98 99 VBOXXPCOMC_DECL(void) 100 VBoxComUnallocIID(nsIID *iid) 101 { 102 if (iid) 103 { 104 nsMemory::Free(iid); 70 nsMemory::Free(ptr); 105 71 } 106 72 } -
trunk/src/VBox/Main/cbinding/cbinding.h
r16489 r16497 44 44 45 45 /* Deallocation functions. */ 46 VBOXXPCOMC_DECL(void) VBoxComUnallocStr(PRUnichar *str_dealloc); 47 VBOXXPCOMC_DECL(void) VBoxComUnallocIID(nsIID *iid); 46 VBOXXPCOMC_DECL(void) VBoxComUnallocMem(void *ptr); 48 47 VBOXXPCOMC_DECL(void) VBoxUtf16Free(PRUnichar *pwszString); 49 VBOXXPCOMC_DECL(void) VBox StrFree(char *pszString);48 VBOXXPCOMC_DECL(void) VBoxUtf8Free(char *pszString); 50 49 51 50 /* Converting to and from ASCII. */ … … 53 52 VBOXXPCOMC_DECL(const PRUnichar *) VBoxConvertAsciitoPRUnichar(char *src); 54 53 55 /* Converting to and from UTF-8. */56 VBOXXPCOMC_DECL(const char *) VBoxConvertPRUnichartoUTF8(PRUnichar *src);57 VBOXXPCOMC_DECL(const PRUnichar *) VBoxConvertUTF8toPRUnichar(char *src);58 59 54 /* Converting to and from UTF-8 and UTF-16. */ 60 VBOXXPCOMC_DECL(int) VBoxStrToUtf16(const char *pszString, PRUnichar **ppwszString);61 VBOXXPCOMC_DECL(int) VBoxUtf16ToUtf8(const PRUnichar *pszString,char **ppwszString);55 VBOXXPCOMC_DECL(int) VBoxUtf16ToUtf8(const PRUnichar *pwszString, char **ppszString); 56 VBOXXPCOMC_DECL(int) VBoxUtf8ToUtf16(const char *pszString, PRUnichar **ppwszString); 62 57 63 58 #ifdef __cplusplus -
trunk/src/VBox/Main/cbinding/tstLinuxC.c
r16487 r16497 80 80 } 81 81 82 printf("VM List:\n\n"); 83 84 /* 85 * Iterate through the collection. 86 */ 87 88 for (i = 0; i < machineCnt; ++i) 89 { 90 IMachine *machine = machines[i]; 91 PRBool isAccessible = PR_FALSE; 92 93 printf("\tMachine #%u\n", (unsigned)i); 94 95 if (!machine) 96 { 97 printf("\t(skipped, NULL)\n"); 98 continue; 99 } 100 101 machine->vtbl->GetAccessible(machine, &isAccessible); 102 103 if (isAccessible) 104 { 105 PRUnichar *machineName; 106 107 machine->vtbl->GetName(machine, &machineName); 108 printf("\tName: %s\n", VBoxConvertPRUnichartoAscii(machineName)); 109 110 VBoxComUnallocStr(machineName); 111 } 112 else 113 { 114 printf("\tName: <inaccessible>\n"); 115 } 116 117 118 { 119 nsID *iid = NULL; 120 char *uuidString; 121 122 machine->vtbl->GetId(machine, &iid); 123 uuidString = nsIDToString(iid); 124 printf("\tUUID: %s\n", uuidString); 125 126 free(uuidString); 127 VBoxComUnallocIID(iid); 128 } 129 130 if (isAccessible) 131 { 132 { 133 PRUnichar *configFile; 134 char *configFile1 = calloc((size_t)64, (size_t)1); 135 136 machine->vtbl->GetSettingsFilePath(machine, &configFile); 137 VBoxUtf16ToUtf8(configFile, &configFile1); 138 printf("\tConfig file: %s\n", configFile1); 139 140 free(configFile1); 141 VBoxComUnallocStr(configFile); 142 } 143 144 { 145 PRUint32 memorySize; 146 147 machine->vtbl->GetMemorySize(machine, &memorySize); 148 printf("\tMemory size: %uMB\n", memorySize); 149 } 150 151 { 152 PRUnichar *typeId; 153 PRUnichar *osName; 154 IGuestOSType *osType = NULL; 155 156 machine->vtbl->GetOSTypeId(machine, &typeId); 157 virtualBox->vtbl->GetGuestOSType(virtualBox, typeId, &osType); 158 osType->vtbl->GetDescription(osType, &osName); 159 printf("\tGuest OS: %s\n\n", VBoxConvertPRUnichartoAscii(osName)); 160 161 osType->vtbl->nsisupports.Release((void *)osType); 162 VBoxComUnallocStr(osName); 163 VBoxComUnallocStr(typeId); 164 } 165 } 166 } 167 168 /* 169 * Let the user chose a machine to start. 170 */ 171 172 printf("Type Machine# to start (0 - %u) or 'quit' to do nothing: ", 173 (unsigned)(machineCnt - 1)); 174 fflush(stdout); 175 176 if (scanf("%u", &start_id) == 1 && start_id < machineCnt) 177 { 178 IMachine *machine = machines[start_id]; 179 180 if (machine) 181 { 182 nsID *iid = NULL; 183 184 machine->vtbl->GetId(machine, &iid); 185 startVM(virtualBox, session, iid); 186 187 VBoxComUnallocIID(iid); 188 } 189 } 190 191 /* 192 * Don't forget to release the objects in the array. 193 */ 194 195 for (i = 0; i < machineCnt; ++i) 196 { 197 IMachine *machine = machines[i]; 198 199 if (machine) 200 { 201 machine->vtbl->nsisupports.Release((void *)machine); 202 } 203 } 82 if(machineCnt) 83 { 84 printf("VM List:\n\n"); 85 86 /* 87 * Iterate through the collection. 88 */ 89 90 for (i = 0; i < machineCnt; ++i) 91 { 92 IMachine *machine = machines[i]; 93 PRBool isAccessible = PR_FALSE; 94 95 printf("\tMachine #%u\n", (unsigned)i); 96 97 if (!machine) 98 { 99 printf("\t(skipped, NULL)\n"); 100 continue; 101 } 102 103 machine->vtbl->GetAccessible(machine, &isAccessible); 104 105 if (isAccessible) 106 { 107 PRUnichar *machineName_; 108 char *machineName; 109 110 machine->vtbl->GetName(machine, &machineName_); 111 VBoxUtf16ToUtf8(machineName_,&machineName); 112 printf("\tName: %s\n", machineName); 113 114 VBoxUtf8Free(machineName); 115 VBoxComUnallocMem(machineName_); 116 } 117 else 118 { 119 printf("\tName: <inaccessible>\n"); 120 } 121 122 123 { 124 nsID *iid = NULL; 125 char *uuidString; 126 127 machine->vtbl->GetId(machine, &iid); 128 uuidString = nsIDToString(iid); 129 printf("\tUUID: %s\n", uuidString); 130 131 free(uuidString); 132 VBoxComUnallocMem(iid); 133 } 134 135 if (isAccessible) 136 { 137 { 138 PRUnichar *configFile; 139 char *configFile1 = calloc((size_t)64, (size_t)1); 140 141 machine->vtbl->GetSettingsFilePath(machine, &configFile); 142 VBoxUtf16ToUtf8(configFile, &configFile1); 143 printf("\tConfig file: %s\n", configFile1); 144 145 free(configFile1); 146 VBoxComUnallocMem(configFile); 147 } 148 149 { 150 PRUint32 memorySize; 151 152 machine->vtbl->GetMemorySize(machine, &memorySize); 153 printf("\tMemory size: %uMB\n", memorySize); 154 } 155 156 { 157 PRUnichar *typeId; 158 PRUnichar *osName_; 159 char *osName; 160 IGuestOSType *osType = NULL; 161 162 machine->vtbl->GetOSTypeId(machine, &typeId); 163 virtualBox->vtbl->GetGuestOSType(virtualBox, typeId, &osType); 164 osType->vtbl->GetDescription(osType, &osName_); 165 VBoxUtf16ToUtf8(osName_,&osName); 166 printf("\tGuest OS: %s\n\n", osName); 167 168 osType->vtbl->nsisupports.Release((void *)osType); 169 VBoxUtf8Free(osName); 170 VBoxComUnallocMem(osName_); 171 VBoxComUnallocMem(typeId); 172 } 173 } 174 } 175 176 /* 177 * Let the user chose a machine to start. 178 */ 179 180 printf("Type Machine# to start (0 - %u) or 'quit' to do nothing: ", 181 (unsigned)(machineCnt - 1)); 182 fflush(stdout); 183 184 if (scanf("%u", &start_id) == 1 && start_id < machineCnt) 185 { 186 IMachine *machine = machines[start_id]; 187 188 if (machine) 189 { 190 nsID *iid = NULL; 191 192 machine->vtbl->GetId(machine, &iid); 193 startVM(virtualBox, session, iid); 194 195 VBoxComUnallocMem(iid); 196 } 197 } 198 199 /* 200 * Don't forget to release the objects in the array. 201 */ 202 203 for (i = 0; i < machineCnt; ++i) 204 { 205 IMachine *machine = machines[i]; 206 207 if (machine) 208 { 209 machine->vtbl->nsisupports.Release((void *)machine); 210 } 211 } 212 } 213 else 214 { 215 printf("\tNo VMs\n"); 216 } 204 217 } 205 218 … … 227 240 } 228 241 229 VBox StrToUtf16("gui", &sessionType);242 VBoxUtf8ToUtf16("gui", &sessionType); 230 243 231 244 rc = virtualBox->vtbl->OpenRemoteSession( … … 262 275 { 263 276 IVirtualBoxErrorInfo *errorInfo; 264 PRUnichar *text; 277 PRUnichar *text_; 278 char *text; 265 279 266 280 progress->vtbl->GetErrorInfo(progress, &errorInfo); 267 errorInfo->vtbl->GetText(errorInfo, &text); 268 printf("[!] Text = %s\n", VBoxConvertPRUnichartoAscii (text)); 281 errorInfo->vtbl->GetText(errorInfo, &text_); 282 VBoxUtf16ToUtf8(text_, &text); 283 printf("Error: %s\n", text); 284 285 VBoxComUnallocMem(text_); 286 VBoxUtf8Free(text); 269 287 } 270 288 else … … 283 301 int main(int argc, char **argv) 284 302 { 285 IVirtualBox *vbox = NULL;286 ISession *session = NULL;287 PRUint32 revision = 0;288 PRUnichar *version = NULL;289 PRUnichar *homefolder = NULL;303 IVirtualBox *vbox = NULL; 304 ISession *session = NULL; 305 PRUint32 revision = 0; 306 PRUnichar *version_ = NULL; 307 PRUnichar *homefolder_ = NULL; 290 308 nsresult rc; /* Result code of various function (method) calls. */ 291 309 … … 335 353 /* 2. Version */ 336 354 337 rc = vbox->vtbl->GetVersion(vbox, &version );355 rc = vbox->vtbl->GetVersion(vbox, &version_); 338 356 if (NS_SUCCEEDED(rc)) 339 357 { 340 printf("\tVersion: %s\n", VBoxConvertPRUnichartoAscii(version)); 358 char *version = NULL; 359 VBoxUtf16ToUtf8(version_, &version); 360 printf("\tVersion: %s\n", version); 361 VBoxUtf8Free(version); 341 362 } 342 363 else … … 345 366 argv[0], (unsigned)rc); 346 367 } 347 VBoxComUnalloc Str(version);368 VBoxComUnallocMem(version_); 348 369 349 370 /* 3. Home Folder */ 350 371 351 rc = vbox->vtbl->GetHomeFolder(vbox, &homefolder );372 rc = vbox->vtbl->GetHomeFolder(vbox, &homefolder_); 352 373 if (NS_SUCCEEDED(rc)) 353 374 { 354 printf("\tHomeFolder: %s\n", VBoxConvertPRUnichartoAscii(homefolder)); 375 char *homefolder = NULL; 376 VBoxUtf16ToUtf8(homefolder_, &homefolder); 377 printf("\tHomeFolder: %s\n", homefolder); 378 VBoxUtf8Free(homefolder); 355 379 } 356 380 else … … 359 383 argv[0], (unsigned)rc); 360 384 } 361 VBoxComUnalloc Str(homefolder);385 VBoxComUnallocMem(homefolder_); 362 386 363 387 listVMs(vbox, session);
Note:
See TracChangeset
for help on using the changeset viewer.

