epoc32/include/mw/obexobjects.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/obexobjects.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@2
     4
// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
williamr@2
     5
// which accompanies this distribution, and is available
williamr@2
     6
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
//
williamr@2
    15
williamr@2
    16
williamr@2
    17
williamr@2
    18
/**
williamr@2
    19
 @file
williamr@2
    20
 @publishedAll
williamr@2
    21
 @released
williamr@2
    22
*/
williamr@2
    23
williamr@2
    24
#ifndef __OBEXOBJECTS_H
williamr@2
    25
#define __OBEXOBJECTS_H
williamr@2
    26
williamr@2
    27
#include <obextypes.h>
williamr@2
    28
#include <obexbaseobject.h>
williamr@2
    29
#include <f32file.h>
williamr@2
    30
williamr@2
    31
class MObexFileWriter;
williamr@2
    32
class TObexBufferingDetails;
williamr@2
    33
williamr@2
    34
/**
williamr@2
    35
This class is a concrete derivation of the CObexBaseObject class. Use it to 
williamr@2
    36
store and transfer OBEX objects with the body part stored in an EPOC file. 
williamr@2
    37
Hence this class is particularly suited to OBEX "file" beaming applications 
williamr@2
    38
(c.f. arbitrary object beaming), although there is in reality no 
williamr@2
    39
restriction in what it is used to transfer. Access to the body is acheived 
williamr@2
    40
through an additional attribute to the object; the data file. This is the 
williamr@2
    41
file-system name of the file used to store the body of the object. Note 
williamr@2
    42
that there is no explicit relation between this and the Name of the object, 
williamr@2
    43
although it is expected that most applications would attempt to relate the 
williamr@2
    44
two.
williamr@2
    45
williamr@2
    46
When ever a valid data file is set (i.e. DataFile().Length > 0), this file 
williamr@2
    47
is effectively open, hence stopping any other application from opening it 
williamr@2
    48
with exclusive rights. Therefore, it is recommended that Reset () be called 
williamr@2
    49
on the object as soon as it is no longer required, and definitely before 
williamr@2
    50
(conceptually) passing ownership of the data file to any other object or 
williamr@2
    51
user.
williamr@2
    52
williamr@2
    53
CObexFileObject is also suited to situations where an object is expected to 
williamr@2
    54
be received, but no information about the purpose of this object is known. 
williamr@2
    55
This is due to CObexFileObject’s ability to create temporary files "on the 
williamr@2
    56
fly" to store received data into, when a specific file is not provided by 
williamr@2
    57
the application.
williamr@2
    58
williamr@2
    59
This class is not designed for user derivation.
williamr@2
    60
williamr@2
    61
@publishedAll
williamr@2
    62
@released
williamr@2
    63
*/
williamr@2
    64
NONSHARABLE_CLASS(CObexFileObject) : public CObexBaseObject
williamr@2
    65
	{
williamr@2
    66
public:
williamr@2
    67
	static IMPORT_C CObexFileObject* NewL();
williamr@2
    68
	static IMPORT_C CObexFileObject* NewL(const TDesC &aDataFile);
williamr@2
    69
	virtual IMPORT_C ~CObexFileObject();
williamr@2
    70
	IMPORT_C void InitFromFileL(const TDesC& aFile);
williamr@2
    71
williamr@2
    72
private:
williamr@2
    73
	void ConstructL(const TDesC &aDataFile);
williamr@2
    74
	void SetDataFileL(const TDesC& aDesc);
williamr@2
    75
	const TDesC& DataFile();
williamr@2
    76
	TBool RenameFile(const TDesC& aDesC);
williamr@2
    77
	void SetTempFilePath(const TDesC& aPath);
williamr@2
    78
	void QueryTempFilePath(TDes& aPath);
williamr@2
    79
	// From CObexBaseObject
williamr@2
    80
	virtual void GetData(TInt aPos, TDes8& aDes);
williamr@2
    81
	virtual void NewData(TInt aPos, TDes8& aDes);
williamr@2
    82
	virtual TInt DataSize();
williamr@2
    83
	virtual void ResetData();
williamr@2
    84
// Data
williamr@2
    85
private:
williamr@2
    86
	RFs iFs;
williamr@2
    87
	TParse iDataFile;
williamr@2
    88
	RFile iFile;
williamr@2
    89
	TBuf<KObexObjectDescriptionSize> iTempFilePath;
williamr@2
    90
	};
williamr@2
    91
williamr@2
    92
williamr@2
    93
williamr@2
    94
