# Copyright (C) 2016 RealVNC Limited. All rights reserved.
from datetime import datetime
import atexit, os, sys, threading
_PYTHON3 = sys.version_info >= (3, 0)
if _PYTHON3:
import queue
try:
callable(None)
except NameError:
# For some annoying reason, they took the callable() builtin out in Python
# 3.0, but it's very hard to get exactly-correct behaviour without it.
# Thankfully, it's back in 3.2, so we go with collections.Callable to cover
# 3.0 and 3.1 (this is what Python's 2to3 tool uses as the replacement for
# callable(), so I think it ought to be a usable replacement).
callable = lambda fn: isinstance(fn, collections.Callable)
else:
import Queue as queue
class DestroyedObjectException(Exception):
def __init__(self):
Exception.__init__(self, "Illegal method call after destroy()")
class VncException(Exception):
def __init__(self, errorCode, callingFunction, detail=''):
if detail: detail = ' (%s)' % detail
Exception.__init__(self, "Error in %s: %s%s" %
(callingFunction, errorCode, detail))
self.errorCode = errorCode
# Lookup table mapping native pointers (integers) to Python objects
_global_native_pointer_lookup = {}
# If we can't find a function via ctypes, we use _unavailable_function to
# create a suitable replacement which simply throws.
def _unavailable_function(name):
@staticmethod
def unavailable(*args):
raise NameError('"%s" is not supported on the current platform' % (name,))
return unavailable
def _wrap_sdk_function(dll, name, argtypes, restype):
try:
func = dll[name]
func.argtypes = argtypes
func.restype = restype
return func
except AttributeError:
return _unavailable_function(name)
# Factory for SDK enum objects, which creates an object with similar usage to
# Python 3.4's enum.Enum.
def _create_enum(name, docstring, **values):
enumerated = {}
reverse_mapping = {}
for k, v in values.items():
klass = type('%s.%s' % (name, k), (object,), {'name': k, 'value': v})
klass.__repr__ = lambda self: "<%s.%s: %d>" % (name, self.name, self.value)
instance = klass()
enumerated[k] = instance
reverse_mapping[v] = instance
enum = type(name, (object,), dict(enumerated, __doc__=docstring))
enum.members = staticmethod(lambda: enumerated.values())
enum.__new__ = staticmethod(lambda cls, v: reverse_mapping[v])
return enum
# Convert the bits of n to a set of instances of enum_class.
# Ignores unexpected bits.
def _int_to_enums(n, enum_class):
vals = [x.value for x in enum_class.members()]
bits = [x for x in vals if x and x & (x-1) == 0]
return set(enum_class(bit) for bit in bits if n & bit)
# Convert a set of Enum instances to an int.
def _enums_to_int(enums):
rv = 0
for e in enums:
rv |= e.value
return rv
# Convert Python string to SDK string (UTF-8 bytes)
def _encode_unicode(string, allowNone=False):
if string is None and allowNone:
return None
if _PYTHON3:
if isinstance(string, str):
return string.encode("utf-8")
elif isinstance(string, bytes):
return string
else:
raise TypeError("expected string or bytes, got {type}".format(type=type(string)))
else:
if isinstance(string, str):
return string
elif isinstance(string, unicode):
return string.encode("utf-8")
else:
raise TypeError("expected string or unicode, got {type}".format(type=type(string)))
# Convert SDK string (UTF-8 bytes) to Python string
def _decode_unicode(bytes):
return bytes.decode("utf-8") if _PYTHON3 else bytes
# Unguarded import, the SDK wrapper requires ctypes.
import ctypes as _CT
import ctypes.util
# Locate a file in the SDK's default directory structure (locates the SDK library
# if filename is None)
def _find_binary(path, filename):
sdk_lib_name = None
sdk_exe_suffix = ''
sdk_dir_name = None
if sys.platform == 'win32' or sys.platform == 'cygwin':
sdk_exe_suffix = '.exe'
sdk_lib_name = 'vncsdk.dll'
sdk_dir_name = 'win-x64' if _CT.sizeof(_CT.c_void_p) == 8 else 'win-x86'
elif sys.platform == 'darwin' and _CT.sizeof(_CT.c_void_p) == 8:
sdk_lib_name = "libvncsdk.{major}.{minor}.dylib".format(
major=1,
minor=7
)
sdk_dir_name = 'mac-x64'
elif 'linux' in sys.platform:
sdk_lib_name = "libvncsdk.so.{major}.{minor}".format(
major=1,
minor=7
)
sdk_dir_name = 'linux-armhf-raspi' if 'arm' in os.uname()[4] else \
'linux-x64' if _CT.sizeof(_CT.c_void_p) == 8 else \
'linux-x86'
else:
raise Exception("could not determine the default directory name for this platform")
if filename is None:
filename = sdk_lib_name
else:
filename = filename + sdk_exe_suffix
sdk_path_pref_dir = os.path.join(path, filename)
sdk_path_pref_dir2 = os.path.join(path, sdk_dir_name, filename)
if os.path.exists(sdk_path_pref_dir):
return sdk_path_pref_dir
if os.path.exists(sdk_path_pref_dir2):
return sdk_path_pref_dir2
raise Exception("could not find the SDK binary {dir} or {dir2}".format(
dir=sdk_path_pref_dir,
dir2=sdk_path_pref_dir2
))
# Finds the path to the SDK library for the current platform
def _find_library():
sdk_path_pref = None
try:
sdk_path_pref = os.path.abspath(os.environ['VNCSDK_LIBRARY'])
except KeyError:
sdk_path_auto = ctypes.util.find_library('vncsdk')
if not sdk_path_auto:
raise ImportError("could not find the SDK shared object: place it in the system path or set the VNCSDK_LIBRARY environment variable to point to it")
return sdk_path_auto
if not os.path.exists(sdk_path_pref):
raise ImportError("could not find the SDK shared object: VNCSDK_LIBRARY is not a file or directory")
if not os.path.isdir(sdk_path_pref):
return sdk_path_pref
try:
return _find_binary(sdk_path_pref, None)
except Exception as e:
raise ImportError(str(e))
class SdkDll():
''' This class loads & unloads the sdk dll
It is responsible for binding the functions in the dll
as well as trying to force the unloading of the dll.
'''
instance = None
nativeFunctionsToWrap = {}
@classmethod
def get_instance(clazz):
if clazz.instance is None:
clazz.instance = SdkDll(_find_library())
return clazz.instance
@classmethod
def has_instance(clazz):
return clazz.instance is not None
@classmethod
def unload_instance(clazz):
clazz.instance = None
@classmethod
def register_class_function(clazz, name, *args):
clazz.nativeFunctionsToWrap[name] = args
def wrapper(*args, **kargs):
return SdkDll.get_instance().get_function(name)(*args, **kargs)
return staticmethod(wrapper)
@classmethod
def register_floating_function(clazz, name, *args):
clazz.nativeFunctionsToWrap[name] = args
def wrapper(*args, **kargs):
return SdkDll.get_instance().get_function(name)(*args, **kargs)
return wrapper
def get_function(self, name):
return getattr(self, name)
def __init__(self, location):
self.dllInstance = ctypes.cdll[location]
for m, args in self.nativeFunctionsToWrap.items():
wrapped = _wrap_sdk_function(self.dllInstance, m, *args)
setattr(self, m, wrapped)
def init(eventLoopType = None):
'''Initializes the SDK with the default vnc_EventLoopType for the platform.'''
if get_major_version() != 1\
or get_minor_version() != 7\
or get_patch_version() != 0\
or get_build_number () != 37830:
e = VncException("VersionError", "init()")
_Private.logger_write(Logger.Level.ERROR, 'PythonSDK', str(e))
raise e
init_internal(\
1,\
7,\
0,\
37830,\
eventLoopType if eventLoopType else EventLoopType.DEFAULT)
def _throwVncException(callingFunction):
ex = get_last_error()
raise VncException(ex if ex else "Unknown", callingFunction)
class ConnectionHandler(object):
'''Opaque type for a connection handler, enabling a Viewer or Server to perfor
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
vncsdk-1.7.0.tar.gz (1082个子文件)
libvncsdk.so.1.7 5.06MB
libvncsdk.so.1.7 4.94MB
libvncsdk.so.1.7 4.88MB
libvncsdk.so.1.7 4.01MB
libvncsdk.so.1.7 3.99MB
libvncsdk.so.1.7 3.98MB
gradlew.bat 2KB
gradlew.bat 2KB
common.cmake 6KB
run.cmd 3KB
CodeResources 8KB
vncsdkServer.conf 145B
App.config 186B
VncViewerSession.cs 18KB
MainWindow.xaml.cs 14KB
VncLibraryThread.cs 7KB
ViewerControl.cs 6KB
VncWinformEventMap.cs 6KB
Resources.Designer.cs 3KB
AssemblyInfo.cs 2KB
VncKeyMapper.cs 2KB
Settings.Designer.cs 1KB
ViewerControl.Designer.cs 1024B
ConnectSettings.cs 911B
ConnectSettingsWindow.xaml.cs 820B
App.xaml.cs 350B
BasicViewerCSharpWpf.csproj 6KB
foundation.css 196KB
theme.css 100KB
jquery-ui.min.css 29KB
font-awesome.min.css 23KB
app.css 22KB
jquery-ui.structure.min.css 14KB
jquery-ui.theme.min.css 14KB
basic.css 9KB
theme.green.css 8KB
theme.grey.css 8KB
normalize.css 8KB
theme.dropbox.css 8KB
app.css 7KB
theme.blue.css 7KB
theme.ice.css 6KB
theme.metro-dark.css 6KB
theme.default.css 5KB
theme.black-ice.css 5KB
filter.formatter.css 5KB
theme.bootstrap_2.css 5KB
theme.dark.css 5KB
theme.bootstrap.css 5KB
theme.jui.css 4KB
pygments.css 4KB
viewer.css 4KB
pygments.css 3KB
badge_only.css 3KB
color-brewer.css 3KB
hybrid.css 3KB
railscasts.css 3KB
default.css 3KB
monokai_sublime.css 2KB
sunburst.css 2KB
xcode.css 2KB
obsidian.css 2KB
arta.css 2KB
googlecode.css 2KB
monokai.css 2KB
school_book.css 2KB
magula.css 2KB
zenburn.css 2KB
docco.css 2KB
atelier-lakeside.light.css 2KB
atelier-lakeside.dark.css 2KB
atelier-seaside.light.css 2KB
atelier-seaside.dark.css 2KB
atelier-forest.light.css 2KB
atelier-forest.dark.css 2KB
atelier-heath.light.css 2KB
far.css 2KB
atelier-heath.dark.css 2KB
atelier-dune.light.css 2KB
idea.css 2KB
atelier-dune.dark.css 2KB
brown_paper.css 2KB
dark.css 2KB
tomorrow-night-blue.css 2KB
tomorrow-night.css 2KB
github.css 2KB
pojoaque.css 2KB
foundation.css 2KB
solarized_dark.css 2KB
solarized_light.css 2KB
tomorrow-night-eighties.css 2KB
tomorrow-night-bright.css 2KB
kimbie.light.css 2KB
kimbie.dark.css 2KB
vs.css 2KB
codepen-embed.css 2KB
paraiso.light.css 2KB
paraiso.dark.css 2KB
ir_black.css 1KB
rainbow.css 1KB
共 1082 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
chinalishiming
- 粉丝: 0
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功