Changeset 55591 in vbox for trunk/src/VBox/Main/include
- Timestamp:
- May 2, 2015 1:57:14 AM (10 years ago)
- Location:
- trunk/src/VBox/Main/include
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h
r55588 r55591 26 26 #include <iprt/env.h> 27 27 #include <iprt/semaphore.h> 28 #include <iprt/cpp/utils.h> 28 29 29 30 #include <VBox/com/com.h> … … 78 79 GuestEnvironmentBase(void) 79 80 : m_hEnv(NIL_RTENV) 81 , m_cRefs(1) 80 82 { } 81 83 … … 85 87 virtual ~GuestEnvironmentBase(void) 86 88 { 89 Assert(m_cRefs <= 1); 87 90 int rc = RTEnvDestroy(m_hEnv); AssertRC(rc); 88 91 m_hEnv = NIL_RTENV; … … 90 93 91 94 /** 92 * Initialize this as a normal environment block. 93 * @returns IPRT status code. 94 */ 95 int initNormal(void) 96 { 97 AssertReturn(m_hEnv == NIL_RTENV, VERR_WRONG_ORDER); 98 return RTEnvCreate(&m_hEnv); 95 * Retains a reference to this object. 96 * @returns New reference count. 97 * @remarks Sharing an object is currently only safe if no changes are made to 98 * it because RTENV does not yet implement any locking. For the only 99 * purpose we need this, implementing IGuestProcess::environment by 100 * using IGuestSession::environmentBase, that's fine as the session 101 * base environment is immutable. 102 */ 103 uint32_t retain(void) 104 { 105 uint32_t cRefs = ASMAtomicIncU32(&m_cRefs); 106 Assert(cRefs > 1); Assert(cRefs < _1M); 107 return cRefs; 108 109 } 110 /** Useful shortcut. */ 111 uint32_t retainConst(void) const { return unconst(this)->retain(); } 112 113 /** 114 * Releases a reference to this object, deleting the object when reaching zero. 115 * @returns New reference count. 116 */ 117 uint32_t release(void) 118 { 119 uint32_t cRefs = ASMAtomicDecU32(&m_cRefs); 120 Assert(cRefs < _1M); 121 if (cRefs == 0) 122 delete this; 123 return cRefs; 124 } 125 126 /** Useful shortcut. */ 127 uint32_t releaseConst(void) const { return unconst(this)->retain(); } 128 129 /** 130 * Checks if the environment has been successfully initialized or not. 131 * 132 * @returns @c true if initialized, @c false if not. 133 */ 134 bool isInitialized(void) const 135 { 136 return m_hEnv != NIL_RTENV; 99 137 } 100 138 … … 167 205 return VINF_SUCCESS; 168 206 } 207 208 /** 209 * Applies the changes from another environment to this. 210 * 211 * @returns IPRT status code. 212 * @param rChanges Reference to an environment which variables will be 213 * imported and, if it's a change record, schedule 214 * variable unsets will be applied. 215 * @sa RTEnvApplyChanges 216 */ 217 int applyChanges(const GuestEnvironmentBase &rChanges) 218 { 219 return RTEnvApplyChanges(m_hEnv, rChanges.m_hEnv); 220 } 221 169 222 170 223 /** … … 219 272 220 273 /** 274 * Checks if the given variable exists. 275 * 276 * @returns @c true if it exists, @c false if not or if it's an scheduled unset 277 * in a environment change record. 278 * @param rName The variable name. 279 * @sa RTEnvExistEx 280 */ 281 bool doesVariableExist(const com::Utf8Str &rName) const 282 { 283 return RTEnvExistEx(m_hEnv, rName.c_str()); 284 } 285 286 /** 221 287 * Set an environment variable. 222 288 * … … 243 309 } 244 310 245 #if 0 246 private: 247 /* No copy operator. */ 248 GuestEnvironmentBase(const GuestEnvironmentBase &) { throw E_FAIL; } 249 #else 311 protected: 250 312 /** 251 313 * Copy constructor. … … 259 321 throw (Global::vboxStatusCodeToCOM(rc)); 260 322 } 261 #endif 262 263 protected: 323 264 324 /** 265 325 * Common clone/copy method with type conversion abilities. … … 304 364 305 365 /** The environment change record. */ 306 RTENV m_hEnv; 307 }; 308 309 310 #if 0 /* Not currently used. */ 366 RTENV m_hEnv; 367 /** Reference counter. */ 368 uint32_t volatile m_cRefs; 369 }; 370 371 311 372 /** 312 373 * Wrapper around the RTEnv API for a normal environment. … … 364 425 } 365 426 }; 366 #endif /* unused */367 427 368 428 … … 548 608 ProcessArguments mArguments; 549 609 /** The process environment change record. */ 550 GuestEnvironmentChanges mEnvironment ;610 GuestEnvironmentChanges mEnvironmentChanges; 551 611 /** Process creation flags. */ 552 612 uint32_t mFlags; … … 980 1040 protected: 981 1041 982 /** 983 * Commom parameters for all derived objects, when then have 984 * an own mData structure to keep their specific data around. 985 */ 986 1042 /** @name Common parameters for all derived objects. They have their own 1043 * mData structure to keep their specific data around. 1044 * @{ */ 987 1045 /** Pointer to parent session. Per definition 988 1046 * this objects *always* lives shorter than the 989 * parent. */ 1047 * parent. 1048 * @todo r=bird: When wanting to use mSession in the 1049 * IGuestProcess::getEnvironment() implementation I wanted to access 1050 * GuestSession::mData::mpBaseEnvironment. Seeing the comment in 1051 * GuestProcess::terminate() saying: 1052 * "Now only API clients still can hold references to it." 1053 * and recalling seeing similar things in VirtualBox.xidl or some such place, 1054 * I'm wondering how this "per definition" behavior is enforced. Is there any 1055 * GuestProcess:uninit() call or similar magic that invalidates objects that 1056 * GuestSession loses track of in place like GuestProcess::terminate() that I've 1057 * failed to spot? 1058 * 1059 * Please enlighten me. 1060 */ 990 1061 GuestSession *mSession; 991 1062 /** The object ID -- must be unique for each guest … … 996 1067 * for guest files this is the internal file ID. */ 997 1068 uint32_t mObjectID; 998 }; 999 #endif // ____H_GUESTIMPLPRIVATE 1000 1069 /** @} */ 1070 }; 1071 #endif // !____H_GUESTIMPLPRIVATE 1072 -
trunk/src/VBox/Main/include/GuestProcessImpl.h
r51321 r55591 22 22 #include "GuestProcessWrap.h" 23 23 24 #include <iprt/cpp/utils.h> 25 24 26 class Console; 25 27 class GuestSession; … … 37 39 DECLARE_EMPTY_CTOR_DTOR(GuestProcess) 38 40 39 int init(Console *aConsole, GuestSession *aSession, ULONG aProcessID, const GuestProcessStartupInfo &aProcInfo); 41 int init(Console *aConsole, GuestSession *aSession, ULONG aProcessID, 42 const GuestProcessStartupInfo &aProcInfo, const GuestEnvironment *pBaseEnv); 40 43 void uninit(void); 41 44 HRESULT FinalConstruct(void); … … 137 140 /** The process startup information. */ 138 141 GuestProcessStartupInfo mProcess; 142 /** Reference to the immutable session base environment. NULL if the 143 * environment feature isn't supported. 144 * @remarks If there is proof that the uninit order of GuestSession and 145 * this class is what GuestObjectBase claims, then this isn't 146 * strictly necessary. */ 147 GuestEnvironment const *mpSessionBaseEnv; 139 148 /** Exit code if process has been terminated. */ 140 149 LONG mExitCode; … … 146 155 * returned from the guest side. */ 147 156 int mLastError; 157 158 Data(void) : mpSessionBaseEnv(NULL) 159 { } 160 ~Data(void) 161 { 162 if (mpSessionBaseEnv) 163 { 164 mpSessionBaseEnv->releaseConst(); 165 mpSessionBaseEnv = NULL; 166 } 167 } 148 168 } mData; 149 169 }; -
trunk/src/VBox/Main/include/GuestSessionImpl.h
r55590 r55591 268 268 HRESULT getProtocolVersion(ULONG *aProtocolVersion); 269 269 HRESULT getStatus(GuestSessionStatus_T *aStatus); 270 HRESULT getEnvironment(std::vector<com::Utf8Str> &aEnvironment); 271 HRESULT setEnvironment(const std::vector<com::Utf8Str> &aEnvironment); 270 HRESULT getEnvironmentChanges(std::vector<com::Utf8Str> &aEnvironmentChanges); 271 HRESULT setEnvironmentChanges(const std::vector<com::Utf8Str> &aEnvironmentChanges); 272 HRESULT getEnvironmentBase(std::vector<com::Utf8Str> &aEnvironmentBase); 272 273 HRESULT getProcesses(std::vector<ComPtr<IGuestProcess> > &aProcesses); 273 274 HRESULT getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories); … … 312 313 HRESULT directorySetACL(const com::Utf8Str &aPath, 313 314 const com::Utf8Str &aAcl); 314 HRESULT environmentSet(const com::Utf8Str &aName, 315 const com::Utf8Str &aValue); 316 HRESULT environmentUnset(const com::Utf8Str &aName); 315 HRESULT environmentScheduleSet(const com::Utf8Str &aName, 316 const com::Utf8Str &aValue); 317 HRESULT environmentScheduleUnset(const com::Utf8Str &aName); 318 HRESULT environmentGetBaseVariable(const com::Utf8Str &aName, 319 com::Utf8Str &aValue); 320 HRESULT environmentDoesBaseVariableExist(const com::Utf8Str &aName, 321 BOOL *aExists); 317 322 HRESULT fileCreateTemp(const com::Utf8Str &aTemplateName, 318 323 ULONG aMode, … … 469 474 /** The set of environment changes for the session for use when 470 475 * creating new guest processes. */ 471 GuestEnvironmentChanges mEnvironment; 476 GuestEnvironmentChanges mEnvironmentChanges; 477 /** Pointer to the immutable base environment for the session. 478 * @note This is not allocated until the guest reports it to the host. It is 479 * also shared with child processes. */ 480 GuestEnvironment const *mpBaseEnvironment; 472 481 /** Directory objects bound to this session. */ 473 482 SessionDirectories mDirectories; … … 488 497 * returned from the guest side. */ 489 498 int mRC; 499 500 Data(void) 501 : mpBaseEnvironment(NULL) 502 { } 503 Data(const Data &rThat) 504 : mCredentials(rThat.mCredentials) 505 , mSession(rThat.mSession) 506 , mStatus(rThat.mStatus) 507 , mEnvironmentChanges(rThat.mEnvironmentChanges) 508 , mpBaseEnvironment(NULL) 509 , mDirectories(rThat.mDirectories) 510 , mFiles(rThat.mFiles) 511 , mProcesses(rThat.mProcesses) 512 , mProtocolVersion(rThat.mProtocolVersion) 513 , mTimeout(rThat.mTimeout) 514 , mNumObjects(rThat.mNumObjects) 515 , mRC(rThat.mRC) 516 { } 490 517 } mData; 491 518 };
Note:
See TracChangeset
for help on using the changeset viewer.