Developer Example: ArbitraryCommandService

Services are used for integrating new applications into the VenueClient. In most cases, these services are for media tools such as vic, rat, DVTS, VLC, etc., which stream audio or video to multicast addresses allocated by the Venue. As a general demonstration of services, however, this example describes a service with one configurable parameter, the path to an executable, which is executed whenever the VenueClient enters a Venue. It is intended simply as an example, but it could be useful in cases in which one wishes to run an application on a machine in the node (yes, any machine) whenever a Venue is entered.

The entire code of the service implementation is included here, since it's so short. Note that the ArbitraryCommandService class includes only four methods:

The constructor for the class, in which the executableOption TextParameter is added to the service configuration

Grabs the path to the executable from the executableOption parameter and executes it

Stops the service (i.e., terminates the executable)

Sets the stream (which is, in this case, unused), and stops/starts the service



from AccessGrid.Descriptions import Capability
from AccessGrid.AGService import AGService
from AccessGrid.AGParameter import TextParameter

class ArbitraryCommandService( AGService ):

def __init__( self ):
AGService.__init__( self )

self.capabilities = [ Capability( Capability.CONSUMER,
self.executable = None

# Set configuration parameters
self.executableOption = TextParameter( "Executable",
"/Applications//" )

def Start( self ):
"""Start service"""
self.executable = self.executableOption.value
if self.executable:"Starting ArbitraryCommandService")" executable = %s" % self.executable)
self._Start( [] )

self.log.exception("Exception in ArbitraryCommandService.Start")

def Stop( self ):
"""Stop the service"""
self.started = 0
try:"Stop service")
self.log.exception("Exception in AGService.Stop ")

def SetStream( self, streamDescription ):
Configure the Service according to the StreamDescription, and
stop and start rat

# Configure the stream
ret = AGService.SetStream( self, streamDescription )
if ret and self.started:
# service is already running with this config; ignore

# If started, stop
if self.started:

# If enabled, start
if self.enabled:

if __name__ == '__main__':

from AccessGrid.interfaces.AGService_interface import AGService as AGServiceI
from AccessGrid.AGService import RunService

service = ArbitraryCommandService()
serviceI = AGServiceI(service)

Supporting Code


login or register to post comments