75 User::LeaveIfError( RProperty::Set( KPSUidUsbWatcher, |
75 User::LeaveIfError( RProperty::Set( KPSUidUsbWatcher, |
76 KUsbWatcherIsPeripheralConnected, |
76 KUsbWatcherIsPeripheralConnected, |
77 KUsbWatcherPeripheralIsNotConnected ) ); |
77 KUsbWatcherPeripheralIsNotConnected ) ); |
78 #endif |
78 #endif |
79 |
79 |
80 iNotifManager = CUsbNotifManager::NewL(); |
|
81 iUsbServiceControl = CUsbServiceControl::NewL(this, iUsb); |
80 iUsbServiceControl = CUsbServiceControl::NewL(this, iUsb); |
82 |
81 |
|
82 User::LeaveIfError(iStates.Append(CUsbState::NewL(this))); |
83 User::LeaveIfError(iStates.Append(CUsbStateHostAInitiate::NewL(this))); |
83 User::LeaveIfError(iStates.Append(CUsbStateHostAInitiate::NewL(this))); |
84 User::LeaveIfError(iStates.Append(CUsbStateHostAHost::NewL(this))); |
84 User::LeaveIfError(iStates.Append(CUsbStateHostAHost::NewL(this))); |
85 User::LeaveIfError(iStates.Append(CUsbStateHostAPeripheral::NewL(this))); |
85 User::LeaveIfError(iStates.Append(CUsbStateHostAPeripheral::NewL(this))); |
86 User::LeaveIfError(iStates.Append(CUsbStateHostAIdle::NewL(this))); |
86 User::LeaveIfError(iStates.Append(CUsbStateHostAIdle::NewL(this))); |
87 User::LeaveIfError(iStates.Append(CUsbStateHostHandle::NewL(this))); |
87 User::LeaveIfError(iStates.Append(CUsbStateHostHandle::NewL(this))); |
92 iBusActivityObserver = CUsbBusActivityObserver::NewL(); |
92 iBusActivityObserver = CUsbBusActivityObserver::NewL(); |
93 iHostEventNotificationObserver = CUsbHostEventNotificationObserver::NewL( |
93 iHostEventNotificationObserver = CUsbHostEventNotificationObserver::NewL( |
94 &iUsb); |
94 &iUsb); |
95 iMessageNotificationObserver = CUsbMessageNotificationObserver::NewL( |
95 iMessageNotificationObserver = CUsbMessageNotificationObserver::NewL( |
96 &iUsb); |
96 &iUsb); |
|
97 |
|
98 iHostState = iStates[EUsbStateUndefined]; |
|
99 |
|
100 // Notif manager must be created at least after VBus observer and iHostState initialization |
|
101 // to allow USb indicator subscribe to its notifications at construction and check their's current states |
|
102 iNotifManager = CUsbNotifManager::NewL(this); |
97 |
103 |
98 iIdPinObserver->SubscribeL(this); |
104 iIdPinObserver->SubscribeL(this); |
99 |
105 |
100 if (CUsbIdPinObserver::EIdPinOn == iIdPinObserver->IdPin()) |
106 if (CUsbIdPinObserver::EIdPinOn == iIdPinObserver->IdPin()) |
101 { |
107 { |
140 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::~CUsbOtgWatcher" ) ); |
146 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::~CUsbOtgWatcher" ) ); |
141 |
147 |
142 #ifndef STIF |
148 #ifndef STIF |
143 RProperty::Delete( KPSUidUsbWatcher, KUsbWatcherIsPeripheralConnected ); |
149 RProperty::Delete( KPSUidUsbWatcher, KUsbWatcherIsPeripheralConnected ); |
144 #endif |
150 #endif |
|
151 |
|
152 // delete Notif manager before VBus observer, due to USB indicator observes VBus |
|
153 delete iNotifManager; |
145 |
154 |
146 delete iIdPinObserver; |
155 delete iIdPinObserver; |
147 delete iVBusObserver; |
156 delete iVBusObserver; |
148 delete iOtgStateObserver; |
157 delete iOtgStateObserver; |
149 delete iBusActivityObserver; |
158 delete iBusActivityObserver; |
150 delete iHostEventNotificationObserver; |
159 delete iHostEventNotificationObserver; |
151 delete iMessageNotificationObserver; |
160 delete iMessageNotificationObserver; |
152 |
161 |
|
162 iOtgStateObservers.Close(); |
|
163 |
153 // Destroy states |
164 // Destroy states |
154 iStates.ResetAndDestroy(); |
165 iStates.ResetAndDestroy(); |
155 iStates.Close(); |
166 iStates.Close(); |
156 |
167 |
157 delete iNotifManager; |
|
158 delete iUsbServiceControl; |
168 delete iUsbServiceControl; |
159 |
169 |
160 iUsb.Close(); |
170 iUsb.Close(); |
161 |
171 |
162 } |
172 } |
801 iHostState = iStates[aNewStateId]; |
811 iHostState = iStates[aNewStateId]; |
802 |
812 |
803 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadState)); |
813 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadState)); |
804 |
814 |
805 iHostState->JustAdvancedToThisStateL(); // checks if there are conditions for advancing to another state(s) |
815 iHostState->JustAdvancedToThisStateL(); // checks if there are conditions for advancing to another state(s) |
806 |
816 |
|
817 // notify state change to observers |
|
818 for (TInt i(0); i < iOtgStateObservers.Count(); ++i) |
|
819 { |
|
820 iOtgStateObservers[i]->OtgWatcherStateChangedL(iHostState->Id()); |
|
821 } |
807 } |
822 } |
808 |
823 |
809 // --------------------------------------------------------------------------- |
824 // --------------------------------------------------------------------------- |
810 // |
825 // |
811 // --------------------------------------------------------------------------- |
826 // --------------------------------------------------------------------------- |
943 iHostEventNotificationObserver = |
956 iHostEventNotificationObserver = |
944 CUsbHostEventNotificationObserver::NewL(&iUsb); |
957 CUsbHostEventNotificationObserver::NewL(&iUsb); |
945 iMessageNotificationObserver = |
958 iMessageNotificationObserver = |
946 CUsbMessageNotificationObserver::NewL(&iUsb); |
959 CUsbMessageNotificationObserver::NewL(&iUsb); |
947 |
960 |
948 /* FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL idPinObserver->Subscribe" ) ); |
961 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Observers getters." ) ); |
949 |
|
950 iIdPinObserver->SubscribeL(this); |
|
951 |
|
952 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL idPinObserver->Unsubscribe" ) ); |
|
953 |
|
954 iIdPinObserver->UnsubscribeL(this); */ |
|
955 |
|
956 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Observers getters." ) ); |
|
957 |
962 |
958 if (iIdPinObserver != IdPinObserver()) |
963 if (iIdPinObserver != IdPinObserver()) |
959 { |
964 { |
960 User::Leave(KErrGeneral); |
965 User::Leave(KErrGeneral); |
961 } |
966 } |
982 |
987 |
983 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Observers destructors." ) ); |
988 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Observers destructors." ) ); |
984 |
989 |
985 delete iIdPinObserver; |
990 delete iIdPinObserver; |
986 iIdPinObserver = 0; |
991 iIdPinObserver = 0; |
987 delete iVBusObserver; |
992 |
988 iVBusObserver = 0; |
993 // Vbus observer is deleted later |
|
994 |
989 delete iOtgStateObserver; |
995 delete iOtgStateObserver; |
990 iOtgStateObserver = 0; |
996 iOtgStateObserver = 0; |
991 delete iBusActivityObserver; |
997 delete iBusActivityObserver; |
992 iBusActivityObserver = 0; |
998 iBusActivityObserver = 0; |
993 delete iHostEventNotificationObserver; |
999 delete iHostEventNotificationObserver; |
994 iHostEventNotificationObserver = 0; |
1000 iHostEventNotificationObserver = 0; |
995 delete iMessageNotificationObserver; |
1001 delete iMessageNotificationObserver; |
996 iMessageNotificationObserver = 0; |
1002 iMessageNotificationObserver = 0; |
997 |
1003 |
998 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL NotifManager and WarningNotifier." ) ); |
|
999 |
|
1000 CUsbNotifManager* usbnotifmanager = CUsbNotifManager::NewL(); |
|
1001 RNotifier rnotifier; |
|
1002 User::LeaveIfError(rnotifier.Connect()); |
|
1003 CUsbWarningNotifier* usbnotifier = CUsbWarningNotifier::NewL(rnotifier, |
|
1004 usbnotifmanager, EUsbOtgPartiallySupportedDevice); |
|
1005 usbnotifier->IsFeedbackNeeded(); |
|
1006 |
|
1007 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL NotifManager and WarningNotifier destruction." ) ); |
|
1008 |
|
1009 delete usbnotifier; |
|
1010 rnotifier.Close(); |
|
1011 delete usbnotifmanager; |
|
1012 |
|
1013 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Creating states." ) ); |
1004 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Creating states." ) ); |
1014 |
1005 |
|
1006 User::LeaveIfError(iStates.Append(CUsbState::NewL(this))); |
1015 User::LeaveIfError(iStates.Append(CUsbStateHostAInitiate::NewL(this))); |
1007 User::LeaveIfError(iStates.Append(CUsbStateHostAInitiate::NewL(this))); |
1016 User::LeaveIfError(iStates.Append(CUsbStateHostAHost::NewL(this))); |
1008 User::LeaveIfError(iStates.Append(CUsbStateHostAHost::NewL(this))); |
1017 User::LeaveIfError(iStates.Append(CUsbStateHostAPeripheral::NewL(this))); |
1009 User::LeaveIfError(iStates.Append(CUsbStateHostAPeripheral::NewL(this))); |
1018 User::LeaveIfError(iStates.Append(CUsbStateHostAIdle::NewL(this))); |
1010 User::LeaveIfError(iStates.Append(CUsbStateHostAIdle::NewL(this))); |
1019 User::LeaveIfError(iStates.Append(CUsbStateHostHandle::NewL(this))); |
1011 User::LeaveIfError(iStates.Append(CUsbStateHostHandle::NewL(this))); |
1031 |
1023 |
1032 if (iStates[EUsbStateHostAInitiate] != CurrentHostState()) |
1024 if (iStates[EUsbStateHostAInitiate] != CurrentHostState()) |
1033 { |
1025 { |
1034 User::Leave(KErrGeneral); |
1026 User::Leave(KErrGeneral); |
1035 } |
1027 } |
|
1028 |
|
1029 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL NotifManager and WarningNotifier." ) ); |
|
1030 |
|
1031 CUsbNotifManager* usbnotifmanager = CUsbNotifManager::NewL(this); |
|
1032 RNotifier rnotifier; |
|
1033 User::LeaveIfError(rnotifier.Connect()); |
|
1034 CUsbWarningNotifier* usbnotifier = CUsbWarningNotifier::NewL(rnotifier, |
|
1035 usbnotifmanager, EUsbOtgPartiallySupportedDevice); |
|
1036 usbnotifier->IsFeedbackNeeded(); |
|
1037 |
|
1038 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL NotifManager and WarningNotifier destruction." ) ); |
|
1039 |
|
1040 delete usbnotifier; |
|
1041 rnotifier.Close(); |
|
1042 delete usbnotifmanager; |
|
1043 |
|
1044 // VBus observer is deleted here, due to it is used by usbnotifmanager.usbindicatornotifier |
|
1045 delete iVBusObserver; |
|
1046 iVBusObserver = 0; |
1036 |
1047 |
1037 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Destructing states." ) ); |
1048 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Destructing states." ) ); |
1038 |
1049 |
1039 iStates.ResetAndDestroy(); |
1050 iStates.ResetAndDestroy(); |
1040 |
1051 |
1049 #endif |
1060 #endif |
1050 return KErrNone; |
1061 return KErrNone; |
1051 |
1062 |
1052 } |
1063 } |
1053 |
1064 |
|
1065 // --------------------------------------------------------------------------- |
|
1066 // |
|
1067 // --------------------------------------------------------------------------- |
|
1068 // |
|
1069 void CUsbOtgWatcher::SubscribeL(MUsbOtgWatcherStateObserver* aObserver) |
|
1070 { |
|
1071 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SubscribeL" ) ); |
|
1072 |
|
1073 User::LeaveIfError(iOtgStateObservers.Append(aObserver)); |
|
1074 |
|
1075 } |
|
1076 |
|
1077 // --------------------------------------------------------------------------- |
|
1078 // |
|
1079 // --------------------------------------------------------------------------- |
|
1080 // |
|
1081 void CUsbOtgWatcher::UnsubscribeL(MUsbOtgWatcherStateObserver* aObserver) |
|
1082 { |
|
1083 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UnsubscribeL" ) ); |
|
1084 if (0 == iOtgStateObservers.Count()) // no items |
|
1085 { |
|
1086 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UnsubscribeL No observers" ) ); |
|
1087 return; |
|
1088 } |
|
1089 |
|
1090 TInt i(0); |
|
1091 while (i < iOtgStateObservers.Count() && aObserver != iOtgStateObservers[i]) |
|
1092 ++i; |
|
1093 |
|
1094 if (aObserver == iOtgStateObservers[i]) // found |
|
1095 { |
|
1096 iOtgStateObservers.Remove(i); |
|
1097 } |
|
1098 else |
|
1099 { |
|
1100 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UnsubscribeL CanNotGetUsbOtgStateWatcherObserver" ) ); |
|
1101 Panic(ECanNotFindUsbOtgWatcherStateObserver); |
|
1102 } |
|
1103 } |