Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:HelsinkiHacklab/reactor
- Loading branch information
Showing
8 changed files
with
116 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash -ex | ||
# Change the working dir to the directory of this file | ||
filep=`realpath "$0"` | ||
cd `dirname "$filep"` | ||
# The visualizer does not have any use for a terminal | ||
python simulationengine/visualizer_launcher.py & | ||
# For others it's usefull for debugging | ||
gnome-terminal --title="arDuBUS" -e "python arDuBUS/ardubus_launcher.py" & | ||
gnome-terminal --title="Noisemaker" -e "python noisemaker/noisemaker_launcher.py" & | ||
gnome-terminal --title="Simulationengine" -e "python simulationengine/simulation_launcher.py" & | ||
sleep 5 # Give the others time to actually register on the bus before firing up the middleware that will throw a hissy fit if it doesn't seem them | ||
gnome-terminal --title="Middleware" -e "python middleware/middleware_launcher.py" & | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Some utility functions to hve more grafull handling of DBUS exceptions we might get when dependent services get restarted""" | ||
import dbus | ||
|
||
dbus_cache = {} | ||
dbus_cache_error_count = {} | ||
bus = dbus.SessionBus() | ||
|
||
def call_cached(buspath, method, *args, **kwargs): | ||
"""Maintains a cache of DBUS proxy objects and calls the given objects method. If the proxy object is stale tries to refresh""" | ||
if not kwargs.has_key('busname'): | ||
kwargs['busname'] = buspath.replace('/', '.')[1:] | ||
busname = kwargs['busname'] | ||
obj_cache_key = "%s@%s" % (busname, buspath) | ||
method_cache_key = "%s::%s" % (obj_cache_key, method) | ||
if not dbus_cache.has_key(obj_cache_key): | ||
dbus_cache[obj_cache_key] = bus.get_object(busname, buspath) | ||
if not dbus_cache.has_key(method_cache_key): | ||
dbus_cache[method_cache_key] = getattr(dbus_cache[obj_cache_key], method) | ||
|
||
try: | ||
ret = dbus_cache[method_cache_key](*args) | ||
if dbus_cache_error_count.has_key(method_cache_key): # Zero the error count | ||
dbus_cache_error_count[method_cache_key] = 0 | ||
return ret | ||
except dbus.exceptions.DBusException: | ||
if not dbus_cache_error_count.has_key(method_cache_key): | ||
dbus_cache_error_count[method_cache_key] = 0 | ||
dbus_cache_error_count[method_cache_key] += 1 | ||
# TODO Check that it's a method os object name exception first | ||
# Remove stale keys | ||
print "dbus_utilities.call_cached: Removing stale keys for %s" % method_cache_key | ||
del(dbus_cache[obj_cache_key]) | ||
del(dbus_cache[method_cache_key]) | ||
if dbus_cache_error_count[method_cache_key] < 4: | ||
return call_cached(busname, buspath, method, *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from __future__ import with_statement | ||
# Boilerplate to add ../pythonlibs (via full path resolution) to import paths | ||
import os,sys | ||
libs_dir = os.path.join(os.path.dirname( os.path.realpath( __file__ ) ), '..', 'pythonlibs') | ||
if os.path.isdir(libs_dir): | ||
sys.path.append(libs_dir) | ||
|
||
# Import our DBUS service module | ||
import service,dbus,gobject,dbus_utilities | ||
import dbus,time | ||
|
||
from PySide import QtCore | ||
from PySide import QtGui | ||
from PySide import QtDeclarative | ||
|
||
|
||
class simcontrol(service.baseclass): | ||
def __init__(self, config, launcher_instance, **kwargs): | ||
super(simcontrol, self).__init__(config, launcher_instance, **kwargs) | ||
|
||
@dbus.service.method('fi.hacklab.reactorsimulator.simcontrol') | ||
def quit(self): | ||
return self.launcher_instance.quit() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Boilerplate to add ../pythonlibs (via full path resolution) to import paths | ||
import os,sys | ||
libs_dir = os.path.join(os.path.dirname( os.path.realpath( __file__ ) ), '..', 'pythonlibs') | ||
if os.path.isdir(libs_dir): | ||
sys.path.append(libs_dir) | ||
# Import the launcher and dbus modules | ||
import launcher,dbus | ||
|
||
|
||
# Define some values that will be used | ||
my_signature = 'fi.hacklab.reactorsimulator.simcontrol' | ||
launcher_config = { | ||
'dbus_default_interface_name': my_signature, | ||
'dbus_object_path': '/fi/hacklab/reactorsimulator/simcontrol', | ||
'main_class_name': os.path.basename(__file__).replace('_launcher.py', ''), | ||
'config_file_path': os.path.realpath(__file__).replace('_launcher.py', '.yml'), | ||
} | ||
|
||
# Basic pass-through implementation | ||
class my_launcher(launcher.baseclass): | ||
def __init__(self, mainloop, bus, **kwargs): | ||
super(my_launcher, self).__init__(mainloop, bus, **kwargs) | ||
print "launcher initialized as %s:%s with config %s" % (self.dbus_interface_name, self.dbus_object_path, repr(self.config)) | ||
|
||
@dbus.service.method(my_signature + '.launcher') | ||
def quit(self): | ||
launcher.baseclass.quit(self) | ||
|
||
@dbus.service.method(my_signature + '.launcher') | ||
def reload(self): | ||
launcher.baseclass.reload(self) | ||
self.main_instance.config_reloaded() | ||
|
||
# Another small bit of boilerplate | ||
if __name__ == '__main__': | ||
launcher.main(my_launcher, **launcher_config) |