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