aboutsummaryrefslogtreecommitdiffstats
path: root/libfsoresource
diff options
context:
space:
mode:
authorSimon Busch <morphis@gravedo.de>2011-07-12 16:01:07 +0200
committerSimon Busch <morphis@gravedo.de>2011-07-12 16:07:23 +0200
commite13cc938ccdcf02de8bad6594afdea3617190061 (patch)
tree8ac9a25e8f641589cc9a88b156c10fe0b1324752 /libfsoresource
parent5d1d96170fef3606a3e7a8eb0d687167fedf28a3 (diff)
downloadcornucopia-e13cc938ccdcf02de8bad6594afdea3617190061.tar.gz
cornucopia-e13cc938ccdcf02de8bad6594afdea3617190061.tar.bz2
cornucopia-e13cc938ccdcf02de8bad6594afdea3617190061.zip
libfsoresource: implement resource registration after registration was lost
In a few cases it can happen that the fsousage daemon dies. When it comes back again all registrations are lost. Especially when using shadow resources this will let the usage daemon wait for ever for the resource to register again. The AbstractDBusResource will now watch if the usage bus disappears and then register the resource again when it comes back. In a stable system this case should never happen but when it happens it is better when the system can solve this simple problem on its own.
Diffstat (limited to 'libfsoresource')
-rw-r--r--libfsoresource/fsoresource/dbusresource.vala57
1 files changed, 50 insertions, 7 deletions
diff --git a/libfsoresource/fsoresource/dbusresource.vala b/libfsoresource/fsoresource/dbusresource.vala
index f24dc18e..103c68cf 100644
--- a/libfsoresource/fsoresource/dbusresource.vala
+++ b/libfsoresource/fsoresource/dbusresource.vala
@@ -30,12 +30,45 @@ public abstract class AbstractDBusResource : FreeSmartphone.Resource, FsoFramewo
private FreeSmartphone.Usage usage;
private string name;
private ObjectPath path;
+ private FsoFramework.DBusServiceNotifier dbusnotifier;
+ private bool resourceRegistrationPending = false;
+ private bool resourceRegistered = false;
+
+ private void onUsageServiceAppearing( string busname )
+ {
+ if (busname != FsoFramework.Usage.ServiceDBusName)
+ return;
+
+ if ( !resourceRegistered && !resourceRegistrationPending )
+ {
+ assert( logger.debug( @"$busname service appeared. Registering resource '$name' ..." ) );
+
+ resourceRegistrationPending = true;
+ Idle.add( () => { registerWithUsage(); return false; });
+ }
+ }
+
+ private void onUsageServiceDisappearing( string busname )
+ {
+ if (busname != FsoFramework.Usage.ServiceDBusName)
+ return;
+
+ resourceRegistered = false;
+ }
public AbstractDBusResource( string name, FsoFramework.Subsystem subsystem )
{
this.name = name;
this.subsystem = subsystem as FsoFramework.DBusSubsystem;
this.path = new ObjectPath( "%s/%s".printf( FsoFramework.Resource.ServicePathPrefix, name ) );
+
+ this.dbusnotifier = new FsoFramework.DBusServiceNotifier();
+ this.dbusnotifier.notifyAppearing( FsoFramework.Usage.ServiceDBusName, onUsageServiceAppearing );
+ this.dbusnotifier.notifyDisappearing( FsoFramework.Usage.ServiceDBusName, onUsageServiceDisappearing );
+
+ resourceRegistrationPending = true;
+ resourceRegistered = false;
+
Idle.add( () => {
registerWithUsage();
return false;
@@ -57,21 +90,31 @@ public abstract class AbstractDBusResource : FreeSmartphone.Resource, FsoFramewo
conn.register_object<FreeSmartphone.Resource>( this.path, this );
usage = yield conn.get_proxy<FreeSmartphone.Usage>( FsoFramework.Usage.ServiceDBusName, FsoFramework.Usage.ServicePathPrefix );
yield usage.register_resource( name, path );
+
logger.info( "Ok. Registered with org.freesmartphone.ousaged" );
- return;
+
+ resourceRegistered = true;
}
catch ( Error e1 )
{
logger.error( @"Could not register $name with ousaged: $(e1.message); trying to enable the resource unconditionally" );
}
- try
- {
- yield enableResource();
- }
- catch ( Error e2 )
+
+#if 0
+ // FIXME why do we enable the resource here when fsouage does not told us to do so?
+ if ( resourceRegistered )
{
- logger.error( @"Can't enable the resource: $(e2.message)" );
+ try
+ {
+ yield enableResource();
+ }
+ catch ( Error e2 )
+ {
+ logger.error( @"Can't enable the resource: $(e2.message)" );
+ }
}
+#endif
+ resourceRegistrationPending = false;
}
/**