|
1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Trace Core |
|
15 // |
|
16 |
|
17 #include "TraceCoreSendReceive.h" |
|
18 #include "TraceCorePluginIf.h" |
|
19 #include "TraceCoreRouter.h" |
|
20 #include "TraceCoreDebug.h" |
|
21 #include "TraceCoreOstLddIf.h" |
|
22 #include "OstTraceDefinitions.h" |
|
23 #ifdef OST_TRACE_COMPILER_IN_USE |
|
24 #include "TraceCoreSendReceiveTraces.h" |
|
25 #endif |
|
26 |
|
27 |
|
28 /** |
|
29 * Constructor |
|
30 */ |
|
31 DTraceCoreSendReceive::DTraceCoreSendReceive() |
|
32 : iPluginInterface( NULL ) |
|
33 , iSendInterface( NULL ) |
|
34 , iMediaWriterInterface( NULL ) |
|
35 , iReceiver( NULL ) |
|
36 { |
|
37 } |
|
38 |
|
39 |
|
40 /** |
|
41 * Destructor |
|
42 */ |
|
43 DTraceCoreSendReceive::~DTraceCoreSendReceive() |
|
44 { |
|
45 DeleteInterfaces(); |
|
46 iReceiver = NULL; |
|
47 } |
|
48 |
|
49 |
|
50 /** |
|
51 * Initializer creates the ISA IF and router |
|
52 */ |
|
53 TInt DTraceCoreSendReceive::Init( MTraceCoreMessageReceiver& aReceiver ) |
|
54 { |
|
55 // Create interfaces |
|
56 TInt ret = CreateInterfaces(); |
|
57 if ( ret == KErrNone ) |
|
58 { |
|
59 // Initialize all Media interfaces |
|
60 for ( int i = 0; i < iMediaInterfaces.Count() && ret == KErrNone; i++ ) |
|
61 { |
|
62 DTraceCoreMediaIf* mediaIf = iMediaInterfaces[ i ]; |
|
63 ret = InitMediaInterface( mediaIf ); |
|
64 } |
|
65 if ( ret == KErrNone ) |
|
66 { |
|
67 iReceiver = &aReceiver; |
|
68 } |
|
69 else |
|
70 { |
|
71 DeleteInterfaces(); |
|
72 } |
|
73 } |
|
74 TC_TRACE( ETraceLevelFlow, Kern::Printf( "<DTraceCoreSendReceive::Init() - %d", ret ) ) |
|
75 return ret; |
|
76 } |
|
77 |
|
78 |
|
79 /** |
|
80 * Initializes a media interface |
|
81 */ |
|
82 TInt DTraceCoreSendReceive::InitMediaInterface( DTraceCoreMediaIf* aMediaIf ) |
|
83 { |
|
84 TInt ret = aMediaIf->Init( *this ); |
|
85 if ( ret == KErrNone ) |
|
86 { |
|
87 TUint32 flags = aMediaIf->GetFlags(); |
|
88 // First interface that supports sending is stored as the send interface. |
|
89 // TODO: Add a TraceCore message which can select the interface used for sending |
|
90 if ( iSendInterface == NULL && ( flags & KMediaIfSendSupported ) ) |
|
91 { |
|
92 iSendInterface = aMediaIf; |
|
93 } |
|
94 // First interface that can write traces is stored to iMediaWriterInterface |
|
95 // TODO: Add a TraceCore message which can select the interface used by the writer |
|
96 if ( iMediaWriterInterface == NULL && ( flags & KMediaIfSendTraceSupported ) ) |
|
97 { |
|
98 iMediaWriterInterface = aMediaIf; |
|
99 } |
|
100 // If the plug-in interface is present, it is stored to iPluginInterface |
|
101 if ( iPluginInterface == NULL && ( flags & KMediaIfPluginSupported ) ) |
|
102 { |
|
103 iPluginInterface = static_cast< DTraceCorePluginIf* >( aMediaIf ); |
|
104 } |
|
105 } |
|
106 TC_TRACE( ETraceLevelFlow, Kern::Printf( "<DTraceCoreSendReceive::InitMediaInterface() - %d", ret ) ); |
|
107 return ret; |
|
108 } |
|
109 |
|
110 |
|
111 /** |
|
112 * Creates the media interfaces. This is platform-specific code |
|
113 */ |
|
114 TInt DTraceCoreSendReceive::CreateInterfaces() |
|
115 { |
|
116 TInt ret( KErrNoMemory ); |
|
117 #ifdef __WINS__ |
|
118 DTraceCoreMediaIf* pluginIf = new DTraceCorePluginIf(); |
|
119 if ( pluginIf != NULL ) |
|
120 { |
|
121 ret = iMediaInterfaces.Append( pluginIf ); |
|
122 } |
|
123 // this is a bit of a hack here for now |
|
124 // we create a DTraceCoreOstLddIf as the writer interface |
|
125 if( ret == KErrNone) |
|
126 { |
|
127 DTraceCoreMediaIf* ostLddIf = new DTraceCoreOstLddIf(); |
|
128 if ( ostLddIf != NULL) |
|
129 { |
|
130 ret = iMediaInterfaces.Append( ostLddIf ); |
|
131 } |
|
132 } |
|
133 #else |
|
134 // - Plug-in API for media plug-in's. Incoming / outgoing messages. |
|
135 // - ISA for incoming messages and media writer output |
|
136 DTraceCoreMediaIf* pluginIf = new DTraceCorePluginIf(); |
|
137 DTraceCoreMediaIf* usbIf = new DTraceCoreOstLddIf(); |
|
138 |
|
139 if ( pluginIf != NULL && usbIf!= NULL ) |
|
140 { |
|
141 ret = iMediaInterfaces.Append( pluginIf ); |
|
142 ret = ( ret == KErrNone ) ? iMediaInterfaces.Append( usbIf ) : ret; |
|
143 } |
|
144 #endif // __WINS__ |
|
145 |
|
146 TC_TRACE( ETraceLevelFlow, Kern::Printf( "<DTraceCoreSendReceive::CreateInterfaces()" ) ); |
|
147 return ret; |
|
148 } |
|
149 |
|
150 |
|
151 /** |
|
152 * Deletes the media interfaces |
|
153 */ |
|
154 void DTraceCoreSendReceive::DeleteInterfaces() |
|
155 { |
|
156 // Delete all interfaces |
|
157 iMediaInterfaces.ResetAndDestroy(); |
|
158 iSendInterface = NULL; |
|
159 iMediaWriterInterface = NULL; |
|
160 iPluginInterface = NULL; |
|
161 } |
|
162 |
|
163 |
|
164 /** |
|
165 * Delegates the incoming message to the router |
|
166 * |
|
167 * @param aMsg The message that was received |
|
168 * @return KErrNotFound if the message id was not found (not subscribed), KErrNone if found |
|
169 */ |
|
170 TInt DTraceCoreSendReceive::MessageReceived( TTraceMessage &aMsg ) |
|
171 { |
|
172 OstTrace1( TRACE_FLOW, DTRACECORESENDRECEIVE_MESSAGERECEIVED_ENTRY, "> DTraceCoreSendReceive::MessageReceived - %d", &aMsg); |
|
173 TInt ret( KErrNotFound ); |
|
174 if ( iReceiver != NULL ) |
|
175 { |
|
176 ret = iReceiver->MessageReceived( aMsg ); |
|
177 } |
|
178 OstTrace1( TRACE_FLOW, DTRACECORESENDRECEIVE_MESSAGERECEIVED_EXIT, "< DTraceCoreSendReceive::MessageReceived - %d",ret); |
|
179 return ret; |
|
180 } |
|
181 |
|
182 /** |
|
183 * Set Sender Media |
|
184 * |
|
185 * @param Sender media |
|
186 */ |
|
187 TInt DTraceCoreSendReceive::SetSenderMedia(DTraceCoreMediaIf* aSenderMedia) |
|
188 { |
|
189 if (aSenderMedia != NULL) |
|
190 { |
|
191 TUint32 flags = aSenderMedia->GetFlags(); |
|
192 if (flags & KMediaIfSendSupported) |
|
193 { |
|
194 iSendInterface = aSenderMedia; |
|
195 } |
|
196 if (flags & KMediaIfSendTraceSupported) |
|
197 { |
|
198 iMediaWriterInterface = aSenderMedia; |
|
199 } |
|
200 } |
|
201 return KErrNone; |
|
202 } |
|
203 |
|
204 |
|
205 /** |
|
206 * Sends a message to media interface |
|
207 * |
|
208 * @param aMessage The message to be sent |
|
209 */ |
|
210 TInt DTraceCoreSendReceive::SendMessage( TTraceMessage &aMessage ) |
|
211 { |
|
212 TInt retval = KErrGeneral; |
|
213 if ( iSendInterface != NULL ) |
|
214 { |
|
215 // Send the message |
|
216 retval = iSendInterface->Send( aMessage ); |
|
217 } |
|
218 OstTrace1( TRACE_FLOW, DTRACECORESENDRECEIVE_SENDMESSAGE_EXIT, "DTraceCoreSendReceive::SendMessage %d", retval ); |
|
219 return retval; |
|
220 } |
|
221 |
|
222 // End of File |