60
|
1 |
/*
|
|
2 |
* Component Name: Headset Simulator
|
|
3 |
* Author: Comarch S.A.
|
|
4 |
* Version: 1.0
|
|
5 |
* Copyright (c) 2010 Comarch S.A.
|
|
6 |
*
|
|
7 |
* This Software is submitted by Comarch S.A. to Symbian Foundation Limited on
|
|
8 |
* the basis of the Member Contribution Agreement entered between Comarch S.A.
|
|
9 |
* and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be
|
|
10 |
* used only in accordance with the terms and conditions of the Agreement.
|
|
11 |
* Any other usage, duplication or redistribution of this Software is not
|
|
12 |
* allowed without written permission of Comarch S.A.
|
|
13 |
*
|
|
14 |
*/
|
|
15 |
|
|
16 |
#include "hsremotecontroltools.h"
|
|
17 |
#include "debug.h"
|
|
18 |
|
|
19 |
CHsRemoteControlParser* CHsRemoteControlParser::NewL()
|
|
20 |
{
|
|
21 |
CHsRemoteControlParser *self = CHsRemoteControlParser::NewLC();
|
|
22 |
CleanupStack::Pop( self );
|
|
23 |
return self;
|
|
24 |
}
|
|
25 |
|
|
26 |
CHsRemoteControlParser* CHsRemoteControlParser::NewLC()
|
|
27 |
{
|
|
28 |
CHsRemoteControlParser *self = new ( ELeave ) CHsRemoteControlParser;
|
|
29 |
CleanupStack::PushL( self );
|
|
30 |
self->ConstructL();
|
|
31 |
return self;
|
|
32 |
}
|
|
33 |
|
|
34 |
CHsRemoteControlParser::~CHsRemoteControlParser()
|
|
35 |
{
|
|
36 |
|
|
37 |
}
|
|
38 |
|
|
39 |
void CHsRemoteControlParser::ConstructL()
|
|
40 |
{
|
|
41 |
|
|
42 |
}
|
|
43 |
|
|
44 |
CHsRemoteControlParser::CHsRemoteControlParser()
|
|
45 |
{
|
|
46 |
|
|
47 |
}
|
|
48 |
|
|
49 |
void CHsRemoteControlParser::ParseL( const TDesC8 &aText,
|
|
50 |
THsRemoteControlCommand &aCommand )
|
|
51 |
{
|
|
52 |
TRACE_FUNC_ENTRY
|
|
53 |
if ( !IsPackageValid( aText ) )
|
|
54 |
{
|
|
55 |
User::Leave( KErrArgument );
|
|
56 |
}
|
|
57 |
|
|
58 |
TBuf8 <KHsRemoteControlPackageTypeMaxLength> typeBuf;
|
|
59 |
TBuf8 <KHsRemoteControlPackageLength - KHsRemoteControlPackageTypeMaxLength>
|
|
60 |
dataBuf;
|
|
61 |
|
|
62 |
User::LeaveIfError( SplitPackage( aText, typeBuf, dataBuf ) );
|
|
63 |
|
|
64 |
THsRemoteControlCommandType cmdType = EHsLast;
|
|
65 |
User::LeaveIfError( RecognizeType( typeBuf, cmdType ) );
|
|
66 |
|
|
67 |
THsControlCommandData cmdData( dataBuf );
|
|
68 |
|
|
69 |
THsRemoteControlCommand tmpCommand( cmdData, cmdType );
|
|
70 |
|
|
71 |
THsRemoteControlCommand::Copy( tmpCommand, aCommand );
|
|
72 |
TRACE_FUNC_EXIT
|
|
73 |
}
|
|
74 |
|
|
75 |
TBool CHsRemoteControlParser::IsPackageValid( const TDesC8 &aData )
|
|
76 |
{
|
|
77 |
return ( aData.Size() <= KHsRemoteControlPackageLength ) && ( aData.Find(
|
|
78 |
KHsRemoteControllerPackageDelim ) != KErrNotFound );
|
|
79 |
}
|
|
80 |
|
|
81 |
TInt CHsRemoteControlParser::SplitPackage( const TDesC8 &aData,
|
|
82 |
TDes8 &aTypePart, TDes8 &aDataPart )
|
|
83 |
{
|
|
84 |
TRACE_FUNC_ENTRY
|
|
85 |
TInt err = KErrNone;
|
|
86 |
|
|
87 |
TInt delimPos = aData.Find( KHsRemoteControllerPackageDelim );
|
|
88 |
if ( delimPos != KErrNotFound )
|
|
89 |
{
|
|
90 |
aTypePart.Copy( aData.Left( delimPos ) );
|
|
91 |
aDataPart.Copy( aData.Right( aData.Length() - delimPos - 1 ) );
|
|
92 |
}
|
|
93 |
else
|
|
94 |
{
|
|
95 |
err = KErrNotFound;
|
|
96 |
}
|
|
97 |
|
|
98 |
TRACE_FUNC_EXIT
|
|
99 |
return err;
|
|
100 |
}
|
|
101 |
|
|
102 |
TInt CHsRemoteControlParser::RecognizeType( const TDesC8 &aTypePart,
|
|
103 |
THsRemoteControlCommandType& aCommandType )
|
|
104 |
{
|
|
105 |
TRACE_FUNC_ENTRY
|
|
106 |
TLex8 lex( aTypePart );
|
|
107 |
TInt val;
|
|
108 |
TInt err = lex.Val( val );
|
|
109 |
|
|
110 |
aCommandType = (THsRemoteControlCommandType) val;
|
|
111 |
TRACE_FUNC_EXIT
|
|
112 |
return err;
|
|
113 |
}
|
|
114 |
|