Support unrar64.dll
[xy_vsfilter.git] / include / atl / atlsharedsvc.h
blobb309f12c6300d682fae51522bfadf7d6f0ae671e
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 __ATLSHAREDSVC_H__
12 #define __ATLSHAREDSVC_H__
14 #pragma once
16 #include <atltime.h>
17 #include <atlsoap.h>
18 #pragma pack(push,_ATL_PACKING)
19 namespace ATL{
21 #ifndef ATL_SHAREDBLOBCACHE_TIMEOUT
22 #define ATL_SHAREDBLOBCACHE_TIMEOUT 36000000000 // in 100 nano second intervals
23 // each entry will be free'd if
24 // no access in 1 hour.
25 #endif
27 // Interface used by to access the shared blob cache.
28 [ uuid("AB4AF9CD-8DB1-4974-A617-CF0449578FB9"), object ]
29 __interface ISharedBlobCache
31 [id(0)] STDMETHOD(AddItem)([in] BSTR szItemName, [in] BSTR szData);
32 [id(1)] STDMETHOD(GetItem)([in] BSTR szItemName, [out,retval] BSTR *szData);
35 class CSharedCache:
36 public CBlobCache<CWorkerThread<>, CStdStatClass >,
37 public IMemoryCacheClient,
38 public ISharedBlobCache
40 typedef CBlobCache<CWorkerThread<>, CStdStatClass > basecache;
41 public:
43 // IMemoryCacheClient method, frees data in the memory cache.
44 STDMETHOD( Free )(const void *pvData)
46 if (pvData)
48 ::SysFreeString((BSTR)pvData);
50 return S_OK;
54 STDMETHODIMP AddItem(BSTR szItemName, BSTR szData)
57 HRESULT hr = E_UNEXPECTED;
59 // We make a copy of the BSTR and stick it in the cache.
60 // The BSTR will be freed in our IMemoryCacheClient::Free
61 // implementation above.
62 BSTR szEntry = SysAllocString(szData);
63 if(szEntry)
65 USES_CONVERSION_EX;
66 // create a time span and for the entry
67 CFileTime tm = CFileTime::GetCurrentTime();
68 CFileTimeSpan span;
69 span.SetTimeSpan(ATL_SHAREDBLOBCACHE_TIMEOUT);
70 tm += span;
71 HCACHEITEM h;
72 hr = basecache::Add(OLE2A_EX(szItemName, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), szEntry, sizeof(BSTR),
73 &tm, _AtlBaseModule.m_hInst, &h, static_cast<IMemoryCacheClient*>(this));
75 if (hr == S_OK)
77 // On successful add, we have to release our
78 // reference on the entry.
79 basecache::ReleaseEntry(h);
82 return hr;
85 STDMETHODIMP GetItem(BSTR szItemName, BSTR *szData)
87 USES_CONVERSION_EX;
88 HRESULT hr = E_UNEXPECTED;
89 HCACHEITEM hEntry = NULL;
91 if (!szItemName || !szData)
92 return hr;
94 hr = basecache::LookupEntry(OLE2A_EX(szItemName, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), &hEntry);
95 if (hr == S_OK)
97 void *pData = NULL;
98 DWORD dwSize = 0;
99 hr = basecache::GetData(hEntry, &pData, &dwSize);
100 if (hr == S_OK)
102 // make a copy of the string
103 *szData = ::SysAllocString((BSTR)pData);
105 basecache::ReleaseEntry(hEntry);
107 return hr;
111 STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
113 HRESULT hr = E_NOINTERFACE;
114 if (InlineIsEqualGUID(__uuidof(IMemoryCacheClient), riid)||
115 InlineIsEqualGUID(__uuidof(IUnknown), riid))
117 *ppv = static_cast<void*>(static_cast<IMemoryCacheClient*>(this));
118 hr = S_OK;
120 else if( InlineIsEqualGUID(__uuidof(ISharedBlobCache), riid))
122 *ppv = static_cast<void*>(static_cast<ISharedBlobCache*>(this));
123 hr = S_OK;
125 return hr;
127 ULONG STDMETHODCALLTYPE AddRef()
129 return 1;
131 ULONG STDMETHODCALLTYPE Release()
133 return 1;
138 // This class implements the SOAP interface for the shared blob cache.
140 soap_handler(
141 name="SharedBlobCache",
142 namespace="http://www.microsoft.com/vc/atlserver/soap/SharedBlobCache",
143 protocol="soap"
145 request_handler(
146 name="SharedBlobCache",
147 sdl="GenSharedBlobCacheWSDL"
150 class CSharedCacheHandler:
151 public ISharedBlobCache
153 public:
154 [soap_method]
155 STDMETHOD(AddItem)(BSTR szItemName, BSTR szData)
157 if (!m_spMemCache)
158 return E_UNEXPECTED;
159 return m_spMemCache->AddItem(szItemName, szData);
162 [soap_method]
163 STDMETHOD(GetItem)(BSTR szItemName, BSTR *szData)
165 if (!m_spMemCache)
166 return E_UNEXPECTED;
167 return m_spMemCache->GetItem(szItemName, szData);
170 HTTP_CODE Initialize(IServiceProvider *pProvider)
172 ATLASSERT(pProvider); // should never be NULL
173 if (!pProvider)
174 return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
176 if (m_spMemCache)
177 return HTTP_SUCCESS; // already initialized
179 pProvider->QueryService(__uuidof(ISharedBlobCache), &m_spMemCache);
180 return m_spMemCache ? HTTP_SUCCESS : HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
183 // override HandleRequest to Initialize our m_spServiceProvider
184 // and to handle authorizing the client.
185 HTTP_CODE HandleRequest(AtlServerRequest *pRequestInfo, IServiceProvider *pProvider)
187 HTTP_CODE dwErr = Initialize(pProvider);
188 if (dwErr != HTTP_SUCCESS)
189 return dwErr;
191 dwErr = CSoapHandler<CSharedCacheHandler>::HandleRequest(pRequestInfo,
192 pProvider);
193 return dwErr;
195 CComPtr<ISharedBlobCache> m_spMemCache;
198 } //ATL
200 #pragma pack(pop)
202 #endif // __ATLSHAREDSVC_H__