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