|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Startusb.cpp |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include <e32test.h> |
|
22 #include <e32twin.h> |
|
23 #include <c32comm.h> |
|
24 #include <d32comm.h> |
|
25 #include <f32file.h> |
|
26 #include <hal.h> |
|
27 #include <usbman.h> |
|
28 |
|
29 static TInt MainL() |
|
30 { |
|
31 RDebug::Print(_L("Main() - Starting!")); |
|
32 |
|
33 RFs theFs; |
|
34 |
|
35 TInt r = theFs.Connect(); |
|
36 if (r != KErrNone) |
|
37 { |
|
38 RDebug::Print(_L("Main() - Failed to connect to the fs. Error = %d"), r); |
|
39 return r; |
|
40 } |
|
41 |
|
42 RDebug::Print(_L("Main() - Connected to file server")); |
|
43 |
|
44 r = StartC32(); |
|
45 if (r!=KErrNone && r !=KErrAlreadyExists) |
|
46 { |
|
47 RDebug::Print(_L("Main() - Failed to start C32. Error = %d"), r); |
|
48 return r; |
|
49 } |
|
50 |
|
51 RDebug::Print(_L("E32Main: Started c32")); |
|
52 |
|
53 RUsb usb; |
|
54 TInt err = usb.Connect(); |
|
55 if (err != KErrNone) |
|
56 { |
|
57 RDebug::Print(_L("MainL() - Unable to Connect to USB server")); |
|
58 theFs.Close(); |
|
59 return err; |
|
60 } |
|
61 RDebug::Print(_L("MainL() - Connected to USB server")); |
|
62 |
|
63 TUsbServiceState state; |
|
64 |
|
65 err = usb.GetCurrentState(state); |
|
66 if (err != KErrNone) |
|
67 { |
|
68 RDebug::Print(_L("MainL() - Failed to fetch service state from usbman, error %d"), err); |
|
69 } |
|
70 else |
|
71 { |
|
72 RDebug::Print(_L("MainL() - Usb service state = 0x%x"), state); |
|
73 } |
|
74 |
|
75 TRequestStatus status; |
|
76 usb.Start(status); |
|
77 User::WaitForRequest(status); |
|
78 |
|
79 if (status.Int() != KErrNone) |
|
80 { |
|
81 RDebug::Print(_L("MainL() - Unable to start USB services. Error %d"), status.Int()); |
|
82 theFs.Close(); |
|
83 return status.Int(); |
|
84 } |
|
85 |
|
86 err = usb.GetCurrentState(state); |
|
87 if (err != KErrNone) |
|
88 { |
|
89 RDebug::Print(_L("MainL() - Failed to fetch service state from usbman, error %d"), err); |
|
90 } |
|
91 else |
|
92 { |
|
93 RDebug::Print(_L("MainL() - Usb service state = 0x%x"), state); |
|
94 } |
|
95 |
|
96 RDebug::Print(_L("MainL() - Started USB services")); |
|
97 usb.Close(); |
|
98 theFs.Close(); |
|
99 RDebug::Print(_L("MainL() - Exiting normally")); |
|
100 return KErrNone; |
|
101 } |
|
102 |
|
103 GLDEF_C TInt E32Main() |
|
104 { |
|
105 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
106 if(cleanup == NULL) |
|
107 { |
|
108 return KErrNoMemory; |
|
109 } |
|
110 TRAPD(err,err=MainL()); |
|
111 |
|
112 if (err != KErrNone) |
|
113 User::Panic(_L("StartUsb::E32Main - Panic"), err); |
|
114 |
|
115 delete cleanup; |
|
116 return err; |
|
117 } |
|
118 /////////////////////// |