6f2f65bd3b9167a317749685bab0e6601445c6b5
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / component / TmfSyntheticEventProviderStub.java
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 };
68 provider.sendRequest(subRequest); // , false);
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) {
76 queueResult(new TmfSyntheticEventStub(e));
77 queueResult(new TmfSyntheticEventStub(e));
78 }
79
80 }
This page took 0.031483 seconds and 4 git commands to generate.