|
1 // Copyright (c) 2006-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 @file |
|
17 @internalComponent |
|
18 */ |
|
19 #include <e32err.h> |
|
20 #include <mtp/mtpprotocolconstants.h> |
|
21 |
|
22 #include "mtpservicecommon.h" |
|
23 #include "rmtpframework.h" |
|
24 #include "cmtpdatacodegenerator.h" |
|
25 #include "cmtpservicemgr.h" |
|
26 |
|
27 |
|
28 |
|
29 // Class constants. |
|
30 __FLOG_STMT(_LIT8(KComponent,"DataCodeGenerator");) |
|
31 |
|
32 const TUint16 KUndenfinedStartCode = EMTPCodeUndefined1Start + 1; |
|
33 const TUint16 KUndenfinedEndCode = EMTPCodeUndefined1End; |
|
34 |
|
35 |
|
36 CMTPDataCodeGenerator* CMTPDataCodeGenerator::NewL() |
|
37 { |
|
38 CMTPDataCodeGenerator* self = new (ELeave) CMTPDataCodeGenerator(); |
|
39 CleanupStack::PushL ( self ); |
|
40 self->ConstructL (); |
|
41 CleanupStack::Pop ( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CMTPDataCodeGenerator::~CMTPDataCodeGenerator() |
|
46 { |
|
47 __FLOG(_L8("CMTPDataCodeGenerator::~CMTPDataCodeGenerator - Entry")); |
|
48 |
|
49 iSingletons.Close(); |
|
50 |
|
51 __FLOG(_L8("CMTPDataCodeGenerator::~CMTPDataCodeGenerator - Exit")); |
|
52 |
|
53 __FLOG_CLOSE; |
|
54 } |
|
55 |
|
56 void CMTPDataCodeGenerator::ConstructL() |
|
57 { |
|
58 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
59 __FLOG(_L8("CMTPDataCodeGenerator::ConstructL - Entry")); |
|
60 |
|
61 iSingletons.OpenL (); |
|
62 |
|
63 __FLOG(_L8("CMTPDataCodeGenerator::ConstructL - Exit")); |
|
64 } |
|
65 |
|
66 CMTPDataCodeGenerator::CMTPDataCodeGenerator() : |
|
67 iUndefinedNextCode(KUndenfinedStartCode ), |
|
68 iVendorExtFormatCode(EMTPFormatCodeVendorExtDynamicStart) |
|
69 { |
|
70 |
|
71 } |
|
72 |
|
73 TInt CMTPDataCodeGenerator::IncServiceIDResource( const TUint aServiceType, TUint& aServiceID ) |
|
74 { |
|
75 __FLOG(_L8("CMTPDataCodeGenerator::IncServiceIDResource - Entry")); |
|
76 if ( iUndefinedNextCode >= KUndenfinedEndCode ) |
|
77 return KErrOverflow; |
|
78 |
|
79 switch ( aServiceType ) |
|
80 { |
|
81 case EMTPServiceTypeNormal: |
|
82 { |
|
83 aServiceID = ( ( ++iUndefinedNextCode ) | KNormalServiceTypeMask ); |
|
84 } |
|
85 break; |
|
86 |
|
87 case EMTPServiceTypeAbstract: |
|
88 { |
|
89 aServiceID = ( (++iUndefinedNextCode) | KAbstrackServiceTypeMask ); |
|
90 } |
|
91 break; |
|
92 default: |
|
93 { |
|
94 __FLOG(_L8("CMTPDataCodeGenerator::IncServiceIDResource - Service Type not supported")); |
|
95 } |
|
96 } |
|
97 __FLOG(_L8("CMTPDataCodeGenerator::IncServiceIDResource - Exit")); |
|
98 return KErrNone; |
|
99 } |
|
100 |
|
101 void CMTPDataCodeGenerator::DecServiceIDResource() |
|
102 { |
|
103 __FLOG(_L8("CMTPDataCodeGenerator::DecServiceIDResource - Entry")); |
|
104 iUndefinedNextCode--; |
|
105 __FLOG(_L8("CMTPDataCodeGenerator::DecServiceIDResource - Exit")); |
|
106 } |
|
107 |
|
108 TBool CMTPDataCodeGenerator::IsValidServiceType( const TUint aServiceType ) const |
|
109 { |
|
110 return ( (EMTPServiceTypeNormal == aServiceType) || (EMTPServiceTypeAbstract == aServiceType) ); |
|
111 } |
|
112 |
|
113 TInt CMTPDataCodeGenerator::AllocateServiceID(const TMTPTypeGuid& aPGUID, const TUint aServiceType, TUint& aServiceID ) |
|
114 { |
|
115 __FLOG(_L8("CMTPDataCodeGenerator::AllocateServiceID - Entry")); |
|
116 |
|
117 if( !IsValidServiceType(aServiceType) ) |
|
118 return KErrArgument; |
|
119 |
|
120 TInt err(KErrNone); |
|
121 TUint retID (KInvliadServiceID); |
|
122 if( iSingletons.ServiceMgr().IsSupportedService(aPGUID) ) |
|
123 { |
|
124 if( iSingletons.ServiceMgr().ServiceTypeOfSupportedService(aPGUID) != aServiceType ) |
|
125 return KErrArgument; |
|
126 |
|
127 err = iSingletons.ServiceMgr().GetServiceId(aPGUID , retID); |
|
128 if( KErrNone != err ) |
|
129 { |
|
130 if((err = IncServiceIDResource( aServiceType, retID )) != KErrNone) |
|
131 return err; |
|
132 |
|
133 err = iSingletons.ServiceMgr().EnableService( aPGUID, retID ); |
|
134 if( KErrNone != err ) |
|
135 { |
|
136 DecServiceIDResource(); |
|
137 return err; |
|
138 } |
|
139 } |
|
140 |
|
141 } |
|
142 else |
|
143 { |
|
144 if((err = IncServiceIDResource( aServiceType, retID )) != KErrNone) |
|
145 return err; |
|
146 } |
|
147 |
|
148 aServiceID = retID; |
|
149 iSingletons.ServiceMgr().InsertServiceId( retID ); |
|
150 |
|
151 __FLOG(_L8("CMTPDataCodeGenerator::AllocateServiceID - Exit")); |
|
152 return KErrNone; |
|
153 } |
|
154 |
|
155 TInt CMTPDataCodeGenerator::AllocateServicePropertyCode( const TMTPTypeGuid& aServicePGUID, const TMTPTypeGuid& aPKNamespace, const TUint aPKID, TUint16& aServicePropertyCode ) |
|
156 { |
|
157 __FLOG(_L8("CMTPDataCodeGenerator::AllocateServicePropertyCode - Entry")); |
|
158 |
|
159 TUint retID = KInvliadU16DataCode; |
|
160 if( iSingletons.ServiceMgr().IsSupportedService(aServicePGUID) ) |
|
161 { |
|
162 TInt err = iSingletons.ServiceMgr().GetServicePropertyCode( aServicePGUID, aPKNamespace, aPKID, retID ); |
|
163 if( KErrNone != err ) |
|
164 return err; |
|
165 |
|
166 if(retID == KInvliadU16DataCode) |
|
167 { |
|
168 if ( iUndefinedNextCode >= KUndenfinedEndCode ) |
|
169 return KErrOverflow; |
|
170 |
|
171 retID = ++iUndefinedNextCode; |
|
172 iSingletons.ServiceMgr().SetServicePropertyCode( aServicePGUID, aPKNamespace, aPKID, retID); |
|
173 } |
|
174 } |
|
175 else |
|
176 { |
|
177 if ( iUndefinedNextCode >= KUndenfinedEndCode ) |
|
178 return KErrOverflow; |
|
179 |
|
180 retID = ++iUndefinedNextCode; |
|
181 } |
|
182 |
|
183 aServicePropertyCode = retID; |
|
184 |
|
185 __FLOG(_L8("CMTPDataCodeGenerator::AllocateServicePropertyCode - Exit")); |
|
186 return KErrNone; |
|
187 } |
|
188 |
|
189 TInt CMTPDataCodeGenerator::AllocateServiceFormatCode( const TMTPTypeGuid& aServicePGUID, const TMTPTypeGuid& aGUID, TUint16& aServiceFormatCode ) |
|
190 { |
|
191 __FLOG(_L8("CMTPServiceConfig::AllocateServiceFormatCode - Entry")); |
|
192 |
|
193 TUint retID = KInvliadU16DataCode; |
|
194 if( iSingletons.ServiceMgr().IsSupportedService(aServicePGUID) ) |
|
195 { |
|
196 TInt err = iSingletons.ServiceMgr().GetServiceFormatCode( aServicePGUID, aGUID, retID ); |
|
197 if( KErrNone != err ) |
|
198 return err; |
|
199 |
|
200 if(retID == KInvliadU16DataCode) |
|
201 { |
|
202 if ( iVendorExtFormatCode > EMTPFormatCodeVendorExtDynamicEnd ) |
|
203 return KErrOverflow; |
|
204 |
|
205 retID = ++iVendorExtFormatCode; |
|
206 iSingletons.ServiceMgr().SetServiceFormatCode( aServicePGUID, aGUID, retID); |
|
207 } |
|
208 } |
|
209 else |
|
210 { |
|
211 if ( iVendorExtFormatCode > EMTPFormatCodeVendorExtDynamicEnd ) |
|
212 return KErrOverflow; |
|
213 |
|
214 retID = ++iVendorExtFormatCode; |
|
215 } |
|
216 |
|
217 aServiceFormatCode = retID; |
|
218 |
|
219 __FLOG(_L8("CMTPServiceConfig::AllocateServiceFormatCode - Exit")); |
|
220 return KErrNone; |
|
221 } |
|
222 |
|
223 TInt CMTPDataCodeGenerator::AllocateServiceMethodFormatCode( const TMTPTypeGuid& aServicePGUID, const TMTPTypeGuid& aGUID, TUint16& aMethodFormatCode ) |
|
224 { |
|
225 __FLOG(_L8("CMTPDataCodeGenerator::AllocateServiceMethodFormatCode - Entry")); |
|
226 |
|
227 TUint retID = KInvliadU16DataCode; |
|
228 if( iSingletons.ServiceMgr().IsSupportedService(aServicePGUID) ) |
|
229 { |
|
230 TInt err = iSingletons.ServiceMgr().GetServiceMethodCode( aServicePGUID, aGUID, retID ); |
|
231 if( KErrNone != err ) |
|
232 return err; |
|
233 |
|
234 if(retID == KInvliadU16DataCode) |
|
235 { |
|
236 if ( iUndefinedNextCode > KUndenfinedEndCode ) |
|
237 return KErrOverflow; |
|
238 |
|
239 retID = ++iUndefinedNextCode; |
|
240 iSingletons.ServiceMgr().SetServiceMethodCode( aServicePGUID, aGUID, retID); |
|
241 } |
|
242 } |
|
243 else |
|
244 { |
|
245 if ( iUndefinedNextCode > KUndenfinedEndCode ) |
|
246 return KErrOverflow; |
|
247 |
|
248 retID = ++iUndefinedNextCode; |
|
249 } |
|
250 |
|
251 aMethodFormatCode = retID; |
|
252 |
|
253 __FLOG(_L8("CMTPDataCodeGenerator::AllocateServiceMethodFormatCode - Exit")); |
|
254 return KErrNone; |
|
255 } |
|
256 |
|
257 |
|
258 |