Skip to content

Commit

Permalink
Move batch API exposure to Python layer
Browse files Browse the repository at this point in the history
Exposes the C core batch API to the Python layers. Provides a shim to
enable the old Python API to remain the same (for now).
  • Loading branch information
soltanmm committed May 18, 2015
1 parent 0fff02c commit da818cc
Show file tree
Hide file tree
Showing 36 changed files with 3,093 additions and 2,957 deletions.
86 changes: 0 additions & 86 deletions src/python/src/grpc/_adapter/_c.c

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,31 @@
*
*/

#ifndef _ADAPTER__SERVER_H_
#define _ADAPTER__SERVER_H_
#include <stdlib.h>

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <grpc/grpc.h>

#include "grpc/_adapter/_completion_queue.h"
#include "grpc/_adapter/_c/types.h"

typedef struct {
PyObject_HEAD
static PyMethodDef c_methods[] = {
{NULL}
};

CompletionQueue *completion_queue;
grpc_server *c_server;
} Server;
PyMODINIT_FUNC init_c(void) {
PyObject *module;

int pygrpc_add_server(PyObject *module);
module = Py_InitModule3("_c", c_methods,
"Wrappings of C structures and functions.");

#endif /* _ADAPTER__SERVER_H_ */
if (pygrpc_module_add_types(module) < 0) {
return;
}

/* GRPC maintains an internal counter of how many times it has been
initialized and handles multiple pairs of grpc_init()/grpc_shutdown()
invocations accordingly. */
grpc_init();
atexit(&grpc_shutdown);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,30 @@
*
*/

#ifndef _ADAPTER__COMPLETION_QUEUE_H_
#define _ADAPTER__COMPLETION_QUEUE_H_
#include "grpc/_adapter/_c/types.h"

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <grpc/grpc.h>

typedef struct {
PyObject_HEAD
grpc_completion_queue *c_completion_queue;
} CompletionQueue;

extern PyTypeObject pygrpc_CompletionQueueType;

int pygrpc_add_completion_queue(PyObject *module);

#endif /* _ADAPTER__COMPLETION_QUEUE_H_ */
int pygrpc_module_add_types(PyObject *module) {
int i;
PyTypeObject *types[] = {
&pygrpc_ClientCredentials_type,
&pygrpc_ServerCredentials_type,
&pygrpc_CompletionQueue_type,
&pygrpc_Call_type,
&pygrpc_Channel_type,
&pygrpc_Server_type
};
for (i = 0; i < sizeof(types)/sizeof(PyTypeObject *); ++i) {
if (PyType_Ready(types[i]) < 0) {
return -1;
}
}
for (i = 0; i < sizeof(types)/sizeof(PyTypeObject *); ++i) {
Py_INCREF(types[i]);
PyModule_AddObject(module, types[i]->tp_name, (PyObject *)types[i]);
}
return 0;
}
Loading

0 comments on commit da818cc

Please sign in to comment.