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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #ifndef __OBEXOBJECTS_H
23 #define __OBEXOBJECTS_H
25 #include <obextypes.h>
26 #include <obexbaseobject.h>
29 class MObexFileWriter;
30 class TObexBufferingDetails;
33 This class is a concrete derivation of the CObexBaseObject class. Use it to
34 store and transfer OBEX objects with the body part stored in an EPOC file.
35 Hence this class is particularly suited to OBEX "file" beaming applications
36 (c.f. arbitrary object beaming), although there is in reality no
37 restriction in what it is used to transfer. Access to the body is acheived
38 through an additional attribute to the object; the data file. This is the
39 file-system name of the file used to store the body of the object. Note
40 that there is no explicit relation between this and the Name of the object,
41 although it is expected that most applications would attempt to relate the
44 When ever a valid data file is set (i.e. DataFile().Length > 0), this file
45 is effectively open, hence stopping any other application from opening it
46 with exclusive rights. Therefore, it is recommended that Reset () be called
47 on the object as soon as it is no longer required, and definitely before
48 (conceptually) passing ownership of the data file to any other object or
51 CObexFileObject is also suited to situations where an object is expected to
52 be received, but no information about the purpose of this object is known.
53 This is due to CObexFileObject’s ability to create temporary files "on the
54 fly" to store received data into, when a specific file is not provided by
57 This class is not designed for user derivation.
62 NONSHARABLE_CLASS(CObexFileObject) : public CObexBaseObject
65 static IMPORT_C CObexFileObject* NewL();
66 static IMPORT_C CObexFileObject* NewL(const TDesC &aDataFile);
67 virtual IMPORT_C ~CObexFileObject();
68 IMPORT_C void InitFromFileL(const TDesC& aFile);
71 void ConstructL(const TDesC &aDataFile);
72 void SetDataFileL(const TDesC& aDesc);
73 const TDesC& DataFile();
74 TBool RenameFile(const TDesC& aDesC);
75 void SetTempFilePath(const TDesC& aPath);
76 void QueryTempFilePath(TDes& aPath);
77 // From CObexBaseObject
78 virtual void GetData(TInt aPos, TDes8& aDes);
79 virtual void NewData(TInt aPos, TDes8& aDes);
80 virtual TInt DataSize();
81 virtual void ResetData();
87 TBuf<KObexObjectDescriptionSize> iTempFilePath;
93 Use this class to hold objects where the body part is stored in a CBufFlat
94 object. Please note that although parameters are supplied as CBufBase objects,
95 non-CBufFlat parameters are not supported and will have unpredictable results.
96 At no point does the CObexBufObject create, or take ownership of any CBaseBuf
97 object it uses - it is always the responsibility of the creator/owner of the
98 CBaseBuf to free it when no longer required.
100 As this class does not take ownership of the buffers it uses, it equally can
101 not create its own buffers ad-hoc for storing new data into. Hence at no
102 time is it valid for a CObexBufObject to exist with out it having a valid
103 data buffer set. If such a situation arises, where it is required that
104 received information should be discarded, consider using a CObexNullObject.
106 It is also posible to supply a file instead of a memory buffer, or to supply
107 both. This functionality is due to the MObexServerNotify class expecting to
108 work only on CObexBufObjects, so CObexFileObjects cannot be returned from the
110 To use a file for body storage, call NewL() passing in a NULL pointer, then
111 call SetDataBufL() manually afterwards. There are three overloads---to allow
112 purely memory based objects, purely file based, or a hybrid. The hybrid object
113 buffers into a memory buffer (which is not allowed to grow), then writes data
114 to the file when the buffer is full. The buffering behaviour can therefore be
115 tuned to the application by setting the size of the buffer prior to use.
117 This class is not designed for user derivation.
122 NONSHARABLE_CLASS(CObexBufObject) : public CObexBaseObject
126 Obex file buffering method.
133 /** Only the supplied buffer will be used to buffer file writes. */
135 /** The object will create a second buffer and perform double buffering. */
140 static IMPORT_C CObexBufObject* NewL(CBufBase* aDataBuf);
141 virtual IMPORT_C ~CObexBufObject();
142 IMPORT_C TInt WriteToFile(const TPtrC& aFileName);
144 IMPORT_C void SetDataBufL(TObexBufferingDetails& aDetails);
145 IMPORT_C void SetDataBufL(CBufBase* aDataBuf);
146 IMPORT_C void SetDataBufL(const TPtrC& aFilename);
147 IMPORT_C void SetDataBufL(const TPtrC& aFilename, CBufBase* aDataBuf);
148 IMPORT_C void SetDataBufL(const TPtrC& aFilename, CBufBase& aDataBuf, const TFileBuffering aBufferingStrategy);
149 IMPORT_C CBufBase* DataBuf();
154 void ConstructL(CBufBase* aDataBuf);
156 void PrepareToSetBufferL();
158 void CopyFileL(const TDesC& aFilename);
159 TInt NewFileData(TInt aPos, TDes8& aDes);
160 void GetFileData(TInt aPos, TDes8& aDes);
162 // From CObexBaseObject
163 virtual void GetData(TInt aPos, TDes8& aDes);
164 virtual void NewData(TInt aPos, TDes8& aDes);
165 virtual TInt DataSize();
166 virtual void ResetData();
168 void CloseDataFile();
169 TInt OpenDataFile(const TDesC& aFilename);
170 void CloseFileServer();
171 TInt OpenFileServer();
172 TInt WriteBufferToFile(TBool aFinal);
184 // Added for double-buffering
187 MObexFileWriter* iWriter;
188 CBufBase* iDoubleBuf;
194 Wraps parameters which can affect the buffering method used by the
196 This version provides a single memory buffer which holds the entire object.
197 Subclasses will always use a memory buffer, but can override the way that
203 NONSHARABLE_CLASS(TObexBufferingDetails)
207 Versions (subclasses) of the buffering style object.
208 This enum should not be used outside the dll.
215 EFilenameBackedBuffer,
220 IMPORT_C TObexBufferingDetails(CBufBase& aBuffer);
222 TVersion Version(); // Return the version of this object
226 TObexBufferingDetails(TVersion aVersion, CBufBase* aBuffer);
232 // This data padding has been added to help prevent future binary compatibility breaks
233 // Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used
240 Provides alternate behaviour for a CObexBufObject, allowing use of a file
241 to hold the object in its entirety. No memory buffer is used. This is a
242 special case option provided to cater for the MObexServerNotify interface
243 which requires the use of CObexBufObject objects. It is generally better to
244 use a buffered variant.
249 NONSHARABLE_CLASS(TObexPureFileBuffer) : public TObexBufferingDetails
252 IMPORT_C TObexPureFileBuffer(const TPtrC& aFilename);
253 const TPtrC& Filename();
256 const TPtrC& iFilename;
258 // This data padding has been added to help prevent future binary compatibility breaks
259 // Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used
265 Provides alternate behaviour for a CObexBufObject, allowing use of a file
266 to hold the object in its entirety. Writes to this object are buffered through
267 the supplied CBufBase derived object, which is never enlarged. Once
268 it is full, the data is flushed to the file.
273 NONSHARABLE_CLASS(TObexFilenameBackedBuffer) : public TObexBufferingDetails
276 IMPORT_C TObexFilenameBackedBuffer(CBufBase& aBuffer, const TPtrC& aFilename, CObexBufObject::TFileBuffering aBufferingStrategy);
277 const TPtrC& Filename();
278 CObexBufObject::TFileBuffering Strategy();
281 const TPtrC& iFilename;
282 CObexBufObject::TFileBuffering iBufferingStrategy;
284 // This data padding has been added to help prevent future binary compatibility breaks
285 // Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used
293 Provides alternate behaviour for a CObexBufObject, allowing use of a file
294 to hold the object in its entirety. Writes to this object are buffered through
295 the supplied CBufBase derived object, which is never enlarged. Once
296 it is full, the data is flushed to the file.
301 NONSHARABLE_CLASS(TObexRFileBackedBuffer) : public TObexBufferingDetails
304 IMPORT_C TObexRFileBackedBuffer(CBufBase& aBuffer, RFile aFile, CObexBufObject::TFileBuffering aBufferingStrategy);
306 CObexBufObject::TFileBuffering Strategy();
310 CObexBufObject::TFileBuffering iBufferingStrategy;
312 // This data padding has been added to help prevent future binary compatibility breaks
313 // Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used
321 Concrete OBEX object with NULL data representation. Use when only the
322 headers of an object are required, and the data (if any) can safely be
328 NONSHARABLE_CLASS(CObexNullObject) : public CObexBaseObject
331 IMPORT_C static CObexNullObject* NewL ();
333 // From CObexBaseObject
335 virtual void GetData (TInt aPos, TDes8& aDes);
336 virtual void NewData (TInt aPos, TDes8& aDes);
337 virtual TInt DataSize ();
338 virtual void ResetData ();
341 #endif // __OBEXOBJECTS_H