ustd: convert to new ustcomm api
[ust.git] / ustd / ustd.c
index 8205ed2b2b5e3c77cc6fa9ecae56e2c2ef7ed0ae..d5884dfe040c8bed7667a03e06784e444023c0e1 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2009  Pierre-Marc Fournier
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #define _GNU_SOURCE
 
 #include <sys/types.h>
@@ -18,6 +35,7 @@ struct list_head buffers = LIST_HEAD_INIT(buffers);
 struct buffer_info {
        char *name;
        pid_t pid;
+       struct ustcomm_connection conn;
 
        int shmid;
        void *mem;
@@ -47,9 +65,9 @@ int get_subbuffer(struct buffer_info *buf)
        int result;
 
        asprintf(&send_msg, "get_subbuffer %s", buf->name);
-       result = send_message(buf->pid, send_msg, &received_msg);
+       result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
        if(result < 0) {
-               ERR("get_subbuffer: send_message failed");
+               ERR("get_subbuffer: ustcomm_send_request failed");
                return -1;
        }
        free(send_msg);
@@ -89,7 +107,7 @@ int put_subbuffer(struct buffer_info *buf)
        int result;
 
        asprintf(&send_msg, "put_subbuffer %s %ld", buf->name, buf->consumed_old);
-       result = send_message(buf->pid, send_msg, &received_msg);
+       result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
        if(result < 0) {
                ERR("put_subbuffer: send_message failed");
                return -1;
@@ -190,9 +208,16 @@ int add_buffer(pid_t pid, char *bufname)
        buf->name = bufname;
        buf->pid = pid;
 
+       /* connect to app */
+       result = ustcomm_connect_app(buf->pid, &buf->conn);
+       if(result) {
+               ERR("unable to connect to process");
+               return -1;
+       }
+
        /* get shmid */
        asprintf(&send_msg, "get_shmid %s", buf->name);
-       send_message(pid, send_msg, &received_msg);
+       ustcomm_send_request(&buf->conn, send_msg, &received_msg);
        free(send_msg);
        DBG("got buffer name %s", buf->name);
 
@@ -206,7 +231,7 @@ int add_buffer(pid_t pid, char *bufname)
 
        /* get n_subbufs */
        asprintf(&send_msg, "get_n_subbufs %s", buf->name);
-       send_message(pid, send_msg, &received_msg);
+       ustcomm_send_request(&buf->conn, send_msg, &received_msg);
        free(send_msg);
 
        result = sscanf(received_msg, "%d", &buf->n_subbufs);
@@ -219,7 +244,7 @@ int add_buffer(pid_t pid, char *bufname)
 
        /* get subbuf size */
        asprintf(&send_msg, "get_subbuf_size %s", buf->name);
-       send_message(pid, send_msg, &received_msg);
+       ustcomm_send_request(&buf->conn, send_msg, &received_msg);
        free(send_msg);
 
        result = sscanf(received_msg, "%d", &buf->subbuf_size);
This page took 0.02434 seconds and 4 git commands to generate.