os/persistentdata/persistentstorage/sql/SRC/Server/SqlSrvFileData.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#ifndef __SQLSRVFILEDATA_H__
sl@0
    17
#define __SQLSRVFILEDATA_H__
sl@0
    18
sl@0
    19
#include <f32file.h>				//TParse, RFs
sl@0
    20
#include "SqlSrvStrings.h"			//KFileHandleSeparator
sl@0
    21
#include "SqlSrvConfig.h"			//TSqlSrvConfig & TSqlSrvConfigParams
sl@0
    22
sl@0
    23
sl@0
    24
/**
sl@0
    25
TSqlSrvFileData class.
sl@0
    26
sl@0
    27
TSqlSrvFileData class owns two sets of data:
sl@0
    28
- data, which never changes during the life time of TSqlSrvFileData object - file session instance, 
sl@0
    29
  system drive name, SQL server private data path, config file parameters, a store of names of existing 
sl@0
    30
  database configuration files. These permanent TSqlSrvFileData properties are initialized by calling 
sl@0
    31
  TSqlSrvFileData::InitL(). 
sl@0
    32
  The SQL server owns only one TSqlSrvFileData instance whose permanent properties are initialized during 
sl@0
    33
  the server startup and that TSqlSrvFileData instance is available to the other SQL server classes 
sl@0
    34
  via a call to CSqServer::FileData();
sl@0
    35
- data, which changes with every call to TSqlSrvFileData::SetL(const RMessage2& aMessage, TInt aArgNum). 
sl@0
    36
  The TSqlSrvFileData instance expects that argument aArgNum of aMessage object contains a file name.
sl@0
    37
  The file name will be parsed by the TSqlSrvFileData instance and then the full file name is made available
sl@0
    38
  through TSqlSrvFileData::FileName() and TSqlSrvFileData::FileNameZ() (zero-terminated file name);
sl@0
    39
  
sl@0
    40
The TSqlSrvFileData instance also can be used for (after calling TSqlSrvFileData::SetL() or TSqlSrvFileData::SetFromHandleL()):
sl@0
    41
- retrieving the full file name;
sl@0
    42
- retrieving the system drive name;
sl@0
    43
- retrieving the server private path;
sl@0
    44
- checking the file name format type - secure or non-secure;
sl@0
    45
- retrieving the SID of the file name, if that is a secure file name;
sl@0
    46
sl@0
    47
With TSqlSrvFileData class we can:
sl@0
    48
- Minimize the stack usage (there is only one, heap based TSqlSrvFileData instance, owned by the SQL server);
sl@0
    49
- Keep in one place all data needed for opening/creating/attaching/copying/deleting a database file;
sl@0
    50
sl@0
    51
@see CSqlServer
sl@0
    52
@see CSqlServer::FileData()
sl@0
    53
@see TSqlSrvFileData::SetL()
sl@0
    54
@see TSqlSrvFileData::SetFromHandleL()
sl@0
    55
@see TSqlSrvFileData::Fs()
sl@0
    56
@see TSqlSrvFileData::PrivatePath()
sl@0
    57
@see TSqlSrvFileData::Drive()
sl@0
    58
@see TSqlSrvFileData::FileName()
sl@0
    59
@see TSqlSrvFileData::FileNameZ()
sl@0
    60
@see TSqlSrvFileData::IsSecureFileNameFmt()
sl@0
    61
@see TSqlSrvFileData::SecureUid()
sl@0
    62
@see TSqlSrvFileData::IsCreated()
sl@0
    63
@see TSqlSrvFileData::IsReadOnly()
sl@0
    64
@see TSqlSrvFileData::ContainHandles()
sl@0
    65
@see TSqlSrvFileData::ConfigParams()
sl@0
    66
@see TSqlSrvFileData::DbConfigFiles()
sl@0
    67
sl@0
    68
@internalComponent
sl@0
    69
*/
sl@0
    70
