toxygen/src/tox.py

54 lines
1.6 KiB
Python
Raw Normal View History

2016-02-16 20:29:18 +01:00
# -*- coding: utf-8 -*-
2016-02-16 19:11:56 +01:00
from ctypes import *
from settings import Settings
2016-02-16 20:29:18 +01:00
import os
2016-02-16 19:11:56 +01:00
class ToxOptions(Structure):
_fields_ = [
("ipv6_enabled", c_bool),
("udp_enabled", c_bool),
("proxy_type", c_int),
("proxy_host", c_char_p),
("proxy_port", c_uint16),
("start_port", c_uint16),
("end_port", c_uint16),
("tcp_port", c_uint16),
("savedata_type", c_int),
2016-02-16 20:29:18 +01:00
("savedata_data", c_char_p),
2016-02-16 19:11:56 +01:00
("savedata_length", c_size_t)
]
class Tox(object):
2016-02-16 20:29:18 +01:00
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:
2016-02-16 19:11:56 +01:00
data = fl.read()
size = len(data)
print size
2016-02-16 20:29:18 +01:00
# 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
2016-02-16 19:11:56 +01:00
if __name__ == "__main__":
t = Tox('tox_save')