smsprotocols/smsstack/smsprot/Inc/smsprot.h
changeset 0 3553901f7fa8
child 5 7ef16719d8cb
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 1999-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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Declares the CSmsProtocol, CSmsProtocolFamily, CSmsProvider and
       
    15 // other classes used internally by them.
       
    16 // Conditional includes
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalAll
       
    23 */
       
    24 
       
    25 #ifndef SMSPROT_H
       
    26 #define SMSPROT_H
       
    27 
       
    28 #include <es_sock.h>
       
    29 #include <es_prot.h>
       
    30 #include <etelmm.h>
       
    31 #include <es_ini.h>
       
    32 #include <mmlist.h>
       
    33 #include <cdblen.h>
       
    34 
       
    35 #include "smsuset.h"
       
    36 #include "smsuaddr.H"
       
    37 #include "smspcomm.h"
       
    38 #include "smspproc.h"
       
    39 #include "nbbackuprestoreint.h"
       
    40 
       
    41 class CSmsProvider;
       
    42 class CFacadeSmsReassemblyStore;
       
    43 class CSmsSegmentationStore;
       
    44 class CLogWrapper;
       
    45 class CSmsModemNotification;
       
    46 class CSmsPDURead;
       
    47 class CSmsPhoneEnumeration;
       
    48 class CSmsMessageWrite;
       
    49 class CSmsPDUDelete;
       
    50 class CSmsReadParams;
       
    51 class CSmsWriteParams;
       
    52 class CSmspWriteQueue;
       
    53 class CQueuedSmsMessage;
       
    54 class CSmspDeleteQueue;
       
    55 class CSmspSendQueue;
       
    56 class CSmsPhoneInitialization;
       
    57 class CSmsProtocolBootTimer;
       
    58 class CBackupAndRestore;
       
    59 class CSmspSetBearer;
       
    60 
       
    61 /**
       
    62  *  CProtocolFamilyBase derived class which identifies the protocols
       
    63  *  we can create, and provides an overidden factory method for
       
    64  *  creating them.
       
    65  *  @internalComponent
       
    66  */
       
    67 class CSmsProtocolFamily : public CProtocolFamilyBase
       
    68     {
       
    69 public:
       
    70     static CSmsProtocolFamily * NewL();
       
    71     TInt Install();
       
    72     TInt Remove();
       
    73     CProtocolBase * NewProtocolL(TUint aSockType,TUint aProtocol);
       
    74     TUint ProtocolList(TServerProtocolDesc *& aProtocolList);
       
    75 private:
       
    76     CSmsProtocolFamily();
       
    77     };
       
    78 
       
    79 /**
       
    80  *  @internalComponent
       
    81  */
       
    82 IMPORT_C CProtocolFamilyBase* InstallSMS();	// Force export
       
    83 
       
    84 /**
       
    85  *  The main class for this protocol which handles requests
       
    86  *  from clients contending for services from the phone.
       
    87  *  @internalComponent
       
    88  */
       
    89 class CSmsProtocol : public CProtocolBase,
       
    90                      public MSmsComm, 
       
    91                      public MNBBackupAndRestoreObserver
       
    92 	{
       
    93 friend class CSmsProvider;
       
    94 
       
    95 public:
       
    96     static CSmsProtocol *NewL();
       
    97     virtual ~CSmsProtocol();
       
    98 
       
    99 // Calls from the socket server which we implement
       
   100     CServProviderBase *NewSAPL(TUint aSocketType);
       
   101     void InitL(TDesC& aTag);
       
   102     void StartL(void);
       
   103     void Identify(TServerProtocolDesc *)const;
       
   104     
       
   105 // Calls from the socket server which we don't implement
       
   106     virtual CHostResolvProvdBase *NewHostResolverL();
       
   107     virtual CServiceResolvProvdBase *NewServiceResolverL();
       
   108     virtual CNetDBProvdBase* NewNetDatabaseL();
       
   109 
       
   110 // Calls from the socket server and other protocols which we just panic
       
   111     void BindL(CProtocolBase *aProtocol, TUint aId);
       
   112     virtual void BindToL(CProtocolBase *aProtocol);
       
   113     TInt Send(TDes8& aDes, TSockAddr *aTo,TSockAddr *aFrom,CProtocolBase* aSourceProtocol);
       
   114     void Process(TDes8& aDes,TSockAddr *aFrom,TSockAddr *to,CProtocolBase* aSourceProtocol);
       
   115     TInt GetOption(TUint aLevel,TUint aName,TDes8 &aOption,CProtocolBase* aSourceProtocol);
       
   116     TInt SetOption(TUint aLevel,TUint aName,const TDesC8& aOption,CProtocolBase* aSourceProtocol);
       
   117     void Error(TInt aError,CProtocolBase* aSourceProtocol);
       
   118 
       
   119 // Functions called for WAP binding or for SAP creation
       
   120     virtual void AddSmsMessageObserverL(MSmsMessageObserver& aObserver);
       
   121     virtual TInt BindSmsMessageObserver(MSmsMessageObserver& aObserver,const TSmsAddr& aSmsAddr);
       
   122     virtual void RemoveSmsMessageObserver(const MSmsMessageObserver& aObserver);
       
   123     virtual TBool SmsAddrIsAlreadyUsed(const MSmsMessageObserver* aObserver,const TSmsAddr& aSmsAddr)const;
       
   124 
       
   125 // Functions called by SAPs (e.g. WAPPROT)
       
   126     virtual void SendSmsMessage(CSmsMessage* aSmsMessage,MSmsMessageObserver& aObserver,TUint aOptions);
       
   127     virtual void CancelSendSmsMessage(MSmsMessageObserver& aObserver,TBool aCancelInternally=ETrue);
       
   128     virtual void EnumeratePhone(MSmsMessageObserver& aObserver);
       
   129     virtual void CancelEnumeratePhone(MSmsMessageObserver& aObserver);
       
   130     
       
   131     void WriteSmsMessage(CSmsMessage* aSmsMessage,MSmsMessageObserver& aObserver);
       
   132     void CancelWriteSmsMessage(MSmsMessageObserver& aObserver);
       
   133     
       
   134     virtual void DeleteSmsMessage(CSmsMessage* aSmsMessage,MSmsMessageObserver& aObserver);
       
   135     virtual void CancelDeleteSmsMessage(MSmsMessageObserver& aObserver);
       
   136     virtual void ReadSmsParameters(MSmsMessageObserver& aObserver);
       
   137     virtual void CancelReadSmsParams();
       
   138     virtual void WriteSmsParameters(CMobilePhoneSmspList* aMobilePhoneSmspList, MSmsMessageObserver& aObserver);
       
   139     virtual void CancelWriteSmsParams();
       
   140 
       
   141 // MSmsComm Notifications used by active objects
       
   142     TInt ProcessMessageL(const CSmsMessage& aSmsMessage,const TSmsAddr* aOriginalSmsAddr,const CSmsMessage* aOriginalSmsMessage,TDes& aDes);
       
   143     void DeletePDUs(const CArrayFix<TGsmSmsSlotEntry>& aSlotArray, MSmsMessageObserver* aObserver);
       
   144     void ModemNotificationCompleted(TInt aStatus,RPhone::TModemDetection aNewState);
       
   145     void DiskSpaceMonitorStateChange(TSmsDiskSpaceMonitorStatus aStatus);
       
   146     void MessageSendCompleted(TInt aStatus);
       
   147     void PhoneEnumerationCompleted(TInt aStatus);
       
   148 
       
   149 	inline RFs& FileSession();
       
   150 	inline virtual TBool ObserverIsPresent(const MSmsMessageObserver& aObserver) const;
       
   151 	const RMobilePhone::TMobilePhoneNetworkInfoV1& NetworkInfo() const;
       
   152     TBool NetworkInfoAvailable() const;
       
   153     // new function which deletes msg from the reassemblystore
       
   154     // by passing them the smsmessage class
       
   155     void DeleteSMSFromReaStoreL(const CSmsMessage& aSmsMessage);
       
   156     void MessageReadedSuccessfully();
       
   157     TBool AllocateLocalAddress(TSmsAddr& aAddr);
       
   158     TInt ExternalizeEnumeratedMessagesL(CSmsProvider& aProvider,TInt& aCount);
       
   159     static TBool IsAppPortSMS(const CSmsMessage& aSmsMessage);
       
   160 
       
   161 protected:
       
   162     void CloseNow();
       
   163 
       
   164 private:
       
   165     CSmsProtocol();
       
   166     
       
   167     TInt ObserverIndex(const MSmsMessageObserver& aObserver) const;
       
   168     void OrderSmsMessageObserver(const MSmsMessageObserver& aObserver);
       
   169     
       
   170     MSmsMessageObserver* MatchSmsAddressToObserver(const TSmsAddr& aAddr);
       
   171     MSmsMessageObserver* MatchSmsMessageToObserver(const CSmsMessage& aSmsMessage);
       
   172     static TBool IsMatch(const TSmsAddr& aSmsAddr, const CSmsMessage& aSmsMessage);
       
   173     static TBool MatchInformationElement(const CSmsMessage& aSmsMessage, CSmsInformationElement::TSmsInformationElementIdentifier aIeVal);
       
   174     void MatchCompleteSmsMessagesToObserverL(MSmsMessageObserver& aObserver,CArrayFix<TInt>& aIndexArray);
       
   175     static TBool MatchApplicationPort(const CSmsMessage& aSmsMessage,TUint aPort,TBool a16Bit);
       
   176     
       
   177     void NotifyMessageObservers(TInt aStatus);
       
   178 
       
   179  	// TODO - flag
       
   180 	TBool IsWapSMS(const CSmsMessage& smsmessage );
       
   181 
       
   182     inline TBool ClosingDown() const;
       
   183     inline void SetClosingDown(TBool aClosingDown);
       
   184     void CloseNowWrap();
       
   185     
       
   186     void PowerUp();			// Handles modem turning on or backup finishing
       
   187     void DoPowerUpL();
       
   188     void PowerDown();		// Handles modem turning off or backup starting
       
   189     void ProcessCompleteSmsMessagesL();
       
   190     TInt CheckPoweredUp() const;
       
   191     virtual void HandleBackupOrRestoreStartingL();
       
   192     virtual void HandleBackupOrRestoreCompleteL();
       
   193     void ReadConfigurableSettingsL(); // from smswap.sms.esk -> [customTimeoutSettings]
       
   194 
       
   195 private:
       
   196     ///< Enumerated flag values for states of the protocol
       
   197     enum TSmsProtocolFlags
       
   198         {
       
   199         ESmsProtocolClosingDown=0x01			///< In the process of shutting down
       
   200         };
       
   201     enum
       
   202         {
       
   203         KNumSARStoreAccessesBeforePurging=8	///< Number of accesses to the segmentation & reassembly stores before purging
       
   204         };
       
   205     
       
   206     enum TSmsProtocolState
       
   207         {
       
   208         EPoweredDown,	///< SmsProt is not initialised and the phone is not swiched on
       
   209         EPoweredUp		///< SmsProt is powered up, phone switched on, ready for action
       
   210         } iState;
       
   211 
       
   212 private:
       
   213     CArrayPtrFlat<MSmsMessageObserver> iSmsMessageObserverList;	///< List of current observers
       
   214 
       
   215     RTelServer iTelServer;                              ///< A session with the telephony server
       
   216     TBuf<KCommsDbSvrMaxFieldLength> iGsmTsyName;        ///< Name of the TSY
       
   217     RMobilePhone iGsmPhone;                             ///< ETEL phone subsession for intialisation and detection events
       
   218     RMobilePhone iEnumerationPhone;                     ///< ETEL phone subsession for enumerating the phone
       
   219     RMobilePhone iWritePhone;                           ///< ETEL phone subsession for writing messages
       
   220     RMobileSmsMessaging iSmsMessaging;                  ///< ETEL phone subsession for advanced messaging services
       
   221 
       
   222     TSmsSettings iSmsSettings;                          ///< Global SMS Protocol settings
       
   223     RMobileSmsMessaging::TMobileSmsCapsV1 iMobileSmsCaps;   // SMS messaging capabilities of the phone
       
   224     
       
   225     TInt iFlags;										///< Flags indicating current state of the protocol
       
   226     
       
   227     RFs iFs;                                            ///< A session with the file server
       
   228     CFacadeSmsReassemblyStore* iReassemblyStore;        ///< Pointer to the reassembly store
       
   229     TInt iNumReassemblyStoreAccesses;                   ///< Counter for number of accesses to the reassembly store
       
   230     CSmsSegmentationStore* iSegmentationStore;          ///< Pointer to the segmentation store
       
   231     TInt iNumSegmentationStoreAccesses;                 ///< Counter for number of accesses to the segmentation store
       
   232     CSmsModemNotification* iSmsModemNotification;		///< Pointer to object for handling modem detection events
       
   233     RPhone::TModemDetection iModemDetection;			///< The current modem detection state
       
   234     
       
   235 
       
   236     CSmsPDURead* iSmsPDURead;                           ///< Pointer to object for receiving SMS PDUs from ETEL
       
   237 
       
   238     CSmsMonitorDiskSpace* iSmsMonitorDiskSpace;         ///< Pointer to object for monitoring of disk space
       
   239     
       
   240     MSmsMessageObserver*    iPhoneEnumerationObserver;  ///< Pointer to the observer of any current enumeration
       
   241     CSmsPhoneEnumeration*   iSmsPhoneEnumeration;       ///< Pointer to object for enumerating messages on the phone
       
   242     
       
   243     CSmspSendQueue*     iSendQueue;                     ///< Queue of messages to send
       
   244     CSmspWriteQueue*    iWriteQueue;                    ///< Pointer to object for writing messages to the phone
       
   245     CSmspDeleteQueue*   iDeleteQueue;                   ///< Queue of PDUs to delete
       
   246     
       
   247     CSmsReadParams*    iSmsReadParams;                  ///< Pointer to object for reading SMS parameters
       
   248     CSmsWriteParams*   iSmsWriteParams;                 ///< Pointer to object for writing SMS parameters
       
   249     
       
   250     CSmsPhoneInitialization*   iSmsPhoneInitialization;
       
   251     CBackupAndRestore*         iBackupRestoreSession;
       
   252     CSmspSetBearer*            iSetBearer;              ///< Pointer to bearer object, used by message sender but cancelled from protocol
       
   253     CSmspReceiveMode*          iReceiveMode;            ///< Pointer to receive mode object, used by PDU reader but cancelled from protocol
       
   254     
       
   255     TInt iNext8BitPort;
       
   256     TInt iNext16BitPort;
       
   257     CSmsProtocolBootTimer*  iBootTimer;                 ///< Pointer to the CSmsProtocolBootTimer object
       
   258     };
       
   259 
       
   260 /**
       
   261  *  A CServProviderBase derived class providing service access points to the
       
   262  *  SMS Protocol.
       
   263  *  @internalComponent
       
   264  */
       
   265 class CSmsProvider : public CServProviderBase, public MSmsMessageObserver
       
   266 	{
       
   267 public:
       
   268     static CSmsProvider* NewL(CSmsProtocol& aProtocol);
       
   269     virtual ~CSmsProvider();
       
   270 public:
       
   271 // pure virtuals from CServProviderBase
       
   272     void Start();
       
   273     void LocalName(TSockAddr& aAddr) const;
       
   274     TInt SetLocalName(TSockAddr& aAddr);
       
   275     void RemName(TSockAddr& aAddr) const;
       
   276     TInt SetRemName(TSockAddr& aAddr);
       
   277     TInt GetOption(TUint aLevel,TUint aName,TDes8& aOption) const;
       
   278     void Ioctl(TUint aLevel,TUint aName,TDes8* aOption);
       
   279     void CancelIoctl(TUint aLevel,TUint aName);
       
   280     TInt SetOption(TUint aLevel,TUint aName,const TDesC8 &aOption);
       
   281     TInt Write(RMBufChain& aBufChain, TUint aOptions, TSockAddr* aAddr=NULL);
       
   282     TInt GetData(RMBufChain& aBufChain, TUint aLength, TUint aOptions, TSockAddr* aAddr=NULL);
       
   283     void ActiveOpen();
       
   284     void ActiveOpen(const TDesC8& aConnectionData);
       
   285     TInt PassiveOpen(TUint aQueSize);
       
   286     TInt PassiveOpen(TUint aQueSize,const TDesC8& aConnectionData);
       
   287     void Shutdown(TCloseType aOption);
       
   288     void Shutdown(TCloseType aOption,const TDesC8& aDisconnectionData);
       
   289     void AutoBind();
       
   290 
       
   291 //  From MSmsMessageObserver
       
   292     const TSmsAddr& GetLocalAddress() const;
       
   293     void SetLocalAddress(const TSmsAddr& aSmsAddr);
       
   294     void ModemNotificationCompleted(TInt aStatus);
       
   295     void MessageSendCompleted(TInt aStatus);  //  aStatus is EPOC error or -(KFailureCauseOffset+failurecause)
       
   296     TInt MessageReceived(const CSmsMessage& aSmsMessage,TDes& aDes);  //  must return EPOC error or -(KFailureCauseOffset+failurecause)
       
   297     void EnumeratePhoneCompleted(TInt aStatus);
       
   298     void MessageWriteCompleted(TInt aStatus, const CSmsMessage* aSmsMessage = NULL);
       
   299     void MessageDeleteCompleted(TInt aStatus);
       
   300     void ReadSmsParamsCompleted(TInt aStatus,CMobilePhoneSmspList* aSmspList);
       
   301     void WriteSmsParamsCompleted(TInt aStatus);
       
   302     virtual TBool ClientConfirmsMessage()const;
       
   303     virtual TBool SmsAddrIsDuplicate(const MSmsMessageObserver* aObserver,const TSmsAddr& aAddr)const;
       
   304     TInt ExternalizeEnumeratedMessagesL(TInt& aCount);
       
   305     TInt ExternalizeMessageL(const CSmsMessage& aSmsMessage,TBool aAppend);
       
   306 
       
   307 protected:
       
   308     CSmsProvider(CSmsProtocol& aProtocol);
       
   309     virtual TInt SecurityCheck(MProvdSecurityChecker* aSecurityChecker);
       
   310     void ConstructL();
       
   311 
       
   312 private:
       
   313     TInt DoMessageReceivedL(const CSmsMessage& aSmsMessage);
       
   314     inline static TInt NumSegments(TInt aSize);
       
   315     void DoWriteL(const TDesC8& aData,TUint aOptions);
       
   316     TInt ExternalizeEnumeratedMesagesL(TInt& aCount);
       
   317     CSmsMessage* InternalizeMessageL();
       
   318     TInt ExternalizeParametersL(const CMobilePhoneSmspList& aMobilePhoneSmspList);
       
   319     CMobilePhoneSmspList* InternalizeParametersL();
       
   320     
       
   321     inline TBool ObserverAddedToProtocol() const;
       
   322     inline void SetObserverAddedToProtocol(TBool aAdded);
       
   323     inline TBool IoctlOutstanding() const;
       
   324     inline void SetIoctlOutstanding(TBool aOutstanding);
       
   325     CSmsMessage* InternalizeMessageL(	CBufSeg* aBufSeg);
       
   326     void PopulateBufferWithPDUSlotsL(const CSmsMessage& aSmsMessage);
       
   327     
       
   328 private:
       
   329     ///< Enumerated flag values for current of the provider
       
   330     enum TSmsProviderFlags
       
   331         {
       
   332         ESmsProviderObserverAddedToProtocol=0x01,   ///< Registered as observer of the protocol
       
   333         ESmsProviderIoctlOutstanding=0x02           ///< Special SMS ioctl is outstanding
       
   334         };
       
   335 
       
   336 private:
       
   337     CSmsProtocol& iProtocol;                    ///< Reference to the SMS Protocol object
       
   338     TSmsAddr iLocalAddress;                     ///< The local address of the access point
       
   339     TInt iFlags;                                ///< Flags indicating current state of the provider
       
   340     CArrayPtr<CBufSeg>* iRecvBufSegArray;       ///< Array of serialized SMS messages to be read from the socket
       
   341     TInt iSegmentIndex;                         ///< Index of next segment of current SMS message to read
       
   342     CBufSeg* iSendBufSeg;                       ///< SMS message segments written to the socket
       
   343     TUint iName;                                ///< The integer "name" of the current ioctl request
       
   344     TBool iEnumSocket;                          ///< this is enumeration client
       
   345     TInt iNumOfEnumeratedMessages;              ///< number of enumerated segments
       
   346     MProvdSecurityChecker* iSecurityChecker;    ///< ESOCK security checker object
       
   347     };
       
   348 
       
   349 #include "smsprot.inl"
       
   350 
       
   351 /**
       
   352  *  @internalComponent
       
   353  */
       
   354 class CSmsProtocolBootTimer : public CTimer
       
   355 	{
       
   356 public:
       
   357     static CSmsProtocolBootTimer* NewL(CSmsProtocol& aSmsProtocol);
       
   358     virtual ~CSmsProtocolBootTimer();
       
   359 
       
   360     void Start(const TTimeIntervalMicroSeconds32& aTimeIntervalMicroSeconds32);
       
   361 
       
   362 private:
       
   363     CSmsProtocolBootTimer(CSmsProtocol& aSmsProtocol);
       
   364     virtual void RunL();
       
   365 
       
   366 protected:
       
   367     CSmsProtocol& iSmsProtocol;         ///< reference to owner CSmsProtocol object
       
   368     };
       
   369 
       
   370 #endif // SMSPROT_H