VirtualBox

Changeset 10826

Show
Ignore:
Timestamp:
07/23/08 12:08:59 (1 month ago)
Author:
vboxsync
Message:

Frontends/VBoxManage: switched VBoxManage to use the new guest property syntax

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r10797 r10826  
    653653 
    654654#ifdef VBOX_WITH_GUEST_PROPS 
    655     if (u64Cmd & USAGE_GETGUESTPROPERTY) 
    656     { 
    657         RTPrintf("VBoxManage getguestproperty <vmname>|<uuid> <key>\n" 
     655    if (u64Cmd & USAGE_GUESTPROPERTY) 
     656    { 
     657        RTPrintf("VBoxManage guestproperty    get <vmname>|<uuid>\n" 
     658                 "                            <property> [-verbose]\n" 
    658659                 "\n"); 
    659     } 
    660  
    661     if (u64Cmd & USAGE_SETGUESTPROPERTY) 
    662     { 
    663         RTPrintf("VBoxManage setguestproperty <vmname>|<uuid> <key>\n" 
    664                  "                            [<value>] (no value deletes key)\n" 
     660        RTPrintf("VBoxManage guestproperty    set <vmname>|<uuid>\n" 
     661                 "                            <property> [<value>] [-flags <flags>]\n" 
    665662                 "\n"); 
    666663    } 
     
    75987595    HRESULT rc = S_OK; 
    75997596 
    7600     if (argc != 2) 
    7601         return errorSyntax(USAGE_GETGUESTPROPERTY, "Incorrect number of parameters"); 
     7597    bool verbose = false; 
     7598    if ((3 == argc) && (0 == strcmp(argv[2], "-verbose"))) 
     7599        verbose = true; 
     7600    else if (argc != 2) 
     7601        return errorSyntax(USAGE_GUESTPROPERTY, "Incorrect parameters"); 
    76027602 
    76037603    ComPtr<IMachine> machine; 
     
    76127612    { 
    76137613        Bstr value; 
    7614         CHECK_ERROR(machine, GetGuestPropertyValue(Bstr(argv[1]), value.asOutParam())); 
     7614        uint64_t u64Timestamp; 
     7615        Bstr flags; 
     7616        CHECK_ERROR(machine, GetGuestProperty(Bstr(argv[1]), value.asOutParam(), 
     7617                    &u64Timestamp, flags.asOutParam())); 
     7618        if (!value) 
     7619            RTPrintf("No value set!\n"); 
    76157620        if (value) 
    76167621            RTPrintf("Value: %lS\n", value.raw()); 
    7617         else 
    7618             RTPrintf("No value set!\n"); 
     7622        if (value && verbose) 
     7623        { 
     7624            RTPrintf("Timestamp: %lld\n", u64Timestamp); 
     7625            RTPrintf("Flags: %lS\n", flags.raw()); 
     7626        } 
    76197627    } 
    76207628    return SUCCEEDED(rc) ? 0 : 1; 
     
    76277635    HRESULT rc = S_OK; 
    76287636 
    7629     if (argc < 2) 
    7630         return errorSyntax(USAGE_SETGUESTPROPERTY, "Not enough parameters"); 
     7637/* 
     7638 * Check the syntax.  We can deduce the correct syntax from the number of 
     7639 * arguments. 
     7640 */ 
     7641    bool usageOK = true; 
     7642    const char *pszName = NULL; 
     7643    const char *pszValue = NULL; 
     7644    const char *pszFlags = NULL; 
     7645    if (3 == argc) 
     7646    { 
     7647        pszName = argv[1]; 
     7648        pszValue = argv[2]; 
     7649    } 
     7650    else if (4 == argc) 
     7651    { 
     7652        pszName = argv[1]; 
     7653        if (strcmp(argv[2], "-flags") != 0) 
     7654            usageOK = false; 
     7655        pszFlags = argv[3]; 
     7656    } 
     7657    else if (5 == argc) 
     7658    { 
     7659        pszName = argv[1]; 
     7660        pszValue = argv[2]; 
     7661        if (strcmp(argv[3], "-flags") != 0) 
     7662            usageOK = false; 
     7663        pszFlags = argv[4]; 
     7664    } 
     7665    else if (argc != 2) 
     7666        usageOK = false; 
     7667    if (!usageOK) 
     7668        return errorSyntax(USAGE_GUESTPROPERTY, "Incorrect parameters"); 
    76317669 
    76327670    ComPtr<IMachine> machine; 
     
    76407678    if (machine) 
    76417679    { 
    7642         if (argc < 3) 
    7643             CHECK_ERROR(machine, SetGuestPropertyValue(Bstr(argv[1]), NULL)); 
    7644         else if (argc == 3) 
    7645             CHECK_ERROR(machine, SetGuestPropertyValue(Bstr(argv[1]), Bstr(argv[2]))); 
     7680        if ((NULL == pszValue) && (NULL == pszFlags)) 
     7681            CHECK_ERROR(machine, SetGuestPropertyValue(Bstr(pszName), NULL)); 
     7682        else if (NULL == pszFlags) 
     7683            CHECK_ERROR(machine, SetGuestPropertyValue(Bstr(pszName), Bstr(pszValue))); 
     7684        else if (NULL == pszValue) 
     7685            CHECK_ERROR(machine, SetGuestProperty(Bstr(pszName), NULL, Bstr(pszFlags))); 
    76467686        else 
    7647             return errorSyntax(USAGE_SETGUESTPROPERTY, "Too many parameters"); 
     7687            CHECK_ERROR(machine, SetGuestProperty(Bstr(pszName), Bstr(pszValue), Bstr(pszFlags))); 
    76487688    } 
    76497689    return SUCCEEDED(rc) ? 0 : 1; 
    76507690} 
     7691 
     7692 
     7693/** 
     7694 * Access the guest property store. 
     7695 * 
     7696 * @returns 0 on success, 1 on failure 
     7697 * @note see the command line API description for parameters 
     7698 */ 
     7699static int handleGuestProperty(int argc, char *argv[], 
     7700                               ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession) 
     7701{ 
     7702    if (0 == argc) 
     7703        return errorSyntax(USAGE_GUESTPROPERTY, "Incorrect parameters"); 
     7704    if (0 == strcmp(argv[0], "get")) 
     7705        return handleGetGuestProperty(argc - 1, argv + 1, aVirtualBox, aSession); 
     7706    else if (0 == strcmp(argv[0], "set")) 
     7707        return handleSetGuestProperty(argc - 1, argv + 1, aVirtualBox, aSession); 
     7708    /* else */ 
     7709    return errorSyntax(USAGE_GUESTPROPERTY, "Incorrect parameters"); 
     7710} 
     7711 
    76517712#endif /* VBOX_WITH_GUEST_PROPS defined */ 
    76527713 
     
    79868047        { "vmstatistics",     handleVMStatistics }, 
    79878048#ifdef VBOX_WITH_GUEST_PROPS 
    7988         { "getguestproperty", handleGetGuestProperty }, 
    7989         { "setguestproperty", handleSetGuestProperty }, 
     8049        { "guestproperty",    handleGuestProperty }, 
    79908050#endif /* VBOX_WITH_GUEST_PROPS defined */ 
    79918051        { NULL,               NULL } 
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r10797 r10826  
    7171#define USAGE_RENAMEVMDK            RT_BIT_64(39) 
    7272#ifdef VBOX_WITH_GUEST_PROPS 
    73 #define USAGE_GETGUESTPROPERTY      RT_BIT_64(40) 
    74 #define USAGE_SETGUESTPROPERTY      RT_BIT_64(41) 
     73#define USAGE_GUESTPROPERTY         RT_BIT_64(40) 
    7574#endif  /* VBOX_WITH_GUEST_PROPS defined */ 
    7675#define USAGE_ALL                   (~(uint64_t)0) 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy