|
1 // Copyright (c) 2003-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 // Name : SIPInviteClientTransaction.cpp |
|
15 // Part of : SIPAPI |
|
16 // Version : SIP/5.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sip.h" |
|
22 #include "SipAssert.h" |
|
23 #include "transactionassociation.h" |
|
24 #include "sipinviteclienttransaction.h" |
|
25 #include "sipstrings.h" |
|
26 #include "sipstrconsts.h" |
|
27 |
|
28 |
|
29 #ifdef CPPUNIT_TEST |
|
30 |
|
31 #include "TestCleanupStack.h" |
|
32 |
|
33 #undef EXPORT_C |
|
34 #define EXPORT_C |
|
35 |
|
36 #endif |
|
37 |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CSIPInviteClientTransaction::NewL |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CSIPInviteClientTransaction* |
|
44 CSIPInviteClientTransaction::NewL(MTransactionAssociation& aAssociation) |
|
45 { |
|
46 CSIPInviteClientTransaction* self = |
|
47 CSIPInviteClientTransaction::NewLC(aAssociation); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CSIPInviteClientTransaction::NewLC |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CSIPInviteClientTransaction* |
|
57 CSIPInviteClientTransaction::NewLC(MTransactionAssociation& aAssociation) |
|
58 { |
|
59 CSIPInviteClientTransaction* self = |
|
60 new (ELeave) CSIPInviteClientTransaction(aAssociation); |
|
61 CleanupStack::PushL(self); |
|
62 self->ConstructL(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CSIPInviteClientTransaction::CSIPInviteClientTransaction |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CSIPInviteClientTransaction::CSIPInviteClientTransaction( |
|
71 MTransactionAssociation& aAssociation) : |
|
72 CSIPClientTransaction(aAssociation, NULL) |
|
73 #ifdef CPPUNIT_TEST |
|
74 , iAssociationArray(1) |
|
75 #endif |
|
76 { |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CSIPInviteClientTransaction::ConstructL |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CSIPInviteClientTransaction::ConstructL() |
|
84 { |
|
85 iAssociationArray.AppendL(iAssociation); |
|
86 |
|
87 CSIPTransactionBase::ConstructL(SIPStrings::StringF(SipStrConsts::EInvite)); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CSIPInviteClientTransaction::~CSIPInviteClientTransaction |
|
92 // RemoveTransaction event is sent to all associations. |
|
93 // CSIPTransactionBase::iAssociation is set to NULL to prevent |
|
94 // ~CSIPTransactionBase() from also sending RemoveTransaction. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C CSIPInviteClientTransaction::~CSIPInviteClientTransaction() |
|
98 { |
|
99 for (TInt i = 0; i < iAssociationArray.Count(); i++) |
|
100 { |
|
101 iAssociationArray[i]->RemoveTransaction(*this); |
|
102 } |
|
103 iAssociationArray.Reset(); |
|
104 |
|
105 iAssociation = NULL; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CSIPInviteClientTransaction::CancelAllowed |
|
110 // It is possible to cancel an INVITE client transaction, though it can be done |
|
111 // only in "proceeding state". This method just indicates whether canceling is |
|
112 // possible at all, and does not check the current state. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 EXPORT_C TBool CSIPInviteClientTransaction::CancelAllowed() const |
|
116 { |
|
117 return ETrue; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CSIPInviteClientTransaction::Detach |
|
122 // iAssociation is set to NULL when the last association is detached. Until that |
|
123 // happens it is set point one of the associations (does not matter which one). |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CSIPInviteClientTransaction::Detach( |
|
127 const MTransactionAssociation& aAssociation) |
|
128 { |
|
129 TInt pos = iAssociationArray.Find(&aAssociation); |
|
130 |
|
131 __ASSERT_DEBUG(pos != KErrNotFound, |
|
132 User::Panic(_L("CSIPInviteClientTransaction::Detach() not found"), |
|
133 KErrNotFound)); |
|
134 |
|
135 if (pos != KErrNotFound) |
|
136 { |
|
137 iAssociationArray.Remove(pos); |
|
138 } |
|
139 |
|
140 if (iAssociationArray.Count() > 0) |
|
141 { |
|
142 iAssociation = iAssociationArray[0]; |
|
143 } |
|
144 else |
|
145 { |
|
146 iAssociation = NULL; |
|
147 } |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CSIPInviteClientTransaction::AddAssociationL |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CSIPInviteClientTransaction::AddAssociationL( |
|
155 MTransactionAssociation& aAssociation) |
|
156 { |
|
157 __ASSERT_ALWAYS(iAssociationArray.Find(&aAssociation) == KErrNotFound, |
|
158 User::Leave(KErrAlreadyExists)); |
|
159 |
|
160 aAssociation.AddTransactionL(*this); |
|
161 |
|
162 TInt err = iAssociationArray.Append(&aAssociation); |
|
163 if (err != KErrNone) |
|
164 { |
|
165 aAssociation.RemoveTransaction(*this); |
|
166 User::Leave(err); |
|
167 } |
|
168 } |