summaryrefslogtreecommitdiff
path: root/src/lib/dev.c
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-24 16:26:40 +0100
committerDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-24 16:26:40 +0100
commitc32ccc39cfc793729890204c8d810eb7608f4474 (patch)
treee01b29ae0ff52d617c656b5d85babd472aaa4149 /src/lib/dev.c
parent683114204c81a4e989042ee5de12c4fc71fc910c (diff)
parent72abee4fc44e5e5092e215d5afee556e6e59347c (diff)
downloadouroboros-c32ccc39cfc793729890204c8d810eb7608f4474.tar.gz
ouroboros-c32ccc39cfc793729890204c8d810eb7608f4474.zip
Merged in sandervrijders/ouroboros/be-irm-msg (pull request #40)
lib: Adds IRMd messages for the dev.h API calls
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r--src/lib/dev.c198
1 files changed, 169 insertions, 29 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c
index c072c5ef..7c0c8a15 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -24,65 +24,205 @@
#include <ouroboros/logs.h>
#include <ouroboros/dev.h>
+#include <ouroboros/sockets.h>
-int ap_reg(char * ap_name, char * ae_name,
- char ** difs, size_t difs_size)
-{
- LOG_MISSING;
+#include <stdlib.h>
- return -1;
+int ap_reg(char * ap_name,
+ char ** difs,
+ size_t difs_size)
+{
+ struct irm_msg msg;
+ struct irm_msg * recv_msg = NULL;
+ int fd = 0;
+
+ if (ap_name == NULL ||
+ difs == NULL ||
+ difs_size == 0) {
+ LOG_ERR("Invalid arguments");
+ return -1;
+ }
+
+ msg.code = IRM_AP_REG;
+ msg.ap_name = ap_name;
+ msg.difs = difs;
+ msg.difs_size = difs_size;
+
+ recv_msg = send_recv_irmd_msg(&msg);
+ if (recv_msg == NULL) {
+ LOG_ERR("Failed to send and receive message");
+ return -1;
+ }
+
+ fd = recv_msg->fd;
+ free(recv_msg);
+
+ return fd;
}
-int ap_unreg(char * ap_name, char * ae_name,
- char ** difs, size_t difs_size)
+int ap_unreg(char * ap_name,
+ char ** difs,
+ size_t difs_size)
{
- LOG_MISSING;
-
- return -1;
+ struct irm_msg msg;
+
+ if (ap_name == NULL ||
+ difs == NULL ||
+ difs_size == 0) {
+ LOG_ERR("Invalid arguments");
+ return -1;
+ }
+
+ msg.code = IRM_AP_UNREG;
+ msg.ap_name = ap_name;
+ msg.difs = difs;
+ msg.difs_size = difs_size;
+
+ if (send_irmd_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
+
+ return 0;
}
-int flow_accept(int fd, char * ap_name, char * ae_name)
+int flow_accept(int fd,
+ char * ap_name,
+ char * ae_name)
{
- LOG_MISSING;
-
- return -1;
+ struct irm_msg msg;
+ struct irm_msg * recv_msg = NULL;
+ int cli_fd = 0;
+
+ if (ap_name == NULL) {
+ LOG_ERR("Invalid arguments");
+ return -1;
+ }
+
+ msg.code = IRM_FLOW_ACCEPT;
+ msg.fd = fd;
+
+ recv_msg = send_recv_irmd_msg(&msg);
+ if (recv_msg == NULL) {
+ LOG_ERR("Failed to send and receive message");
+ return -1;
+ }
+
+ cli_fd = recv_msg->fd;
+ ap_name = recv_msg->ap_name;
+ if (ae_name == NULL)
+ ae_name = "";
+ else
+ ae_name = recv_msg->ae_name;
+ free(recv_msg);
+
+ return cli_fd;
}
-int flow_alloc_resp(int fd, int result)
+int flow_alloc_resp(int fd,
+ int result)
{
- LOG_MISSING;
+ struct irm_msg msg;
- return -1;
+ msg.code = IRM_FLOW_ALLOC_RESP;
+ msg.fd = fd;
+ msg.result = result;
+
+ if (send_irmd_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
+
+ return 0;
}
-int flow_alloc(char * dst_ap_name, char * dst_ae_name,
- char * src_ap_name, char * src_ae_name,
- struct qos_spec * qos, int oflags)
+int flow_alloc(char * dst_ap_name,
+ char * src_ap_name,
+ char * src_ae_name,
+ struct qos_spec * qos,
+ int oflags)
{
- LOG_MISSING;
-
- return -1;
+ struct irm_msg msg;
+ struct irm_msg * recv_msg = NULL;
+ int fd = 0;
+
+ if (dst_ap_name == NULL ||
+ src_ap_name == NULL) {
+ LOG_ERR("Invalid arguments");
+ return -1;
+ }
+
+ msg.code = IRM_FLOW_ALLOC;
+ msg.dst_ap_name = dst_ap_name;
+ msg.ap_name = src_ap_name;
+ if (src_ae_name == NULL)
+ msg.ae_name = "";
+ else
+ msg.ae_name = src_ae_name;
+ msg.qos = qos;
+ msg.oflags = oflags;
+
+ recv_msg = send_recv_irmd_msg(&msg);
+ if (recv_msg == NULL) {
+ LOG_ERR("Failed to send and receive message");
+ return -1;
+ }
+
+ fd = recv_msg->fd;
+ free(recv_msg);
+
+ return fd;
}
int flow_alloc_res(int fd)
{
- LOG_MISSING;
+ struct irm_msg msg;
+ struct irm_msg * recv_msg = NULL;
+ int result = 0;
- return -1;
+ msg.code = IRM_FLOW_ALLOC_RES;
+ msg.fd = fd;
+
+ recv_msg = send_recv_irmd_msg(&msg);
+ if (recv_msg == NULL) {
+ LOG_ERR("Failed to send and receive message");
+ return -1;
+ }
+
+ result = recv_msg->result;
+ free(recv_msg);
+
+ return result;
}
int flow_dealloc(int fd)
{
- LOG_MISSING;
+ struct irm_msg msg;
- return -1;
+ msg.code = IRM_FLOW_DEALLOC;
+ msg.fd = fd;
+
+ if (send_irmd_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
+
+ return 0;
}
int flow_cntl(int fd, int oflags)
{
- LOG_MISSING;
+ struct irm_msg msg;
- return -1;
+ msg.fd = fd;
+ msg.oflags = oflags;
+
+ if (send_irmd_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
+
+ return 0;
}
ssize_t flow_write(int fd,