/**
williamr@2
    95
Use this class to hold objects where the body part is stored in a CBufFlat
williamr@2
    96
object. Please note that although parameters are supplied as CBufBase objects,
williamr@2
    97
non-CBufFlat parameters are not supported and will have unpredictable results.
williamr@2
    98
At no point does the CObexBufObject create, or take ownership of any CBaseBuf
williamr@2
    99
object it uses - it is always the responsibility of the creator/owner of the
williamr@2
   100
CBaseBuf to free it when no longer required.
williamr@2
   101
williamr@2
   102
As this class does not take ownership of the buffers it uses, it equally can
williamr@2
   103
not create its own buffers ad-hoc for storing new data into. Hence at no 
williamr@2
   104
time is it valid for a CObexBufObject to exist with out it having a valid 
williamr@2
   105
data buffer set. If such a situation arises, where it is required that 
williamr@2
   106
received information should be discarded, consider using a CObexNullObject.
williamr@2
   107
williamr@2
   108
It is also posible to supply a file instead of a memory buffer, or to supply
williamr@2
   109
both.  This functionality is due to the MObexServerNotify class expecting to
williamr@2
   110
work only on CObexBufObjects, so CObexFileObjects cannot be returned from the
williamr@2
   111
upcalls.
williamr@2
   112
To use a file for body storage, call NewL() passing in a NULL pointer, then
williamr@2
   113
call SetDataBufL() manually afterwards.  There are three overloads---to allow
williamr@2
   114
purely memory based objects, purely file based, or a hybrid.  The hybrid object
williamr@2
   115
buffers into a memory buffer (which is not allowed to grow), then writes data
williamr@2
   116
to the file when the buffer is full.  The buffering behaviour can therefore be
williamr@2
   117
tuned to the application by setting the size of the buffer prior to use.
williamr@2
   118
williamr@2
   119
This class is not designed for user derivation.
williamr@2
   120
williamr@2
   121
@publishedAll
williamr@2
   122
@released
williamr@2
   123
*/
williamr@2
   124
NONSHARABLE_CLASS(CObexBufObject) : public CObexBaseObject
williamr@2
   125
	{
williamr@2
   126
public:
williamr@2
   127
	/**
williamr@2
   128
	Obex file buffering method.
williamr@2
   129
	
williamr@2
   130
	@publishedAll
williamr@2
   131
	@released
williamr@2
   132
	*/
williamr@2
   133
	enum TFileBuffering
williamr@2
   134
		{
williamr@2
   135
		/** Only the supplied buffer will be used to buffer file writes. */
williamr@2
   136
		ESingleBuffering,
williamr@2
   137
		/** The object will create a second buffer and perform double buffering. */
williamr@2
   138
		EDoubleBuffering
williamr@2
   139
		};
williamr@2
   140
williamr@2
   141
public:
williamr@2
   142
	static IMPORT_C CObexBufObject* NewL(CBufBase* aDataBuf);
williamr@2
   143
	virtual IMPORT_C ~CObexBufObject();
williamr@2
   144
	IMPORT_C TInt WriteToFile(const TPtrC& aFileName);
williamr@2
   145
	
williamr@2
   146
	IMPORT_C void SetDataBufL(TObexBufferingDetails& aDetails);
williamr@2
   147
	IMPORT_C void SetDataBufL(CBufBase* aDataBuf);
williamr@2
   148
	IMPORT_C void SetDataBufL(const TPtrC& aFilename);
williamr@2
   149
	IMPORT_C void SetDataBufL(const TPtrC& aFilename, CBufBase* aDataBuf);
williamr@2
   150
	IMPORT_C void SetDataBufL(const TPtrC& aFilename, CBufBase& aDataBuf, const TFileBuffering aBufferingStrategy);
williamr@2
   151
	IMPORT_C CBufBase* DataBuf();
williamr@2
   152
	HBufC* FileName();
williamr@2
   153
williamr@2
   154
private:
williamr@2
   155
	CObexBufObject();
williamr@2
   156
	void ConstructL(CBufBase* aDataBuf);
williamr@2
   157
	
williamr@2
   158
	void PrepareToSetBufferL();
williamr@2
   159
williamr@2
   160
	void CopyFileL(const TDesC& aFilename);
williamr@2
   161
	TInt NewFileData(TInt aPos, TDes8& aDes);
williamr@2
   162
	void GetFileData(TInt aPos, TDes8& aDes);
williamr@2
   163
williamr@2
   164
	// From CObexBaseObject
williamr@2
   165
	virtual void GetData(TInt aPos, TDes8& aDes);
williamr@2
   166
	virtual void NewData(TInt aPos, TDes8& aDes);
williamr@2
   167
	virtual TInt DataSize();
williamr@2
   168
	virtual void ResetData();
williamr@2
   169
williamr@2
   170
	void CloseDataFile();
williamr@2
   171
	TInt OpenDataFile(const TDesC& aFilename);
williamr@2
   172
	void CloseFileServer();
williamr@2
   173
	TInt OpenFileServer();
williamr@2
   174
	TInt WriteBufferToFile(TBool aFinal);
williamr@2
   175
williamr@2
   176
// Data
williamr@2
   177
private:
williamr@2
   178
	CBufBase* iBuf;
williamr@2
   179
	HBufC* iFilename;
williamr@2
   180
	RFs* iFileServ;
williamr@2
   181
	RFile* iFile;
williamr@2
   182
	TInt iBufOffset;
williamr@2
   183
	TInt iBuffered;
williamr@2
   184
	TInt iBufSegSize;
williamr@2
   185
williamr@2
   186
// Added for double-buffering
williamr@2
   187
private:
williamr@2
   188
	// Owned
williamr@2
   189
	MObexFileWriter*	iWriter;
williamr@2
   190
	CBufBase*			iDoubleBuf;
williamr@2
   191
	};
