Convert PS bindings instantiation into a singleton to cut resource usage
This commit is contained in:
parent
d334b6e3bd
commit
eef5e5b18a
@ -1,7 +1,7 @@
|
||||
from sugar import env
|
||||
from sugar.chat.BuddyChat import BuddyChat
|
||||
from sugar.activity import ActivityFactory
|
||||
from sugar.presence.PresenceService import PresenceService
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.p2p.Stream import Stream
|
||||
from sugar.chat.Chat import Chat
|
||||
|
||||
@ -21,7 +21,7 @@ class ChatController:
|
||||
del self._id_to_name[activity_id]
|
||||
|
||||
def listen(self):
|
||||
self._pservice = PresenceService()
|
||||
self._pservice = PresenceService.get_instance()
|
||||
|
||||
self._pservice.register_service_type(BuddyChat.SERVICE_TYPE)
|
||||
self._service = self._pservice.register_service(env.get_nick_name(),
|
||||
|
@ -25,7 +25,7 @@ class ShellOwner(object):
|
||||
fd.close()
|
||||
break
|
||||
|
||||
self._pservice = PresenceService.PresenceService()
|
||||
self._pservice = PresenceService.get_instance()
|
||||
|
||||
def announce(self):
|
||||
# Create and announce our presence
|
||||
|
@ -2,7 +2,7 @@ import gtk
|
||||
import gobject
|
||||
import dbus
|
||||
|
||||
from sugar.presence.PresenceService import PresenceService
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.presence.Service import Service
|
||||
from sugar.chat.BuddyChat import BuddyChat
|
||||
|
||||
@ -20,7 +20,7 @@ class PresenceView(gtk.VBox):
|
||||
self._activity_ps = None
|
||||
self._shell = shell
|
||||
|
||||
self._pservice = PresenceService()
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._pservice.connect("activity-appeared", self._activity_appeared_cb)
|
||||
|
||||
self._setup_ui()
|
||||
|
@ -173,7 +173,7 @@ class Shell(gobject.GObject):
|
||||
if activity:
|
||||
activity.present()
|
||||
else:
|
||||
pservice = PresenceService.PresenceService()
|
||||
pservice = PresenceService.get_instance()
|
||||
activity_ps = pservice.get_activity(activity_id)
|
||||
|
||||
if activity_ps:
|
||||
|
@ -1,6 +1,6 @@
|
||||
import gobject
|
||||
|
||||
from sugar.presence.PresenceService import PresenceService
|
||||
from sugar.presence import PresenceService
|
||||
|
||||
class Friend:
|
||||
def __init__(self, buddy):
|
||||
@ -22,7 +22,7 @@ class FriendsModel(gobject.GObject):
|
||||
|
||||
self._friends = []
|
||||
|
||||
self._pservice = PresenceService()
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._pservice.connect("buddy-appeared", self.__buddy_appeared_cb)
|
||||
|
||||
for buddy in self._pservice.get_buddies():
|
||||
|
@ -1,6 +1,6 @@
|
||||
import gobject
|
||||
|
||||
from sugar.presence.PresenceService import PresenceService
|
||||
from sugar.presence import PresenceService
|
||||
from sugar import conf
|
||||
|
||||
class ActivityInfo:
|
||||
@ -32,7 +32,7 @@ class MeshModel(gobject.GObject):
|
||||
|
||||
self._activities = {}
|
||||
|
||||
self._pservice = PresenceService()
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._pservice.connect("service-appeared", self.__service_appeared_cb)
|
||||
|
||||
for service in self._pservice.get_services():
|
||||
|
@ -206,6 +206,14 @@ class PresenceService(gobject.GObject):
|
||||
def unregister_service_type(self, stype):
|
||||
self._ps.unregisterServiceType(stype)
|
||||
|
||||
_ps = None
|
||||
def get_instance():
|
||||
global _ps
|
||||
if not _ps:
|
||||
_ps = PresenceService()
|
||||
return _ps
|
||||
|
||||
|
||||
def start():
|
||||
bus = dbus.SessionBus()
|
||||
ps = dbus.Interface(bus.get_object(DBUS_SERVICE, DBUS_PATH), DBUS_INTERFACE)
|
||||
|
Loading…
Reference in New Issue
Block a user