xref: /btstack/platform/daemon/binding/python/btstack/btstack_server.py (revision 6ccd8248590f666db07dd7add13fecb4f5664fb5)
1#!/usr/bin/env python3
2
3from threading import Thread
4from ctypes import *
5
6# global variables
7btstack_server_library = None
8
9class btstackServerThread (Thread):
10    def run(self):
11        global btstack_server_library
12        print ("[+] BTstack Server thread started")
13        btstack_server_library.btstack_server_run_tcp()
14        print ("[+] BTstack Server thread quit")
15
16class BTstackServer(object):
17    def __init__(self):
18        pass
19
20    def load(self, path = None):
21        global btstack_server_library
22        if path == None:
23            path = "../../../../port/daemon/src/"
24        print("[+] Load BTstack Server from %s" % path)
25        path += "libBTstackServer.dylib"
26        # TODO: check OS (mac,linux,windows)
27        # TODO: construct path to load library from
28        btstack_server_library = cdll.LoadLibrary("../../../../port/daemon/src/libBTstackServer.dylib")
29
30    def set_storage_path(self, path):
31        global btstack_server_library
32        print("[+] Set storage path to %s" % path)
33        btstack_server_library.btstack_server_set_storage_path("/tmp")
34
35    def run_tcp(self):
36        print("[+] Run TCP server")
37        btstackServerThread(name="BTstackServerThread").start()
38