2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * 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
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
16 * Part of : SIP Client
17 * Interface : SDK API, SIP Client API
30 #include <stringpool.h>
31 #include "_sipcodecdefs.h"
33 // FORWARD DECLARATIONS
34 class CSIPClientTransaction;
35 class CSIPMessageElements;
36 class MSIPRefreshAssociation;
44 * Class for managing SIP refresh.
45 * It provides functions for getting associated sip transaction
46 * and state. Class also provides functions for updating and terminating
47 * stand-alone refreshes.
49 * Note that only stand-alone refreshes (i.e. refreshes that are not associated
50 * with registration binding or dialog associations) can be terminated or
51 * updated using functions defined in this class.
55 class CSIPRefresh: public CBase
59 /** SIP refresh states */
62 /** SIP refresh is inactive */
64 /** SIP refresh active */
66 /** SIP refresh is terminated */
68 /** Object is being constructed and is not yet ready for use */
72 public: // Constructors and destructor
75 * Two-phased constructor
76 * @return New object. Ownership is transferred.
78 IMPORT_C static CSIPRefresh* NewL();
81 * Two-phased constructor
82 * @return New object. Ownership is transferred.
84 IMPORT_C static CSIPRefresh* NewLC();
89 IMPORT_C ~CSIPRefresh();
91 public: // New functions
94 * Gets the state of the refresh
95 * @return refresh state
97 IMPORT_C CSIPRefresh::TState State() const;
100 * Tests if the refresh is a stand-alone refresh
101 * @return ETrue if refresh is a stand-alone; EFalse otherwise
103 IMPORT_C TBool IsStandAlone() const;
106 * Gets the associated SIP transaction with this refresh.
108 * @return Associated SIP transaction or 0-pointer. Ownership is not
111 IMPORT_C const CSIPClientTransaction* SIPTransaction() const;
114 * Terminates the refresh by sending SIP request to the remote
115 * destination. The new client transactation will be of the same type
116 * as the first transaction associated with this request.
117 * @pre State()==EActive
118 * @pre IsStandAlone()==ETrue
119 * @param aElements contains optional SIP message headers and body.
120 * Ownership is transferred.
121 * @return SIP client transaction. Ownership is transferred.
122 * @leave KErrSIPInvalidTransactionState if State() is not EActive
123 * KErrNotFound if the CSIPRefresh is no longer associated to
125 * KSIPErrInvalidRegistrationState if trying to terminate a
127 * KErrSIPInvalidDialogState if trying to terminate a dialog
128 * association being refreshed.
129 * @capability NetworkServices
131 IMPORT_C CSIPClientTransaction*
132 TerminateL(CSIPMessageElements* aElements=0);
135 * Updates the refresh by sending SIP request to the remote destination.
136 * The new client transactation will be of the same type as the first
137 * transaction associated with this request.
138 * @pre State()==EActive
139 * @pre IsStandAlone()==ETrue
140 * @param aElements contains optional SIP message headers and body.
141 * Ownership is transferred.
142 * @return SIP client transaction. Ownership is transferred.
143 * @leave KErrSIPInvalidTransactionState if State() is not EActive
144 * KErrNotFound if the CSIPRefresh is no longer associated to
146 * KErrSIPInvalidRegistrationState if trying to update a
148 * KSIPErrInvalidDialogState if trying to update a
149 * dialog association being refreshed.
150 * @capability NetworkServices
152 IMPORT_C CSIPClientTransaction*
153 UpdateL(CSIPMessageElements* aElements=0);
156 * Compares this object to another object
157 * @param aRefresh a CSIPRefresh type object to compare
158 * @return ETrue if the objects are equal otherwise EFalse
160 IMPORT_C TBool operator==(const CSIPRefresh& aRefresh) const;
163 * Gets current refresh interval
164 * @pre State()==CSIPRefresh::EActive
165 * @return current refresh interval in seconds
166 * @leave KErrSIPInvalidTransactionState if State() is not EActive
167 * @leave KErrSIPResourceNotAvailable if SIP server can't be contacted
168 * because a required resource has been deleted.
170 IMPORT_C TUint IntervalL() const;
173 * Sets refresh interval.
174 * Note that SIP server choses the refresh interval. This function should
175 * be used only if SIP server has indicated new refresh interval using
176 * SIP messages that are not associated to the refresh needing the update.
177 * @pre State()==CSIPRefresh::EActive
179 * @param aInterval a new interval in seconds
180 * @leave KErrArgument if aInterval == 0
181 * @leave KErrSIPInvalidTransactionState if State() is not EActive
182 * @leave KErrSIPResourceNotAvailable if SIP server can't be contacted
183 * because a required resource has been deleted.
185 IMPORT_C void SetIntervalL(TUint aInterval);
187 public: // New functions, for internal use
189 TBool DoesMatch(TUint32 aRefreshId) const;
192 * Associate the CSIPRefresh with another object.
193 * @param aAssoc Object associated with the CSIPRefresh
194 * @return ETrue if the objects are equal otherwise EFalse
196 void SetRefreshOwner(MSIPRefreshAssociation& aAssoc);
198 void RemoveRefreshOwner(const MSIPRefreshAssociation& aAssoc);
200 void ChangeState(CSIPRefresh::TState aNextState);
202 void UpdateRefreshState(TUint aStatusCode);
204 TUint32 RefreshId() const;
206 void SetRefreshIdIfEmpty(TUint32 aRefreshId);
208 RStringF RequestType() const;
210 void SetRequestType(RStringF aType);
212 void AddTransaction(CSIPClientTransaction& aTransaction);
214 void RemoveTransaction();
216 CSIPClientTransaction* Transaction();
218 private: // Constructors
226 void CheckStateL() const;
230 MSIPRefreshAssociation* iOwner;
232 //Client transaction which is refreshed, not owned by CSIPRefresh.
233 CSIPClientTransaction* iClientTransaction;
235 //Current state of the refresh
238 //RefreshId received from SIP client
241 //Identifies the request method which is being refreshed
242 RStringF iRequestType;
244 private: // For testing purposes
247 UNIT_TEST(CSIPConnection_Test)