aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-08-19 18:36:24 +0200
committerMattias Andrée <maandree@kth.se>2016-08-19 18:36:24 +0200
commitd72dcb6fd886d1a5a869d0ae0ae391889af5cb2d (patch)
tree3f3b4f6135fff7267b7ffb91760b43cc59e1905e
parent_send functions have async parameter rather than creating their instance (diff)
downloadpylibcoopgamma-d72dcb6fd886d1a5a869d0ae0ae391889af5cb2d.tar.gz
pylibcoopgamma-d72dcb6fd886d1a5a869d0ae0ae391889af5cb2d.tar.bz2
pylibcoopgamma-d72dcb6fd886d1a5a869d0ae0ae391889af5cb2d.tar.xz
work on test + fix errors
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--src/libcoopgamma.py17
-rw-r--r--src/libcoopgamma_native.pyx.gpp2
-rwxr-xr-xsrc/test73
3 files changed, 81 insertions, 11 deletions
diff --git a/src/libcoopgamma.py b/src/libcoopgamma.py
index 21843f6..7d561db 100644
--- a/src/libcoopgamma.py
+++ b/src/libcoopgamma.py
@@ -891,7 +891,7 @@ class Context:
corresponding AsyncContext is not listed.
'''
pending = [p.address for p in pending]
- (successful, value) = libcoopgamma_native.libcoopgamma_native_flush(self.address, pending)
+ (successful, value) = libcoopgamma_native.libcoopgamma_native_synchronise(self.address, pending)
if not successful:
if value == 0:
return None
@@ -957,10 +957,9 @@ class Context:
@param async:AsyncContext Slot for information about the request that is
needed to identify and parse the response
'''
- (successful, value) = libcoopgamma_native.libcoopgamma_native_get_gamma_info_send(
- crtc, self.address, async.address)
- if not successful:
- raise ErrorReport.create_error(value)
+ error = libcoopgamma_native.libcoopgamma_native_get_gamma_info_send(crtc, self.address, async.address)
+ if error != 0:
+ raise ErrorReport.create_error(error)
def get_gamma_info_recv(self, async):
'''
@@ -969,7 +968,7 @@ class Context:
@param async:AsyncContext Information about the request
@return :CRTCInfo Information about the CRTC
'''
- value = libcoopgamma_native.libcoopgamma_native_get_gamma_info_send(self.address, async.address)
+ value = libcoopgamma_native.libcoopgamma_native_get_gamma_info_recv(self.address, async.address)
if isinstance(value, int):
raise ErrorReport.create_error(value)
(successful, value) = value
@@ -1017,7 +1016,7 @@ class Context:
@param async:AsyncContext Information about the request
@return :FilterTable Filter table
'''
- value = libcoopgamma_native.libcoopgamma_native_get_gamma_send(self.address, async.address)
+ value = libcoopgamma_native.libcoopgamma_native_get_gamma_recv(self.address, async.address)
if isinstance(value, int):
raise ErrorReport.create_error(value)
(successful, value) = value
@@ -1095,6 +1094,7 @@ class AsyncContext:
@param buf:bytes? Buffer to unmarshal
'''
+ self.address = None
if buf is None:
(successful, value) = libcoopgamma_native.libcoopgamma_native_async_context_create()
if not successful:
@@ -1113,7 +1113,8 @@ class AsyncContext:
'''
Destructor
'''
- libcoopgamma_native.libcoopgamma_native_async_context_free(self.address)
+ if self.address is not None:
+ libcoopgamma_native.libcoopgamma_native_async_context_free(self.address)
def __repr__(self):
'''
diff --git a/src/libcoopgamma_native.pyx.gpp b/src/libcoopgamma_native.pyx.gpp
index 5c6b796..1597e0c 100644
--- a/src/libcoopgamma_native.pyx.gpp
+++ b/src/libcoopgamma_native.pyx.gpp
@@ -1043,7 +1043,7 @@ def libcoopgamma_native_context_set_fd(address : int, fd : int):
this.fd = fd
-def libcoopgamma_native_context_create():
+def libcoopgamma_native_async_context_create():
'''
Create an instance of `libcoopgamma_context_t`
diff --git a/src/test b/src/test
index d12cfa7..8d5d5e9 100755
--- a/src/test
+++ b/src/test
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
'''
-import os, sys, time
+import os, sys, time, errno
os.chdir('/'.join(sys.argv[0].split('/')[:-1]))
sys.path.append('../bin')
@@ -61,7 +61,8 @@ else:
g.attach()
print('\033[1m%s:\033[m' % 'CRTC:s')
-for crtc in g.get_crtcs_sync():
+crtcs = g.get_crtcs_sync()
+for crtc in crtcs:
print(crtc)
print()
@@ -150,5 +151,73 @@ fltr.ramps.blue = [Y(x / (table.blue_size - 1)) for x in range(table.blue_size)]
g.set_gamma_sync(fltr)
time.sleep(0.5)
+g.set_nonbreaking(False)
+
+async = cg.AsyncContext()
+
+def flush(e):
+ if e.errno in (errno.EINTR, errno.EWOULDBLOCK, errno.EAGAIN):
+ while True:
+ try:
+ g.flush()
+ except OSError as ex:
+ if ex.errno in (errno.EINTR, errno.EWOULDBLOCK, errno.EAGAIN):
+ continue
+ else:
+ raise ex
+ break
+ else:
+ raise e
+
+try:
+ g.get_crtcs_send(async)
+except OSError as e:
+ flush(e)
+if g.synchronise([async]) != 0:
+ sys.exit(1)
+if g.get_crtcs_recv(async) != crtcs:
+ sys.exit(2)
+
+try:
+ g.get_gamma_info_send(crtc, async)
+except OSError as e:
+ flush(e)
+if g.synchronise([async]) != 0:
+ sys.exit(3)
+info2 = g.get_gamma_info_recv(async)
+if info2.cooperative != info.cooperative:
+ sys.exit(4)
+if info2.depth != info.depth:
+ sys.exit(4)
+if info2.supported != info.supported:
+ sys.exit(4)
+if info2.red_size != info.red_size:
+ sys.exit(4)
+if info2.green_size != info.green_size:
+ sys.exit(4)
+if info2.blue_size != info.blue_size:
+ sys.exit(4)
+if info2.colourspace != info.colourspace:
+ sys.exit(4)
+if (info2.gamut is None) != (info.gamut is None):
+ sys.exit(4)
+if info.gamut is not None:
+ if info2.gamut.red.x_raw != info.gamut.red.x_raw or info2.gamut.red.x != info.gamut.red.x:
+ sys.exit(4)
+ if info2.gamut.red.y_raw != info.gamut.red.y_raw or info2.gamut.red.y != info.gamut.red.y:
+ sys.exit(4)
+ if info2.gamut.green.x_raw != info.gamut.green.x_raw or info2.gamut.green.x != info.gamut.green.x:
+ sys.exit(4)
+ if info2.gamut.green.y_raw != info.gamut.green.y_raw or info2.gamut.green.y != info.gamut.green.y:
+ sys.exit(4)
+ if info2.gamut.blue.x_raw != info.gamut.blue.x_raw or info2.gamut.blue.x != info.gamut.blue.x:
+ sys.exit(4)
+ if info2.gamut.blue.y_raw != info.gamut.blue.y_raw or info2.gamut.blue.y != info.gamut.blue.y:
+ sys.exit(4)
+ if info2.gamut.white.x_raw != info.gamut.white.x_raw or info2.gamut.white.x != info.gamut.white.x:
+ sys.exit(4)
+ if info2.gamut.white.y_raw != info.gamut.white.y_raw or info2.gamut.white.y != info.gamut.white.y:
+ sys.exit(4)
+
del g