NONSHARABLE_CLASS(TSqlSrvFileData)
sl@0
    71
	{
sl@0
    72
public:
sl@0
    73
	inline void InitL(RFs& aFs, const TDriveName& aSysDriveName, const TDesC& aServerPrivatePath, 
sl@0
    74
					  const TDesC& aConfigFileName, const CDbConfigFiles* aDbConfigFiles);
sl@0
    75
	void SetL(const RMessage2& aMessage, TInt aFileNameLen, TInt aFileNameArgNum,
sl@0
    76
#ifdef SQLSRV_STARTUP_TEST
sl@0
    77
	          const TDesC& aDbFileName,
sl@0
    78
#endif	        
sl@0
    79
	          const TDesC8* aConfigStr = NULL);
sl@0
    80
  	void SetFromHandleL(const RMessage2& aMessage, const TDesC& aDbFileName, TBool aCreated, TBool aReadOnly, const TDesC8* aConfigStr = NULL);
sl@0
    81
sl@0
    82
	inline RFs& Fs() const;
sl@0
    83
	inline TPtrC PrivatePath() const;
sl@0
    84
	inline TDriveNumber Drive() const;
sl@0
    85
	inline TPtrC FileName() const;
sl@0
    86
	inline TPtrC FileNameZ() const;
sl@0
    87
	inline TBool IsSecureFileNameFmt() const;
sl@0
    88
	inline TUid SecureUid() const;
sl@0
    89
	inline TBool IsCreated() const;
sl@0
    90
	inline TBool IsReadOnly() const;
sl@0
    91
	inline TBool ContainHandles() const;
sl@0
    92
	inline const TSqlSrvConfigParams& ConfigParams() const;
sl@0
    93
	inline const CDbConfigFiles* DbConfigFiles() const;
sl@0
    94
sl@0
    95
private:
sl@0
    96
	RFs						iFs;
sl@0
    97
	TParse					iSysDrivePrivatePath;// <System drive name> + <Private directory>
sl@0
    98
	TSqlSrvConfig			iConfig;			 // Contains the config file parameters (not used directly. TSqlSrvConfig::GetConfigParamsL()
sl@0
    99
												 // should be used to get the right set of configuration parameters)	
sl@0
   100
	TBuf<KMaxFileName + 1>	iFileName;
sl@0
   101
	TDriveNumber 			iDrive;
sl@0
   102
	TBool					iIsSecureFileNameFmt;
sl@0
   103
	TUid					iSecureUid;
sl@0
   104
	TBool					iCreated;			// If the file is a private database, iCreated is true if the file was created,
sl@0
   105
												// false if the file was opened by the client side
sl@0
   106
	TBool					iReadOnly;
sl@0
   107
	TSqlSrvConfigParams		iConfigParams;		// Contains the configuration parameters, which shall be used 
sl@0
   108
												// for the database connection (when creating/openning)
sl@0
   109
	const CDbConfigFiles*	iDbConfigFilesPtr;  // Pointer to server's store of existing database config file names, NULL if there are no config files
sl@0
   110
	};
sl@0
   111
sl@0
   112
/**
sl@0
   113
Initializes the permanent data of TSqlSrvFileData instance.
sl@0
   114
This type of initialization happens during the SQL server startup.
sl@0
   115
Once initialized, the permanent set of data stays unchanged for the whole life time of TSqlSrvFileData instance.
sl@0
   116
sl@0
   117
@code
sl@0
   118
The permanent set of data includes:
sl@0
   119
- a file session instance;
sl@0
   120
- system drive name;
sl@0
   121
- SQL server private data path;
sl@0
   122
- config file parameters;
sl@0
   123
- a store of names of existing database configuration files
sl@0
   124
@endcode
sl@0
   125
sl@0
   126
@param aFs A reference to a file session instance
sl@0
   127
@param aSysDriveName A reference to the system drive name
sl@0
   128
@param aServerPrivatePath A reference to SQL server private data path
sl@0
   129
@param aConfigFileName SQL server configuration file name
sl@0
   130
@param aDbConfigFiles A pointer to the server's store of existing database configuration file names
sl@0
   131
*/
sl@0
   132
inline void TSqlSrvFileData::InitL(RFs& aFs, const TDriveName& aSysDriveName, const TDesC& aServerPrivatePath, 
sl@0
   133
								   const TDesC& aConfigFileName, const CDbConfigFiles* aDbConfigFiles)
sl@0
   134
	{
sl@0
   135
	iFs = aFs;
sl@0
   136
	__SQLLEAVE_IF_ERROR(iSysDrivePrivatePath.Set(aSysDriveName, &aServerPrivatePath, 0));
sl@0
   137
	iConfig.InitL(aFs, aConfigFileName);
sl@0
   138
	iConfig.GetConfigParamsL(KNullDesC8, iConfigParams);//iConfigParams initialized with the config file params 
sl@0
   139
														//(because an empty configuration string is passed as an argument)
sl@0
   140
	iDbConfigFilesPtr = aDbConfigFiles;
sl@0
   141
	}
sl@0
   142
sl@0
   143