williamr@2
   192
williamr@2
   193
williamr@2
   194
williamr@2
   195
/**
williamr@2
   196
Wraps parameters which can affect the buffering method used by the
williamr@2
   197
CObexBufObject.
williamr@2
   198
This version provides a single memory buffer which holds the entire object.
williamr@2
   199
Subclasses will always use a memory buffer, but can override the way that
williamr@2
   200
Obex uses it.
williamr@2
   201
williamr@2
   202
@publishedAll
williamr@2
   203
@released
williamr@2
   204
*/
williamr@2
   205
NONSHARABLE_CLASS(TObexBufferingDetails)
williamr@2
   206
	{
williamr@2
   207
public:
williamr@2
   208
	/**
williamr@2
   209
	Versions (subclasses) of the buffering style object.
williamr@2
   210
	@internalComponent
williamr@2
   211
	*/
williamr@2
   212
	enum TVersion
williamr@2
   213
		{
williamr@2
   214
		EBasicBuffer,
williamr@2
   215
		EPureFile,
williamr@2
   216
		EFilenameBackedBuffer,
williamr@2
   217
		ERFileBackedBuffer,
williamr@2
   218
		ELastVersion
williamr@2
   219
		};
williamr@2
   220
	
williamr@2
   221
	IMPORT_C TObexBufferingDetails(CBufBase& aBuffer);
williamr@2
   222
	
williamr@2
   223
	TVersion Version();	// Return the version of this object
williamr@2
   224
	CBufBase* Buffer();
williamr@2
   225
williamr@2
   226
protected:
williamr@2
   227
	TObexBufferingDetails(TVersion aVersion, CBufBase* aBuffer);
williamr@2
   228
williamr@2
   229
private:
williamr@2
   230
	TVersion iVersion;
williamr@2
   231
	CBufBase* iBuffer;
williamr@2
   232
williamr@2
   233
	// This data padding has been added to help prevent future binary compatibility breaks	
williamr@2
   234
	// Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used
williamr@2
   235
	TUint32     iPadding1; 
williamr@2
   236
	TUint32     iPadding2; 	
williamr@2
   237
	};
williamr@2
   238
williamr@2
   239
williamr@2
   240
/**
williamr@2
   241
Provides alternate behaviour for a CObexBufObject, allowing use of a file
williamr@2
   242
to hold the object in its entirety.  No memory buffer is used.  This is a
williamr@2
   243
special case option provided to cater for the MObexServerNotify interface
williamr@2
   244
which requires the use of CObexBufObject objects.  It is generally better to
williamr@2
   245
use a buffered variant.
williamr@2
   246
williamr@2
   247
@publishedAll
williamr@2
   248
@released
williamr@2
   249
*/
williamr@2
   250
NONSHARABLE_CLASS(TObexPureFileBuffer) : public TObexBufferingDetails
williamr@2
   251
	{
williamr@2
   252
public:
williamr@2
   253
	IMPORT_C TObexPureFileBuffer(const TPtrC& aFilename);
williamr@2
   254
	const TPtrC& Filename();
williamr@2
   255
williamr@2
   256
private:
williamr@2
   257
	const TPtrC& iFilename;
williamr@2
   258
williamr@2
   259
	// This data padding has been added to help prevent future binary compatibility breaks	
williamr@2
   260
	// Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used
williamr@2
   261
	TUint32     iPadding1; 
williamr@2
   262
	TUint32     iPadding2; 
williamr@2
   263
	};
