2005-12-10 22:52:07 -08:00
|
|
|
/* Timer example.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Ecore.h>
|
|
|
|
|
2005-12-30 11:19:59 -08:00
|
|
|
#include <string.h>
|
2005-12-10 22:52:07 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2005-12-30 11:19:59 -08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2005-12-10 22:52:07 -08:00
|
|
|
|
2006-02-28 22:00:41 -08:00
|
|
|
int size = 0;
|
|
|
|
int exe_count = 0;
|
|
|
|
int data_count = 0;
|
|
|
|
int line_count = 0;
|
|
|
|
double then = 0.0, now = 0.0;
|
|
|
|
Ecore_Exe *exe0 = NULL;
|
|
|
|
Ecore_Exe *exe1 = NULL;
|
|
|
|
Ecore_Exe *exe2 = NULL;
|
|
|
|
Ecore_Exe *exe3 = NULL;
|
2006-04-07 06:54:16 -07:00
|
|
|
Ecore_Exe *exe4 = NULL;
|
2005-12-30 11:19:59 -08:00
|
|
|
|
2005-12-10 22:52:07 -08:00
|
|
|
static int
|
|
|
|
exe_data(void *data, int type, void *event)
|
|
|
|
{
|
2006-01-15 03:27:19 -08:00
|
|
|
Ecore_Exe_Event_Data *ev;
|
2006-02-28 22:00:41 -08:00
|
|
|
int i;
|
2005-12-10 22:52:07 -08:00
|
|
|
|
|
|
|
ev = event;
|
2006-02-28 22:00:41 -08:00
|
|
|
printf(" [*] DATA RET EXE %p - %p [%i bytes]\n", ev->exe, ev->data,
|
|
|
|
ev->size);
|
2005-12-15 20:03:04 -08:00
|
|
|
|
|
|
|
if (ev->lines)
|
2006-02-28 22:00:41 -08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; ev->lines[i].line != NULL; i++)
|
|
|
|
{
|
|
|
|
printf("%d %s\n", ev->lines[i].size, ev->lines[i].line);
|
|
|
|
}
|
|
|
|
}
|
2005-12-15 20:03:04 -08:00
|
|
|
else
|
2006-02-28 22:00:41 -08:00
|
|
|
{
|
|
|
|
for (i = 0; i < ev->size; i++)
|
|
|
|
putchar(((unsigned char *)ev->data)[i]);
|
|
|
|
}
|
2005-12-10 22:52:07 -08:00
|
|
|
printf("\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-12-30 11:19:59 -08:00
|
|
|
static int
|
|
|
|
exe_data_count(void *data, int type, void *event)
|
|
|
|
{
|
2006-01-15 03:27:19 -08:00
|
|
|
Ecore_Exe_Event_Data *ev;
|
2006-02-28 22:00:41 -08:00
|
|
|
int i;
|
2005-12-30 11:19:59 -08:00
|
|
|
|
|
|
|
ev = event;
|
|
|
|
|
|
|
|
if (ev->lines)
|
2006-02-28 22:00:41 -08:00
|
|
|
{
|
|
|
|
for (i = 0; ev->lines[i].line != NULL; i++)
|
|
|
|
line_count++;
|
|
|
|
/* printf("%d ", i); This is for testing the number of lines per event. */
|
|
|
|
}
|
2005-12-30 11:19:59 -08:00
|
|
|
|
2006-01-01 09:20:33 -08:00
|
|
|
data_count += ev->size;
|
2005-12-30 11:19:59 -08:00
|
|
|
if (data_count >= size)
|
2006-02-28 22:00:41 -08:00
|
|
|
{
|
|
|
|
now = ecore_time_get();
|
|
|
|
printf
|
|
|
|
("\n\nApproximate data rate - %f bytes/second (%d lines and %d bytes (x2) in %f seconds).\n",
|
|
|
|
((double)data_count * 2.0) / (now - then), line_count, data_count,
|
|
|
|
now - then);
|
|
|
|
if (data_count != size)
|
|
|
|
printf("Size discrepency of %d bytes.\n", size - data_count);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* Since there does not seem to be anyway to convince /bin/cat to finish... */
|
|
|
|
ecore_exe_terminate(exe0);
|
|
|
|
}
|
2005-12-30 11:19:59 -08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-12-10 22:52:07 -08:00
|
|
|
static int
|
|
|
|
exe_exit(void *data, int type, void *event)
|
|
|
|
{
|
2006-01-15 03:27:19 -08:00
|
|
|
Ecore_Exe_Event_Del *ev;
|
2005-12-10 22:52:07 -08:00
|
|
|
|
|
|
|
ev = event;
|
|
|
|
printf(" [*] EXE EXIT: %p\n", ev->exe);
|
2005-12-30 11:19:59 -08:00
|
|
|
exe_count--;
|
|
|
|
if (exe_count <= 0)
|
|
|
|
ecore_main_loop_quit();
|
2005-12-10 22:52:07 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-02-28 22:00:41 -08:00
|
|
|
int
|
|
|
|
timer_once(void *data)
|
2006-01-01 09:20:33 -08:00
|
|
|
{
|
2006-02-28 22:00:41 -08:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
int i = 1;
|
2006-01-01 09:20:33 -08:00
|
|
|
|
|
|
|
ecore_app_args_get(&argc, &argv);
|
2006-01-12 22:38:44 -08:00
|
|
|
ecore_event_handler_add(ECORE_EXE_EVENT_DATA, exe_data_count, NULL);
|
2006-04-07 06:54:16 -07:00
|
|
|
ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, exe_data_count, NULL);
|
2006-01-01 09:20:33 -08:00
|
|
|
printf("FILE : %s\n", argv[i]);
|
2006-02-28 22:00:41 -08:00
|
|
|
exe0 =
|
|
|
|
ecore_exe_pipe_run("/bin/cat",
|
|
|
|
ECORE_EXE_PIPE_WRITE | ECORE_EXE_PIPE_READ |
|
|
|
|
ECORE_EXE_PIPE_READ_LINE_BUFFERED, NULL);
|
2006-01-01 09:20:33 -08:00
|
|
|
|
|
|
|
if (exe0)
|
2006-02-28 22:00:41 -08:00
|
|
|
{
|
|
|
|
struct stat s;
|
|
|
|
|
|
|
|
exe_count++;
|
|
|
|
if (stat(argv[i], &s) == 0)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
size = s.st_size;
|
|
|
|
if ((fd = open(argv[i], O_RDONLY)) != -1)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
int length;
|
|
|
|
|
|
|
|
then = ecore_time_get();
|
|
|
|
while ((length = read(fd, buf, 1024)) > 0)
|
|
|
|
ecore_exe_send(exe0, buf, length);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FIXME: Fuckit, neither of these will actually cause /bin/cat to shut down. What the fuck does it take? */
|
|
|
|
ecore_exe_send(exe0, "\004", 1); /* Send an EOF. */
|
|
|
|
ecore_exe_close_stdin(exe0); /* /bin/cat should stop when it's stdin closes. */
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-01-01 09:20:33 -08:00
|
|
|
}
|
|
|
|
|
2006-02-28 22:00:41 -08:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
2005-12-30 11:19:59 -08:00
|
|
|
{
|
2006-02-28 22:00:41 -08:00
|
|
|
ecore_app_args_set(argc, (const char **)argv);
|
2005-12-30 11:19:59 -08:00
|
|
|
|
2005-12-10 22:52:07 -08:00
|
|
|
ecore_init();
|
2006-01-12 22:38:44 -08:00
|
|
|
ecore_event_handler_add(ECORE_EXE_EVENT_DEL, exe_exit, NULL);
|
2005-12-30 11:19:59 -08:00
|
|
|
|
|
|
|
if (argc == 1)
|
2006-02-28 22:00:41 -08:00
|
|
|
{
|
|
|
|
ecore_event_handler_add(ECORE_EXE_EVENT_DATA, exe_data, NULL);
|
2006-04-07 06:54:16 -07:00
|
|
|
ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, exe_data, NULL);
|
2006-02-28 22:00:41 -08:00
|
|
|
exe0 = ecore_exe_run("/bin/uname -a", NULL);
|
|
|
|
if (exe0)
|
|
|
|
exe_count++;
|
|
|
|
|
|
|
|
exe1 = ecore_exe_pipe_run("/bin/sh",
|
|
|
|
ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE,
|
|
|
|
NULL);
|
|
|
|
if (exe1)
|
|
|
|
{
|
|
|
|
exe_count++;
|
|
|
|
ecore_exe_send(exe1, "ls\n", 3);
|
|
|
|
ecore_exe_send(exe1, "exit\n", 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
exe2 = ecore_exe_pipe_run("/usr/bin/find . -print",
|
|
|
|
ECORE_EXE_PIPE_READ |
|
|
|
|
ECORE_EXE_PIPE_READ_LINE_BUFFERED, NULL);
|
|
|
|
if (exe2)
|
|
|
|
exe_count++;
|
|
|
|
|
|
|
|
exe3 = ecore_exe_pipe_run("/bin/cat", ECORE_EXE_PIPE_WRITE, NULL);
|
|
|
|
if (exe3)
|
|
|
|
{
|
|
|
|
exe_count++;
|
|
|
|
ecore_exe_send(exe3, "ls\n", 3);
|
|
|
|
}
|
2006-04-07 06:54:16 -07:00
|
|
|
exe4 = ecore_exe_pipe_run(".libs/output_tester",
|
|
|
|
ECORE_EXE_PIPE_READ |
|
|
|
|
ECORE_EXE_PIPE_READ_LINE_BUFFERED |
|
|
|
|
ECORE_EXE_PIPE_ERROR |
|
|
|
|
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED, NULL);
|
|
|
|
if (exe4)
|
|
|
|
exe_count++;
|
2006-02-28 22:00:41 -08:00
|
|
|
|
|
|
|
printf(" [*] exe0 = %p (/bin/uname -a)\n", exe0);
|
|
|
|
printf(" [*] exe1 = %p (echo \"ls\" | /bin/sh)\n", exe1);
|
|
|
|
printf(" [*] exe2 = %p (/usr/bin/find / -print)\n", exe2);
|
|
|
|
printf(" [*] exe3 = %p (echo \"ls\" | /bin/cat)\n", exe3);
|
2006-04-07 06:54:16 -07:00
|
|
|
printf(" [*] exe4 = %p (.libs/output_tester)\n", exe4);
|
2006-02-28 22:00:41 -08:00
|
|
|
}
|
2005-12-30 11:19:59 -08:00
|
|
|
else
|
2006-01-01 09:20:33 -08:00
|
|
|
ecore_timer_add(0.5, timer_once, NULL);
|
2005-12-30 11:19:59 -08:00
|
|
|
|
2006-01-01 09:20:33 -08:00
|
|
|
if ((exe_count > 0) || (argc > 1))
|
2005-12-30 11:19:59 -08:00
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2005-12-10 22:52:07 -08:00
|
|
|
ecore_shutdown();
|
|
|
|
return 0;
|
|
|
|
}
|