diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makefile | 7 | ||||
| -rw-r--r-- | lib/python/Makefile | 3 | ||||
| -rw-r--r-- | lib/python/alarms.c | 43 | 
3 files changed, 19 insertions, 34 deletions
| diff --git a/lib/Makefile b/lib/Makefile index 43a9d87..4961c4e 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,8 +1,8 @@  CFLAGS += -I../inc/ -all: libalarm.so python +all: python -python: +python: libalarm.so  	make -C python  %.so: %.o @@ -12,6 +12,7 @@ python:  	$(CC) -c -o $@ $< $(LDFLAGS) $(CFLAGS)  clean: -	rm libalarm.{s,}o +	rm -f libalarm.{s,}o +	make -C python clean  .PHONY: python diff --git a/lib/python/Makefile b/lib/python/Makefile index 1e2c24a..d5d3702 100644 --- a/lib/python/Makefile +++ b/lib/python/Makefile @@ -1,6 +1,7 @@  PYTHONINC = /usr/include/python3.7m/ -LDFLAGS += "-luuid" +LDFLAGS += -L../../lib \ +           -luuid -lalarm  CFLAGS += -fPIC \            -I$(PYTHONINC) \            -I../../inc/ diff --git a/lib/python/alarms.c b/lib/python/alarms.c index 57670e8..1ac42af 100644 --- a/lib/python/alarms.c +++ b/lib/python/alarms.c @@ -34,13 +34,6 @@ static struct PyModuleDef alarm_python = {  static PyObject *alarmd_error; -/* Helper function */ -int send_packet_uuid(int sock, uint32_t packet_type, uuid_t uuid) -{ -	return (send(sock, &packet_type, sizeof(packet_type), 0) != sizeof(packet_type) -	        || send(sock, uuid, sizeof(uuid_t), 0) != 16); -} -  PyObject* PyInit_alarms(void) {  	PyObject *module = NULL; @@ -93,31 +86,12 @@ PyObject* pyalarmd_register(PyObject *self, PyObject *args)  	char *desc;  	char uuid_str[37];  	uuid_t uuid; -	uint8_t length = 0; -	uint32_t packet_type = 0;  	if (!PyArg_ParseTuple(args, "is", &sock, &desc)) {  		return NULL;  	} -	packet_type = ALARMD_PACKET_TYPE_REGISTER; -	if (send(sock, &packet_type, sizeof(packet_type), 0) != sizeof(packet_type)) { -		PyErr_SetFromErrno(alarmd_error); -		return NULL; -	} - -	length = strlen(desc); -	if (send(sock, &length, sizeof(length), 0) != sizeof(length)) { -		PyErr_SetFromErrno(alarmd_error); -		return NULL; -	} - -	if (send(sock, desc, strlen(desc), 0) != strlen(desc)) { -		PyErr_SetFromErrno(alarmd_error); -		return NULL; -	} - -	if (recv(sock, &uuid, sizeof(uuid), 0) != sizeof(uuid)) { +	if (alarmd_register(sock, desc, &uuid)) {  		PyErr_SetFromErrno(alarmd_error);  		return NULL;  	} @@ -142,7 +116,10 @@ PyObject* pyalarmd_deregister(PyObject *self, PyObject *args)  		return NULL;  	} -	send_packet_uuid(sock, ALARMD_PACKET_TYPE_DEREGISTER, uuid); +	if (alarmd_deregister(sock, uuid)) { +		PyErr_SetFromErrno(alarmd_error); +		return NULL; +	}  	Py_RETURN_NONE;  } @@ -162,7 +139,10 @@ PyObject* pyalarmd_raise(PyObject *self, PyObject *args)  		return NULL;  	} -	send_packet_uuid(sock, ALARMD_PACKET_TYPE_RAISE, uuid); +	if (alarmd_raise(sock, uuid)) { +		PyErr_SetFromErrno(alarmd_error); +		return NULL; +	}  	Py_RETURN_NONE;  } @@ -182,7 +162,10 @@ PyObject* pyalarmd_clear(PyObject *self, PyObject *args)  		return NULL;  	} -	send_packet_uuid(sock, ALARMD_PACKET_TYPE_CLEAR, uuid); +	if (alarmd_clear(sock, uuid)) { +		PyErr_SetFromErrno(alarmd_error); +		return NULL; +	}  	Py_RETURN_NONE;  } | 
