epoc32/include/bsp.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 bsp.h
     1 // Copyright (c) 1998-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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // BSP.H (Base Script Parser)
       
    15 // Abstract class for different Parsers.
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 #if !defined(__BSP_H__)
       
    21 #define __BSP_H__
       
    22 
       
    23 #if !defined(__MTCLREG_H__)
       
    24 #include <mtclreg.h>
       
    25 #endif
       
    26 
       
    27 #if !defined(__MTCLBASE_H__)
       
    28 #include <mtclbase.h>
       
    29 #endif
       
    30 
       
    31 #include <e32base.h>
       
    32 #if !defined(__S32STRM_H__)
       
    33 #include <s32strm.h>
       
    34 #endif
       
    35 
       
    36 #include <msvstd.h>
       
    37 // CRichText etc. includes
       
    38 #include <txtrich.h>
       
    39 #include <txtfmlyr.h>
       
    40 
       
    41 #include <bif.h>
       
    42 
       
    43 
       
    44 
       
    45 // Symbols:
       
    46 /** Space character. */
       
    47 #define KCharSpace          ' '
       
    48 /** Tab character. */
       
    49 #define KCharTab            '\t'
       
    50 /** Line feed character. */
       
    51 #define KCharLineFeed       '\n'
       
    52 
       
    53 
       
    54 // Define some generic error codes:
       
    55 /** BIO error code base. */
       
    56 const TInt KBspBaseError					= (-500);
       
    57 
       
    58 /** Invalid BIO message error code. */
       
    59 const TInt KBspInvalidMessage				= (KBspBaseError);
       
    60 /** Invalid smart message token error code. */
       
    61 const TInt KBspSmartMessageInvalidToken		= (KBspBaseError-1);
       
    62 /** No smart message parser defined error code. */
       
    63 const TInt KBspSmartMessageNoParserDefined	= (KBspBaseError-2);
       
    64 
       
    65 // Parsed field class for use by parsers.
       
    66 class CParsedField : public CBase
       
    67 /** Represents a single token-value pair for a given field in a BIO/smart message 
       
    68 grammar. 
       
    69 @publishedAll
       
    70 @released
       
    71 */
       
    72 {
       
    73 public:
       
    74 	IMPORT_C CParsedField();
       
    75 	IMPORT_C ~CParsedField();
       
    76 
       
    77 	IMPORT_C TPtrC FieldName() const;
       
    78 	IMPORT_C void SetFieldNameL( const TDesC& aFieldName);
       
    79 	IMPORT_C TPtrC FieldValue() const;
       
    80 	IMPORT_C void SetFieldValueL( const TDesC& aFieldValue);
       
    81 	IMPORT_C TBool MandatoryField() const;
       
    82 	IMPORT_C void SetMandatoryField(TBool aMandatoryField);
       
    83 
       
    84 	IMPORT_C void InternalizeL(RReadStream& aStream);
       
    85 	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
       
    86 private:
       
    87 	void Reset();
       
    88 private:
       
    89 	HBufC* iFieldName;
       
    90 	HBufC* iFieldValue;
       
    91 	TBool  iMandatoryField;
       
    92 };
       
    93 
       
    94 // Forward declarations:
       
    95 class CMsvServerEntry;
       
    96 class CMsvEntry;
       
    97 class CRegisteredParserDll;
       
    98 class RMsvReadStream;
       
    99 class RMsvWriteStream;
       
   100 class CMsvStore;
       
   101 class CSmsMessage;
       
   102 
       
   103 
       
   104 
       
   105 /** Base class for BIO message parsers V2.
       
   106 
       
   107 Concrete derived classes are implemented in parser DLL's to parse particular 
       
   108 types of BIO message.
       
   109 
       
   110 On receiving an appropriate command (see TBioOperation), the BIO server MTM 
       
   111 loads the appropriate parser and passes the message body to it for interpretation. 
       
   112 In fact, the parser interface expects the parser to divide its operation into 
       
   113 two stages: 
       
   114 
       
   115 1. parsing: which involves extracting information from the raw message body and 
       
   116 storing it in a structured format. The parsing stage can also alter the message 
       
   117 body, and create files in the directory associated with the message (e.g. 
       
   118 parsing a ring tones message will generate a ring tone file).
       
   119 
       
   120 2. processing: which involves using the extracted information to achieve the 
       
   121 purpose of the BIO message (e.g. setting some phone configuration setttings).
       
   122 
       
   123 This separation allows, for example, a UI to display the parsed information 
       
   124 to the user for confirmation, before it is acted upon. For some parsers, however, 
       
   125 this two stage division is not sensible, in which case they implement only 
       
   126 the first.
       
   127 
       
   128 The base class provides a pointer iSettings to reference the raw message data, 
       
   129 and an array of token-value pairs, iParsedFieldArray, for storing parsed information 
       
   130 (if this is appropriate). 
       
   131 @publishedAll
       
   132 @released
       
   133 */
       
   134 class CBaseScriptParser2: public CActive
       
   135 	{
       
   136 public:
       
   137 	IMPORT_C CBaseScriptParser2(CRegisteredParserDll& aRegisteredParserDll, CMsvEntry& aEntry, RFs& aFs);
       
   138 	IMPORT_C ~CBaseScriptParser2();
       
   139 
       
   140 	/** Called by the BIO server MTM to asynchronously parse message body data.
       
   141 	
       
   142 	When parsing is complete, the function should indicate this by setting the 
       
   143 	message's index field iMtmData3 to 1.
       
   144 	
       
   145 	The function should leave if the buffer cannot be parsed successfully.
       
   146 	
       
   147 	@param aStatus Asynchronous status word
       
   148 	@param aSms Buffer to parse */
       
   149 	virtual void ParseL(TRequestStatus& aStatus, const TDesC& aSms)=0; //parses sms data into CParsedField
       
   150 	/** Called by the BIO server MTM to asynchronously process the parsed data.
       
   151 	
       
   152 	The function takes appropriate parser-specific action on the results of a 
       
   153 	previous call to ParseL().
       
   154 	
       
   155 	When processing is complete, the function should indicate this by setting 
       
   156 	the message's index field iMtmData3 to 2.
       
   157 	
       
   158 	The function should leave if processing is not successful.
       
   159 	
       
   160 	@param aStatus Asynchronous status word */
       
   161 	virtual void ProcessL(TRequestStatus& aStatus)=0; //stores parsed data into streams and data base
       
   162 
       
   163 	IMPORT_C TUid ParserUid();
       
   164 	IMPORT_C void RestoreL(CMsvStore& aMessageStore);
       
   165 	IMPORT_C void StoreL(CMsvStore& aMsvStore) const;
       
   166 	IMPORT_C void RestoreL(const TFileName& aFileName);
       
   167 	IMPORT_C void StoreL(const TFileName& aFileName) const;
       
   168 	IMPORT_C void ResetL();
       
   169 	
       
   170 protected:
       
   171 //	Parsing:
       
   172 	IMPORT_C void UnfoldMessageL();
       
   173 
       
   174 //	Streaming operations:
       
   175 	void InternalizeL(RMsvReadStream& aStream);
       
   176 	void ExternalizeL(RMsvWriteStream& aStream) const;
       
   177 
       
   178 protected:
       
   179 	/** Object that loaded the parser. It contains a reference counter of the use of 
       
   180 	the parser. */
       
   181 	CRegisteredParserDll&		iRegisteredParserDll;
       
   182 	/** The message entry the parser should parse. */
       
   183 	CMsvEntry&					iEntry;
       
   184 	/** Connected file server handle. */
       
   185 	RFs&						iFs;
       
   186 
       
   187 	/** Lexer intended for Smart Message use.
       
   188 	
       
   189 	This is not used by the base class. */
       
   190 	TLex						iSms;
       
   191 	/** Array of token-value pairs.
       
   192 	
       
   193 	Derived classes can use this for storing parsed information (if this is appropriate). */
       
   194 	CArrayPtrSeg<CParsedField>* iParsedFieldArray;
       
   195 
       
   196 	/** Flag intended for Smart Message use.
       
   197 	
       
   198 	This is not used by the base class. */
       
   199 	TBool						iSmsParsed;
       
   200 	/** ID of iEntry. */
       
   201 	TMsvId						iEntryId;
       
   202 	
       
   203 	/** Pointer to message data.
       
   204 	
       
   205 	This is not set by the base class. */
       
   206 	HBufC*						iSettings;
       
   207 	/** Pointer to SMS data (intended for Smart Message use).
       
   208 	
       
   209 	This is not set by the base class. */
       
   210     HBufC*						iSmsBuf;                // Local copy of buffer passed to ParseL()
       
   211 	/** Temporary pointer used by RestoreL(). */
       
   212 	HBufC8*						iReadBuffer;			// used to restore data from file
       
   213 	};
       
   214 
       
   215  
       
   216 /** BIO data location flag values.
       
   217 
       
   218 @see TMsvBIOEntry */
       
   219 enum TMsvBIODataLocation
       
   220 	{
       
   221 	/** Unknown. */
       
   222 	EUnknown,
       
   223 	/** Parser wrote data into the body text. */
       
   224 	EBodyText,		// parser wrote data back into richText
       
   225 	/** Parser wrote data into the parsed fields data stream. */
       
   226 	EBIODataStream,	// parser wrote data into KUIDMsvBioStream
       
   227 	/** Parser wrote data into an attachment file. */
       
   228 	EFile			// parser wrote data into attachment file
       
   229 	};
       
   230 
       
   231 
       
   232 /** Bearer Independent Object entry.
       
   233 Specialises the TMsvEntry message entry class to store additional BIO message-specific 
       
   234 information. 
       
   235 @internalTechnology
       
   236 @released
       
   237 */
       
   238 class TMsvBIOEntry : public TMsvEntry
       
   239 	{
       
   240 public:
       
   241 	/** Constructor. */
       
   242 	TMsvBIOEntry() : TMsvEntry() {};
       
   243 	void SetBIOParserUid(const TUid aId);
       
   244 	const TUid BIOParserUid() const;
       
   245 	void SetLocationOfData(const TMsvBIODataLocation aLocation);
       
   246 	const TMsvBIODataLocation LocationOfData() const;
       
   247 
       
   248 private:
       
   249 	TMsvBIODataLocation	iLocationOfData;
       
   250 	};
       
   251 
       
   252 #include <bsp.inl>
       
   253 
       
   254 #endif