VirtualBox

Changeset 51503 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Jun 3, 2014 7:24:46 AM (11 years ago)
Author:
vboxsync
Message:

Additions/common/VBoxService: make most service call-back functions optional.

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp

    r50051 r51503  
    490490        if (!g_aServices[j].fPreInited)
    491491        {
    492             int rc = g_aServices[j].pDesc->pfnPreInit();
    493             if (RT_FAILURE(rc))
    494                 return VBoxServiceError("Service '%s' failed pre-init: %Rrc\n", g_aServices[j].pDesc->pszName, rc);
     492            if (g_aServices[j].pDesc->pfnPreInit != NULL)
     493            {
     494                int rc = g_aServices[j].pDesc->pfnPreInit();
     495                if (RT_FAILURE(rc))
     496                    return VBoxServiceError("Service '%s' failed pre-init: %Rrc\n",
     497                                            g_aServices[j].pDesc->pszName, rc);
     498            }
    495499            g_aServices[j].fPreInited = true;
    496500        }
     
    556560    VBoxServiceVerbose(2, "Initializing services ...\n");
    557561    for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
    558         if (g_aServices[j].fEnabled)
     562        if (g_aServices[j].fEnabled && g_aServices[j].pDesc->pfnInit != NULL)
    559563        {
    560564            rc = g_aServices[j].pDesc->pfnInit();
     
    601605         * to exit the loop before we skipped the fShutdown check
    602606         * below the service will fail to start! */
     607        /** @todo This presumably means either a one-shot service or that
     608         * something has gone wrong.  In the second case treating it as failure
     609         * to start is probably right, so we need a way to signal the first. */
    603610        RTThreadUserWait(g_aServices[j].Thread, 60 * 1000);
    604611        if (g_aServices[j].fShutdown)
     
    640647     */
    641648    for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
    642         if (g_aServices[j].fStarted)
     649        if (g_aServices[j].fStarted && g_aServices[j].pDesc->pfnStop != NULL)
    643650        {
    644651            VBoxServiceVerbose(3, "Calling stop function for service '%s' ...\n", g_aServices[j].pDesc->pszName);
     
    656663        if (!g_aServices[j].fEnabled) /* Only stop services which were started before. */
    657664            continue;
    658         if (g_aServices[j].Thread != NIL_RTTHREAD)
     665        if (   g_aServices[j].Thread != NIL_RTTHREAD
     666            && g_aServices[j].pDesc->pfnStop != NULL)
    659667        {
    660668            VBoxServiceVerbose(2, "Waiting for service '%s' to stop ...\n", g_aServices[j].pDesc->pszName);
     
    676684            }
    677685        }
    678         VBoxServiceVerbose(3, "Terminating service '%s' (%d) ...\n", g_aServices[j].pDesc->pszName, j);
    679         g_aServices[j].pDesc->pfnTerm();
     686        if (g_aServices[j].pDesc->pfnTerm != NULL)
     687        {
     688            VBoxServiceVerbose(3, "Terminating service '%s' (%d) ...\n",
     689                               g_aServices[j].pDesc->pszName, j);
     690            g_aServices[j].pDesc->pfnTerm();
     691        }
    680692    }
    681693
     
    906918                    for (unsigned j = 0; !fFound && j < RT_ELEMENTS(g_aServices); j++)
    907919                    {
     920                        if (g_aServices[j].pDesc->pfnOption == NULL)
     921                            continue;
    908922                        rc = g_aServices[j].pDesc->pfnOption(NULL, argc, argv, &i);
    909923                        fFound = rc == VINF_SUCCESS;
     
    977991                    for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
    978992                    {
     993                        if (g_aServices[j].pDesc->pfnOption == NULL)
     994                            continue;
    979995                        rc = g_aServices[j].pDesc->pfnOption(&psz, argc, argv, &i);
    980996                        fFound = rc == VINF_SUCCESS;
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp

    r50461 r51503  
    6868/** The Shared Folders service client ID. */
    6969static uint32_t         g_SharedFoldersSvcClientID = 0;
    70 
    71 /** @copydoc VBOXSERVICE::pfnPreInit */
    72 static DECLCALLBACK(int) VBoxServiceAutoMountPreInit(void)
    73 {
    74     return VINF_SUCCESS;
    75 }
    76 
    77 
    78 /** @copydoc VBOXSERVICE::pfnOption */
    79 static DECLCALLBACK(int) VBoxServiceAutoMountOption(const char **ppszShort, int argc, char **argv, int *pi)
    80 {
    81     NOREF(ppszShort);
    82     NOREF(argc);
    83     NOREF(argv);
    84     NOREF(pi);
    85 
    86     return -1;
    87 }
    88 
    8970
    9071/** @copydoc VBOXSERVICE::pfnInit */
     
    618599    NULL,
    619600    /* methods */
    620     VBoxServiceAutoMountPreInit,
    621     VBoxServiceAutoMountOption,
     601    /* pfnPreInit */
     602    NULL,
     603    /* pfnOption */
     604    NULL,
    622605    VBoxServiceAutoMountInit,
    623606    VBoxServiceAutoMountWorker,
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceBalloon.cpp

    r44528 r51503  
    224224
    225225    return VINF_SUCCESS;
    226 }
    227 
    228 
    229 /** @copydoc VBOXSERVICE::pfnPreInit */
    230 static DECLCALLBACK(int) VBoxServiceBalloonPreInit(void)
    231 {
    232     return VINF_SUCCESS;
    233 }
    234 
    235 
    236 /** @copydoc VBOXSERVICE::pfnOption */
    237 static DECLCALLBACK(int) VBoxServiceBalloonOption(const char **ppszShort, int argc, char **argv, int *pi)
    238 {
    239     NOREF(ppszShort);
    240     NOREF(argc);
    241     NOREF(argv);
    242     NOREF(pi);
    243 
    244     return -1;
    245226}
    246227
     
    396377}
    397378
    398 /** @copydoc VBOXSERVICE::pfnTerm */
    399 static DECLCALLBACK(void) VBoxServiceBalloonTerm(void)
    400 {
    401     VBoxServiceVerbose(3, "VBoxServiceBalloonTerm\n");
    402     return;
    403 }
    404 
    405379
    406380/** @copydoc VBOXSERVICE::pfnStop */
     
    425399    NULL,
    426400    /* methods */
    427     VBoxServiceBalloonPreInit,
    428     VBoxServiceBalloonOption,
     401    /* pfnPreInit */
     402    NULL,
     403    /* pfnOption */
     404    NULL,
    429405    VBoxServiceBalloonInit,
    430406    VBoxServiceBalloonWorker,
    431407    VBoxServiceBalloonStop,
    432     VBoxServiceBalloonTerm
     408    /* pfnTerm */
     409    NULL
    433410};
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceCpuHotPlug.cpp

    r50286 r51503  
    395395}
    396396#endif /* RT_OS_LINUX */
    397 
    398 
    399 /** @copydoc VBOXSERVICE::pfnPreInit */
    400 static DECLCALLBACK(int) VBoxServiceCpuHotPlugPreInit(void)
    401 {
    402     return VINF_SUCCESS;
    403 }
    404 
    405 
    406 /** @copydoc VBOXSERVICE::pfnOption */
    407 static DECLCALLBACK(int) VBoxServiceCpuHotPlugOption(const char **ppszShort, int argc, char **argv, int *pi)
    408 {
    409     NOREF(ppszShort);
    410     NOREF(argc);
    411     NOREF(argv);
    412     NOREF(pi);
    413 
    414     return -1;
    415 }
    416 
    417 
    418 /** @copydoc VBOXSERVICE::pfnInit */
    419 static DECLCALLBACK(int) VBoxServiceCpuHotPlugInit(void)
    420 {
    421     return VINF_SUCCESS;
    422 }
    423397
    424398
     
    620594
    621595
    622 /** @copydoc VBOXSERVICE::pfnTerm */
    623 static DECLCALLBACK(void) VBoxServiceCpuHotPlugTerm(void)
    624 {
    625     return;
    626 }
    627 
    628 
    629596/**
    630597 * The 'timesync' service description.
     
    641608    NULL,
    642609    /* methods */
    643     VBoxServiceCpuHotPlugPreInit,
    644     VBoxServiceCpuHotPlugOption,
    645     VBoxServiceCpuHotPlugInit,
     610    /* pfnPreInit */
     611    NULL,
     612    /* pfnOption */
     613    NULL,
     614    /* pnfInit */
     615    NULL,
    646616    VBoxServiceCpuHotPlugWorker,
    647617    VBoxServiceCpuHotPlugStop,
    648     VBoxServiceCpuHotPlugTerm
     618    /* pfnTerm */
     619    NULL
    649620};
    650621
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h

    r47335 r51503  
    4646
    4747    /**
    48      * Called before parsing arguments.
     48     * Called before parsing arguments.  Optional.
    4949     * @returns VBox status code.
    5050     */
     
    5252
    5353    /**
    54      * Tries to parse the given command line option.
     54     * Tries to parse the given command line option.  Optional.
    5555     *
    5656     * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
     
    6464
    6565    /**
    66      * Called before parsing arguments.
     66     * Called before parsing arguments.  Optional.
    6767     * @returns VBox status code.
    6868     */
     
    7979
    8080    /**
    81      * Stop an service.
     81     * Stop an service.  If the service can safely be stopped at any time this
     82     * may be left NULL.
    8283     */
    8384    DECLCALLBACKMEMBER(void, pfnStop)(void);
    8485
    8586    /**
    86      * Does termination cleanups.
     87     * Does termination cleanups.  Optional.
    8788     *
    8889     * @remarks This may be called even if pfnInit hasn't been called!
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServicePageSharing.cpp

    r46593 r51503  
    525525#endif
    526526
    527 /** @copydoc VBOXSERVICE::pfnPreInit */
    528 static DECLCALLBACK(int) VBoxServicePageSharingPreInit(void)
    529 {
    530     return VINF_SUCCESS;
    531 }
    532 
    533 
    534 /** @copydoc VBOXSERVICE::pfnOption */
    535 static DECLCALLBACK(int) VBoxServicePageSharingOption(const char **ppszShort, int argc, char **argv, int *pi)
    536 {
    537     NOREF(ppszShort);
    538     NOREF(argc);
    539     NOREF(argv);
    540     NOREF(pi);
    541 
    542     return -1;
    543 }
    544 
    545 
    546527/** @copydoc VBOXSERVICE::pfnInit */
    547528static DECLCALLBACK(int) VBoxServicePageSharingInit(void)
     
    731712#endif /* RT_OS_WINDOWS */
    732713
    733 /** @copydoc VBOXSERVICE::pfnTerm */
    734 static DECLCALLBACK(void) VBoxServicePageSharingTerm(void)
    735 {
    736     VBoxServiceVerbose(3, "VBoxServicePageSharingTerm\n");
    737 }
    738 
    739 
    740714/** @copydoc VBOXSERVICE::pfnStop */
    741715static DECLCALLBACK(void) VBoxServicePageSharingStop(void)
     
    759733    NULL,
    760734    /* methods */
    761     VBoxServicePageSharingPreInit,
    762     VBoxServicePageSharingOption,
     735    /* pfnPreInit */
     736    NULL,
     737    /* pfnOption */
     738    NULL,
    763739    VBoxServicePageSharingInit,
    764740#ifdef RT_OS_WINDOWS
     
    768744#endif
    769745    VBoxServicePageSharingStop,
    770     VBoxServicePageSharingTerm
     746    /* pfnTerm */
     747    NULL
    771748};
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp

    r48311 r51503  
    8383/** The semaphore we're blocking on. */
    8484static RTSEMEVENTMULTI  g_VMStatEvent = NIL_RTSEMEVENTMULTI;
    85 
    86 
    87 /** @copydoc VBOXSERVICE::pfnPreInit */
    88 static DECLCALLBACK(int) VBoxServiceVMStatsPreInit(void)
    89 {
    90     return VINF_SUCCESS;
    91 }
    92 
    93 
    94 /** @copydoc VBOXSERVICE::pfnOption */
    95 static DECLCALLBACK(int) VBoxServiceVMStatsOption(const char **ppszShort, int argc, char **argv, int *pi)
    96 {
    97     NOREF(ppszShort);
    98     NOREF(argc);
    99     NOREF(argv);
    100     NOREF(pi);
    101 
    102     return -1;
    103 }
    10485
    10586
     
    681662
    682663
    683 /** @copydoc VBOXSERVICE::pfnTerm */
    684 static DECLCALLBACK(void) VBoxServiceVMStatsTerm(void)
    685 {
    686     VBoxServiceVerbose(3, "VBoxServiceVMStatsTerm\n");
    687     return;
    688 }
    689 
    690 
    691664/** @copydoc VBOXSERVICE::pfnStop */
    692665static DECLCALLBACK(void) VBoxServiceVMStatsStop(void)
     
    710683    NULL,
    711684    /* methods */
    712     VBoxServiceVMStatsPreInit,
    713     VBoxServiceVMStatsOption,
     685    /* pfnPreInit */
     686    NULL,
     687    /* pfnOption */
     688    NULL,
    714689    VBoxServiceVMStatsInit,
    715690    VBoxServiceVMStatsWorker,
    716691    VBoxServiceVMStatsStop,
    717     VBoxServiceVMStatsTerm
     692    /* pfnTerm */
     693    NULL
    718694};
    719695
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r50571 r51503  
    155155
    156156
    157 /** @copydoc VBOXSERVICE::pfnPreInit */
    158 static DECLCALLBACK(int) VBoxServiceVMInfoPreInit(void)
    159 {
    160     return VINF_SUCCESS;
    161 }
    162 
    163 
    164157/** @copydoc VBOXSERVICE::pfnOption */
    165158static DECLCALLBACK(int) VBoxServiceVMInfoOption(const char **ppszShort, int argc, char **argv, int *pi)
     
    15921585    ,
    15931586    /* methods */
    1594     VBoxServiceVMInfoPreInit,
     1587    /* pfnPreInit */
     1588    NULL,
    15951589    VBoxServiceVMInfoOption,
    15961590    VBoxServiceVMInfoInit,
Note: See TracChangeset for help on using the changeset viewer.

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