williamr@2
   264
williamr@2
   265
/**
williamr@2
   266
Provides alternate behaviour for a CObexBufObject, allowing use of a file
williamr@2
   267
to hold the object in its entirety.  Writes to this object are buffered through
williamr@2
   268
the supplied CBufBase derived object, which is never enlarged.  Once
williamr@2
   269
it is full, the data is flushed to the file.
williamr@2
   270
williamr@2
   271
@publishedAll
williamr@2
   272
@released
williamr@2
   273
*/
williamr@2
   274
NONSHARABLE_CLASS(TObexFilenameBackedBuffer) : public TObexBufferingDetails
williamr@2
   275
	{
williamr@2
   276
public:
williamr@2
   277
	IMPORT_C TObexFilenameBackedBuffer(CBufBase& aBuffer, const TPtrC& aFilename, CObexBufObject::TFileBuffering aBufferingStrategy);
williamr@2
   278
	const TPtrC& Filename();
williamr@2
   279
	CObexBufObject::TFileBuffering Strategy();
williamr@2
   280
	
williamr@2
   281
private:
williamr@2
   282
	const TPtrC& iFilename;
williamr@2
   283
	CObexBufObject::TFileBuffering iBufferingStrategy;
williamr@2
   284
williamr@2
   285
	// This data padding has been added to help prevent future binary compatibility breaks	
williamr@2
   286
	// Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used
williamr@2
   287
	TUint32     iPadding1; 
williamr@2
   288
	TUint32     iPadding2; 	
williamr@2
   289
	};
williamr@2
   290
williamr@2
   291
williamr@2
   292
williamr@2
   293
/**
williamr@2
   294
Provides alternate behaviour for a CObexBufObject, allowing use of a file
williamr@2
   295
to hold the object in its entirety.  Writes to this object are buffered through
williamr@2
   296
the supplied CBufBase derived object, which is never enlarged.  Once
williamr@2
   297
it is full, the data is flushed to the file.
williamr@2
   298
williamr@2
   299
@publishedAll
williamr@2
   300
@released
williamr@2
   301
*/
williamr@2
   302
NONSHARABLE_CLASS(TObexRFileBackedBuffer) : public TObexBufferingDetails
williamr@2
   303
	{
williamr@2
   304
public:
williamr@2
   305
	IMPORT_C TObexRFileBackedBuffer(CBufBase& aBuffer, RFile aFile, CObexBufObject::TFileBuffering aBufferingStrategy);
williamr@2
   306
	RFile File();
williamr@2
   307
	CObexBufObject::TFileBuffering Strategy();
williamr@2
   308
	
williamr@2
   309
private:
williamr@2
   310
	RFile iFile;
williamr@2
   311
	CObexBufObject::TFileBuffering iBufferingStrategy;
williamr@2
   312
williamr@2
   313
	// This data padding has been added to help prevent future binary compatibility breaks	
williamr@2
   314
	// Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used
williamr@2
   315
	TUint32     iPadding1; 
williamr@2
   316
	TUint32     iPadding2; 
williamr@2
   317
	};
williamr@2
   318
williamr@2
   319
williamr@2
   320
williamr@2
   321
/**
williamr@2
   322
Concrete OBEX object with NULL data representation. Use when only the 
williamr@2
   323
headers of an object are required, and the data (if any) can safely be 
williamr@2
   324
discarded.
williamr@2
   325
williamr@2
   326
@publishedAll
williamr@2
   327
@released
williamr@2
   328
*/
williamr@2
   329
NONSHARABLE_CLASS(CObexNullObject) : public CObexBaseObject
williamr@2
   330
	{
williamr@2
   331
public:
williamr@2
   332
	IMPORT_C static CObexNullObject* NewL ();
williamr@2
   333
private:
williamr@2
   334
	// From CObexBaseObject
williamr@2
   335
	void ConstructL();
williamr@2
   336
	virtual void GetData (TInt aPos, TDes8& aDes);
williamr@2
   337
	virtual void NewData (TInt aPos, TDes8& aDes);
williamr@2
   338
	virtual TInt DataSize ();
williamr@2
   339
	virtual void ResetData ();
williamr@2
   340
	};
williamr@2
   341
williamr@2
   342
#endif // __OBEXOBJECTS_H