1 // This is a part of the Active Template Library.
2 // Copyright (C) Microsoft Corporation
3 // All rights reserved.
5 // This source code is only intended as a supplement to the
6 // Active Template Library Reference and related
7 // electronic documentation provided with the library.
8 // See these sources for detailed information regarding the
9 // Active Template Library product.
11 #ifndef __ATLEXTMGMT_H__
12 #define __ATLEXTMGMT_H__
16 #pragma warning(disable: 4702)
19 #include <atlsrvres.h>
20 #include <atlsecurity.h>
23 // You can change the local group that is used for authorizing
24 // site administrators by #define'ing ATL_DEFAULT_AUTH group
25 // to something else before including this header file. For
27 // #define ATL_DEFAULT_AUTHGRP CSid(_T("My Heros"))
28 // Verify that the logged on user is a member of
29 // the local group 'My Heros' before allowing them to
30 // administrate this site.
32 // #define ATL_DEFAULT_AUTHGRP Sids::World
33 // Allow everyone access
35 // #define ATL_DEFAULT_AUTHGRP Sids::Null
36 // Allow no one access
38 #ifndef ATL_DEFAULT_AUTHGRP
39 #define ATL_DEFAULT_AUTHGRP Sids::Admins()
42 // If you #define ATL_NO_DEFAULT_AUTHORITY then there will be no authorization
43 // check before allowing access to management functions. You can also #define
44 // ATL_NO_DEFAULT_AUTHORITY and then declare you own instance of _Authority
45 // before #include-ing atlextmgmt.h to use a different authorization scheme.
46 #ifndef ATL_NO_DEFAULT_AUTHORITY
47 __declspec(selectany
) CDefaultAuth _Authority
;
50 // You can choose which of the management handlers actually get used by
51 // #defining the following constants before including this header
52 // _ATL_THREADPOOL_MANAGEMENT (The thread pool manager web service and web based UI)
53 // _ATL_STENCILCACHE_MANAGEMENT (The stencil cache manager web service and web based UI)
54 // _ATL_DLLCACHE_MANAGEMENT (The DLL cache manager service and web based UI)
56 // You can use the following constants to remove the web based UI if you don't
58 // _ATL_THREADPOOL_NOUI (removes the thread pool mgr's stencil handler)
59 // _ATL_STENCILCACHE_NOUI (removes the stencil cache mgr's stencil handler)
60 // _ATL_DLLCACHE_NOUI (removes the dll cache mgr's stencil handler)
62 // You can use the following constants to remove the web service management
63 // components individually
64 // _ATL_THREADPOOL_NOWEBSERVICE (removes the thread pool mgr's stencil handler)
65 // _ATL_STENCILCACHE_NOWEBSERVICE (removes the stencil cache mgr's stencil handler)
66 // _ATL_DLLCACHE_NOWEBSERVICE (removes the dll cache mgr's stencil handler)
69 // The following constants declare resource names of stencils included
70 // as resources in the module that uses this header. These stencils are
71 // used for the web based UI for the management objects. You can provide
72 // stencils of your own by including them as resources and redefining these
73 // constants before including this header.
74 #ifndef IDR_THREADMGR_SRF
75 #define IDR_THREADMGR_SRF "THREADMGR.SRF"
78 #ifndef IDR_STENCILMGR_SRF
79 #define IDR_STENCILMGR_SRF "STENCILMGR.SRF"
82 #ifndef IDR_DLLMGR_SRF
83 #define IDR_DLLMGR_SRF "DLLMGR.SRF"
86 // A warning so users using the web based UI to manage their extension
87 // will remember to include the stencil resources in their projects
88 #if (defined(_ATL_THREADPOOL_MANAGEMENT) && !defined(_ATL_THREADPOOL_NOUI)) || (defined(_ATL_STENCILCACHE_MANAGEMENT) && !defined(_ATL_STENCILCACHE_NOUI)) || (defined(_ATL_DLLCACHE_MANAGEMENT) && !defined(_ATL_DLLCACHE_NOUI))
89 #ifndef NO_ATL_MGMT_STENCIL_WARNING
90 #pragma message("*************** Please Note ***************")
91 #pragma message("Your usage of atlextmgmt.h requires you to include management")
92 #pragma message("stencil resources in your module's resource file.")
93 #pragma message("Please make sure you include atlsrv.rc in your resource file.\r\n")
97 // These constants define the names used for the handler objects for the
98 // various services. You can change the names by redefining these constants
99 // before including this header
101 #ifndef ID_THREADMGR_WEBSERVICE_NAME
102 #define ID_THREADMGR_WEBSERVICE_NAME "ThreadPoolManager"
105 #ifndef ID_THREADMGR_WEBSERVICE_URL
106 #define ID_THREADMGR_WEBSERVICE_URL "http://www.microsoft.com/vc/atlserver/soap/ThreadPoolManager"
109 #ifndef ID_THREADMGR_WEBSERVICE_WSDL
110 #define ID_THREADMGR_WEBSERVICE_WSDL "GenThreadPoolManagerWSDL"
113 #ifndef ID_THREADMGR_SRFHANDLER_NAME
114 #define ID_THREADMGR_SRFHANDLER_NAME "ThreadMgrSrf"
117 #ifndef ID_STENCILCACHEMGR_WEBSERVICE_NAME
118 #define ID_STENCILCACHEMGR_WEBSERVICE_NAME "StencilCacheManager"
121 #ifndef ID_STENCILCACHEMGR_WEBSERVICE_URL
122 #define ID_STENCILCACHEMGR_WEBSERVICE_URL "http://www.microsoft.com/vc/atlserver/soap/StencilCacheManager"
125 #ifndef ID_STENCILCACHEMGR_WEBSERVICE_WSDL
126 #define ID_STENCILCACHEMGR_WEBSERVICE_WSDL "GenStencilCacheManagerWSDL"
129 #ifndef ID_STENCILCACHEMGR_SRFHANDLER_NAME
130 #define ID_STENCILCACHEMGR_SRFHANDLER_NAME "StencilMgrSrf"
133 #ifndef ID_DLLCACHEMGR_WEBSERVICE_NAME
134 #define ID_DLLCACHEMGR_WEBSERVICE_NAME "DllCacheManager"
137 #ifndef ID_DLLCACHEMGR_WEBSERVICE_URL
138 #define ID_DLLCACHEMGR_WEBSERVICE_URL "http://www.microsoft.com/vc/atlserver/soap/DllCacheManager"
141 #ifndef ID_DLLCACHEMGR_WEBSERVICE_WSDL
142 #define ID_DLLCACHEMGR_WEBSERVICE_WSDL "GenDllCacheManagerWSDL"
146 #ifndef ID_DLLCACHEMGR_SRFHANDLER_NAME
147 #define ID_DLLCACHEMGR_SRFHANDLER_NAME "DllMgrSrf"
150 #pragma pack(push,_ATL_PACKING)
153 [emitidl(restricted
)];
155 #define ATL_COLOR_TR1 RGB(0xd2, 0xff, 0xff)
156 #define ATL_COLOR_TR2 RGB(0xd2, 0xff, 0xd2)
157 #define ATL_COLOR_BODYBG RGB(0xec, 0xf9, 0xec)
159 // _AtlRedirectToPage builds up a redirect URL from the
160 // current request plus a Handler= specification and
161 // redirects the user's browser to that page.
162 inline HTTP_CODE
_AtlRedirectToPage(
163 IHttpServerContext
*pContext
,
164 CHttpRequest
& request
,
165 CHttpResponse
& response
,
166 const char *szHandler
)
169 CStringA
strRedirect("http://");
171 char buff
[ATL_URL_MAX_URL_LENGTH
];
172 DWORD dwLen
= static_cast<DWORD
>(_countof(buff
));
173 if (!pContext
->GetServerVariable("SERVER_NAME", buff
, &dwLen
))
177 buff
[_countof(buff
)-1]='\0';
180 dwLen
= static_cast<DWORD
>(_countof(buff
));
181 if (!request
.GetUrl(buff
, &dwLen
))
185 buff
[_countof(buff
)-1]='\0';
187 strRedirect
+=szHandler
;
189 if (strRedirect
.GetLength() >= ATL_URL_MAX_URL_LENGTH
)
194 BOOL bOK
=response
.Redirect(strRedirect
.GetString());
196 return bOK
? HTTP_SUCCESS_NO_PROCESS
: HTTP_FAIL
;
199 #ifdef _ATL_THREADPOOL_MANAGEMENT
200 ///////////////////////////////////////////////////////////////////////
201 // Thread pool management
203 [ uuid("44e9962a-5207-4d2a-a466-5f08a76e0e5d"), object
]
204 __interface IThreadPoolMgr
206 [id(0)] STDMETHOD(SetSize
)([in
] int nNumThreads
);
207 [id(1)] STDMETHOD(GetSize
)([out
,retval
] int *pnNumThreads
);
212 class CThreadPoolMgrObject
215 CThreadPoolMgrObject() throw()
219 HRESULT
SetSize(int nNumThreads
) throw()
221 if (!m_spThreadPoolConfig
)
224 CRevertThreadToken revert
;
225 if (!revert
.Initialize())
228 HRESULT hr
= m_spThreadPoolConfig
->SetSize(nNumThreads
);
230 DWORD dwErr
= revert
.Restore();
232 return AtlHresultFromWin32(dwErr
);
238 HRESULT
GetSize(int *pnNumThreads
) throw()
240 if (!m_spThreadPoolConfig
)
243 return m_spThreadPoolConfig
->GetSize(pnNumThreads
);
247 HTTP_CODE
Initialize(IServiceProvider
*pProvider
) throw()
249 ATLASSERT(pProvider
); // should never be NULL
251 return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED
);
253 if (m_spThreadPoolConfig
)
254 return HTTP_SUCCESS
; // already initialized
256 pProvider
->QueryService(__uuidof(IThreadPoolConfig
), &m_spThreadPoolConfig
);
257 return m_spThreadPoolConfig
? HTTP_SUCCESS
: HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED
);
261 CComPtr
<IThreadPoolConfig
> m_spThreadPoolConfig
;
264 #ifndef _ATL_THREADPOOL_NOWEBSERVICE
265 #pragma warning(push)
266 #pragma warning(disable:4199)
269 name
= ID_THREADMGR_WEBSERVICE_NAME
,
270 namespace= ID_THREADMGR_WEBSERVICE_URL
,
274 name
= ID_THREADMGR_WEBSERVICE_NAME
,
275 sdl
= ID_THREADMGR_WEBSERVICE_WSDL
278 class CThreadPoolManager
:
279 public IThreadPoolMgr
284 STDMETHOD(SetSize
)(int nNumThreads
)
286 return m_PoolMgr
.SetSize(nNumThreads
);
290 STDMETHOD(GetSize
)(int *pnNumThreads
)
292 return m_PoolMgr
.GetSize(pnNumThreads
);
295 // override HandleRequest to Initialize our m_spServiceProvider
296 // and to handle authorizing the client.
297 HTTP_CODE
HandleRequest(AtlServerRequest
*pRequestInfo
, IServiceProvider
*pProvider
)
299 HTTP_CODE hcErr
= m_PoolMgr
.Initialize(pProvider
);
300 if (hcErr
!= HTTP_SUCCESS
)
303 // Make sure caller is authorized on this system
304 __if_exists(_Authority
)
307 ATLTRY(hcErr
= _Authority
.IsAuthorized(pRequestInfo
, ATL_DEFAULT_AUTHGRP
))
309 if (hcErr
== HTTP_SUCCESS
)
311 hcErr
= __super::HandleRequest(pRequestInfo
, pProvider
);
316 CThreadPoolMgrObject m_PoolMgr
;
318 #endif //_ATL_THREADPOOL_NOWEBSERVICE
320 #ifndef _ATL_THREADPOOL_NOUI
321 #define INVALID_COMMAND_ID -1
322 #define MAX_COMMAND_ID 64
324 [request_handler(name
=ID_THREADMGR_SRFHANDLER_NAME
)]
325 class CThreadMgrStencil
328 CThreadMgrStencil() :
329 m_nColor(ATL_COLOR_TR1
)
334 [tag_name("GetSize")]
338 HRESULT hr
= m_PoolMgr
.GetSize(&nSize
);
341 m_HttpResponse
<< nSize
;
344 m_HttpResponse
<< "size not found";
349 [tag_name("GetTRColor")]
350 HTTP_CODE
GetTRColor()
352 m_nColor
= (m_nColor
== ATL_COLOR_TR1
) ? ATL_COLOR_TR2
: ATL_COLOR_TR1
;
354 if (RGBToHtml(m_nColor
, cr
, sizeof(cr
)))
355 m_HttpResponse
<< cr
;
360 [tag_name("GetBodyColor")]
361 HTTP_CODE
GetBodyColor()
364 if (RGBToHtml(ATL_COLOR_BODYBG
, cr
, sizeof(cr
)))
365 m_HttpResponse
<< cr
;
370 HTTP_CODE
ValidateAndExchange() throw()
374 // Initialize the thread pool manager instance. Internally
375 // the initialize function will only intialize it's data structures
377 HTTP_CODE hcErr
= m_PoolMgr
.Initialize(m_spServiceProvider
);
378 if (hcErr
!= HTTP_SUCCESS
)
381 __if_exists(_Authority
)
383 // Make sure caller is authorized on this system
385 ATLTRY(hcErr
= _Authority
.IsAuthorized(m_pRequestInfo
, ATL_DEFAULT_AUTHGRP
))
386 if (hcErr
!= HTTP_SUCCESS
)
391 m_HttpResponse
.SetContentType("text/html");
393 CString strHandler
, strOptParam
;
394 int nCmdToExec
= INVALID_COMMAND_ID
;
396 if (m_HttpRequest
.GetMethod() == CHttpRequest::HTTP_METHOD_POST
)
398 // check to see if we have a "Method" form variable and can execute a command
399 DWORD dwErr
= m_HttpRequest
.FormVars
.Exchange("Method", &strHandler
);
400 if (dwErr
== VALIDATION_S_OK
)
402 if (strHandler
== _T("ExecuteCommand"))
404 // get the value of the command parameter so we can execute it
405 dwErr
= m_HttpRequest
.FormVars
.Validate("command", &nCmdToExec
, 0, MAX_COMMAND_ID
);
406 if (dwErr
== VALIDATION_S_OK
)
408 // get the optional parameter if it's there.
409 m_HttpRequest
.FormVars
.Validate("DynValue", &strOptParam
, 0, MAX_COMMAND_ID
);
411 hcErr
= ExecCommand(nCmdToExec
, strOptParam
);
418 // If we had a proper command to execute, we would have done it by now.
419 // Just handle like it's a normal request to view the thread count.
420 hcErr
= LoadStencilResource(m_hInstHandler
, IDR_THREADMGR_SRF
);
430 HTTP_CODE
ExecCommand(int nCmdToExec
, CString
& strOptParam
)
436 int nValue
= _tcstoul(strOptParam
, &pStop
, 10);
437 m_PoolMgr
.SetSize(nValue
);
441 return _AtlRedirectToPage(
445 "?Handler=" ID_THREADMGR_SRFHANDLER_NAME
449 CThreadPoolMgrObject m_PoolMgr
;
456 #endif // _ATL_THREADPOOL_NOUI
457 #endif // _ATL_THREADPOOL_MANAGEMENT
459 #ifdef _ATL_STENCILCACHE_MANAGEMENT
460 //////////////////////////////////////////////////////////////////////
461 // Stencil cache management
462 class CStencilCacheMgrObject
465 CStencilCacheMgrObject()
470 HRESULT
GetCurrentEntryCount(__int64
*pdwSize
)
472 ATLASSUME(m_spMemCacheStats
);
477 HRESULT hr
= m_spMemCacheStats
->GetCurrentEntryCount(&dwValue
);
487 ATLENSURE(m_spMemCacheStats
);
488 return m_spMemCacheStats
->ClearStats();
491 HRESULT
GetHitCount(__int64
*pdwSize
)
493 ATLENSURE(m_spMemCacheStats
);
498 HRESULT hr
= m_spMemCacheStats
->GetHitCount(&dwValue
);
506 HRESULT
GetMissCount(__int64
*pdwSize
)
508 ATLENSURE(m_spMemCacheStats
);
514 HRESULT hr
= m_spMemCacheStats
->GetMissCount(&dwValue
);
522 HRESULT
GetCurrentAllocSize(__int64
*pdwSize
)
524 ATLENSURE(m_spMemCacheStats
);
530 HRESULT hr
= m_spMemCacheStats
->GetCurrentAllocSize(&dwValue
);
538 HRESULT
GetMaxAllocSize(__int64
*pdwSize
)
540 ATLENSURE(m_spMemCacheStats
);
546 HRESULT hr
= m_spMemCacheStats
->GetMaxAllocSize(&dwValue
);
555 HRESULT
GetMaxEntryCount(__int64
*pdwSize
)
557 ATLENSURE(m_spMemCacheStats
);
563 HRESULT hr
= m_spMemCacheStats
->GetMaxEntryCount(&dwValue
);
572 HRESULT
RemoveStencil(__int64 hStencil
)
574 ATLENSURE(m_spStencilCacheControl
);
575 return m_spStencilCacheControl
->RemoveStencil((const HCACHEITEM
)hStencil
);
578 HRESULT
RemoveStencilByName(BSTR szStencil
) throw()
580 ATLENSURE_RETURN(m_spStencilCacheControl
);
581 return m_spStencilCacheControl
->RemoveStencilByName(CW2A(szStencil
));
585 HRESULT
RemoveAllStencils()
587 ATLENSURE(m_spStencilCacheControl
);
588 return m_spStencilCacheControl
->RemoveAllStencils();
591 // we show lifespan in milliseconds in the UI so we have to
592 // do the conversion to 100ns intervals here.
593 HRESULT
SetDefaultLifespan(unsigned __int64 dwdwLifespan
)
595 ATLENSURE(m_spStencilCacheControl
);
596 // convert to 100ns intervals
597 return m_spStencilCacheControl
->SetDefaultLifespan(dwdwLifespan
* CFileTime::Millisecond
);
600 HRESULT
GetDefaultLifespan(unsigned __int64
*pdwdwLifespan
)
602 ATLENSURE(m_spStencilCacheControl
);
603 ATLENSURE(pdwdwLifespan
!=NULL
);
605 unsigned __int64 dwls
= 0;
606 HRESULT hr
= m_spStencilCacheControl
->GetDefaultLifespan(&dwls
);
608 // convert to milliseconds
611 dwls
/= CFileTime::Millisecond
;
612 *pdwdwLifespan
= dwls
;
618 HTTP_CODE
Initialize(IServiceProvider
*pProvider
) throw()
621 ATLASSERT(pProvider
); // should never be NULL
623 return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED
);
626 if (m_spMemCacheStats
&& m_spStencilCacheControl
)
627 return HTTP_SUCCESS
; // already initialized
629 CComPtr
<IStencilCache
> spStencilCache
;
630 pProvider
->QueryService(__uuidof(IStencilCache
), &spStencilCache
);
633 if (!m_spMemCacheStats
)
635 spStencilCache
->QueryInterface(__uuidof(IMemoryCacheStats
),
636 (void**)&m_spMemCacheStats
);
638 if (!m_spStencilCacheControl
)
640 spStencilCache
->QueryInterface(__uuidof(IStencilCacheControl
),
641 (void**)&m_spStencilCacheControl
);
645 return (m_spMemCacheStats
&& m_spStencilCacheControl
)
646 ? HTTP_SUCCESS
: HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED
);
650 CComPtr
<IMemoryCacheStats
> m_spMemCacheStats
;
651 CComPtr
<IStencilCacheControl
> m_spStencilCacheControl
;
655 #ifndef _ATL_STENCILCACHE_NOWEBSERVICE
657 [ uuid("3813895C-4C4C-41df-95F4-12220140B164"), object
]
658 __interface IStencilCacheMgr
661 [id(0)] STDMETHOD(GetCurrentEntryCount
)([out
,retval
] __int64
*pdwSize
);
662 [id(1)] STDMETHOD(GetHitCount
)([out
,retval
] __int64
*pdwSize
);
663 [id(2)] STDMETHOD(GetMissCount
)([out
,retval
] __int64
*pdwSize
);
664 [id(3)] STDMETHOD(GetCurrentAllocSize
)([out
,retval
] __int64
*pdwSize
);
665 [id(4)] STDMETHOD(GetMaxAllocSize
)([out
,retval
] __int64
*pdwSize
);
666 [id(5)] STDMETHOD(GetMaxEntryCount
)([out
,retval
] __int64
*pdwSize
);
667 [id(6)] STDMETHOD(GetDefaultLifespan
)([out
,retval
] unsigned __int64
*pdwdwLifespan
);
670 [id(7)] STDMETHOD(ClearStats
)();
671 [id(8)] STDMETHOD(RemoveStencil
)([in
] __int64 hStencil
);
672 [id(9)] STDMETHOD(RemoveStencilByName
)([in
] BSTR szStencil
);
673 [id(10)] STDMETHOD(RemoveAllStencils
)();
674 [id(11)] STDMETHOD(SetDefaultLifespan
)([in
] unsigned __int64 dwdwLifespan
);
677 #pragma warning(push)
678 #pragma warning(disable:4199)
680 soap_handler( name
= ID_STENCILCACHEMGR_WEBSERVICE_NAME
,
681 namespace= ID_STENCILCACHEMGR_WEBSERVICE_URL
,
685 name
= ID_STENCILCACHEMGR_WEBSERVICE_NAME
,
686 sdl
= ID_STENCILCACHEMGR_WEBSERVICE_WSDL
)
688 class CStencilCacheManager
:
689 public IStencilCacheMgr
694 STDMETHOD(GetCurrentEntryCount
)(__int64
*pdwSize
)
696 return m_MgrObj
.GetCurrentEntryCount(pdwSize
);
700 STDMETHOD(ClearStats
)()
702 return m_MgrObj
.ClearStats();
706 STDMETHOD(GetHitCount
)(__int64
*pdwSize
)
708 return m_MgrObj
.GetHitCount(pdwSize
);
712 STDMETHOD(GetMissCount
)(__int64
*pdwSize
)
714 return m_MgrObj
.GetMissCount(pdwSize
);
718 STDMETHOD(GetCurrentAllocSize
)(__int64
*pdwSize
)
720 return m_MgrObj
.GetCurrentAllocSize(pdwSize
);
724 STDMETHOD(GetMaxAllocSize
)(__int64
*pdwSize
)
726 return m_MgrObj
.GetMaxAllocSize(pdwSize
);
730 STDMETHOD(GetMaxEntryCount
)(__int64
*pdwSize
)
732 return m_MgrObj
.GetMaxEntryCount(pdwSize
);
736 STDMETHOD(RemoveStencil
)(__int64 hStencil
)
738 return m_MgrObj
.RemoveStencil(hStencil
);
742 STDMETHOD(RemoveStencilByName
)(BSTR bstrStencil
)
744 return m_MgrObj
.RemoveStencilByName(bstrStencil
);
748 STDMETHOD(RemoveAllStencils
)()
750 return m_MgrObj
.RemoveAllStencils();
753 // we show lifespan in milliseconds in the UI.
754 // m_MgrObj handles the conversion to 100ns intervals.
756 STDMETHOD(SetDefaultLifespan
)(unsigned __int64 dwdwLifespan
)
758 return m_MgrObj
.SetDefaultLifespan(dwdwLifespan
);
762 STDMETHOD(GetDefaultLifespan
)(unsigned __int64
*pdwdwLifespan
)
764 return m_MgrObj
.GetDefaultLifespan(pdwdwLifespan
);
767 HTTP_CODE
HandleRequest(AtlServerRequest
*pRequestInfo
, IServiceProvider
*pProvider
)
769 HTTP_CODE hcErr
= m_MgrObj
.Initialize(pProvider
);
770 if (hcErr
!= HTTP_SUCCESS
)
773 __if_exists(_Authority
)
775 // Make sure caller is authorized on this system
777 ATLTRY(hcErr
= _Authority
.IsAuthorized(pRequestInfo
, ATL_DEFAULT_AUTHGRP
))
779 if (hcErr
== HTTP_SUCCESS
)
781 hcErr
= __super::HandleRequest(pRequestInfo
, pProvider
);
786 CStencilCacheMgrObject m_MgrObj
;
788 #endif //_ATL_STENCILCACHE_NOWEBSERVICE
789 #ifndef _ATL_STENCILCACHE_NOUI
790 typedef HRESULT (CStencilCacheMgrObject::*PFNGETDATA
)(__int64
*pdwSize
);
798 #define INVALID_DATA_PTR ((DWORD_PTR) -1)
799 #define INVALID_COMMAND_ID -1
800 #define MAX_COMMAND_ID 64
801 #define ATL_STENCILCACHECMD_CLEARALLSTATS 0
802 #define ATL_STENCILCACHECMD_REMOVESTENCIL 1
803 #define ATL_STENCILCACHECMD_REMOVEALLSTENCILS 2
804 #define ATL_STENCILCACHECMD_SETDEFLIFESPAN 3
806 [request_handler(name
=ID_STENCILCACHEMGR_SRFHANDLER_NAME
)]
812 m_pData
= (CCache_data
*)INVALID_DATA_PTR
;
813 m_nColor
= ATL_COLOR_TR1
;
816 HTTP_CODE
ValidateAndExchange() throw()
820 HTTP_CODE hcErr
= m_MgrObj
.Initialize(m_spServiceProvider
);
821 if (hcErr
!= HTTP_SUCCESS
)
824 __if_exists(_Authority
)
826 // Make sure caller is authorized on this system
828 ATLTRY(hcErr
= _Authority
.IsAuthorized(m_pRequestInfo
, ATL_DEFAULT_AUTHGRP
))
829 if (hcErr
!= HTTP_SUCCESS
)
832 m_HttpResponse
.SetContentType("text/html");
834 // check to see if we have a "Handler" form variable
835 CString strHandler
, strOptParam
;
838 if (m_HttpRequest
.GetMethod() == CHttpRequest::HTTP_METHOD_POST
)
840 DWORD dwErr
= m_HttpRequest
.FormVars
.Exchange("Method", &strHandler
);
841 if (dwErr
== VALIDATION_S_OK
)
843 if (strHandler
== _T("ExecuteCommand"))
845 // get the value of the command parameter so we can execute it
846 dwErr
= m_HttpRequest
.FormVars
.Validate("command", &nCmdToExec
, 0, MAX_COMMAND_ID
);
847 if (dwErr
== VALIDATION_S_OK
)
849 // get the optional parameter if it's there.
850 m_HttpRequest
.FormVars
.Validate("DynValue", &strOptParam
, 0, MAX_COMMAND_ID
);
851 hcErr
= ExecCommand(nCmdToExec
, strOptParam
);
857 hcErr
= LoadStencilResource(m_hInstHandler
, IDR_STENCILMGR_SRF
);
866 HTTP_CODE
ExecCommand(int nCmdToExec
, CString
& strOptParam
)
870 case ATL_STENCILCACHECMD_CLEARALLSTATS
:
871 m_MgrObj
.ClearStats();
874 case ATL_STENCILCACHECMD_REMOVESTENCIL
:
875 m_MgrObj
.RemoveStencilByName(strOptParam
.AllocSysString());
878 case ATL_STENCILCACHECMD_REMOVEALLSTENCILS
:
879 m_MgrObj
.RemoveAllStencils();
882 case ATL_STENCILCACHECMD_SETDEFLIFESPAN
:
884 m_MgrObj
.SetDefaultLifespan(_tcstoul(strOptParam
, &pStop
, 10));
888 return _AtlRedirectToPage(
892 "?Handler=" ID_STENCILCACHEMGR_SRFHANDLER_NAME
897 [tag_name("GetNextStencilCacheStats")]
898 HTTP_CODE
GetNextStencilCacheStats()
900 if (m_pData
== (CCache_data
*)INVALID_DATA_PTR
)
902 m_pData
= GetCacheData();
907 if (m_pData
->m_pfn
!= NULL
)
910 m_pData
= (CCache_data
*)INVALID_DATA_PTR
;
915 [tag_name("GetCacheValue")]
916 HTTP_CODE
GetCacheValue()
919 ATLENSURE(m_pData
!= (CCache_data
*)INVALID_DATA_PTR
);
920 m_HttpResponse
<< m_pData
->m_sz
;
924 [tag_name("GetCacheQuantity")]
925 HTTP_CODE
GetCacheQuantity()
928 ATLENSURE(m_pData
!= (CCache_data
*)INVALID_DATA_PTR
);
930 PFNGETDATA pfn
= m_pData
->m_pfn
;
932 CStencilCacheMgrObject
*pMgr
= &m_MgrObj
;
933 (pMgr
->*pfn
)(&dwValue
);
935 m_HttpResponse
<< dwValue
;
939 [tag_name("GetTRColor")]
940 HTTP_CODE
GetTRColor()
942 m_nColor
= (m_nColor
== ATL_COLOR_TR1
) ? ATL_COLOR_TR2
: ATL_COLOR_TR1
;
944 if (RGBToHtml(m_nColor
, cr
, sizeof(cr
)))
945 m_HttpResponse
<< cr
;
950 [tag_name("GetBodyColor")]
951 HTTP_CODE
GetBodyColor()
954 if (RGBToHtml(ATL_COLOR_BODYBG
, cr
, sizeof(cr
)))
955 m_HttpResponse
<< cr
;
959 static CCache_data
* GetCacheData()
961 static CCache_data cache_data
[] =
963 {(PFNGETDATA
)&CStencilCacheMgrObject::GetCurrentEntryCount
, "Current Cache Entry Count(stencils)"},
964 {(PFNGETDATA
)&CStencilCacheMgrObject::GetHitCount
, "Cache Hit Count(stencils)"},
965 {(PFNGETDATA
)&CStencilCacheMgrObject::GetMissCount
, "Cache Miss Count(stencils)"},
966 {(PFNGETDATA
)&CStencilCacheMgrObject::GetCurrentAllocSize
, "Cache memory allocation(bytes)"},
967 {(PFNGETDATA
)&CStencilCacheMgrObject::GetMaxAllocSize
, "Cache maximum allocation size(bytes)"},
968 {(PFNGETDATA
)&CStencilCacheMgrObject::GetMaxEntryCount
, "Cache maximum entry count(stencils)"},
969 {(PFNGETDATA
)&CStencilCacheMgrObject::GetDefaultLifespan
, "Default stencil lifespan(ms)"},
975 CStencilCacheMgrObject m_MgrObj
;
976 CCache_data
*m_pData
;
979 //__declspec(selectany) CComObjectGlobal<CStencilCacheManager> CStencilMgr::m_cachemgr;
980 #endif // _ATL_STENCILCACHE_NOUI
981 #endif // _ATL_STENCILCACHE_MANAGEMENT
983 //////////////////////////////////////////////////////////////////////
984 // DLL cache management
985 #ifdef _ATL_DLLCACHE_MANAGEMENT
988 #ifndef _ATL_DLLCACHE_NOWEBSERVICE
991 struct _DLL_CACHE_ENTRY
1002 HRESULT
GetEntries(DWORD dwCount
, _DLL_CACHE_ENTRY
*pEntries
, DWORD
*pdwCopied
)
1004 ATLASSUME(m_spDllCache
);
1005 HRESULT hr
= E_FAIL
;
1006 DLL_CACHE_ENTRY
*pe
= NULL
;
1009 return E_UNEXPECTED
;
1011 if (dwCount
!= 0 && pEntries
== NULL
)
1012 return E_UNEXPECTED
; // asking for entries but no place to put them
1020 pe
= new DLL_CACHE_ENTRY
[dwCount
];
1022 return E_OUTOFMEMORY
;
1025 hr
= m_spDllCache
->GetEntries(dwCount
, pe
, pdwCopied
);
1026 if (hr
== S_OK
&& dwCount
!= 0 && pEntries
!= NULL
)
1028 // SysAllocString our path strings
1029 for (DWORD i
= 0; i
<*pdwCopied
; i
++)
1031 pEntries
[i
].hInstDll
= (DWORD
)(DWORD_PTR
)pe
[i
].hInstDll
;
1032 pEntries
[i
].dwRefs
= pe
[i
].dwRefs
;
1033 pEntries
[i
].szDllName
= ::SysAllocString(CA2W(pe
[i
].szDllName
));
1042 HRESULT
GetEntryCount(DWORD
*pdwCount
)
1044 ATLASSUME(m_spDllCache
);
1046 return E_UNEXPECTED
;
1048 return m_spDllCache
->GetEntries(0, NULL
, pdwCount
);
1051 HTTP_CODE
Initialize(IServiceProvider
*pProvider
)
1053 ATLASSERT(pProvider
); // should never be NULL
1055 return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED
);
1058 return HTTP_SUCCESS
; // already initialized
1060 pProvider
->QueryService(__uuidof(IDllCache
), &m_spDllCache
);
1061 return m_spDllCache
? HTTP_SUCCESS
: HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED
);
1065 CComPtr
<IDllCache
> m_spDllCache
;
1070 #ifndef _ATL_DLLCACHE_NOWEBSERVICE
1071 // _DLL_CACHE_ENTRY is our own version of DLL_CACHE_ENTRY(atlcache.h) that
1072 // uses a BSTR instead of a fixed length string for the szDllName for compatiblility
1073 // with our SOAP implementation.
1074 [ uuid("A0C00AF8-CEA5-46b9-97ED-FDEE55B583EF"), object
]
1075 __interface IDllCacheMgr
1077 [id(0)] STDMETHOD(GetEntries
)([in
] DWORD dwCount
, [out
] _DLL_CACHE_ENTRY
*pEntries
, [out
, retval
] DWORD
*pdwCopied
);
1078 [id(1)] STDMETHOD(GetEntryCount
)([out
, retval
] DWORD
*pdwCount
);
1083 #pragma warning(push)
1084 #pragma warning(disable:4199)
1087 name
= ID_DLLCACHEMGR_WEBSERVICE_NAME
,
1088 namespace= ID_DLLCACHEMGR_WEBSERVICE_URL
,
1092 name
= ID_DLLCACHEMGR_WEBSERVICE_NAME
,
1093 sdl
= ID_DLLCACHEMGR_WEBSERVICE_WSDL
1096 class CDllCacheManager
:
1099 #pragma warning(pop)
1102 HRESULT
GetEntries(DWORD dwCount
, _DLL_CACHE_ENTRY
*pEntries
, DWORD
*pdwCopied
)
1104 return m_MgrObj
.GetEntries(dwCount
, pEntries
, pdwCopied
);
1108 STDMETHOD(GetEntryCount
)(DWORD
*pdwCount
)
1110 return m_MgrObj
.GetEntries(0, NULL
, pdwCount
);
1113 HTTP_CODE
HandleRequest(AtlServerRequest
*pRequestInfo
, IServiceProvider
*pProvider
)
1115 HTTP_CODE hcErr
= m_MgrObj
.Initialize(pProvider
);
1116 if (hcErr
!= HTTP_SUCCESS
)
1119 __if_exists(_Authority
)
1121 // Make sure caller is authorized on this system
1123 ATLTRY(hcErr
= _Authority
.IsAuthorized(pRequestInfo
, ATL_DEFAULT_AUTHGRP
))
1125 if (hcErr
== HTTP_SUCCESS
)
1127 hcErr
= __super::HandleRequest(pRequestInfo
, pProvider
);
1133 CDllMgrObject m_MgrObj
;
1135 #endif _ATL_DLLCACHE_NOWEBSERVICE
1137 #ifndef _ATL_DLLCACHE_NOUI
1138 #define INVALID_INDEX -1
1141 request_handler(name
=ID_DLLCACHEMGR_SRFHANDLER_NAME
)
1146 CDllCacheMgr() : m_nColor(ATL_COLOR_TR1
),
1147 m_nEnumCount(INVALID_INDEX
),
1148 m_nEnumIndex(INVALID_INDEX
),
1154 [tag_name("GetTRColor")]
1155 HTTP_CODE
GetTRColor()
1157 m_nColor
= (m_nColor
== ATL_COLOR_TR1
) ? ATL_COLOR_TR2
: ATL_COLOR_TR1
;
1159 if (RGBToHtml(m_nColor
, cr
, sizeof(cr
)))
1160 m_HttpResponse
<< cr
;
1162 return HTTP_SUCCESS
;
1165 [tag_name("GetBodyColor")]
1166 HTTP_CODE
GetBodyColor()
1169 if (RGBToHtml(ATL_COLOR_BODYBG
, cr
, sizeof(cr
)))
1170 m_HttpResponse
<< cr
;
1171 return HTTP_SUCCESS
;
1175 [tag_name("GetNumEntries")]
1176 HTTP_CODE
GetNumEntries()
1178 DWORD dwEntries
= 0;
1179 m_MgrObj
.GetEntryCount(&dwEntries
);
1180 m_HttpResponse
<< dwEntries
;
1181 return HTTP_SUCCESS
;
1185 [tag_name("EnumEntries")]
1186 HTTP_CODE
EnumEntries()
1188 // we lock the cache while we enum entries so no entries
1189 // will be removed during the enumeration request.
1190 if (m_nEnumIndex
== INVALID_INDEX
)
1192 // set up for the iteration
1193 m_MgrObj
.GetEntryCount((DWORD
*)&m_nEnumCount
);
1195 return HTTP_S_FALSE
; // nothing to enum
1197 m_pEntries
= new _DLL_CACHE_ENTRY
[m_nEnumCount
];
1199 return HTTP_ERROR(500, ISE_SUBERR_OUTOFMEM
);
1201 DWORD dwFetched
= INVALID_INDEX
;
1203 if (S_OK
!= m_MgrObj
.GetEntries(m_nEnumCount
, m_pEntries
, &dwFetched
))
1204 return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED
);
1207 return HTTP_SUCCESS
;
1211 if (m_nEnumIndex
< m_nEnumCount
)
1212 return HTTP_SUCCESS
; // continue iterating
1217 for (int i
= 0; i
< m_nEnumCount
; i
++)
1219 ::SysFreeString(m_pEntries
[i
].szDllName
);
1221 delete [] m_pEntries
;
1223 m_nEnumCount
= INVALID_INDEX
;
1224 m_nEnumIndex
= INVALID_INDEX
;
1225 return HTTP_S_FALSE
; // terminate iterations.
1229 [tag_name("GetDllName")]
1230 HTTP_CODE
GetDllName()
1232 m_HttpResponse
<< m_pEntries
[m_nEnumIndex
].szDllName
;
1233 return HTTP_SUCCESS
;
1236 [tag_name("GetDllReferences")]
1237 HTTP_CODE
GetDllReferences()
1239 m_HttpResponse
<< m_pEntries
[m_nEnumIndex
].dwRefs
;
1240 return HTTP_SUCCESS
;
1243 HTTP_CODE
ValidateAndExchange()
1246 HTTP_CODE hcErr
= m_MgrObj
.Initialize(m_spServiceProvider
);
1247 if (hcErr
!= HTTP_SUCCESS
)
1250 __if_exists(_Authority
)
1252 // Make sure caller is authorized on this system
1254 ATLTRY(hcErr
= _Authority
.IsAuthorized(m_pRequestInfo
, ATL_DEFAULT_AUTHGRP
))
1255 if (hcErr
!= HTTP_SUCCESS
)
1258 hcErr
= LoadStencilResource(m_hInstHandler
, IDR_DLLMGR_SRF
);
1259 m_HttpResponse
.SetContentType("text/html");
1264 CDllMgrObject m_MgrObj
;
1268 _DLL_CACHE_ENTRY
*m_pEntries
;
1272 #endif // _ATL_DLLCACHE_NOUI
1273 #endif // _ATL_DLLCACHE_MANAGEMENT
1278 #pragma warning(pop)
1279 #endif // __ATLEXTMGMT_H__