Libraries load added

This commit is contained in:
ingvar1995 2016-02-16 22:29:18 +03:00
parent a8d50bb699
commit fa2877fc23
2 changed files with 25 additions and 10 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ src/toxcore
src/libs src/libs
.idea .idea
*~ *~
*.so

View File

@ -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')