Make D-Bus calls async on startup

This commit is contained in:
John (J5) Palmieri 2007-08-27 15:47:58 -04:00
parent 2cae66b0ea
commit c06d639487
6 changed files with 123 additions and 22 deletions

View File

@ -52,27 +52,36 @@ class BuddyModel(gobject.GObject):
self._buddy = None
# If given just a key, try to get the buddy from the PS first
if not buddy:
self._key = key
for iter_buddy in self._pservice.get_buddies():
if iter_buddy.props.key == key:
buddy = iter_buddy
break
# If successful, copy properties from the PS buddy object
if buddy:
self._update_buddy(buddy)
else:
# Otherwise, connect to the PS's buddy-appeared signal and
self._key = key
# connect to the PS's buddy-appeared signal and
# wait for the buddy to appear
self._ba_handler = self._pservice.connect('buddy-appeared',
self._buddy_appeared_cb)
self._key = key
# Set color to 'inactive'/'disconnected'
self._set_color_from_string(_NOT_PRESENT_COLOR)
self._nick = nick
self._pservice.get_buddies_async(reply_handler=self._get_buddies_cb)
else:
self._update_buddy(buddy)
def _get_buddies_cb(self, list):
buddy = None
for iter_buddy in list:
if iter_buddy.props.key == key:
buddy = iter_buddy
break
if buddy:
if self._ba_handler:
# Once we have the buddy, we no longer need to
# monitor buddy-appeared events
self._pservice.disconnect(self._ba_handler)
self._ba_handler = None
self._update_buddy(buddy)
def _set_color_from_string(self, color_string):
self._color = XoColor(color_string)

View File

@ -87,11 +87,9 @@ class MeshModel(gobject.GObject):
self._buddy_disappeared_cb)
# Add any buddies the PS knows about already
for buddy in self._pservice.get_buddies():
self._buddy_appeared_cb(self._pservice, buddy)
self._pservice.get_buddies_async(reply_handler=self._get_buddies_cb)
for activity in self._pservice.get_activities():
self._check_activity(activity)
self._pservice.get_activities_async(reply_handler=self._get_activities_cb)
network_manager = hardwaremanager.get_network_manager()
if network_manager:
@ -102,6 +100,14 @@ class MeshModel(gobject.GObject):
network_manager.connect('device-removed',
self._nm_device_removed_cb)
def _get_buddies_cb(self, list):
for buddy in list:
self._buddy_appeared_cb(self._pservice, buddy)
def _get_activities_cb(self, list):
for activity in list:
self._check_activity(activity)
def _nm_device_added_cb(self, manager, nm_device):
self._add_network_device(nm_device)

View File

@ -68,9 +68,7 @@ class ActivitiesBox(hippo.CanvasBox):
self._invites = self._shell_model.get_invites()
registry = activity.get_registry()
for activity_info in registry.get_activities():
if activity_info.show_launcher:
self.add_activity(activity_info)
registry.get_activities_async(reply_handler=self._get_activities_cb)
registry.connect('activity-added', self._activity_added_cb)
@ -79,6 +77,11 @@ class ActivitiesBox(hippo.CanvasBox):
self._invites.connect('invite-added', self._invite_added_cb)
self._invites.connect('invite-removed', self._invite_removed_cb)
def _get_activities_cb(self, activity_list):
for activity_info in activity_list:
if activity_info.show_launcher:
self.add_activity(activity_info)
def _activity_clicked_cb(self, icon):
self._shell.start_activity(icon.get_bundle_id())

View File

@ -54,13 +54,16 @@ class FriendsBox(hippo.CanvasBox):
self.__activity_appeared_cb)
# Add initial activities the PS knows about
for activity in self._pservice.get_activities():
self.__activity_appeared_cb(self._pservice, activity)
self._pservice.get_activities_async(reply_handler=self._get_activities_cb)
home_model = shell.get_model().get_home()
home_model.connect('active-activity-changed',
self._active_activity_changed_cb)
def _get_activities_cb(self, list):
for activity in list:
self.__activity_appeared_cb(self._pservice, activity)
def add_buddy(self, buddy):
if self._buddies.has_key(buddy.props.key):
return

View File

@ -77,6 +77,29 @@ class ActivityRegistry(gobject.GObject):
info_list = self._registry.GetActivities()
return self._convert_info_list(info_list)
def _get_activities_cb(self, reply_handler, info_list):
result = []
i = 0
for info_dict in info_list:
result.append(_activity_info_from_dict(info_dict))
reply_handler(result)
def _get_activities_error_cb(self, error_handler, e):
if error_handler:
error_handler(e)
else:
logging.error('Error getting activities async: %s' % str(e))
def get_activities_async(self, reply_handler=None, error_handler=None):
if not reply_handler:
logging.error('Function get_activities_async called without a reply handler. Can not run.')
return
self._registry.GetActivities(
reply_handler=lambda info_list:self._get_activities_cb(reply_handler, info_list),
error_handler=lambda e:self._get_activities_error_cb(error_handler, e))
def get_activity(self, service_name):
if self._service_name_to_activity_info.has_key(service_name):
return self._service_name_to_activity_info[service_name]

View File

@ -268,6 +268,35 @@ class PresenceService(gobject.GObject):
acts.append(self._new_object(item))
return acts
def _get_activities_cb(self, reply_handler, resp):
acts = []
for item in resp:
acts.append(self._new_object(item))
reply_handler(acts)
def _get_activities_error_cb(self, error_handler, e):
if error_handler:
error_handler(e)
else:
_logger.warn(
"""Unable to retrieve activity-list from presence service: %s"""
% e
)
def get_buddies_async(self, reply_handler=None, error_handler=None):
"""Retrieve set of all activities from service asyncronously
"""
if not reply_handler:
logging.error('Function get_activities_async called without a reply handler. Can not run.')
return
self._ps.GetActivities(
reply_handler=lambda resp:self._get_activities_cb(reply_handler, resp),
error_handler=lambda e:self._get_activities_error_cb(error_handler, e))
def get_activity(self, activity_id):
"""Retrieve single Activity object for the given unique id
@ -306,6 +335,34 @@ class PresenceService(gobject.GObject):
buddies.append(self._new_object(item))
return buddies
def _get_buddies_cb(self, reply_handler, resp):
buddies = []
for item in resp:
buddies.append(self._new_object(item))
reply_handler(buddies)
def _get_buddies_error_cb(self, error_handler, e):
if error_handler:
error_handler(e)
else:
_logger.warn(
"""Unable to retrieve buddy-list from presence service: %s"""
% e
)
def get_buddies_async(self, reply_handler=None, error_handler=None):
"""Retrieve set of all buddies from service asyncronously
"""
if not reply_handler:
logging.error('Function get_buddies_async called without a reply handler. Can not run.')
return
self._ps.GetBuddies(
reply_handler=lambda resp:self._get_buddies_cb(reply_handler, resp),
error_handler=lambda e:self._get_buddies_error_cb(error_handler, e))
def get_buddy(self, key):
"""Retrieve single Buddy object for the given public key