|
1 /* |
|
2 * Copyright (c) 2008-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 */ |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include "msmmengine.h" |
|
24 #include "msmmnodebase.h" |
|
25 |
|
26 #include <usb/usblogger.h> |
|
27 |
|
28 #ifdef __FLOG_ACTIVE |
|
29 _LIT8(KLogComponent, "UsbHostMsmmServer"); |
|
30 #endif |
|
31 |
|
32 CMsmmEngine::~CMsmmEngine() |
|
33 { |
|
34 LOG_FUNC |
|
35 if (iDataEntrys) |
|
36 { |
|
37 delete iDataEntrys; |
|
38 } |
|
39 } |
|
40 |
|
41 CMsmmEngine* CMsmmEngine::NewL() |
|
42 { |
|
43 LOG_STATIC_FUNC_ENTRY |
|
44 CMsmmEngine* self = CMsmmEngine::NewLC(); |
|
45 CleanupStack::Pop(self); |
|
46 |
|
47 return self; |
|
48 } |
|
49 |
|
50 CMsmmEngine* CMsmmEngine::NewLC() |
|
51 { |
|
52 LOG_STATIC_FUNC_ENTRY |
|
53 CMsmmEngine* self = new (ELeave) CMsmmEngine(); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(); |
|
56 |
|
57 return self; |
|
58 } |
|
59 |
|
60 void CMsmmEngine::AddUsbMsDeviceL(const TUSBMSDeviceDescription& aDevice) |
|
61 { |
|
62 LOG_FUNC |
|
63 TUsbMsDevice* device = SearchDevice(aDevice.iDeviceId); |
|
64 if (!device) |
|
65 { |
|
66 device = new (ELeave) TUsbMsDevice(aDevice); |
|
67 iDataEntrys->AddChild(device); |
|
68 } |
|
69 } |
|
70 |
|
71 TUsbMsInterface* CMsmmEngine::AddUsbMsInterfaceL(TInt aDeviceId, TUint8 aInterfaceNumber, |
|
72 TInt32 aInterfaceToken) |
|
73 { |
|
74 LOG_FUNC |
|
75 TUsbMsDevice* device = SearchDevice(aDeviceId); |
|
76 if (!device) |
|
77 { |
|
78 User::Leave(KErrArgument); |
|
79 } |
|
80 TUsbMsInterface* interface = |
|
81 SearchInterface(device, aInterfaceNumber); |
|
82 if (interface) |
|
83 { |
|
84 User::Leave(KErrAlreadyExists); |
|
85 } |
|
86 else |
|
87 { |
|
88 interface = AddUsbMsInterfaceNodeL(device, aInterfaceNumber, aInterfaceToken); |
|
89 } |
|
90 return interface; |
|
91 } |
|
92 |
|
93 void CMsmmEngine::AddUsbMsLogicalUnitL(TInt aDeviceId, |
|
94 TInt aInterfaceNumber, TInt aLogicalUnitNumber, TText aDrive) |
|
95 { |
|
96 LOG_FUNC |
|
97 TUsbMsDevice* device = SearchDevice(aDeviceId); |
|
98 if (!device) |
|
99 { |
|
100 User::Leave(KErrArgument); // A proper device node can't be found |
|
101 } |
|
102 |
|
103 TUsbMsInterface* interface = SearchInterface(device, aInterfaceNumber); |
|
104 if (interface) |
|
105 { |
|
106 AddUsbMsLogicalUnitNodeL(interface, aLogicalUnitNumber, aDrive); |
|
107 } |
|
108 else |
|
109 { |
|
110 User::Leave(KErrArgument); // A proper interface node can't be found |
|
111 } |
|
112 } |
|
113 |
|
114 void CMsmmEngine::RemoveUsbMsNode(TMsmmNodeBase* aNodeToBeRemoved) |
|
115 { |
|
116 LOG_FUNC |
|
117 delete aNodeToBeRemoved; |
|
118 } |
|
119 |
|
120 TUsbMsDevice* CMsmmEngine::SearchDevice(TInt aDeviceId) const |
|
121 { |
|
122 LOG_FUNC |
|
123 return static_cast<TUsbMsDevice*>( |
|
124 iDataEntrys->SearchInChildren(aDeviceId)); |
|
125 } |
|
126 |
|
127 TUsbMsInterface* CMsmmEngine::SearchInterface(TMsmmNodeBase* aDevice, |
|
128 TInt aInterfaceNumber) const |
|
129 { |
|
130 LOG_FUNC |
|
131 return static_cast<TUsbMsInterface*>( |
|
132 aDevice->SearchInChildren(aInterfaceNumber)); |
|
133 } |
|
134 |
|
135 CMsmmEngine::CMsmmEngine() |
|
136 { |
|
137 LOG_FUNC |
|
138 } |
|
139 |
|
140 void CMsmmEngine::ConstructL() |
|
141 { |
|
142 LOG_FUNC |
|
143 // Create the root of the whole node tree |
|
144 iDataEntrys = new (ELeave) TMsmmNodeBase(0x0); |
|
145 } |
|
146 |
|
147 TUsbMsInterface* CMsmmEngine::AddUsbMsInterfaceNodeL(TUsbMsDevice* iParent, |
|
148 TInt aInterfaceNumber, TInt aInterfaceToken) |
|
149 { |
|
150 LOG_FUNC |
|
151 TUsbMsInterface* interface = new (ELeave) TUsbMsInterface( |
|
152 aInterfaceNumber, aInterfaceToken); |
|
153 iParent->AddChild(interface); |
|
154 |
|
155 return interface; |
|
156 } |
|
157 |
|
158 TUsbMsLogicalUnit* CMsmmEngine::AddUsbMsLogicalUnitNodeL( |
|
159 TUsbMsInterface* iParent, TInt aLogicalUnitNumber, |
|
160 TText aDrive) |
|
161 { |
|
162 LOG_FUNC |
|
163 TUsbMsLogicalUnit* logicalUnit = new (ELeave) TUsbMsLogicalUnit( |
|
164 aLogicalUnitNumber, aDrive); |
|
165 iParent->AddChild(logicalUnit); |
|
166 |
|
167 return logicalUnit; |
|
168 } |
|
169 |
|
170 // End of file |