[REFACTOR] separate buffer code
authorNikita Kalyazin <n.kalyazin@samsung.com>
Sun, 30 Jun 2013 12:42:01 +0000 (16:42 +0400)
committerNikita Kalyazin <n.kalyazin@samsung.com>
Sun, 30 Jun 2013 12:42:01 +0000 (16:42 +0400)
daemon/Makefile
daemon/buffer.c [new file with mode: 0644]
daemon/buffer.h [new file with mode: 0644]
daemon/da_protocol.c

index 02c9997..85dba3b 100644 (file)
@@ -29,7 +29,8 @@ DAEMON_SRCS :=        \
        da_data.c       \
        utils.c         \
        sys_stat.c      \
-       elf.c
+       elf.c           \
+       buffer.c
 
 DAEMON_SRCS_HOST :=    \
        main.c          \
diff --git a/daemon/buffer.c b/daemon/buffer.c
new file mode 100644 (file)
index 0000000..c945ec6
--- /dev/null
@@ -0,0 +1,36 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include "daemon.h"
+#include "buffer.h"
+
+static int buf_fd = 0;
+
+int open_buf(void)
+{
+       buf_fd = creat(BUF_FILENAME, 0644);
+       if (buf_fd == -1) {
+               LOGE("Cannot open buffer: %s\n", strerror(errno));
+               return 1;
+       }
+       LOGI("buffer opened: %s, %d\n", BUF_FILENAME, buf_fd);
+
+       return 0;
+}
+
+void close_buf(void)
+{
+       close(buf_fd);
+}
+
+int write_to_buf(struct msg_data_t *msg)
+{
+       if (write(buf_fd, msg, MSG_DATA_HDR_LEN + msg->len) == -1) {
+               LOGE("write to buf: %s\n", strerror(errno));
+               return 1;
+       }
+       return 0;
+}
diff --git a/daemon/buffer.h b/daemon/buffer.h
new file mode 100644 (file)
index 0000000..ffb157f
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _BUFFER_
+#define _BUFFER_
+
+#include "da_protocol.h"
+
+#define BUF_FILENAME "/tmp/daemon_events"
+
+int open_buf(void);
+void close_buf(void);
+int write_to_buf(struct msg_data_t *msg);
+
+#endif /* _BUFFER_ */
index c0a2ea1..076e150 100644 (file)
@@ -1,5 +1,3 @@
-
-
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #define SYSTEM_INFO_DEBUG
 #define parse_deb_on
 
-
-#define BUF_FILENAME "/tmp/daemon_events"
-int buf_fd = 0;
-
-int open_buf(void)
-{
-       buf_fd = creat(BUF_FILENAME, 0644);
-       if (buf_fd == -1) {
-               LOGE("Cannot open buffer: %s\n", strerror(errno));
-               return 1;
-       }
-       LOGI("buffer opened: %s, %d\n", BUF_FILENAME, buf_fd);
-
-       return 0;
-}
-
-void close_buf(void)
-{
-       close(buf_fd);
-}
-
-int write_to_buf(struct msg_data_t *msg)
-{
-       if (write(buf_fd, msg, MSG_DATA_HDR_LEN + msg->len) == -1) {
-               LOGE("write to buf: %s\n", strerror(errno));
-               return 1;
-       }
-       return 0;
-}
-
 void inline free_msg_data(struct msg_data_t *msg)
 {
        free(msg);