/**
sl@0
   144
@return A reference to the file session instance
sl@0
   145
*/
sl@0
   146
inline RFs& TSqlSrvFileData::Fs() const
sl@0
   147
	{
sl@0
   148
	return const_cast <RFs&> (iFs);	
sl@0
   149
	}
sl@0
   150
sl@0
   151
/**
sl@0
   152
@return SQL server private path.
sl@0
   153
*/
sl@0
   154
inline TPtrC TSqlSrvFileData::PrivatePath() const
sl@0
   155
	{
sl@0
   156
	return iSysDrivePrivatePath.Path();
sl@0
   157
	}
sl@0
   158
	
sl@0
   159
/**
sl@0
   160
@return The file drive.
sl@0
   161
*/
sl@0
   162
inline TDriveNumber TSqlSrvFileData::Drive() const
sl@0
   163
	{
sl@0
   164
	return iDrive;	
sl@0
   165
	}
sl@0
   166
sl@0
   167
/**
sl@0
   168
@return A read-only descriptor pointing to the file name.
sl@0
   169
*/
sl@0
   170
inline TPtrC TSqlSrvFileData::FileName() const
sl@0
   171
	{
sl@0
   172
	return iFileName.Left(iFileName.Length() - 1);
sl@0
   173
	}
sl@0
   174
sl@0
   175
/**
sl@0
   176
@return A read-only descriptor pointing to the file name, zero-terminated.
sl@0
   177
*/
sl@0
   178
inline TPtrC TSqlSrvFileData::FileNameZ() const
sl@0
   179
	{
sl@0
   180
	return iFileName;
sl@0
   181
	}
sl@0
   182
sl@0
   183
/**
sl@0
   184
@return True if the file name format refers to a secure file name.
sl@0
   185
*/
sl@0
   186
inline TBool TSqlSrvFileData::IsSecureFileNameFmt() const
sl@0
   187
	{
sl@0
   188
	return iIsSecureFileNameFmt;
sl@0
   189
	}
sl@0
   190
	
sl@0
   191
/**
sl@0
   192
@return The secure UID, if the file name is a secure file name, KNullUid otherwise.
sl@0
   193
*/
sl@0
   194
inline TUid TSqlSrvFileData::SecureUid() const
sl@0
   195
	{
sl@0
   196
	return iSecureUid;
sl@0
   197
	}
sl@0
   198
sl@0
   199
/**
sl@0
   200
Returns true if the file was created, false if the file was opened by the client side.
sl@0
   201
This function should be used only for private databases, e.g. for which ContainHandles() returns true.
sl@0
   202
@return True if the file was created, false if the file was opened by the client side.
sl@0
   203
sl@0
   204
@see TSqlSrvFileData::ContainHandles()
sl@0
   205
*/
sl@0
   206
inline TBool TSqlSrvFileData::IsCreated() const
sl@0
   207
	{
sl@0
   208
	return iCreated;
sl@0
   209
	}
sl@0
   210
sl@0
   211
/**
sl@0
   212
@return True if the file is a read-only file.
sl@0
   213
*/
sl@0
   214
inline TBool TSqlSrvFileData::IsReadOnly() const
sl@0
   215
	{
sl@0
   216
	return iReadOnly;
sl@0
   217
	}
sl@0
   218
sl@0
   219
/**
sl@0
   220
@return True if the file name contains file and session handles
sl@0
   221
*/
sl@0
   222
inline TBool TSqlSrvFileData::ContainHandles() const
sl@0
   223
	{
sl@0
   224
	return iFileName[0] == KFileHandleSeparator;
sl@0
   225
	}
sl@0
   226
sl@0
   227
/**
sl@0
   228
@return A reference to the configuration parameters.
sl@0
   229
*/
sl@0
   230
inline const TSqlSrvConfigParams& TSqlSrvFileData::ConfigParams() const
sl@0
   231
	{
sl@0
   232
	return iConfigParams;
sl@0
   233
	}
sl@0
   234
sl@0
   235
/**
sl@0
   236
@return A pointer to the server's store of existing database configuration file names 
sl@0
   237
        (will be NULL if there are no existing configuration files)
sl@0
   238
*/	
sl@0
   239
inline const CDbConfigFiles* TSqlSrvFileData::DbConfigFiles() const
sl@0
   240
	{
sl@0
   241
	return iDbConfigFilesPtr;
sl@0
   242
	}
sl@0
   243
sl@0
   244
#endif//__SQLSRVFILEDATA_H__