Преглед изворни кода

Client construct: added flag to ensure the client's name will match the desired one

Fabian Peter Hammerle пре 9 година
родитељ
комит
61ec1a05aa
5 измењених фајлова са 54 додато и 4 уклоњено
  1. 16 0
      docker/Dockerfile
  2. 11 0
      docker/run
  3. 14 3
      jack.c
  4. 2 1
      setup.py
  5. 11 0
      tests/test_client.py

+ 16 - 0
docker/Dockerfile

@@ -0,0 +1,16 @@
+FROM ubuntu:14.04
+
+RUN apt-get update && apt-get install -y \
+    git \
+    python-dev \
+    python-pip
+    
+RUN pip install pytest
+
+RUN git clone https://github.com/jackaudio/jack2
+RUN cd jack2 && ./waf configure && ./waf build && ./waf install
+
+# add search path to find libjackserver.so.0
+RUN echo '/usr/local/lib' >>/etc/ld.so.conf && ldconfig
+
+RUN echo 'jackd -d dummy &' >>$HOME/.bash_history

+ 11 - 0
docker/run

@@ -0,0 +1,11 @@
+#!/bin/bash
+
+set -e
+
+script_dir="$( dirname "$BASH_SOURCE" )"
+project_dir="$( readlink -f "$script_dir/.." )"
+
+docker build -t jacker "$script_dir"
+
+docker run -it -v "$project_dir":/jacker --workdir=/jacker jacker \
+    bash -c "pip install .; bash"

+ 14 - 3
jack.c

@@ -187,9 +187,13 @@ static PyObject* client___new__(PyTypeObject* type, PyObject* args, PyObject* kw
 
     if(self) {
         char* client_name;
+        unsigned char use_exact_name = 0;
         char* server_name = NULL;
-        static char* kwlist[] = {"client_name", "server_name", NULL};
-        if(!PyArg_ParseTupleAndKeywords(args, kwargs, "s|s", kwlist, &client_name, &server_name)) {
+        static char* kwlist[] = {"client_name", "use_exact_name", "server_name", NULL};
+        if(!PyArg_ParseTupleAndKeywords(
+                    args, kwargs, "s|bs", kwlist,
+                    &client_name, &use_exact_name, &server_name
+                    )) {
             return NULL;
         }
 
@@ -197,11 +201,18 @@ static PyObject* client___new__(PyTypeObject* type, PyObject* args, PyObject* kw
         if(server_name) {
             open_options |= JackServerName;
         }
+        if(use_exact_name) {
+            open_options |= JackUseExactName;
+        }
 
         jack_status_t status;
         self->client = jack_client_open(client_name, open_options, &status, server_name);
         if(!self->client) {
-            if(status & JackFailure) {
+            if(status & JackNameNotUnique) {
+                PyErr_SetString(error, "The desired client name was not unique.");
+            } else if(status & JackServerError) {
+                PyErr_SetString(error, "Communication error with the JACK server.");
+            } else if(status & JackFailure) {
                 PyErr_SetString(failure, "Overall operation failed.");
             }
             return NULL;

+ 2 - 1
setup.py

@@ -17,6 +17,7 @@ setup(
             'jack', 
             sources = glob.glob('*.c'),
             libraries = ['jack'],
-            )
+            ),
         ],
+    tests_require = ['pytest'],
     )

+ 11 - 0
tests/test_client.py

@@ -0,0 +1,11 @@
+import pytest
+
+import jack
+
+def test_create():
+    jack.Client('test')
+
+def test_name_conflict():
+    client = jack.Client('test')
+    with pytest.raises(jack.Error):
+        jack.Client(client.get_name(), use_exact_name = True)