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 | ||
cbd4ad82 FC |
37 | @Override |
38 | public void register() { | |
39 | super.register(); | |
40 | } | |
41 | ||
54d55ced FC |
42 | @Override |
43 | public void deregister() { | |
44 | super.deregister(); | |
45 | } | |
46 | ||
d18dd09b ASL |
47 | @SuppressWarnings("unchecked") |
48 | @Override | |
fc6ccf6f | 49 | public ITmfContext armRequest(final TmfDataRequest<TmfSyntheticEventStub> request) { |
d18dd09b ASL |
50 | |
51 | // Get the TmfSyntheticEventStub provider | |
951d134a FC |
52 | ITmfDataProvider<TmfEvent>[] eventProviders = (ITmfDataProvider<TmfEvent>[]) TmfProviderManager.getProviders(TmfEvent.class, TmfEventProviderStub.class); |
53 | ITmfDataProvider<TmfEvent> provider = eventProviders[0]; | |
d18dd09b ASL |
54 | |
55 | // make sure we have the right type of request | |
fc6ccf6f | 56 | if (!(request instanceof TmfEventRequest<?>)) { |
d18dd09b ASL |
57 | request.cancel(); |
58 | return null; | |
59 | } | |
60 | ||
61 | TmfEventRequest<TmfSyntheticEventStub> eventRequest = (TmfEventRequest<TmfSyntheticEventStub>) request; | |
62 | TmfTimeRange range = eventRequest.getRange(); | |
63 | final TmfEventRequest<TmfEvent> subRequest = | |
64 | new TmfEventRequest<TmfEvent>(TmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { | |
65 | @Override | |
66 | public void handleData() { | |
67 | TmfEvent[] events = getData(); | |
68 | if (events.length > 0) { | |
69 | for (TmfEvent e : events) { | |
70 | handleIncomingData(e); | |
71 | } | |
72 | } else { | |
73 | request.done(); | |
74 | } | |
75 | } | |
76 | }; | |
951d134a | 77 | provider.sendRequest(subRequest); // , false); |
d18dd09b ASL |
78 | |
79 | // Return a dummy context | |
80 | return new TmfContext(); | |
81 | } | |
82 | ||
83 | // Queue 2 synthetic events per base event | |
84 | private void handleIncomingData(TmfEvent e) { | |
fc6ccf6f FC |
85 | queueResult(new TmfSyntheticEventStub(e)); |
86 | queueResult(new TmfSyntheticEventStub(e)); | |
d18dd09b ASL |
87 | } |
88 | ||
89 | } |