tstXPCOMCCall.c revision f60ec22bd796760b850219cbfc447acd8231ab84
/* $Revision$ */
/** @file tstXPCOMCGlue.c
* Demonstrator program to illustrate use of C bindings of Main API.
*
* Linux only at the moment due to shared library magic in the Makefile.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxXPCOMCGlue.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
static void registerCallBack(IVirtualBox *virtualBox, ISession *session, nsID *machineId, nsIEventQueue *queue);
int volatile g_refcount = 0;
/**
* Helper function to convert an nsID into a human readable string.
*
* @returns result string, allocated. Has to be freed using free()
* @param guid Pointer to nsID that will be converted.
*/
{
/* Avoid magic number 39. Yes, sizeof "literal" includes the NUL byte. */
{
}
return res;
}
/**
* Callback functions
*/
{
switch (machineState)
{
case MachineState_Null: return "<null>";
case MachineState_PoweredOff: return "PoweredOff";
case MachineState_Saved: return "Saved";
case MachineState_Aborted: return "Aborted";
case MachineState_Running: return "Running";
case MachineState_Paused: return "Paused";
case MachineState_Stuck: return "Stuck";
case MachineState_Starting: return "Starting";
case MachineState_Stopping: return "Stopping";
case MachineState_Saving: return "Saving";
case MachineState_Restoring: return "Restoring";
case MachineState_Discarding: return "Discarding";
case MachineState_SettingUp: return "SettingUp";
default: return "no idea";
}
}
static nsresult OnMousePointerShapeChange(
) {
printf("OnMousePointerShapeChange\n");
return 0;
}
static nsresult OnMouseCapabilityChange(
) {
printf("OnMouseCapabilityChange\n");
return 0;
}
static nsresult OnKeyboardLedsChange(
) {
printf("OnMouseCapabilityChange\n");
return 0;
}
static nsresult OnStateChange(
) {
return 0;
}
{
printf("OnAdditionsStateChange\n");
return 0;
}
{
printf("OnDVDDriveChange \n");
return 0;
}
{
printf("OnFloppyDriveChange \n");
return 0;
}
static nsresult OnNetworkAdapterChange(
) {
printf("OnNetworkAdapterChange\n");
return 0;
}
static nsresult OnSerialPortChange(
) {
printf("OnSerialPortChange\n");
return 0;
}
static nsresult OnParallelPortChange(
) {
printf("OnParallelPortChange\n");
return 0;
}
{
printf("OnStorageControllerChange\n");
return 0;
}
{
printf("OnVRDPServerChange\n");
return 0;
}
{
printf("OnUSBControllerChange\n");
return 0;
}
static nsresult OnUSBDeviceStateChange(
IUSBDevice * device,
) {
printf("OnUSBDeviceStateChange\n");
return 0;
}
static nsresult OnSharedFolderChange(
) {
printf("OnSharedFolderChange\n");
return 0;
}
static nsresult OnRuntimeError(
) {
printf("OnRuntimeError\n");
return 0;
}
static nsresult OnCanShowWindow(
) {
printf("OnCanShowWindow\n");
return 0;
}
static nsresult OnShowWindow(
) {
printf("OnShowWindow\n");
return 0;
}
{
nsresult c;
printf("AddRef\n");
c = g_refcount++;
return c;
}
{
nsresult c;
printf("Release\n");
c = g_refcount--;
if (c == 0)
{
/* delete object */
}
return c;
}
{
printf("QueryInterface\n");
/* match iid */
g_refcount++;
return 0;
}
/**
* Register callback functions for the selected VM.
*
* @param virtualBox ptr to IVirtualBox object
* @param session ptr to ISession object
* @param id identifies the machine to start
* @param queue handle to the event queue
*/
static void registerCallBack(IVirtualBox *virtualBox, ISession *session, nsID *machineId, nsIEventQueue *queue)
{
if (console) {
g_refcount = 1;
{
/* crude way to show how it works, but any
* great ideas anyone?
*/
int run = 10000000;
while (run-- > 0) {
}
}
}
}
}
/**
* List the registered VMs.
*
* @param virtualBox ptr to IVirtualBox object
* @param session ptr to ISession object
* @param queue handle to the event queue
*/
{
PRUint32 machineCnt = 0;
PRUint32 i;
unsigned start_id;
/*
* Get the list of all registered VMs.
*/
{
(unsigned)rc);
return;
}
if (machineCnt == 0)
{
printf("\tNo VMs\n");
return;
}
printf("VM List:\n\n");
/*
* Iterate through the collection.
*/
for (i = 0; i < machineCnt; ++i)
{
printf("\tMachine #%u\n", (unsigned)i);
if (!machine)
{
printf("\t(skipped, NULL)\n");
continue;
}
if (isAccessible)
{
char *machineName;
}
else
{
printf("\tName: <inaccessible>\n");
}
{
char *uuidString;
}
if (isAccessible)
{
{
}
{
}
{
char *osName;
}
}
}
/*
* Let the user chose a machine to start.
*/
printf("Type Machine# to start (0 - %u) or 'quit' to do nothing: ",
(unsigned)(machineCnt - 1));
{
if (machine)
{
}
}
/*
* Don't forget to release the objects in the array.
*/
for (i = 0; i < machineCnt; ++i)
{
if (machine)
{
}
}
}
/**
* Start a VM.
*
* @param virtualBox ptr to IVirtualBox object
* @param session ptr to ISession object
* @param id identifies the machine to start
* @param queue handle to the event queue
*/
{
{
return;
}
id,
env,
);
{
}
else
{
printf("Waiting for the remote session to open...\n");
{
}
if (NS_FAILED(resultCode))
{
char *text;
}
else
{
}
}
/* It's important to always release resources. */
}
/* Main - Start the ball rolling. */
{
printf("Starting Main\n");
/*
* VBoxComInitialize does all the necessary startup action and
* provides us with pointers to vbox and session handles.
* It should be matched by a call to VBoxComUninitialize(vbox)
* when done.
*/
if (VBoxCGlueInit() != 0)
{
return EXIT_FAILURE;
}
{
return EXIT_FAILURE;
}
{
return EXIT_FAILURE;
}
/*
* Now ask for revision, version and home folder information of
* this vbox. Were not using fancy macros here so it
* remains easy to see how we access C++'s vtable.
*/
printf("----------------------------------------------------\n");
/* 1. Revision */
if (NS_SUCCEEDED(rc))
{
}
else
{
}
/* 2. Version */
if (NS_SUCCEEDED(rc))
{
}
else
{
}
/* 3. Home Folder */
if (NS_SUCCEEDED(rc))
{
char *homefolder = NULL;
}
else
{
}
printf("----------------------------------------------------\n");
/*
* Do as mom told us: always clean up after yourself.
*/
printf("Finished Main\n");
return 0;
}
/* vim: set ts=4 sw=4 et: */