From fa2877fc23a70e1ce4d5b3adfa7448ad67542b5a Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 16 Feb 2016 22:29:18 +0300 Subject: [PATCH 1/2] Libraries load added --- .gitignore | 1 + src/tox.py | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 9b7a72c..44bf488 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ src/toxcore src/libs .idea *~ +*.so diff --git a/src/tox.py b/src/tox.py index 792ac45..714701c 100644 --- a/src/tox.py +++ b/src/tox.py @@ -1,5 +1,7 @@ +# -*- coding: utf-8 -*- from ctypes import * from settings import Settings +import os class ToxOptions(Structure): @@ -13,25 +15,37 @@ class ToxOptions(Structure): ("end_port", c_uint16), ("tcp_port", c_uint16), ("savedata_type", c_int), - ("savedata_data", POINTER(c_uint8)), + ("savedata_data", c_char_p), ("savedata_length", c_size_t) ] class Tox(object): - def __init__(self, name): - path = Settings.get_default_path() + name + '.tox' - with open(path, 'rb') as fl: + def __init__(self, name, path=None): + if path is None: + path = Settings.get_default_path() + full_path = path + name + '.tox' + with open(full_path, 'rb') as fl: data = fl.read() size = len(data) print size - libtoxcore = CDLL('libtoxcore.so') - libtoxcore.tox_options_new.restype = POINTER(ToxOptions) - self.tox_options = libtoxcore.tox_options_new(0) - libtoxcore.tox_new.restype = POINTER(c_void_p) - tox = libtoxcore.tox_new(None, None) - self.libtoxcore = libtoxcore + # TODO: different names for different OS + temp = os.path.abspath(__file__) + temp = os.path.realpath(temp) + temp = os.path.dirname(temp) + os.chdir(temp + '/libs/') + self.libtoxcore = CDLL('libtoxcore.so') + print self.libtoxcore.__dict__ + self.libtoxcore.tox_options_new.restype = POINTER(ToxOptions) + # TODO: load from settings + self.tox_options = self.libtoxcore.tox_options_new(0) + self.tox_options.contents.savedata_length = size + self.tox_options.contents.savedata_data = c_char_p(data) + self.libtoxcore.tox_new.restype = POINTER(c_void_p) + self.tox = self.libtoxcore.tox_new(self.tox_options, None) # Tox *tox + print self.tox.contents + if __name__ == "__main__": t = Tox('tox_save') From 4447de99ac7d67e22bc377e67d7e3fe786650c78 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 16 Feb 2016 22:31:44 +0300 Subject: [PATCH 2/2] Libraries loading updated --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 44bf488..ee7cf01 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ src/toxcore src/libs .idea *~ +*.iml *.so