Skip to content

Commit

Permalink
#1761: use a stub base class to define empty methods for all mixins, …
Browse files Browse the repository at this point in the history
…use the same method names in all mixins so we can delegate to all bases

git-svn-id: https://xpra.org/svn/Xpra/trunk@18531 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 22, 2018
1 parent ef1b559 commit d074722
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 105 deletions.
10 changes: 8 additions & 2 deletions src/xpra/client/mixins/audio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from xpra.net.compression import Compressed
from xpra.os_util import get_machine_id, get_user_uuid, bytestostr, OSX, POSIX
from xpra.util import envint, typedict, csv
from xpra.client.mixins.stub_client_mixin import StubClientMixin


glib = import_glib()
Expand All @@ -24,7 +25,7 @@
"""
Utility superclass for clients that handle audio
"""
class AudioClient(object):
class AudioClient(StubClientMixin):

def __init__(self):
self.sound_source_plugin = None
Expand Down Expand Up @@ -117,6 +118,7 @@ def vinfo(k):
def cleanup(self):
self.stop_all_sound()


def stop_all_sound(self):
if self.sound_source:
self.stop_sending_sound()
Expand All @@ -139,7 +141,10 @@ def get_audio_capabilities(self):
log("audio capabilities: %s", caps)
return caps

def process_capabilities(self):
def setup_connection(self, _conn):
pass

def parse_server_capabilities(self):
c = self.server_capabilities
self.server_av_sync = c.boolget("av-sync.enabled")
avsynclog("av-sync: server=%s, client=%s", self.server_av_sync, self.av_sync)
Expand All @@ -162,6 +167,7 @@ def process_capabilities(self):
self.start_receiving_sound()
if self.server_sound_receive and self.microphone_enabled:
self.start_sending_sound()
return True


######################################################################
Expand Down
21 changes: 13 additions & 8 deletions src/xpra/client/mixins/clipboard_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
log = Logger("clipboard")


from xpra.client.mixins.stub_client_mixin import StubClientMixin
from xpra.platform.features import CLIPBOARD_WANT_TARGETS, CLIPBOARD_GREEDY, CLIPBOARDS
from xpra.scripts.config import FALSE_OPTIONS
from xpra.os_util import bytestostr
Expand All @@ -20,7 +21,7 @@
"""
Utility superclass for clients that handle clipboard synchronization
"""
class ClipboardClient(object):
class ClipboardClient(StubClientMixin):

def __init__(self):
self.client_clipboard_type = ""
Expand All @@ -40,6 +41,7 @@ def init(self, opts):
self.client_clipboard_direction = opts.clipboard_direction
self.client_supports_clipboard = not ((opts.clipboard or "").lower() in FALSE_OPTIONS)


def cleanup(self):
ch = self.clipboard_helper
log("ClipboardClient.cleanup() clipboard_helper=%s", ch)
Expand All @@ -50,12 +52,6 @@ def cleanup(self):
except:
log.error("error on clipboard helper '%s' cleanup", ch, exc_info=True)

def process_ui_capabilities(self):
#ui may want to know this is now set:
self.emit("clipboard-toggled")
if self.server_clipboard:
#from now on, we will send a message to the server whenever the clipboard flag changes:
self.connect("clipboard-toggled", self.clipboard_toggled)

def get_clipboard_caps(self):
return {
Expand All @@ -69,7 +65,7 @@ def get_clipboard_caps(self):
"set_enabled" : True,
}

def parse_capabilities(self):
def parse_server_capabilities(self):
c = self.server_capabilities
self.server_clipboard = c.boolget("clipboard")
self.server_clipboard_loop_uuids = c.dictget("clipboard.loop-uuids")
Expand All @@ -94,6 +90,9 @@ def parse_capabilities(self):
self.client_supports_clipboard, self.client_clipboard_direction)
self.clipboard_enabled = self.client_supports_clipboard and self.server_clipboard
log("parse_clipboard_caps() clipboard enabled=%s", self.clipboard_enabled)
return True

def process_ui_capabilities(self):
if self.clipboard_enabled:
self.clipboard_helper = self.make_clipboard_helper()
self.clipboard_enabled = self.clipboard_helper is not None
Expand All @@ -103,6 +102,12 @@ def parse_capabilities(self):
#(could have been translated, or limited if the client only has one, etc)
log("clipboard enabled clipboard helper=%s", self.clipboard_helper)
self.send_clipboard_selections(self.clipboard_helper.remote_clipboards)
#ui may want to know this is now set:
self.emit("clipboard-toggled")
if self.server_clipboard:
#from now on, we will send a message to the server whenever the clipboard flag changes:
self.connect("clipboard-toggled", self.clipboard_toggled)


