summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVasilii Chernov <vchernov@inr.ru>2016-03-01 16:42:48 +0100
committerVasilii Chernov <vchernov@inr.ru>2016-03-01 16:42:48 +0100
commit9b947f32c3db96c3022afad401b1349205d22259 (patch)
tree1bc5fbc5c82752d1808a240964317c6813ad19c3
parent5d775d64bdec554b9842823bd1c46263210425fd (diff)
downloadpcitool-9b947f32c3db96c3022afad401b1349205d22259.tar.gz
pcitool-9b947f32c3db96c3022afad401b1349205d22259.tar.bz2
pcitool-9b947f32c3db96c3022afad401b1349205d22259.tar.xz
pcitool-9b947f32c3db96c3022afad401b1349205d22259.zip
1. api-serer:
- change multiprosessing work mechanism - add new pywrap functions handling 2. html-server: - now works through api-server
-rw-r--r--html_server/html_server.py257
-rw-r--r--html_server/static/base.css46
-rw-r--r--html_server/static/check_err.js4
-rw-r--r--html_server/templates/base.html63
-rw-r--r--html_server/templates/property_info.html6
-rw-r--r--html_server/templates/registers/table_scripts.html8
-rw-r--r--pywrap/api_server.py146
-rw-r--r--pywrap/pcipywrap.c2
-rw-r--r--pywrap/pcipywrap.h2
-rw-r--r--pywrap/pcipywrap.i2
-rw-r--r--xml/scripts/test_script.py2
-rw-r--r--xml/test/test_prop_mt.py2
12 files changed, 297 insertions, 243 deletions
diff --git a/html_server/html_server.py b/html_server/html_server.py
index 0d4bca8..22194cd 100644
--- a/html_server/html_server.py
+++ b/html_server/html_server.py
@@ -1,6 +1,10 @@
-import pcipywrap
import json
-from optparse import OptionParser
+
+from optparse import OptionParser, OptionGroup
+from multiprocessing import Process
+
+import requests
+from api_server import ApiServer
#import flask elements
from flask import render_template
@@ -9,140 +13,107 @@ from flask import request
from flask import url_for
from flask import redirect
from flask import send_from_directory
+from flask import make_response
app = Flask(__name__)
-pcilib = 0;
-device = '/dev/fpga0'
-model = ''
+api_server_port = 9000
+api_server_host = '0.0.0.0'
-# property json api
-@app.route("/property_info_json")
-def get_property_list_json():
- branch = request.args.get('branch')
- if not branch is None:
- branch = str(branch)
+@app.route("/json/<command>")
+def process_json_command(command):
+ headers = {'content-type': 'application/json'}
+ message = {'command': command}
- prop_info = 0
- try:
- prop_info = pcilib.get_property_list(branch)
- return json.dumps(prop_info)
- except Exception as e:
- return json.dumps({'error': str(e)})
-
-@app.route('/get_property_json')
-def get_property_json():
- prop = request.args.get('prop')
-
- try:
- val = pcilib.get_property(str(prop))
- return json.dumps({'value': val})
- except Exception as e:
- return json.dumps({'error': str(e)})
-
-@app.route('/set_property_json')
-def set_property_json():
- val = request.args.get('val')
- prop = request.args.get('prop')
-
- try:
- pcilib.set_property(float(val), str(prop))
- return json.dumps({'status': 'ok'})
- except Exception as e:
- return json.dumps({'error': str(e)})
+ for arg in request.args:
+ message[arg] = request.args[arg]
-# register json api
-@app.route("/registers_list_json")
-def get_registers_list_json():
- reg_list = 0
+ r = 0;
try:
- reg_list = pcilib.get_registers_list()
- return json.dumps(reg_list)
+ r = requests.get('http://' + api_server_host + ':' + str(api_server_port),
+ data=json.dumps(message),
+ headers=headers)
except Exception as e:
- return json.dumps({'error': str(e)})
-
-@app.route('/read_register_json')
-def read_register_json():
- name = request.args.get('name')
- bank = request.args.get('bank')
+ return str(json.dumps({'status':'error', 'description': e}))
- try:
- value = pcilib.read_register(str(name), str(bank))
- return json.dumps({'value': value})
- except Exception as e:
- return json.dumps({'error': str(e)})
-
-@app.route('/write_register_json')
-def write_register_json():
- val = request.args.get('val')
- name = request.args.get('name')
- bank = request.args.get('bank')
-
- try:
- pcilib.write_register(float(val), str(name), str(bank))
- return json.dumps({'status': 'ok'})
- except Exception as e:
- return json.dumps({'error': str(e)})
+ #application/octet-stream
+ response = make_response(r.content)
+ for header in r.headers:
+ response.headers[header] = r.headers[header]
+
+ return response
#html api
-@app.route('/set_property')
-def set_property():
- val = request.args.get('val')
- prop = request.args.get('prop')
-
- try:
- pcilib.set_property(float(val), str(prop))
- return redirect(url_for('get_property_list', branch=prop))
- except Exception as e:
- return str(e)
-
-@app.route('/write_register')
-def write_register():
- val = request.args.get('val')
- name = request.args.get('name')
- bank = request.args.get('bank')
-
- try:
- pcilib.write_register(float(val), str(name), str(bank))
- return redirect(url_for('get_register_info', name=name, bank=bank))
- except Exception as e:
- return str(e)
-
@app.route('/register_info')
def get_register_info():
+ #get parameters
name = request.args.get('name')
bank = request.args.get('bank')
+ #load register info
reg_info = 0
value = dict()
try:
- reg_info = pcilib.get_register_info(str(name), str(bank))
- value[name] = pcilib.read_register(str(name), str(bank))
+ r = requests.get(url_for('process_json_command',
+ command = 'get_register_info',
+ bank = bank,
+ reg = name, _external = True))
+ if(r.json().get('status') == 'error'):
+ return 'Error: ' + r.json()['description']
+
+ reg_info = r.json()['register']
+
+ #get register value
+ r = requests.get(url_for('process_json_command',
+ command = 'read_register',
+ bank = bank,
+ reg = name, _external = True))
+ if(r.json().get('status') == 'error'):
+ return 'Error: ' + r.json()['description']
+
+ value[name] = r.json()['value']
except Exception as e:
return str(e)
+
return render_template('register_info.html',
register=reg_info,
value=value)
@app.route("/registers_list")
def get_registers_list():
+ #get parameters
bank = request.args.get('bank')
if not bank is None:
bank = str(bank)
-
- reg_list = 0
+
+ #load registers list
+ reg_list = []
try:
- reg_list = pcilib.get_registers_list(bank)
+ r = requests.get(url_for('process_json_command',
+ command = 'get_registers_list',
+ bank = bank, _external = True))
+ if(r.json().get('status') == 'error'):
+ return 'Error: ' + r.json()['description']
+ reg_list = r.json()['registers']
except Exception as e:
return str(e)
+ #get register values
value = dict()
for reg in reg_list:
try:
- value[reg['name']] = pcilib.read_register(str(reg['name']),
- str(reg['bank']))
+ r = requests.get(url_for('process_json_command',
+ command = 'read_register',
+ bank = str(reg['bank']),
+ reg = str(reg['name']), _external = True))
+ if(r.json().get('status') == 'error'):
+ value[reg['name']] = 'Error: ' + r.json()['description']
+ else:
+ value[reg['name']] = r.json()['value']
+
except Exception as e:
- value[reg['name']] = str(e)
+ value[reg['name']] = 'Error: ' + str(e)
+ #render result
return render_template('registers_list.html',
registers = reg_list,
render_template = render_template,
@@ -151,30 +122,40 @@ def get_registers_list():
@app.route("/property_info")
def get_property_list():
+ #get parameters
branch = request.args.get('branch')
if not branch is None:
branch = str(branch)
- prop_info = 0
+ #get properties info
+ prop_info = 0
try:
- prop_info = pcilib.get_property_list(branch)
+ r = requests.get(url_for('process_json_command',
+ command = 'get_property_list',
+ branch = branch, _external = True))
+
+ if(r.json().get('status') == 'error'):
+ return 'Error: ' + r.json()['description']
+
+ prop_info = r.json()['properties']
+
except Exception as e:
return str(e)
value = dict()
- if (len(prop_info) == 1) and not ('childs' in (prop_info[0])['flags']):
+ for prop in prop_info:
try:
- branch = (prop_info[0])['path']
- value[branch] = pcilib.get_property(branch)
+ path = prop['path']
+ r = requests.get(url_for('process_json_command',
+ command = 'get_property',
+ prop = path, _external = True))
+ if(r.json().get('status') == 'error'):
+ value[path] = 'Error: ' + r.json()['description']
+ else:
+ value[path] = r.json()['value']
+
except Exception as e:
- return str(e)
- else:
- for prop in prop_info:
- try:
- path = prop['path']
- value[path] = pcilib.get_property(path)
- except Exception as e:
- value[path] = str(e)
+ value[path] = str(e)
return render_template('property_info.html',
value = value,
@@ -195,12 +176,32 @@ if __name__ == "__main__":
parser.add_option("-p", "--port", action="store",
type="int", dest="port", default=5000,
help="Set server port (5000)")
- parser.add_option("-d", "--device", action="store",
- type="string", dest="device", default=str('/dev/fpga0'),
- help="FPGA device (/dev/fpga0)")
- parser.add_option("-m", "--model", action="store",
- type="string", dest="model", default=None,
- help="Memory model (autodetected)")
+
+ pcilib_group = OptionGroup(parser, "Api server",
+ "Api server options group")
+ pcilib_group.add_option("-e", "--external", action="store_true",
+ dest="external_api_server",
+ default=False,
+ help="Dont start own api server. Use external"
+ " server instead");
+ pcilib_group.add_option("--api-server-host", action="store",
+ type="string", dest="api_server_host",
+ default='0.0.0.0',
+ help="Api server ip adress (0.0.0.0)")
+ pcilib_group.add_option("--api-server-port", action="store",
+ type="int", dest="api_server_port",
+ default=9000,
+ help="Api server port (9000)")
+ pcilib_group.add_option("-d", "--device", action="store",
+ type="string", dest="device",
+ default=str('/dev/fpga0'),
+ help="FPGA device (/dev/fpga0)")
+ pcilib_group.add_option("-m", "--model", action="store",
+ type="string", dest="model", default=None,
+ help="Memory model (autodetected)")
+
+ parser.add_option_group(pcilib_group)
+
opts = parser.parse_args()[0]
HOST_NAME = '0.0.0.0'
@@ -209,6 +210,22 @@ if __name__ == "__main__":
device = opts.device
model = opts.model
- pcilib = pcipywrap.Pcipywrap(device, model)
- pcipywrap.__redirect_logs_to_exeption()
- app.run(host = HOST_NAME, port = PORT_NUMBER, threaded=True)
+ #start api server in separate process
+ api_server_host = opts.api_server_host
+ api_server_port = opts.api_server_port
+ if(not opts.external_api_server):
+ api_server = ApiServer(device, model, (api_server_host, api_server_port))
+ def serve_forever(server):
+ try:
+ server.serve_forever()
+ except KeyboardInterrupt:
+ pass
+
+ Process(target=serve_forever, args=(api_server,)).start()
+
+ #start Flask html server
+ app.run(host = HOST_NAME,
+ port = PORT_NUMBER,
+ threaded=True,
+ #debug=True
+ )
diff --git a/html_server/static/base.css b/html_server/static/base.css
new file mode 100644
index 0000000..15c2249
--- /dev/null
+++ b/html_server/static/base.css
@@ -0,0 +1,46 @@
+.tabs > div, .tabs > input { display: none; }
+
+.tabs label {
+ padding: 5px;
+ border: 1px solid #aaa;
+ line-height: 28px;
+ cursor: pointer;
+ position: relative;
+ bottom: 1px;
+ background: #fff;
+}
+
+.tabs input[type="radio"]:checked + label { border-bottom: 2px solid #fff; }
+
+.tabs > input:nth-of-type(1):checked ~ div:nth-of-type(1),
+.tabs > input:nth-of-type(2):checked ~ div:nth-of-type(2) {
+ display: block;
+ padding: 5px;
+ border:
+ 1px solid #aaa;
+}
+.tree {
+ height: 85vh;
+ padding: 5px;
+ border: 1px solid #aaa;
+ line-height: 28px;
+ cursor: pointer;
+ position: relative;
+ bottom: 1px;
+ background: #fff;
+ overflow:auto;
+}
+
+.infoTable {
+ padding: 2px;
+
+ border: 1px solid #aaa;
+ line-height: 28px;
+ cursor: pointer;
+ position: relative;
+ background: #fff;
+ overflow:auto;
+ bottom: 1px;
+
+ text-align: left;
+}
diff --git a/html_server/static/check_err.js b/html_server/static/check_err.js
index a63d7bc..66519ea 100644
--- a/html_server/static/check_err.js
+++ b/html_server/static/check_err.js
@@ -1,4 +1,4 @@
function checkError(json) {
- if(json.error)
- alert('Error: ' + json.error)
+ if(json.status === 'error')
+ alert('Error: ' + json.description)
}
diff --git a/html_server/templates/base.html b/html_server/templates/base.html
index 0e3aea8..a2df1e9 100644
--- a/html_server/templates/base.html
+++ b/html_server/templates/base.html
@@ -5,6 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='codebase/dhtmlx.css') }}"/>
+ <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='base.css') }}"/>
<script type=text/javascript src="{{ url_for('static', filename='jquery-2.2.1.js') }}"></script>
<script src="{{ url_for('static', filename='codebase/dhtmlx.js') }}"></script>
<script src="{{ url_for('static', filename='check_err.js') }}"></script>
@@ -13,8 +14,8 @@
function createPropertyTree(branch, id) {
function getPropertyItemsOnLevel(branch, id) {
- pathToProperties = "{{ url_for('get_property_list_json') }}"
- completePath = pathToProperties + '?branch=' + branch
+ var pathToProperties = "{{ url_for('process_json_command', command = 'get_property_list') }}"
+ var completePath = pathToProperties + '?branch=' + branch
$.getJSON(completePath,
function(json) {
@@ -25,6 +26,9 @@
function parsePropertyItems(json, branch, id) {
+ checkError(json)
+ json = json.properties
+
function loadPropertyInfo(branch) {
var pathToProperties = "{{ url_for('get_property_list') }}"
@@ -57,6 +61,8 @@
var regTree
function createRegistersList() {
function parseJsonRegisterList(json) {
+ checkError(json)
+ json = json.registers
function loadRegistersList(bank) {
var pathToGetRegisterList = "{{ url_for('get_registers_list') }}"
@@ -129,7 +135,7 @@
}
//get registers json list
- getRegistersListPath = "{{ url_for('get_registers_list_json') }}"
+ var getRegistersListPath = "{{ url_for('process_json_command', command = 'get_registers_list') }}"
$.getJSON(getRegistersListPath, parseJsonRegisterList);
}
@@ -152,54 +158,6 @@
<h2>Device {{ device }} model={{ model }} control page </h2>
</div>
{% endblock %}
- <style>
- .tabs > div, .tabs > input { display: none; }
-
- .tabs label {
- padding: 5px;
- border: 1px solid #aaa;
- line-height: 28px;
- cursor: pointer;
- position: relative;
- bottom: 1px;
- background: #fff;
- }
-
- .tabs input[type="radio"]:checked + label { border-bottom: 2px solid #fff; }
-
- .tabs > input:nth-of-type(1):checked ~ div:nth-of-type(1),
- .tabs > input:nth-of-type(2):checked ~ div:nth-of-type(2) {
- display: block;
- padding: 5px;
- border:
- 1px solid #aaa;
- }
- .tree {
- height: 85vh;
- padding: 5px;
- border: 1px solid #aaa;
- line-height: 28px;
- cursor: pointer;
- position: relative;
- bottom: 1px;
- background: #fff;
- overflow:auto;
- }
-
- .infoTable {
- padding: 2px;
-
- border: 1px solid #aaa;
- line-height: 28px;
- cursor: pointer;
- position: relative;
- background: #fff;
- overflow:auto;
- bottom: 1px;
-
- text-align: left;
- }
- </style>
<div class="tabs">
<input type="radio" name="current" checked="checked" id="props_id"/>
@@ -229,5 +187,8 @@
</div>
{% block content %}
{% endblock %}
+ <div class="block1" >
+ <a href="{{ url_for('process_json_command', command='help') }}">Json API usage</a>
+ </div>
</body>
</html>
diff --git a/html_server/templates/property_info.html b/html_server/templates/property_info.html
index 4e7c92f..62ea1ba 100644
--- a/html_server/templates/property_info.html
+++ b/html_server/templates/property_info.html
@@ -7,7 +7,7 @@
<script>
function updateProperty(prop) {
- var pathToGetProperty = "{{ url_for('get_property_json') }}"
+ var pathToGetProperty = "{{ url_for('process_json_command', command = 'get_property') }}"
var completePath = pathToGetProperty + '?prop=' + prop
$.getJSON(completePath, function(json){
@@ -23,9 +23,9 @@
if(value == "")
return
- var pathToGetProperty = "{{ url_for('set_property_json') }}"
+ var pathToGetProperty = "{{ url_for('process_json_command', command = 'set_property') }}"
var completePath = pathToGetProperty + '?prop=' + prop +
- '&val=' + value;
+ '&value=' + value;
$.getJSON(completePath,
function(json) {
diff --git a/html_server/templates/registers/table_scripts.html b/html_server/templates/registers/table_scripts.html
index 017c910..a772b9f 100644
--- a/html_server/templates/registers/table_scripts.html
+++ b/html_server/templates/registers/table_scripts.html
@@ -13,9 +13,9 @@
*/
function updateRegister(bank, name) {
- var pathToReadRegister = "{{ url_for('read_register_json') }}"
+ var pathToReadRegister = "{{ url_for('process_json_command', command = 'read_register') }}"
var completePath = pathToReadRegister + '?bank=' + bank +
- '&name=' + name
+ '&reg=' + name
$.getJSON(completePath, function(json){
checkError(json)
@@ -29,9 +29,9 @@
if(value == "")
return
- var pathToReadRegister = "{{ url_for('write_register_json') }}"
+ var pathToReadRegister = "{{ url_for('process_json_command', command = 'write_register') }}"
var completePath = pathToReadRegister + '?bank=' + bank +
- '&name=' + name + '&val=' + value;
+ '&reg=' + name + '&value=' + value;
$.getJSON(completePath,
function(json) {
diff --git a/pywrap/api_server.py b/pywrap/api_server.py
index da3a275..18ee1f8 100644
--- a/pywrap/api_server.py
+++ b/pywrap/api_server.py
@@ -7,8 +7,12 @@ import time
import json
from optparse import OptionParser
-from multiprocessing import Process, current_process
+from multiprocessing import Process
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
+from SocketServer import ThreadingMixIn
+
+class MultiThreadedHTTPServer(ThreadingMixIn, HTTPServer):
+ pass
class PcilibServerHandler(BaseHTTPRequestHandler):
@@ -22,6 +26,12 @@ class PcilibServerHandler(BaseHTTPRequestHandler):
s.end_headers()
def do_GET(s):
+ #run request in separate process
+ p = Process(target=s.do_GET_worker, args=())
+ p.start()
+ p.join()
+
+ def do_GET_worker(s):
length = int(s.headers['Content-Length'])
#deserialize input data
@@ -289,7 +299,6 @@ class PcilibServerHandler(BaseHTTPRequestHandler):
lock_id = str(data.get('lock_id'))
try:
- print 'unlocking ' + lock_id
s.pcilib.unlock(lock_id)
except Exception as e:
s.error(str(e), data)
@@ -300,6 +309,48 @@ class PcilibServerHandler(BaseHTTPRequestHandler):
+ elif(command == 'get_scripts_list'):
+ scripts = list()
+ try:
+ scripts = s.pcilib.get_scripts_list()
+ except Exception as e:
+ s.error(str(e), data)
+ return
+
+ #Success! Create and send reply
+ s.wrapMessageAndSend({'status': 'ok', 'scripts': scripts}, data)
+
+
+
+ elif(command == 'run_script'):
+ #check required arguments
+ if not 'script_name' in data:
+ s.error('message doesnt contains "script_name" field, '
+ 'which is required for "run_script" command', data)
+ return
+ #parse command arguments and convert them to string
+ script_name = str(data.get('script_name'))
+ value = data.get('value', None)
+
+ out = None
+ try:
+ out = s.pcilib.run_script(script_name, value)
+ except Exception as e:
+ s.error(str(e), data)
+ return
+
+ #Success! Create and send reply
+ if(type(out) == bytearray):
+ s.send_response(200)
+ s.send_header('content-disposition', 'inline; filename=value')
+ s.send_header('content-type', 'application/octet-stream')
+ s.end_headers()
+ s.wfile.write(out)
+ else:
+ s.wrapMessageAndSend({'status': 'ok', 'value': out}, data)
+
+
+
#elif(command == 'lock_global'):
# #check if global_lock already setted by server
# try:
@@ -324,17 +375,14 @@ class PcilibServerHandler(BaseHTTPRequestHandler):
# s.wrapMessageAndSend({'status': 'ok'}, data)
-
else:
s.error('command "' + command + '" undefined', data)
return
else:
s.error('message doesnt contains "command" field, which is required', data)
return
-
-
- #print str(s.headers['content-type'])
- #print post_data['some']
+
+
#open device context
#def openPcilibInstance(s, device, model):
@@ -418,9 +466,22 @@ class PcilibServerHandler(BaseHTTPRequestHandler):
' lock_id: - lock id\n'
'\n'
+ ' command: get_scripts_list - Get aviable scripts with description\n'
+ '\n'
+
+ ' command: run_script - Run specified script\n'
+ ' required fields\n'
+ ' script_name: - script name (with extension)\n'
+ ' value: - input value in json format\n'
+ '\n'
+
'\n')
- out = {'status': 'ok', 'usage' : usage}
- s.wrapMessageAndSend(out, received_message)
+
+ #send help as plain text
+ s.send_response(200)
+ s.send_header('content-type', 'text/plain')
+ s.end_headers()
+ s.wfile.write(usage)
#Send error message with text description
def error(s, info, received_message = None):
@@ -439,19 +500,15 @@ class PcilibServerHandler(BaseHTTPRequestHandler):
message['received_message'] = received_message
s.wfile.write(json.dumps(message))
-def serve_forever(server):
- try:
- server.serve_forever()
- except KeyboardInterrupt:
- pass
-
-def runpool(server, number_of_processes):
- # create child processes to act as workers
- for i in range(number_of_processes-1):
- Process(target=serve_forever, args=(server,)).start()
-
- # main process also acts as a worker
- serve_forever(server)
+class ApiServer(MultiThreadedHTTPServer):
+ def __init__(self, device='/dev/fpga0', model=None, adress=('0.0.0.0', 9000)):
+ #redirect logs to exeption
+ pcipywrap.redirect_logs_to_exeption()
+ #pass Pcipywrap to to server handler
+ self.lib = pcipywrap.Pcipywrap(device, model)
+ def handler(*args):
+ PcilibServerHandler(self.lib, *args)
+ MultiThreadedHTTPServer.__init__(self, adress, handler)
if __name__ == '__main__':
@@ -466,51 +523,24 @@ if __name__ == '__main__':
parser.add_option("-m", "--model", action="store",
type="string", dest="model", default=None,
help="Memory model (autodetected)")
- parser.add_option("-n", "--number_processes", action="store",
- type="int", dest="processes", default=4,
- help="Number of processes, used by server (4)")
+
opts = parser.parse_args()[0]
- HOST_NAME = ''
+ HOST_NAME = '0.0.0.0'
PORT_NUMBER = opts.port
MODEL = opts.model
DEVICE = opts.device
-
-
- #Set enviroment variables, if it not setted already
- if not 'APP_PATH' in os.environ:
- APP_PATH = ''
- file_dir = os.path.dirname(os.path.abspath(__file__))
- APP_PATH = str(os.path.abspath(file_dir + '/../..'))
- os.environ["APP_PATH"] = APP_PATH
-
- if not 'PCILIB_MODEL_DIR' in os.environ:
- os.environ['PCILIB_MODEL_DIR'] = os.environ["APP_PATH"] + "/xml"
-
- if not 'LD_LIBRARY_PATH' in os.environ:
- os.environ['LD_LIBRARY_PATH'] = os.environ["APP_PATH"] + "/pcilib"
-
-
-
- #redirect logs to exeption
- pcipywrap.__redirect_logs_to_exeption()
-
- #pass Pcipywrap to to server handler
- global pcilib
- lib = pcipywrap.Pcipywrap(DEVICE, MODEL)
- def handler(*args):
- PcilibServerHandler(lib, *args)
-
#start server
- httpd = HTTPServer((HOST_NAME, PORT_NUMBER), handler)
- runpool(httpd, opts.processes)
+ httpd = ApiServer(DEVICE, MODEL, (HOST_NAME, PORT_NUMBER))
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
- #try:
- # httpd.serve_forever()
- #except KeyboardInterrupt:
- # pass
+
+ try:
+ httpd.serve_forever()
+ except KeyboardInterrupt:
+ pass
httpd.server_close()
+
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
diff --git a/pywrap/pcipywrap.c b/pywrap/pcipywrap.c
index cfb4e53..9113d40 100644
--- a/pywrap/pcipywrap.c
+++ b/pywrap/pcipywrap.c
@@ -97,7 +97,7 @@ void set_python_exception(const char* msg, ...)
}
-void __redirect_logs_to_exeption()
+void redirect_logs_to_exeption()
{
pcilib_set_logger(pcilib_get_log_level(),
pcilib_print_error_to_py,
diff --git a/pywrap/pcipywrap.h b/pywrap/pcipywrap.h
index 2d9115b..cfb5651 100644
--- a/pywrap/pcipywrap.h
+++ b/pywrap/pcipywrap.h
@@ -28,7 +28,7 @@ typedef struct {
* After that, logger will write last error, and all accumulated errors
* to Python exeption text
*/
-void __redirect_logs_to_exeption();
+void redirect_logs_to_exeption();
/*!
* \brief Wraps for pcilib_open function.
diff --git a/pywrap/pcipywrap.i b/pywrap/pcipywrap.i
index 104e19f..697820d 100644
--- a/pywrap/pcipywrap.i
+++ b/pywrap/pcipywrap.i
@@ -4,7 +4,7 @@
#include "pcipywrap.h"
%}
-extern void __redirect_logs_to_exeption();
+extern void redirect_logs_to_exeption();
typedef struct {
%extend {
diff --git a/xml/scripts/test_script.py b/xml/scripts/test_script.py
index 16e4adb..5363a94 100644
--- a/xml/scripts/test_script.py
+++ b/xml/scripts/test_script.py
@@ -1,4 +1,4 @@
description='this is a test script'
def run(ctx, inpt):
- return ctx.get_registers_list();
+ return bytearray('111')
diff --git a/xml/test/test_prop_mt.py b/xml/test/test_prop_mt.py
index 3714597..a5e5fab 100644
--- a/xml/test/test_prop_mt.py
+++ b/xml/test/test_prop_mt.py
@@ -8,7 +8,7 @@ def read_from_register(ctx, value):
cur = read_from_register.counter
read_from_register.counter += 1
- for i in range (0, 60):
+ for i in range (0, 5):
time.sleep(0.1)
print cur
out = ctx.get_property('/test/prop3') / 2