| |
- Dictionary
- DictionaryKeyChangeReason
- KeyListener
class Dictionary |
|
This class represents the Phidget Dictionary.
The Phidget Dictionary is a service provided by the Phidget Webservice.
The Webservice maintains a centralized dictionary of key-value pairs that can be accessed and changed from any number of clients.
Note that the Webservice uses this dictionary to control access to Phidgets through the openRemote and openRemoteIP interfaces,
and as such, you should never add or modify a key that starts with /PSK/ or /PCK/, unless you want to explicitly modify Phidget
specific data -- and this is highly discouraged, as it's very easy to break things. Listening to these keys is fine if so desired.
The intended use for the dictionary is as a central repository for communication and persistent storage of data between several
client applications. As an example - a higher level interface exposed by one application -- which controls the Phidgets,
for others to access -- rather then every client talking directly to the Phidgets themselves.
The dictionary makes use of extended regular expressions for key matching. |
|
Methods defined here:
- __del__(self)
- __init__(self)
- The Constructor Method for the Dictionary Class
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: If this Phidget is not opened.
- addKey(self, key, value, persist=True)
- Adds a new key to the Dictionary, or modifies the value of an existing key.
The key can only contain numbers, letters, "/", ".", "-", "_", and must begin with a letter, "_" or "/".
The value can contain any value.
The persistent value controls whether a key will stay in the dictionary after the client that created it disconnects.
If persist == False, the key is removed when the connection closes. Otherwise the key remains in the dictionary until it is explicitly removed.
Specifying the persist parameter is optional and will default to True if not provided when calling this method.
Parameters:
key<string>: The key to add to the Dictionary.
value<string>: The value to be associated with the key in the Dictionary.
persist<boolean>: Flag to specify whether to make this Dictionary entry persistent or not.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: if the Phidget Webservice cannot be contacted
- closeDictionary(self)
- Closes this Dictionary.
This will shut down all threads dealing with this Dictionary and you won't recieve any more events.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: If this Dictionary is not opened.
- getKey(self, key)
- Gets the value for the provided key from the dictionary. If more then one key matches, only the first value is returned.
Parameters:
key<string>: The key for the intry in the dictionary.
Returns:
The value from the entry in the dictionary.
Exceptions:
RuntimeError: If current platform is not supported/phidget c dll cannot be found.
PhidgetException: if this Dictionary was not opened, or the server is not connected.
- getServerAddress(self)
- Returns the Address of a Phidget Webservice when this Dictionary was opened as remote.
This may be an IP Address or a hostname.
Returns:
The server address for the webservice <string>.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: if this Dictionary was not opened.
- getServerID(self)
- Returns the Server ID of a Phidget Webservice when this Dictionary was opened as remote.
This is an arbitrary server identifier, independant of IP address and Port.
Returns:
The ServerID for the webservice <string>.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: if this Dictionary was not opened.
- getServerPort(self)
- Returns the Port of a Phidget Webservice when this Dictionary was opened as remote.
Returns:
The server port for the webservice.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: if this Dictionary was not opened.
- isAttachedToServer(self)
- Gets the attached status of this Dictionary.
Returns:
The attached status of this Dictionary <boolean>.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: if this Dictionary was not opened.
- openRemote(self, serverID, password='')
- Open this Dictionary remotely using a Server ID, and securely using a password.
This password can be set as a parameter when starting the Phidget Webservice.
The use of a password is optional and calling the function without providing a password will
connect normally.
Parameters:
serverID<string>: ServerID of the Phidget Webservice.
password<string>: The secure password for the Phidget Webservice.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: if the Phidget Webservice cannot be contacted
- openRemoteIP(self, IPAddress, port, password='')
- Open this Dictionary remotely using an IP Address and port, and securely using a password.
This password can be set as a parameter when starting the Phidget Webservice.
The use of a password is optional and calling the function without providing a password will
connect normally.
Parameters:
IPAddress<string>: IP Address or hostname of the Phidget Webservice
port<int>: Port of the Phidget Webservice
password<string>: The secure password for the Phidget Webservice
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: if the Phidget Webservice cannot be contacted
- removeKey(self, pattern)
- Removes a key, or set of keys, from the Dictionary.
The key name is a regular expressions pattern, and so care must be taken to only have it match the specific keys you want to remove.
Parameters:
pattern<string>: The regular expression pattern to match to the keys you want to remove from the Dictionary.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: if the Phidget Webservice cannot be contacted
- setErrorHandler(self, errorhandler)
- Sets the Error Event Handler.
Parameters:
errorhandler: hook to the errorhandler callback function.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException
- setServerConnectHandler(self, serverConnectHandler)
- Sets the Server Connect event handler.
The serverConnect handler is a method that will be called when a connection to a server is made.
Parameters:
serverConnectHandler: hook to the serverConnectHandler callback function.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException
- setServerDisconnectHandler(self, serverDisconnectHandler)
- Sets the Server Disconnect Event Handler.
The serverDisconnect handler is a method that will be called when a connection to a server is terminated.
Parameters:
serverDisconnectHandler: hook to the serverDisconnectHandler callback function.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException
|
class DictionaryKeyChangeReason |
|
This is an enumeration for the key change reasons to make checks and setting more straightforward and readable |
|
Data and other attributes defined here:
- PHIDGET_DICTIONARY_CURRENT_VALUE = 4
- PHIDGET_DICTIONARY_ENTRY_ADDED = 2
- PHIDGET_DICTIONARY_ENTRY_REMOVING = 3
- PHIDGET_DICTIONARY_VALUE_CHANGED = 1
|
class KeyListener |
|
This class represents a key listener.
This key listener is used, along with the Dictionary object,
to set up listener for specific keys, or groups of keys.
Events are available for key add or change, and for key removal. |
|
Methods defined here:
- __init__(self, dict, keyPattern)
- The Constructor Method for the KeyListener Class
Creates a new key listener, for a specific pattern, on a specific dictionary object.
- getDictionary(self)
- Returns the Dictionary handle that this listener is listening on.
- setKeyChangeHandler(self, keyChangeHandler)
- Sets the KeyChange event handler.
Parameters:
keyChangeHandler: hook to the keyChangeHandler callback function.
- setKeyRemovalListener(self, keyRemovalHandler)
- Sets the KeyRemoval event handler.
Parameters:
keyRemovalHandler: hook to the keyRemovalHandler callback function.
- start(self)
- Start this key listener.
This method should not be called until the coresponding dictionary is connected.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: If this Dictionary is not opened.
- stop(self)
- Stop this key listener.
Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: If this Dictionary is not opened.
| |