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 if ( KErrAlreadyExists == ret ) |
|
54 { |
|
55 LOG( "UsbWatcher is already running." ); |
|
56 } |
|
57 else if ( KErrNone != ret ) |
|
58 { |
|
59 LOG1( "ERROR: StartUsbWatcherL = %d", ret ); |
|
60 } |
|
61 |
|
62 delete cleanup; // destroy clean-up stack |
|
63 __UHEAP_MARKEND; |
|
64 |
|
65 LOG1( "E32Main = %d", ret ); |
|
66 return ret; |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // Constructs and installs the active scheduler, constructs USB Watcher's |
|
71 // objects. |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 static void StartUsbWatcherL() |
|
75 { |
|
76 LOG_FUNC |
|
77 LOG( "Starting USB Watcher..." ); |
|
78 |
|
79 LOG( "Create CUsbWatcherScheduler..." ); |
|
80 // Construct and install the active scheduler |
|
81 CUsbWatcherScheduler *myScheduler = CUsbWatcherScheduler::NewL(); |
|
82 |
|
83 // Push onto the cleanup stack |
|
84 CleanupStack::PushL( myScheduler ); |
|
85 |
|
86 LOG( "Install ActiveScheduler..." ); |
|
87 // Install as the active scheduler |
|
88 CActiveScheduler::Install( myScheduler ); |
|
89 |
|
90 CUsbWatcherServer* usbwatcher; |
|
91 |
|
92 LOG( "Create CUsbWatcherServer..." ); |
|
93 usbwatcher = CUsbWatcherServer::NewLC(); |
|
94 RProcess::Rendezvous(KErrNone); |
|
95 |
|
96 LOG( "Set server..." ); |
|
97 myScheduler->SetServer( *usbwatcher ); |
|
98 |
|
99 |
|
100 LOG( "Start Active scheduler..." ); |
|
101 CActiveScheduler::Start(); |
|
102 |
|
103 LOG( "Cleanup CUsbWatcherServer and CUsbWatcherScheduler ..." ); |
|
104 CleanupStack::PopAndDestroy( 2, myScheduler ); //usbwatcher, myScheduler |
|
105 } |
|
106 |
|
107 // End of file |
|