kerneltest/e32test/usbho/t_usbdi/t_usbhost_usbman_src/t_usbhost_usbman.cpp
changeset 259 57b9594f5772
parent 0 a41df078684a
child 257 3e88ff8f41d5
child 269 d57b86b1867a
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 #include <e32cmn.h>
    16 #include <e32cmn.h>
    17 #include <e32cmn_private.h>
    17 #include <e32cmn_private.h>
    18 #include <e32property.h>
    18 #include <e32property.h>
    19 #include <d32otgdi.h>
    19 #include <d32otgdi.h>
    20 #include "..\..\t_usbdi\inc\testdebug.h"
    20 #include "..\..\t_usbdi\inc\testdebug.h"
       
    21 #include "OstTraceDefinitions.h"
       
    22 #ifdef OST_TRACE_COMPILER_IN_USE
       
    23 #include "t_usbhost_usbmanTraces.h"
       
    24 #endif
    21 
    25 
    22 _LIT(KOtgdiLddFileName, "otgdi");
    26 _LIT(KOtgdiLddFileName, "otgdi");
    23 _LIT(KArgClient,        "client");
    27 _LIT(KArgClient,        "client");
    24 
    28 
    25 static const TUid KWordOfDeathCat = {0x01066600};
    29 static const TUid KWordOfDeathCat = {0x01066600};
    28 TBool RunClient(RUsbOtgDriver& aOtg, TInt event);
    32 TBool RunClient(RUsbOtgDriver& aOtg, TInt event);
    29 TBool RunHost(RUsbOtgDriver& aOtg, TInt event);
    33 TBool RunHost(RUsbOtgDriver& aOtg, TInt event);
    30 
    34 
    31 TInt E32Main()
    35 TInt E32Main()
    32 	{
    36 	{
    33 	RDebug::Print(_L("---> Main OTG Sub-Process"));
    37 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN, "---> Main OTG Sub-Process");
    34 
    38 
    35 	CTrapCleanup* trapHandler = CTrapCleanup::New();
    39 	CTrapCleanup* trapHandler = CTrapCleanup::New();
    36 
    40 
    37 	if(!trapHandler)
    41 	if(!trapHandler)
    38 		{
    42 		{
    56 		TPtrC firstToken = args.NextToken(); // e.g. client ??
    60 		TPtrC firstToken = args.NextToken(); // e.g. client ??
    57 
    61 
    58 		if(firstToken.Compare(KArgClient) == 0)
    62 		if(firstToken.Compare(KArgClient) == 0)
    59 			{
    63 			{
    60 			clientFlag = ETrue;
    64 			clientFlag = ETrue;
    61             RDebug::Print(_L("usbhost_usbman running as a Client"));
    65             OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP01, "usbhost_usbman running as a Client");
    62 			}
    66 			}
    63 		else
    67 		else
    64 			{
    68 			{
    65 			clientFlag = EFalse;
    69 			clientFlag = EFalse;
    66             RDebug::Print(_L("usbhost_usbman running as a Host"));
    70             OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP02, "usbhost_usbman running as a Host");
    67 			}
    71 			}
    68 
    72 
    69 		delete cmdLine;
    73 		delete cmdLine;
    70 		}			
    74 		}			
    71 
    75 
    72 	TInt r = User::LoadLogicalDevice(KOtgdiLddFileName);
    76 	TInt r = User::LoadLogicalDevice(KOtgdiLddFileName);
    73 
    77 
    74 	if(r != KErrNone && r != KErrAlreadyExists) // persistent loading since process will be killed while it is in the loop below and doesnt unload it
    78 	if(r != KErrNone && r != KErrAlreadyExists) // persistent loading since process will be killed while it is in the loop below and doesnt unload it
    75 		{
    79 		{
    76 		RDebug::Print(_L("   LoadLogicalDevice(KOtgdiLddFileName) error = %d"), r);
    80 		OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP03, "   LoadLogicalDevice(KOtgdiLddFileName) error = %d", r);
    77 		delete trapHandler;
    81 		delete trapHandler;
    78 		return r;		
    82 		return r;		
    79 		}
    83 		}
    80 
    84 
    81 	
    85 	
    84 	TRequestStatus waiting_for_death;
    88 	TRequestStatus waiting_for_death;
    85 	TRequestStatus status;
    89 	TRequestStatus status;
    86 	RUsbOtgDriver::TOtgEvent event;
    90 	RUsbOtgDriver::TOtgEvent event;
    87 	TBool running = ETrue;
    91 	TBool running = ETrue;
    88 	
    92 	
    89 	RDebug::Print(_L("   opening otg driver"));
    93 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP04, "   opening otg driver");
    90 	
    94 	
    91 	r = otg.Open();
    95 	r = otg.Open();
    92 	if(r != KErrNone)
    96 	if(r != KErrNone)
    93 		{
    97 		{
    94 		RDebug::Print(_L("   otg.Open fails %d"), r);
    98 		OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP05, "   otg.Open fails %d", r);
    95         goto Abort;
    99         goto Abort;
    96 		}
   100 		}
    97 
   101 
    98 	RDebug::Print(_L("   otg driver successfully opened"));
   102 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP06, "   otg driver successfully opened");
    99 
   103 
   100 	RDebug::Print(_L("   otg : starting stacks now"));
   104 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP07, "   otg : starting stacks now");
   101 	
   105 	
   102 	r = otg.StartStacks();
   106 	r = otg.StartStacks();
   103 
   107 
   104 	if(r != KErrNone)
   108 	if(r != KErrNone)
   105 		{
   109 		{
   106 		RDebug::Print(_L("   otg.StartStacks fails %d"), r);
   110 		OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP08, "   otg.StartStacks fails %d", r);
   107         goto Abort;
   111         goto Abort;
   108 		}	
   112 		}	
   109 
   113 
   110 	RDebug::Print(_L("   otg stacks successfully started"));
   114 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP09, "   otg stacks successfully started");
   111 
   115 
   112 //	RProcess::Rendezvous(KErrNone);
   116 //	RProcess::Rendezvous(KErrNone);
   113 
   117 
   114     // attach to the word of deathproperty
   118     // attach to the word of deathproperty
   115     r = wordofdeath.Attach(KWordOfDeathCat, KWordOfDeathKey, EOwnerThread);
   119     r = wordofdeath.Attach(KWordOfDeathCat, KWordOfDeathKey, EOwnerThread);
   116     if(r != KErrNone)
   120     if(r != KErrNone)
   117         {
   121         {
   118         RDebug::Print(_L("Failed to connect to word of death"));
   122         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS, "Failed to connect to word of death");
   119         }
   123         }
   120     
   124     
   121     // wait for the previously attached counterproperty to be updated
   125     // wait for the previously attached counterproperty to be updated
   122     wordofdeath.Subscribe(waiting_for_death);
   126     wordofdeath.Subscribe(waiting_for_death);
   123     while(running)
   127     while(running)
   124         {
   128         {
   125 		otg.QueueOtgEventRequest(event, status);
   129 		otg.QueueOtgEventRequest(event, status);
   126 		User::WaitForRequest(status, waiting_for_death);
   130 		User::WaitForRequest(status, waiting_for_death);
   127 
   131 
   128         RDebug::Print(_L("waiting_for_death= %d"), waiting_for_death.Int());
   132         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP01, "waiting_for_death= %d", waiting_for_death.Int());
   129         RDebug::Print(_L("Otg Event        = %d"), status.Int());
   133         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP02, "Otg Event        = %d", status.Int());
   130 
   134 
   131         r = waiting_for_death.Int();
   135         r = waiting_for_death.Int();
   132         if(r != KRequestPending)
   136         if(r != KRequestPending)
   133             {
   137             {
   134             running = EFalse;
   138             running = EFalse;
   150             }
   154             }
   151         }
   155         }
   152 
   156 
   153 	// Shut down nicely
   157 	// Shut down nicely
   154 
   158 
   155     RDebug::Print(_L("StopStacks()"));
   159     OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP03, "StopStacks()");
   156 
   160 
   157     otg.StopStacks(); //NB This drops the bus
   161     otg.StopStacks(); //NB This drops the bus
   158 
   162 
   159     RDebug::Print(_L("******** ShutdownStack Complete ********"));
   163     OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP04, "******** ShutdownStack Complete ********");
   160 
   164 
   161     RDebug::Print(_L("Close Otg stack()"));
   165     OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP05, "Close Otg stack()");
   162 
   166 
   163     otg.Close();
   167     otg.Close();
   164 
   168 
   165 Abort:
   169 Abort:
   166     RDebug::Print(_L("Free LDD"));
   170     OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP06, "Free LDD");
   167     User::FreeLogicalDevice(RUsbOtgDriver::Name());
   171     User::FreeLogicalDevice(RUsbOtgDriver::Name());
   168 
   172 
   169     delete trapHandler;
   173     delete trapHandler;
   170 
   174 
   171     RDebug::Print(_L("usbhost_usbman Finished"));
   175     OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP07, "usbhost_usbman Finished");
   172 
   176 
   173     return KErrNone;
   177     return KErrNone;
   174     }
   178     }
   175 	
   179 	
   176 
   180 
   179 TBool RunClient(RUsbOtgDriver& aOtg, TInt event)
   183 TBool RunClient(RUsbOtgDriver& aOtg, TInt event)
   180     {
   184     {
   181     switch(event)
   185     switch(event)
   182         {
   186         {
   183     case RUsbOtgDriver::EEventVbusRaised:
   187     case RUsbOtgDriver::EEventVbusRaised:
   184         RDebug::Print(_L("Client Side : Vbus raise detected due to Event VbusRaised"));
   188         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP08, "Client Side : Vbus raise detected due to Event VbusRaised");
   185         break;
   189         break;
   186 
   190 
   187     case RUsbOtgDriver::EEventRoleChangedToDevice:
   191     case RUsbOtgDriver::EEventRoleChangedToDevice:
   188         RDebug::Print(_L("Client Side : Vbus raise detected due to Event RoleChangedToDevice"));
   192         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP09, "Client Side : Vbus raise detected due to Event RoleChangedToDevice");
   189         break;
   193         break;
   190 
   194 
   191     default:
   195     default:
   192         RDebug::Print(_L("Client Side : Event %d received"), event);
   196         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP10, "Client Side : Event %d received", event);
   193         break;
   197         break;
   194         }
   198         }
   195 
   199 
   196     return ETrue;
   200     return ETrue;
   197     }
   201     }
   203     {
   207     {
   204     TInt r;
   208     TInt r;
   205     switch(event)
   209     switch(event)
   206         {
   210         {
   207     case RUsbOtgDriver::EEventAPlugInserted:
   211     case RUsbOtgDriver::EEventAPlugInserted:
   208         RDebug::Print(_L("Host side otg got APlugInserted Event"));
   212         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP11, "Host side otg got APlugInserted Event");
   209         r = aOtg.BusRequest();
   213         r = aOtg.BusRequest();
   210         RDebug::Print(_L("BusRequest() made - returned %d"), r);
   214         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP12, "BusRequest() made - returned %d", r);
   211         break;
   215         break;
   212 
   216 
   213     case RUsbOtgDriver::EEventAPlugRemoved:
   217     case RUsbOtgDriver::EEventAPlugRemoved:
   214         RDebug::Print(_L("Host side otg got APlugRemoved Event - shutting down"));
   218         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP13, "Host side otg got APlugRemoved Event - shutting down");
   215         return EFalse;
   219         return EFalse;
   216 
   220 
   217     case RUsbOtgDriver::EEventVbusRaised:
   221     case RUsbOtgDriver::EEventVbusRaised:
   218         RDebug::Print(_L("Host side otg got VbusRaised Event"));
   222         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP14, "Host side otg got VbusRaised Event");
   219         break;
   223         break;
   220 
   224 
   221     case RUsbOtgDriver::EEventVbusDropped:
   225     case RUsbOtgDriver::EEventVbusDropped:
   222         RDebug::Print(_L("Host side otg got VbusDropped Event"));
   226         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP15, "Host side otg got VbusDropped Event");
   223         break;
   227         break;
   224 
   228 
   225     case RUsbOtgDriver::EEventSrpInitiated:
   229     case RUsbOtgDriver::EEventSrpInitiated:
   226         RDebug::Print(_L("Host side otg got SrpInitiated Event"));
   230         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP16, "Host side otg got SrpInitiated Event");
   227         break;
   231         break;
   228 
   232 
   229     case RUsbOtgDriver::EEventSrpReceived:
   233     case RUsbOtgDriver::EEventSrpReceived:
   230         RDebug::Print(_L("Host side otg got SrpReceived Event"));
   234         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP17, "Host side otg got SrpReceived Event");
   231         break;
   235         break;
   232 
   236 
   233     case RUsbOtgDriver::EEventHnpEnabled:
   237     case RUsbOtgDriver::EEventHnpEnabled:
   234         RDebug::Print(_L("Host side otg got HnpEnabled Event"));
   238         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP18, "Host side otg got HnpEnabled Event");
   235         break;
   239         break;
   236 
   240 
   237     case RUsbOtgDriver::EEventHnpDisabled:
   241     case RUsbOtgDriver::EEventHnpDisabled:
   238         RDebug::Print(_L("Host side otg got HnpDisabled Event"));
   242         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP19, "Host side otg got HnpDisabled Event");
   239         break;
   243         break;
   240 
   244 
   241     case RUsbOtgDriver::EEventHnpSupported:
   245     case RUsbOtgDriver::EEventHnpSupported:
   242         RDebug::Print(_L("Host side otg got HnpSupported Event"));
   246         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP20, "Host side otg got HnpSupported Event");
   243         break;
   247         break;
   244 
   248 
   245     case RUsbOtgDriver::EEventHnpAltSupported:
   249     case RUsbOtgDriver::EEventHnpAltSupported:
   246         RDebug::Print(_L("Host side otg got HnpAltSupported Event"));
   250         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP21, "Host side otg got HnpAltSupported Event");
   247         break;
   251         break;
   248 
   252 
   249 
   253 
   250     case RUsbOtgDriver::EEventBusConnectionBusy:
   254     case RUsbOtgDriver::EEventBusConnectionBusy:
   251         RDebug::Print(_L("Host side otg got BusConnectionBusy Event"));
   255         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP22, "Host side otg got BusConnectionBusy Event");
   252         break;
   256         break;
   253 
   257 
   254     case RUsbOtgDriver::EEventBusConnectionIdle:
   258     case RUsbOtgDriver::EEventBusConnectionIdle:
   255         RDebug::Print(_L("Host side otg got BusConnectionIdle Event"));
   259         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP23, "Host side otg got BusConnectionIdle Event");
   256         break;
   260         break;
   257 
   261 
   258 
   262 
   259     case RUsbOtgDriver::EEventRoleChangedToHost:
   263     case RUsbOtgDriver::EEventRoleChangedToHost:
   260         RDebug::Print(_L("Host side otg got RoleChangedToHost Event"));
   264         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP24, "Host side otg got RoleChangedToHost Event");
   261         break;
   265         break;
   262 
   266 
   263     case RUsbOtgDriver::EEventRoleChangedToDevice:
   267     case RUsbOtgDriver::EEventRoleChangedToDevice:
   264         RDebug::Print(_L("Host side otg got RoleChangedToDevice Event"));
   268         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP25, "Host side otg got RoleChangedToDevice Event");
   265         break;
   269         break;
   266 
   270 
   267     case RUsbOtgDriver::EEventRoleChangedToIdle:
   271     case RUsbOtgDriver::EEventRoleChangedToIdle:
   268         RDebug::Print(_L("Host side otg got RoleChangedToIdle Event"));
   272         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP26, "Host side otg got RoleChangedToIdle Event");
   269         break;
   273         break;
   270 
   274 
   271     default:
   275     default:
   272         RDebug::Print(_L("Host Side otg unknown event catcher tickled - event %d - shutting down"), event);
   276         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP27, "Host Side otg unknown event catcher tickled - event %d - shutting down", event);
   273         return EFalse;
   277         return EFalse;
   274      }
   278      }
   275 
   279 
   276     return ETrue;
   280     return ETrue;
   277     }
   281     }