-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.h
79 lines (68 loc) · 2.24 KB
/
messages.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Created by Nils Morczinietz on 29.04.2024.
//
#ifndef BHAGA_MESSAGES_H
#define BHAGA_MESSAGES_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include "subscriptions.h"
#define MSG_PUT_TYPE 11
#define MSG_SIZE 128
// Struktur für die Nachricht
struct msg_buffer {
long msg_type;
char msg_text[MSG_SIZE];
};
/**
* Creates a new message queue or returns the ID of an existing one.
*
* @param msg_q_id The ID of the message queue.
* @return The ID of the message queue created or accessed.
*/
int messageQueueCreate();
/**
* Sends a PUT message to a specified message queue.
*
* @param msg_q_id The ID of the message queue to send the message to.
* @param key The key part of the message.
* @param value The value part of the message.
* @return Returns 0 on success, or -1 on failure.
*/
int messageSendPUT(int msg_q_id, char*key, char*value);
/**
* Sends a PUT message to all specified message queues except the one with the own_msg_q_id.
*
* @param own_msg_q_id The ID of the message queue to exclude from sending.
* @param msg_q_ids Array of message queue IDs to send the message to.
* @param key The key part of the message.
* @param value The value part of the message.
* @return Returns 0 on success, or -1 on failure.
*/
int messageSendToAllPUT(int own_msg_q_id, int * msg_q_ids, char*key, char*value);
/**
* Prints information about the specified message queue.
*
* @param msg_q_id The ID of the message queue.
*/
void messageQueueInfo(int msg_q_id);
/**
* Receives the content of a message from the specified message queue and returns it.
*
* @param msg_q_id The ID of the message queue.
* @param sub_list A pointer to the SubscriptionArray to check subscription.
* @return The content of the received message, or an empty string if no message is received or the key is not subscribed.
*/
char* receiveMessageContent(int msg_q_id, SubscriptionArray * sub_list);
/**
* Splits a message into key and value parts.
*
* @param message The message to split.
* @param key A pointer to store the key part.
* @param value A pointer to store the value part.
*/
void splitMessage(const char *message, char **key, char **value);
#endif //BHAGA_MESSAGES_H