|
1 /* |
|
2 * Copyright (c) 2002-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: Entry point for UsbWatcher |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <c32comm.h> |
|
20 #include "cusbwatcher.h" |
|
21 #include "cusbwatcherscheduler.h" |
|
22 #include "cusbwatcherserver.h" |
|
23 #include "usbwatchershared.h" |
|
24 |
|
25 // LITERALS |
|
26 _LIT( KUsbWatcherName, "UsbWatcher" ); |
|
27 |
|
28 // LOCAL FUNCTION PROTOTYPES |
|
29 static void StartUsbWatcherL(); |
|
30 |
|
31 // ============================= LOCAL FUNCTIONS ============================== |
|
32 |
|
33 // ---------------------------------------------------------------------------- |
|
34 // Entry-point for the USB Watcher. |
|
35 // ---------------------------------------------------------------------------- |
|
36 // |
|
37 TInt E32Main() |
|
38 { |
|
39 LOG_FUNC |
|
40 |
|
41 // rename the thread so it is easy to find the panic application |
|
42 TInt ret = User::RenameThread( KUsbWatcherName ); |
|
43 if( KErrNone != ret ) // Not fatal |
|
44 { |
|
45 LOG1( "ERROR: User::RenameThread = %d", ret ); |
|
46 } |
|
47 |
|
48 __UHEAP_MARK; |
|
49 // create clean-up stack |
|
50 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
51 |
|
52 TRAP( ret, StartUsbWatcherL() ); |
|
53 |
|
54 delete cleanup; // destroy clean-up stack |
|
55 __UHEAP_MARKEND; |
|
56 |
|
57 LOG1( "E32Main = %d", ret ); |
|
58 return ret; |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // Constructs and installs the active scheduler, constructs USB Watcher's |
|
63 // objects. |
|
64 // ---------------------------------------------------------------------------- |
|
65 // |
|
66 static void StartUsbWatcherL() |
|
67 { |
|
68 LOG_FUNC |
|
69 LOG( "Starting USB Watcher..." ); |
|
70 |
|
71 LOG( "Create CUsbWatcherScheduler..." ); |
|
72 // Construct and install the active scheduler |
|
73 CUsbWatcherScheduler *myScheduler = CUsbWatcherScheduler::NewL(); |
|
74 |
|
75 // Push onto the cleanup stack |
|
76 CleanupStack::PushL( myScheduler ); |
|
77 |
|
78 LOG( "Install ActiveScheduler..." ); |
|
79 // Install as the active scheduler |
|
80 CActiveScheduler::Install( myScheduler ); |
|
81 |
|
82 CUsbWatcherServer* usbwatcher; |
|
83 |
|
84 LOG( "Create CUsbWatcherServer..." ); |
|
85 usbwatcher = CUsbWatcherServer::NewLC(); |
|
86 RProcess::Rendezvous(KErrNone); |
|
87 |
|
88 LOG( "Set server..." ); |
|
89 myScheduler->SetServer( *usbwatcher ); |
|
90 |
|
91 |
|
92 LOG( "Start Active scheduler..." ); |
|
93 CActiveScheduler::Start(); |
|
94 |
|
95 LOG( "Cleanup CUsbWatcherServer and CUsbWatcherScheduler ..." ); |
|
96 CleanupStack::PopAndDestroy( 2, myScheduler ); //usbwatcher, myScheduler |
|
97 } |
|
98 |
|
99 // End of file |