VirtualBox

Changeset 28967 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
May 3, 2010 11:44:28 AM (15 years ago)
Author:
vboxsync
Message:

VBoxService: Introduced guest property cache (used by VM information thread). Not tested yet.

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
2 added
6 edited

Legend:

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

    r28800 r28967  
    5555        VBoxServiceTimeSync.cpp \
    5656        VBoxServiceUtils.cpp \
    57         VBoxServiceStats.cpp
     57        VBoxServiceStats.cpp \
     58        VBoxServicePropCache.cpp
    5859ifdef VBOX_WITH_GUEST_CONTROL
    5960 VBoxService_SOURCES    += \
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp

    r28887 r28967  
    590590    if (iMain == ~0U)
    591591        return VBoxServiceSyntax("At least one service must be enabled.\n");
    592 
    593592#ifndef RT_OS_WINDOWS
    594593    /*
     
    652651    }
    653652#endif
    654 
    655653#ifdef RT_OS_WINDOWS
    656654    /*
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp

    r28887 r28967  
    339339
    340340        if (pNext && RTListNodeIsLast(&g_GuestControlExecThreads, &pNext->Node))
    341               break;
     341            break;
    342342
    343343        pNode = pNext;
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h

    r28943 r28967  
    213213/** Pointer to a standard input buffer. */
    214214typedef VBOXSERVICECTRLSTDINBUF *PVBOXSERVICECTRLSTDINBUF;
    215 #endif
     215#endif /* VBOX_WITH_GUEST_CONTROL */
     216
     217#ifdef VBOX_WITH_GUEST_PROPS
     218/**
     219 * A guest propertiy cache.
     220 */
     221typedef struct
     222{   
     223    /** The client ID for HGCM communication. */
     224    uint32_t uClientID;
     225    RTLISTNODE Node;
     226} VBOXSERVICEVEPROPCACHE;
     227/** Pointer to a guest property cache. */
     228typedef VBOXSERVICEVEPROPCACHE *PVBOXSERVICEVEPROPCACHE;
     229
     230/**
     231 * Handling guest properties used by the VM information service.
     232 */
     233typedef struct
     234{   
     235    /** Node. */
     236    RTLISTNODE Node;
     237    /** Name (and full path) of guest property. */
     238    char    *pszName;
     239    /** The last value stored (for reference). */
     240    char    *pszValue;
     241    /** Reset value to write if property is temporary. */
     242    char    *pszValueReset;
     243    /** Flags. */
     244    uint32_t uFlags;
     245} VBOXSERVICEVEPROPCACHEENTRY;
     246/** Pointer to a cached guest property. */
     247typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
     248#endif /* VBOX_WITH_GUEST_PROPS */
    216249
    217250RT_C_DECLS_BEGIN
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp

    r28800 r28967  
    183183    return rc;
    184184}
    185 
    186185#endif /* VBOX_WITH_GUEST_PROPS */
    187186#ifdef RT_OS_WINDOWS
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r28800 r28967  
    5454#include "VBoxServiceInternal.h"
    5555#include "VBoxServiceUtils.h"
     56#include "VBoxServicePropCache.h"
    5657
    5758
     
    6061*******************************************************************************/
    6162/** The vminfo interval (millseconds). */
    62 uint32_t                g_VMInfoInterval = 0;
     63uint32_t                        g_VMInfoInterval = 0;
    6364/** The semaphore we're blocking on. */
    64 static RTSEMEVENTMULTI  g_VMInfoEvent = NIL_RTSEMEVENTMULTI;
     65static RTSEMEVENTMULTI          g_VMInfoEvent = NIL_RTSEMEVENTMULTI;
    6566/** The guest property service client ID. */
    66 static uint32_t         g_VMInfoGuestPropSvcClientID = 0;
     67static uint32_t                 g_VMInfoGuestPropSvcClientID = 0;
    6768/** Number of logged in users in OS. */
    68 static uint32_t         g_cVMInfoLoggedInUsers = UINT32_MAX;
     69static uint32_t                 g_cVMInfoLoggedInUsers = UINT32_MAX;
     70/** The guest property cache. */
     71static VBOXSERVICEVEPROPCACHE   g_VMInfoPropCache;
    6972
    7073
     
    124127    }
    125128
     129    if (RT_SUCCESS(rc))
     130    {
     131        VBoxServicePropCacheInit(&g_VMInfoPropCache, g_VMInfoGuestPropSvcClientID);
     132
     133        VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count",
     134                                     VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, "0", "0");
     135        VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList",
     136                                     VBOXSERVICEPROPCACHEFLAG_TEMPORARY, NULL, NULL);
     137        VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsers",
     138                                     VBOXSERVICEPROPCACHEFLAG_TEMPORARY, "0", "0");
     139        VBoxServicePropCacheUpdateEx(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers",
     140                                     VBOXSERVICEPROPCACHEFLAG_TEMPORARY, "true", "true");
     141    }
    126142    return rc;
    127143}
     
    306322
    307323        if (cUsersInList > 0)
    308             VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", "%s", szUserList);
     324            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", "%s", szUserList);
    309325        else
    310             VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", NULL);
    311         VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/LoggedInUsers", "%u", cUsersInList);
     326            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", NULL);
     327        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsers", "%u", cUsersInList);
    312328        if (   g_cVMInfoLoggedInUsers != cUsersInList
    313329            || g_cVMInfoLoggedInUsers == UINT32_MAX)
    314330        {
    315             /* Update this property ONLY if there is a real change from no users to
     331            /*
     332             * Update this property ONLY if there is a real change from no users to
    316333             * users or vice versa. The only exception is that the initialization
    317334             * forces an update, but only once. This ensures consistent property
    318              * settings even if the VM aborted previously. */
     335             * settings even if the VM aborted previously.
     336             */
    319337            if (cUsersInList == 0)
    320                 VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", "true");
     338                VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", "true");
    321339            else if (g_cVMInfoLoggedInUsers == 0)
    322                 VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", "false");
     340                VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", "false");
    323341        }
    324342        g_cVMInfoLoggedInUsers = cUsersInList;
     
    383401         * properties are no longer valid.
    384402         */
    385         VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/Net/Count", "%d",
    386                               nNumInterfaces > 1 ? nNumInterfaces-1 : 0);
     403        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count", "%d",
     404                                   nNumInterfaces > 1 ? nNumInterfaces-1 : 0);
    387405
    388406        /** @todo Use GetAdaptersInfo() and GetAdapterAddresses (IPv4 + IPv6) for more information. */
     
    409427            Assert(pAddress);
    410428            RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/IP", iCurIface);
    411             VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
     429            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    412430
    413431#ifdef RT_OS_WINDOWS
     
    422440#endif
    423441            RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Broadcast", iCurIface);
    424             VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
     442            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    425443
    426444#ifdef RT_OS_WINDOWS
     
    440458#endif
    441459            RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/V4/Netmask", iCurIface);
    442             VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
     460            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    443461
    444462            RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%d/Status", iCurIface);
    445             VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, szPropPath,
    446                                   nFlags & IFF_UP ? "Up" : "Down");
    447 
     463            VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath,
     464                                       nFlags & IFF_UP ? "Up" : "Down");
    448465            iCurIface++;
    449466        }
     
    496513    if (g_VMInfoEvent != NIL_RTSEMEVENTMULTI)
    497514    {
    498         /** @todo temporary solution: Zap all values which are not valid
    499          *        anymore when VM goes down (reboot/shutdown ). Needs to
    500          *        be replaced with "temporary properties" later.
    501          *
    502          *        One idea is to introduce a (HGCM-)session guest property
    503          *        flag meaning that a guest property is only valid as long
    504          *        as the HGCM session isn't closed (e.g. guest application
    505          *        terminates).
    506          */
    507         rc = VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", NULL);
    508         rc = VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/LoggedInUsers", "%d", 0);
    509         if (g_cVMInfoLoggedInUsers > 0)
    510             VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", "true");
    511 
     515        /* Delete the "../Net" branch. */
    512516        const char *apszPat[1] = { "/VirtualBox/GuestInfo/Net/*" };
    513517        rc = VbglR3GuestPropDelSet(g_VMInfoGuestPropSvcClientID, &apszPat[0], RT_ELEMENTS(apszPat));
    514         rc = VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/Net/Count", "%d", 0);
     518
     519        /* Destroy property cache. */
     520        VBoxServicePropCacheDestroy(&g_VMInfoPropCache);
    515521
    516522        /* Disconnect from guest properties service. */
     
    519525            VBoxServiceError("Failed to disconnect from guest property service! Error: %Rrc\n", rc);
    520526        g_VMInfoGuestPropSvcClientID = 0;
    521 
    522527
    523528        RTSemEventMultiDestroy(g_VMInfoEvent);
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