|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Class for testing the asynchronous api of CObjectExchange client |
|
20 |
|
21 #include "OsmObexSender.h" |
|
22 #include "ObjectExchangeClient.h" |
|
23 |
|
24 |
|
25 COsmObexSender* COsmObexSender::NewL( MOsmObexSenderObserver& aObserver ) |
|
26 { |
|
27 COsmObexSender* self = NewLC( aObserver ); |
|
28 CleanupStack::Pop(self); |
|
29 return self; |
|
30 } |
|
31 |
|
32 COsmObexSender* COsmObexSender::NewLC( MOsmObexSenderObserver& aObserver ) |
|
33 { |
|
34 COsmObexSender* self = new (ELeave) COsmObexSender( aObserver ); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 return self; |
|
38 } |
|
39 |
|
40 COsmObexSender::COsmObexSender( MOsmObexSenderObserver& aObserver ) : |
|
41 CActive(CActive::EPriorityStandard), |
|
42 iState(EWaitingToConnect), // Set initial state. Waiting for StartL function call |
|
43 iObserver( aObserver ) |
|
44 { |
|
45 CActiveScheduler::Add(this); |
|
46 } |
|
47 |
|
48 void COsmObexSender::ConstructL() |
|
49 { |
|
50 iObexClient = CObjectExchangeClient::NewL(); |
|
51 } |
|
52 |
|
53 |
|
54 COsmObexSender::~COsmObexSender() |
|
55 { |
|
56 Cancel(); |
|
57 |
|
58 delete iObexClient; |
|
59 } |
|
60 |
|
61 void COsmObexSender::DoCancel() |
|
62 { |
|
63 if (iState != EWaitingToConnect && iObexClient) |
|
64 { |
|
65 iObexClient->Cancel(); // NOTE: following could do this? |
|
66 } |
|
67 iState = EWaitingToConnect; // Return to initial state |
|
68 } |
|
69 |
|
70 |
|
71 void COsmObexSender::RunL() |
|
72 { |
|
73 // add proper implementations for these: |
|
74 if( iStatus != KErrNone ) |
|
75 { |
|
76 switch( iState ) |
|
77 { |
|
78 case EWaitingToConnect: |
|
79 iObserver.ObexDisconnected( iStatus.Int(), EWaitingToConnect ); |
|
80 iState = EWaitingToConnect; |
|
81 break; |
|
82 case EConnecting: |
|
83 iObserver.ObexDisconnected( iStatus.Int(), EConnecting ); |
|
84 iState = EWaitingToConnect; |
|
85 break; |
|
86 case ESending: |
|
87 iObserver.ObexDisconnected( iStatus.Int(), ESending ); |
|
88 iState = EWaitingToConnect; |
|
89 break; |
|
90 case EDisconnecting: |
|
91 iObserver.ObexDisconnected( iStatus.Int(), EDisconnecting ); |
|
92 iState = EWaitingToConnect; |
|
93 break; |
|
94 default: |
|
95 // should panic here? |
|
96 break; |
|
97 } |
|
98 } |
|
99 else |
|
100 { |
|
101 switch( iState ) |
|
102 { |
|
103 case EWaitingToConnect: |
|
104 break; |
|
105 case EConnecting: |
|
106 iState = ESending; |
|
107 iObexClient->SendObjectL( iFileName, iStatus ); |
|
108 SetActive(); |
|
109 break; |
|
110 case ESending: |
|
111 iState = EDisconnecting; |
|
112 iObexClient->DisconnectL( iStatus ); |
|
113 SetActive(); |
|
114 break; |
|
115 case EDisconnecting: |
|
116 iState = EWaitingToConnect; |
|
117 iObserver.ObexFileSent(); |
|
118 // Sent successfully |
|
119 break; |
|
120 default: |
|
121 // should panic here? |
|
122 break; |
|
123 }; |
|
124 } |
|
125 } |
|
126 |
|
127 |
|
128 |
|
129 void COsmObexSender::SendFileL( TOsmConnectionType aConnectionType, const TDesC& aFileName ) |
|
130 { |
|
131 iFileName.Copy( aFileName ); |
|
132 |
|
133 if (iState == EWaitingToConnect) |
|
134 { |
|
135 iState = EConnecting; |
|
136 if( aConnectionType == EOsmConnectionBT ) |
|
137 { |
|
138 iObexClient->ConnectL( iStatus ); |
|
139 } |
|
140 else |
|
141 { |
|
142 // iObexClient->ConnectIrL( iStatus ); |
|
143 } |
|
144 |
|
145 SetActive(); |
|
146 } |
|
147 } |
|
148 |
|
149 |
|
150 void COsmObexSender::StopL() |
|
151 { |
|
152 iObexClient->StopL(); |
|
153 |
|
154 /* Implementation for this?? */ |
|
155 /* |
|
156 if (iClient && iClient->IsConnected()) |
|
157 { |
|
158 iClient->Abort(); |
|
159 iState = EWaitingToGetDevice; |
|
160 } |
|
161 */ |
|
162 } |
|
163 |
|
164 |
|
165 |