tstHeadless.cpp revision bd8e360cd1db83dcb2694ea9122ce3bc5bae678a
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * VBox frontends: VBoxHeadless frontend:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Copyright (C) 2006-2007 innotek GmbH
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * This file is part of VirtualBox Open Source Edition (OSE), as
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * available from http://www.virtualbox.org. This file is free software;
ed22c7109fc5dd9e1b7a5d0333bdc7ad2718e2abYuri Pankov * you can redistribute it and/or modify it under the terms of the GNU
ed22c7109fc5dd9e1b7a5d0333bdc7ad2718e2abYuri Pankov * General Public License (GPL) as published by the Free Software
ed22c7109fc5dd9e1b7a5d0333bdc7ad2718e2abYuri Pankov * Foundation, in version 2 as it comes in the "COPYING" file of the
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Loweusing namespace com;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe////////////////////////////////////////////////////////////////////////////////
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Entry point.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe // initialize VBox Runtime
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe // the below cannot be Bstr because on Linux Bstr doesn't work
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe // until XPCOM (nsMemory) is initialized
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe // parse the command line
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "%s <machine_name> [on|off|pause|resume]\n\n",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "Operation : %s\n\n",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CHECK_ERROR_NI_BREAK (virtualBox.createLocalObject (CLSID_VirtualBox));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CHECK_ERROR_NI_BREAK (session.createInprocObject (CLSID_Session));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe // create the event queue
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe // (here it is necessary only to process remaining XPCOM/IPC events
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe // after the session is closed)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe // find ID by name
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CHECK_ERROR_BREAK (virtualBox, FindMachine (Bstr (name), m.asOutParam()));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CHECK_ERROR_BREAK (m, COMGETTER(Id) (id.asOutParam()));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe RTPrintf ("Opening a new (remote) session...\n");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe RTPrintf ("Waiting for the remote session to open...\n");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CHECK_ERROR_BREAK (progress, COMGETTER(Completed) (&completed));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CHECK_ERROR_BREAK (progress, COMGETTER(ResultCode) (&resultCode));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe COMGETTER(ErrorInfo) (errorInfo.asOutParam()));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe RTPrintf ("Remote session has been successfully opened.\n");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CHECK_ERROR_BREAK (virtualBox, OpenExistingSession (session, id));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe CHECK_ERROR_BREAK (session, COMGETTER (Console) (console.asOutParam()));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe RTPrintf ("Closing the session (may fail after power off)...\n");