|
1 /* |
|
2 * Name : ConnectionManager.cpp |
|
3 * Description : Manages application connection |
|
4 * Project : This file is part of OpenMAR, an Open Mobile Augmented Reality browser |
|
5 * Website : http://OpenMAR.org |
|
6 * |
|
7 * Copyright (c) 2010 David Caabeiro |
|
8 * |
|
9 * All rights reserved. This program and the accompanying materials are made available |
|
10 * under the terms of the Eclipse Public License v1.0 which accompanies this |
|
11 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html |
|
12 * |
|
13 */ |
|
14 |
|
15 #include "ConnectionManager.h" |
|
16 |
|
17 #include "SettingManager.h" |
|
18 |
|
19 #include <CommDbConnPref.h> |
|
20 #include <es_enum.h> |
|
21 |
|
22 #include "Logger.h" |
|
23 |
|
24 CConnectionManager* CConnectionManager::NewL(MConnectionManager& aObserver, CSettingManager& aSetting) |
|
25 { |
|
26 CConnectionManager* self = new(ELeave) CConnectionManager(aObserver, aSetting); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(); |
|
29 CleanupStack::Pop(self); |
|
30 |
|
31 return self; |
|
32 } |
|
33 |
|
34 CConnectionManager::~CConnectionManager() |
|
35 { |
|
36 Cancel(); |
|
37 |
|
38 iMonitor.Close(); |
|
39 iConnection.Close(); |
|
40 iSocketServ.Close(); |
|
41 } |
|
42 |
|
43 CConnectionManager::CConnectionManager(MConnectionManager& aObserver, CSettingManager& aSetting) |
|
44 : CActive(CActive::EPriorityStandard), iObserver(aObserver), iSetting(aSetting) |
|
45 { |
|
46 CActiveScheduler::Add(this); |
|
47 } |
|
48 |
|
49 void CConnectionManager::ConstructL() |
|
50 { |
|
51 LOGTXT("Initializing connection.."); |
|
52 |
|
53 User::LeaveIfError(iSocketServ.Connect()); |
|
54 User::LeaveIfError(iConnection.Open(iSocketServ)); |
|
55 |
|
56 iMonitor.ConnectL(); |
|
57 iMonitor.NotifyEventL(*this); |
|
58 |
|
59 // _LIT8(KDefault, "/application/destination"); |
|
60 TUint destinationId = 0; |
|
61 // iSettings.Get(KDefault, destinationId, EHex); |
|
62 |
|
63 if (destinationId == 0) |
|
64 { |
|
65 // "Always ask" |
|
66 TCommDbConnPref pref; |
|
67 pref.SetDialogPreference(ECommDbDialogPrefPrompt); |
|
68 |
|
69 iConnection.Start(pref, iStatus); |
|
70 } |
|
71 else |
|
72 { |
|
73 TConnSnapPref pref; |
|
74 pref.SetSnap(destinationId); |
|
75 |
|
76 iConnection.Start(pref, iStatus); |
|
77 } |
|
78 |
|
79 SetActive(); |
|
80 } |
|
81 |
|
82 void CConnectionManager::RunL() |
|
83 { |
|
84 _LIT(KIapId, "IAP\\Id"); |
|
85 iConnection.GetIntSetting(KIapId, iIapId); |
|
86 |
|
87 LOGARG("Connected with iap %u", iIapId); |
|
88 |
|
89 iObserver.ConnectionStartedL(iStatus.Int()); |
|
90 } |
|
91 |
|
92 void CConnectionManager::DoCancel() |
|
93 { |
|
94 // Unfortunately no RConnection::StartCancel() available.. |
|
95 } |
|
96 |
|
97 void CConnectionManager::EventL(const CConnMonEventBase& aEvent) |
|
98 { |
|
99 switch (aEvent.EventType()) |
|
100 { |
|
101 /* |
|
102 case EConnMonConnectionStatusChange: |
|
103 { |
|
104 const CConnMonNetworkStatusChange& event = static_cast<const CConnMonNetworkStatusChange&>(aEvent); |
|
105 break; |
|
106 } |
|
107 */ |
|
108 case EConnMonDeleteConnection: |
|
109 { |
|
110 TUint count = 0; |
|
111 iConnection.EnumerateConnections(count); |
|
112 |
|
113 if (count == 0) |
|
114 LOGTXT("Connection dropped"); |
|
115 |
|
116 /* |
|
117 if (info().iIapId == iIapId) |
|
118 { |
|
119 connFound = ETrue; |
|
120 break; |
|
121 } |
|
122 */ |
|
123 break; |
|
124 } |
|
125 |
|
126 default: |
|
127 break; |
|
128 } |
|
129 } |