|
1 // Copyright (c) 2000-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 <watcher.h> |
|
17 #include <e32property.h> |
|
18 #include "msvtestutils.h" |
|
19 #include <ir_sock.h> |
|
20 #include "irwatcher.h" |
|
21 |
|
22 |
|
23 //********************************** |
|
24 // Globals |
|
25 //********************************** |
|
26 |
|
27 |
|
28 |
|
29 #include <ecom/implementationproxy.h> |
|
30 |
|
31 const TImplementationProxy ImplementationTable[] = |
|
32 { |
|
33 IMPLEMENTATION_PROXY_ENTRY(0x10008C68, CIrWatcher::NewL) |
|
34 }; |
|
35 |
|
36 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
37 { |
|
38 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
39 |
|
40 return ImplementationTable; |
|
41 } |
|
42 |
|
43 //********************************** |
|
44 // CIrWatcher |
|
45 //********************************** |
|
46 |
|
47 // static |
|
48 CIrWatcher* CIrWatcher::NewL(TAny* aWatcherParams) |
|
49 { |
|
50 TWatcherParams* params = reinterpret_cast<TWatcherParams*>(aWatcherParams); |
|
51 CIrWatcher* self = new (ELeave) CIrWatcher(EPriorityStandard, params->iLog); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 CIrWatcher::CIrWatcher(TInt aPriority, CWatcherLog& aLog) |
|
59 : CActive(aPriority), iLog(aLog) |
|
60 { |
|
61 CActiveScheduler::Add(this); |
|
62 } |
|
63 |
|
64 CIrWatcher::~CIrWatcher() |
|
65 { |
|
66 iProperty.Close(); |
|
67 Cancel(); |
|
68 } |
|
69 |
|
70 void CIrWatcher::ConstructL() |
|
71 { |
|
72 User::LeaveIfError(iProperty.Attach(KIrdaPropertyCategory, KIrdaStatus)); |
|
73 iProperty.Subscribe(iStatus); |
|
74 // Start the watcher |
|
75 iLog.Printf(_L("IrWatcher: Starting watcher")); |
|
76 SetActive(); |
|
77 } |
|
78 |
|
79 void CIrWatcher::DisplayState(TInt aState) |
|
80 { |
|
81 switch(aState) |
|
82 { |
|
83 |
|
84 case TIrdaStatusCodes::EIrLoaded: |
|
85 iLog.Printf(_L("IrWatcher: Loaded")); |
|
86 break; |
|
87 |
|
88 case TIrdaStatusCodes::EIrDiscoveredPeer: |
|
89 iLog.Printf(_L("IrWatcher: Start Discovery")); |
|
90 break; |
|
91 |
|
92 case TIrdaStatusCodes::EIrLostPeer: |
|
93 iLog.Printf(_L("IrWatcher: End Discovery")); |
|
94 break; |
|
95 |
|
96 case TIrdaStatusCodes::EIrConnected: |
|
97 iLog.Printf(_L("IrWatcher: Connected")); |
|
98 break; |
|
99 |
|
100 case TIrdaStatusCodes::EIrBlocked: |
|
101 iLog.Printf(_L("IrWatcher: Blocked")); |
|
102 break; |
|
103 |
|
104 case TIrdaStatusCodes::EIrDisconnected: |
|
105 iLog.Printf(_L("IrWatcher: Disconnected")); |
|
106 break; |
|
107 |
|
108 case TIrdaStatusCodes::EIrUnloaded: |
|
109 iLog.Printf(_L("IrWatcher: Unloaded")); |
|
110 break; |
|
111 |
|
112 default: |
|
113 iLog.Printf(_L("IrWatcher: Unknown")); |
|
114 break; |
|
115 }; |
|
116 } |
|
117 |
|
118 void CIrWatcher::RunL() |
|
119 { |
|
120 TInt state; |
|
121 iProperty.Subscribe(iStatus); |
|
122 iProperty.Get(state); |
|
123 DisplayState(state); |
|
124 SetActive(); |
|
125 } |
|
126 |
|
127 void CIrWatcher::DoCancel() |
|
128 { |
|
129 iLog.Printf(_L("IrWatcher: DoCancel")); |
|
130 iProperty.Cancel(); |
|
131 } |
|
132 |
|
133 |