summaryrefslogtreecommitdiff
path: root/legacy/ecore
diff options
context:
space:
mode:
authorDavid Walter Seikel <onefang@gmail.com>2006-01-17 11:33:39 +0000
committerDavid Walter Seikel <onefang@gmail.com>2006-01-17 11:33:39 +0000
commit29b4630756bdc13c5e979db3c56e31044ef180b8 (patch)
tree179703b22cda5be6030a56eb11fdb2b3961ee5ab /legacy/ecore
parent7ba3cbe1e35afbb464e79c45e7e0bf9b1cea0c25 (diff)
Seperate the data event code from the fd handler code in preparation for
fork'n'bitch. SVN revision: 19876
Diffstat (limited to 'legacy/ecore')
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_exe.c245
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_private.h3
2 files changed, 160 insertions, 88 deletions
diff --git a/legacy/ecore/src/lib/ecore/ecore_exe.c b/legacy/ecore/src/lib/ecore/ecore_exe.c
index baf393263a..9372f873eb 100644
--- a/legacy/ecore/src/lib/ecore/ecore_exe.c
+++ b/legacy/ecore/src/lib/ecore/ecore_exe.c
@@ -271,15 +271,21 @@ ecore_exe_pipe_run(const char *exe_cmd, Ecore_Exe_Flags flags, const void *data)
271 exe = calloc(1, sizeof(Ecore_Exe)); 271 exe = calloc(1, sizeof(Ecore_Exe));
272 if (exe == NULL) return NULL; 272 if (exe == NULL) return NULL;
273 273
274 if ( (flags & ECORE_EXE_PIPE_AUTO) && (! (flags & ECORE_EXE_PIPE_ERROR)) && (! (flags & ECORE_EXE_PIPE_READ)) )
275 flags |= ECORE_EXE_PIPE_READ; /* We need something to auto pipe. */
276
274 /* Create some pipes. */ 277 /* Create some pipes. */
275 if (ok) E_IF_NO_ERRNO_NOLOOP(result, pipe(statusPipe), ok) 278 if (ok) E_IF_NO_ERRNO_NOLOOP(result, pipe(statusPipe), ok)
276 ; 279 ;
277 if (ok && (flags & ECORE_EXE_PIPE_ERROR)) E_IF_NO_ERRNO_NOLOOP(result, pipe(errorPipe), ok) 280 if (ok && (flags & ECORE_EXE_PIPE_ERROR))
278 exe->child_fd_error = errorPipe[0]; 281 E_IF_NO_ERRNO_NOLOOP(result, pipe(errorPipe), ok)
279 if (ok && (flags & ECORE_EXE_PIPE_READ)) E_IF_NO_ERRNO_NOLOOP(result, pipe(readPipe), ok) 282 exe->child_fd_error = errorPipe[0];
280 exe->child_fd_read = readPipe[0]; 283 if (ok && (flags & ECORE_EXE_PIPE_READ))
281 if (ok && (flags & ECORE_EXE_PIPE_WRITE)) E_IF_NO_ERRNO_NOLOOP(result, pipe(writePipe), ok) 284 E_IF_NO_ERRNO_NOLOOP(result, pipe(readPipe), ok)
282 exe->child_fd_write = writePipe[1]; 285 exe->child_fd_read = readPipe[0];
286 if (ok && (flags & ECORE_EXE_PIPE_WRITE))
287 E_IF_NO_ERRNO_NOLOOP(result, pipe(writePipe), ok)
288 exe->child_fd_write = writePipe[1];
283 289
284 if (ok) 290 if (ok)
285 { 291 {
@@ -522,16 +528,21 @@ ecore_exe_auto_limits_set(Ecore_Exe *exe, int start_bytes, int end_bytes, int st
522 * more generic designs. It does seem like the closer we get to poll driven, 528 * more generic designs. It does seem like the closer we get to poll driven,
523 * the more issues and corner cases there are. 529 * the more issues and corner cases there are.
524 * 530 *
531 * Instead of doing the usual register an event handler thing, we are ecore_exe,
532 * we can take some short cuts. Don't send the events, just leave the exe buffers
533 * as is until the user asks for them, then return the event.
534 *
525 * start = 0, end = 0; clogged arteries get flushed, everything is ignored. 535 * start = 0, end = 0; clogged arteries get flushed, everything is ignored.
526 * start = -1, end = -1; clogged arteries get transferred to internal buffers. Actually, either == -1 means buffer everything. 536 * start = -1, end = -1; clogged arteries get transferred to internal buffers. Actually, either == -1 means buffer everything.
527 * start = X, end = 0; buffer first X out of clogged arteries, flush and ignore rest. 537 * start = X, end = 0; buffer first X out of clogged arteries, flush and ignore rest.
528 * start = 0, end = X; circular buffer X 538 * start = 0, end = X; circular buffer X
529 * start = X, end = Y; buffer first X out of clogged arteries, circular buffer Y from beginning. 539 * start = X, end = Y; buffer first X out of clogged arteries, circular buffer Y from beginning.
530 * 540 *
531 * bytes vs lines, which ever one reaches the limit first. 541 * bytes vs lines, which ever one reaches the limit first.
532 * 542 *
533 * Other issues - 543 * Other issues -
534 * Spank programmer for polling data if polling is not turned on. 544 * Spank programmer for polling data if polling is not turned on.
545 * Spank programmer for setting up event callbacks if polling is turned on.
535 * Spank programmer for freeing the event data if it came from the event system, as that autofrees. 546 * Spank programmer for freeing the event data if it came from the event system, as that autofrees.
536 * Spank the programmer if they try to set the limits bigger than what has been gathered & ignored already, coz they just lost data. 547 * Spank the programmer if they try to set the limits bigger than what has been gathered & ignored already, coz they just lost data.
537 * Spank onefang and raster for opening this can of worms. 548 * Spank onefang and raster for opening this can of worms.
@@ -1048,6 +1059,124 @@ _ecore_exe_exec_it(const char *exe_cmd)
1048 return; 1059 return;
1049} 1060}
1050 1061
1062static Ecore_Exe_Event_Data *
1063_ecore_exe_create_event_data(Ecore_Exe *exe, Ecore_Fd_Handler_Flags flags)
1064{
1065 Ecore_Exe_Event_Data *e = NULL;
1066 int is_buffered = 0;
1067 unsigned char *inbuf;
1068 int inbuf_num;
1069
1070 /* Sort out what sort of event we are. */
1071 if (flags & ECORE_FD_READ)
1072 {
1073 flags = ECORE_FD_READ;
1074 if (exe->flags & ECORE_EXE_PIPE_READ_LINE_BUFFERED)
1075 is_buffered = 1;
1076 }
1077 else
1078 {
1079 flags = ECORE_FD_ERROR;
1080 if (exe->flags & ECORE_EXE_PIPE_ERROR_LINE_BUFFERED)
1081 is_buffered = 1;
1082 }
1083
1084 /* Get the data. */
1085 if (flags & ECORE_FD_READ)
1086 {
1087 inbuf = exe->read_data_buf;
1088 inbuf_num = exe->read_data_size;
1089 exe->read_data_buf = NULL;
1090 exe->read_data_size = 0;
1091 }
1092 else
1093 {
1094 inbuf = exe->error_data_buf;
1095 inbuf_num = exe->error_data_size;
1096 exe->error_data_buf = NULL;
1097 exe->error_data_size = 0;
1098 }
1099
1100 e = calloc(1, sizeof(Ecore_Exe_Event_Data));
1101 if (e)
1102 {
1103 e->exe = exe;
1104 e->data = inbuf;
1105 e->size = inbuf_num;
1106
1107 if (is_buffered)
1108 { /* Deal with line buffering. */
1109 int max = 0;
1110 int count = 0;
1111 int i;
1112 int last = 0;
1113 char *c;
1114
1115 c = (char *)inbuf;
1116 for (i = 0; i < inbuf_num; i++) /* Find the lines. */
1117 {
1118 if (inbuf[i] == '\n')
1119 {
1120 if (count >= max)
1121 {
1122 /* In testing, the lines seem to arrive in batches of 500 to 1000 lines at most, roughly speaking. */
1123 max += 10; /* FIXME: Maybe keep track of the largest number of lines ever sent, and add half that many instead of 10. */
1124 e->lines = realloc(e->lines, sizeof(Ecore_Exe_Event_Data_Line) * (max + 1)); /* Allow room for the NULL termination. */
1125 }
1126 /* raster said to leave the line endings as line endings, however -
1127 * This is line buffered mode, we are not dealing with binary here, but lines.
1128 * If we are not dealing with binary, we must be dealing with ASCII, unicode, or some other text format.
1129 * Thus the user is most likely gonna deal with this text as strings.
1130 * Thus the user is most likely gonna pass this data to str functions.
1131 * rasters way - the endings are always gonna be '\n'; onefangs way - they will always be '\0'
1132 * We are handing them the string length as a convenience.
1133 * Thus if they really want it in raw format, they can e->lines[i].line[e->lines[i].size - 1] = '\n'; easily enough.
1134 * In the default case, we can do this conversion quicker than the user can, as we already have the index and pointer.
1135 * Let's make it easy on them to use these as standard C strings.
1136 *
1137 * onefang is proud to announce that he has just set a new personal record for the
1138 * most over documentation of a simple assignment statement. B-)
1139 */
1140 inbuf[i] = '\0';
1141 e->lines[count].line = c;
1142 e->lines[count].size = i - last;
1143 last = i + 1;
1144 c = (char *)&inbuf[last];
1145 count++;
1146 }
1147 }
1148 if (count == 0) /* No lines to send, cancel the event. */
1149 {
1150 _ecore_exe_event_exe_data_free(NULL, e);
1151 e = NULL;
1152 }
1153 else /* NULL terminate the array, so that people know where the end is. */
1154 {
1155 e->lines[count].line = NULL;
1156 e->lines[count].size = 0;
1157 }
1158 if (i > last) /* Partial line left over, save it for next time. */
1159 {
1160 e->size = last;
1161 if (flags & ECORE_FD_READ)
1162 {
1163 exe->read_data_size = i - last;
1164 exe->read_data_buf = malloc(exe->read_data_size);
1165 memcpy(exe->read_data_buf, c, exe->read_data_size);
1166 }
1167 else
1168 {
1169 exe->error_data_size = i - last;
1170 exe->error_data_buf = malloc(exe->error_data_size);
1171 memcpy(exe->error_data_buf, c, exe->error_data_size);
1172 }
1173 }
1174 }
1175 }
1176
1177 return e;
1178}
1179
1051static int 1180static int
1052_ecore_exe_data_generic_handler(void *data, Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags) 1181_ecore_exe_data_generic_handler(void *data, Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags)
1053{ 1182{
@@ -1057,6 +1186,8 @@ _ecore_exe_data_generic_handler(void *data, Ecore_Fd_Handler *fd_handler, Ecore_
1057 int event_type; 1186 int event_type;
1058 1187
1059 exe = data; 1188 exe = data;
1189
1190 /* Sort out what sort of handler we are. */
1060 if (flags & ECORE_FD_READ) 1191 if (flags & ECORE_FD_READ)
1061 { 1192 {
1062 flags = ECORE_FD_READ; 1193 flags = ECORE_FD_READ;
@@ -1123,86 +1254,25 @@ _ecore_exe_data_generic_handler(void *data, Ecore_Fd_Handler *fd_handler, Ecore_
1123 if (inbuf) 1254 if (inbuf)
1124 { 1255 {
1125 Ecore_Exe_Event_Data *e; 1256 Ecore_Exe_Event_Data *e;
1126 1257
1127 e = calloc(1, sizeof(Ecore_Exe_Event_Data)); 1258 /* Stash the data away for later. */
1128 if (e) 1259 if (flags & ECORE_FD_READ)
1260 {
1261 exe->read_data_buf = inbuf;
1262 exe->read_data_size = inbuf_num;
1263 }
1264 else
1265 {
1266 exe->error_data_buf = inbuf ;
1267 exe->error_data_size = inbuf_num;
1268 }
1269
1270 if (! (exe->flags & ECORE_EXE_PIPE_AUTO))
1129 { 1271 {
1130 e->exe = exe; 1272 e = _ecore_exe_create_event_data(exe, flags);
1131 e->data = inbuf; 1273 if (e) /* Send the event. */
1132 e->size = inbuf_num;
1133
1134 if (is_buffered)
1135 { /* Deal with line buffering. */
1136 int max = 0;
1137 int count = 0;
1138 int i;
1139 int last = 0;
1140 char *c;
1141
1142 c = (char *)inbuf;
1143 for (i = 0; i < inbuf_num; i++) /* Find the lines. */
1144 {
1145 if (inbuf[i] == '\n')
1146 {
1147 if (count >= max)
1148 {
1149 /* In testing, the lines seem to arrive in batches of 500 to 1000 lines at most, roughly speaking. */
1150 max += 10; /* FIXME: Maybe keep track of the largest number of lines ever sent, and add half that many instead of 10. */
1151 e->lines = realloc(e->lines, sizeof(Ecore_Exe_Event_Data_Line) * (max + 1)); /* Allow room for the NULL termination. */
1152 }
1153 /* raster said to leave the line endings as line endings, however -
1154 * This is line buffered mode, we are not dealing with binary here, but lines.
1155 * If we are not dealing with binary, we must be dealing with ASCII, unicode, or some other text format.
1156 * Thus the user is most likely gonna deal with this text as strings.
1157 * Thus the user is most likely gonna pass this data to str functions.
1158 * rasters way - the endings are always gonna be '\n'; onefangs way - they will always be '\0'
1159 * We are handing them the string length as a convenience.
1160 * Thus if they really want it in raw format, they can e->lines[i].line[e->lines[i].size - 1] = '\n'; easily enough.
1161 * In the default case, we can do this conversion quicker than the user can, as we already have the index and pointer.
1162 * Let's make it easy on them to use these as standard C strings.
1163 *
1164 * onefang is proud to announce that he has just set a new personal record for the
1165 * most over documentation of a simple assignment statement. B-)
1166 */
1167 inbuf[i] = '\0';
1168 e->lines[count].line = c;
1169 e->lines[count].size = i - last;
1170 last = i + 1;
1171 c = (char *)&inbuf[last];
1172 count++;
1173 }
1174 }
1175 if (count == 0) /* No lines to send, cancel the event. */
1176 {
1177 _ecore_exe_event_exe_data_free(NULL, e);
1178 e = NULL;
1179 }
1180 else /* NULL terminate the array, so that people know where the end is. */
1181 {
1182 e->lines[count].line = NULL;
1183 e->lines[count].size = 0;
1184 }
1185 if (i > last) /* Partial line left over, save it for next time. */
1186 {
1187 e->size = last;
1188 if (flags & ECORE_FD_READ)
1189 {
1190 exe->read_data_size = i - last;
1191 exe->read_data_buf = malloc(exe->read_data_size);
1192 memcpy(exe->read_data_buf, c, exe->read_data_size);
1193 }
1194 else
1195 {
1196 exe->error_data_size = i - last;
1197 exe->error_data_buf = malloc(exe->error_data_size);
1198 memcpy(exe->error_data_buf, c, exe->error_data_size);
1199 }
1200 }
1201 }
1202
1203 if (e) /* Send the event. */
1204 ecore_event_add(event_type, e, 1274 ecore_event_add(event_type, e,
1205 _ecore_exe_event_exe_data_free, NULL); 1275 _ecore_exe_event_exe_data_free, NULL);
1206 } 1276 }
1207 } 1277 }
1208 if (lost_exe) 1278 if (lost_exe)
@@ -1222,7 +1292,7 @@ _ecore_exe_data_generic_handler(void *data, Ecore_Fd_Handler *fd_handler, Ecore_
1222 * recently and the pid has not had a chance to recycle. 1292 * recently and the pid has not had a chance to recycle.
1223 * It is also a paranoid catchall, coz the usual ecore_signal 1293 * It is also a paranoid catchall, coz the usual ecore_signal
1224 * mechenism should kick in. But let's give it a good 1294 * mechenism should kick in. But let's give it a good
1225 * kick anyway. 1295 * kick in the head anyway.
1226 */ 1296 */
1227 ecore_exe_terminate(exe); 1297 ecore_exe_terminate(exe);
1228 } 1298 }
@@ -1354,4 +1424,5 @@ _ecore_exe_event_del_free(void *data __UNUSED__, void *ev)
1354 if (e->exe) ecore_exe_free(e->exe); 1424 if (e->exe) ecore_exe_free(e->exe);
1355 free(e); 1425 free(e);
1356} 1426}
1427
1357#endif 1428#endif
diff --git a/legacy/ecore/src/lib/ecore/ecore_private.h b/legacy/ecore/src/lib/ecore/ecore_private.h
index 3cac0f07f4..930b7c96e7 100644
--- a/legacy/ecore/src/lib/ecore/ecore_private.h
+++ b/legacy/ecore/src/lib/ecore/ecore_private.h
@@ -156,7 +156,8 @@ enum _Ecore_Exe_Flags
156 ECORE_EXE_PIPE_ERROR = 4, 156 ECORE_EXE_PIPE_ERROR = 4,
157 ECORE_EXE_PIPE_READ_LINE_BUFFERED = 8, 157 ECORE_EXE_PIPE_READ_LINE_BUFFERED = 8,
158 ECORE_EXE_PIPE_ERROR_LINE_BUFFERED = 16, 158 ECORE_EXE_PIPE_ERROR_LINE_BUFFERED = 16,
159 ECORE_EXE_RESPAWN = 32 159 ECORE_EXE_PIPE_AUTO = 32,
160 ECORE_EXE_RESPAWN = 64
160 /* FIXME: Getting respawn to work 161 /* FIXME: Getting respawn to work
161 * 162 *
162 * There is no way that we can do anything about the internal state info of 163 * There is no way that we can do anything about the internal state info of