mirror of https://github.com/grpc/grpc.git
Merge pull request #13891 from nathanielmanistaatgoogle/12531
Reform cygrpc.OperationTag and cygrpc.Event.pull/13895/head
commit
e1d592a999
18 changed files with 366 additions and 229 deletions
@ -0,0 +1,45 @@ |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
|
||||
cdef class ConnectivityEvent: |
||||
|
||||
cdef readonly grpc_completion_type completion_type |
||||
cdef readonly bint success |
||||
cdef readonly object tag |
||||
|
||||
|
||||
cdef class RequestCallEvent: |
||||
|
||||
cdef readonly grpc_completion_type completion_type |
||||
cdef readonly bint success |
||||
cdef readonly object tag |
||||
cdef readonly Call call |
||||
cdef readonly CallDetails call_details |
||||
cdef readonly tuple invocation_metadata |
||||
|
||||
|
||||
cdef class BatchOperationEvent: |
||||
|
||||
cdef readonly grpc_completion_type completion_type |
||||
cdef readonly bint success |
||||
cdef readonly object tag |
||||
cdef readonly object batch_operations |
||||
|
||||
|
||||
cdef class ServerShutdownEvent: |
||||
|
||||
cdef readonly grpc_completion_type completion_type |
||||
cdef readonly bint success |
||||
cdef readonly object tag |
@ -0,0 +1,55 @@ |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
|
||||
cdef class ConnectivityEvent: |
||||
|
||||
def __cinit__( |
||||
self, grpc_completion_type completion_type, bint success, object tag): |
||||
self.completion_type = completion_type |
||||
self.success = success |
||||
self.tag = tag |
||||
|
||||
|
||||
cdef class RequestCallEvent: |
||||
|
||||
def __cinit__( |
||||
self, grpc_completion_type completion_type, bint success, object tag, |
||||
Call call, CallDetails call_details, tuple invocation_metadata): |
||||
self.completion_type = completion_type |
||||
self.success = success |
||||
self.tag = tag |
||||
self.call = call |
||||
self.call_details = call_details |
||||
self.invocation_metadata = invocation_metadata |
||||
|
||||
|
||||
cdef class BatchOperationEvent: |
||||
|
||||
def __cinit__( |
||||
self, grpc_completion_type completion_type, bint success, object tag, |
||||
object batch_operations): |
||||
self.completion_type = completion_type |
||||
self.success = success |
||||
self.tag = tag |
||||
self.batch_operations = batch_operations |
||||
|
||||
|
||||
cdef class ServerShutdownEvent: |
||||
|
||||
def __cinit__( |
||||
self, grpc_completion_type completion_type, bint success, object tag): |
||||
self.completion_type = completion_type |
||||
self.success = success |
||||
self.tag = tag |
@ -0,0 +1,58 @@ |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
|
||||
cdef class _Tag: |
||||
|
||||
cdef object event(self, grpc_event c_event) |
||||
|
||||
|
||||
cdef class _ConnectivityTag(_Tag): |
||||
|
||||
cdef readonly object _user_tag |
||||
|
||||
cdef ConnectivityEvent event(self, grpc_event c_event) |
||||
|
||||
|
||||
cdef class _RequestCallTag(_Tag): |
||||
|
||||
cdef readonly object _user_tag |
||||
cdef Call call |
||||
cdef CallDetails call_details |
||||
cdef grpc_metadata_array c_invocation_metadata |
||||
|
||||
cdef void prepare(self) |
||||
cdef RequestCallEvent event(self, grpc_event c_event) |
||||
|
||||
|
||||
cdef class _BatchOperationTag(_Tag): |
||||
|
||||
cdef object _user_tag |
||||
cdef readonly object _operations |
||||
cdef readonly object _retained_call |
||||
cdef grpc_op *c_ops |
||||
cdef size_t c_nops |
||||
|
||||
cdef void prepare(self) |
||||
cdef BatchOperationEvent event(self, grpc_event c_event) |
||||
|
||||
|
||||
cdef class _ServerShutdownTag(_Tag): |
||||
|
||||
cdef readonly object _user_tag |
||||
# This allows CompletionQueue to notify the Python Server object that the |
||||
# underlying GRPC core server has shutdown |
||||
cdef readonly Server _shutting_down_server |
||||
|
||||
cdef ServerShutdownEvent event(self, grpc_event c_event) |
@ -0,0 +1,87 @@ |
||||
# Copyright 2017 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
|
||||
cdef class _Tag: |
||||
|
||||
cdef object event(self, grpc_event c_event): |
||||
raise NotImplementedError() |
||||
|
||||
|
||||
cdef class _ConnectivityTag(_Tag): |
||||
|
||||
def __cinit__(self, user_tag): |
||||
self._user_tag = user_tag |
||||
|
||||
cdef ConnectivityEvent event(self, grpc_event c_event): |
||||
return ConnectivityEvent(c_event.type, c_event.success, self._user_tag) |
||||
|
||||
|
||||
cdef class _RequestCallTag(_Tag): |
||||
|
||||
def __cinit__(self, user_tag): |
||||
self._user_tag = user_tag |
||||
self.call = None |
||||
self.call_details = None |
||||
|
||||
cdef void prepare(self): |
||||
self.call = Call() |
||||
self.call_details = CallDetails() |
||||
grpc_metadata_array_init(&self.c_invocation_metadata) |
||||
|
||||
cdef RequestCallEvent event(self, grpc_event c_event): |
||||
cdef tuple invocation_metadata = _metadata(&self.c_invocation_metadata) |
||||
grpc_metadata_array_destroy(&self.c_invocation_metadata) |
||||
return RequestCallEvent( |
||||
c_event.type, c_event.success, self._user_tag, self.call, |
||||
self.call_details, invocation_metadata) |
||||
|
||||
|
||||
cdef class _BatchOperationTag: |
||||
|
||||
def __cinit__(self, user_tag, operations, call): |
||||
self._user_tag = user_tag |
||||
self._operations = operations |
||||
self._retained_call = call |
||||
|
||||
cdef void prepare(self): |
||||
self.c_nops = 0 if self._operations is None else len(self._operations) |
||||
if 0 < self.c_nops: |
||||
self.c_ops = <grpc_op *>gpr_malloc(sizeof(grpc_op) * self.c_nops) |
||||
for index, operation in enumerate(self._operations): |
||||
(<Operation>operation).c() |
||||
self.c_ops[index] = (<Operation>operation).c_op |
||||
|
||||
cdef BatchOperationEvent event(self, grpc_event c_event): |
||||
if 0 < self.c_nops: |
||||
for index, operation in enumerate(self._operations): |
||||
(<Operation>operation).c_op = self.c_ops[index] |
||||
(<Operation>operation).un_c() |
||||
gpr_free(self.c_ops) |
||||
return BatchOperationEvent( |
||||
c_event.type, c_event.success, self._user_tag, self._operations) |
||||
else: |
||||
return BatchOperationEvent( |
||||
c_event.type, c_event.success, self._user_tag, ()) |
||||
|
||||
|
||||
cdef class _ServerShutdownTag(_Tag): |
||||
|
||||
def __cinit__(self, user_tag, shutting_down_server): |
||||
self._user_tag = user_tag |
||||
self._shutting_down_server = shutting_down_server |
||||
|
||||
cdef ServerShutdownEvent event(self, grpc_event c_event): |
||||
self._shutting_down_server.notify_shutdown_complete() |
||||
return ServerShutdownEvent(c_event.type, c_event.success, self._user_tag) |
Loading…
Reference in new issue