]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation/src/org/simantics/simulation/data/Datasource.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.simulation / src / org / simantics / simulation / data / Datasource.java
1 /*******************************************************************************
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     VTT Technical Research Centre of Finland - initial API and implementation
10  *******************************************************************************/
11 package org.simantics.simulation.data;
12
13 import java.util.Collection;
14 import java.util.concurrent.Executor;
15 import java.util.concurrent.locks.Lock;
16
17 import org.simantics.databoard.binding.Binding;
18 import org.simantics.databoard.binding.NumberBinding;
19 import org.simantics.databoard.type.Datatype;
20 import org.simantics.databoard.util.Bean;
21
22 /**
23  * Interface for adapting data provider to HistoryCollector.
24  * 
25  * @author Toni Kalajainen
26  */
27 public interface Datasource {
28         
29         Collection<String> getVariables();
30         Datatype getType(String key);
31         Lock readLock();
32         void addListener(DatasourceListener listener);
33         void removeListener(DatasourceListener listener);
34
35         /**
36          * Try to open a handle to a variable
37          * 
38          * @param item
39          *            the subscription item to open a handle for
40          * @param key
41          *            requested handle address, should equal
42          *            SubscriptionItem#variableId
43          * @param valueBinding
44          *            binding for handling the requested value
45          * @return Variable Handle or <code>null</code> if handle cannot be resolved
46          *         for any reason
47          */
48         VariableHandle openHandle(Bean item, String key, Binding valueBinding);
49         
50         public interface DatasourceListener {
51                 
52                 /**
53                  * When listeners are processed, the data source does not proceed.
54                  * It is locked, but this is valid only for listeners with executor
55                  * as null. Values are typically read within a listener.
56                  * 
57                  * @param source
58                  */
59                 void onStep(Datasource source);
60                 
61                 /**
62                  * Get executor where listener is handled.
63                  * If returned value is null, listener is handled synchronously in 
64                  * current thread.
65                  * 
66                  * @return
67                  */
68                 Executor getExecutor();
69         }
70
71         //
72         // The following methods produce sensible values only when the source
73         // is locked or within listener (when it is locked).
74         // 
75         
76         Object getTime(NumberBinding binding);
77
78 }
79