VirtualBox

Changeset 26322 in vbox


Ignore:
Timestamp:
Feb 8, 2010 11:08:02 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57403
Message:

Frontends/VBoxSDL+VBoxHeadless: code cleanup, reorganize code a little.

Location:
trunk/src/VBox/Frontends
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp

    r26089 r26322  
    7171#define LogError(m,rc) \
    7272    do { \
    73         Log (("VBoxHeadless: ERROR: " m " [rc=0x%08X]\n", rc)); \
    74         RTPrintf ("%s\n", m); \
     73        Log(("VBoxHeadless: ERROR: " m " [rc=0x%08X]\n", rc)); \
     74        RTPrintf("%s\n", m); \
    7575    } while (0)
    7676
     
    9090{
    9191public:
    92     StateChangeEvent (MachineState_T state) : mState (state) {}
     92    StateChangeEvent(MachineState_T state) : mState(state) {}
    9393protected:
    9494    void *handler()
    9595    {
    96         LogFlow (("VBoxHeadless: StateChangeEvent: %d\n", mState));
     96        LogFlow(("VBoxHeadless: StateChangeEvent: %d\n", mState));
    9797        /* post the termination event if the machine has been PoweredDown/Saved/Aborted */
    9898        if (mState < MachineState_Running)
    99             gEventQ->postEvent (NULL);
     99            gEventQ->postEvent(NULL);
    100100        return 0;
    101101    }
     
    275275public:
    276276
    277     ConsoleCallback ()
     277    ConsoleCallback()
    278278    {
    279279#ifndef VBOX_WITH_XPCOM
     
    302302    VBOX_SCRIPTABLE_DISPATCH_IMPL(IConsoleCallback)
    303303
    304     STDMETHOD(OnMousePointerShapeChange) (BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
    305                                           ULONG width, ULONG height, BYTE *shape)
    306     {
    307         return S_OK;
    308     }
    309 
    310     STDMETHOD(OnMouseCapabilityChange) (BOOL supportsAbsolute, BOOL needsHostCursor)
     304    STDMETHOD(OnMousePointerShapeChange)(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
     305                                         ULONG width, ULONG height, BYTE *shape)
     306    {
     307        return S_OK;
     308    }
     309
     310    STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL needsHostCursor)
    311311    {
    312312        /* Emit absolute mouse event to actually enable the host mouse cursor. */
     
    328328    }
    329329
    330     STDMETHOD(OnStateChange) (MachineState_T machineState)
    331     {
    332         gEventQ->postEvent (new StateChangeEvent (machineState));
    333         return S_OK;
    334     }
    335 
    336     STDMETHOD(OnExtraDataChange) (BSTR key)
     330    STDMETHOD(OnStateChange)(MachineState_T machineState)
     331    {
     332        gEventQ->postEvent(new StateChangeEvent(machineState));
     333        return S_OK;
     334    }
     335
     336    STDMETHOD(OnExtraDataChange)(BSTR key)
    337337    {
    338338        return S_OK;
     
    344344    }
    345345
    346     STDMETHOD(OnNetworkAdapterChange) (INetworkAdapter *aNetworkAdapter)
    347     {
    348         return S_OK;
    349     }
    350 
    351     STDMETHOD(OnSerialPortChange) (ISerialPort *aSerialPort)
    352     {
    353         return S_OK;
    354     }
    355 
    356     STDMETHOD(OnParallelPortChange) (IParallelPort *aParallelPort)
     346    STDMETHOD(OnNetworkAdapterChange)(INetworkAdapter *aNetworkAdapter)
     347    {
     348        return S_OK;
     349    }
     350
     351    STDMETHOD(OnSerialPortChange)(ISerialPort *aSerialPort)
     352    {
     353        return S_OK;
     354    }
     355
     356    STDMETHOD(OnParallelPortChange)(IParallelPort *aParallelPort)
    357357    {
    358358        return S_OK;
     
    412412    }
    413413
    414     STDMETHOD(OnUSBDeviceStateChange) (IUSBDevice *aDevice, BOOL aAttached,
     414    STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *aDevice, BOOL aAttached,
    415415                                      IVirtualBoxErrorInfo *aError)
    416416    {
     
    418418    }
    419419
    420     STDMETHOD(OnSharedFolderChange) (Scope_T aScope)
     420    STDMETHOD(OnSharedFolderChange)(Scope_T aScope)
    421421    {
    422422        return S_OK;
     
    437437    }
    438438
    439     STDMETHOD(OnShowWindow) (ULONG64 *winId)
     439    STDMETHOD(OnShowWindow)(ULONG64 *winId)
    440440    {
    441441        /* OnCanShowWindow() always returns FALSE, so this call should never
     
    457457
    458458#ifdef VBOX_WITH_XPCOM
    459 NS_DECL_CLASSINFO (VirtualBoxCallback)
    460 NS_IMPL_THREADSAFE_ISUPPORTS1_CI (VirtualBoxCallback, IVirtualBoxCallback)
    461 NS_DECL_CLASSINFO (ConsoleCallback)
    462 NS_IMPL_THREADSAFE_ISUPPORTS1_CI (ConsoleCallback, IConsoleCallback)
     459NS_DECL_CLASSINFO(VirtualBoxCallback)
     460NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VirtualBoxCallback, IVirtualBoxCallback)
     461NS_DECL_CLASSINFO(ConsoleCallback)
     462NS_IMPL_THREADSAFE_ISUPPORTS1_CI(ConsoleCallback, IConsoleCallback)
    463463#endif
    464464
     
    597597 *  Entry point.
    598598 */
    599 extern "C" DECLEXPORT (int) TrustedMain (int argc, char **argv, char **envp)
     599extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
    600600{
    601601#ifdef VBOX_WITH_VRDP
     
    862862        {
    863863            ComPtr <IMachine> m;
    864             rc = virtualBox->FindMachine (Bstr (name), m.asOutParam());
    865             if (FAILED (rc))
    866             {
    867                 LogError ("Invalid machine name!\n", rc);
    868                 break;
    869             }
    870             m->COMGETTER(Id) (id.asOutParam());
    871             AssertComRC (rc);
    872             if (FAILED (rc))
    873                 break;
    874         }
    875 
    876         Log (("VBoxHeadless: Opening a session with machine (id={%s})...\n",
     864            rc = virtualBox->FindMachine(Bstr(name), m.asOutParam());
     865            if (FAILED(rc))
     866            {
     867                LogError("Invalid machine name!\n", rc);
     868                break;
     869            }
     870            m->COMGETTER(Id)(id.asOutParam());
     871            AssertComRC(rc);
     872            if (FAILED(rc))
     873                break;
     874        }
     875
     876        Log(("VBoxHeadless: Opening a session with machine (id={%s})...\n",
    877877              Utf8Str(id).raw()));
    878878
    879879        // open a session
    880         CHECK_ERROR_BREAK(virtualBox, OpenSession (session, id));
     880        CHECK_ERROR_BREAK(virtualBox, OpenSession(session, id));
    881881        fSessionOpened = true;
    882882
    883883        /* get the console */
    884884        ComPtr <IConsole> console;
    885         CHECK_ERROR_BREAK(session, COMGETTER (Console) (console.asOutParam()));
     885        CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam()));
    886886
    887887        /* get the machine */
    888888        ComPtr <IMachine> machine;
    889         CHECK_ERROR_BREAK(console, COMGETTER(Machine) (machine.asOutParam()));
     889        CHECK_ERROR_BREAK(console, COMGETTER(Machine)(machine.asOutParam()));
    890890
    891891        ComPtr <IDisplay> display;
    892         CHECK_ERROR_BREAK(console, COMGETTER(Display) (display.asOutParam()));
     892        CHECK_ERROR_BREAK(console, COMGETTER(Display)(display.asOutParam()));
    893893
    894894#ifdef VBOX_FFMPEG
     
    923923                             "you wish to use is supported on your system\n", rcc);
    924924            }
    925             if (RT_SUCCESS(rrc) && (S_OK == rcc))
     925            if (RT_SUCCESS(rrc) && (rcc == S_OK))
    926926            {
    927927                Log2(("VBoxHeadless: Registering framebuffer\n"));
     
    952952            }
    953953#endif /* defined(VBOX_FFMPEG) */
    954             VRDPFramebuffer *pVRDPFramebuffer = new VRDPFramebuffer ();
     954            VRDPFramebuffer *pVRDPFramebuffer = new VRDPFramebuffer();
    955955            if (!pVRDPFramebuffer)
    956956            {
     
    10271027        /* register a callback for machine events */
    10281028        {
    1029             ConsoleCallback *callback = new ConsoleCallback ();
     1029            ConsoleCallback *callback = new ConsoleCallback();
    10301030            callback->AddRef();
    1031             CHECK_ERROR(console, RegisterCallback (callback));
     1031            CHECK_ERROR(console, RegisterCallback(callback));
    10321032            callback->Release();
    1033             if (FAILED (rc))
     1033            if (FAILED(rc))
    10341034                break;
    10351035        }
     
    10401040        BOOL fVRDPEnabled;
    10411041        ComPtr <IVRDPServer> vrdpServer;
    1042         CHECK_ERROR_BREAK(machine, COMGETTER (VRDPServer) (vrdpServer.asOutParam()));
    1043         CHECK_ERROR_BREAK(vrdpServer, COMGETTER(Enabled) (&fVRDPEnabled));
     1042        CHECK_ERROR_BREAK(machine, COMGETTER(VRDPServer)(vrdpServer.asOutParam()));
     1043        CHECK_ERROR_BREAK(vrdpServer, COMGETTER(Enabled)(&fVRDPEnabled));
    10441044
    10451045        if (vrdpEnabled != NULL)
     
    10621062        if (fVRDPEnable)
    10631063        {
    1064             Log (("VBoxHeadless: Enabling VRDP server...\n"));
     1064            Log(("VBoxHeadless: Enabling VRDP server...\n"));
    10651065
    10661066            /* set VRDP port if requested by the user */
     
    10781078            if (!fVRDPEnabled)
    10791079            {
    1080                 CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled) (TRUE));
     1080                CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled)(TRUE));
    10811081            }
    10821082        }
     
    10861086            if (fVRDPEnabled)
    10871087            {
    1088                 CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled) (FALSE));
    1089             }
    1090         }
    1091 #endif
    1092         Log (("VBoxHeadless: Powering up the machine...\n"));
     1088                CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled)(FALSE));
     1089            }
     1090        }
     1091#endif
     1092        Log(("VBoxHeadless: Powering up the machine...\n"));
    10931093
    10941094        ComPtr <IProgress> progress;
    1095         CHECK_ERROR_BREAK(console, PowerUp (progress.asOutParam()));
     1095        CHECK_ERROR_BREAK(console, PowerUp(progress.asOutParam()));
    10961096
    10971097        /* wait for result because there can be errors */
    1098         if (SUCCEEDED(progress->WaitForCompletion (-1)))
     1098        if (SUCCEEDED(progress->WaitForCompletion(-1)))
    10991099        {
    11001100            LONG progressRc;
     
    11201120#endif
    11211121
    1122         Log (("VBoxHeadless: Waiting for PowerDown...\n"));
     1122        Log(("VBoxHeadless: Waiting for PowerDown...\n"));
    11231123
    11241124        Event *e;
    11251125
    1126         while (gEventQ->waitForEvent (&e) && e)
    1127           gEventQ->handleEvent (e);
    1128 
    1129         Log (("VBoxHeadless: event loop has terminated...\n"));
     1126        while (gEventQ->waitForEvent(&e) && e)
     1127          gEventQ->handleEvent(e);
     1128
     1129        Log(("VBoxHeadless: event loop has terminated...\n"));
    11301130
    11311131#ifdef VBOX_FFMPEG
    11321132        if (pFramebuffer)
    11331133        {
    1134             pFramebuffer->Release ();
     1134            pFramebuffer->Release();
    11351135            Log(("Released framebuffer\n"));
    11361136            pFramebuffer = NULL;
     
    11511151         * unregister the callback we've registered before.
    11521152         */
    1153         Log (("VBoxHeadless: Closing the session...\n"));
     1153        Log(("VBoxHeadless: Closing the session...\n"));
    11541154        session->Close();
    11551155    }
     
    11611161    com::Shutdown();
    11621162
    1163     LogFlow (("VBoxHeadless FINISHED.\n"));
     1163    LogFlow(("VBoxHeadless FINISHED.\n"));
    11641164
    11651165    return rc;
     
    11711171 * Main entry point.
    11721172 */
    1173 int main (int argc, char **argv, char **envp)
     1173int main(int argc, char **argv, char **envp)
    11741174{
    11751175    // initialize VBox Runtime
     
    11911191    }
    11921192
    1193     return TrustedMain (argc, argv, envp);
     1193    return TrustedMain(argc, argv, envp);
    11941194}
    11951195#endif /* !VBOX_WITH_HARDENING */
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r26089 r26322  
    991991    }
    992992
    993     rc = com::Initialize();
    994     if (FAILED(rc))
    995     {
    996         RTPrintf("Error: COM initialization failed, rc = 0x%x!\n", rc);
    997         return 1;
    998     }
    999 
    1000     do
    1001     {
    1002     // scopes all the stuff till shutdown
    1003     ////////////////////////////////////////////////////////////////////////////
    1004 
    1005     ComPtr <IVirtualBox> virtualBox;
    1006     ComPtr <ISession> session;
    1007     bool sessionOpened = false;
    1008 
    1009     rc = virtualBox.createLocalObject (CLSID_VirtualBox);
    1010     if (FAILED(rc))
    1011     {
    1012         com::ErrorInfo info;
    1013         if (info.isFullAvailable())
    1014             PrintError("Failed to create VirtualBox object",
    1015                        info.getText().raw(), info.getComponent().raw());
    1016         else
    1017             RTPrintf("Failed to create VirtualBox object! No error information available (rc = 0x%x).\n", rc);
    1018         break;
    1019     }
    1020     rc = session.createInprocObject (CLSID_Session);
    1021     if (FAILED(rc))
    1022     {
    1023         RTPrintf("Failed to create session object, rc = 0x%x!\n", rc);
    1024         break;
    1025     }
    1026 
    1027     EventQueue* eventQ = com::EventQueue::getMainEventQueue();
    1028 
    1029     /* Get the number of network adapters */
    1030     ULONG NetworkAdapterCount = 0;
    1031     ComPtr <ISystemProperties> sysInfo;
    1032     virtualBox->COMGETTER(SystemProperties) (sysInfo.asOutParam());
    1033     sysInfo->COMGETTER (NetworkAdapterCount) (&NetworkAdapterCount);
    1034 
    1035993    // command line argument parsing stuff
    1036994    for (int curArg = 1; curArg < argc; curArg++)
     
    10461004            {
    10471005                RTPrintf("Error: VM not specified (UUID or name)!\n");
    1048                 rc = E_FAIL;
    1049                 break;
     1006                return 1;
    10501007            }
    10511008            // first check if a UUID was supplied
     
    10621019            {
    10631020                RTPrintf("Error: missing argument for comment!\n");
    1064                 rc = E_FAIL;
    1065                 break;
     1021                return 1;
    10661022            }
    10671023        }
     
    10721028            {
    10731029                RTPrintf("Error: missing argument for boot drive!\n");
    1074                 rc = E_FAIL;
    1075                 break;
     1030                return 1;
    10761031            }
    10771032            switch (argv[curArg][0])
     
    11041059                {
    11051060                    RTPrintf("Error: wrong argument for boot drive!\n");
    1106                     rc = E_FAIL;
    1107                     break;
     1061                    return 1;
    11081062                }
    11091063            }
    1110             if (FAILED (rc))
    1111                 break;
    11121064        }
    11131065        else if (   !strcmp(argv[curArg], "--memory")
     
    11181070            {
    11191071                RTPrintf("Error: missing argument for memory size!\n");
    1120                 rc = E_FAIL;
    1121                 break;
     1072                return 1;
    11221073            }
    11231074            memorySize = atoi(argv[curArg]);
     
    11291080            {
    11301081                RTPrintf("Error: missing argument for vram size!\n");
    1131                 rc = E_FAIL;
    1132                 break;
     1082                return 1;
    11331083            }
    11341084            vramSize = atoi(argv[curArg]);
     
    11541104            {
    11551105                RTPrintf("Error: missing arguments for fixed video mode!\n");
    1156                 rc = E_FAIL;
    1157                 break;
     1106                return 1;
    11581107            }
    11591108            fixedWidth  = atoi(argv[++curArg]);
     
    11831132            {
    11841133                RTPrintf("Error: missing a string of disabled hostkey combinations\n");
    1185                 rc = E_FAIL;
    1186                 break;
     1134                return 1;
    11871135            }
    11881136            gHostKeyDisabledCombinations = argv[curArg];
     
    11941142                    RTPrintf("Error: <hostkey> + '%c' is not a valid combination\n",
    11951143                             gHostKeyDisabledCombinations[i]);
    1196                     rc = E_FAIL;
    1197                     break;
     1144                    return 1;
    11981145                }
    11991146            }
    1200             if (rc == E_FAIL)
    1201                 break;
    12021147        }
    12031148        else if (   !strcmp(argv[curArg], "--nograbonclick")
     
    12171162            {
    12181163                RTPrintf("Error: missing file name for --pidfile!\n");
    1219                 rc = E_FAIL;
    1220                 break;
     1164                return 1;
    12211165            }
    12221166            gpszPidFile = argv[curArg];
     
    12281172            {
    12291173                RTPrintf("Error: missing file name for first hard disk!\n");
    1230                 rc = E_FAIL;
    1231                 break;
     1174                return 1;
    12321175            }
    12331176            /* resolve it. */
     
    12371180            {
    12381181                RTPrintf("Error: The path to the specified harddisk, '%s', could not be resolved.\n", argv[curArg]);
    1239                 rc = E_FAIL;
    1240                 break;
     1182                return 1;
    12411183            }
    12421184        }
     
    12471189            {
    12481190                RTPrintf("Error: missing file/device name for first floppy disk!\n");
    1249                 rc = E_FAIL;
    1250                 break;
     1191                return 1;
    12511192            }
    12521193            /* resolve it. */
     
    12561197            {
    12571198                RTPrintf("Error: The path to the specified floppy disk, '%s', could not be resolved.\n", argv[curArg]);
    1258                 rc = E_FAIL;
    1259                 break;
     1199                return 1;
    12601200            }
    12611201        }
     
    12661206            {
    12671207                RTPrintf("Error: missing file/device name for cdrom!\n");
    1268                 rc = E_FAIL;
    1269                 break;
     1208                return 1;
    12701209            }
    12711210            /* resolve it. */
     
    12751214            {
    12761215                RTPrintf("Error: The path to the specified cdrom, '%s', could not be resolved.\n", argv[curArg]);
    1277                 rc = E_FAIL;
    1278                 break;
     1216                return 1;
    12791217            }
    12801218        }
     
    13201258            {
    13211259                RTPrintf("Error: missing font file name for secure label!\n");
    1322                 rc = E_FAIL;
    1323                 break;
     1260                return 1;
    13241261            }
    13251262            secureLabelFontFile = argv[curArg];
     
    13311268            {
    13321269                RTPrintf("Error: missing font point size for secure label!\n");
    1333                 rc = E_FAIL;
    1334                 break;
     1270                return 1;
    13351271            }
    13361272            secureLabelPointSize = atoi(argv[curArg]);
     
    13421278            {
    13431279                RTPrintf("Error: missing font pixel offset for secure label!\n");
    1344                 rc = E_FAIL;
    1345                 break;
     1280                return 1;
    13461281            }
    13471282            secureLabelFontOffs = atoi(argv[curArg]);
     
    13531288            {
    13541289                RTPrintf("Error: missing text color value for secure label!\n");
    1355                 rc = E_FAIL;
    1356                 break;
     1290                return 1;
    13571291            }
    13581292            sscanf(argv[curArg], "%X", &secureLabelColorFG);
     
    13641298            {
    13651299                RTPrintf("Error: missing background color value for secure label!\n");
    1366                 rc = E_FAIL;
    1367                 break;
     1300                return 1;
    13681301            }
    13691302            sscanf(argv[curArg], "%X", &secureLabelColorBG);
     
    14071340            {
    14081341                RTPrintf("Error: missing the rate value for the --warpdrive option!\n");
    1409                 rc = E_FAIL;
    1410                 break;
     1342                return 1;
    14111343            }
    14121344            u32WarpDrive = RTStrToUInt32(argv[curArg]);
     
    14141346            {
    14151347                RTPrintf("Error: the warp drive rate is restricted to [2..20000]. (%d)\n", u32WarpDrive);
    1416                 rc = E_FAIL;
    1417                 break;
     1348                return 1;
    14181349            }
    14191350        }
     
    14331364            {
    14341365                RTPrintf("Error: not enough arguments for host keys!\n");
    1435                 rc = E_FAIL;
    1436                 break;
     1366                return 1;
    14371367            }
    14381368            gHostKeySym1 = atoi(argv[curArg++]);
     
    14551385        }
    14561386    }
     1387
     1388    rc = com::Initialize();
    14571389    if (FAILED(rc))
     1390    {
     1391        RTPrintf("Error: COM initialization failed, rc = 0x%x!\n", rc);
     1392        return 1;
     1393    }
     1394
     1395    do
     1396    {
     1397    // scopes all the stuff till shutdown
     1398    ////////////////////////////////////////////////////////////////////////////
     1399
     1400    ComPtr <IVirtualBox> virtualBox;
     1401    ComPtr <ISession> session;
     1402    bool sessionOpened = false;
     1403
     1404    rc = virtualBox.createLocalObject (CLSID_VirtualBox);
     1405    if (FAILED(rc))
     1406    {
     1407        com::ErrorInfo info;
     1408        if (info.isFullAvailable())
     1409            PrintError("Failed to create VirtualBox object",
     1410                       info.getText().raw(), info.getComponent().raw());
     1411        else
     1412            RTPrintf("Failed to create VirtualBox object! No error information available (rc = 0x%x).\n", rc);
    14581413        break;
     1414    }
     1415    rc = session.createInprocObject (CLSID_Session);
     1416    if (FAILED(rc))
     1417    {
     1418        RTPrintf("Failed to create session object, rc = 0x%x!\n", rc);
     1419        break;
     1420    }
     1421
     1422    EventQueue* eventQ = com::EventQueue::getMainEventQueue();
    14591423
    14601424    /*
     
    29222886    LogFlow(("Returning from main()!\n"));
    29232887    RTLogFlush(NULL);
    2924     return FAILED (rc) ? 1 : 0;
     2888    return FAILED(rc) ? 1 : 0;
    29252889}
    29262890
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette