r1014: Enable horizontal scrolling with the mouse wheel by pressing Ctrl.
[cinelerra_cv/ct.git] / cinelerra / messages.C
blobde369c59cb437070ed2e6bdf1d5f02d9a78ecda5
1 #include <string.h>
2 #include "bcipc.h"
3 #include "language.h"
4 #include "messages.h"
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
10 Messages::Messages(int input_flag, int output_flag, int id)
12         if(id == -1)
13         {
14                 msgid = msgget(IPC_PRIVATE, IPC_CREAT | 0777);
15                 client = 0;
16         }
17         else
18         {
19                 this->msgid = id;
20                 client = 1;
21         }
22         
23         this->input_flag = input_flag;
24         this->output_flag = output_flag;
25         bc_enter_msg_id(msgid);
28 Messages::~Messages()
30         if(!client)
31         {
32                 msgctl(msgid, IPC_RMID, NULL);
33                 bc_remove_msg_id(msgid);
34         }
37 char* Messages::get_message_buffer()
39         return buffer.text;
42 int Messages::read_message(char *text)
44         buffer.mtype = input_flag;
46         if((msgrcv(msgid, (struct msgbuf*)&buffer, MESSAGESIZE, input_flag, 0)) < 0)
47         {
48                 printf(_("recieve message failed\n"));
49                 sleep(1);     // don't flood the screen during the loop
50                 return -1;
51         }
53 //printf("%d %d\n", buffer.text[0], buffer.mtype);
54         strcpy(text, buffer.text);
55         return 0;
58 long Messages::read_message()
60         buffer.mtype = input_flag;
61         
62         if((msgrcv(msgid, (struct msgbuf*)&buffer, MESSAGESIZE, input_flag, 0)) < 0)
63         {
64                 printf(_("recieve message failed\n"));
65                 sleep(1);
66                 return -1;
67         }
68         return atol(buffer.text);
71 float Messages::read_message_f()
73         float value;
74         char *data = read_message_raw();
75         sscanf(data, "%f", &value);
76         return value;
79 char* Messages::read_message_raw()
81         buffer.mtype = input_flag;
82         
83         if((msgrcv(msgid, (struct msgbuf*)&buffer, MESSAGESIZE, input_flag, 0)) < 0)
84         {
85                 printf(_("recieve message failed\n"));
86                 sleep(1);
87                 return "RECIEVE MESSAGE FAILED";
88         }
89         else
90                 return buffer.text;
93 int Messages::read_message(long *value1, long *value2)
95         char *data = read_message_raw();
96         sscanf(data, "%ld %ld", value1, value2);
97         return 0;
100 int Messages::read_message_f(float *value1, float *value2)
102         char *data = read_message_raw();
103         sscanf(data, "%f %f", value1, value2);
104         return 0;
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);
111         return 0;
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);
118         return 0;
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);
125         return 0;
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);
132         return 0;
135 int Messages::read_message(int *command, char *text)
137         int i, j;
138         
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++) { ; }
143 // get the space
144         i++;
145 // copy the text part
146         for(j = 0; (text[j] = data[i]) != 0; i++, j++) { ; }
147         return 0;
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"));
157         return 0;
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"));
165         return 0;
168 int Messages::write_message_flagged(int output_flag, int command)
170         buffer.mtype = output_flag;
171         sprintf(buffer.text, "%d", command);
172         
173         if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(buffer.text) + 1, 0)) < 0) printf(_("send message failed\n"));
174         return 0;
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"));
182         return 0;
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"));
190         return 0;
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()
237         return msgid;