plugins/consoles/vt100cons/src/usb/vtc_usb.cpp
changeset 0 7f656887cf89
child 77 60f47003f4b1
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // vtc_usb.cpp
       
     2 // 
       
     3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <e32std.h>
       
    14 #include <fshell/consoleextensions.h>
       
    15 #include "vtc_usb.h"
       
    16 #include <usbclassuids.h>
       
    17 
       
    18 EXPORT_C TAny* NewConsole()
       
    19 	{
       
    20 	return new CUsbConsole;
       
    21 	}
       
    22 	
       
    23 //______________________________________________________________________________
       
    24 //						CUsbConsole
       
    25 CUsbConsole::CUsbConsole()
       
    26 	{
       
    27 	}
       
    28 
       
    29 CUsbConsole::~CUsbConsole()
       
    30 	{
       
    31 	iUsb.Close();
       
    32 	}
       
    33 	
       
    34 void CUsbConsole::ConstructL(const TDesC& aTitle)
       
    35 	{
       
    36 	User::LeaveIfError(iUsb.Connect());
       
    37 	
       
    38 	TRequestStatus stat;
       
    39 	// assume USB device already started
       
    40 	/*iUsb.Start(stat);
       
    41 	User::WaitForRequest(stat);
       
    42 	// KErrAccessDenied returned if already started;
       
    43 	if (stat.Int()!=KErrAccessDenied)
       
    44 		{
       
    45 		Message(EError, KUsbError, stat.Int(), 1);
       
    46 		User::LeaveIfError(stat.Int());
       
    47 		}*/
       
    48 
       
    49 	// Wait for an enumeration that supports ACM (this is so that if the device defaulted to say mass storage and was then reconfigured to a personality with ACM, we wait for the ACM reconfiguration
       
    50 	TBool gotAcm = EFalse;
       
    51 	while (!gotAcm)
       
    52 		{
       
    53 		TUsbDeviceState usbState;
       
    54 		User::LeaveIfError(iUsb.GetDeviceState(usbState));
       
    55 		if (usbState & EUsbDeviceStateConfigured)
       
    56 			{
       
    57 			// Check if we have ACM
       
    58 			TInt currentPersonality;
       
    59 			User::LeaveIfError(iUsb.GetCurrentPersonalityId(currentPersonality));
       
    60 			User::LeaveIfError(iUsb.ClassSupported(currentPersonality, KECACMUid, gotAcm));
       
    61 			_LIT(KGotIt, "Current USB personality has ACM, proceeding");
       
    62 			_LIT(KNotGotIt, "Current USB personality doesn't have ACM, waiting for re-enumeration");
       
    63 			if (gotAcm) Message(EInformation, KGotIt);
       
    64 			else Message(EInformation, KNotGotIt);
       
    65 			}
       
    66 
       
    67 		if (!gotAcm)
       
    68 			{
       
    69 			// We're not enumerated, or we are but don't have ACM. So wait for a (re-)enumeration
       
    70 			_LIT(KWaitingForEnumeration, "Waiting for USB enumeration (please connect USB cable)");
       
    71 			Message(EInformation, KWaitingForEnumeration);
       
    72 			iUsb.DeviceStateNotification(EUsbDeviceStateConfigured, usbState, stat);
       
    73 			User::WaitForRequest(stat);
       
    74 			if (stat.Int() != KErrNone)
       
    75 				{
       
    76 				_LIT(KUsbError, "Error configuring USB: %d");
       
    77 				Message(EError, KUsbError, stat.Int());
       
    78 				User::Leave(stat.Int());
       
    79 				}
       
    80 			_LIT(KUsbEnumerated, "USB cable connected.");
       
    81 			Message(EInformation, KUsbEnumerated);
       
    82 			}
       
    83 		}
       
    84 	
       
    85 	// Run the preamble script, if we have one. Because iosrv is multithreaded this shouldn't cause a deadlock so long as we use a different console (in this case, nullcons)
       
    86 	_LIT(KPreamble, "--console nullcons vt100usbcons_preamble");
       
    87 	RProcess preamble;
       
    88 	TInt err = preamble.Create(_L("fshell.exe"), KPreamble);
       
    89 	if (err == KErrNone)
       
    90 		{
       
    91 		preamble.Logon(stat);
       
    92 		if (stat == KRequestPending)
       
    93 			{
       
    94 			preamble.Resume();
       
    95 			User::WaitForRequest(stat);
       
    96 			}
       
    97 		err = stat.Int();
       
    98 		preamble.Close();
       
    99 		}
       
   100 
       
   101 	if (err == KErrNone)
       
   102 		{
       
   103 		Message(EInformation, _L("Preamble script ran ok"));
       
   104 		}
       
   105 	else if (err != KErrNotFound)
       
   106 		{
       
   107 		Message(EInformation, _L("Preamble script failed with %d"), err);
       
   108 		}
       
   109 
       
   110 	//TODO should we ensure that the port passed in here is an ACM::%s port?
       
   111 	Message(EInformation, _L("Opening %S"), &aTitle);
       
   112 	CVtcSerialConsole::ConstructL(aTitle);
       
   113 	}