|
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 #include <mtp/mmtptype.h> |
|
17 #include <mtp/mtpdatatypeconstants.h> |
|
18 #include <e32base.h> |
|
19 |
|
20 EXPORT_C TBool MMTPType::CommitRequired() const |
|
21 { |
|
22 return EFalse; |
|
23 } |
|
24 |
|
25 EXPORT_C MMTPType* MMTPType::CommitChunkL(TPtr8& /*aChunk*/) |
|
26 { |
|
27 User::Leave(KErrNotSupported); |
|
28 return NULL; |
|
29 } |
|
30 |
|
31 EXPORT_C TInt MMTPType::Validate() const |
|
32 { |
|
33 return KErrNone; |
|
34 } |
|
35 |
|
36 EXPORT_C void MMTPType::CopyL(const MMTPType& aFrom, MMTPType& aTo) |
|
37 { |
|
38 TBool commit(aTo.CommitRequired()); |
|
39 TBool complete(EFalse); |
|
40 TPtr8 dest(NULL, 0); |
|
41 TPtrC8 src; |
|
42 TBool useAoWrite = EFalse; |
|
43 if(EMTPTypeFile == aTo.Type()) //should change later use API to get the write type |
|
44 { |
|
45 useAoWrite = ETrue; |
|
46 } |
|
47 |
|
48 TInt readErr(KErrNone); |
|
49 TInt writeErr(KErrNone); |
|
50 |
|
51 // Obtain the initial read and write chunks. |
|
52 User::LeaveIfError(readErr = aFrom.FirstReadChunk(src)); |
|
53 User::LeaveIfError(writeErr = aTo.FirstWriteChunk(dest)); |
|
54 |
|
55 while (!complete) |
|
56 { |
|
57 TUint dataAvailable(src.Length()); |
|
58 TUint writeCapacity(dest.MaxLength() - dest.Length()); |
|
59 |
|
60 complete = |
|
61 (((readErr == KMTPChunkSequenceCompletion) && !dataAvailable) || |
|
62 (writeErr == KMTPChunkSequenceCompletion)); |
|
63 |
|
64 if (writeCapacity < dataAvailable) |
|
65 { |
|
66 if (writeCapacity) |
|
67 { |
|
68 /* |
|
69 Write chunk capacity is available, but not enough to accomodate |
|
70 the available read chunk data. Fill the available write chunk |
|
71 capacity and adjust the read chunk pointer. |
|
72 */ |
|
73 dest.Append(src.Left(writeCapacity)); |
|
74 src.Set(src.Right(dataAvailable - writeCapacity)); |
|
75 } |
|
76 |
|
77 if (commit) |
|
78 { |
|
79 /* |
|
80 Always commit write chunks which require it, even if the write |
|
81 chunk has no capacity. |
|
82 */ |
|
83 aTo.CommitChunkL(dest); |
|
84 if(useAoWrite) |
|
85 { |
|
86 TInt err = KErrNone; |
|
87 while(CActiveScheduler::RunIfReady(err, CActive::EPriorityIdle)) |
|
88 { |
|
89 //let the write ao run |
|
90 } |
|
91 User::LeaveIfError(err); |
|
92 } |
|
93 } |
|
94 |
|
95 if (writeErr != KMTPChunkSequenceCompletion) |
|
96 { |
|
97 // Obtain the next write chunk |
|
98 User::LeaveIfError(writeErr = aTo.NextWriteChunk(dest)); |
|
99 } |
|
100 } |
|
101 else if (dataAvailable) |
|
102 { |
|
103 /* |
|
104 Write chunk can accomodate the available read chunk data. Consume |
|
105 the available read chunk data, adjust the read chunk pointer, |
|
106 and obtain the next write chunk. |
|
107 */ |
|
108 dest.Append(src); |
|
109 if (commit && (dest.Length() == dest.MaxLength() || KMTPChunkSequenceCompletion == readErr)) //doesn't commit a half chunk unless it is the last chunk |
|
110 { |
|
111 aTo.CommitChunkL(dest); |
|
112 if(useAoWrite) |
|
113 { |
|
114 TInt err = KErrNone; |
|
115 while(CActiveScheduler::RunIfReady(err, CActive::EPriorityIdle)) |
|
116 { |
|
117 //let the write ao run |
|
118 } |
|
119 User::LeaveIfError(err); |
|
120 } |
|
121 } |
|
122 |
|
123 if (readErr != KMTPChunkSequenceCompletion) |
|
124 { |
|
125 User::LeaveIfError(readErr = aFrom.NextReadChunk(src)); |
|
126 } |
|
127 else |
|
128 { |
|
129 src.Set(KNullDesC8); |
|
130 } |
|
131 |
|
132 /* |
|
133 If the write chunk is full, and more write chunks are available, |
|
134 obtain the next write chunk. |
|
135 */ |
|
136 if ((dest.Length() == dest.MaxLength()) && (writeErr != KMTPChunkSequenceCompletion)) |
|
137 { |
|
138 User::LeaveIfError(writeErr = aTo.NextWriteChunk(dest)); |
|
139 } |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 EXPORT_C TAny* MMTPType::GetExtendedInterface(TUid /*aInterfaceUid*/) |
|
145 { |
|
146 return NULL; |
|
147 } |
|
148 |
|
149 EXPORT_C TInt MMTPType::FirstWriteChunk(TPtr8& aChunk, TUint /*aDataLength*/ ) |
|
150 { |
|
151 return FirstWriteChunk(aChunk); |
|
152 } |
|
153 |
|
154 EXPORT_C TInt MMTPType::NextWriteChunk(TPtr8& aChunk, TUint /*aDataLength*/ ) |
|
155 { |
|
156 return NextWriteChunk(aChunk); |
|
157 } |
|
158 |
|
159 EXPORT_C TBool MMTPType::ReserveTransportHeader(TUint /* aHeaderLength */, TPtr8& /* aHeader */) |
|
160 { |
|
161 return EFalse; |
|
162 } |
|
163 |