Merge remote-tracking branch 'origin/master'
Conflicts: .gitignore
This commit is contained in:
commit
679ff926e8
2 changed files with 25 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ src/libs
|
||||||
.idea
|
.idea
|
||||||
*~
|
*~
|
||||||
*.iml
|
*.iml
|
||||||
|
*.so
|
||||||
|
|
34
src/tox.py
34
src/tox.py
|
@ -1,5 +1,7 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class ToxOptions(Structure):
|
class ToxOptions(Structure):
|
||||||
|
@ -13,25 +15,37 @@ class ToxOptions(Structure):
|
||||||
("end_port", c_uint16),
|
("end_port", c_uint16),
|
||||||
("tcp_port", c_uint16),
|
("tcp_port", c_uint16),
|
||||||
("savedata_type", c_int),
|
("savedata_type", c_int),
|
||||||
("savedata_data", POINTER(c_uint8)),
|
("savedata_data", c_char_p),
|
||||||
("savedata_length", c_size_t)
|
("savedata_length", c_size_t)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class Tox(object):
|
class Tox(object):
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name, path=None):
|
||||||
path = Settings.get_default_path() + name + '.tox'
|
if path is None:
|
||||||
with open(path, 'rb') as fl:
|
path = Settings.get_default_path()
|
||||||
|
full_path = path + name + '.tox'
|
||||||
|
with open(full_path, 'rb') as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
size = len(data)
|
size = len(data)
|
||||||
print size
|
print size
|
||||||
libtoxcore = CDLL('libtoxcore.so')
|
# TODO: different names for different OS
|
||||||
libtoxcore.tox_options_new.restype = POINTER(ToxOptions)
|
temp = os.path.abspath(__file__)
|
||||||
self.tox_options = libtoxcore.tox_options_new(0)
|
temp = os.path.realpath(temp)
|
||||||
libtoxcore.tox_new.restype = POINTER(c_void_p)
|
temp = os.path.dirname(temp)
|
||||||
tox = libtoxcore.tox_new(None, None)
|
os.chdir(temp + '/libs/')
|
||||||
self.libtoxcore = libtoxcore
|
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__":
|
if __name__ == "__main__":
|
||||||
t = Tox('tox_save')
|
t = Tox('tox_save')
|
||||||
|
|
Loading…
Reference in a new issue