|
1 // Copyright (c) 2005-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 // |
|
15 |
|
16 #include "serverasyncao.h" |
|
17 #include <e32cons.h> |
|
18 #include <obexserver.h> |
|
19 |
|
20 #include <obexobjects.h> |
|
21 |
|
22 |
|
23 CServerAsyncAO* CServerAsyncAO::NewL(CObexServer& aObexServer) |
|
24 { |
|
25 CServerAsyncAO* self = new(ELeave) CServerAsyncAO(aObexServer); |
|
26 CleanupStack::PushL(self); |
|
27 self->ConstructL(); |
|
28 CleanupStack::Pop(); |
|
29 return self; |
|
30 } |
|
31 |
|
32 CServerAsyncAO::CServerAsyncAO(CObexServer& aObexServer) |
|
33 :CActive(EPriorityStandard), |
|
34 iObexServer(aObexServer) |
|
35 { |
|
36 CActiveScheduler::Add(this); |
|
37 } |
|
38 |
|
39 void CServerAsyncAO::ConstructL() |
|
40 { |
|
41 iConsole = Console::NewL(_L("OBEX DLL Test Code"),TSize(55,12)); |
|
42 } |
|
43 |
|
44 CServerAsyncAO::~CServerAsyncAO() |
|
45 { |
|
46 delete iConsole; |
|
47 } |
|
48 |
|
49 void CServerAsyncAO::CompletionIndication(CObex::TOperation aOpcode, TObexResponse aResponse) |
|
50 { |
|
51 _LIT(KPutIndication, "PutCompleteIndication\n"); |
|
52 _LIT(KGetIndication, "GetCompleteIndication\n"); |
|
53 _LIT(KSetPathIndication, "SetPathIndication\n"); |
|
54 |
|
55 iState = ECompleteIndication; |
|
56 iDefaultResponse = aResponse; |
|
57 |
|
58 switch(aOpcode) |
|
59 { |
|
60 case CObex::EOpPut: |
|
61 iConsole->Printf(KPutIndication); |
|
62 break; |
|
63 case CObex::EOpGet: |
|
64 iConsole->Printf(KGetIndication); |
|
65 break; |
|
66 case CObex::EOpSetPath: |
|
67 iConsole->Printf(KSetPathIndication); |
|
68 break; |
|
69 default: |
|
70 User::Invariant(); |
|
71 } |
|
72 |
|
73 iConsole->Printf(_L("Please enter the response code: 0x%x"), aResponse); |
|
74 iConsole->Read(iStatus); |
|
75 SetActive(); |
|
76 } |
|
77 |
|
78 void CServerAsyncAO::RequestIndication(CObex::TOperation aOpcode, CObexBaseObject *aObject) |
|
79 { |
|
80 if(aOpcode == CObex::EOpPut) |
|
81 { |
|
82 iConsole->Printf(_L("Put")); |
|
83 } |
|
84 else if(aOpcode == CObex::EOpGet) |
|
85 { |
|
86 iConsole->Printf(_L("Get")); |
|
87 } |
|
88 else |
|
89 { |
|
90 User::Invariant(); |
|
91 } |
|
92 iState = ERequestIndication; |
|
93 iObject = aObject; |
|
94 iConsole->Printf(_L("RequestIndication, press any key to continue\n")); |
|
95 iConsole->Read(iStatus); |
|
96 SetActive(); |
|
97 } |
|
98 |
|
99 void CServerAsyncAO::RunL() |
|
100 { |
|
101 TObexResponse resp = ERespSuccess; |
|
102 TBuf<2> buf; |
|
103 |
|
104 TKeyCode key = iConsole->KeyCode(); |
|
105 |
|
106 if(iState == ECompleteIndication) |
|
107 { |
|
108 buf.AppendFormat(_L("%x"), iDefaultResponse); |
|
109 do { |
|
110 |
|
111 if(key == EKeyBackspace&&buf.Length()!=0) |
|
112 { |
|
113 buf.SetLength(buf.Length()-1); |
|
114 } |
|
115 else if( buf.Length() < buf.MaxLength()) |
|
116 { |
|
117 buf.Append(key); |
|
118 } |
|
119 else |
|
120 continue; |
|
121 iConsole->Printf(_L("%c"),key); |
|
122 } |
|
123 while((key = iConsole->Getch())!=EKeyEnter); |
|
124 iConsole->Printf(_L("\n")); |
|
125 |
|
126 TLex lex(buf); |
|
127 TUint value; |
|
128 TInt lex_err = lex.Val(value, EHex); |
|
129 |
|
130 if(lex_err == KErrNone) |
|
131 { |
|
132 resp = static_cast<TObexResponse>(value); |
|
133 } |
|
134 else |
|
135 { |
|
136 iConsole->Printf(_L("Input parsing failed, use success as default response\n")); |
|
137 } |
|
138 |
|
139 TInt ret = iObexServer.RequestCompleteIndicationCallback(resp); |
|
140 iConsole->Printf(_L("Server returned with error code %d\n\n"), ret); |
|
141 } |
|
142 else |
|
143 { |
|
144 TInt ret = iObexServer.RequestIndicationCallback(iObject); |
|
145 iConsole->Printf(_L("Server returned with error code %d\n\n"), ret); |
|
146 } |
|
147 } |
|
148 |
|
149 void CServerAsyncAO::DoCancel() |
|
150 { |
|
151 iConsole->ReadCancel(); |
|
152 } |
|
153 |