commands/usb/usb.cpp
changeset 77 60f47003f4b1
parent 0 7f656887cf89
equal deleted inserted replaced
74:4349d4d62266 77:60f47003f4b1
    66 void CCmdUsb::OptionsL(RCommandOptionList& /*aOptions*/)
    66 void CCmdUsb::OptionsL(RCommandOptionList& /*aOptions*/)
    67 	{
    67 	{
    68 	}
    68 	}
    69 
    69 
    70 #define CASE_LIT(x) case x: { _LIT(KName, #x); return &KName; }
    70 #define CASE_LIT(x) case x: { _LIT(KName, #x); return &KName; }
       
    71 #define CASE_LIT2(x, y) case x: { _LIT(KName, y); return &KName; }
       
    72 
       
    73 _LIT(KUnknown, "?");
    71 
    74 
    72 const TDesC* DeviceState(TUsbDeviceState aState)
    75 const TDesC* DeviceState(TUsbDeviceState aState)
    73 	{
    76 	{
    74 	switch (aState)
    77 	switch (aState)
    75 		{
    78 		{
    80 		CASE_LIT(EUsbDeviceStateConfigured);
    83 		CASE_LIT(EUsbDeviceStateConfigured);
    81 		CASE_LIT(EUsbDeviceStateAddress);
    84 		CASE_LIT(EUsbDeviceStateAddress);
    82 		CASE_LIT(EUsbDeviceStateSuspended);
    85 		CASE_LIT(EUsbDeviceStateSuspended);
    83 		default:
    86 		default:
    84 			{
    87 			{
    85 			_LIT(KUnknown, "?");
       
    86 			return &KUnknown;
    88 			return &KUnknown;
    87 			}
    89 			}
    88 		}
    90 		}
    89 	}
    91 	}
    90 
    92 
    96 		CASE_LIT(EUsbServiceStarting);
    98 		CASE_LIT(EUsbServiceStarting);
    97 		CASE_LIT(EUsbServiceStarted);
    99 		CASE_LIT(EUsbServiceStarted);
    98 		CASE_LIT(EUsbServiceStopping);
   100 		CASE_LIT(EUsbServiceStopping);
    99 		CASE_LIT(EUsbServiceFatalError);
   101 		CASE_LIT(EUsbServiceFatalError);
   100 		default:
   102 		default:
   101 			{
       
   102 			_LIT(KUnknown, "?");
       
   103 			return &KUnknown;
   103 			return &KUnknown;
   104 			}
   104 		}
       
   105 	}
       
   106 
       
   107 const TDesC* ClassName(TUid aClass)
       
   108 	{
       
   109 	switch (aClass.iUid)
       
   110 		{
       
   111 		CASE_LIT2(0x101FBF22, "ACM");
       
   112 		CASE_LIT2(0x101fbf24, "Obex");
       
   113 		CASE_LIT2(0x10204bbc, "Mass storage");
       
   114 		default:
       
   115 			return &KUnknown;
   105 		}
   116 		}
   106 	}
   117 	}
   107 
   118 
   108 void CCmdUsb::DoRunL()
   119 void CCmdUsb::DoRunL()
   109 	{
   120 	{
   116 	TUsbServiceState servicestate;
   127 	TUsbServiceState servicestate;
   117 	LeaveIfErr(iUsb.GetServiceState(servicestate), _L("Couldn't get service state"));
   128 	LeaveIfErr(iUsb.GetServiceState(servicestate), _L("Couldn't get service state"));
   118 	Printf(_L("Usb Service state = %S (%d)\r\n"), ServiceState(servicestate), servicestate);
   129 	Printf(_L("Usb Service state = %S (%d)\r\n"), ServiceState(servicestate), servicestate);
   119 
   130 
   120 	RArray<TInt> ids;
   131 	RArray<TInt> ids;
       
   132 	CleanupClosePushL(ids);
   121 	LeaveIfErr(iUsb.GetPersonalityIds(ids), _L("Couldn't get personalities ids"));
   133 	LeaveIfErr(iUsb.GetPersonalityIds(ids), _L("Couldn't get personalities ids"));
   122 	for (TInt i = 0; i < ids.Count(); i++)
   134 	for (TInt i = 0; i < ids.Count(); i++)
   123 		{
   135 		{
   124 		Printf(_L("Personality %d\r\n"), ids[i]);
   136 		Printf(_L("Personality %d\r\n"), ids[i]);
       
   137 		RArray<TUid> classUids;
       
   138 		CleanupClosePushL(classUids);
       
   139 		TInt err = iUsb.GetSupportedClasses(ids[i], classUids);
       
   140 		if (err)
       
   141 			{
       
   142 			PrintWarning(_L("Couldn't get classes for personality %d, err=%d"), ids[i], err);
       
   143 			}
       
   144 		else
       
   145 			{
       
   146 			for (TInt classIdx = 0; classIdx < classUids.Count(); classIdx++)
       
   147 				{
       
   148 				Printf(_L("    0x%08x (%S)\r\n"), classUids[classIdx], ClassName(classUids[classIdx]));
       
   149 				}
       
   150 			}
       
   151 		CleanupStack::PopAndDestroy(&classUids);
   125 		}
   152 		}
   126 
   153 
   127 	if (iArguments.IsPresent(&iPersonality))
   154 	if (iArguments.IsPresent(&iPersonality))
   128 		{
   155 		{
   129 		TRequestStatus stat;
   156 		TRequestStatus stat;
   130 		iUsb.TryStart(iPersonality, stat);
   157 		iUsb.TryStart(iPersonality, stat);
   131 		User::WaitForRequest(stat);
   158 		User::WaitForRequest(stat);
   132 		LeaveIfErr(stat.Int(), _L("Couldn't start USB personality %d"), iPersonality);
   159 		LeaveIfErr(stat.Int(), _L("Couldn't start USB personality %d"), iPersonality);
   133 		Printf(_L("USB started ok.\r\n"));
   160 		Printf(_L("USB started ok.\r\n"));
   134 		}
   161 		}
       
   162 	CleanupStack::PopAndDestroy(&ids);
   135 	}
   163 	}