VirtualBox

Changeset 10931 in vbox


Ignore:
Timestamp:
Jul 29, 2008 1:26:38 PM (17 years ago)
Author:
vboxsync
Message:

Additions/common: added guest property enumeration to VBoxControl

File:
1 edited

Legend:

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

    r10859 r10931  
    3030#include <iprt/path.h>
    3131#include <iprt/initterm.h>
     32#include <iprt/autores>
    3233#include <VBox/log.h>
    3334#include <VBox/VBoxGuest.h>
     
    106107    {
    107108        doUsage("get <property> [-verbose]\n", g_pszProgName, "guestproperty");
    108         doUsage("set <property> [<value>] [--flags <flags>]\n", g_pszProgName, "guestproperty");
     109        doUsage("set <property> [<value>] [-flags <flags>]\n", g_pszProgName, "guestproperty");
     110        doUsage("enumerate [-patterns <patterns>]\n", g_pszProgName, "guestproperty");
    109111    }
    110112#endif
     
    891893 * Here we actually retrieve the value from the host.
    892894 */
    893     void *pvBuf = NULL;
    894895    const char *pszName = argv[0];
    895896    char *pszValue = NULL;
    896897    uint64_t u64Timestamp = 0;
    897898    char *pszFlags = NULL;
     899    /* The buffer for storing the data and its initial size.  We leave a bit
     900     * of space here in case the maximum values are raised. */
     901    void *pvBuf = NULL;
     902    uint32_t cbBuf = MAX_VALUE_LEN + MAX_FLAGS_LEN + 1024;
    898903    if (RT_SUCCESS(rc))
    899904    {
     
    903908         * enough with buffer space. */
    904909        bool finish = false;
    905         /* We leave a bit of space here in case the maximum values are raised. */
    906         uint32_t cbBuf = MAX_VALUE_LEN + MAX_FLAGS_LEN + 1024;
    907910        for (unsigned i = 0; (i < 10) && !finish; ++i)
    908911        {
     
    10231026
    10241027/**
     1028 * Enumerates the properties in the guest property store.
     1029 * This is accessed through the "VBoxGuestPropSvc" HGCM service.
     1030 *
     1031 * @returns 0 on success, 1 on failure
     1032 * @note see the command line API description for parameters
     1033 */
     1034static int enumGuestProperty(int argc, char *argv[])
     1035{
     1036/*
     1037 * Check the syntax.  We can deduce the correct syntax from the number of
     1038 * arguments.
     1039 */
     1040    const char *paszPatterns = NULL;
     1041    if ((argc > 1) && (0 == strcmp(argv[0], "-patterns")))
     1042        paszPatterns = argv[1];
     1043    else if (argc != 0)
     1044    {
     1045        usage(GUEST_PROP);
     1046        return 1;
     1047    }
     1048
     1049/*
     1050 * Do the actual enumeration.
     1051 */
     1052    uint32_t u32ClientId = 0;
     1053    PVBGLR3GUESTPROPENUM pHandleRaw = NULL;
     1054    RTMemAutoPtr<VBGLR3GUESTPROPENUM, VbglR3GuestPropEnumFree> pHandle;
     1055    char *pszName = NULL, *pszValue = NULL, *pszFlags = NULL;
     1056    uint64_t u64Timestamp = 0;
     1057    int rc = VINF_SUCCESS;
     1058    rc = VbglR3GuestPropConnect(&u32ClientId);
     1059    if (!RT_SUCCESS(rc))
     1060        VBoxControlError("Failed to connect to the guest property service, error %Rrc\n", rc);
     1061    if (RT_SUCCESS(rc))
     1062    {
     1063        char **ppaszPatterns = argc > 1 ? argv + 1 : NULL;
     1064        int cPatterns = argc > 1 ? argc - 1 : 0;
     1065        rc = VbglR3GuestPropEnum(u32ClientId, ppaszPatterns, cPatterns, &pHandleRaw,
     1066                                 &pszName, &pszValue, &u64Timestamp, &pszFlags);
     1067        if (RT_SUCCESS(rc))
     1068        {
     1069            pHandle = pHandleRaw;
     1070        }
     1071        else if (VERR_NOT_FOUND == rc)
     1072            RTPrintf("No properties found.\n");
     1073        else
     1074            VBoxControlError("Failed to enumerate the guest properties, error %Rrc.\n", rc);
     1075    }
     1076    while (RT_SUCCESS(rc) && (pszName != NULL))
     1077    {
     1078        RTPrintf("Name: %s, value: %s, timestamp: %lld, flags: %s\n",
     1079                 pszName, pszValue, u64Timestamp, pszFlags);
     1080        rc = VbglR3GuestPropEnumNext(pHandle.get(), &pszName, &pszValue, &u64Timestamp, &pszFlags);
     1081        if (!RT_SUCCESS(rc))
     1082            VBoxControlError("Error while enumerating guest propertied: %Rrc\n", rc);
     1083    }
     1084
     1085    if (u32ClientId != 0)
     1086        VbglR3GuestPropDisconnect(u32ClientId);
     1087    return RT_SUCCESS(rc) ? 0 : 1;
     1088}
     1089
     1090
     1091/**
    10251092 * Access the guest property store through the "VBoxGuestPropSvc" HGCM
    10261093 * service.
     
    10401107    else if (0 == strcmp(argv[0], "set"))
    10411108        return setGuestProperty(argc - 1, argv + 1);
     1109    else if (0 == strcmp(argv[0], "enumerate"))
     1110        return enumGuestProperty(argc - 1, argv + 1);
    10421111    /* else */
    10431112    usage(GUEST_PROP);
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