-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg.h
81 lines (62 loc) · 1.65 KB
/
msg.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
80
81
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <errno.h>
#include <iostream>
using namespace std;
/* The maximum length for a name */
#define MAX_NAME_LEN 100
/* The structure representing the message */
struct message
{
/** IMPORTANT: every message structure must start with this **/
long messageType;
/* A number */
int id;
/* The first name */
char firstName[MAX_NAME_LEN];
/* The last name */
char lastName[MAX_NAME_LEN];
/**
* Prints a record.
* @param fp - the file stream to print to
*/
void print(FILE* fp)
{
fprintf(fp, "messageType=%ld id=%d firstName=%s lastName=%s\n",
messageType, id, firstName, lastName);
}
};
/* The client to server message type */
#define CLIENT_TO_SERVER_MSG 1
/* The message sent from server to client message type */
#define SERVER_TO_CLIENT_MSG 2
/**
* The key to use for the message queue
* @param key - the key to use
* @return - the message queue id
*/
int createMessageQueue(key_t key);
/**
* The key to use for the message queue
* @param key - the key to use
* @return - the message queue id
*/
int connectToMessageQueue(key_t key);
/**
* Sends the message over the message queue
* @param msg - the message queue id
* @param messagePtr - the pointer to the message
*/
void sendMessage(const int& msqid, message& msg);
/**
* Retrieves a message from the message queue
* @param msqid - the message queue id
* @param msg - the structure where
* to store the message received.
* @param messageType - the message type
*/
void recvMessage(const int& msqid, message& msg, const int& messageType);