Changeset 70058 in vbox for trunk/include/VBox/HostServices
- Timestamp:
- Dec 11, 2017 3:02:07 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 119600
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/HostServices/GuestPropertySvc.h
r69107 r70058 35 35 #include <iprt/string.h> 36 36 37 /** Everything defined in this file lives in this namespace. */38 namespace guestProp {39 40 /******************************************************************************41 * Typedefs, constants and inlines *42 ******************************************************************************/43 37 44 38 /** Maximum length for property names */ 45 enum { MAX_NAME_LEN = 64 }; 39 #define GUEST_PROP_MAX_NAME_LEN 64 46 40 /** Maximum length for property values */ 47 enum { MAX_VALUE_LEN = 128 }; 41 #define GUEST_PROP_MAX_VALUE_LEN 128 48 42 /** Maximum number of properties per guest */ 49 enum { MAX_PROPS = 256 }; 43 #define GUEST_PROP_MAX_PROPS 256 50 44 /** Maximum size for enumeration patterns */ 51 enum { MAX_PATTERN_LEN = 1024 }; 45 #define GUEST_PROP_MAX_PATTERN_LEN 1024 52 46 /** Maximum number of changes we remember for guest notifications */ 53 enum { MAX_GUEST_NOTIFICATIONS = 256 }; 54 55 /** 56 * The guest property flag values which are currently accepted. 57 */ 58 enum ePropFlags 59 { 60 NILFLAG = 0, 61 /** Transient until VM gets shut down. */ 62 TRANSIENT = RT_BIT(1), 63 RDONLYGUEST = RT_BIT(2), 64 RDONLYHOST = RT_BIT(3), 65 /** Transient until VM gets a reset / restarts. 66 * Implies TRANSIENT. */ 67 TRANSRESET = RT_BIT(4), 68 READONLY = RDONLYGUEST | RDONLYHOST, 69 ALLFLAGS = TRANSIENT | READONLY | TRANSRESET 70 }; 47 #define GUEST_PROP_MAX_GUEST_NOTIFICATIONS 256 48 49 50 /** @name GUEST_PROP_F_XXX - The guest property flag values which are currently accepted. 51 * @{ 52 */ 53 #define GUEST_PROP_F_NILFLAG UINT32_C(0) 54 /** Transient until VM gets shut down. */ 55 #define GUEST_PROP_F_TRANSIENT RT_BIT_32(1) 56 #define GUEST_PROP_F_RDONLYGUEST RT_BIT_32(2) 57 #define GUEST_PROP_F_RDONLYHOST RT_BIT_32(3) 58 /** Transient until VM gets a reset / restarts. 59 * Implies TRANSIENT. */ 60 #define GUEST_PROP_F_TRANSRESET RT_BIT_32(4) 61 #define GUEST_PROP_F_READONLY (GUEST_PROP_F_RDONLYGUEST | GUEST_PROP_F_RDONLYHOST) 62 #define GUEST_PROP_F_ALLFLAGS (GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_READONLY | GUEST_PROP_F_TRANSRESET) 63 /** @} */ 71 64 72 65 /** … … 76 69 * list. 77 70 */ 78 DECLINLINE(const char *) flagName(uint32_t fFlag)71 DECLINLINE(const char *) GuestPropFlagName(uint32_t fFlag) 79 72 { 80 73 switch (fFlag) 81 74 { 82 case TRANSIENT:75 case GUEST_PROP_F_TRANSIENT: 83 76 return "TRANSIENT"; 84 case RDONLYGUEST:77 case GUEST_PROP_F_RDONLYGUEST: 85 78 return "RDONLYGUEST"; 86 case RDONLYHOST:79 case GUEST_PROP_F_RDONLYHOST: 87 80 return "RDONLYHOST"; 88 case READONLY:81 case GUEST_PROP_F_READONLY: 89 82 return "READONLY"; 90 case TRANSRESET:83 case GUEST_PROP_F_TRANSRESET: 91 84 return "TRANSRESET"; 92 85 default: … … 102 95 * list. 103 96 */ 104 DECLINLINE(size_t) flagNameLen(uint32_t fFlag)105 { 106 const char *pcszName = flagName(fFlag);97 DECLINLINE(size_t) GuestPropFlagNameLen(uint32_t fFlag) 98 { 99 const char *pcszName = GuestPropFlagName(fFlag); 107 100 return RT_LIKELY(pcszName != NULL) ? strlen(pcszName) : 0; 108 101 } … … 112 105 * RDONLYGUEST, RDONLYHOST and RDONLY 113 106 */ 114 enum { MAX_FLAGS_LEN = sizeof("TRANSIENT, RDONLYGUEST, TRANSRESET") }; 107 #define GUEST_PROP_MAX_FLAGS_LEN sizeof("TRANSIENT, RDONLYGUEST, TRANSRESET") 115 108 116 109 /** 117 110 * Parse a guest properties flags string for flag names and make sure that 118 111 * there is no junk text in the string. 112 * 119 113 * @returns IPRT status code 120 * @ret urns VERR_INVALID_PARAMif the flag string is not valid114 * @retval VERR_INVALID_PARAMETER if the flag string is not valid 121 115 * @param pcszFlags the flag string to parse 122 116 * @param pfFlags where to store the parse result. May not be NULL. … … 125 119 * its own library. 126 120 */ 127 DECLINLINE(int) validateFlags(const char *pcszFlags, uint32_t *pfFlags)121 DECLINLINE(int) GuestPropValidateFlags(const char *pcszFlags, uint32_t *pfFlags) 128 122 { 129 123 static const uint32_t s_aFlagList[] = 130 124 { 131 TRANSIENT, READONLY, RDONLYGUEST, RDONLYHOST,TRANSRESET125 GUEST_PROP_F_TRANSIENT, GUEST_PROP_F_READONLY, GUEST_PROP_F_RDONLYGUEST, GUEST_PROP_F_RDONLYHOST, GUEST_PROP_F_TRANSRESET 132 126 }; 133 127 const char *pcszNext = pcszFlags; … … 144 138 unsigned i = 0; 145 139 for (; i < RT_ELEMENTS(s_aFlagList); ++i) 146 if (RTStrNICmp(pcszNext, flagName(s_aFlagList[i]), 147 flagNameLen(s_aFlagList[i])) == 0) 140 if (RTStrNICmp(pcszNext, GuestPropFlagName(s_aFlagList[i]), GuestPropFlagNameLen(s_aFlagList[i])) == 0) 148 141 break; 149 142 if (RT_ELEMENTS(s_aFlagList) == i) … … 152 145 { 153 146 fFlags |= s_aFlagList[i]; 154 pcszNext += flagNameLen(s_aFlagList[i]);147 pcszNext += GuestPropFlagNameLen(s_aFlagList[i]); 155 148 while (' ' == *pcszNext) 156 149 ++pcszNext; … … 169 162 } 170 163 164 171 165 /** 172 166 * Write out flags to a string. … … 176 170 * a buffer of size (at least) MAX_FLAGS_LEN. 177 171 */ 178 DECLINLINE(int) writeFlags(uint32_t fFlags, char *pszFlags)172 DECLINLINE(int) GuestPropWriteFlags(uint32_t fFlags, char *pszFlags) 179 173 { 180 174 /* Putting READONLY before the other RDONLY flags keeps the result short. */ 181 175 static const uint32_t s_aFlagList[] = 182 176 { 183 TRANSIENT, READONLY, RDONLYGUEST, RDONLYHOST,TRANSRESET177 GUEST_PROP_F_TRANSIENT, GUEST_PROP_F_READONLY, GUEST_PROP_F_RDONLYGUEST, GUEST_PROP_F_RDONLYHOST, GUEST_PROP_F_TRANSRESET 184 178 }; 185 179 int rc = VINF_SUCCESS; 186 180 187 181 AssertLogRelReturn(VALID_PTR(pszFlags), VERR_INVALID_POINTER); 188 if ((fFlags & ~ ALLFLAGS) ==NILFLAG)182 if ((fFlags & ~GUEST_PROP_F_ALLFLAGS) == GUEST_PROP_F_NILFLAG) 189 183 { 184 char *pszNext; 185 190 186 /* TRANSRESET implies TRANSIENT. For compatability with old clients we 191 187 always set TRANSIENT when TRANSRESET appears. */ 192 if (fFlags & TRANSRESET)193 fFlags |= TRANSIENT;194 195 char *pszNext = pszFlags;188 if (fFlags & GUEST_PROP_F_TRANSRESET) 189 fFlags |= GUEST_PROP_F_TRANSIENT; 190 191 pszNext = pszFlags; 196 192 for (unsigned i = 0; i < RT_ELEMENTS(s_aFlagList); ++i) 197 193 { 198 194 if (s_aFlagList[i] == (fFlags & s_aFlagList[i])) 199 195 { 200 strcpy(pszNext, flagName(s_aFlagList[i]));201 pszNext += flagNameLen(s_aFlagList[i]);196 strcpy(pszNext, GuestPropFlagName(s_aFlagList[i])); 197 pszNext += GuestPropFlagNameLen(s_aFlagList[i]); 202 198 fFlags &= ~s_aFlagList[i]; 203 if (fFlags != NILFLAG)199 if (fFlags != GUEST_PROP_F_NILFLAG) 204 200 { 205 201 strcpy(pszNext, ", "); … … 210 206 *pszNext = '\0'; 211 207 212 Assert(fFlags == NILFLAG); /* bad s_aFlagList */208 Assert(fFlags == GUEST_PROP_F_NILFLAG); /* bad s_aFlagList */ 213 209 } 214 210 else … … 217 213 } 218 214 219 /** 220 * The service functions which are callable by host. 221 */ 222 enum eHostFn 223 { 224 /** 225 * Set properties in a block. The parameters are pointers to 226 * NULL-terminated arrays containing the parameters. These are, in order, 227 * name, value, timestamp, flags. Strings are stored as pointers to 228 * mutable utf8 data. All parameters must be supplied. 229 */ 230 SET_PROPS_HOST = 1, 231 /** 232 * Get the value attached to a guest property 233 * The parameter format matches that of GET_PROP. 234 */ 235 GET_PROP_HOST = 2, 236 /** 237 * Set the value attached to a guest property 238 * The parameter format matches that of SET_PROP. 239 */ 240 SET_PROP_HOST = 3, 241 /** 242 * Set the value attached to a guest property 243 * The parameter format matches that of SET_PROP_VALUE. 244 */ 245 SET_PROP_VALUE_HOST = 4, 246 /** 247 * Remove a guest property. 248 * The parameter format matches that of DEL_PROP. 249 */ 250 DEL_PROP_HOST = 5, 251 /** 252 * Enumerate guest properties. 253 * The parameter format matches that of ENUM_PROPS. 254 */ 255 ENUM_PROPS_HOST = 6, 256 257 /** 258 * Set global flags for the service. Currently RDONLYGUEST is supported. 259 * Takes one 32-bit unsigned integer parameter for the flags. 260 */ 261 SET_GLOBAL_FLAGS_HOST = 7, 262 263 /** 264 * Return the pointer to a debug info function enumerating all guest properties. 265 */ 266 GET_DBGF_INFO_FN = 8 267 }; 268 269 /** 270 * The service functions which are called by guest. The numbers may not change, 271 * so we hardcode them. 272 */ 273 enum eGuestFn 274 { 275 /** Get a guest property */ 276 GET_PROP = 1, 277 /** Set a guest property */ 278 SET_PROP = 2, 279 /** Set just the value of a guest property */ 280 SET_PROP_VALUE = 3, 281 /** Delete a guest property */ 282 DEL_PROP = 4, 283 /** Enumerate guest properties */ 284 ENUM_PROPS = 5, 285 /** Poll for guest notifications */ 286 GET_NOTIFICATION = 6 287 }; 288 289 /** 290 * Data structure to pass to the service extension callback. We use this to 291 * notify the host of changes to properties. 292 */ 293 typedef struct _HOSTCALLBACKDATA 294 { 295 /** Magic number to identify the structure */ 296 uint32_t u32Magic; 215 216 /** @name The service functions which are callable by host. 217 * @{ 218 */ 219 /** Set properties in a block. 220 * The parameters are pointers to NULL-terminated arrays containing the 221 * parameters. These are, in order, name, value, timestamp, flags. Strings are 222 * stored as pointers to mutable utf8 data. All parameters must be supplied. */ 223 #define GUEST_PROP_FN_SET_PROPS_HOST 1 224 /** Get the value attached to a guest property. 225 * The parameter format matches that of GET_PROP. */ 226 #define GUEST_PROP_FN_GET_PROP_HOST 2 227 /** Set the value attached to a guest property. 228 * The parameter format matches that of SET_PROP. */ 229 #define GUEST_PROP_FN_SET_PROP_HOST 3 230 /** Set the value attached to a guest property. 231 * The parameter format matches that of SET_PROP_VALUE. */ 232 #define GUEST_PROP_FN_SET_PROP_VALUE_HOST 4 233 /** Remove a guest property. 234 * The parameter format matches that of DEL_PROP. */ 235 #define GUEST_PROP_FN_DEL_PROP_HOST 5 236 /** Enumerate guest properties. 237 * The parameter format matches that of ENUM_PROPS. */ 238 #define GUEST_PROP_FN_ENUM_PROPS_HOST 6 239 /** Set global flags for the service. 240 * Currently RDONLYGUEST is supported. Takes one 32-bit unsigned integer 241 * parameter for the flags. */ 242 #define GUEST_PROP_FN_SET_GLOBAL_FLAGS_HOST 7 243 /** Return the pointer to a debug info function enumerating all guest 244 * properties. */ 245 #define GUEST_PROP_FN_GET_DBGF_INFO_FN 8 246 /** @} */ 247 248 249 /** @name The service functions which are called by guest. 250 * 251 * @note The numbers may not change! 252 * @{ 253 */ 254 /** Get a guest property */ 255 #define GUEST_PROP_FN_GET_PROP 1 256 /** Set a guest property */ 257 #define GUEST_PROP_FN_SET_PROP 2 258 /** Set just the value of a guest property */ 259 #define GUEST_PROP_FN_SET_PROP_VALUE 3 260 /** Delete a guest property */ 261 #define GUEST_PROP_FN_DEL_PROP 4 262 /** Enumerate guest properties */ 263 #define GUEST_PROP_FN_ENUM_PROPS 5 264 /** Poll for guest notifications */ 265 #define GUEST_PROP_FN_GET_NOTIFICATION 6 266 /** @} */ 267 268 269 /** 270 * Data structure to pass to the service extension callback. 271 * We use this to notify the host of changes to properties. 272 */ 273 typedef struct GUESTPROPHOSTCALLBACKDATA 274 { 275 /** Magic number to identify the structure (GUESTPROPHOSTCALLBACKDATA_MAGIC). */ 276 uint32_t u32Magic; 297 277 /** The name of the property that was changed */ 298 const char *pcszName;278 const char *pcszName; 299 279 /** The new property value, or NULL if the property was deleted */ 300 const char *pcszValue;280 const char *pcszValue; 301 281 /** The timestamp of the modification */ 302 uint64_t u64Timestamp;282 uint64_t u64Timestamp; 303 283 /** The flags field of the modified property */ 304 const char *pcszFlags; 305 } HOSTCALLBACKDATA, *PHOSTCALLBACKDATA; 306 307 enum 308 { 309 /** Magic number for sanity checking the HOSTCALLBACKDATA structure */ 310 HOSTCALLBACKMAGIC = 0x69c87a78 311 }; 284 const char *pcszFlags; 285 } GUESTPROPHOSTCALLBACKDATA; 286 /** Poitner to a data structure to pass to the service extension callback. */ 287 typedef GUESTPROPHOSTCALLBACKDATA *PGUESTPROPHOSTCALLBACKDATA; 288 289 /** Magic number for sanity checking the HOSTCALLBACKDATA structure */ 290 #define GUESTPROPHOSTCALLBACKDATA_MAGIC UINT32_C(0x69c87a78) 291 292 /** Everything defined in this file lives in this namespace. */ 293 namespace guestProp { 312 294 313 295 /**
Note:
See TracChangeset
for help on using the changeset viewer.