X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bindings%2Fpython%2Fbt2%2Fbt2%2Fquery_executor.py;h=a87713ff1c8a4f2c540fb35fabd81592cd910692;hb=68b66a256a54d32992dfefeaad11eea88b7df234;hp=00644166e20f2f248fc7ba599c3f28ed802547a2;hpb=c7eee084ca459af66ba1f6d375fba3f89db93584;p=babeltrace.git diff --git a/bindings/python/bt2/bt2/query_executor.py b/bindings/python/bt2/bt2/query_executor.py index 00644166..a87713ff 100644 --- a/bindings/python/bt2/bt2/query_executor.py +++ b/bindings/python/bt2/bt2/query_executor.py @@ -25,15 +25,18 @@ import bt2.component import bt2 -class QueryExecutor(object._Object): +class QueryExecutor(object._SharedObject): + _get_ref = staticmethod(native_bt.query_executor_get_ref) + _put_ref = staticmethod(native_bt.query_executor_put_ref) + def _handle_status(self, status, gen_error_msg): - if status == native_bt.QUERY_STATUS_AGAIN: + if status == native_bt.QUERY_EXECUTOR_STATUS_AGAIN: raise bt2.TryAgain - elif status == native_bt.QUERY_STATUS_EXECUTOR_CANCELED: + elif status == native_bt.QUERY_EXECUTOR_STATUS_CANCELED: raise bt2.QueryExecutorCanceled - elif status == native_bt.QUERY_STATUS_INVALID_OBJECT: + elif status == native_bt.QUERY_EXECUTOR_STATUS_INVALID_OBJECT: raise bt2.InvalidQueryObject - elif status == native_bt.QUERY_STATUS_INVALID_PARAMS: + elif status == native_bt.QUERY_EXECUTOR_STATUS_INVALID_PARAMS: raise bt2.InvalidQueryParams elif status < 0: raise bt2.Error(gen_error_msg) @@ -57,6 +60,9 @@ class QueryExecutor(object._Object): return is_canceled > 0 def query(self, component_class, object, params=None): + if self.is_canceled: + raise bt2.QueryExecutorCanceled + if not isinstance(component_class, bt2.component._GenericComponentClass): err = False @@ -78,19 +84,10 @@ class QueryExecutor(object._Object): params = bt2.create_value(params) params_ptr = params._ptr - if isinstance(component_class, bt2.component._GenericComponentClass): - cc_ptr = component_class._ptr - else: - cc_ptr = component_class._cc_ptr + cc_ptr = component_class._component_class_ptr() status, result_ptr = native_bt.query_executor_query(self._ptr, cc_ptr, object, params_ptr) self._handle_status(status, 'cannot query component class') assert(result_ptr) - return bt2.values._create_from_ptr(result_ptr) - - def __eq__(self, other): - if type(other) is not type(self): - return False - - return self.addr == other.addr + return bt2.value._create_from_ptr(result_ptr)