Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.5 KiB

  1. //*** CUACount -- user-assistance counter w/ decay
  2. //
  3. #define XXX_DELETE 1
  4. #define XXX_VERSIONED 0
  5. //*** NRW -- named i/o
  6. // DESCRIPTION
  7. // i/o to a 'named' location (e.g. registry)
  8. typedef struct {
  9. void *self;
  10. LPCTSTR pszName;
  11. } NRWINFO, *PNRWINFO;
  12. typedef HRESULT (*PFNNRW)(void *pvBuf, DWORD cbBuf, PNRWINFO prwi);
  13. typedef struct {
  14. PFNNRW _pfnRead;
  15. PFNNRW _pfnWrite;
  16. PFNNRW _pfnDelete;
  17. } FNNRW3, *PFNNRW3;
  18. //*** UAQ_* -- quantum
  19. // NOTES
  20. // todo: for now everything is flat
  21. typedef enum {
  22. UAQ_TASK=0,
  23. UAQ_DOC=0,
  24. UAQ_APP=0,
  25. UAQ_SESSION=0
  26. } UAQUANTUM;
  27. #define UAQ_DEFAULT UAQ_SESSION // currently implemented quanta
  28. #define UAQ_COUNT (UAQ_SESSION + 1)
  29. typedef DWORD UATIME; // 1 minute (approx)
  30. #define UAT_MINUTE1 ((UATIME)1) // 1 minute
  31. #define UAT_HOUR12 ((UATIME)(12 * 60)) // 12 hours (see FTToUATime)
  32. extern UATIME GetUaTime(LPSYSTEMTIME pst);
  33. //*** UATTOMSEC -- convert UATIME to mSec's
  34. // NOTES
  35. // ISSUE: we should be more accurate. currently we just assume a UATIME
  36. // is exactly 1 minute, which it's not... easy enough to do, but we'll
  37. // wait until i have time to do the math.
  38. #define UATTOMSEC(uat) ((uat) * 60 * 1000)
  39. class IUASession
  40. {
  41. public:
  42. virtual void SetSession(UAQUANTUM uaq, BOOL fForce) PURE;
  43. virtual int GetSessionId() PURE;
  44. };
  45. class CUASession : public IUASession
  46. {
  47. struct SUASession {
  48. #if XXX_VERSIONED
  49. UINT _cbSize;
  50. #endif
  51. UATIME _qtMru;
  52. int _cCnt;
  53. };
  54. public:
  55. void SetSession(UAQUANTUM uaq, BOOL fForce);
  56. int GetSessionId();
  57. CUASession(); // n.b. public so can stack-alloc
  58. HRESULT Initialize();
  59. HRESULT LoadFrom(PFNNRW3 pfnIO, PNRWINFO pRwi);
  60. HRESULT SaveTo(BOOL fForce, PFNNRW3 pfnIO, PNRWINFO pRwi);
  61. protected:
  62. // for xfers directly into me w/o an extra copy-ctor
  63. // e.g. p->QueryValue(pszName, aUac.GetRawData(), &cb);
  64. // e.g. p->SetValue (pszName, aUac.GetRawData(), aUac.GetRawCount());
  65. _inline BYTE * _GetRawData() { return (BYTE *)&_qtMru; };
  66. _inline DWORD _GetRawCount() { return SIZEOF(SUASession); };
  67. //struct SUASession {
  68. #if XXX_VERSIONED
  69. UINT _cbSize;
  70. #endif
  71. UATIME _qtMru;
  72. int _cCnt;
  73. //};
  74. BITBOOL _fInited : 1; // 1:we've been initialized
  75. BITBOOL _fDirty : 1; // 1:save me (e.g. _sidMru was xformed)
  76. };
  77. // all special values are < 0 for easy check
  78. #define SID_SNOWREAD (-1) // like SID_SNOWINIT, but no auto-save
  79. #define SID_SNOWINIT (-2) // convert to 'now' on 1st read
  80. #define SID_SNOWALWAYS (-3) // always 'now'
  81. #define ISSID_SSPECIAL(s) ((int)(s) < 0)
  82. // tunable values for IncCount (talk to your neighborhood PM)
  83. #define UAC_NEWCOUNT 2 // brand-new count starts from here
  84. #define UAC_MINCOUNT 6 // incr to a minimum of this
  85. class CUACount
  86. {
  87. // must match CUACount semi-embedded struct
  88. struct SUACount
  89. {
  90. #define UAC_d0 _sidMruDisk
  91. #if XXX_VERSIONED
  92. #undef UAC_d0
  93. #define UAC_d0 _cbSize
  94. UINT _cbSize;
  95. #endif
  96. UINT _sidMruDisk; // MRU for this entry
  97. // todo: eventually we'll want task,doc,app,session
  98. // so this will be _cCnt[UAQ_COUNT], and we'll index by _cCnt[quanta]
  99. int _cCnt; // use count (lazily decayed)
  100. FILETIME _ftExecuteTime;
  101. };
  102. public:
  103. CUACount(); // n.b. public so can stack-alloc
  104. HRESULT Initialize(IUASession *puas);
  105. HRESULT LoadFrom(PFNNRW3 pfnIO, PNRWINFO pRwi);
  106. HRESULT SaveTo(BOOL fForce, PFNNRW3 pfnIO, PNRWINFO pRwi);
  107. #ifdef DEBUG
  108. BOOL DBIsInit();
  109. #endif
  110. int GetCount();
  111. void IncCount();
  112. void AddCount(int i);
  113. void SetCount(int cCnt);
  114. void UpdateFileTime();
  115. FILETIME GetFileTime();
  116. void SetFileTime(const FILETIME *pft);
  117. // most people should *not* call these
  118. void _SetMru(UINT sidMru) { _sidMruDisk = sidMru; Initialize(_puas); };
  119. int _GetCount() { return _cCnt; };
  120. #if XXX_DELETE
  121. DWORD _SetFlags(DWORD dwMask, DWORD dwValue);
  122. #define UACF_INHERITED 0x01
  123. #define UACF_NODECAY 0x02
  124. #endif
  125. protected:
  126. int _DecayCount(BOOL fWrite);
  127. UINT _ExpandSpecial(UINT sidMru);
  128. // for xfers directly into me w/o an extra copy-ctor
  129. // e.g. p->QueryValue(pszName, aUac.GetRawData(), &cb);
  130. // e.g. p->SetValue (pszName, aUac.GetRawData(), aUac.GetRawCount());
  131. _inline BYTE * _GetRawData() { return (BYTE *)&UAC_d0; };
  132. _inline DWORD _GetRawCount() { return SIZEOF(SUACount); };
  133. // struct SUACount {
  134. #if XXX_VERSIONED
  135. UINT _cbSize; // SIZEOF
  136. #endif
  137. UINT _sidMruDisk; // MRU for this entry
  138. // todo: eventually we'll want task,doc,app,session
  139. // so this will be cCnt[UAQ_COUNT], and we'll index by cCnt[quanta]
  140. int _cCnt; // use count (lazily decayed)
  141. FILETIME _ftExecuteTime;
  142. // }
  143. UINT _sidMru; // MRU for this entry
  144. IUASession * _puas; // session callback
  145. BITBOOL _fInited : 1; // 1:we've been initialized
  146. BITBOOL _fDirty : 1; // 1:save me (e.g. _sidMru was xformed)
  147. #if XXX_DELETE
  148. BITBOOL _fInherited : 1; // 1:we didn't exist
  149. #else
  150. BITBOOL _fUnused : 1;
  151. #endif
  152. BITBOOL _fNoDecay : 1; // 1:don't decay me
  153. BITBOOL _fNoPurge : 1; // 1:don't auto-delete me (debug)
  154. private:
  155. };