Enlightenment CVS committal
Author : horms
Project : e17
Module : apps/entice
Dir : e17/apps/entice/src/bin
Modified Files:
entice.c entice.h ipc.c ipc.h main.c
Log Message:
Fix and clean-up initial ipc
===================================================================
RCS file: /cvs/e/e17/apps/entice/src/bin/entice.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -3 -r1.67 -r1.68
--- entice.c 5 Sep 2005 12:21:49 -0000 1.67
+++ entice.c 15 Apr 2006 08:05:18 -0000 1.68
@@ -14,6 +14,7 @@
#include <Esmart/Esmart_Trans_X11.h>
#include <Esmart/Esmart_Draggies.h>
#include <Epsilon.h>
+#include <Ecore_Ipc.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -122,7 +123,6 @@
memset(e, 0, sizeof(Entice));
e->ee = ee;
- epsilon_init();
ecore_evas_geometry_get(ee, &x, &y, &w, &h);
o = edje_object_add(ecore_evas_get(ee));
if (!edje_object_file_set(o, entice_config_theme_get(), "entice"))
@@ -586,94 +586,74 @@
{
struct stat st;
- if (file)
- {
- if (stat(file, &st) < 0)
- return (0);
- if (S_ISDIR(st.st_mode))
- return (1);
- }
- return (0);
+ if (file && !stat(file, &st)&& S_ISDIR(st.st_mode))
+ return 1;
+ return 0;
}
void
-entice_file_add_dir_job_cb(void *data)
+entice_file_add_job_dir(Ecore_Ipc_Server *server, const char *dirname)
{
DIR *d = NULL;
struct dirent *dent = NULL;
- char buf[PATH_MAX], *file = NULL;
-
- if (data)
- {
- file = (char *) data;
-
- if ((d = opendir(data)))
- {
- while ((dent = readdir(d)))
- {
- if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")
- || (dent->d_name[0] == '.'))
- continue;
- snprintf(buf, PATH_MAX, "%s/%s", file, dent->d_name);
- if (!entice_file_is_dir(buf))
- entice_file_add_job_cb(buf, IPC_FILE_APPEND);
- }
- closedir(d);
- }
- }
+ char buf[PATH_MAX];
+ if (!dirname || ! (d = opendir(dirname)))
+ return;
+ while ((dent = readdir(d)))
+ {
+ if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")
+ || (dent->d_name[0] == '.'))
+ continue;
+ snprintf(buf, PATH_MAX, "%s/%s", dirname, dent->d_name);
+ if (!entice_file_is_dir(buf))
+ entice_file_add_job(server, buf, IPC_FILE_APPEND);
+ }
+ closedir(d);
}
/**
- * entice_file_add_job_cb - generate the cached thumb and send an ipc
+ * entice_file_add_job - generate the cached thumb and send an ipc
* message telling entice to load it
* @data - the full or relative path to the file we want to cache
* @add_type - whether to display or show the image
*/
void
-entice_file_add_job_cb(void *data, int add_type)
+entice_file_add_job(Ecore_Ipc_Server *server, const char *filename,
+ int add_type)
{
Epsilon *e = NULL;
- char buf[PATH_MAX], *file = NULL;
+ char buf[PATH_MAX];
- if (data)
- {
- file = (char *) data;
+ if (!filename)
+ return;
- if (file)
- {
- if (file[0] == '/')
- snprintf(buf, PATH_MAX, "%s", file);
- else if ((strlen(file) > 7) && !strncmp(file, "http://", 7))
- {
- fprintf(stderr, "Entice Compiled without http loading support\n");
- }
- else
- {
- char mycwd[PATH_MAX];
+ if (filename[0] == '/')
+ snprintf(buf, PATH_MAX-1, "%s", filename);
+ else if ((strlen(filename) > 7) && !strncmp(filename, "http://", 7))
+ fprintf(stderr, "Entice Compiled without http loading support\n");
+ else
+ {
+ char mycwd[PATH_MAX];
+ memset(mycwd, 0, sizeof(mycwd));
+ if (getcwd(mycwd, PATH_MAX))
+ snprintf(buf, PATH_MAX, "%s/%s", mycwd, filename);
+ }
+
+ if (entice_file_is_dir(buf))
+ {
+ entice_file_add_job_dir(server, buf);
+ return;
+ }
+
+ entice_ipc_client_request_image_load(server, buf, add_type);
+
+ epsilon_init();
+ if (!(e = epsilon_new(buf)) || (epsilon_exists(e) == EPSILON_FAIL &&
+ epsilon_generate(e) == EPSILON_FAIL))
+ fprintf(stderr, "Unable to thumbnail %s\n", filename);
- memset(mycwd, 0, sizeof(mycwd));
- if (getcwd(mycwd, PATH_MAX))
- {
- snprintf(buf, PATH_MAX, "%s/%s", mycwd, file);
- }
- }
- if (entice_file_is_dir(buf))
- entice_file_add_dir_job_cb(buf);
- else if ((e = epsilon_new(buf)))
- {
- if (epsilon_exists(e) == EPSILON_FAIL)
- {
- if (epsilon_generate(e) == EPSILON_FAIL)
- {
- fprintf(stderr, "Unable to thumbnail %s\n", file);
- }
- }
- epsilon_free(e);
- entice_ipc_client_request_image_load(buf, add_type);
- }
- }
- }
+ epsilon_free(e);
}
static void
===================================================================
RCS file: /cvs/e/e17/apps/entice/src/bin/entice.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -3 -r1.19 -r1.20
--- entice.h 17 Feb 2005 03:27:24 -0000 1.19
+++ entice.h 15 Apr 2006 08:05:18 -0000 1.20
@@ -13,6 +13,7 @@
#include<Edje.h>
#include<Ecore.h>
#include<Ecore_Evas.h>
+#include<Ecore_Ipc.h>
struct _Entice
{
@@ -43,8 +44,9 @@
int entice_file_del(const char *file);
int entice_file_del_from_fs(const char *file);
int entice_current_image_set(const char *file);
-void entice_file_add_job_cb(void *data, int add_type);
-void entice_file_add_dir_job_cb(void *data);
+void entice_file_add_job(Ecore_Ipc_Server *server, const char *filename,
+ int add_type);
+void entice_file_add_job_dir(Ecore_Ipc_Server *server, const char *dirname);
void entice_thumbs_scroll_next_start(void);
void entice_thumbs_scroll_prev_start(void);
===================================================================
RCS file: /cvs/e/e17/apps/entice/src/bin/ipc.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- ipc.c 5 Sep 2005 12:21:49 -0000 1.8
+++ ipc.c 15 Apr 2006 08:05:18 -0000 1.9
@@ -9,20 +9,18 @@
#define IPC_TITLE "entice"
+static unsigned int entice_ipc_client_request_pending = 0;
+
/**
* ipc_server_add - when we connect to the ipc daemon
* @data -
* @type -
* @event - the Ecore_Ipc_Event_Server_Add that triggered us
*/
-int
+static int
ipc_server_add(void *data, int type, void *event)
{
- Ecore_Ipc_Event_Server_Add *e;
-
- e = (Ecore_Ipc_Event_Server_Add *) event;
- // fprintf(stderr, "Server add\n");
- return (1);
+ return 1;
}
/**
@@ -31,14 +29,10 @@
* @type -
* @event - the Ecore_Ipc_Event_Server_Del that triggered us
*/
-int
+static int
ipc_server_del(void *data, int type, void *event)
{
- Ecore_Ipc_Event_Server_Del *e;
-
- e = (Ecore_Ipc_Event_Server_Del *) event;
- /* fprintf(stderr, "Server delete\n"); */
- return (1);
+ return 1;
}
/**
@@ -47,84 +41,77 @@
* @type -
* @event - the Ecore_Ipc_Event_Server_Data that triggered us
*/
-int
+static int
ipc_server_data(void *data, int type, void *event)
{
- Ecore_Ipc_Event_Server_Data *e;
-
- e = (Ecore_Ipc_Event_Server_Data *) event;
- /*
- printf("!! Server sent: [%i] [%i] (%i) \"%s\"\n", e->major, e->minor,
- e->size, e->data); */
- return (1);
+ Ecore_Ipc_Event_Server_Data *e = (Ecore_Ipc_Event_Server_Data *)event;
+ /* printf("ipc_server_data: %p [%i] [%i] [%i] (%s)\n",
+ e->server, e->major, e->minor, e->size, (char *)e->data); */
+ if (!--entice_ipc_client_request_pending)
+ ecore_main_loop_quit();
+ return 1;
}
/**
* ipc_client_add -
* @data -
* @type -
- * @event -
+ * @event - the Ecore_Ipc_Event_Server_Add that triggered us
*/
-int
+static int
ipc_client_add(void *data, int type, void *event)
{
- Ecore_Ipc_Event_Client_Add *e;
-
- e = (Ecore_Ipc_Event_Client_Add *) event;
- // fprintf(stderr, "Client Connected!!!\n");
- return (1);
+ return 1;
}
/**
* ipc_client_del -
* @data -
* @type -
- * @event -
+ * @event - the Ecore_Ipc_Event_Server_Del that triggered us
*/
-int
+static int
ipc_client_del(void *data, int type, void *event)
{
- Ecore_Ipc_Event_Client_Del *e;
-
- e = (Ecore_Ipc_Event_Client_Del *) event;
- // fprintf(stderr, "Client Disconnected!!!\n");
- return (1);
+ return 1;
}
/**
* ipc_client_data - when we get sent stuff by an entice client
* @data -
* @type -
- * @event -
+ * @event - the Ecore_Ipc_Event_Server_Data that triggered us
*/
-int
+#define IPC_CLIENT_ACK_MSG "ACK: Pants On!"
+static int
ipc_client_data(void *data, int type, void *event)
{
- Ecore_Ipc_Event_Client_Data *e;
+ Ecore_Ipc_Event_Client_Data *e= (Ecore_Ipc_Event_Client_Data *)event;
+ char buf[e->size];
- if ((e = (Ecore_Ipc_Event_Client_Data *) event))
- {
- char buf[e->size];
-
- snprintf(buf, e->size, "%s", (char *) e->data);
- switch (e->major)
- {
- case IPC_FILE_APPEND:
- entice_file_add(buf);
- break;
- case IPC_FILE_DISPLAY:
- entice_current_image_set(buf);
- break;
- default:
- fprintf(stderr, "Unknown major code sent by client(%d)\n",
- e->major);
- break;
- }
- /*
- printf("!! Client sent: [%i] [%i] (%i) \"%s\"\n", e->major,
- e->minor, e->size, buf); */
- }
- return (1);
+ if (!e)
+ return 1;
+
+ ecore_ipc_client_send(e->client, 3, 4, 0, 0, 0,
+ IPC_CLIENT_ACK_MSG, strlen(IPC_CLIENT_ACK_MSG) + 1);
+
+ snprintf(buf, e->size, "%s", (char *) e->data);
+ switch (e->major)
+ {
+ case IPC_FILE_APPEND:
+ entice_file_add(buf);
+ break;
+ case IPC_FILE_DISPLAY:
+ entice_current_image_set(buf);
+ break;
+ default:
+ fprintf(stderr, "Unknown major code sent by client(%d)\n",
+ e->major);
+ break;
+ }
+ /* printf("!! Client sent: [%i] [%i] (%i) \"%s\"\n", e->major,
+ e->minor, e->size, buf); */
+ return 1;
}
/**
@@ -132,56 +119,57 @@
* already is running
* @argc - the number of arguments passed to entice
* @argv - the string arguments passed to entice
- * Basically it tries to connect to an already running entice ipc server.
- * If it successfully connects, it sends the filenames to the current entice
- * daemon and should exit. If it does not successfully connect it registers
- * itself as the server and the app should then start up.
- */
-int
-entice_ipc_init(int argc, const char **argv)
-{
- int i;
+ * Attempts to connect to an existing entice ipc server.
+ * If it successful, it sends the filenames to the current entice daemon
+ * and exits. Else, it registers itself as the server and the app should
+ * then start up.
+ */
+int
+entice_ipc_init(int argc, const char **argv)
+{
+ int i;
+ char buf[PATH_MAX];
Ecore_Ipc_Server *server = NULL;
- /* we definitely fail if we can't connect to ecore_ipc */
if (ecore_ipc_init() < 1)
- return (1);
+ return 1;
+ server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, IPC_TITLE, 0, NULL);
/* If we can connect to a currently running entice process */
- if ((server =
- ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, IPC_TITLE, 0, NULL)))
- {
- ecore_ipc_server_del(server);
- for (i = 1; i < argc; i++)
- {
- entice_file_add_job_cb((void *) argv[i], IPC_FILE_APPEND);
- }
- if (argc > 0)
- entice_file_add_job_cb((void *) argv[1], IPC_FILE_DISPLAY);
- return (1);
- }
- /* Otherwise we create it */
- else
- {
- char buf[PATH_MAX];
-
- snprintf(buf, PATH_MAX, "%s/.ecore/entice/0", getenv("HOME"));
- unlink(buf);
- /*
- printf("creating new server\n"); */
- server = ecore_ipc_server_add(ECORE_IPC_LOCAL_USER, IPC_TITLE, 0, NULL);
- if (server == NULL)
- printf("creating new IPC server failed\n");
- ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, ipc_client_add,
- NULL);
- ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, ipc_client_del,
- NULL);
- ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, ipc_client_data,
- NULL);
- /*
- fprintf(stderr, "Listener Started\n"); */
- }
- return (0);
+ if (server)
+ {
+ if (! (server = entice_ipc_client_init()) )
+ return 1;
+ for (i = 1; i < argc; i++)
+ {
+ entice_file_add_job(server, argv[i], IPC_FILE_APPEND);
+ if (i == 1)
+ entice_file_add_job(server, argv[1], IPC_FILE_DISPLAY);
+ /* Flush every now an again */
+ if ((i & 0xf) == 0x1)
+ entice_ipc_client_wait(server);
+ }
+ entice_ipc_client_wait(server);
+ entice_ipc_client_shutdown(server);
+ return 1;
+ }
+
+ /* Otherwise we create an entice server */
+ snprintf(buf, PATH_MAX, "%s/.ecore/entice/0", getenv("HOME"));
+ unlink(buf);
+ server = ecore_ipc_server_add(ECORE_IPC_LOCAL_USER, IPC_TITLE, 0, NULL);
+ if (!server)
+ {
+ printf("creating new IPC server failed\n");
+ return 1;
+ }
+ ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, ipc_client_add,
+ NULL);
+ ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, ipc_client_del,
+ NULL);
+ ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, ipc_client_data,
+ NULL);
+ return 0;
}
/**
@@ -190,46 +178,86 @@
void
entice_ipc_shutdown(void)
{
- // printf("shutting down IPC\n");
ecore_ipc_shutdown();
}
/**
+ * entice_ipc_client_init - initilaise client ipc
+ * Must be called before entice_ipc_client_send
+ * Returns handle to entice server
+ */
+Ecore_Ipc_Server *
+entice_ipc_client_init(void)
+{
+ Ecore_Ipc_Server *server;
+
+ if (!ecore_init())
+ {
+ fprintf(stderr, "unable to init ecore\n");
+ return NULL;
+ }
+
+ if (!ecore_ipc_init())
+ {
+ fprintf(stderr, "unable to init ecore_con\n");
+ goto out_ecore;
+ }
+
+ server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, IPC_TITLE, 0, NULL);
+ if (!server)
+ {
+ fprintf(stderr, "unable to connect to server\n");
+ goto out_ecore_ipc;
+ }
+ ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, ipc_server_add, NULL);
+ ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, ipc_server_del, NULL);
+ ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, ipc_server_data, NULL);
+
+ return server;
+
+out_ecore_ipc:
+ ecore_ipc_shutdown();
+out_ecore:
+ ecore_shutdown();
+ return NULL;
+}
+
+/**
+ * entice_ipc_client_shutdown - shutdown client
+ * @server - handle to entice server
+ */
+void
+entice_ipc_client_shutdown(Ecore_Ipc_Server *server)
+{
+ ecore_ipc_server_del(server);
+ ecore_ipc_shutdown();
+ ecore_shutdown();
+}
+
+/**
+ * entice_ipc_client_wait - wait for all pending messages to be procecced
+ * Must be called after issuing one or more entice_ipc_client_send
+ * @server - handle to entice server
+ */
+void
+entice_ipc_client_wait(Ecore_Ipc_Server *server)
+{
+ if (entice_ipc_client_request_pending)
+ ecore_main_loop_begin();
+}
+
+/**
* entice_ipc_client_request_image_load - send a message to a running
* entice process telling it to load the file
+ * @server - handle to entice server
* @file - the absolute path to file
+ * @major - major number of request
*/
void
-entice_ipc_client_request_image_load(const char *file, int major)
+entice_ipc_client_request_image_load(Ecore_Ipc_Server *server,
+ const char *file, int major)
{
- Ecore_Ipc_Server *server = NULL;
-
- /* we definitely fail if we can't connect to ecore_ipc */
- if (ecore_ipc_init() < 1)
- return;
-
- /* If we can connect to a currently running entice process */
- if ((server =
- ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, IPC_TITLE, 0, NULL)))
- {
- char buf[PATH_MAX];
-
- ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, ipc_server_add,
- NULL);
- ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, ipc_server_del,
- NULL);
- ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, ipc_server_data,
- NULL);
-
- snprintf(buf, PATH_MAX, "%s", file);
- ecore_ipc_server_send(server, major, 6, 0, 0, 0, buf, strlen(buf) + 1);
- memset(buf, 0, sizeof(buf));
- ecore_ipc_server_del(server);
- }
-#if DEBUG
- else
- {
- fprintf(stderr, "ERROR: Unable to connect to entice IPC Server\n");
- }
-#endif
+ entice_ipc_client_request_pending++;
+ ecore_ipc_server_send(server, major, 6, 0, 0, 0, (void *)file,
+ strlen(file) + 1);
}
===================================================================
RCS file: /cvs/e/e17/apps/entice/src/bin/ipc.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- ipc.h 8 Jan 2004 05:03:54 -0000 1.2
+++ ipc.h 15 Apr 2006 08:05:18 -0000 1.3
@@ -4,14 +4,14 @@
#define IPC_FILE_APPEND 1
#define IPC_FILE_DISPLAY 2
-/**
- * entice_ipc_init - entialize entice's ipc handlers
- * @argc - the number or arguments
- * @argv - pointer to the argument strings
- * Lengthy descriptin in entice_ipc.c
- */
int entice_ipc_init(int argc, const char **argv);
void entice_ipc_shutdown(void);
-void entice_ipc_client_request_image_load(const char *file, int major);
+int entice_ipc_init(int argc, const char **argv);
+void entice_ipc_shutdown(void);
+Ecore_Ipc_Server *entice_ipc_client_init(void);
+void entice_ipc_client_shutdown(Ecore_Ipc_Server *server);
+void entice_ipc_client_wait(Ecore_Ipc_Server *server);
+void entice_ipc_client_request_image_load(Ecore_Ipc_Server *server,
+ const char *file, int major);
#endif
===================================================================
RCS file: /cvs/e/e17/apps/entice/src/bin/main.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -3 -r1.35 -r1.36
--- main.c 5 Sep 2005 12:21:49 -0000 1.35
+++ main.c 15 Apr 2006 08:05:18 -0000 1.36
@@ -148,48 +148,57 @@
int fd[2];
char line[PATH_MAX];
struct stat status;
+ Ecore_Ipc_Server *server;
if (pipe(fd) < 0)
- exit(1);
+ {
+ perror("pipe");
+ exit(1);
+ }
if ((pid = fork()) < 0)
- {
- fprintf(stderr, "Forking error\n");
- exit(1);
- }
- else if (pid > 0) /* parent */
- {
- close(fd[0]);
- return (fd[1]);
- }
- else /* child */
- {
- close(fd[1]);
- while ((n = read(fd[0], line, PATH_MAX)) > 0)
- {
- if (!strncmp(line, "ok", n))
- {
- for (i = 1; i < argc; i++)
- {
- snprintf(line, PATH_MAX, "%s", argv[i]);
- if (!stat(line, &status))
- {
- if (S_ISDIR(status.st_mode))
- {
- entice_file_add_dir_job_cb(line);
- }
- else
- {
- entice_file_add_job_cb(line, IPC_FILE_APPEND);
- }
- }
- }
- break;
- }
- }
- close(fd[0]);
- exit(0);
- }
+ {
+ perror("fork");
+ exit(1);
+ }
+
+ if (pid > 0) /* parent */
+ {
+ close(fd[0]);
+ return fd[1];
+ }
+
+ /* child */
+ close(fd[1]);
+ while ((n = read(fd[0], line, PATH_MAX)) > 0)
+ if (!strncmp(line, "ok", n))
+ break;
+ if ( !(server=entice_ipc_client_init()) )
+ {
+ fprintf(stderr, "Could not intialise client IPC\n");
+ exit(1);
+ }
+ for (i = 1; i < argc; i++)
+ {
+ snprintf(line, PATH_MAX, "%s", argv[i]);
+ if (stat(line, &status))
+ continue;
+ if (S_ISDIR(status.st_mode))
+ entice_file_add_job_dir(server, line);
+ else
+ entice_file_add_job(server, line, IPC_FILE_APPEND);
+ /* Flush rather than waiting for all thumbnails before displaying
+ * anything */
+ if ((i & 0xf) == 0x1)
+ entice_ipc_client_wait(server);
+ }
+
+ entice_ipc_client_wait(server);
+ entice_ipc_client_shutdown(server);
+ exit(0);
+
+ /* Not reached */
+ close(fd[0]);
return (0);
}
@@ -204,14 +213,14 @@
* 7. for(;;)
*/
int
-main(int argc, char *argv[])
+main(int argc, char **argv)
{
int pnum = -1;
int x, y, w, h;
Ecore_Evas *ee = NULL;
if (argc > 1)
- pnum = entice_pipe_foo(argc, (const char **) argv);
+ pnum = entice_pipe_foo(argc, argv);
ecore_init();
ecore_app_args_set(argc, (const char **) argv);
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs