aboutsummaryrefslogtreecommitdiff
path: root/aufgabe3
diff options
context:
space:
mode:
authorThorsten Töpper <atsutane@freethoughts.de>2010-12-31 20:30:44 +0100
committerThorsten Töpper <atsutane@freethoughts.de>2010-12-31 20:30:44 +0100
commit78ba3b87b0526c2a783fd19cb720a15ea464b9b5 (patch)
tree2613361bccce9f9936a89269c13959f5db7ff468 /aufgabe3
parent43d16388f5ab5ec87f2373f10ae9a648c3464c3b (diff)
downloadprozesskommunikation-78ba3b87b0526c2a783fd19cb720a15ea464b9b5.tar.gz
prozesskommunikation-78ba3b87b0526c2a783fd19cb720a15ea464b9b5.tar.bz2
Aufgabe 3: conv weitgehend fertiggestellt
* Makefile um Bibliothekslink erweitert * queue.h an simples Modell mit 3 Queues angepasst.
Diffstat (limited to 'aufgabe3')
-rw-r--r--aufgabe3/Makefile2
-rw-r--r--aufgabe3/conv.c40
-rw-r--r--aufgabe3/queue.h7
3 files changed, 44 insertions, 5 deletions
diff --git a/aufgabe3/Makefile b/aufgabe3/Makefile
index d08af51..c8a143b 100644
--- a/aufgabe3/Makefile
+++ b/aufgabe3/Makefile
@@ -4,7 +4,7 @@ all:
gcc -Wall -c -o statistic.o statistic.c
gcc -Wall -c -o monitor.o monitor.c
gcc -Wall -c -o main.o main.c
- gcc -o pk main.o conv.o log.o statistic.o monitor.o
+ gcc -o pk main.o conv.o log.o statistic.o monitor.o -lrt
clean:
rm -f *.o
diff --git a/aufgabe3/conv.c b/aufgabe3/conv.c
index 35b7d33..9ca90f8 100644
--- a/aufgabe3/conv.c
+++ b/aufgabe3/conv.c
@@ -5,20 +5,56 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include <string.h>
#include "queue.h"
void conv() {
int random_number = 0;
+ mqd_t log;
+ mqd_t statistic;
+ size_t message_size = sizeof(int)*2+1;
+ char *msg_one, *msg_two;
- sprintf(stderr, "conv() was started");
+ /*
+ * Message Queues zur Kommunikation mit dem log
+ * und dem statstic Prozess öffnen.
+ */
+ log = mq_open(MQ_TO_LOG, O_WRONLY);
+ statistic = mq_open(MQ_TO_STATISTIC, O_WRONLY);
+ if ((log == -1) || (statistic == -1)) {
+ perror("conv() mq_open");
+ exit(EXIT_FAILURE);
+ }
for (;;) {
- rand();
+ random_number = rand();
+
+ msg_one = calloc(1, message_size);
+ msg_two = calloc(1, message_size);
+
+ /* Message im Hexadezimalformat generieren. */
+ sprintf(msg_one, "%x", random_number);
+ sprintf(msg_two, "%x", random_number);
+
+ printf("conv:\t%s\t\t%s\n", msg_one, msg_two);
+// fgetc(stdin);
+
+ /* Message sowohl in die Queue zum log Prozess als auch
+ * in die Queue zum statistic Prozess schreiben.
+ */
+ if ((mq_send(log, msg_one, strlen(msg_one)+1, 0) == -1) ||
+ mq_send(statistic, msg_two, strlen(msg_two)+1, 0) == -1){
+ perror("conv() mq_send");
+ exit(EXIT_FAILURE);
+ }
+
}
}
void conv_cleanup() {
printf("conv cleanup\n");
+ mq_unlink(MQ_TO_LOG);
+ mq_unlink(MQ_TO_STATISTIC);
_exit(EXIT_SUCCESS);
}
diff --git a/aufgabe3/queue.h b/aufgabe3/queue.h
index 67a6110..01aaa9a 100644
--- a/aufgabe3/queue.h
+++ b/aufgabe3/queue.h
@@ -1,13 +1,16 @@
#ifndef _QUEUE_H
#define _QUEUE_H
+#include <errno.h>
#include <sys/stat.h>
#include <mqueue.h>
/*
- * Definition des Namens der verwendeten Message Queue.
+ * Definition der Namen der verwendeten Message Queues.
* Erspart bei einer Änderung das editieren an mehreren
* Stellen im Sourcecode.
*/
-#define MQ_NAME "/mq_bts_pk"
+#define MQ_TO_LOG "/mq_bts_pk_log"
+#define MQ_TO_STATISTIC "/mq_bts_pk_statistic"
+#define MQ_TO_MONITOR "/mq_bts_pk_monitor"
#endif