Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server_x11 performance boost #105

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions server/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def __init__(self, rpc_impl, server, plugins=tuple(), logger=None):
self.logger = logger or logging.getLogger(self.__class__.__name__)
self.server = server

self.logger.debug('using {0} for input emulation'.format(
rpc_impl.__class__.__name__))

for rpc_func, rpc_name in rpc_impl.rpc_commands.items():
self.server.register_function(rpc_name, rpc_func)
self.server.register_function(self.multiple_actions, 'multiple_actions')
Expand All @@ -51,17 +54,20 @@ def from_config(cls, platform_rpcs, config):
log_file=getattr(config, 'LOG_FILE', None))
logger = logging.getLogger(AeneaLoggingManager.aenea_logger_name)

rpc_server = SimpleJSONRPCServer((config.HOST, config.PORT))
rpc_server = SimpleJSONRPCServer(
(config.HOST, config.PORT), logRequests=False)

# TODO: dynamically load/instantiate platform_rpcs from config instead
# of requiring it as an explicit argument

plugins = AeneaPluginLoader(logger).get_plugins(
getattr(config, 'PLUGIN_DIR', None))
getattr(config, 'PLUGIN_PATH', None))

return cls(platform_rpcs, rpc_server, plugins=plugins, logger=logger)

def serve_forever(self):
self.logger.debug(
'starting server on {0}:{1}'.format(*self.server.server_address))
self.server.serve_forever()

def multiple_actions(self, actions):
Expand Down
6 changes: 4 additions & 2 deletions server/linux_x11/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
python-libxdo==0.1.2a1
psutil==3.0.0
jsonrpclib >= 0.1.7
mock >= 1.3.0
python-xlib >= 0.15rc1
yapsy >= 1.11.223
svn+https://svn.code.sf.net/p/python-xlib/code/trunk/
yapsy >= 1.11.223
66 changes: 46 additions & 20 deletions server/linux_x11/server_x11.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
# Copyright (2014) Alex Roper
# Alex Roper <alex@aroper.net>
import argparse
import os
import sys
from os.path import join, dirname, realpath
Expand All @@ -25,30 +26,55 @@

import config
from server.core import AeneaServer
from server.linux_x11.x11_xdotool import XdotoolPlatformRpcs

if __name__ == '__main__':
if '-d' in sys.argv or '--daemon' in sys.argv:


def daemonize():
if os.fork() == 0:
os.setsid()
if os.fork() == 0:
os.setsid()
if os.fork() == 0:
os.chdir('/')
os.umask(0)
# Safe upper bound on number of fds we could
# possibly have opened.
for fd in range(64):
try:
os.close(fd)
except OSError:
pass
os.open(os.devnull, os.O_RDWR)
os.dup2(0, 1)
os.dup2(0, 2)
else:
os._exit(0)
os.chdir('/')
os.umask(0)
# Safe upper bound on number of fds we could
# possibly have opened.
for fd in range(64):
try:
os.close(fd)
except OSError:
pass
os.open(os.devnull, os.O_RDWR)
os.dup2(0, 1)
os.dup2(0, 2)
else:
os._exit(0)
else:
os._exit(0)


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Aenea Linux X11 Server')
parser.add_argument(
'--daemon', action='store_const', const=True, default=False,
required=False, help='If provided the server runs in the background.')
parser.add_argument(
'--input', action='store', type=str, default='xdotool',
choices=('xdotool', 'libxdo'), required=False, dest='impl',
help='Aenea Server Input Method. Providing the default, '
'"xdotool" will make the server shell out to the xdotool '
'program to emulate input. "libxdo" will cause the server '
'to make calls to the xdo library.')

arguments = parser.parse_args()

if arguments.impl == 'xdotool':
from server.linux_x11.x11_xdotool import XdotoolPlatformRpcs
platform_rpcs = XdotoolPlatformRpcs(config)
elif arguments.impl == 'libxdo':
from server.linux_x11.x11_libxdo import XdoPlatformRpcs
platform_rpcs = XdoPlatformRpcs()

if arguments.daemon:
daemonize()

platform_rpcs = XdotoolPlatformRpcs(config)
server = AeneaServer.from_config(platform_rpcs, config)
server.serve_forever()
Loading