/[tivodecode]/tivocom/trunk/CChunkCollection.cpp
ViewVC logotype

Contents of /tivocom/trunk/CChunkCollection.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (show annotations) (download)
Wed Aug 29 06:53:05 2007 UTC (14 years, 4 months ago) by jeremyd2019
File size: 1933 byte(s)
squelch warnings

1 // CChunkCollection.cpp : Implementation of CChunkCollection
2
3 #include "stdafx.h"
4 #include "CChunkCollection.h"
5
6 // CChunkCollection
7
8 namespace
9 {
10 class CopyTivoChunk
11 {
12 public:
13 static HRESULT copy(VARIANT * p1, const CComPtr<ITivoChunk> * p2)
14 {
15 ATLENSURE(p1 != NULL && p2 != NULL);
16 CComVariant var (*p2);
17 return var.Detach(p1);
18 }
19 static void init(VARIANT* p) {VariantInit(p);}
20 static void destroy(VARIANT* p) {VariantClear(p);}
21 };
22
23 } // end anon namespace
24
25
26 STDMETHODIMP CChunkCollection::Init(const std::string & mak, USHORT nChunks, off_t chunks_start, CTivoFile* tivoFile)
27 {
28 try
29 {
30 m_nChunks = nChunks;
31 m_chunkstart = chunks_start;
32 m_tivofile = tivoFile;
33 _com_util::CheckError(tivoFile->get_fh(&m_fh));
34 m_chunks.resize(m_nChunks);
35 fseek(m_fh, m_chunkstart, SEEK_SET);
36 for (USHORT i = 0; i < m_nChunks; ++i)
37 {
38 CTivoChunk *chunk = new CComObject<CTivoChunk> ();
39 m_chunks[i] = chunk;
40 _com_util::CheckError(chunk->Init (mak, m_chunks[0], m_fh));
41 }
42 }
43 catch (const _com_error & ex)
44 {
45 return ex.Error();
46 }
47 return S_OK;
48 }
49
50
51
52 STDMETHODIMP CChunkCollection::get_Count(long* pVal)
53 {
54 if (!pVal)
55 return E_POINTER;
56
57 *pVal = static_cast<long>(m_chunks.size());
58 return S_OK;
59 }
60
61 STDMETHODIMP CChunkCollection::get_Item(long Index, ITivoChunk** pVal)
62 {
63 if (Index < 1 || static_cast<size_t>(Index) > m_chunks.size())
64 return E_INVALIDARG;
65
66 return m_chunks[Index-1].CopyTo(pVal);
67 }
68
69 STDMETHODIMP CChunkCollection::get__NewEnum(IUnknown** pVal)
70 {
71 typedef CComEnumOnSTL<IEnumVARIANT, &IID_IEnumVARIANT, VARIANT, CopyTivoChunk, std::vector<CComPtr<ITivoChunk> > > EnumType;
72 try
73 {
74 CComObject<EnumType>* foo;
75 _com_util::CheckError(CComObject<EnumType>::CreateInstance(&foo));
76 CComPtr<IUnknown> retval = foo;
77 _com_util::CheckError(foo->Init (GetUnknown(), m_chunks));
78 _com_util::CheckError(retval.CopyTo(pVal));
79 }
80 catch (const _com_error & ex)
81 {
82 return ex.Error();
83 }
84
85 return S_OK;
86 }

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13