williamr@2: /*
williamr@2: * Copyright (c) 2009 Sony Ericsson Mobile Communications AB
williamr@2: * All rights reserved.
williamr@2: * This component and the accompanying materials are made available
williamr@2: * 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: * which accompanies this distribution, and is available
williamr@2: * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2: *
williamr@2: * Initial Contributors:
williamr@2: * Sony Ericsson Mobile Communications AB - initial contribution.
williamr@2: * Nokia Corporation - additional changes.
williamr@2: * 
williamr@2: * Contributors:
williamr@2: * 
williamr@2: * Description:
williamr@2: * Provides the base class for CEmsInformationElements and a factory with which
williamr@2: * to create Ems Elements.
williamr@2: *
williamr@2: */
williamr@2: 
williamr@2: 
williamr@2: /**
williamr@2:  *  @file
williamr@2:  *  
williamr@2:  *  Defines  CEmsInformationElement  class
williamr@2:  */
williamr@2: 
williamr@2: 
williamr@2: #ifndef __EMSInformationElement__
williamr@2: #define __EMSInformationElement__
williamr@2: 
williamr@2: #include <gsmuelem.h>
williamr@2: 
williamr@2: /**
williamr@2:  *  @internalComponent
williamr@2:  */
williamr@2: #define SHIFT_BOOL_LEFT(a,x) ((TUint8) ((a ? 1 : 0) <<x))
williamr@2: /**
williamr@2:  *  @internalComponent
williamr@2:  */
williamr@2: #define BOOL_AT(a,x)		 ((TBool) ((a >> x) & 0x01))
williamr@2: 
williamr@2: /**
williamr@2:  *  @internalComponent
williamr@2:  */
williamr@2: #define HI_BYTE(a)	(TUint8) ((a&0xFF00) >> 8)
williamr@2: /**
williamr@2:  *  @internalComponent
williamr@2:  */
williamr@2: #define LO_BYTE(a)	(TUint8) (a&0x00FF)
williamr@2: 
williamr@2: 
williamr@2: 
williamr@2: class CEmsInformationElement : public CSmsInformationElement
williamr@2: /**
williamr@2:  *  Abstract base class used to allow ems objects to be passed around, and to be
williamr@2:  *  handled as a generic group of objects.
williamr@2:  *  @internalComponent
williamr@2:  */
williamr@2: 	{
williamr@2: 	friend class CEmsFactory;
williamr@2: 
williamr@2: public:
williamr@2: 	// Externally available and exported functions
williamr@2: 	IMPORT_C virtual CEmsInformationElement* DuplicateL() const = 0;
williamr@2: 	IMPORT_C void SetStartPosition(TUint aValue);
williamr@2: 	IMPORT_C TUint StartPosition() const;
williamr@2: 
williamr@2: 	// Length of the generated encoded information element, INCLUDING
williamr@2: 	// the IE header
williamr@2: 	IMPORT_C TInt Length() const;
williamr@2: 
williamr@2: public:
williamr@2: 	// Encodes the CSmsInformationElement part and decodes to from an
williamr@2: 	// external CSmsInformationElement.
williamr@2: 	IMPORT_C void EncodeInformationElementL();
williamr@2: 	static CEmsInformationElement* DecodeInformationElementL(const CSmsInformationElement& aSmsIe);
williamr@2: 
williamr@2: 	// Serialisation operations
williamr@2: 	void ExternalizeL(RWriteStream& aStream) const;
williamr@2: 	static CEmsInformationElement* InternalizeL(RReadStream& aStream);
williamr@2: 
williamr@2: protected:
williamr@2: 	// constructor which takes an ems id and a boolean indicating whether or
williamr@2: 	// not the start position is encoded in the pdu (true by default,
williamr@2: 	// but needs to false for UserPrompt
williamr@2: 	inline CEmsInformationElement(TSmsId aId, TBool aStartPosEncoded = ETrue);
williamr@2: 	void CopyL(const CEmsInformationElement& aSrc);
williamr@2: 
williamr@2: 	// Encodes and decodes the body of an information element, EXCLUDING the
williamr@2: 	// start position. The boolean flag indicates whether or not it is for
williamr@2: 	// serialisation or PDU transmission. This impacts in particular the
williamr@2: 	// EmsFormatIE object, which stores the length in 16-bits if serialised
williamr@2: 	// but only 8-bits when encoded.
williamr@2: 	virtual void EncodeBodyL(TPtr8 aPtr, TBool aIsForSerialisation) const = 0;
williamr@2: 	virtual void DecodeBodyL(const TPtrC8 aPtr, TBool aIsFromSerialisation) = 0;
williamr@2: 
williamr@2: 	// This virtual function returns the length of object body when it is to
williamr@2: 	// be serialised - note that this is generally the same as the encoded
williamr@2: 	// body length, except for the Format object
williamr@2: 	virtual TInt SerialisedBodyLength() const;
williamr@2: 
williamr@2: protected:
williamr@2: 	// The start position in relation to the entire text
williamr@2: 	TUint iStartPosition;
williamr@2: 
williamr@2: 	// Length of the encoded body, EXCLUDING the start position and IE header
williamr@2: 	TUint iEncodedBodyLength;
williamr@2: 
williamr@2: private:
williamr@2: 	// boolean to indicate if the start position needs to be encoded in the
williamr@2: 	// pdu
williamr@2: 	const TBool iStartPosEncoded;
williamr@2: 
williamr@2: protected:
williamr@2: 	// the scope of the following functions of CSmsInformationElement have
williamr@2: 	// been downgraded to protected to prevent them from being used when
williamr@2: 	// accessed as an EMS element. The point of transition from being
williamr@2: 	// a CEmsInformationElement to a CSmsInformation element should occur
williamr@2: 	// in the EncodeInformationElement function
williamr@2: 	using CSmsInformationElement::Data;
williamr@2: 	using CSmsInformationElement::EncodeL;
williamr@2: 	using CSmsInformationElement::DecodeL;
williamr@2: 	};
williamr@2: 
williamr@2: 
williamr@2: class CEmsFactory : public CBase
williamr@2: /**
williamr@2:  *  Factory class used to create an EMS object from the given data.
williamr@2:  *  @internalComponent
williamr@2:  */
williamr@2: 	{
williamr@2: public:
williamr@2: 	static TBool Supported(TSmsId aId);
williamr@2: 
williamr@2: 	// Creates an information element with a given ID
williamr@2: 	static CEmsInformationElement* CreateIeL(TSmsId aId);
williamr@2: 	static void InternalizeL(RPointerArray<CEmsInformationElement>& aObjectStore, RReadStream& aStream);
williamr@2: 	static void ExternalizeL(RPointerArray<CEmsInformationElement>& aObjectStore, RWriteStream& aStream);
williamr@2: 	static CEmsInformationElement* CreateReceivedEmsIEL(const CSmsInformationElement& aIE,TInt aBaseAddr);
williamr@2: 	};
williamr@2: 
williamr@2: #include <emsinformationelement.inl>
williamr@2: #endif // __EMSInformationElement__