public class SIMPlugin
extends java.lang.Object
To create a connector, you do not call "new SIMPlugin(String)" as this class should be considered abstract.
Instead call the static factor method createSIMPlugin(String)
,
where the String argument is the SIM's name. See below for supported SIMs.
Once a connector has been created, you then call run(Callback)
method
passing in an instance of a Callback
Class
that you must implement to get called when data is available.
So, to make things a little easier, I have 2 implementations for you to use out of the box.
For Java Applications, see SIMPluginAWTEventDispatcher
.
This dispatcher allows you to register standard PropertyListener's that will receive events when data they are listening to changes.
For Web Server Applications, I have implemented several J2EE Servlets for different protocols, including HTTP and Web Socket.
See com.SIMRacingApps.servlets
for details.
The most important SIMPlugin method is getData(String)
.
This method takes a string that is formatted as a path to the data you want to get or change.
It breaks down this path and calls the corresponding method to retrieve the data.
The method the path maps to must return a Data
object and be overloaded to take String arguments.
In a pure Java Application, you can also get a reference to these objects through the SIMPlugin instance and call them directly.
Here are the main path entry points. See the documentation for each one for more details on the data they can provide.
//NOTE: The leading slash is optional/(method)
/(args)/TeamSpeak
/(method)/(args)/Session
/(method)/(args)/Session/Track
/(method)/(args)/Session/Car
/(car)/(method)/(args)/Session/Car/(car)/Gauge
/(gaugeType)/(method)/(args) //Also, the Car and Track can be accessed without the /Session prefix on the path as follows./Track
/(method)/(args)/Car
/(car)/(method)/(args)/Car/(car)/Gauge
/(gaugeType)/(method)/(args) //For direct access to the SIM's data, put the SIM name as the first argument followed by the path. //Refer to the SIM's documentation for available paths. It is beyond the scope of these documents to do so. //If you find yourself needing to use this, consider implementing a generic method, //so clients do not have to be SIM specific./iRacing
/(args) //TODO: Put a link to all supported SIMs
Modifier and Type | Class and Description |
---|---|
static interface |
SIMPlugin.Callback
This interface is used to call back to your implementation as data is received.
|
static class |
SIMPlugin.SIMPluginException
This class returns the exception message thrown by the SIMPlugin Class
|
Modifier and Type | Method and Description |
---|---|
boolean |
addCallback(java.lang.String name)
Creates a callback instance from the specified name
|
void |
close()
Closes the connection to the SIM and kills any threads it may have spawned.
|
static SIMPlugin |
createSIMPlugin(java.lang.String SIM)
A static factory method for creating a SIM specific connector and returning it.
|
SIMPluginCallback |
getCallback(java.lang.String name)
Returns an instance to a callback.
|
Data |
getData(java.lang.String path)
Returns a value from the SIM.
|
Data |
getEndingVersion()
Returns the Data Version of where the playing file should stop.
|
Data |
getPlay()
Returns the name of the currently playing recorded file.
|
Data |
getRecord()
Returns the name of the file being recorded.
|
Session |
getSession()
Returns an instance to the SIM's session.
|
Data |
getSetting(java.lang.String arg) |
Data |
getSetting(java.lang.String arg,
java.lang.String defaultValue)
Returns the value of arg from the settings.txt file.
|
Data |
getSIMData(java.lang.String... args)
This gets called when the path specifies a specific SIM should return the data.
|
Data |
getSIMName()
Returns the name of the SIM this connector is for.
|
Data |
getStartingVersion()
Returns the Data Version of where the playing file should start.
|
Data |
getSync()
Returns the sync flag.
|
Data |
getVersion()
Returns the version of the SIMRacingApps Plugin as a String in a printable format.
|
Data |
getVolume()
Returns the master volume setting as a percentage.
|
void |
removeCallback(java.lang.String name)
Removes a callback.
|
void |
run() |
void |
run(SIMPlugin.Callback callback)
Starts the run loop that notifies the caller when data is available through the Callback class.
|
Data |
setEndingVersion(java.lang.String endingversion)
Sets the Data Version of where the playing file should stop.
|
Data |
setPlay(java.lang.String Filename)
Sets the filename to be played back.
|
Data |
setRecord(java.lang.String Filename)
Sets the filename to record this session to.
|
Data |
setStartingVersion(java.lang.String startingversion)
Sets the Data Version of where the playing file should start.
|
Data |
setSync(boolean sync)
Sets the the sync flag.
|
Data |
setSynce(java.lang.String sync) |
Data |
setVolume(double percentage)
Returns the master volume setting as a percentage.
|
Data |
setVolume(java.lang.String percentage) |
public static SIMPlugin createSIMPlugin(java.lang.String SIM) throws SIMPlugin.SIMPluginException
For example: SIMPlugin c = SIMPlugin.createSIMPlugin("iRacing");
SIM
- The name of a SIM supported by a SIMPlugin class implementation in the com.SIMRacingApps.SIMPlugins package.SIMPlugin.SIMPluginException
- If there's a problem creating a SIMPlugin instance for this SIM.public void close()
public boolean addCallback(java.lang.String name)
name
- The callback class name relative to com.SIMRacingApps.SIMPluginCallbacks.public SIMPluginCallback getCallback(java.lang.String name)
name
- The callback name as it is named in the list of callbacks.public void removeCallback(java.lang.String name)
name
- The callback name as it is named in the list of callbacks.public Data getSIMName()
PATH = /SIMName
Data
container.public Data getPlay()
Data
container.public Data setPlay(java.lang.String Filename)
Filename
- The complete path to the file to play.Data
container.public Data getRecord()
Data
container.public Data setRecord(java.lang.String Filename)
Filename
- The complete path to the file to record to.Data
container.public Data getStartingVersion()
Data
container.public Data setStartingVersion(java.lang.String startingversion)
startingversion
- The starting version in the format specified by the SIM.Data
container.public Data getEndingVersion()
public Data setEndingVersion(java.lang.String endingversion)
endingversion
- The ending version in the format specified by the SIM.Data
container.public Data getSetting(java.lang.String arg, java.lang.String defaultValue)
arg
- The name of the setting value to return.defaultValue
- (Optional) The value to return if the arg is not defined. Defaults to empty string.public Data getSetting(java.lang.String arg)
public Data getSync()
public Data setSync(boolean sync)
sync
- Y or NData
container.public Data setSynce(java.lang.String sync)
public Data getVolume()
PATH = /Volume
Data
container.public Data setVolume(double percentage)
PATH = /Volume/(PERCENTAGE)
percentage
- The new volume as a percentage. Range 0.0 to 100.0.Data
container.public Data setVolume(java.lang.String percentage)
public Data getData(java.lang.String path) throws SIMPlugin.SIMPluginException
The first argument is tested to see if it matches a public method on this class that takes the same number of String arguments, then calls it.
If it's a "get", the "get" is optional, but "set", "decrement", and "increment" are required.
If the first argument matches the name of the SIM, all the arguments are passed to the SIM version of getSIMData(String...)
.
It is not recommended to call the SIM version directly as this will tie your client to that SIM.
Although you will have to use it if the API is missing something you need,
but consider enhancing the generic API instead.
For Examples see SIMPlugin
.
path
- The path to the requested value with arguments separated by slashes in a RESTfull syntax.Data
container.
If the path was invalid, then it returns an error message in a Data
container with the State set to ERROR.SIMPlugin.SIMPluginException
- for other syntax or runtime errorspublic void run(SIMPlugin.Callback callback)
callback
- (Optional) An instance a callback implementation to process the datapublic void run()
public Session getSession()
Session
public Data getVersion()
PATH = /Version
public Data getSIMData(java.lang.String... args)
args
- An array of String arguments as specified by the SIM.Data
container.