kerneltest/e32test/usbho/t_usbdi/t_usbhost_usbman_src/t_usbhost_usbman.cpp
changeset 281 13fbfa31d2ba
parent 259 57b9594f5772
child 291 206a6eaaeb71
equal deleted inserted replaced
266:0008ccd16016 281:13fbfa31d2ba
    31 
    31 
    32 TBool RunClient(RUsbOtgDriver& aOtg, TInt event);
    32 TBool RunClient(RUsbOtgDriver& aOtg, TInt event);
    33 TBool RunHost(RUsbOtgDriver& aOtg, TInt event);
    33 TBool RunHost(RUsbOtgDriver& aOtg, TInt event);
    34 
    34 
    35 TInt E32Main()
    35 TInt E32Main()
    36 	{
    36     {
    37 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN, "---> Main OTG Sub-Process");
    37     OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN, "---> Main OTG Sub-Process");
    38 
    38 
    39 	CTrapCleanup* trapHandler = CTrapCleanup::New();
    39     CTrapCleanup* trapHandler = CTrapCleanup::New();
    40 
    40 
    41 	if(!trapHandler)
    41     if(!trapHandler)
    42 		{
    42         {
    43 		return KErrNoMemory;
    43         return KErrNoMemory;
    44 		}
    44         }
    45 
    45 
    46 	TBool clientFlag = EFalse; // default to host
    46     TBool clientFlag = EFalse; // default to host
    47 	
    47     
    48 	// Process the command line option for role
    48     // Process the command line option for role
    49 	TInt cmdLineLength(User::CommandLineLength());
    49     TInt cmdLineLength(User::CommandLineLength());
    50 
    50 
    51 	if(cmdLineLength != 0)
    51     if(cmdLineLength != 0)
    52 		{
    52         {
    53 		HBufC* cmdLine = HBufC::NewMax(cmdLineLength);	
    53         HBufC* cmdLine = HBufC::NewMax(cmdLineLength);    
    54 		TPtr cmdLinePtr = cmdLine->Des();
    54         TPtr cmdLinePtr = cmdLine->Des();
    55 		User::CommandLine(cmdLinePtr);
    55         User::CommandLine(cmdLinePtr);
    56 		TLex args(*cmdLine);
    56         TLex args(*cmdLine);
    57 		args.SkipSpace();
    57         args.SkipSpace();
    58 		
    58         
    59 		// Obtain the role of this test module
    59         // Obtain the role of this test module
    60 		TPtrC firstToken = args.NextToken(); // e.g. client ??
    60         TPtrC firstToken = args.NextToken(); // e.g. client ??
    61 
    61 
    62 		if(firstToken.Compare(KArgClient) == 0)
    62         if(firstToken.Compare(KArgClient) == 0)
    63 			{
    63             {
    64 			clientFlag = ETrue;
    64             clientFlag = ETrue;
    65             OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP01, "usbhost_usbman running as a Client");
    65             OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP01, "usbhost_usbman running as a Client");
    66 			}
    66             }
    67 		else
    67         else
    68 			{
    68             {
    69 			clientFlag = EFalse;
    69             clientFlag = EFalse;
    70             OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP02, "usbhost_usbman running as a Host");
    70             OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP02, "usbhost_usbman running as a Host");
    71 			}
    71             }
    72 
    72 
    73 		delete cmdLine;
    73         delete cmdLine;
    74 		}			
    74         }            
    75 
    75 
    76 	TInt r = User::LoadLogicalDevice(KOtgdiLddFileName);
    76     TInt r = User::LoadLogicalDevice(KOtgdiLddFileName);
    77 
    77 
    78 	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
    79 		{
    79         {
    80 		OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP03, "   LoadLogicalDevice(KOtgdiLddFileName) error = %d", r);
    80         OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP03, "   LoadLogicalDevice(KOtgdiLddFileName) error = %d", r);
    81 		delete trapHandler;
    81         delete trapHandler;
    82 		return r;		
    82         return r;        
    83 		}
    83         }
    84 
    84 
    85 	
    85     
    86 	RUsbOtgDriver otg;
    86     RUsbOtgDriver otg;
    87 	RProperty wordofdeath;
    87     RProperty wordofdeath;
    88 	TRequestStatus waiting_for_death;
    88     TRequestStatus waiting_for_death;
    89 	TRequestStatus status;
    89     TRequestStatus status;
    90 	RUsbOtgDriver::TOtgEvent event;
    90     RUsbOtgDriver::TOtgEvent event;
    91 	TBool running = ETrue;
    91     TBool running = ETrue;
    92 	
    92     
    93 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP04, "   opening otg driver");
    93     OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP04, "   opening otg driver");
    94 	
    94     
    95 	r = otg.Open();
    95     r = otg.Open();
    96 	if(r != KErrNone)
    96     if(r != KErrNone)
    97 		{
    97         {
    98 		OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP05, "   otg.Open fails %d", r);
    98         OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP05, "   otg.Open fails %d", r);
    99         goto Abort;
    99         goto Abort;
   100 		}
   100         }
   101 
   101 
   102 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP06, "   otg driver successfully opened");
   102     OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP06, "   otg driver successfully opened");
   103 
   103 
   104 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP07, "   otg : starting stacks now");
   104     OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP07, "   otg : starting stacks now");
   105 	
   105     
   106 	r = otg.StartStacks();
   106     r = otg.StartStacks();
   107 
   107 
   108 	if(r != KErrNone)
   108     if(r != KErrNone)
   109 		{
   109         {
   110 		OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP08, "   otg.StartStacks fails %d", r);
   110         OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP08, "   otg.StartStacks fails %d", r);
   111         goto Abort;
   111         goto Abort;
   112 		}	
   112         }    
   113 
   113 
   114 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP09, "   otg stacks successfully started");
   114     OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP09, "   otg stacks successfully started");
   115 
   115 
   116 //	RProcess::Rendezvous(KErrNone);
   116 //    RProcess::Rendezvous(KErrNone);
   117 
   117 
   118     // attach to the word of deathproperty
   118     // attach to the word of deathproperty
   119     r = wordofdeath.Attach(KWordOfDeathCat, KWordOfDeathKey, EOwnerThread);
   119     r = wordofdeath.Attach(KWordOfDeathCat, KWordOfDeathKey, EOwnerThread);
   120     if(r != KErrNone)
   120     if(r != KErrNone)
   121         {
   121         {
   124     
   124     
   125     // wait for the previously attached counterproperty to be updated
   125     // wait for the previously attached counterproperty to be updated
   126     wordofdeath.Subscribe(waiting_for_death);
   126     wordofdeath.Subscribe(waiting_for_death);
   127     while(running)
   127     while(running)
   128         {
   128         {
   129 		otg.QueueOtgEventRequest(event, status);
   129         otg.QueueOtgEventRequest(event, status);
   130 		User::WaitForRequest(status, waiting_for_death);
   130         User::WaitForRequest(status, waiting_for_death);
   131 
   131 
   132         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP01, "waiting_for_death= %d", waiting_for_death.Int());
   132         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP01, "waiting_for_death= %d", waiting_for_death.Int());
   133         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP02, "Otg Event        = %d", status.Int());
   133         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP02, "Otg Event        = %d", status.Int());
   134 
   134 
   135         r = waiting_for_death.Int();
   135         r = waiting_for_death.Int();
   142         r = status.Int();
   142         r = status.Int();
   143         if(r != KRequestPending)
   143         if(r != KRequestPending)
   144             {
   144             {
   145             // Run client or host modes against this otg event
   145             // Run client or host modes against this otg event
   146             if(clientFlag)
   146             if(clientFlag)
   147                 {		
   147                 {        
   148                 running = RunClient(otg, event);
   148                 running = RunClient(otg, event);
   149                 }
   149                 }
   150             else
   150             else
   151                 {
   151                 {
   152                 running = RunHost(otg, event);
   152                 running = RunHost(otg, event);
   153                 }
   153                 }
   154             }
   154             }
   155         }
   155         }
   156 
   156 
   157 	// Shut down nicely
   157     // Shut down nicely
   158 
   158 
   159     OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP03, "StopStacks()");
   159     OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP03, "StopStacks()");
   160 
   160 
   161     otg.StopStacks(); //NB This drops the bus
   161     otg.StopStacks(); //NB This drops the bus
   162 
   162 
   174 
   174 
   175     OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP07, "usbhost_usbman Finished");
   175     OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP07, "usbhost_usbman Finished");
   176 
   176 
   177     return KErrNone;
   177     return KErrNone;
   178     }
   178     }
   179 	
   179     
   180 
   180 
   181 
   181 
   182 
   182 
   183 TBool RunClient(RUsbOtgDriver& aOtg, TInt event)
   183 TBool RunClient(RUsbOtgDriver& aOtg, TInt event)
   184     {
   184     {
   203 
   203 
   204 
   204 
   205 
   205 
   206 TBool RunHost(RUsbOtgDriver& aOtg, TInt event)
   206 TBool RunHost(RUsbOtgDriver& aOtg, TInt event)
   207     {
   207     {
   208     TInt r;
       
   209     switch(event)
   208     switch(event)
   210         {
   209         {
   211     case RUsbOtgDriver::EEventAPlugInserted:
   210     case RUsbOtgDriver::EEventAPlugInserted:
   212         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP11, "Host side otg got APlugInserted Event");
   211             {
   213         r = aOtg.BusRequest();
   212             OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP11, "Host side otg got APlugInserted Event");
   214         OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP12, "BusRequest() made - returned %d", r);
   213 #ifdef OST_TRACE_COMPILER_IN_USE
   215         break;
   214             TInt r = 
       
   215 #endif
       
   216             aOtg.BusRequest();
       
   217             OstTrace1(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP12, "BusRequest() made - returned %d", r);
       
   218             }
       
   219             break;
   216 
   220 
   217     case RUsbOtgDriver::EEventAPlugRemoved:
   221     case RUsbOtgDriver::EEventAPlugRemoved:
   218         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP13, "Host side otg got APlugRemoved Event - shutting down");
   222         OstTrace0(TRACE_NORMAL, RPROCESS_RENDEZVOUS_DUP13, "Host side otg got APlugRemoved Event - shutting down");
   219         return EFalse;
   223         return EFalse;
   220 
   224