|
1 // Copyright (c) 2003-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 <f32file.h> |
|
22 #include "obexsyncfilewriter.h" |
|
23 #include "logger.h" |
|
24 |
|
25 #ifdef __FLOG_ACTIVE |
|
26 _LIT8(KLogComponent, "OBEX"); |
|
27 #endif |
|
28 |
|
29 // |
|
30 // Panic category for CObexSyncFileWriter |
|
31 // |
|
32 _LIT(KObexSyncFileWriterPanic, "Obex-SFW"); |
|
33 |
|
34 /** |
|
35 Panic codes for CObexSyncFileWriter |
|
36 |
|
37 @internalComponent |
|
38 @released |
|
39 */ |
|
40 enum TSyncObexFileWriterPanic |
|
41 { |
|
42 /** Null buffer pointer */ |
|
43 ENullBufferPointer |
|
44 }; |
|
45 |
|
46 // |
|
47 // Implementation of CObexSyncFileWriter |
|
48 // |
|
49 |
|
50 /** |
|
51 Factory function |
|
52 |
|
53 Note that we return a pointer to the interface class, so |
|
54 that this class can only be used through this interface. |
|
55 This class in an implementation of a strategy as part of |
|
56 a Strategy pattern. CObexAsyncFileWriter provides an |
|
57 alternative strategy implementation, with CObexBufObject |
|
58 as the context for these strategies. |
|
59 |
|
60 @see MObexFileWriter |
|
61 @see CObexAsyncFileWriter |
|
62 @see CObexBufObject |
|
63 |
|
64 @internalComponent |
|
65 @released |
|
66 |
|
67 @param aFile The file we're writing to |
|
68 @return An MObexFileWriter for writing to file |
|
69 */ |
|
70 MObexFileWriter* CObexSyncFileWriter::NewL(RFile& aFile) |
|
71 { |
|
72 CObexSyncFileWriter* self = new(ELeave) CObexSyncFileWriter(aFile); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop(self); |
|
76 return self; |
|
77 } |
|
78 |
|
79 /** |
|
80 Constructor |
|
81 |
|
82 @internalComponent |
|
83 @released |
|
84 |
|
85 @param aFile The file to write to |
|
86 */ |
|
87 CObexSyncFileWriter::CObexSyncFileWriter(RFile& aFile) |
|
88 : iFile(aFile) |
|
89 { |
|
90 } |
|
91 |
|
92 /** |
|
93 2nd phase constructor |
|
94 |
|
95 @internalComponent |
|
96 @released |
|
97 */ |
|
98 void CObexSyncFileWriter::ConstructL() |
|
99 { |
|
100 } |
|
101 |
|
102 /** |
|
103 Normal write to file |
|
104 |
|
105 @internalComponent |
|
106 @released |
|
107 |
|
108 @param aPos The file position |
|
109 @param aBuf The buffer we're to write. We use this buffer by copying the pointer |
|
110 and return the buffer we previously wrote to the caller by updating |
|
111 the pointer. If an error occurs, the buffers are not swapped and |
|
112 the pointer is not updated. Note that this class never owns any |
|
113 buffers and that passing a buffer to this function does not imply a |
|
114 transfer of ownership. |
|
115 @return Symbian OS error code |
|
116 */ |
|
117 TInt CObexSyncFileWriter::Write(TInt aPos, CBufBase*& aBuf) |
|
118 { |
|
119 __ASSERT_ALWAYS(aBuf, PANIC(KObexSyncFileWriterPanic, ENullBufferPointer)); |
|
120 |
|
121 // Write the next block |
|
122 return iFile.Write(aPos, aBuf->Ptr(0)); |
|
123 } |
|
124 |
|
125 /** |
|
126 Final, synchronous write to file |
|
127 |
|
128 @internalComponent |
|
129 @released |
|
130 |
|
131 @param aPos The file position |
|
132 @param aBuf The buffer we're to write. We use this buffer by copying the pointer |
|
133 and return the buffer we previously wrote to the caller by updating |
|
134 the pointer. If an error occurs, the buffers are not swapped and |
|
135 the pointer is not updated. Note that this class never owns any |
|
136 buffers and that passing a buffer to this function does not imply a |
|
137 transfer of ownership. |
|
138 @param aLength The amount of the buffer to write |
|
139 @return Symbian OS error code |
|
140 */ |
|
141 TInt CObexSyncFileWriter::FinalWrite(TInt aPos, CBufBase*& aBuf, TInt aLength) |
|
142 { |
|
143 __ASSERT_ALWAYS(aBuf, PANIC(KObexSyncFileWriterPanic, ENullBufferPointer)); |
|
144 |
|
145 // Write the final block |
|
146 TInt err = iFile.Write(aPos, aBuf->Ptr(0), aLength); |
|
147 if (err == KErrNone) |
|
148 { |
|
149 //flush the buffer, commit the write |
|
150 return iFile.Flush(); |
|
151 } |
|
152 else |
|
153 { |
|
154 return err; |
|
155 } |
|
156 } |
|
157 |
|
158 /** |
|
159 Destructor |
|
160 |
|
161 @internalComponent |
|
162 @released |
|
163 */ |
|
164 CObexSyncFileWriter::~CObexSyncFileWriter() |
|
165 { |
|
166 } |