Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
/* Copyright (C) 2010-2011 Circuits At Home, LTD. All rights reserved.
2
 
3
This software may be distributed and modified under the terms of the GNU
4
General Public License version 2 (GPL2) as published by the Free Software
5
Foundation and appearing in the file GPL2.TXT included in the packaging of
6
this file. Please note that GPL2 Section 2[b] requires that all works based
7
on this software must also be made publicly available under the terms of
8
the GPL2 ("Copyleft").
9
 
10
Contact information
11
-------------------
12
 
13
Circuits At Home, LTD
14
Web      :  http://www.circuitsathome.com
15
e-mail   :  support@circuitsathome.com
16
*/
17
#include "ptpcallback.h"
18
#include "ptpdebug.h"
19
 
20
bool MultiByteValueParser::Parse(uint8_t **pp, uint16_t *pcntdn)
21
{
22
        if (!pBuf)
23
        {
24
                Notify(PSTR("Buffer pointer is NULL!\r\n"));
25
                return false;
26
        }
27
        for (; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++)
28
                pBuf[valueSize-countDown] = (**pp);
29
 
30
        if (countDown)
31
                return false;
32
 
33
        countDown = valueSize;
34
        return true;
35
}
36
 
37
bool PTPListParser::Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me)
38
{
39
        switch (nStage)
40
        {
41
        case 0:
42
                pBuf->valueSize = lenSize;
43
                theParser.Initialize(pBuf);
44
                nStage = 1;
45
 
46
        case 1:
47
                if (!theParser.Parse(pp, pcntdn))
48
                        return false;
49
 
50
                arLen = 0;
51
                arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue));
52
                arLenCntdn = arLen;
53
                nStage = 2;
54
 
55
        case 2:
56
                pBuf->valueSize = valSize;
57
                theParser.Initialize(pBuf);
58
                nStage = 3;
59
 
60
        case 3:
61
                for (; arLenCntdn; arLenCntdn--)
62
                {
63
                        if (!theParser.Parse(pp, pcntdn))
64
                                return false;
65
 
66
                        if (pf)
67
                                pf(pBuf, (arLen - arLenCntdn), me);
68
                }
69
 
70
                nStage = 0;
71
        }
72
        return true;
73
}