def init_authenticated_packet_handlers(self):
self.set_packet_handlers(self._ui_packet_handlers, {
Expand Down
10 changes: 4 additions & 6 deletions src/xpra/client/mixins/display_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from xpra.scripts.config import FALSE_OPTIONS
from xpra.os_util import monotonic_time
from xpra.util import iround, envint, envfloat, log_screen_sizes, engs
from xpra.client.mixins.stub_client_mixin import StubClientMixin


MONITOR_CHANGE_REINIT = envint("XPRA_MONITOR_CHANGE_REINIT")
Expand All @@ -40,7 +41,7 @@ def fequ(v1, v2):
Utility superclass for clients that handle a desktop / display
Adds client-side scaling handling
"""
class DisplayClient(object):
class DisplayClient(StubClientMixin):
def __init__(self):
self.dpi = 0
self.initial_scaling = 1, 1
Expand Down Expand Up @@ -70,10 +71,6 @@ def init(self, opts):
self.xscale, self.yscale = self.initial_scaling


def cleanup(self):
pass


def get_screen_sizes(self, xscale=1, yscale=1):
raise NotImplementedError()

Expand Down Expand Up @@ -161,8 +158,9 @@ def parse_server_capabilities(self):
log("server actual desktop size=%s", self.server_actual_desktop_size)
self.server_randr = c.boolget("resize_screen")
log("server has randr: %s", self.server_randr)
return True

def parse_ui_capabilities(self):
def process_ui_capabilities(self):
c = self.server_capabilities
server_desktop_size = c.intlistget("desktop_size")
log("server desktop size=%s", server_desktop_size)
Expand Down
13 changes: 3 additions & 10 deletions src/xpra/client/mixins/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from xpra.scripts.config import parse_bool_or_int
from xpra.net import compression
from xpra.util import envint, envbool, updict
from xpra.client.mixins.stub_client_mixin import StubClientMixin

B_FRAMES = envbool("XPRA_B_FRAMES", True)
PAINT_FLUSH = envbool("XPRA_PAINT_FLUSH", True)
Expand All @@ -33,7 +34,7 @@
"""
Mixin for adding encodings to a client
"""
class Encodings(object):
class Encodings(StubClientMixin):
def __init__(self):
self.allowed_encodings = []
self.core_encodings = None
Expand Down Expand Up @@ -86,17 +87,14 @@ def get_caps(self):

def parse_server_capabilities(self):
c = self.server_capabilities

self.server_compressors = c.strlistget("compressors", ["zlib"])

self.server_encodings = c.strlistget("encodings")
self.server_core_encodings = c.strlistget("encodings.core", self.server_encodings)
self.server_encodings_problematic = c.strlistget("encodings.problematic", PROBLEMATIC_ENCODINGS) #server is telling us to try to avoid those
self.server_encodings_with_speed = c.strlistget("encodings.with_speed", ("h264",)) #old servers only supported x264
self.server_encodings_with_quality = c.strlistget("encodings.with_quality", ("jpeg", "webp", "h264"))
self.server_encodings_with_lossless_mode = c.strlistget("encodings.with_lossless_mode", ())
self.server_auto_video_encoding = c.boolget("auto-video-encoding")

e = c.strget("encoding")
if e:
if self.encoding and e!=self.encoding:
Expand All @@ -105,6 +103,7 @@ def parse_server_capabilities(self):
else:
log.info("server is using %s encoding instead of %s", e, self.encoding)
self.encoding = e
return True


def get_batch_caps(self):
Expand Down Expand Up @@ -292,9 +291,3 @@ def send_min_speed(self):
log("send_min_speed() min-speed=%s", s)
assert s==-1 or (s>=0 and s<=100), "invalid min-speed: %s" % s
self.send("min-speed", s)


######################################################################
# packets:
def init_authenticated_packet_handlers(self):
pass
5 changes: 4 additions & 1 deletion src/xpra/client/mixins/mmap_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from xpra.platform.features import MMAP_SUPPORTED
from xpra.scripts.config import TRUE_OPTIONS
from xpra.simple_stats import std_unit
from xpra.client.mixins.stub_client_mixin import StubClientMixin


"""
Mixin for adding mmap support to a client
"""
class MmapClient(object):
class MmapClient(StubClientMixin):
def __init__(self):
self.mmap_enabled = False
self.mmap = None
Expand Down Expand Up @@ -70,6 +71,8 @@ def parse_server_capabilities(self):
log.info("enabled fast mmap transfers using %sB shared memory area", std_unit(self.mmap_size, unit=1024))
#the server will have a handle on the mmap file by now, safe to delete:
self.clean_mmap()
return True


def get_caps(self):
if self.mmap_enabled:
Expand Down
14 changes: 6 additions & 8 deletions src/xpra/client/mixins/network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from xpra.os_util import monotonic_time, POSIX
from xpra.util import envint, csv
from xpra.exit_codes import EXIT_TIMEOUT
from xpra.client.mixins.stub_client_mixin import StubClientMixin


FAKE_BROKEN_CONNECTION = envint("XPRA_FAKE_BROKEN_CONNECTION")
Expand All @@ -27,7 +28,7 @@
- ping and echo
- info request and response
"""
class NetworkState(object):
class NetworkState(StubClientMixin):

def __init__(self):
self.start_time = monotonic_time()
Expand Down Expand Up @@ -57,10 +58,6 @@ def init(self, opts):
self.pings = opts.pings


def cleanup(self):
pass


def get_caps(self):
return {"info-namespace" : True}

Expand All @@ -70,6 +67,7 @@ def parse_server_capabilities(self):
self.server_bandwidth_limit_change = c.boolget("network.bandwidth-limit-change")
self.server_bandwidth_limit = c.intget("network.bandwidth-limit")
bandwidthlog("server_bandwidth_limit_change=%s, server_bandwidth_limit=%s", self.server_bandwidth_limit_change, self.server_bandwidth_limit)
return True

def process_ui_capabilities(self):
self.send_deflate_level()
Expand Down Expand Up @@ -113,11 +111,11 @@ def check_server_echo(self, ping_sent_time):
else:
self._server_ok = self.last_ping_echoed_time>=ping_sent_time
log("check_server_echo(%s) last=%s, server_ok=%s (last_ping_echoed_time=%s)", ping_sent_time, last, self._server_ok, self.last_ping_echoed_time)
self.server_state_change()
self.server_connection_state_change()
return False

def server_state_change(self):
log("server_state_change() ok=%s", self._server_ok)
def server_connection_state_change(self):
log("server_connection_state_change() ok=%s", self._server_ok)

def check_echo_timeout(self, ping_time):
log("check_echo_timeout(%s) last_ping_echoed_time=%s", ping_time, self.last_ping_echoed_time)
Expand Down
5 changes: 4 additions & 1 deletion src/xpra/client/mixins/notification_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from xpra.platform.gui import get_native_notifier_classes
from xpra.os_util import bytestostr
from xpra.util import envbool, repr_ellipsized, make_instance
from xpra.client.mixins.stub_client_mixin import StubClientMixin


NATIVE_NOTIFIER = envbool("XPRA_NATIVE_NOTIFIER", True)
Expand All @@ -19,7 +20,7 @@
"""
Utility superclass for clients that handle notifications
"""
class NotificationClient(object):
class NotificationClient(StubClientMixin):

def __init__(self):
self.client_supports_notifications = False
Expand Down Expand Up @@ -56,6 +57,8 @@ def parse_server_capabilities(self):
self.server_notifications_close = c.boolget("notifications.close")
self.server_notifications_actions = c.boolget("notifications.actions")
self.notifications_enabled = self.client_supports_notifications
return True


def get_notifications_caps(self):
return {
Expand Down
5 changes: 4 additions & 1 deletion src/xpra/client/mixins/remote_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

from xpra.scripts.config import parse_bool
from xpra.os_util import monotonic_time, strtobytes
from xpra.client.mixins.stub_client_mixin import StubClientMixin


"""
Mixin for remote logging support
"""
class RemoteLogging(object):
class RemoteLogging(StubClientMixin):

def __init__(self):
self.client_supports_remote_logging = False
Expand Down Expand Up @@ -51,6 +52,8 @@ def parse_server_capabilities(self):
if not self.log_both:
log.info(" see server log file for further output")
self.local_logging = set_global_logging_handler(self.remote_logging_handler)
return True


def remote_logging_handler(self, log, level, msg, *args, **kwargs):
#prevent loops (if our send call ends up firing another logging call):
Expand Down
22 changes: 17 additions & 5 deletions src/xpra/client/mixins/rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

from xpra.util import envint, AtomicInteger
from xpra.os_util import monotonic_time
from xpra.gtk_common.gobject_compat import import_glib
from xpra.client.mixins.stub_client_mixin import StubClientMixin

glib = import_glib()

RPC_TIMEOUT = envint("XPRA_RPC_TIMEOUT", 5000)


"""
Utility superclass for client classes that handle RPC calls
"""
class RPCClient(object):
class RPCClient(StubClientMixin):

def __init__(self):
#rpc / dbus:
Expand All @@ -32,7 +32,15 @@ def init(self, _opts):
def cleanup(self):
pass

def parse_capabilities(self):

def run(self):
pass

def setup_connection(self, _conn):
pass


def parse_server_capabilities(self):
c = self.server_capabilities
self.server_dbus_proxy = c.boolget("dbus_proxy")
#default for pre-0.16 servers:
Expand All @@ -41,6 +49,10 @@ def parse_capabilities(self):
else:
default_rpc_types = []
self.server_rpc_types = c.strlistget("rpc-types", default_rpc_types)
return True

def process_ui_capabilities(self):
pass


def rpc_call(self, rpc_type, rpc_args, reply_handler=None, error_handler=None):
Expand All @@ -53,7 +65,7 @@ def rpc_call(self, rpc_type, rpc_args, reply_handler=None, error_handler=None):
log("sending %s rpc request %s to server: %s", rpc_type, rpcid, req)
packet = ["rpc", rpc_type, rpcid] + rpc_args
self.send(*packet)
glib.timeout_add(RPC_TIMEOUT, self.rpc_filter_pending)
self.timeout_add(RPC_TIMEOUT, self.rpc_filter_pending)

def rpc_filter_pending(self):
""" removes timed out dbus requests """
Expand Down
Loading

0 comments on commit d074722

Please sign in to comment.