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