Commit | Line | Data |
---|---|---|
d18dd09b ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.component; | |
14 | ||
15 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
16 | import org.eclipse.linuxtools.tmf.event.TmfSyntheticEventStub; | |
17 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
fc6ccf6f | 18 | import org.eclipse.linuxtools.tmf.request.TmfDataRequest; |
d18dd09b ASL |
19 | import org.eclipse.linuxtools.tmf.request.TmfEventRequest; |
20 | import org.eclipse.linuxtools.tmf.trace.ITmfContext; | |
21 | import org.eclipse.linuxtools.tmf.trace.TmfContext; | |
22 | ||
23 | /** | |
24 | * <b><u>TmfSyntheticEventProviderStub</u></b> | |
25 | * <p> | |
26 | * TODO: Implement me. Please. | |
27 | */ | |
28 | public class TmfSyntheticEventProviderStub extends TmfEventProvider<TmfSyntheticEventStub> { | |
29 | ||
30 | public static final int BLOCK_SIZE = 100; | |
31 | public static final int NB_EVENTS = 1000; | |
32 | ||
33 | public TmfSyntheticEventProviderStub() { | |
fc6ccf6f | 34 | super(TmfSyntheticEventStub.class); |
d18dd09b ASL |
35 | } |
36 | ||
37 | @SuppressWarnings("unchecked") | |
38 | @Override | |
fc6ccf6f | 39 | public ITmfContext armRequest(final TmfDataRequest<TmfSyntheticEventStub> request) { |
d18dd09b ASL |
40 | |
41 | // Get the TmfSyntheticEventStub provider | |
fc6ccf6f FC |
42 | TmfDataProvider<TmfEvent>[] eventProviders = (TmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfEventProviderStub.class); |
43 | TmfDataProvider<TmfEvent> provider = eventProviders[0]; | |
d18dd09b ASL |
44 | |
45 | // make sure we have the right type of request | |
fc6ccf6f | 46 | if (!(request instanceof TmfEventRequest<?>)) { |
d18dd09b ASL |
47 | request.cancel(); |
48 | return null; | |
49 | } | |
50 | ||
51 | TmfEventRequest<TmfSyntheticEventStub> eventRequest = (TmfEventRequest<TmfSyntheticEventStub>) request; | |
52 | TmfTimeRange range = eventRequest.getRange(); | |
53 | final TmfEventRequest<TmfEvent> subRequest = | |
54 | new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { | |
55 | @Override | |
56 | public void handleData() { | |
57 | TmfEvent[] events = getData(); | |
58 | if (events.length > 0) { | |
59 | for (TmfEvent e : events) { | |
60 | handleIncomingData(e); | |
61 | } | |
62 | } else { | |
63 | request.done(); | |
64 | } | |
65 | } | |
66 | }; | |
fc6ccf6f | 67 | provider.processRequest(subRequest, false); |
d18dd09b ASL |
68 | |
69 | // Return a dummy context | |
70 | return new TmfContext(); | |
71 | } | |
72 | ||
73 | // Queue 2 synthetic events per base event | |
74 | private void handleIncomingData(TmfEvent e) { | |
fc6ccf6f FC |
75 | queueResult(new TmfSyntheticEventStub(e)); |
76 | queueResult(new TmfSyntheticEventStub(e)); | |
d18dd09b ASL |
77 | } |
78 | ||
79 | } |