VirtualBox

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


Ignore:
Timestamp:
Sep 29, 2008 4:27:32 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
37166
Message:

VbglR3GuestPropDelTree -> VbglR3GuestPropDelSet, added missing docs and make some adjustments. Fixed the missing 'const'-ness of the enumeration API.

Location:
trunk/src/VBox/Additions/common
Files:
2 edited

Legend:

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

    r12719 r12812  
    10441044static int enumGuestProperty(int argc, char *argv[])
    10451045{
    1046 /*
    1047  * Check the syntax.  We can deduce the correct syntax from the number of
    1048  * arguments.
    1049  */
    1050     const char *paszPatterns = NULL;
    1051     if ((argc > 1) && (0 == strcmp(argv[0], "-patterns")))
    1052         paszPatterns = argv[1];
     1046    /*
     1047     * Check the syntax.  We can deduce the correct syntax from the number of
     1048     * arguments.
     1049     */
     1050    char const * const *papszPatterns = NULL;
     1051    size_t cPatterns = 0;
     1052    if (    argc > 1
     1053        && !strcmp(argv[0], "-patterns"))
     1054    {
     1055        papszPatterns = (char const * const *)&argv[1];
     1056        cPatterns = argc - 1;
     1057    }
    10531058    else if (argc != 0)
    10541059    {
     
    10571062    }
    10581063
    1059 /*
    1060  * Do the actual enumeration.
    1061  */
     1064    /*
     1065     * Do the actual enumeration.
     1066     */
    10621067    uint32_t u32ClientId = 0;
    1063     PVBGLR3GUESTPROPENUM pHandle = NULL;
    1064     RTMemAutoPtr<VBGLR3GUESTPROPENUM, VbglR3GuestPropEnumFree> Handle;
    1065     char *pszName = NULL, *pszValue = NULL, *pszFlags = NULL;
    1066     uint64_t u64Timestamp = 0;
    1067     int rc = VINF_SUCCESS;
    1068     rc = VbglR3GuestPropConnect(&u32ClientId);
    1069     if (!RT_SUCCESS(rc))
    1070         VBoxControlError("Failed to connect to the guest property service! Error: %Rrc\n", rc);
     1068    int rc = VbglR3GuestPropConnect(&u32ClientId);
    10711069    if (RT_SUCCESS(rc))
    10721070    {
    1073         char **ppaszPatterns = argc > 1 ? argv + 1 : NULL;
    1074         int cPatterns = argc > 1 ? argc - 1 : 0;
    1075         rc = VbglR3GuestPropEnum(u32ClientId, ppaszPatterns, cPatterns, &pHandle,
     1071        PVBGLR3GUESTPROPENUM pHandle;
     1072        const char *pszName, *pszValue, *pszFlags;
     1073        uint64_t u64Timestamp;
     1074
     1075        rc = VbglR3GuestPropEnum(u32ClientId, papszPatterns, cPatterns, &pHandle,
    10761076                                 &pszName, &pszValue, &u64Timestamp, &pszFlags);
    10771077        if (RT_SUCCESS(rc))
    10781078        {
    1079             Handle = pHandle;
     1079            while (RT_SUCCESS(rc) && !pszName)
     1080            {
     1081                RTPrintf("Name: %s, value: %s, timestamp: %lld, flags: %s\n",
     1082                         pszName, pszValue, u64Timestamp, pszFlags);
     1083
     1084                rc = VbglR3GuestPropEnumNext(pHandle, &pszName, &pszValue, &u64Timestamp, &pszFlags);
     1085                if (RT_FAILURE(rc))
     1086                    VBoxControlError("Error while enumerating guest properties: %Rrc\n", rc);
     1087            }
     1088
     1089            VbglR3GuestPropEnumFree(pHandle);
    10801090        }
    10811091        else if (VERR_NOT_FOUND == rc)
     
    10831093        else
    10841094            VBoxControlError("Failed to enumerate the guest properties! Error: %Rrc\n", rc);
    1085     }
    1086     while (RT_SUCCESS(rc) && (pszName != NULL))
    1087     {
    1088         RTPrintf("Name: %s, value: %s, timestamp: %lld, flags: %s\n",
    1089                  pszName, pszValue, u64Timestamp, pszFlags);
    1090         rc = VbglR3GuestPropEnumNext(Handle.get(), &pszName, &pszValue, &u64Timestamp, &pszFlags);
    1091         if (!RT_SUCCESS(rc))
    1092             VBoxControlError("Error while enumerating guest properties: %Rrc\n", rc);
    1093     }
    1094 
    1095     if (u32ClientId != 0)
    10961095        VbglR3GuestPropDisconnect(u32ClientId);
     1096    }
     1097    else
     1098        VBoxControlError("Failed to connect to the guest property service! Error: %Rrc\n", rc);
    10971099    return RT_SUCCESS(rc) ? 0 : 1;
    10981100}
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp

    r12810 r12812  
    523523 * @param   ppszFlags       Where to store the first flags value on success.
    524524 *                          Should not be freed.
    525  *
    526  * @todo    Make papszPatterns char const * const *, and cPatterns size_t (so we
    527  *          can use RT_ELEMENTS without getting warnings on Windows).
    528  *          Most of the returns should also be made char const * to discourage
    529  *          changes and encourage compiler optimizations.
    530525 */
    531526VBGLR3DECL(int) VbglR3GuestPropEnum(uint32_t u32ClientId,
    532                                     char **papszPatterns,
    533                                     int cPatterns,
     527                                    char const * const *papszPatterns,
     528                                    size_t cPatterns,
    534529                                    PVBGLR3GUESTPROPENUM *ppHandle,
    535                                     char **ppszName,
    536                                     char **ppszValue,
     530                                    char const **ppszName,
     531                                    char const **ppszValue,
    537532                                    uint64_t *pu64Timestamp,
    538                                     char **ppszFlags)
     533                                    char const **ppszFlags)
    539534{
    540535    int rc = VINF_SUCCESS;
    541536    RTMemAutoPtr<VBGLR3GUESTPROPENUM, VbglR3GuestPropEnumFree> Handle;
    542     Handle = (PVBGLR3GUESTPROPENUM) RTMemAllocZ(sizeof(VBGLR3GUESTPROPENUM));
     537    Handle = (PVBGLR3GUESTPROPENUM)RTMemAllocZ(sizeof(VBGLR3GUESTPROPENUM));
    543538    if (!Handle)
    544539        rc = VERR_NO_MEMORY;
     
    546541    /* Get the length of the pattern string, including the final terminator. */
    547542    uint32_t cchPatterns = 1;
    548     for (int i = 0; i < cPatterns; ++i)
     543    for (unsigned i = 0; i < cPatterns; ++i)
    549544        cchPatterns += strlen(papszPatterns[i]) + 1;
     545
    550546    /* Pack the pattern array */
    551547    RTMemAutoPtr<char> Patterns;
    552     Patterns = (char *) RTMemAlloc(cchPatterns);
     548    Patterns = (char *)RTMemAlloc(cchPatterns);
    553549    size_t iOffs = 0;
    554     for (int i = 0; i < cPatterns; ++i)
     550    for (size_t i = 0; i < cPatterns; ++i)
    555551    {
    556552        size_t cb = strlen(papszPatterns[i]) + 1;
     
    619615 *                       set to NULL if there are no more properties to
    620616 *                       enumerate.  This pointer should not be freed.
    621  *
    622  * @todo return char const *.
    623617 */
    624618VBGLR3DECL(int) VbglR3GuestPropEnumNext(PVBGLR3GUESTPROPENUM pHandle,
    625                                         char **ppszName,
    626                                         char **ppszValue,
     619                                        char const **ppszName,
     620                                        char const **ppszValue,
    627621                                        uint64_t *pu64Timestamp,
    628                                         char **ppszFlags)
     622                                        char const **ppszFlags)
    629623{
    630624    uint32_t iBuf = pHandle->iBuf;
    631625    char *pszName = pHandle->pchBuf + iBuf;
    632     /** @todo replace these with safe memchr's and return an error if needed. */
     626    /** @todo replace these with safe memchr's and return an error if needed. A
     627     *        PLEASE add a comment about the layout because this is rather
     628     *        unreadable. */
    633629    iBuf += strlen(pszName) + 1;
    634630    char *pszValue = pHandle->pchBuf + iBuf;
     
    680676{
    681677    PVBGLR3GUESTPROPENUM pHandle;
    682     char *pszName;
    683     char *pszValue;
     678    char const *pszName, *pszValue, *pszFlags;
    684679    uint64_t pu64Timestamp;
    685     char *pszFlags;
    686680    int rc = VbglR3GuestPropEnum(u32ClientId,
    687681                                 (char **)papszPatterns, /** @todo fix this cast. */
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