|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <remconcoreapi.h> |
|
22 #include "remconserialbeareruid.h" |
|
23 #include "coreserialconverter.h" |
|
24 |
|
25 _LIT8(KCmdText, "Cmd"); |
|
26 _LIT8(KRspText, "Rsp"); |
|
27 |
|
28 /** |
|
29 Factory function. |
|
30 @return Ownership of a new CRemConSerialBearer. |
|
31 */ |
|
32 CCoreSerialConverter* CCoreSerialConverter::NewL() |
|
33 { |
|
34 CCoreSerialConverter* self = new(ELeave) CCoreSerialConverter; |
|
35 return self; |
|
36 } |
|
37 |
|
38 /** |
|
39 Destructor. |
|
40 */ |
|
41 CCoreSerialConverter::~CCoreSerialConverter() |
|
42 { |
|
43 } |
|
44 |
|
45 /** |
|
46 Constructor. |
|
47 */ |
|
48 CCoreSerialConverter::CCoreSerialConverter() |
|
49 { |
|
50 } |
|
51 |
|
52 TAny* CCoreSerialConverter::GetInterface(TUid aUid) |
|
53 { |
|
54 TAny* ret = NULL; |
|
55 if ( aUid == TUid::Uid(KRemConConverterInterface1) ) |
|
56 { |
|
57 ret = reinterpret_cast<TAny*>( |
|
58 static_cast<MRemConConverterInterface*>(this) |
|
59 ); |
|
60 } |
|
61 |
|
62 return ret; |
|
63 } |
|
64 |
|
65 TBool CCoreSerialConverter::SupportedUids(const TUid& aInterfaceUid, const TUid& aBearerUid) const |
|
66 { |
|
67 return (aInterfaceUid == TUid::Uid(KRemConCoreApiUid) && |
|
68 aBearerUid == TUid::Uid(KRemConSerialBearerUid)); |
|
69 } |
|
70 |
|
71 TBool CCoreSerialConverter::SupportedInterface(const TDesC8& /*aInterfaceData*/, const TUid& aBearerUid) const |
|
72 { |
|
73 // aInterfaceData is not used by the serial bearer. |
|
74 return aBearerUid == TUid::Uid(KRemConSerialBearerUid); |
|
75 } |
|
76 |
|
77 /** |
|
78 Convert data from the API's form (as we're given it by RemCon) the |
|
79 bearer-specific form. |
|
80 */ |
|
81 TInt CCoreSerialConverter::InterfaceToBearer(TUid aInterfaceUid, |
|
82 TUint aOperationId, |
|
83 const TDesC8& aData, |
|
84 TRemConMessageType aMsgType, |
|
85 TDes8& aBearerData) const |
|
86 { |
|
87 TInt ret = KErrCorrupt; |
|
88 |
|
89 if ( aData.Length() <= 10 ) |
|
90 { |
|
91 if ( aMsgType == ERemConCommand ) |
|
92 { |
|
93 aBearerData.Format(_L8("0x%08x 0x%02x %S %S"), aInterfaceUid, aOperationId, &KCmdText(), &aData); |
|
94 // Pad it up in case aData was less than 4 characters. |
|
95 while ( aBearerData.Length() < KRemConSerialBearerMessageLength ) |
|
96 { |
|
97 aBearerData.Append(_L8(" ")); |
|
98 } |
|
99 ret = KErrNone; |
|
100 } |
|
101 else if ( aMsgType == ERemConResponse ) |
|
102 { |
|
103 aBearerData.Format(_L8("0x%08x 0x%02x %S %S"), aInterfaceUid, aOperationId, &KRspText(), &aData); |
|
104 // Pad it up in case aData was less than 4 characters. |
|
105 while ( aBearerData.Length() < KRemConSerialBearerMessageLength ) |
|
106 { |
|
107 aBearerData.Append(_L8(" ")); |
|
108 } |
|
109 ret = KErrNone; |
|
110 } |
|
111 } |
|
112 |
|
113 return ret; |
|
114 } |
|
115 |
|
116 |
|
117 TInt CCoreSerialConverter::BearerToInterface(const TDesC8& aBearerData, |
|
118 TUid& aInterfaceUid, |
|
119 TUint& aOperationId, |
|
120 TRemConMessageType& aMsgType, |
|
121 TDes8& aData) const |
|
122 { |
|
123 TInt ret = KErrCorrupt; |
|
124 |
|
125 // We read KRemConSerialBearerMessageLength bytes at a time, so we should |
|
126 // get precisely one message. |
|
127 if ( aBearerData.Length() == KRemConSerialBearerMessageLength ) |
|
128 { |
|
129 TPtrC8 ptr; |
|
130 ptr.Set(aBearerData); |
|
131 |
|
132 TPtrC8 interfaceUid; |
|
133 interfaceUid.Set(ptr.Mid(2, 8)); |
|
134 TLex8 interfaceLex(interfaceUid); |
|
135 TUint uid = 0; |
|
136 ret = interfaceLex.Val(uid, EHex); |
|
137 if ( ret == KErrNone ) |
|
138 { |
|
139 aInterfaceUid = TUid::Uid(uid); |
|
140 |
|
141 TPtrC8 operationId; |
|
142 operationId.Set(ptr.Mid(13, 2)); |
|
143 TLex8 operationLex(operationId); |
|
144 TUint id = 0; |
|
145 ret = operationLex.Val(id, EHex); |
|
146 if ( ret == KErrNone ) |
|
147 { |
|
148 aOperationId = id; |
|
149 |
|
150 TPtrC8 data; |
|
151 data.Set(ptr.Mid(16, 3)); |
|
152 if ( data == KCmdText() ) |
|
153 { |
|
154 aMsgType = ERemConCommand; |
|
155 } |
|
156 else if ( data == KRspText() ) |
|
157 { |
|
158 aMsgType = ERemConResponse; |
|
159 } |
|
160 else |
|
161 { |
|
162 ret = KErrCorrupt; |
|
163 } |
|
164 |
|
165 if ( ret == KErrNone ) |
|
166 { |
|
167 TPtrC8 data; |
|
168 data.Set(ptr.Mid(20, 10)); |
|
169 aData.Copy(data); |
|
170 } |
|
171 } |
|
172 } |
|
173 } |
|
174 |
|
175 return ret; |
|
176 } |