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; | |
18 | import org.eclipse.linuxtools.tmf.request.ITmfDataRequest; | |
19 | import org.eclipse.linuxtools.tmf.request.ITmfEventRequest; | |
20 | import org.eclipse.linuxtools.tmf.request.TmfEventRequest; | |
21 | import org.eclipse.linuxtools.tmf.trace.ITmfContext; | |
22 | import org.eclipse.linuxtools.tmf.trace.TmfContext; | |
23 | ||
24 | /** | |
25 | * <b><u>TmfSyntheticEventProviderStub</u></b> | |
26 | * <p> | |
27 | * TODO: Implement me. Please. | |
28 | */ | |
29 | public class TmfSyntheticEventProviderStub extends TmfEventProvider<TmfSyntheticEventStub> { | |
30 | ||
31 | public static final int BLOCK_SIZE = 100; | |
32 | public static final int NB_EVENTS = 1000; | |
33 | ||
34 | public TmfSyntheticEventProviderStub() { | |
35 | super("TmfSyntheticEventProviderStub", TmfSyntheticEventStub.class); | |
36 | } | |
37 | ||
38 | @SuppressWarnings("unchecked") | |
39 | @Override | |
40 | public ITmfContext armRequest(final ITmfDataRequest<TmfSyntheticEventStub> request) { | |
41 | ||
42 | // Get the TmfSyntheticEventStub provider | |
43 | ITmfDataProvider<TmfEvent>[] eventProviders = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfEventProviderStub.class); | |
44 | ITmfDataProvider<TmfEvent> provider = eventProviders[0]; | |
45 | ||
46 | // make sure we have the right type of request | |
47 | if (!(request instanceof ITmfEventRequest<?>)) { | |
48 | request.cancel(); | |
49 | return null; | |
50 | } | |
51 | ||
52 | TmfEventRequest<TmfSyntheticEventStub> eventRequest = (TmfEventRequest<TmfSyntheticEventStub>) request; | |
53 | TmfTimeRange range = eventRequest.getRange(); | |
54 | final TmfEventRequest<TmfEvent> subRequest = | |
55 | new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { | |
56 | @Override | |
57 | public void handleData() { | |
58 | TmfEvent[] events = getData(); | |
59 | if (events.length > 0) { | |
60 | for (TmfEvent e : events) { | |
61 | handleIncomingData(e); | |
62 | } | |
63 | } else { | |
64 | request.done(); | |
65 | } | |
66 | } | |
67 | }; | |
9aae0442 | 68 | provider.sendRequest(subRequest); |
d18dd09b ASL |
69 | |
70 | // Return a dummy context | |
71 | return new TmfContext(); | |
72 | } | |
73 | ||
74 | // Queue 2 synthetic events per base event | |
75 | private void handleIncomingData(TmfEvent e) { | |
9aae0442 ASL |
76 | try { |
77 | queueResult(new TmfSyntheticEventStub(e)); | |
78 | queueResult(new TmfSyntheticEventStub(e)); | |
79 | } catch (InterruptedException e1) { | |
80 | e1.printStackTrace(); | |
81 | } | |
82 | } | |
83 | ||
84 | @Override | |
85 | public void sendRequest(ITmfDataRequest<TmfSyntheticEventStub> request, ExecutionType execType) { | |
86 | super.sendRequest(request, execType); | |
87 | } | |
88 | ||
89 | @Override | |
90 | public void sendRequest(ITmfDataRequest<TmfSyntheticEventStub> request) { | |
91 | super.sendRequest(request); | |
d18dd09b ASL |
92 | } |
93 | ||
94 | } |