Changeset 48225 in vbox for trunk/src/VBox
- Timestamp:
- Sep 2, 2013 11:14:11 AM (11 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 1 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxHeadless/testcase/Makefile.kmk
r41477 r48225 21 21 ifdef VBOX_WITH_TESTCASES 22 22 PROGRAMS += tstHeadless 23 tstHeadless_TEMPLATE = VBOXMAINCLIENT EXE23 tstHeadless_TEMPLATE = VBOXMAINCLIENTTSTEXE 24 24 tstHeadless_SOURCES = tstHeadless.cpp 25 25 endif -
trunk/src/VBox/Main/cbinding/Makefile.kmk
r41477 r48225 5 5 6 6 # 7 # Copyright (C) 2009-201 2Oracle Corporation7 # Copyright (C) 2009-2013 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 30 30 XpComCSamples_SOURCES = \ 31 31 tstXPCOMCGlue.c \ 32 tstXPCOMC Call.c \32 tstXPCOMCEvent.c \ 33 33 makefile.tstXPCOMCGlue=>Makefile 34 34 … … 51 51 VBoxCAPI_v4_0.h \ 52 52 VBoxCAPI_v4_1.h \ 53 VBoxCAPI_v4_2.h \ 53 54 $(XpComCHeaders_0_OUTDIR)/VBoxCAPI.h=>VBoxCAPI_v$(VBOX_API_VERSION).h 54 55 … … 107 108 # 108 109 PROGRAMS += tstXPCOMCGlue 109 tstXPCOMCGlue_TEMPLATE = VBOXR3 EXE110 tstXPCOMCGlue_TEMPLATE = VBOXR3TSTEXE 110 111 tstXPCOMCGlue_INCS = \ 111 112 $(VBOX_PATH_SDK)/bindings/xpcom/include \ 112 113 $(VBOX_PATH_SDK)/bindings/xpcom/cbinding 113 114 tstXPCOMCGlue_INTERMEDIATES = \ 114 $(VBOX_PATH_SDK)/bindings/xpcom/cbinding/VBoxXPCOMCGlue.h \115 $(VBOX_PATH_SDK)/bindings/xpcom/cbinding/VBoxXPCOMCGlue.h \ 115 116 $(VBOX_PATH_SDK)/bindings/xpcom/include/VBoxCAPI_v$(VBOX_API_VERSION).h 116 117 tstXPCOMCGlue_SOURCES = \ … … 119 120 $(VBoxXPCOMCGlue_1_TARGET) 120 121 121 ifeq (disabled,1)122 #123 # The callback testcase.124 #125 PROGRAMS += tstXPCOMCCall126 tstXPCOMCCall_TEMPLATE = VBOXR3EXE127 tstXPCOMCCall_INCS =\128 $(VBOX_PATH_SDK)/bindings/xpcom/include129 tstXPCOMCCall_INTERMEDIATES = \130 $(VBOX_PATH_SDK)/bindings/xpcom/include/VBoxCAPI_v$(VBOX_API_VERSION).h131 tstXPCOMCCall_SOURCES = \132 tstXPCOMCCall.c133 tstXPCOMCCall_LIBS = \134 $(VBoxXPCOMCGlue_1_TARGET)135 endif122 # 123 # The event listener testcase. 124 # 125 PROGRAMS += tstXPCOMCEvent 126 tstXPCOMCEvent_TEMPLATE = VBOXR3TSTEXE 127 tstXPCOMCEvent_INCS = \ 128 $(VBOX_PATH_SDK)/bindings/xpcom/include \ 129 $(VBOX_PATH_SDK)/bindings/xpcom/cbinding 130 tstXPCOMCEvent_INTERMEDIATES = \ 131 $(VBOX_PATH_SDK)/bindings/xpcom/cbinding/VBoxXPCOMCGlue.h \ 132 $(VBOX_PATH_SDK)/bindings/xpcom/include/VBoxCAPI_v$(VBOX_API_VERSION).h 133 tstXPCOMCEvent_SOURCES = \ 134 tstXPCOMCEvent.c 135 tstXPCOMCEvent_LIBS = \ 136 $(VBoxXPCOMCGlue_1_TARGET) 136 137 endif 137 138 -
trunk/src/VBox/Main/cbinding/makefile.tstXPCOMCGlue
r44529 r48225 5 5 6 6 # 7 # Copyright (C) 2009-201 0Oracle Corporation7 # Copyright (C) 2009-2013 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 24 24 25 25 .PHONY: all 26 all: tstXPCOMCGlue tstXPCOMC Call26 all: tstXPCOMCGlue tstXPCOMCEvent 27 27 28 28 .PHONY: clean 29 29 clean: 30 rm -f tstXPCOMCGlue.o tstXPCOMCGlue VBoxXPCOMCGlue.o tstXPCOMC Call.o tstXPCOMCCall30 rm -f tstXPCOMCGlue.o tstXPCOMCGlue VBoxXPCOMCGlue.o tstXPCOMCEvent.o tstXPCOMCEvent 31 31 32 32 tstXPCOMCGlue: tstXPCOMCGlue.o VBoxXPCOMCGlue.o … … 36 36 $(CC) $(CFLAGS) $(INCS_XPCOM) $(GLUE_INC) -o $@ -c $< 37 37 38 tstXPCOMC Call: tstXPCOMCCall.o VBoxXPCOMCGlue.o38 tstXPCOMCEvent: tstXPCOMCEvent.o VBoxXPCOMCGlue.o 39 39 $(CC) -o $@ $^ -ldl -lpthread 40 40 41 tstXPCOMC Call.o: tstXPCOMCCall.c41 tstXPCOMCEvent.o: tstXPCOMCEvent.c 42 42 $(CC) $(CFLAGS) $(INCS_XPCOM) $(GLUE_INC) -o $@ -c $< 43 43 -
trunk/src/VBox/Main/cbinding/tstXPCOMCEvent.c
r48192 r48225 1 1 /* $Revision$ */ 2 /** @file tstXPCOMCGlue.c 3 * Demonstrator program to illustrate use of C bindings of Main API. 2 /** @file tstXPCOMCEvent.c 3 * Demonstrator program to illustrate use of C bindings of Main API, 4 * and in particular how to handle active event listeners (event delivery 5 * through callbacks). The code is derived from tstXPCOMCGlue.c, so keep 6 * the diffs to the original code as small as possible. 4 7 * 5 8 * Linux only at the moment due to shared library magic in the Makefile. … … 7 10 8 11 /* 9 * Copyright (C) 2009-201 0Oracle Corporation12 * Copyright (C) 2009-2013 Oracle Corporation 10 13 * 11 14 * This file is part of VirtualBox Open Source Edition (OSE), as … … 28 31 #include <signal.h> 29 32 #include <sys/poll.h> 30 31 /*******************************************************************************32 * Internal Functions *33 *******************************************************************************/34 static void listVMs(IVirtualBox *virtualBox, ISession *session, nsIEventQueue *queue);35 static void registerCallBack(IVirtualBox *virtualBox, ISession *session, PRUnichar *machineId, nsIEventQueue *queue);36 static void startVM(IVirtualBox *virtualBox, ISession *session, PRUnichar *id, nsIEventQueue *queue);37 33 38 34 /******************************************************************************* … … 62 58 }\ 63 59 64 /**65 * Callback functions66 */67 60 static const char *GetStateName(PRUint32 machineState) 68 61 { … … 75 68 case MachineState_Aborted: return "Aborted"; 76 69 case MachineState_Running: return "Running"; 70 case MachineState_Paused: return "Paused"; 71 case MachineState_Stuck: return "Stuck"; 77 72 case MachineState_Teleporting: return "Teleporting"; 78 73 case MachineState_LiveSnapshotting: return "LiveSnapshotting"; 79 case MachineState_Paused: return "Paused";80 case MachineState_Stuck: return "Stuck";81 74 case MachineState_Starting: return "Starting"; 82 75 case MachineState_Stopping: return "Stopping"; … … 85 78 case MachineState_TeleportingPausedVM: return "TeleportingPausedVM"; 86 79 case MachineState_TeleportingIn: return "TeleportingIn"; 87 case MachineState_Discarding: return "Discarding"; 80 case MachineState_FaultTolerantSyncing: return "FaultTolerantSyncing"; 81 case MachineState_DeletingSnapshotOnline: return "DeletingSnapshotOnline"; 82 case MachineState_DeletingSnapshotPaused: return "DeletingSnapshotPaused"; 83 case MachineState_RestoringSnapshot: return "RestoringSnapshot"; 84 case MachineState_DeletingSnapshot: return "DeletingSnapshot"; 88 85 case MachineState_SettingUp: return "SettingUp"; 89 86 default: return "no idea"; … … 91 88 } 92 89 93 static nsresult OnMousePointerShapeChange( 94 IConsoleCallback *pThis, 95 PRBool visible, 96 PRBool alpha, 97 PRUint32 xHot, 98 PRUint32 yHot, 99 PRUint32 width, 100 PRUint32 height, 101 PRUint8 * shape 102 ) { 103 printf("OnMousePointerShapeChange\n"); 90 /** 91 * Event handler function 92 */ 93 static nsresult HandleEvent(IEventListener *pThis, IEvent *event) 94 { 95 enum VBoxEventType evType; 96 nsresult rc; 97 98 if (!event) 99 { 100 printf("event null\n"); 101 return 0; 102 } 103 104 evType = VBoxEventType_Invalid; 105 rc = event->vtbl->GetType(event, &evType); 106 if (NS_FAILED(rc)) 107 { 108 printf("cannot get event type, rc=%#x\n", rc); 109 return 0; 110 } 111 112 switch (evType) 113 { 114 case VBoxEventType_OnMousePointerShapeChanged: 115 printf("OnMousePointerShapeChanged\n"); 116 break; 117 118 case VBoxEventType_OnMouseCapabilityChanged: 119 printf("OnMouseCapabilityChanged\n"); 120 break; 121 122 case VBoxEventType_OnKeyboardLedsChanged: 123 printf("OnMouseCapabilityChanged\n"); 124 break; 125 126 case VBoxEventType_OnStateChanged: 127 { 128 static const nsID istateChangedEventUUID = ISTATECHANGEDEVENT_IID; 129 IStateChangedEvent *ev = NULL; 130 enum MachineState state; 131 rc = event->vtbl->nsisupports.QueryInterface((nsISupports *)event, &istateChangedEventUUID, (void **)&ev); 132 if (NS_FAILED(rc)) 133 { 134 printf("cannot get StateChangedEvent interface, rc=%#x\n", rc); 135 return 0; 136 } 137 if (!ev) 138 { 139 printf("StateChangedEvent reference null\n"); 140 return 0; 141 } 142 rc = ev->vtbl->GetState(ev, &state); 143 if (NS_FAILED(rc)) 144 printf("warning: cannot get state, rc=%#x\n", rc); 145 ev->vtbl->ievent.nsisupports.Release((nsISupports *)ev); 146 printf("OnStateChanged: %s\n", GetStateName(state)); 147 148 fflush(stdout); 149 if ( state == MachineState_PoweredOff 150 || state == MachineState_Saved 151 || state == MachineState_Teleported 152 || state == MachineState_Aborted 153 ) 154 g_fStop = 1; 155 break; 156 } 157 158 case VBoxEventType_OnAdditionsStateChanged: 159 printf("OnAdditionsStateChanged\n"); 160 break; 161 162 case VBoxEventType_OnNetworkAdapterChanged: 163 printf("OnNetworkAdapterChanged\n"); 164 break; 165 166 case VBoxEventType_OnSerialPortChanged: 167 printf("OnSerialPortChanged\n"); 168 break; 169 170 case VBoxEventType_OnParallelPortChanged: 171 printf("OnParallelPortChanged\n"); 172 break; 173 174 case VBoxEventType_OnStorageControllerChanged: 175 printf("OnStorageControllerChanged\n"); 176 break; 177 178 case VBoxEventType_OnMediumChanged: 179 printf("OnMediumChanged\n"); 180 break; 181 182 case VBoxEventType_OnVRDEServerChanged: 183 printf("OnVRDEServerChanged\n"); 184 break; 185 186 case VBoxEventType_OnUSBControllerChanged: 187 printf("OnUSBControllerChanged\n"); 188 break; 189 190 case VBoxEventType_OnUSBDeviceStateChanged: 191 printf("OnUSBDeviceStateChanged\n"); 192 break; 193 194 case VBoxEventType_OnSharedFolderChanged: 195 printf("OnSharedFolderChanged\n"); 196 break; 197 198 case VBoxEventType_OnRuntimeError: 199 printf("OnRuntimeError\n"); 200 break; 201 202 case VBoxEventType_OnCanShowWindow: 203 printf("OnCanShowWindow\n"); 204 break; 205 206 case VBoxEventType_OnShowWindow: 207 printf("OnShowWindow\n"); 208 break; 209 210 default: 211 printf("unknown event: %d\n", evType); 212 } 213 104 214 return 0; 105 215 } 106 107 static nsresult OnMouseCapabilityChange(108 IConsoleCallback *pThis,109 PRBool supportsAbsolute,110 PRBool needsHostCursor111 ) {112 printf("OnMouseCapabilityChange\n");113 return 0;114 }115 116 static nsresult OnKeyboardLedsChange(117 IConsoleCallback *pThis,118 PRBool numLock,119 PRBool capsLock,120 PRBool scrollLock121 ) {122 printf("OnMouseCapabilityChange\n");123 return 0;124 }125 126 static nsresult OnStateChange(127 IConsoleCallback *pThis,128 PRUint32 state129 ) {130 printf("OnStateChange: %s\n", GetStateName(state));131 fflush(stdout);132 if ( state == MachineState_PoweredOff133 || state == MachineState_Saved134 || state == MachineState_Teleported135 || state == MachineState_Aborted136 )137 g_fStop = 1;138 return 0;139 }140 141 static nsresult OnAdditionsStateChange(IConsoleCallback *pThis )142 {143 printf("OnAdditionsStateChange\n");144 return 0;145 }146 147 static nsresult OnNetworkAdapterChange(148 IConsoleCallback *pThis,149 INetworkAdapter * networkAdapter150 ) {151 printf("OnNetworkAdapterChange\n");152 return 0;153 }154 155 static nsresult OnSerialPortChange(156 IConsoleCallback *pThis,157 ISerialPort * serialPort158 ) {159 printf("OnSerialPortChange\n");160 return 0;161 }162 163 static nsresult OnParallelPortChange(164 IConsoleCallback *pThis,165 IParallelPort * parallelPort166 ) {167 printf("OnParallelPortChange\n");168 return 0;169 }170 171 static nsresult OnStorageControllerChange(IConsoleCallback *pThis)172 {173 printf("OnStorageControllerChange\n");174 return 0;175 }176 177 static nsresult OnMediumChange(IConsoleCallback *pThis,178 IMediumAttachment *mediumAttachment)179 {180 printf("OnMediumChange\n");181 return 0;182 }183 184 static nsresult OnVRDPServerChange(IConsoleCallback *pThis )185 {186 printf("OnVRDPServerChange\n");187 return 0;188 }189 190 static nsresult OnUSBControllerChange(IConsoleCallback *pThis )191 {192 printf("OnUSBControllerChange\n");193 return 0;194 }195 196 static nsresult OnUSBDeviceStateChange(197 IConsoleCallback *pThis,198 IUSBDevice * device,199 PRBool attached,200 IVirtualBoxErrorInfo * error201 ) {202 printf("OnUSBDeviceStateChange\n");203 return 0;204 }205 206 static nsresult OnSharedFolderChange(207 IConsoleCallback *pThis,208 PRUint32 scope209 ) {210 printf("OnSharedFolderChange\n");211 return 0;212 }213 214 static nsresult OnRuntimeError(215 IConsoleCallback *pThis,216 PRBool fatal,217 PRUnichar * id,218 PRUnichar * message219 ) {220 printf("OnRuntimeError\n");221 return 0;222 }223 224 static nsresult OnCanShowWindow(225 IConsoleCallback *pThis,226 PRBool * canShow227 ) {228 printf("OnCanShowWindow\n");229 return 0;230 }231 232 static nsresult OnShowWindow(233 IConsoleCallback *pThis,234 PRUint64 * winId235 ) {236 printf("OnShowWindow\n");237 return 0;238 }239 240 216 241 217 static nsresult AddRef(nsISupports *pThis) … … 265 241 static nsresult QueryInterface(nsISupports *pThis, const nsID *iid, void **resultp) 266 242 { 267 static const nsID i virtualboxCallbackUUID = IVIRTUALBOXCALLBACK_IID;243 static const nsID ieventListenerUUID = IEVENTLISTENER_IID; 268 244 static const nsID isupportIID = NS_ISUPPORTS_IID; 269 245 270 246 /* match iid */ 271 if ( memcmp(iid, &i virtualboxCallbackUUID, sizeof(nsID)) == 0247 if ( memcmp(iid, &ieventListenerUUID, sizeof(nsID)) == 0 272 248 || memcmp(iid, &isupportIID, sizeof(nsID)) == 0) 273 249 { … … 278 254 } 279 255 280 /* printf(" vboxCallbackQueryInterface didn't find a matching interface\n"); */256 /* printf("event listener QueryInterface didn't find a matching interface\n"); */ 281 257 printUUID(iid); 282 printUUID(&i virtualboxCallbackUUID);258 printUUID(&ieventListenerUUID); 283 259 return NS_NOINTERFACE; 284 260 } 285 261 286 262 /** 287 * Signal callback.263 * Signal handler, terminate event listener. 288 264 * 289 265 * @param iSig The signal number (ignored). … … 297 273 298 274 /** 299 * Register callback functionsfor the selected VM.275 * Register event listener for the selected VM. 300 276 * 301 277 * @param virtualBox ptr to IVirtualBox object … … 304 280 * @param queue handle to the event queue 305 281 */ 306 static void register CallBack(IVirtualBox *virtualBox, ISession *session, PRUnichar *machineId, nsIEventQueue *queue)282 static void registerEventListener(IVirtualBox *virtualBox, ISession *session, PRUnichar *machineId, nsIEventQueue *queue) 307 283 { 308 284 IConsole *console = NULL; … … 312 288 if ((NS_SUCCEEDED(rc)) && console) 313 289 { 314 IConsoleCallback *consoleCallback = NULL; 315 316 consoleCallback = calloc(1, sizeof(IConsoleCallback)); 317 consoleCallback->vtbl = calloc(1, sizeof(struct IConsoleCallback_vtbl)); 318 319 if (consoleCallback && consoleCallback->vtbl) 320 { 321 consoleCallback->vtbl->nsisupports.AddRef = &AddRef; 322 consoleCallback->vtbl->nsisupports.Release = &Release; 323 consoleCallback->vtbl->nsisupports.QueryInterface = &QueryInterface; 324 consoleCallback->vtbl->OnMousePointerShapeChange = &OnMousePointerShapeChange; 325 consoleCallback->vtbl->OnMouseCapabilityChange = &OnMouseCapabilityChange; 326 consoleCallback->vtbl->OnKeyboardLedsChange =&OnKeyboardLedsChange; 327 consoleCallback->vtbl->OnStateChange = &OnStateChange; 328 consoleCallback->vtbl->OnAdditionsStateChange = &OnAdditionsStateChange; 329 consoleCallback->vtbl->OnNetworkAdapterChange = &OnNetworkAdapterChange; 330 consoleCallback->vtbl->OnSerialPortChange = &OnSerialPortChange; 331 consoleCallback->vtbl->OnParallelPortChange = &OnParallelPortChange; 332 consoleCallback->vtbl->OnStorageControllerChange = &OnStorageControllerChange; 333 consoleCallback->vtbl->OnMediumChange = &OnMediumChange; 334 consoleCallback->vtbl->OnVRDPServerChange = &OnVRDPServerChange; 335 consoleCallback->vtbl->OnUSBControllerChange = &OnUSBControllerChange; 336 consoleCallback->vtbl->OnUSBDeviceStateChange = &OnUSBDeviceStateChange; 337 consoleCallback->vtbl->OnSharedFolderChange = &OnSharedFolderChange; 338 consoleCallback->vtbl->OnRuntimeError = &OnRuntimeError; 339 consoleCallback->vtbl->OnCanShowWindow = &OnCanShowWindow; 340 consoleCallback->vtbl->OnShowWindow = &OnShowWindow; 341 g_refcount = 1; 342 343 rc = console->vtbl->RegisterCallback(console, consoleCallback); 344 if (NS_SUCCEEDED(rc)) 290 IEventSource *es = NULL; 291 rc = console->vtbl->GetEventSource(console, &es); 292 if (NS_SUCCEEDED(rc) && es) 293 { 294 PRUint32 interestingEvents[] = 295 { 296 VBoxEventType_OnMousePointerShapeChanged, 297 VBoxEventType_OnMouseCapabilityChanged, 298 VBoxEventType_OnKeyboardLedsChanged, 299 VBoxEventType_OnStateChanged, 300 VBoxEventType_OnAdditionsStateChanged, 301 VBoxEventType_OnNetworkAdapterChanged, 302 VBoxEventType_OnSerialPortChanged, 303 VBoxEventType_OnParallelPortChanged, 304 VBoxEventType_OnStorageControllerChanged, 305 VBoxEventType_OnMediumChanged, 306 VBoxEventType_OnVRDEServerChanged, 307 VBoxEventType_OnUSBControllerChanged, 308 VBoxEventType_OnUSBDeviceStateChanged, 309 VBoxEventType_OnSharedFolderChanged, 310 VBoxEventType_OnRuntimeError, 311 VBoxEventType_OnCanShowWindow, 312 VBoxEventType_OnShowWindow 313 }; 314 IEventListener *consoleListener = NULL; 315 consoleListener = calloc(1, sizeof(IEventListener)); 316 consoleListener->vtbl = calloc(1, sizeof(struct IEventListener_vtbl)); 317 318 if (consoleListener && consoleListener->vtbl) 345 319 { 346 /* crude way to show how it works, but any 347 * great ideas anyone? 348 */ 349 PRInt32 fd; 350 int ret; 351 352 printf("Entering event loop, PowerOff the machine to exit or press Ctrl-C to terminate\n"); 353 fflush(stdout); 354 signal(SIGINT, sigIntHandler); 355 356 fd = queue->vtbl->GetEventQueueSelectFD(queue); 357 if (fd >= 0) 320 consoleListener->vtbl->nsisupports.AddRef = &AddRef; 321 consoleListener->vtbl->nsisupports.Release = &Release; 322 consoleListener->vtbl->nsisupports.QueryInterface = &QueryInterface; 323 consoleListener->vtbl->HandleEvent = &HandleEvent; 324 g_refcount = 1; 325 326 rc = es->vtbl->RegisterListener(es, consoleListener, 327 sizeof(interestingEvents) / sizeof(interestingEvents[0]), 328 interestingEvents, 1 /* active */); 329 if (NS_SUCCEEDED(rc)) 358 330 { 359 while (!g_fStop) 331 /* crude way to show how it works, but any 332 * great ideas anyone? 333 */ 334 PRInt32 fd; 335 int ret; 336 337 printf("Entering event loop, PowerOff the machine to exit or press Ctrl-C to terminate\n"); 338 fflush(stdout); 339 signal(SIGINT, sigIntHandler); 340 341 fd = queue->vtbl->GetEventQueueSelectFD(queue); 342 if (fd >= 0) 360 343 { 361 struct pollfd pfd; 362 363 pfd.fd = fd; 364 pfd.events = POLLIN | POLLERR | POLLHUP; 365 pfd.revents = 0; 366 367 ret = poll(&pfd, 1, 250); 368 369 if (ret <= 0) 370 continue; 371 372 if (pfd.revents & POLLHUP) 373 g_fStop = 1; 374 375 queue->vtbl->ProcessPendingEvents(queue); 344 while (!g_fStop) 345 { 346 struct pollfd pfd; 347 348 pfd.fd = fd; 349 pfd.events = POLLIN | POLLERR | POLLHUP; 350 pfd.revents = 0; 351 352 ret = poll(&pfd, 1, 250); 353 354 if (ret <= 0) 355 continue; 356 357 if (pfd.revents & POLLHUP) 358 g_fStop = 1; 359 360 queue->vtbl->ProcessPendingEvents(queue); 361 } 376 362 } 363 else 364 { 365 while (!g_fStop) 366 { 367 PLEvent *pEvent = NULL; 368 rc = queue->vtbl->WaitForEvent(queue, &pEvent); 369 /*printf("event: %p rc=%x\n", (void *)pEvent, rc);*/ 370 if (NS_SUCCEEDED(rc)) 371 queue->vtbl->HandleEvent(queue, pEvent); 372 } 373 } 374 signal(SIGINT, SIG_DFL); 377 375 } 378 else 379 { 380 while (!g_fStop) 381 { 382 PLEvent *pEvent = NULL; 383 rc = queue->vtbl->WaitForEvent(queue, &pEvent); 384 /*printf("event: %p rc=%x\n", (void *)pEvent, rc);*/ 385 if (NS_SUCCEEDED(rc)) 386 queue->vtbl->HandleEvent(queue, pEvent); 387 } 388 } 389 signal(SIGINT, SIG_DFL); 376 es->vtbl->UnregisterListener(es, consoleListener); 377 consoleListener->vtbl->nsisupports.Release((nsISupports *)consoleListener); 390 378 } 391 console->vtbl->UnregisterCallback(console, consoleCallback); 392 consoleCallback->vtbl->nsisupports.Release((nsISupports *)consoleCallback); 379 else 380 { 381 printf("Failed while allocating memory for console event listener.\n"); 382 } 383 es->vtbl->nsisupports.Release((nsISupports *)es); 384 } 385 console->vtbl->nsisupports.Release((nsISupports *)console); 386 } 387 } 388 389 /** 390 * Start a VM. 391 * 392 * @param virtualBox ptr to IVirtualBox object 393 * @param session ptr to ISession object 394 * @param id identifies the machine to start 395 * @param queue handle to the event queue 396 */ 397 398 static void startVM(IVirtualBox *virtualBox, ISession *session, PRUnichar *id, nsIEventQueue *queue) 399 { 400 nsresult rc; 401 IMachine *machine = NULL; 402 IProgress *progress = NULL; 403 PRUnichar *env = NULL; 404 PRUnichar *sessionType; 405 406 rc = virtualBox->vtbl->FindMachine(virtualBox, id, &machine); 407 408 if (NS_FAILED(rc) || !machine) 409 { 410 fprintf(stderr, "Error: Couldn't get the machine handle.\n"); 411 return; 412 } 413 414 g_pVBoxFuncs->pfnUtf8ToUtf16("gui", &sessionType); 415 416 rc = machine->vtbl->LaunchVMProcess(machine, 417 session, 418 sessionType, 419 env, 420 &progress 421 ); 422 423 g_pVBoxFuncs->pfnUtf16Free(sessionType); 424 425 if (NS_FAILED(rc)) 426 { 427 fprintf(stderr, "Error: OpenRemoteSession failed.\n"); 428 } 429 else 430 { 431 PRBool completed; 432 PRInt32 resultCode; 433 434 printf("Waiting for the remote session to open...\n"); 435 progress->vtbl->WaitForCompletion(progress, -1); 436 437 rc = progress->vtbl->GetCompleted(progress, &completed); 438 if (NS_FAILED(rc)) 439 { 440 fprintf (stderr, "Error: GetCompleted status failed.\n"); 441 } 442 443 progress->vtbl->GetResultCode(progress, &resultCode); 444 if (NS_FAILED(resultCode)) 445 { 446 IVirtualBoxErrorInfo *errorInfo; 447 PRUnichar *textUtf16; 448 char *text; 449 450 progress->vtbl->GetErrorInfo(progress, &errorInfo); 451 errorInfo->vtbl->GetText(errorInfo, &textUtf16); 452 g_pVBoxFuncs->pfnUtf16ToUtf8(textUtf16, &text); 453 printf("Error: %s\n", text); 454 455 g_pVBoxFuncs->pfnComUnallocMem(textUtf16); 456 g_pVBoxFuncs->pfnUtf8Free(text); 393 457 } 394 458 else 395 459 { 396 printf("Failed while allocating memory for console Callback.\n"); 397 } 398 } 460 fprintf(stderr, "Remote session has been successfully opened.\n"); 461 registerEventListener(virtualBox, session, id, queue); 462 } 463 progress->vtbl->nsisupports.Release((nsISupports *)progress); 464 } 465 466 /* It's important to always release resources. */ 467 machine->vtbl->nsisupports.Release((nsISupports *)machine); 399 468 } 400 469 … … 515 584 printf("\tGuest OS: %s\n\n", osName); 516 585 517 osType->vtbl->nsisupports.Release(( void*)osType);586 osType->vtbl->nsisupports.Release((nsISupports *)osType); 518 587 g_pVBoxFuncs->pfnUtf8Free(osName); 519 588 g_pVBoxFuncs->pfnComUnallocMem(osNameUtf16); … … 559 628 } 560 629 } 561 }562 563 /**564 * Start a VM.565 *566 * @param virtualBox ptr to IVirtualBox object567 * @param session ptr to ISession object568 * @param id identifies the machine to start569 * @param queue handle to the event queue570 */571 572 static void startVM(IVirtualBox *virtualBox, ISession *session, PRUnichar *id, nsIEventQueue *queue)573 {574 nsresult rc;575 IMachine *machine = NULL;576 IProgress *progress = NULL;577 PRUnichar *env = NULL;578 PRUnichar *sessionType;579 580 rc = virtualBox->vtbl->GetMachine(virtualBox, id, &machine);581 582 if (NS_FAILED(rc) || !machine)583 {584 fprintf(stderr, "Error: Couldn't get the machine handle.\n");585 return;586 }587 588 g_pVBoxFuncs->pfnUtf8ToUtf16("gui", &sessionType);589 590 rc = virtualBox->vtbl->OpenRemoteSession(591 virtualBox,592 session,593 id,594 sessionType,595 env,596 &progress597 );598 599 g_pVBoxFuncs->pfnUtf16Free(sessionType);600 601 if (NS_FAILED(rc))602 {603 fprintf(stderr, "Error: OpenRemoteSession failed.\n");604 }605 else606 {607 PRBool completed;608 PRInt32 resultCode;609 610 printf("Waiting for the remote session to open...\n");611 progress->vtbl->WaitForCompletion(progress, -1);612 613 rc = progress->vtbl->GetCompleted(progress, &completed);614 if (NS_FAILED(rc))615 {616 fprintf (stderr, "Error: GetCompleted status failed.\n");617 }618 619 progress->vtbl->GetResultCode(progress, &resultCode);620 if (NS_FAILED(resultCode))621 {622 IVirtualBoxErrorInfo *errorInfo;623 PRUnichar *textUtf16;624 char *text;625 626 progress->vtbl->GetErrorInfo(progress, &errorInfo);627 errorInfo->vtbl->GetText(errorInfo, &textUtf16);628 g_pVBoxFuncs->pfnUtf16ToUtf8(textUtf16, &text);629 printf("Error: %s\n", text);630 631 g_pVBoxFuncs->pfnComUnallocMem(textUtf16);632 g_pVBoxFuncs->pfnUtf8Free(text);633 }634 else635 {636 fprintf(stderr, "Remote session has been successfully opened.\n");637 registerCallBack(virtualBox, session, id, queue);638 }639 progress->vtbl->nsisupports.Release((void *)progress);640 }641 642 /* It's important to always release resources. */643 machine->vtbl->nsisupports.Release((void *)machine);644 630 } 645 631 … … 743 729 744 730 listVMs(vbox, session, queue); 745 session->vtbl-> Close(session);731 session->vtbl->UnlockMachine(session); 746 732 747 733 printf("----------------------------------------------------\n"); -
trunk/src/VBox/Main/cbinding/tstXPCOMCGlue.c
r44529 r48225 7 7 8 8 /* 9 * Copyright (C) 2009-201 0Oracle Corporation9 * Copyright (C) 2009-2013 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 25 25 #include <string.h> 26 26 #include <stdlib.h> 27 28 static void listVMs(IVirtualBox *virtualBox, ISession *session);29 static void startVM(IVirtualBox *virtualBox, ISession *session, PRUnichar *id);30 31 /**32 * List the registered VMs.33 *34 * @param virtualBox ptr to IVirtualBox object35 * @param session ptr to ISession object36 */37 static void listVMs(IVirtualBox *virtualBox, ISession *session)38 {39 nsresult rc;40 IMachine **machines = NULL;41 PRUint32 machineCnt = 0;42 PRUint32 i;43 unsigned start_id;44 45 /*46 * Get the list of all registered VMs.47 */48 49 rc = virtualBox->vtbl->GetMachines(virtualBox, &machineCnt, &machines);50 if (NS_FAILED(rc))51 {52 fprintf(stderr, "could not get list of machines, rc=%08x\n",53 (unsigned)rc);54 return;55 }56 57 if (machineCnt == 0)58 {59 printf("\tNo VMs\n");60 return;61 }62 63 printf("VM List:\n\n");64 65 /*66 * Iterate through the collection.67 */68 69 for (i = 0; i < machineCnt; ++i)70 {71 IMachine *machine = machines[i];72 PRBool isAccessible = PR_FALSE;73 74 printf("\tMachine #%u\n", (unsigned)i);75 76 if (!machine)77 {78 printf("\t(skipped, NULL)\n");79 continue;80 }81 82 machine->vtbl->GetAccessible(machine, &isAccessible);83 84 if (isAccessible)85 {86 PRUnichar *machineNameUtf16;87 char *machineName;88 89 machine->vtbl->GetName(machine, &machineNameUtf16);90 g_pVBoxFuncs->pfnUtf16ToUtf8(machineNameUtf16,&machineName);91 printf("\tName: %s\n", machineName);92 93 g_pVBoxFuncs->pfnUtf8Free(machineName);94 g_pVBoxFuncs->pfnComUnallocMem(machineNameUtf16);95 }96 else97 {98 printf("\tName: <inaccessible>\n");99 }100 101 102 {103 PRUnichar *uuidUtf16 = NULL;104 char *uuidUtf8 = NULL;105 106 machine->vtbl->GetId(machine, &uuidUtf16);107 g_pVBoxFuncs->pfnUtf16ToUtf8(uuidUtf16, &uuidUtf8);108 printf("\tUUID: %s\n", uuidUtf8);109 110 g_pVBoxFuncs->pfnUtf8Free(uuidUtf8);111 g_pVBoxFuncs->pfnUtf16Free(uuidUtf16);112 }113 114 if (isAccessible)115 {116 {117 PRUnichar *configFile;118 char *configFile1 = calloc((size_t)64, (size_t)1);119 120 machine->vtbl->GetSettingsFilePath(machine, &configFile);121 g_pVBoxFuncs->pfnUtf16ToUtf8(configFile, &configFile1);122 printf("\tConfig file: %s\n", configFile1);123 124 free(configFile1);125 g_pVBoxFuncs->pfnComUnallocMem(configFile);126 }127 128 {129 PRUint32 memorySize;130 131 machine->vtbl->GetMemorySize(machine, &memorySize);132 printf("\tMemory size: %uMB\n", memorySize);133 }134 135 {136 PRUnichar *typeId;137 PRUnichar *osNameUtf16;138 char *osName;139 IGuestOSType *osType = NULL;140 141 machine->vtbl->GetOSTypeId(machine, &typeId);142 virtualBox->vtbl->GetGuestOSType(virtualBox, typeId, &osType);143 osType->vtbl->GetDescription(osType, &osNameUtf16);144 g_pVBoxFuncs->pfnUtf16ToUtf8(osNameUtf16,&osName);145 printf("\tGuest OS: %s\n\n", osName);146 147 osType->vtbl->nsisupports.Release((void *)osType);148 g_pVBoxFuncs->pfnUtf8Free(osName);149 g_pVBoxFuncs->pfnComUnallocMem(osNameUtf16);150 g_pVBoxFuncs->pfnComUnallocMem(typeId);151 }152 }153 }154 155 /*156 * Let the user chose a machine to start.157 */158 159 printf("Type Machine# to start (0 - %u) or 'quit' to do nothing: ",160 (unsigned)(machineCnt - 1));161 fflush(stdout);162 163 if (scanf("%u", &start_id) == 1 && start_id < machineCnt)164 {165 IMachine *machine = machines[start_id];166 167 if (machine)168 {169 PRUnichar *uuidUtf16 = NULL;170 171 machine->vtbl->GetId(machine, &uuidUtf16);172 startVM(virtualBox, session, uuidUtf16);173 174 g_pVBoxFuncs->pfnUtf16Free(uuidUtf16);175 }176 }177 178 /*179 * Don't forget to release the objects in the array.180 */181 182 for (i = 0; i < machineCnt; ++i)183 {184 IMachine *machine = machines[i];185 186 if (machine)187 {188 machine->vtbl->nsisupports.Release((void *)machine);189 }190 }191 }192 27 193 28 /** … … 262 97 fprintf(stderr, "Remote session has been successfully opened.\n"); 263 98 } 264 progress->vtbl->nsisupports.Release(( void*)progress);99 progress->vtbl->nsisupports.Release((nsISupports *)progress); 265 100 } 266 101 267 102 /* It's important to always release resources. */ 268 machine->vtbl->nsisupports.Release((void *)machine); 103 machine->vtbl->nsisupports.Release((nsISupports *)machine); 104 } 105 106 /** 107 * List the registered VMs. 108 * 109 * @param virtualBox ptr to IVirtualBox object 110 * @param session ptr to ISession object 111 */ 112 static void listVMs(IVirtualBox *virtualBox, ISession *session) 113 { 114 nsresult rc; 115 IMachine **machines = NULL; 116 PRUint32 machineCnt = 0; 117 PRUint32 i; 118 unsigned start_id; 119 120 /* 121 * Get the list of all registered VMs. 122 */ 123 124 rc = virtualBox->vtbl->GetMachines(virtualBox, &machineCnt, &machines); 125 if (NS_FAILED(rc)) 126 { 127 fprintf(stderr, "could not get list of machines, rc=%08x\n", 128 (unsigned)rc); 129 return; 130 } 131 132 if (machineCnt == 0) 133 { 134 printf("\tNo VMs\n"); 135 return; 136 } 137 138 printf("VM List:\n\n"); 139 140 /* 141 * Iterate through the collection. 142 */ 143 144 for (i = 0; i < machineCnt; ++i) 145 { 146 IMachine *machine = machines[i]; 147 PRBool isAccessible = PR_FALSE; 148 149 printf("\tMachine #%u\n", (unsigned)i); 150 151 if (!machine) 152 { 153 printf("\t(skipped, NULL)\n"); 154 continue; 155 } 156 157 machine->vtbl->GetAccessible(machine, &isAccessible); 158 159 if (isAccessible) 160 { 161 PRUnichar *machineNameUtf16; 162 char *machineName; 163 164 machine->vtbl->GetName(machine, &machineNameUtf16); 165 g_pVBoxFuncs->pfnUtf16ToUtf8(machineNameUtf16,&machineName); 166 printf("\tName: %s\n", machineName); 167 168 g_pVBoxFuncs->pfnUtf8Free(machineName); 169 g_pVBoxFuncs->pfnComUnallocMem(machineNameUtf16); 170 } 171 else 172 { 173 printf("\tName: <inaccessible>\n"); 174 } 175 176 { 177 PRUnichar *uuidUtf16 = NULL; 178 char *uuidUtf8 = NULL; 179 180 machine->vtbl->GetId(machine, &uuidUtf16); 181 g_pVBoxFuncs->pfnUtf16ToUtf8(uuidUtf16, &uuidUtf8); 182 printf("\tUUID: %s\n", uuidUtf8); 183 184 g_pVBoxFuncs->pfnUtf8Free(uuidUtf8); 185 g_pVBoxFuncs->pfnUtf16Free(uuidUtf16); 186 } 187 188 if (isAccessible) 189 { 190 { 191 PRUnichar *configFile; 192 char *configFile1 = calloc((size_t)64, (size_t)1); 193 194 machine->vtbl->GetSettingsFilePath(machine, &configFile); 195 g_pVBoxFuncs->pfnUtf16ToUtf8(configFile, &configFile1); 196 printf("\tConfig file: %s\n", configFile1); 197 198 free(configFile1); 199 g_pVBoxFuncs->pfnComUnallocMem(configFile); 200 } 201 202 { 203 PRUint32 memorySize; 204 205 machine->vtbl->GetMemorySize(machine, &memorySize); 206 printf("\tMemory size: %uMB\n", memorySize); 207 } 208 209 { 210 PRUnichar *typeId; 211 PRUnichar *osNameUtf16; 212 char *osName; 213 IGuestOSType *osType = NULL; 214 215 machine->vtbl->GetOSTypeId(machine, &typeId); 216 virtualBox->vtbl->GetGuestOSType(virtualBox, typeId, &osType); 217 osType->vtbl->GetDescription(osType, &osNameUtf16); 218 g_pVBoxFuncs->pfnUtf16ToUtf8(osNameUtf16,&osName); 219 printf("\tGuest OS: %s\n\n", osName); 220 221 osType->vtbl->nsisupports.Release((nsISupports *)osType); 222 g_pVBoxFuncs->pfnUtf8Free(osName); 223 g_pVBoxFuncs->pfnComUnallocMem(osNameUtf16); 224 g_pVBoxFuncs->pfnComUnallocMem(typeId); 225 } 226 } 227 } 228 229 /* 230 * Let the user chose a machine to start. 231 */ 232 233 printf("Type Machine# to start (0 - %u) or 'quit' to do nothing: ", 234 (unsigned)(machineCnt - 1)); 235 fflush(stdout); 236 237 if (scanf("%u", &start_id) == 1 && start_id < machineCnt) 238 { 239 IMachine *machine = machines[start_id]; 240 241 if (machine) 242 { 243 PRUnichar *uuidUtf16 = NULL; 244 245 machine->vtbl->GetId(machine, &uuidUtf16); 246 startVM(virtualBox, session, uuidUtf16); 247 248 g_pVBoxFuncs->pfnUtf16Free(uuidUtf16); 249 } 250 } 251 252 /* 253 * Don't forget to release the objects in the array. 254 */ 255 256 for (i = 0; i < machineCnt; ++i) 257 { 258 IMachine *machine = machines[i]; 259 260 if (machine) 261 { 262 machine->vtbl->nsisupports.Release((nsISupports *)machine); 263 } 264 } 269 265 } 270 266 … … 273 269 int main(int argc, char **argv) 274 270 { 275 IVirtualBox *vbox = NULL;271 IVirtualBox *vbox = NULL; 276 272 ISession *session = NULL; 277 273 PRUint32 revision = 0;
Note:
See TracChangeset
for help on using the changeset viewer.