10 Messages::Messages(int input_flag, int output_flag, int id)
14 msgid = msgget(IPC_PRIVATE, IPC_CREAT | 0777);
23 this->input_flag = input_flag;
24 this->output_flag = output_flag;
25 bc_enter_msg_id(msgid);
32 msgctl(msgid, IPC_RMID, NULL);
33 bc_remove_msg_id(msgid);
37 char* Messages::get_message_buffer()
42 int Messages::read_message(char *text)
44 buffer.mtype = input_flag;
46 if((msgrcv(msgid, (struct msgbuf*)&buffer, MESSAGESIZE, input_flag, 0)) < 0)
48 printf(_("recieve message failed\n"));
49 sleep(1); // don't flood the screen during the loop
53 //printf("%d %d\n", buffer.text[0], buffer.mtype);
54 strcpy(text, buffer.text);
58 long Messages::read_message()
60 buffer.mtype = input_flag;
62 if((msgrcv(msgid, (struct msgbuf*)&buffer, MESSAGESIZE, input_flag, 0)) < 0)
64 printf(_("recieve message failed\n"));
68 return atol(buffer.text);
71 float Messages::read_message_f()
74 char *data = read_message_raw();
75 sscanf(data, "%f", &value);
79 char* Messages::read_message_raw()
81 buffer.mtype = input_flag;
83 if((msgrcv(msgid, (struct msgbuf*)&buffer, MESSAGESIZE, input_flag, 0)) < 0)
85 printf(_("recieve message failed\n"));
87 return "RECIEVE MESSAGE FAILED";
93 int Messages::read_message(long *value1, long *value2)
95 char *data = read_message_raw();
96 sscanf(data, "%ld %ld", value1, value2);
100 int Messages::read_message_f(float *value1, float *value2)
102 char *data = read_message_raw();
103 sscanf(data, "%f %f", value1, value2);
107 int Messages::read_message(long *command, long *value1, long *value2)
109 char *data = read_message_raw();
110 sscanf(data, "%ld %ld %ld", command, value1, value2);
114 int Messages::read_message(long *command, long *value1, long *value2, long *value3)
116 char *data = read_message_raw();
117 sscanf(data, "%ld %ld %ld %ld", command, value1, value2, value3);
121 int Messages::read_message_f(float *value1, float *value2, float *value3)
123 char *data = read_message_raw();
124 sscanf(data, "%f %f %f", value1, value2, value3);
128 int Messages::read_message_f(float *value1, float *value2, float *value3, float *value4)
130 char *data = read_message_raw();
131 sscanf(data, "%f %f %f %f", value1, value2, value3, value4);
135 int Messages::read_message(int *command, char *text)
139 char *data = read_message_raw();
140 sscanf(data, "%d", command);
141 // find the start of the text
142 for(i = 0; i < MESSAGESIZE && data[i] != ' '; i++) { ; }
145 // copy the text part
146 for(j = 0; (text[j] = data[i]) != 0; i++, j++) { ; }
151 int Messages::write_message(char *text)
153 buffer.mtype = output_flag;
154 strcpy(buffer.text, text);
156 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(text) + 1, 0)) < 0) printf(_("send message failed\n"));
160 int Messages::write_message_raw()
162 buffer.mtype = output_flag;
164 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(buffer.text) + 1, 0)) < 0) printf(_("send message failed\n"));
168 int Messages::write_message_flagged(int output_flag, int command)
170 buffer.mtype = output_flag;
171 sprintf(buffer.text, "%d", command);
173 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(buffer.text) + 1, 0)) < 0) printf(_("send message failed\n"));
177 int Messages::write_message(int number)
179 sprintf(buffer.text, "%d", number);
180 buffer.mtype = output_flag;
181 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(buffer.text) + 1, 0)) < 0) perror(_("Messages::write_message"));
185 int Messages::write_message_f(float number)
187 sprintf(buffer.text, "%f", number);
188 buffer.mtype = output_flag;
189 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(buffer.text) + 1, 0)) < 0) perror(_("Messages::write_message"));
193 int Messages::write_message(int command, char *text)
195 sprintf(buffer.text, "%d %s", command, text);
196 return write_message_raw();
199 int Messages::write_message(long command, long value)
201 sprintf(buffer.text, "%ld %ld", command, value);
202 return write_message_raw();
205 int Messages::write_message_f(float value1, float value2)
207 sprintf(buffer.text, "%f %f", value1, value2);
208 return write_message_raw();
211 int Messages::write_message(long command, long value1, long value2)
213 sprintf(buffer.text, "%ld %ld %ld", command, value1, value2);
214 return write_message_raw();
217 int Messages::write_message(long command, long value1, long value2, long value3)
219 sprintf(buffer.text, "%ld %ld %ld %ld", command, value1, value2, value3);
220 return write_message_raw();
223 int Messages::write_message_f(float value1, float value2, float value3, float value4)
225 sprintf(buffer.text, "%f %f %f %f", value1, value2, value3, value4);
226 return write_message_raw();
229 int Messages::write_message_f(float value1, float value2, float value3)
231 sprintf(buffer.text, "%f %f %f", value1, value2, value3);
232 return write_message_raw();
235 int Messages::get_id()