Remove unused ProjectConfiguration
[xy_vsfilter.git] / include / atl / atlextmgmt.h
blob59f8d435322add55ac08bd8ea29de61a7f3c8a5f
1 // This is a part of the Active Template Library.
2 // Copyright (C) Microsoft Corporation
3 // All rights reserved.
4 //
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__
14 #pragma once
15 #pragma warning(push)
16 #pragma warning(disable: 4702)
17 #include <atlsoap.h>
18 #include <atlutil.h>
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
26 // example:
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()
40 #endif
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;
48 #endif
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
57 // want to use it.
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"
76 #endif
78 #ifndef IDR_STENCILMGR_SRF
79 #define IDR_STENCILMGR_SRF "STENCILMGR.SRF"
80 #endif
82 #ifndef IDR_DLLMGR_SRF
83 #define IDR_DLLMGR_SRF "DLLMGR.SRF"
84 #endif
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")
94 #endif
95 #endif
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"
103 #endif
105 #ifndef ID_THREADMGR_WEBSERVICE_URL
106 #define ID_THREADMGR_WEBSERVICE_URL "http://www.microsoft.com/vc/atlserver/soap/ThreadPoolManager"
107 #endif
109 #ifndef ID_THREADMGR_WEBSERVICE_WSDL
110 #define ID_THREADMGR_WEBSERVICE_WSDL "GenThreadPoolManagerWSDL"
111 #endif
113 #ifndef ID_THREADMGR_SRFHANDLER_NAME
114 #define ID_THREADMGR_SRFHANDLER_NAME "ThreadMgrSrf"
115 #endif
117 #ifndef ID_STENCILCACHEMGR_WEBSERVICE_NAME
118 #define ID_STENCILCACHEMGR_WEBSERVICE_NAME "StencilCacheManager"
119 #endif
121 #ifndef ID_STENCILCACHEMGR_WEBSERVICE_URL
122 #define ID_STENCILCACHEMGR_WEBSERVICE_URL "http://www.microsoft.com/vc/atlserver/soap/StencilCacheManager"
123 #endif
125 #ifndef ID_STENCILCACHEMGR_WEBSERVICE_WSDL
126 #define ID_STENCILCACHEMGR_WEBSERVICE_WSDL "GenStencilCacheManagerWSDL"
127 #endif
129 #ifndef ID_STENCILCACHEMGR_SRFHANDLER_NAME
130 #define ID_STENCILCACHEMGR_SRFHANDLER_NAME "StencilMgrSrf"
131 #endif
133 #ifndef ID_DLLCACHEMGR_WEBSERVICE_NAME
134 #define ID_DLLCACHEMGR_WEBSERVICE_NAME "DllCacheManager"
135 #endif
137 #ifndef ID_DLLCACHEMGR_WEBSERVICE_URL
138 #define ID_DLLCACHEMGR_WEBSERVICE_URL "http://www.microsoft.com/vc/atlserver/soap/DllCacheManager"
139 #endif
141 #ifndef ID_DLLCACHEMGR_WEBSERVICE_WSDL
142 #define ID_DLLCACHEMGR_WEBSERVICE_WSDL "GenDllCacheManagerWSDL"
143 #endif
146 #ifndef ID_DLLCACHEMGR_SRFHANDLER_NAME
147 #define ID_DLLCACHEMGR_SRFHANDLER_NAME "DllMgrSrf"
148 #endif
150 #pragma pack(push,_ATL_PACKING)
151 namespace ATL {
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)
168 ATLENSURE(pContext);
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))
175 return HTTP_FAIL;
177 buff[_countof(buff)-1]='\0';
178 strRedirect+=buff;
180 dwLen = static_cast<DWORD>(_countof(buff));
181 if (!request.GetUrl(buff, &dwLen))
183 return HTTP_FAIL;
185 buff[_countof(buff)-1]='\0';
186 strRedirect+=buff;
187 strRedirect+=szHandler;
189 if (strRedirect.GetLength() >= ATL_URL_MAX_URL_LENGTH)
191 return HTTP_FAIL;
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
214 public:
215 CThreadPoolMgrObject() throw()
219 HRESULT SetSize(int nNumThreads) throw()
221 if (!m_spThreadPoolConfig)
222 return E_UNEXPECTED;
224 CRevertThreadToken revert;
225 if (!revert.Initialize())
226 return E_FAIL;
228 HRESULT hr = m_spThreadPoolConfig->SetSize(nNumThreads);
230 DWORD dwErr = revert.Restore();
231 if (dwErr)
232 return AtlHresultFromWin32(dwErr);
234 return hr;
238 HRESULT GetSize(int *pnNumThreads) throw()
240 if (!m_spThreadPoolConfig)
241 return E_UNEXPECTED;
243 return m_spThreadPoolConfig->GetSize(pnNumThreads);
247 HTTP_CODE Initialize(IServiceProvider *pProvider) throw()
249 ATLASSERT(pProvider); // should never be NULL
250 if (!pProvider)
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);
260 private:
261 CComPtr<IThreadPoolConfig> m_spThreadPoolConfig;
264 #ifndef _ATL_THREADPOOL_NOWEBSERVICE
265 #pragma warning(push)
266 #pragma warning(disable:4199)
268 soap_handler(
269 name= ID_THREADMGR_WEBSERVICE_NAME,
270 namespace= ID_THREADMGR_WEBSERVICE_URL,
271 protocol= "soap"
273 request_handler(
274 name= ID_THREADMGR_WEBSERVICE_NAME,
275 sdl= ID_THREADMGR_WEBSERVICE_WSDL
278 class CThreadPoolManager :
279 public IThreadPoolMgr
281 #pragma warning(pop)
282 public:
283 [soap_method]
284 STDMETHOD(SetSize)(int nNumThreads)
286 return m_PoolMgr.SetSize(nNumThreads);
289 [soap_method]
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)
301 return hcErr;
303 // Make sure caller is authorized on this system
304 __if_exists(_Authority)
306 hcErr = HTTP_FAIL;
307 ATLTRY(hcErr = _Authority.IsAuthorized(pRequestInfo, ATL_DEFAULT_AUTHGRP))
309 if (hcErr == HTTP_SUCCESS)
311 hcErr = __super::HandleRequest(pRequestInfo, pProvider);
313 return hcErr;
315 private:
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
327 public:
328 CThreadMgrStencil() :
329 m_nColor(ATL_COLOR_TR1)
334 [tag_name("GetSize")]
335 HTTP_CODE GetSize()
337 int nSize = 0;
338 HRESULT hr = m_PoolMgr.GetSize(&nSize);
339 if (SUCCEEDED(hr))
341 m_HttpResponse << nSize;
343 else
344 m_HttpResponse << "size not found";
346 return HTTP_SUCCESS;
349 [tag_name("GetTRColor")]
350 HTTP_CODE GetTRColor()
352 m_nColor = (m_nColor == ATL_COLOR_TR1) ? ATL_COLOR_TR2 : ATL_COLOR_TR1;
353 TCHAR cr[8];
354 if (RGBToHtml(m_nColor, cr, sizeof(cr)))
355 m_HttpResponse << cr;
357 return HTTP_SUCCESS;
360 [tag_name("GetBodyColor")]
361 HTTP_CODE GetBodyColor()
363 TCHAR cr[8];
364 if (RGBToHtml(ATL_COLOR_BODYBG, cr, sizeof(cr)))
365 m_HttpResponse << cr;
366 return HTTP_SUCCESS;
370 HTTP_CODE ValidateAndExchange() throw()
372 _ATLTRY
374 // Initialize the thread pool manager instance. Internally
375 // the initialize function will only intialize it's data structures
376 // once.
377 HTTP_CODE hcErr = m_PoolMgr.Initialize(m_spServiceProvider);
378 if (hcErr != HTTP_SUCCESS)
379 return hcErr;
381 __if_exists(_Authority)
383 // Make sure caller is authorized on this system
384 hcErr = HTTP_FAIL;
385 ATLTRY(hcErr = _Authority.IsAuthorized(m_pRequestInfo, ATL_DEFAULT_AUTHGRP))
386 if (hcErr != HTTP_SUCCESS)
387 return hcErr;
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);
412 return hcErr;
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);
421 return hcErr;
424 _ATLCATCHALL()
426 return HTTP_FAIL;
430 HTTP_CODE ExecCommand(int nCmdToExec, CString& strOptParam)
432 switch (nCmdToExec)
434 case 0:
435 TCHAR *pStop = NULL;
436 int nValue = _tcstoul(strOptParam, &pStop, 10);
437 m_PoolMgr.SetSize(nValue);
438 break;
441 return _AtlRedirectToPage(
442 m_spServerContext,
443 m_HttpRequest,
444 m_HttpResponse,
445 "?Handler=" ID_THREADMGR_SRFHANDLER_NAME
448 private:
449 CThreadPoolMgrObject m_PoolMgr;
450 long m_nColor;
451 CString m_strUrl;
456 #endif // _ATL_THREADPOOL_NOUI
457 #endif // _ATL_THREADPOOL_MANAGEMENT
459 #ifdef _ATL_STENCILCACHE_MANAGEMENT
460 //////////////////////////////////////////////////////////////////////
461 // Stencil cache management
462 class CStencilCacheMgrObject
464 public:
465 CStencilCacheMgrObject()
470 HRESULT GetCurrentEntryCount(__int64 *pdwSize)
472 ATLASSUME(m_spMemCacheStats);
473 if (!pdwSize)
474 return E_INVALIDARG;
476 DWORD dwValue;
477 HRESULT hr = m_spMemCacheStats->GetCurrentEntryCount(&dwValue);
478 if (hr == S_OK)
480 *pdwSize = dwValue;
482 return hr;
485 HRESULT ClearStats()
487 ATLENSURE(m_spMemCacheStats);
488 return m_spMemCacheStats->ClearStats();
491 HRESULT GetHitCount(__int64 *pdwSize)
493 ATLENSURE(m_spMemCacheStats);
494 if (!pdwSize)
495 return E_INVALIDARG;
497 DWORD dwValue;
498 HRESULT hr = m_spMemCacheStats->GetHitCount(&dwValue);
499 if (hr == S_OK)
501 *pdwSize = dwValue;
503 return hr;
506 HRESULT GetMissCount(__int64 *pdwSize)
508 ATLENSURE(m_spMemCacheStats);
509 if (!pdwSize)
510 return E_INVALIDARG;
512 DWORD dwValue;
514 HRESULT hr = m_spMemCacheStats->GetMissCount(&dwValue);
515 if (hr == S_OK)
517 *pdwSize = dwValue;
519 return hr;
522 HRESULT GetCurrentAllocSize(__int64 *pdwSize)
524 ATLENSURE(m_spMemCacheStats);
525 if (!pdwSize)
526 return E_INVALIDARG;
528 DWORD dwValue;
530 HRESULT hr = m_spMemCacheStats->GetCurrentAllocSize(&dwValue);
531 if (hr == S_OK)
533 *pdwSize = dwValue;
535 return hr;
538 HRESULT GetMaxAllocSize(__int64 *pdwSize)
540 ATLENSURE(m_spMemCacheStats);
541 if (!pdwSize)
542 return E_INVALIDARG;
544 DWORD dwValue;
546 HRESULT hr = m_spMemCacheStats->GetMaxAllocSize(&dwValue);
547 if (hr == S_OK)
549 *pdwSize = dwValue;
551 return hr;
555 HRESULT GetMaxEntryCount(__int64 *pdwSize)
557 ATLENSURE(m_spMemCacheStats);
558 if (!pdwSize)
559 return E_INVALIDARG;
561 DWORD dwValue;
563 HRESULT hr = m_spMemCacheStats->GetMaxEntryCount(&dwValue);
564 if (hr == S_OK)
566 *pdwSize = dwValue;
568 return hr;
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);
604 *pdwdwLifespan = 0;
605 unsigned __int64 dwls = 0;
606 HRESULT hr = m_spStencilCacheControl->GetDefaultLifespan(&dwls);
608 // convert to milliseconds
609 if (SUCCEEDED(hr))
611 dwls /= CFileTime::Millisecond;
612 *pdwdwLifespan = dwls;
615 return hr;
618 HTTP_CODE Initialize(IServiceProvider *pProvider) throw()
621 ATLASSERT(pProvider); // should never be NULL
622 if (!pProvider)
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);
631 if (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);
649 private:
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
660 // data access
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);
669 // commands
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,
682 protocol= "soap"
684 request_handler(
685 name= ID_STENCILCACHEMGR_WEBSERVICE_NAME,
686 sdl= ID_STENCILCACHEMGR_WEBSERVICE_WSDL )
688 class CStencilCacheManager :
689 public IStencilCacheMgr
691 #pragma warning(pop)
692 public:
693 [ soap_method ]
694 STDMETHOD(GetCurrentEntryCount)(__int64 *pdwSize)
696 return m_MgrObj.GetCurrentEntryCount(pdwSize);
699 [ soap_method ]
700 STDMETHOD(ClearStats)()
702 return m_MgrObj.ClearStats();
705 [ soap_method ]
706 STDMETHOD(GetHitCount)(__int64 *pdwSize)
708 return m_MgrObj.GetHitCount(pdwSize);
711 [ soap_method ]
712 STDMETHOD(GetMissCount)(__int64 *pdwSize)
714 return m_MgrObj.GetMissCount(pdwSize);
717 [ soap_method ]
718 STDMETHOD(GetCurrentAllocSize)(__int64 *pdwSize)
720 return m_MgrObj.GetCurrentAllocSize(pdwSize);
723 [ soap_method ]
724 STDMETHOD(GetMaxAllocSize)(__int64 *pdwSize)
726 return m_MgrObj.GetMaxAllocSize(pdwSize);
729 [ soap_method ]
730 STDMETHOD(GetMaxEntryCount)(__int64 *pdwSize)
732 return m_MgrObj.GetMaxEntryCount(pdwSize);
735 [ soap_method ]
736 STDMETHOD(RemoveStencil)(__int64 hStencil)
738 return m_MgrObj.RemoveStencil(hStencil);
741 [ soap_method ]
742 STDMETHOD(RemoveStencilByName)(BSTR bstrStencil)
744 return m_MgrObj.RemoveStencilByName(bstrStencil);
747 [ soap_method ]
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.
755 [ soap_method ]
756 STDMETHOD(SetDefaultLifespan)(unsigned __int64 dwdwLifespan)
758 return m_MgrObj.SetDefaultLifespan(dwdwLifespan);
761 [ soap_method ]
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)
771 return hcErr;
773 __if_exists(_Authority)
775 // Make sure caller is authorized on this system
776 hcErr = HTTP_FAIL;
777 ATLTRY(hcErr = _Authority.IsAuthorized(pRequestInfo, ATL_DEFAULT_AUTHGRP))
779 if (hcErr == HTTP_SUCCESS)
781 hcErr = __super::HandleRequest(pRequestInfo, pProvider);
783 return hcErr;
785 private:
786 CStencilCacheMgrObject m_MgrObj;
788 #endif //_ATL_STENCILCACHE_NOWEBSERVICE
789 #ifndef _ATL_STENCILCACHE_NOUI
790 typedef HRESULT (CStencilCacheMgrObject::*PFNGETDATA)(__int64 *pdwSize);
792 struct CCache_data
794 PFNGETDATA m_pfn;
795 char m_sz[128];
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)]
807 class CStencilMgr
809 public:
810 CStencilMgr()
812 m_pData = (CCache_data*)INVALID_DATA_PTR;
813 m_nColor = ATL_COLOR_TR1;
816 HTTP_CODE ValidateAndExchange() throw()
818 _ATLTRY
820 HTTP_CODE hcErr = m_MgrObj.Initialize(m_spServiceProvider);
821 if (hcErr != HTTP_SUCCESS)
822 return hcErr;
824 __if_exists(_Authority)
826 // Make sure caller is authorized on this system
827 hcErr = HTTP_FAIL;
828 ATLTRY(hcErr = _Authority.IsAuthorized(m_pRequestInfo, ATL_DEFAULT_AUTHGRP))
829 if (hcErr != HTTP_SUCCESS)
830 return hcErr;
832 m_HttpResponse.SetContentType("text/html");
834 // check to see if we have a "Handler" form variable
835 CString strHandler, strOptParam;
836 int nCmdToExec;
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);
852 return hcErr;
857 hcErr = LoadStencilResource(m_hInstHandler, IDR_STENCILMGR_SRF);
858 return hcErr;
860 _ATLCATCHALL()
862 return HTTP_FAIL;
866 HTTP_CODE ExecCommand(int nCmdToExec, CString& strOptParam)
868 switch (nCmdToExec)
870 case ATL_STENCILCACHECMD_CLEARALLSTATS:
871 m_MgrObj.ClearStats();
872 break;
874 case ATL_STENCILCACHECMD_REMOVESTENCIL:
875 m_MgrObj.RemoveStencilByName(strOptParam.AllocSysString());
876 break;
878 case ATL_STENCILCACHECMD_REMOVEALLSTENCILS:
879 m_MgrObj.RemoveAllStencils();
880 break;
882 case ATL_STENCILCACHECMD_SETDEFLIFESPAN:
883 TCHAR *pStop = NULL;
884 m_MgrObj.SetDefaultLifespan(_tcstoul(strOptParam, &pStop, 10));
885 break;
888 return _AtlRedirectToPage(
889 m_spServerContext,
890 m_HttpRequest,
891 m_HttpResponse,
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();
903 return HTTP_SUCCESS;
905 m_pData++;
907 if (m_pData->m_pfn != NULL)
908 return HTTP_SUCCESS;
910 m_pData = (CCache_data*)INVALID_DATA_PTR;
911 return HTTP_S_FALSE;
915 [tag_name("GetCacheValue")]
916 HTTP_CODE GetCacheValue()
918 ATLENSURE(m_pData);
919 ATLENSURE(m_pData != (CCache_data*)INVALID_DATA_PTR);
920 m_HttpResponse << m_pData->m_sz;
921 return HTTP_SUCCESS;
924 [tag_name("GetCacheQuantity")]
925 HTTP_CODE GetCacheQuantity()
927 ATLENSURE(m_pData);
928 ATLENSURE(m_pData != (CCache_data*)INVALID_DATA_PTR);
929 __int64 dwValue = 0;
930 PFNGETDATA pfn = m_pData->m_pfn;
931 ATLENSURE(pfn);
932 CStencilCacheMgrObject *pMgr = &m_MgrObj;
933 (pMgr->*pfn)(&dwValue);
935 m_HttpResponse << dwValue;
936 return HTTP_SUCCESS;
939 [tag_name("GetTRColor")]
940 HTTP_CODE GetTRColor()
942 m_nColor = (m_nColor == ATL_COLOR_TR1) ? ATL_COLOR_TR2 : ATL_COLOR_TR1;
943 TCHAR cr[8];
944 if (RGBToHtml(m_nColor, cr, sizeof(cr)))
945 m_HttpResponse << cr;
947 return HTTP_SUCCESS;
950 [tag_name("GetBodyColor")]
951 HTTP_CODE GetBodyColor()
953 TCHAR cr[8];
954 if (RGBToHtml(ATL_COLOR_BODYBG, cr, sizeof(cr)))
955 m_HttpResponse << cr;
956 return HTTP_SUCCESS;
958 private:
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)"},
970 {NULL, NULL}
972 return cache_data;
975 CStencilCacheMgrObject m_MgrObj;
976 CCache_data *m_pData;
977 long m_nColor;
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
989 [export]
990 #endif
991 struct _DLL_CACHE_ENTRY
993 DWORD hInstDll;
994 DWORD dwRefs;
995 BSTR szDllName;
999 class CDllMgrObject
1001 public:
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;
1008 if (!m_spDllCache)
1009 return E_UNEXPECTED;
1011 if (dwCount != 0 && pEntries == NULL)
1012 return E_UNEXPECTED; // asking for entries but no place to put them
1014 if (!pdwCopied)
1015 return E_POINTER;
1016 *pdwCopied = 0;
1018 if (dwCount)
1020 pe = new DLL_CACHE_ENTRY[dwCount];
1021 if (!pe)
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));
1037 delete [] pe;
1038 return hr;
1042 HRESULT GetEntryCount(DWORD *pdwCount)
1044 ATLASSUME(m_spDllCache);
1045 if (!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
1054 if (!pProvider)
1055 return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
1057 if (m_spDllCache)
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);
1064 private:
1065 CComPtr<IDllCache> m_spDllCache;
1067 }; // CDllMgrObject
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)
1086 soap_handler(
1087 name= ID_DLLCACHEMGR_WEBSERVICE_NAME,
1088 namespace= ID_DLLCACHEMGR_WEBSERVICE_URL,
1089 protocol= "soap"
1091 request_handler(
1092 name= ID_DLLCACHEMGR_WEBSERVICE_NAME,
1093 sdl= ID_DLLCACHEMGR_WEBSERVICE_WSDL
1096 class CDllCacheManager :
1097 public IDllCacheMgr
1099 #pragma warning(pop)
1100 public:
1101 [soap_method]
1102 HRESULT GetEntries(DWORD dwCount, _DLL_CACHE_ENTRY *pEntries, DWORD *pdwCopied)
1104 return m_MgrObj.GetEntries(dwCount, pEntries, pdwCopied);
1107 [soap_method]
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)
1117 return hcErr;
1119 __if_exists(_Authority)
1121 // Make sure caller is authorized on this system
1122 hcErr = HTTP_FAIL;
1123 ATLTRY(hcErr = _Authority.IsAuthorized(pRequestInfo, ATL_DEFAULT_AUTHGRP))
1125 if (hcErr == HTTP_SUCCESS)
1127 hcErr = __super::HandleRequest(pRequestInfo, pProvider);
1129 return hcErr;
1132 protected:
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)
1143 class CDllCacheMgr
1145 public:
1146 CDllCacheMgr() : m_nColor(ATL_COLOR_TR1),
1147 m_nEnumCount(INVALID_INDEX),
1148 m_nEnumIndex(INVALID_INDEX),
1149 m_pEntries(NULL)
1154 [tag_name("GetTRColor")]
1155 HTTP_CODE GetTRColor()
1157 m_nColor = (m_nColor == ATL_COLOR_TR1) ? ATL_COLOR_TR2 : ATL_COLOR_TR1;
1158 TCHAR cr[8];
1159 if (RGBToHtml(m_nColor, cr, sizeof(cr)))
1160 m_HttpResponse << cr;
1162 return HTTP_SUCCESS;
1165 [tag_name("GetBodyColor")]
1166 HTTP_CODE GetBodyColor()
1168 TCHAR cr[8];
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);
1194 if (!m_nEnumCount)
1195 return HTTP_S_FALSE; // nothing to enum
1197 m_pEntries = new _DLL_CACHE_ENTRY[m_nEnumCount];
1198 if (!m_pEntries)
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);
1206 m_nEnumIndex = 0;
1207 return HTTP_SUCCESS;
1210 m_nEnumIndex++;
1211 if (m_nEnumIndex < m_nEnumCount)
1212 return HTTP_SUCCESS; // continue iterating
1214 else
1216 // done, clean up
1217 for (int i = 0; i< m_nEnumCount; i++)
1219 ::SysFreeString(m_pEntries[i].szDllName);
1221 delete [] m_pEntries;
1222 m_pEntries = NULL;
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)
1248 return hcErr;
1250 __if_exists(_Authority)
1252 // Make sure caller is authorized on this system
1253 hcErr = HTTP_FAIL;
1254 ATLTRY(hcErr = _Authority.IsAuthorized(m_pRequestInfo, ATL_DEFAULT_AUTHGRP))
1255 if (hcErr != HTTP_SUCCESS)
1256 return hcErr;
1258 hcErr = LoadStencilResource(m_hInstHandler, IDR_DLLMGR_SRF);
1259 m_HttpResponse.SetContentType("text/html");
1260 return hcErr;
1264 CDllMgrObject m_MgrObj;
1265 long m_nColor;
1266 int m_nEnumCount;
1267 int m_nEnumIndex;
1268 _DLL_CACHE_ENTRY *m_pEntries;
1272 #endif // _ATL_DLLCACHE_NOUI
1273 #endif // _ATL_DLLCACHE_MANAGEMENT
1275 }; // ATL
1277 #pragma pack(pop)
1278 #pragma warning(pop)
1279 #endif // __ATLEXTMGMT_H__