|
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 #ifndef HSREMOTECONTROLTOOLS_H |
|
17 #define HSREMOTECONTROLTOOLS_H |
|
18 |
|
19 #include <e32base.h> |
|
20 |
|
21 #include "hsremoterequest.h" |
|
22 |
|
23 /** Request package length */ |
|
24 const TInt KHsRemoteControlPackageLength = 128; |
|
25 |
|
26 /** Request package header length */ |
|
27 const TInt KHsRemoteControlPackageTypeMaxLength = 2; |
|
28 |
|
29 _LIT8(KHsRemoteControllerPackageDelim, ":"); |
|
30 |
|
31 /** Request package data */ |
|
32 typedef TBuf8 <KHsRemoteControlPackageLength> THsControlCommandData; |
|
33 |
|
34 /** |
|
35 * @brief Represents remote control request |
|
36 */ |
|
37 class THsRemoteControlCommand |
|
38 { |
|
39 public: |
|
40 /** |
|
41 * Constructor |
|
42 * |
|
43 * @param aData data |
|
44 * @param aCommandType type of command |
|
45 */ |
|
46 THsRemoteControlCommand( THsControlCommandData& aData, |
|
47 THsRemoteControlCommandType aCommandType ); |
|
48 |
|
49 public: |
|
50 |
|
51 /** |
|
52 * Getter for type of command |
|
53 * |
|
54 * @param aCmdType type |
|
55 */ |
|
56 void GetType( THsRemoteControlCommandType &aCmdType ); |
|
57 |
|
58 /** |
|
59 * Getter for command's data |
|
60 * |
|
61 * @param aCmdData data |
|
62 * |
|
63 */ |
|
64 void GetData( TDes8 &aCmdData ); |
|
65 |
|
66 /** |
|
67 * Clones THsRemoteControlCommand object |
|
68 * |
|
69 * @param aCmdFrom source |
|
70 * @param aCmdTo destination |
|
71 */ |
|
72 static void Copy( const THsRemoteControlCommand& aCmdFrom, |
|
73 THsRemoteControlCommand& aCmdTo ); |
|
74 private: |
|
75 |
|
76 /** Data */ |
|
77 THsControlCommandData &iData; |
|
78 |
|
79 /** Type */ |
|
80 THsRemoteControlCommandType iType; |
|
81 }; |
|
82 |
|
83 /** |
|
84 * @brief Parser for remote control packages |
|
85 */ |
|
86 class CHsRemoteControlParser : public CBase |
|
87 { |
|
88 public: |
|
89 /** |
|
90 * Two-phased constructor. |
|
91 * |
|
92 * @return class instance |
|
93 */ |
|
94 static CHsRemoteControlParser* NewL(); |
|
95 |
|
96 /** |
|
97 * Two-phased constructor. |
|
98 * |
|
99 * @return class instance |
|
100 */ |
|
101 static CHsRemoteControlParser* NewLC(); |
|
102 |
|
103 /** |
|
104 * Destructor |
|
105 */ |
|
106 ~CHsRemoteControlParser(); |
|
107 |
|
108 public: |
|
109 /** |
|
110 * Parses and transforms data into THsRemoteControlCommand object |
|
111 * |
|
112 * @param aText remote request package |
|
113 * @param aCommand created command |
|
114 */ |
|
115 void ParseL( const TDesC8 &aText, THsRemoteControlCommand &aCommand ); |
|
116 |
|
117 private: |
|
118 /** |
|
119 * Constructor for performing 1st stage construction |
|
120 */ |
|
121 CHsRemoteControlParser(); |
|
122 |
|
123 /** |
|
124 * Constructor for performing 2nd stage construction |
|
125 */ |
|
126 void ConstructL(); |
|
127 |
|
128 private: |
|
129 |
|
130 /** |
|
131 * Checks if package is proper |
|
132 * |
|
133 * @aData remote request package |
|
134 * @return ETrue if OK, otherwise EFalse |
|
135 */ |
|
136 TBool IsPackageValid( const TDesC8 &aData ); |
|
137 |
|
138 /** |
|
139 * Retrieves header part and data part of remote request package |
|
140 * |
|
141 * @param aData remote request package |
|
142 * @param aTypePart header of the package |
|
143 * @param aDataPart package's data |
|
144 * @return error code value |
|
145 */ |
|
146 TInt SplitPackage( const TDesC8 &aData, TDes8 &aTypePart, TDes8 &aDataPart ); |
|
147 |
|
148 /** |
|
149 * Transforms header of the package into THsRemoteControlCommandType |
|
150 * |
|
151 * @param aTypePart header of the package |
|
152 * @param aCommandType header tranformed into THsRemoteControlCommandType object |
|
153 * @return error code value |
|
154 */ |
|
155 TInt RecognizeType( const TDesC8 &aTypePart, |
|
156 THsRemoteControlCommandType &aCommandType ); |
|
157 |
|
158 }; |
|
159 |
|
160 #endif // HSREMOTECONTROLTOOLS_H |