2009-06-04 14:21:43 -07:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 by ProFUSION embedded systems
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* @author Rafael Antognolli <antognolli@profusion.mobi>
|
|
|
|
*/
|
2009-09-17 05:04:35 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2009-06-04 14:21:43 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <Ethumb.h>
|
|
|
|
#include <Eina.h>
|
|
|
|
#include <Ecore_Getopt.h>
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <E_DBus.h>
|
|
|
|
|
|
|
|
#include "ethumbd_private.h"
|
|
|
|
|
|
|
|
#ifndef PATH_MAX
|
|
|
|
#define PATH_MAX 4096
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MAX_ID 2000000
|
|
|
|
|
2010-07-01 12:48:54 -07:00
|
|
|
#define DBG(...) EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__)
|
|
|
|
#define INF(...) EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__)
|
|
|
|
#define WRN(...) EINA_LOG_DOM_WARN(_log_domain, __VA_ARGS__)
|
|
|
|
#define ERR(...) EINA_LOG_DOM_ERR(_log_domain, __VA_ARGS__)
|
|
|
|
#define CRIT(...) EINA_LOG_DOM_CRIT(_log_domain, __VA_ARGS__)
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
static const char _ethumb_dbus_bus_name[] = "org.enlightenment.Ethumb";
|
|
|
|
static const char _ethumb_dbus_interface[] = "org.enlightenment.Ethumb";
|
|
|
|
static const char _ethumb_dbus_objects_interface[] = "org.enlightenment.Ethumb.objects";
|
|
|
|
static const char _ethumb_dbus_path[] = "/org/enlightenment/Ethumb";
|
|
|
|
static const char fdo_interface[] = "org.freedesktop.DBus";
|
|
|
|
static const char fdo_bus_name[] = "org.freedesktop.DBus";
|
|
|
|
static const char fdo_path[] = "/org/freedesktop/DBus";
|
|
|
|
|
2010-07-01 12:48:54 -07:00
|
|
|
static int _log_domain = -1;
|
|
|
|
|
2009-06-04 14:21:43 -07:00
|
|
|
struct _Ethumb_Setup
|
|
|
|
{
|
|
|
|
struct
|
2009-07-17 07:44:11 -07:00
|
|
|
{
|
|
|
|
Eina_Bool fdo : 1;
|
|
|
|
Eina_Bool size : 1;
|
|
|
|
Eina_Bool format : 1;
|
|
|
|
Eina_Bool aspect : 1;
|
|
|
|
Eina_Bool crop : 1;
|
|
|
|
Eina_Bool quality : 1;
|
|
|
|
Eina_Bool compress : 1;
|
|
|
|
Eina_Bool directory : 1;
|
|
|
|
Eina_Bool category : 1;
|
|
|
|
Eina_Bool frame : 1;
|
|
|
|
Eina_Bool video_time : 1;
|
|
|
|
Eina_Bool video_start : 1;
|
|
|
|
Eina_Bool video_interval : 1;
|
|
|
|
Eina_Bool video_ntimes : 1;
|
|
|
|
Eina_Bool video_fps : 1;
|
|
|
|
Eina_Bool document_page : 1;
|
|
|
|
} flags;
|
2009-06-04 14:21:43 -07:00
|
|
|
int fdo;
|
|
|
|
int tw, th;
|
|
|
|
int format;
|
|
|
|
int aspect;
|
|
|
|
float cx, cy;
|
2009-07-09 12:16:02 -07:00
|
|
|
int quality;
|
|
|
|
int compress;
|
2009-06-04 14:21:43 -07:00
|
|
|
const char *directory;
|
|
|
|
const char *category;
|
|
|
|
const char *theme_file;
|
|
|
|
const char *group;
|
|
|
|
const char *swallow;
|
|
|
|
float video_time;
|
2009-07-13 12:38:17 -07:00
|
|
|
float video_start;
|
|
|
|
float video_interval;
|
2009-09-17 07:05:04 -07:00
|
|
|
unsigned int video_ntimes;
|
|
|
|
unsigned int video_fps;
|
|
|
|
unsigned int document_page;
|
2009-06-04 14:21:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ethumb_Request
|
|
|
|
{
|
2009-07-09 12:26:16 -07:00
|
|
|
int id;
|
2009-06-04 14:21:43 -07:00
|
|
|
const char *file, *key;
|
|
|
|
const char *thumb, *thumb_key;
|
|
|
|
struct _Ethumb_Setup setup;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ethumb_Object
|
|
|
|
{
|
|
|
|
int used;
|
|
|
|
const char *path;
|
|
|
|
const char *client;
|
|
|
|
Eina_List *queue;
|
|
|
|
int nqueue;
|
2009-07-09 12:26:16 -07:00
|
|
|
int id_count;
|
|
|
|
int max_id;
|
|
|
|
int min_id;
|
2009-06-04 14:21:43 -07:00
|
|
|
E_DBus_Object *dbus_obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ethumb_Queue
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
int max_count;
|
|
|
|
int nqueue;
|
|
|
|
int last;
|
|
|
|
int current;
|
|
|
|
struct _Ethumb_Object *table;
|
|
|
|
int *list;
|
|
|
|
};
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
struct _Ethumb_Slave
|
|
|
|
{
|
|
|
|
Ecore_Exe *exe;
|
|
|
|
Ecore_Event_Handler *data_cb;
|
|
|
|
Ecore_Event_Handler *del_cb;
|
|
|
|
char *bufcmd; // buffer to read commands from slave
|
|
|
|
int scmd; // size of command to read
|
|
|
|
int pcmd; // position in the command buffer
|
|
|
|
};
|
|
|
|
|
2009-06-04 14:21:43 -07:00
|
|
|
struct _Ethumbd
|
|
|
|
{
|
|
|
|
E_DBus_Connection *conn;
|
|
|
|
E_DBus_Signal_Handler *name_owner_changed_handler;
|
|
|
|
E_DBus_Interface *eiface, *objects_iface;
|
|
|
|
E_DBus_Object *dbus_obj;
|
|
|
|
Ecore_Idler *idler;
|
|
|
|
struct _Ethumb_Request *processing;
|
|
|
|
struct _Ethumb_Queue queue;
|
|
|
|
double timeout;
|
|
|
|
Ecore_Timer *timeout_timer;
|
2009-12-01 05:34:09 -08:00
|
|
|
struct _Ethumb_Slave slave;
|
2009-06-04 14:21:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ethumb_Object_Data
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
struct _Ethumbd *ed;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ethumb_DBus_Method_Table
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const char *signature;
|
|
|
|
const char *reply;
|
|
|
|
E_DBus_Method_Cb function;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Ethumb_DBus_Signal_Table
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const char *signature;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Ecore_Getopt optdesc = {
|
|
|
|
"ethumbd",
|
|
|
|
NULL,
|
|
|
|
PACKAGE_VERSION,
|
|
|
|
"(C) 2009 - ProFUSION embedded systems",
|
|
|
|
"LGPL v3 - GNU Lesser General Public License",
|
|
|
|
"Ethumb daemon.\n"
|
2009-07-17 07:44:11 -07:00
|
|
|
"\n"
|
|
|
|
"ethumbd uses the Ethumb library to create thumbnails for any "
|
|
|
|
"program that requests it (now just by dbus).\n",
|
2009-06-04 14:21:43 -07:00
|
|
|
0,
|
|
|
|
{
|
2009-07-17 07:44:11 -07:00
|
|
|
ECORE_GETOPT_STORE_DOUBLE
|
|
|
|
('t', "timeout", "finish ethumbd after <timeout> seconds of no activity."),
|
|
|
|
ECORE_GETOPT_LICENSE('L', "license"),
|
|
|
|
ECORE_GETOPT_COPYRIGHT('C', "copyright"),
|
|
|
|
ECORE_GETOPT_VERSION('V', "version"),
|
|
|
|
ECORE_GETOPT_HELP('h', "help"),
|
|
|
|
ECORE_GETOPT_SENTINEL
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-09 12:26:16 -07:00
|
|
|
static void _ethumb_dbus_generated_signal(struct _Ethumbd *ed, int *id, const char *thumb_path, const char *thumb_key, Eina_Bool success);
|
2009-12-01 05:34:09 -08:00
|
|
|
static int _ethumbd_slave_spawn(struct _Ethumbd *ed);
|
2009-06-04 14:21:43 -07:00
|
|
|
|
2010-07-01 12:42:12 -07:00
|
|
|
static Eina_Bool
|
2009-06-04 14:21:43 -07:00
|
|
|
_ethumbd_timeout_cb(void *data)
|
|
|
|
{
|
|
|
|
struct _Ethumbd *ed = data;
|
|
|
|
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
ed->timeout_timer = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumbd_timeout_start(struct _Ethumbd *ed)
|
|
|
|
{
|
|
|
|
if (ed->timeout < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ed->timeout_timer)
|
|
|
|
ed->timeout_timer = ecore_timer_add(ed->timeout, _ethumbd_timeout_cb, ed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumbd_timeout_stop(struct _Ethumbd *ed)
|
|
|
|
{
|
|
|
|
if (!ed->timeout_timer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ecore_timer_del(ed->timeout_timer);
|
|
|
|
ed->timeout_timer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-09 12:26:16 -07:00
|
|
|
_ethumb_dbus_check_id(struct _Ethumb_Object *eobject, int id)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
if (id < 0 || id > MAX_ID)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (eobject->min_id < eobject->max_id)
|
|
|
|
return id < eobject->min_id || id > eobject->max_id;
|
|
|
|
else if (eobject->min_id > eobject->max_id)
|
|
|
|
return id < eobject->min_id && id > eobject->max_id;
|
|
|
|
else
|
|
|
|
return id != eobject->max_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-07-09 12:26:16 -07:00
|
|
|
_ethumb_dbus_inc_max_id(struct _Ethumb_Object *eobject, int id)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
if (eobject->min_id < 0 && eobject->max_id < 0)
|
|
|
|
eobject->min_id = id;
|
|
|
|
|
|
|
|
eobject->max_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumb_dbus_inc_min_id(struct _Ethumb_Object *eobject)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
|
|
|
|
l = eobject->queue;
|
|
|
|
while (l)
|
|
|
|
{
|
|
|
|
struct _Ethumb_Request *request = l->data;
|
|
|
|
if (request->id >= 0)
|
|
|
|
{
|
|
|
|
eobject->min_id = request->id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
eobject->min_id = -1;
|
|
|
|
eobject->max_id = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_write_safe(struct _Ethumbd *ed, const void *buf, ssize_t size)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
if (!ed->slave.exe)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("slave process isn't running.");
|
2009-12-01 05:34:09 -08:00
|
|
|
return 0;
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
ecore_exe_send(ed->slave.exe, buf, size);
|
2009-06-04 14:21:43 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumbd_child_write_op_new(struct _Ethumbd *ed, int index)
|
|
|
|
{
|
|
|
|
int id = ETHUMBD_OP_NEW;
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_write_safe(ed, &id, sizeof(id));
|
|
|
|
_ethumbd_write_safe(ed, &index, sizeof(index));
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumbd_child_write_op_del(struct _Ethumbd *ed, int index)
|
|
|
|
{
|
|
|
|
int id = ETHUMBD_OP_DEL;
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_write_safe(ed, &id, sizeof(id));
|
|
|
|
_ethumbd_write_safe(ed, &index, sizeof(index));
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_str_write(struct _Ethumbd *ed, const char *str)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
len = strlen(str) + 1;
|
|
|
|
else
|
|
|
|
len = 0;
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_write_safe(ed, &len, sizeof(len));
|
|
|
|
_ethumbd_write_safe(ed, str, len);
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumbd_child_write_op_generate(struct _Ethumbd *ed, int index, const char *path, const char *key, const char *thumb_path, const char *thumb_key)
|
|
|
|
{
|
|
|
|
int id = ETHUMBD_OP_GENERATE;
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_write_safe(ed, &id, sizeof(id));
|
|
|
|
_ethumbd_write_safe(ed, &index, sizeof(index));
|
2009-06-04 14:21:43 -07:00
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_str_write(ed, path);
|
|
|
|
_ethumbd_pipe_str_write(ed, key);
|
|
|
|
_ethumbd_pipe_str_write(ed, thumb_path);
|
|
|
|
_ethumbd_pipe_str_write(ed, thumb_key);
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_generated_cb(struct _Ethumbd *ed, Eina_Bool success, const char *thumb_path, const char *thumb_key)
|
|
|
|
{
|
|
|
|
int i = ed->queue.current;
|
|
|
|
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("thumbnail ready at: \"%s:%s\"", thumb_path, thumb_key);
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
if (ed->queue.table[i].used)
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_generated_signal
|
|
|
|
(ed, &ed->processing->id, thumb_path, thumb_key, success);
|
2009-06-04 14:21:43 -07:00
|
|
|
eina_stringshare_del(ed->processing->file);
|
|
|
|
eina_stringshare_del(ed->processing->key);
|
|
|
|
eina_stringshare_del(ed->processing->thumb);
|
|
|
|
eina_stringshare_del(ed->processing->thumb_key);
|
|
|
|
free(ed->processing);
|
|
|
|
ed->processing = NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-01 16:34:40 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_write_safe(int fd, void *data, size_t size)
|
|
|
|
{
|
|
|
|
unsigned char *buf = data;
|
|
|
|
size_t todo = size;
|
|
|
|
while (todo > 0)
|
|
|
|
{
|
|
|
|
size_t r = write(fd, buf, todo);
|
|
|
|
if (r > 0)
|
|
|
|
{
|
|
|
|
todo -= r;
|
|
|
|
buf += r;
|
|
|
|
}
|
|
|
|
else if ((r < 0) && (errno != EINTR))
|
|
|
|
{
|
|
|
|
ERR("could not write to fd=%d: %s", fd, strerror(errno));
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
static void
|
|
|
|
_ethumbd_slave_cmd_ready(struct _Ethumbd *ed)
|
|
|
|
{
|
|
|
|
char *bufcmd = ed->slave.bufcmd;
|
|
|
|
Eina_Bool *success;
|
2010-07-01 12:54:47 -07:00
|
|
|
const char *thumb_path = NULL;
|
|
|
|
const char *thumb_key = NULL;
|
2009-12-01 05:34:09 -08:00
|
|
|
int *size_path, *size_key;
|
|
|
|
|
|
|
|
success = (Eina_Bool *)bufcmd;
|
|
|
|
bufcmd += sizeof(*success);
|
|
|
|
|
|
|
|
size_path = (int *)bufcmd;
|
|
|
|
bufcmd += sizeof(*size_path);
|
|
|
|
|
2010-03-01 16:34:40 -08:00
|
|
|
_write_safe(STDERR_FILENO, bufcmd, ed->slave.scmd);
|
2009-12-01 05:34:09 -08:00
|
|
|
|
2010-07-01 12:54:47 -07:00
|
|
|
if (*size_path)
|
|
|
|
{
|
|
|
|
thumb_path = bufcmd;
|
|
|
|
bufcmd += *size_path;
|
|
|
|
}
|
2009-12-01 05:34:09 -08:00
|
|
|
|
|
|
|
size_key = (int *)bufcmd;
|
|
|
|
bufcmd += sizeof(*size_key);
|
|
|
|
|
2010-07-01 12:54:47 -07:00
|
|
|
if (*size_key) thumb_key = bufcmd;
|
2009-12-01 05:34:09 -08:00
|
|
|
|
|
|
|
_generated_cb(ed, *success, thumb_path, thumb_key);
|
|
|
|
|
|
|
|
free(ed->slave.bufcmd);
|
|
|
|
ed->slave.bufcmd = NULL;
|
|
|
|
ed->slave.scmd = 0;
|
|
|
|
}
|
|
|
|
|
2009-06-04 14:21:43 -07:00
|
|
|
static int
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_slave_alloc_cmd(struct _Ethumbd *ed, int ssize, char *sdata)
|
|
|
|
{
|
|
|
|
int *scmd;
|
|
|
|
|
|
|
|
if (ed->slave.bufcmd)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
scmd = (int *)sdata;
|
|
|
|
if (ssize < sizeof(*scmd)) {
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not read size of command.");
|
2009-12-01 05:34:09 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ed->slave.bufcmd = malloc(*scmd);
|
|
|
|
ed->slave.scmd = *scmd;
|
|
|
|
ed->slave.pcmd = 0;
|
|
|
|
|
|
|
|
return sizeof(*scmd);
|
|
|
|
}
|
|
|
|
|
2010-07-01 12:42:12 -07:00
|
|
|
static Eina_Bool
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_slave_data_read_cb(void *data, int type, void *event)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
struct _Ethumbd *ed = data;
|
2009-12-01 05:34:09 -08:00
|
|
|
Ecore_Exe_Event_Data *ev = event;
|
|
|
|
int ssize;
|
|
|
|
char *sdata;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
if (ev->exe != ed->slave.exe)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("PARENT ERROR: slave != ev->exe");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
ssize = ev->size;
|
|
|
|
sdata = ev->data;
|
|
|
|
|
2010-03-01 16:34:40 -08:00
|
|
|
if (!_write_safe(STDERR_FILENO, sdata, ssize))
|
|
|
|
return 0;
|
2009-12-01 05:34:09 -08:00
|
|
|
|
|
|
|
while (ssize > 0)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2009-12-01 05:34:09 -08:00
|
|
|
if (!ed->slave.bufcmd)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
n = _ethumbd_slave_alloc_cmd(ed, ssize, sdata);
|
|
|
|
ssize -= n;
|
|
|
|
sdata += n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *bdata;
|
|
|
|
int nbytes;
|
|
|
|
bdata = ed->slave.bufcmd + ed->slave.pcmd;
|
|
|
|
nbytes = ed->slave.scmd - ed->slave.pcmd;
|
|
|
|
nbytes = ssize < nbytes ? ssize : nbytes;
|
|
|
|
memcpy(bdata, sdata, nbytes);
|
|
|
|
sdata += nbytes;
|
|
|
|
ssize -= nbytes;
|
|
|
|
ed->slave.pcmd += nbytes;
|
|
|
|
|
|
|
|
if (ed->slave.pcmd == ed->slave.scmd)
|
|
|
|
_ethumbd_slave_cmd_ready(ed);
|
|
|
|
}
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
return 1;
|
|
|
|
}
|
2009-06-04 14:21:43 -07:00
|
|
|
|
2010-07-01 12:42:12 -07:00
|
|
|
static Eina_Bool
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_slave_del_cb(void *data, int type, void *event)
|
|
|
|
{
|
|
|
|
struct _Ethumbd *ed = data;
|
|
|
|
Ecore_Exe_Event_Del *ev = event;
|
|
|
|
int i;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
if (ev->exe != ed->slave.exe)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (ev->exited)
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("slave exited with code: %d", ev->exit_code);
|
2009-12-01 05:34:09 -08:00
|
|
|
else if (ev->signalled)
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("slave exited by signal: %d", ev->exit_signal);
|
2009-12-01 05:34:09 -08:00
|
|
|
|
|
|
|
if (!ed->processing)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
i = ed->queue.current;
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("failed to generate thumbnail for: \"%s:%s\"",
|
2009-12-01 05:34:09 -08:00
|
|
|
ed->processing->file, ed->processing->key);
|
|
|
|
|
|
|
|
if (ed->queue.table[i].used)
|
|
|
|
_ethumb_dbus_generated_signal
|
|
|
|
(ed, &ed->processing->id, NULL, NULL, EINA_FALSE);
|
|
|
|
eina_stringshare_del(ed->processing->file);
|
|
|
|
eina_stringshare_del(ed->processing->key);
|
|
|
|
eina_stringshare_del(ed->processing->thumb);
|
|
|
|
eina_stringshare_del(ed->processing->thumb_key);
|
|
|
|
free(ed->processing);
|
|
|
|
ed->processing = NULL;
|
|
|
|
|
|
|
|
end:
|
|
|
|
ed->slave.exe = NULL;
|
|
|
|
if (ed->slave.bufcmd)
|
|
|
|
free(ed->slave.bufcmd);
|
|
|
|
|
|
|
|
return _ethumbd_slave_spawn(ed);
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(struct _Ethumbd *ed, int type, const void *data)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
const int *i_value;
|
|
|
|
const float *f_value;
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_write_safe(ed, &type, sizeof(type));
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ETHUMBD_FDO:
|
|
|
|
case ETHUMBD_FORMAT:
|
|
|
|
case ETHUMBD_ASPECT:
|
2009-07-09 12:16:02 -07:00
|
|
|
case ETHUMBD_QUALITY:
|
|
|
|
case ETHUMBD_COMPRESS:
|
2009-06-04 14:21:43 -07:00
|
|
|
case ETHUMBD_SIZE_W:
|
|
|
|
case ETHUMBD_SIZE_H:
|
|
|
|
case ETHUMBD_DOCUMENT_PAGE:
|
2009-07-13 12:38:17 -07:00
|
|
|
case ETHUMBD_VIDEO_NTIMES:
|
|
|
|
case ETHUMBD_VIDEO_FPS:
|
2009-06-04 14:21:43 -07:00
|
|
|
i_value = data;
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_write_safe(ed, i_value, sizeof(*i_value));
|
2009-06-04 14:21:43 -07:00
|
|
|
break;
|
|
|
|
case ETHUMBD_CROP_X:
|
|
|
|
case ETHUMBD_CROP_Y:
|
|
|
|
case ETHUMBD_VIDEO_TIME:
|
2009-07-13 12:38:17 -07:00
|
|
|
case ETHUMBD_VIDEO_START:
|
|
|
|
case ETHUMBD_VIDEO_INTERVAL:
|
2009-06-04 14:21:43 -07:00
|
|
|
f_value = data;
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_write_safe(ed, f_value, sizeof(*f_value));
|
2009-06-04 14:21:43 -07:00
|
|
|
break;
|
|
|
|
case ETHUMBD_DIRECTORY:
|
|
|
|
case ETHUMBD_CATEGORY:
|
|
|
|
case ETHUMBD_FRAME_FILE:
|
|
|
|
case ETHUMBD_FRAME_GROUP:
|
|
|
|
case ETHUMBD_FRAME_SWALLOW:
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_str_write(ed, data);
|
2009-06-04 14:21:43 -07:00
|
|
|
break;
|
|
|
|
case ETHUMBD_SETUP_FINISHED:
|
|
|
|
break;
|
|
|
|
default:
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("wrong ethumb setup parameter.");
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_process_setup(struct _Ethumbd *ed)
|
|
|
|
{
|
|
|
|
int op_id = ETHUMBD_OP_SETUP;
|
|
|
|
int index = ed->queue.current;
|
|
|
|
|
|
|
|
struct _Ethumb_Setup *setup = &ed->processing->setup;
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_write_safe(ed, &op_id, sizeof(op_id));
|
|
|
|
_ethumbd_write_safe(ed, &index, sizeof(index));
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
if (setup->flags.fdo)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_FDO, &setup->fdo);
|
2009-06-04 14:21:43 -07:00
|
|
|
if (setup->flags.size)
|
|
|
|
{
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_SIZE_W, &setup->tw);
|
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_SIZE_H, &setup->th);
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
if (setup->flags.format)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_FORMAT, &setup->format);
|
2009-06-04 14:21:43 -07:00
|
|
|
if (setup->flags.aspect)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_ASPECT, &setup->aspect);
|
2009-06-04 14:21:43 -07:00
|
|
|
if (setup->flags.crop)
|
|
|
|
{
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_CROP_X, &setup->cx);
|
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_CROP_Y, &setup->cy);
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
2009-07-09 12:16:02 -07:00
|
|
|
if (setup->flags.quality)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_QUALITY, &setup->quality);
|
2009-07-09 12:16:02 -07:00
|
|
|
if (setup->flags.compress)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_COMPRESS, &setup->compress);
|
2009-06-04 14:21:43 -07:00
|
|
|
if (setup->flags.directory)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_DIRECTORY, setup->directory);
|
2009-06-04 14:21:43 -07:00
|
|
|
if (setup->flags.category)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_CATEGORY, setup->category);
|
2009-06-04 14:21:43 -07:00
|
|
|
if (setup->flags.frame)
|
|
|
|
{
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_FRAME_FILE, setup->theme_file);
|
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_FRAME_GROUP, setup->group);
|
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_FRAME_SWALLOW, setup->swallow);
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
if (setup->flags.video_time)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_TIME, &setup->video_time);
|
2009-07-13 12:38:17 -07:00
|
|
|
if (setup->flags.video_start)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_START, &setup->video_start);
|
2009-07-13 12:38:17 -07:00
|
|
|
if (setup->flags.video_interval)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_INTERVAL,
|
2009-07-13 12:38:17 -07:00
|
|
|
&setup->video_interval);
|
|
|
|
if (setup->flags.video_ntimes)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_NTIMES, &setup->video_ntimes);
|
2009-07-13 12:38:17 -07:00
|
|
|
if (setup->flags.video_fps)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_VIDEO_FPS, &setup->video_fps);
|
2009-06-04 14:21:43 -07:00
|
|
|
if (setup->flags.document_page)
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_DOCUMENT_PAGE,
|
2009-06-04 14:21:43 -07:00
|
|
|
&setup->document_page);
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_pipe_write_setup(ed, ETHUMBD_SETUP_FINISHED, NULL);
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
|
|
|
|
if (setup->directory) eina_stringshare_del(setup->directory);
|
|
|
|
if (setup->category) eina_stringshare_del(setup->category);
|
|
|
|
if (setup->theme_file) eina_stringshare_del(setup->theme_file);
|
|
|
|
if (setup->group) eina_stringshare_del(setup->group);
|
|
|
|
if (setup->swallow) eina_stringshare_del(setup->swallow);
|
|
|
|
|
|
|
|
free(ed->processing);
|
|
|
|
ed->processing = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_process_file(struct _Ethumbd *ed)
|
|
|
|
{
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumbd_child_write_op_generate
|
|
|
|
(ed, ed->queue.current, ed->processing->file,
|
|
|
|
ed->processing->key, ed->processing->thumb, ed->processing->thumb_key);
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_get_next_on_queue(struct _Ethumb_Queue *queue)
|
|
|
|
{
|
|
|
|
int i, index;
|
|
|
|
struct _Ethumb_Object *eobject;
|
|
|
|
|
|
|
|
i = queue->last;
|
|
|
|
i++;
|
|
|
|
if (i >= queue->count)
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
index = queue->list[i];
|
|
|
|
eobject = &(queue->table[index]);
|
|
|
|
while (!eobject->nqueue)
|
|
|
|
{
|
|
|
|
i = (i + 1) % queue->count;
|
|
|
|
|
|
|
|
index = queue->list[i];
|
|
|
|
eobject = &(queue->table[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return queue->list[i];
|
|
|
|
}
|
|
|
|
|
2010-07-01 12:42:12 -07:00
|
|
|
static Eina_Bool
|
2009-06-04 14:21:43 -07:00
|
|
|
_process_queue_cb(void *data)
|
|
|
|
{
|
|
|
|
struct _Ethumb_Object *eobject;
|
|
|
|
int i;
|
|
|
|
struct _Ethumbd *ed = data;
|
|
|
|
struct _Ethumb_Queue *queue = &ed->queue;
|
|
|
|
struct _Ethumb_Request *request;
|
|
|
|
|
|
|
|
if (ed->processing)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!queue->nqueue)
|
|
|
|
{
|
|
|
|
ed->idler = NULL;
|
|
|
|
if (!queue->count)
|
|
|
|
_ethumbd_timeout_start(ed);
|
|
|
|
ed->idler = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = _get_next_on_queue(queue);
|
|
|
|
eobject = &(queue->table[i]);
|
|
|
|
|
|
|
|
request = eina_list_data_get(eobject->queue);
|
|
|
|
eobject->queue = eina_list_remove_list(eobject->queue, eobject->queue);
|
|
|
|
ed->queue.current = i;
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("processing file: \"%s:%s\"...", request->file,
|
2009-07-17 07:44:11 -07:00
|
|
|
request->key);
|
2009-06-04 14:21:43 -07:00
|
|
|
ed->processing = request;
|
|
|
|
|
|
|
|
if (request->id < 0)
|
|
|
|
_process_setup(ed);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_process_file(ed);
|
|
|
|
_ethumb_dbus_inc_min_id(eobject);
|
|
|
|
}
|
|
|
|
eobject->nqueue--;
|
|
|
|
queue->nqueue--;
|
|
|
|
|
|
|
|
queue->last = i;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_process_queue_start(struct _Ethumbd *ed)
|
|
|
|
{
|
|
|
|
if (!ed->idler)
|
|
|
|
ed->idler = ecore_idler_add(_process_queue_cb, ed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_process_queue_stop(struct _Ethumbd *ed)
|
|
|
|
{
|
|
|
|
if (ed->idler)
|
|
|
|
{
|
|
|
|
ecore_idler_del(ed->idler);
|
|
|
|
ed->idler = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_ethumb_table_append(struct _Ethumbd *ed)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char buf[1024];
|
|
|
|
struct _Ethumb_Queue *q = &ed->queue;
|
|
|
|
|
|
|
|
if (q->count == q->max_count)
|
|
|
|
{
|
|
|
|
int new_max = q->max_count + 5;
|
|
|
|
int start, size;
|
2010-03-01 16:34:40 -08:00
|
|
|
void *tmp;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
start = q->max_count;
|
|
|
|
size = new_max - q->max_count;
|
|
|
|
|
2010-03-01 16:34:40 -08:00
|
|
|
tmp = realloc(q->table, new_max * sizeof(struct _Ethumb_Object));
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
CRIT("could not realloc q->table to %zd bytes: %s",
|
|
|
|
new_max * sizeof(struct _Ethumb_Object), strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
q->table = tmp;
|
2009-06-04 14:21:43 -07:00
|
|
|
memset(&q->table[start], 0, size * sizeof(struct _Ethumb_Object));
|
|
|
|
|
2010-03-01 16:34:40 -08:00
|
|
|
tmp = realloc(q->list, new_max * sizeof(int));
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
CRIT("could not realloc q->list to %zd bytes: %s",
|
|
|
|
new_max * sizeof(int), strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
q->list = tmp;
|
|
|
|
|
2009-06-04 14:21:43 -07:00
|
|
|
q->max_count = new_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < q->max_count; i++)
|
|
|
|
{
|
|
|
|
if (!q->table[i].used)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%d", _ethumb_dbus_path, i);
|
|
|
|
q->table[i].used = 1;
|
|
|
|
q->table[i].path = eina_stringshare_add(buf);
|
|
|
|
q->table[i].max_id = -1;
|
|
|
|
q->table[i].min_id = -1;
|
|
|
|
q->list[q->count] = i;
|
|
|
|
q->count++;
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("new object: %s, index = %d, count = %d", buf, i, q->count);
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
_get_index_for_path(const char *path)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n;
|
|
|
|
n = sscanf(path, "/org/enlightenment/Ethumb/%d", &i);
|
|
|
|
if (!n)
|
|
|
|
return -1;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumb_table_del(struct _Ethumbd *ed, int i)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
Eina_List *l;
|
|
|
|
const Eina_List *il;
|
|
|
|
struct _Ethumb_Queue *q = &ed->queue;
|
|
|
|
struct _Ethumb_Object_Data *odata;
|
|
|
|
|
|
|
|
eina_stringshare_del(q->table[i].path);
|
|
|
|
|
|
|
|
l = q->table[i].queue;
|
|
|
|
while (l)
|
|
|
|
{
|
|
|
|
struct _Ethumb_Request *request = l->data;
|
|
|
|
eina_stringshare_del(request->file);
|
|
|
|
eina_stringshare_del(request->key);
|
|
|
|
eina_stringshare_del(request->thumb);
|
|
|
|
eina_stringshare_del(request->thumb_key);
|
|
|
|
free(request);
|
|
|
|
l = eina_list_remove_list(l, l);
|
|
|
|
}
|
|
|
|
q->nqueue -= q->table[i].nqueue;
|
|
|
|
|
|
|
|
il = e_dbus_object_interfaces_get(q->table[i].dbus_obj);
|
|
|
|
while (il)
|
|
|
|
{
|
|
|
|
e_dbus_object_interface_detach(q->table[i].dbus_obj, il->data);
|
|
|
|
il = e_dbus_object_interfaces_get(q->table[i].dbus_obj);
|
|
|
|
}
|
|
|
|
odata = e_dbus_object_data_get(q->table[i].dbus_obj);
|
|
|
|
free(odata);
|
|
|
|
e_dbus_object_free(q->table[i].dbus_obj);
|
|
|
|
|
|
|
|
memset(&(q->table[i]), 0, sizeof(struct _Ethumb_Object));
|
|
|
|
for (j = 0; j < q->count; j++)
|
|
|
|
{
|
|
|
|
if (q->list[j] == i)
|
|
|
|
q->list[j] = q->list[q->count - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
q->count--;
|
|
|
|
_ethumbd_child_write_op_del(ed, i);
|
|
|
|
if (!q->count && !ed->processing)
|
|
|
|
_ethumbd_timeout_start(ed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumb_table_clear(struct _Ethumbd *ed)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ed->queue.max_count; i++)
|
|
|
|
if (ed->queue.table[i].used)
|
|
|
|
_ethumb_table_del(ed, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_name_owner_changed_cb(void *data, DBusMessage *msg)
|
|
|
|
{
|
|
|
|
DBusError err;
|
|
|
|
struct _Ethumbd *ed = data;
|
|
|
|
struct _Ethumb_Queue *q = &ed->queue;
|
|
|
|
const char *name, *from, *to;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dbus_error_init(&err);
|
|
|
|
if (!dbus_message_get_args(msg, &err,
|
2009-07-17 07:44:11 -07:00
|
|
|
DBUS_TYPE_STRING, &name,
|
|
|
|
DBUS_TYPE_STRING, &from,
|
|
|
|
DBUS_TYPE_STRING, &to,
|
|
|
|
DBUS_TYPE_INVALID))
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not get NameOwnerChanged arguments: %s: %s",
|
2009-07-17 07:44:11 -07:00
|
|
|
err.name, err.message);
|
2009-06-04 14:21:43 -07:00
|
|
|
dbus_error_free(&err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("NameOwnerChanged: name = %s, from = %s, to = %s", name, from, to);
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
if (from[0] == '\0' || to[0] != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
from = eina_stringshare_add(from);
|
|
|
|
for (i = 0; i < q->max_count; i++)
|
|
|
|
{
|
|
|
|
if (q->table[i].used && q->table[i].client == from)
|
|
|
|
{
|
|
|
|
_ethumb_table_del(ed, i);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("deleting [%d] from queue table.", i);
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumb_dbus_add_name_owner_changed_cb(struct _Ethumbd *ed)
|
|
|
|
{
|
2009-07-17 07:44:11 -07:00
|
|
|
ed->name_owner_changed_handler = e_dbus_signal_handler_add
|
|
|
|
(ed->conn, fdo_bus_name, fdo_path, fdo_interface, "NameOwnerChanged",
|
2009-06-04 14:21:43 -07:00
|
|
|
_name_owner_changed_cb, ed);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBusMessage *
|
|
|
|
_ethumb_dbus_ethumb_new_cb(E_DBus_Object *object, DBusMessage *msg)
|
|
|
|
{
|
|
|
|
DBusMessage *reply;
|
|
|
|
DBusMessageIter iter;
|
|
|
|
E_DBus_Object *dbus_object;
|
|
|
|
struct _Ethumb_Object_Data *odata;
|
|
|
|
int i;
|
|
|
|
const char *return_path = "";
|
|
|
|
const char *client;
|
|
|
|
struct _Ethumbd *ed;
|
|
|
|
|
|
|
|
ed = e_dbus_object_data_get(object);
|
|
|
|
client = dbus_message_get_sender(msg);
|
|
|
|
if (!client)
|
|
|
|
goto end_new;
|
|
|
|
|
|
|
|
i = _ethumb_table_append(ed);
|
2010-03-01 16:34:40 -08:00
|
|
|
if (i < 0)
|
|
|
|
goto end_new;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
odata = calloc(1, sizeof(*odata));
|
|
|
|
odata->index = i;
|
|
|
|
odata->ed = ed;
|
|
|
|
|
|
|
|
ed->queue.table[i].client = eina_stringshare_add(client);
|
|
|
|
return_path = ed->queue.table[i].path;
|
|
|
|
|
|
|
|
dbus_object = e_dbus_object_add(ed->conn, return_path, odata);
|
|
|
|
if (!dbus_object)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not create dbus_object.");
|
2009-06-04 14:21:43 -07:00
|
|
|
free(odata);
|
|
|
|
return_path = "";
|
|
|
|
goto end_new;
|
|
|
|
}
|
|
|
|
|
|
|
|
e_dbus_object_interface_attach(dbus_object, ed->objects_iface);
|
|
|
|
ed->queue.table[i].dbus_obj = dbus_object;
|
|
|
|
|
|
|
|
_ethumbd_child_write_op_new(ed, i);
|
|
|
|
_ethumbd_timeout_stop(ed);
|
|
|
|
|
2009-07-17 07:44:11 -07:00
|
|
|
end_new:
|
2009-06-04 14:21:43 -07:00
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
|
|
|
|
&return_path);
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct _Ethumb_DBus_Method_Table _ethumb_dbus_methods[] =
|
2009-07-17 07:44:11 -07:00
|
|
|
{
|
|
|
|
{"new", "", "o", _ethumb_dbus_ethumb_new_cb},
|
|
|
|
{NULL, NULL, NULL, NULL}
|
|
|
|
};
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
_ethumb_dbus_get_bytearray(DBusMessageIter *iter)
|
|
|
|
{
|
|
|
|
int el_type;
|
|
|
|
int length;
|
|
|
|
DBusMessageIter riter;
|
|
|
|
const char *result;
|
|
|
|
|
|
|
|
el_type = dbus_message_iter_get_element_type(iter);
|
|
|
|
if (el_type != DBUS_TYPE_BYTE)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("not an byte array element.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(iter, &riter);
|
|
|
|
dbus_message_iter_get_fixed_array(&riter, &result, &length);
|
|
|
|
|
2009-10-19 07:04:43 -07:00
|
|
|
if ((length == 0) || (result[0] == '\0'))
|
2009-06-04 14:21:43 -07:00
|
|
|
return NULL;
|
|
|
|
else
|
2009-10-19 07:04:43 -07:00
|
|
|
return eina_stringshare_add_length(result, length);
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumb_dbus_append_bytearray(DBusMessageIter *iter, const char *string)
|
|
|
|
{
|
|
|
|
DBusMessageIter viter;
|
|
|
|
|
|
|
|
if (!string)
|
|
|
|
string = "";
|
|
|
|
|
|
|
|
dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "y", &viter);
|
2009-07-17 07:44:11 -07:00
|
|
|
dbus_message_iter_append_fixed_array
|
|
|
|
(&viter, DBUS_TYPE_BYTE, &string, strlen(string) + 1);
|
2009-06-04 14:21:43 -07:00
|
|
|
dbus_message_iter_close_container(iter, &viter);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBusMessage *
|
|
|
|
_ethumb_dbus_queue_add_cb(E_DBus_Object *object, DBusMessage *msg)
|
|
|
|
{
|
|
|
|
DBusMessage *reply;
|
|
|
|
DBusMessageIter iter;
|
|
|
|
const char *file, *key;
|
|
|
|
const char *thumb, *thumb_key;
|
|
|
|
struct _Ethumb_Object_Data *odata;
|
|
|
|
struct _Ethumb_Object *eobject;
|
|
|
|
struct _Ethumbd *ed;
|
|
|
|
struct _Ethumb_Request *request;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_int32_t id = -1;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
dbus_message_iter_init(msg, &iter);
|
|
|
|
dbus_message_iter_get_basic(&iter, &id);
|
|
|
|
dbus_message_iter_next(&iter);
|
|
|
|
file = _ethumb_dbus_get_bytearray(&iter);
|
|
|
|
dbus_message_iter_next(&iter);
|
|
|
|
key = _ethumb_dbus_get_bytearray(&iter);
|
|
|
|
dbus_message_iter_next(&iter);
|
|
|
|
thumb = _ethumb_dbus_get_bytearray(&iter);
|
|
|
|
dbus_message_iter_next(&iter);
|
|
|
|
thumb_key = _ethumb_dbus_get_bytearray(&iter);
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("no filename given.");
|
2009-06-04 14:21:43 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
odata = e_dbus_object_data_get(object);
|
|
|
|
if (!odata)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not get dbus_object data.");
|
2009-06-04 14:21:43 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ed = odata->ed;
|
|
|
|
eobject = &(ed->queue.table[odata->index]);
|
|
|
|
if (!_ethumb_dbus_check_id(eobject, id))
|
|
|
|
goto end;
|
|
|
|
request = calloc(1, sizeof(*request));
|
|
|
|
request->id = id;
|
|
|
|
request->file = file;
|
|
|
|
request->key = key;
|
|
|
|
request->thumb = thumb;
|
|
|
|
request->thumb_key = thumb_key;
|
|
|
|
eobject->queue = eina_list_append(eobject->queue, request);
|
|
|
|
eobject->nqueue++;
|
|
|
|
ed->queue.nqueue++;
|
|
|
|
_ethumb_dbus_inc_max_id(eobject, id);
|
|
|
|
|
|
|
|
_process_queue_start(ed);
|
|
|
|
|
2009-07-17 07:44:11 -07:00
|
|
|
end:
|
2009-06-04 14:21:43 -07:00
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &id);
|
2009-06-04 14:21:43 -07:00
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBusMessage *
|
|
|
|
_ethumb_dbus_queue_remove_cb(E_DBus_Object *object, DBusMessage *msg)
|
|
|
|
{
|
|
|
|
DBusMessage *reply;
|
|
|
|
DBusMessageIter iter;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_int32_t id;
|
2009-06-04 14:21:43 -07:00
|
|
|
struct _Ethumb_Object_Data *odata;
|
|
|
|
struct _Ethumb_Object *eobject;
|
|
|
|
struct _Ethumb_Request *request;
|
|
|
|
struct _Ethumbd *ed;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_bool_t r = 0;
|
2009-06-04 14:21:43 -07:00
|
|
|
Eina_List *l;
|
|
|
|
|
|
|
|
dbus_message_iter_init(msg, &iter);
|
|
|
|
dbus_message_iter_get_basic(&iter, &id);
|
|
|
|
|
|
|
|
odata = e_dbus_object_data_get(object);
|
|
|
|
if (!odata)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not get dbus_object data.");
|
2009-06-04 14:21:43 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ed = odata->ed;
|
|
|
|
eobject = &ed->queue.table[odata->index];
|
|
|
|
l = eobject->queue;
|
|
|
|
while (l)
|
|
|
|
{
|
|
|
|
request = l->data;
|
|
|
|
if (id == request->id)
|
|
|
|
break;
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l)
|
|
|
|
{
|
|
|
|
r = 1;
|
|
|
|
eina_stringshare_del(request->file);
|
|
|
|
eina_stringshare_del(request->key);
|
|
|
|
eina_stringshare_del(request->thumb);
|
|
|
|
eina_stringshare_del(request->thumb_key);
|
|
|
|
free(request);
|
|
|
|
eobject->queue = eina_list_remove_list(eobject->queue, l);
|
|
|
|
eobject->nqueue--;
|
|
|
|
ed->queue.nqueue--;
|
|
|
|
_ethumb_dbus_inc_min_id(eobject);
|
|
|
|
}
|
|
|
|
|
2009-07-17 07:44:11 -07:00
|
|
|
end:
|
2009-06-04 14:21:43 -07:00
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &r);
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBusMessage *
|
|
|
|
_ethumb_dbus_queue_clear_cb(E_DBus_Object *object, DBusMessage *msg)
|
|
|
|
{
|
|
|
|
DBusMessage *reply;
|
|
|
|
struct _Ethumb_Object_Data *odata;
|
|
|
|
struct _Ethumb_Object *eobject;
|
|
|
|
struct _Ethumbd *ed;
|
|
|
|
Eina_List *l;
|
|
|
|
|
|
|
|
odata = e_dbus_object_data_get(object);
|
|
|
|
if (!odata)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not get dbus_object data.");
|
2009-06-04 14:21:43 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ed = odata->ed;
|
|
|
|
eobject = &ed->queue.table[odata->index];
|
|
|
|
l = eobject->queue;
|
|
|
|
while (l)
|
|
|
|
{
|
|
|
|
struct _Ethumb_Request *request = l->data;
|
|
|
|
eina_stringshare_del(request->file);
|
|
|
|
eina_stringshare_del(request->key);
|
|
|
|
eina_stringshare_del(request->thumb);
|
|
|
|
eina_stringshare_del(request->thumb_key);
|
|
|
|
free(request);
|
|
|
|
l = eina_list_remove_list(l, l);
|
|
|
|
}
|
|
|
|
ed->queue.nqueue -= eobject->nqueue;
|
|
|
|
eobject->nqueue = 0;
|
|
|
|
|
2009-07-17 07:44:11 -07:00
|
|
|
end:
|
2009-06-04 14:21:43 -07:00
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBusMessage *
|
|
|
|
_ethumb_dbus_delete_cb(E_DBus_Object *object, DBusMessage *msg)
|
|
|
|
{
|
|
|
|
DBusMessage *reply;
|
|
|
|
DBusMessageIter iter;
|
|
|
|
struct _Ethumb_Object_Data *odata;
|
|
|
|
struct _Ethumbd *ed;
|
|
|
|
|
|
|
|
dbus_message_iter_init(msg, &iter);
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
|
|
|
|
odata = e_dbus_object_data_get(object);
|
|
|
|
if (!odata)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not get dbus_object data for del_cb.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
ed = odata->ed;
|
|
|
|
_ethumb_table_del(ed, odata->index);
|
|
|
|
free(odata);
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_fdo_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request __UNUSED__)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
int type;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_int32_t fdo;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
2009-07-09 12:26:16 -07:00
|
|
|
if (type != DBUS_TYPE_INT32)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for fdo_set.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &fdo);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting fdo to: %d", fdo);
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_size_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
DBusMessageIter oiter;
|
|
|
|
int type;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_int32_t w, h;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
|
|
|
if (type != DBUS_TYPE_STRUCT)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for size_set.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(iter, &oiter);
|
|
|
|
dbus_message_iter_get_basic(&oiter, &w);
|
|
|
|
dbus_message_iter_next(&oiter);
|
|
|
|
dbus_message_iter_get_basic(&oiter, &h);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting size to: %dx%d", w, h);
|
2009-06-04 14:21:43 -07:00
|
|
|
request->setup.flags.size = 1;
|
|
|
|
request->setup.tw = w;
|
|
|
|
request->setup.th = h;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_format_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
int type;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_int32_t format;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
2009-07-09 12:26:16 -07:00
|
|
|
if (type != DBUS_TYPE_INT32)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for format_set.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &format);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting format to: %d", format);
|
2009-06-04 14:21:43 -07:00
|
|
|
request->setup.flags.format = 1;
|
|
|
|
request->setup.format = format;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_aspect_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
int type;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_int32_t aspect;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
2009-07-09 12:26:16 -07:00
|
|
|
if (type != DBUS_TYPE_INT32)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for aspect_set.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &aspect);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting aspect to: %d", aspect);
|
2009-06-04 14:21:43 -07:00
|
|
|
request->setup.flags.aspect = 1;
|
|
|
|
request->setup.aspect = aspect;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_crop_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
DBusMessageIter oiter;
|
|
|
|
int type;
|
2009-07-09 12:26:16 -07:00
|
|
|
double x, y;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
|
|
|
if (type != DBUS_TYPE_STRUCT)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for crop_set.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(iter, &oiter);
|
|
|
|
dbus_message_iter_get_basic(&oiter, &x);
|
|
|
|
dbus_message_iter_next(&oiter);
|
|
|
|
dbus_message_iter_get_basic(&oiter, &y);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting crop to: %3.2f,%3.2f", x, y);
|
2009-06-04 14:21:43 -07:00
|
|
|
request->setup.flags.crop = 1;
|
|
|
|
request->setup.cx = x;
|
|
|
|
request->setup.cy = y;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-07-09 12:16:02 -07:00
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_quality_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-07-09 12:16:02 -07:00
|
|
|
{
|
|
|
|
int type;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_int32_t quality;
|
2009-07-09 12:16:02 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
2009-07-09 12:26:16 -07:00
|
|
|
if (type != DBUS_TYPE_INT32)
|
2009-07-09 12:16:02 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for quality_set.");
|
2009-07-09 12:16:02 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &quality);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting quality to: %d", quality);
|
2009-07-09 12:16:02 -07:00
|
|
|
request->setup.flags.quality = 1;
|
|
|
|
request->setup.quality = quality;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_compress_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-07-09 12:16:02 -07:00
|
|
|
{
|
|
|
|
int type;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_int32_t compress;
|
2009-07-09 12:16:02 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
2009-07-09 12:26:16 -07:00
|
|
|
if (type != DBUS_TYPE_INT32)
|
2009-07-09 12:16:02 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for compress_set.");
|
2009-07-09 12:16:02 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &compress);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting compress to: %d", compress);
|
2009-07-09 12:16:02 -07:00
|
|
|
request->setup.flags.compress = 1;
|
|
|
|
request->setup.compress = compress;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-04 14:21:43 -07:00
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_frame_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
DBusMessageIter oiter;
|
|
|
|
int type;
|
|
|
|
const char *file, *group, *swallow;
|
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
|
|
|
if (type != DBUS_TYPE_STRUCT)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for frame_set.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(iter, &oiter);
|
|
|
|
file = _ethumb_dbus_get_bytearray(&oiter);
|
|
|
|
dbus_message_iter_next(&oiter);
|
|
|
|
group = _ethumb_dbus_get_bytearray(&oiter);
|
|
|
|
dbus_message_iter_next(&oiter);
|
|
|
|
swallow = _ethumb_dbus_get_bytearray(&oiter);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting frame to \"%s:%s:%s\"", file, group, swallow);
|
2009-06-04 14:21:43 -07:00
|
|
|
request->setup.flags.frame = 1;
|
|
|
|
request->setup.theme_file = eina_stringshare_add(file);
|
|
|
|
request->setup.group = eina_stringshare_add(group);
|
|
|
|
request->setup.swallow = eina_stringshare_add(swallow);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_directory_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
const char *directory;
|
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
|
|
|
if (type != DBUS_TYPE_ARRAY)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for dir_path_set.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
directory = _ethumb_dbus_get_bytearray(iter);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting directory to: %s", directory);
|
2009-06-04 14:21:43 -07:00
|
|
|
request->setup.flags.directory = 1;
|
|
|
|
request->setup.directory = eina_stringshare_add(directory);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_category_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
const char *category;
|
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
|
|
|
if (type != DBUS_TYPE_ARRAY)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for category.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
category = _ethumb_dbus_get_bytearray(iter);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting category to: %s", category);
|
2009-06-04 14:21:43 -07:00
|
|
|
request->setup.flags.category = 1;
|
|
|
|
request->setup.category = eina_stringshare_add(category);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_video_time_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
double video_time;
|
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
|
|
|
if (type != DBUS_TYPE_DOUBLE)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for video_time_set.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &video_time);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting video_time to: %3.2f", video_time);
|
2009-06-04 14:21:43 -07:00
|
|
|
request->setup.flags.video_time = 1;
|
|
|
|
request->setup.video_time = video_time;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-07-13 12:38:17 -07:00
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_video_start_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-07-13 12:38:17 -07:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
double video_start;
|
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
|
|
|
if (type != DBUS_TYPE_DOUBLE)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for video_start_set.");
|
2009-07-13 12:38:17 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &video_start);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting video_start to: %3.2f", video_start);
|
2009-07-13 12:38:17 -07:00
|
|
|
request->setup.flags.video_start = 1;
|
|
|
|
request->setup.video_start = video_start;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_video_interval_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-07-13 12:38:17 -07:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
double video_interval;
|
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
|
|
|
if (type != DBUS_TYPE_DOUBLE)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for video_interval_set.");
|
2009-07-13 12:38:17 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &video_interval);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting video_interval to: %3.2f", video_interval);
|
2009-07-13 12:38:17 -07:00
|
|
|
request->setup.flags.video_interval = 1;
|
|
|
|
request->setup.video_interval = video_interval;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_video_ntimes_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-07-13 12:38:17 -07:00
|
|
|
{
|
|
|
|
int type;
|
2009-09-17 07:05:04 -07:00
|
|
|
unsigned int video_ntimes;
|
2009-07-13 12:38:17 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
2009-09-17 07:05:04 -07:00
|
|
|
if (type != DBUS_TYPE_UINT32)
|
2009-07-13 12:38:17 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for video_ntimes_set.");
|
2009-07-13 12:38:17 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &video_ntimes);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting video_ntimes to: %3.2d", video_ntimes);
|
2009-07-13 12:38:17 -07:00
|
|
|
request->setup.flags.video_ntimes = 1;
|
|
|
|
request->setup.video_ntimes = video_ntimes;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_video_fps_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-07-13 12:38:17 -07:00
|
|
|
{
|
|
|
|
int type;
|
2009-09-17 07:05:04 -07:00
|
|
|
unsigned int video_fps;
|
2009-07-13 12:38:17 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
2009-09-17 07:05:04 -07:00
|
|
|
if (type != DBUS_TYPE_UINT32)
|
2009-07-13 12:38:17 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for video_fps_set.");
|
2009-07-13 12:38:17 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &video_fps);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting video_fps to: %3.2d", video_fps);
|
2009-07-13 12:38:17 -07:00
|
|
|
request->setup.flags.video_fps = 1;
|
|
|
|
request->setup.video_fps = video_fps;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-04 14:21:43 -07:00
|
|
|
static int
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_document_page_set(struct _Ethumb_Object *eobject __UNUSED__, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
int type;
|
2009-09-17 07:05:04 -07:00
|
|
|
unsigned int document_page;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
type = dbus_message_iter_get_arg_type(iter);
|
2009-09-17 07:05:04 -07:00
|
|
|
if (type != DBUS_TYPE_UINT32)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("invalid param for document_page_set.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, &document_page);
|
2010-03-01 16:39:37 -08:00
|
|
|
DBG("setting document_page to: %d", document_page);
|
2009-06-04 14:21:43 -07:00
|
|
|
request->setup.flags.document_page = 1;
|
|
|
|
request->setup.document_page = document_page;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const char *option;
|
|
|
|
int (*setup_func)(struct _Ethumb_Object *eobject, DBusMessageIter *iter, struct _Ethumb_Request *request);
|
|
|
|
} _option_cbs[] = {
|
2009-07-17 07:44:11 -07:00
|
|
|
{"fdo", _ethumb_dbus_fdo_set},
|
|
|
|
{"size", _ethumb_dbus_size_set},
|
|
|
|
{"format", _ethumb_dbus_format_set},
|
|
|
|
{"aspect", _ethumb_dbus_aspect_set},
|
|
|
|
{"crop", _ethumb_dbus_crop_set},
|
|
|
|
{"quality", _ethumb_dbus_quality_set},
|
|
|
|
{"compress", _ethumb_dbus_compress_set},
|
|
|
|
{"frame", _ethumb_dbus_frame_set},
|
|
|
|
{"directory", _ethumb_dbus_directory_set},
|
|
|
|
{"category", _ethumb_dbus_category_set},
|
|
|
|
{"video_time", _ethumb_dbus_video_time_set},
|
|
|
|
{"video_start", _ethumb_dbus_video_start_set},
|
|
|
|
{"video_interval", _ethumb_dbus_video_interval_set},
|
|
|
|
{"video_ntimes", _ethumb_dbus_video_ntimes_set},
|
|
|
|
{"video_fps", _ethumb_dbus_video_fps_set},
|
|
|
|
{"document_page", _ethumb_dbus_document_page_set},
|
|
|
|
{NULL, NULL}
|
2009-06-04 14:21:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
_ethumb_dbus_ethumb_setup_parse_element(struct _Ethumb_Object *eobject, DBusMessageIter *iter, struct _Ethumb_Request *request)
|
|
|
|
{
|
|
|
|
DBusMessageIter viter, diter;
|
|
|
|
const char *option;
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(iter, &diter);
|
|
|
|
dbus_message_iter_get_basic(&diter, &option);
|
|
|
|
dbus_message_iter_next(&diter);
|
|
|
|
|
|
|
|
r = 0;
|
|
|
|
for (i = 0; _option_cbs[i].option; i++)
|
|
|
|
if (!strcmp(_option_cbs[i].option, option))
|
|
|
|
{
|
|
|
|
r = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!r)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("ethumb_setup invalid option: %s", option);
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(&diter, &viter);
|
|
|
|
return _option_cbs[i].setup_func(eobject, &viter, request);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBusMessage *
|
|
|
|
_ethumb_dbus_ethumb_setup_cb(E_DBus_Object *object, DBusMessage *msg)
|
|
|
|
{
|
|
|
|
DBusMessage *reply;
|
|
|
|
DBusMessageIter iter, aiter;
|
|
|
|
struct _Ethumb_Object_Data *odata;
|
|
|
|
struct _Ethumbd *ed;
|
|
|
|
struct _Ethumb_Object *eobject;
|
|
|
|
struct _Ethumb_Request *request;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_bool_t r = 0;
|
2009-06-04 14:21:43 -07:00
|
|
|
int atype;
|
|
|
|
|
|
|
|
dbus_message_iter_init(msg, &iter);
|
|
|
|
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("wrong parameters.");
|
2009-06-04 14:21:43 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
odata = e_dbus_object_data_get(object);
|
|
|
|
if (!odata)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not get dbus_object data for setup_cb.");
|
2009-06-04 14:21:43 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ed = odata->ed;
|
|
|
|
eobject = &ed->queue.table[odata->index];
|
|
|
|
|
|
|
|
request = calloc(1, sizeof(*request));
|
|
|
|
request->id = -1;
|
|
|
|
dbus_message_iter_recurse(&iter, &aiter);
|
|
|
|
atype = dbus_message_iter_get_arg_type(&aiter);
|
|
|
|
|
|
|
|
r = 1;
|
|
|
|
while (atype != DBUS_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
if (!_ethumb_dbus_ethumb_setup_parse_element(eobject, &aiter, request))
|
|
|
|
r = 0;
|
|
|
|
dbus_message_iter_next(&aiter);
|
|
|
|
atype = dbus_message_iter_get_arg_type(&aiter);
|
|
|
|
}
|
|
|
|
|
|
|
|
eobject->queue = eina_list_append(eobject->queue, request);
|
|
|
|
eobject->nqueue++;
|
|
|
|
ed->queue.nqueue++;
|
|
|
|
|
2009-07-17 07:44:11 -07:00
|
|
|
end:
|
2009-06-04 14:21:43 -07:00
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &r);
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-07-09 12:26:16 -07:00
|
|
|
_ethumb_dbus_generated_signal(struct _Ethumbd *ed, int *id, const char *thumb_path, const char *thumb_key, Eina_Bool success)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
DBusMessage *signal;
|
|
|
|
int current;
|
|
|
|
const char *opath;
|
|
|
|
DBusMessageIter iter;
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_bool_t value;
|
|
|
|
dbus_int32_t id32;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
value = success;
|
2009-07-09 12:26:16 -07:00
|
|
|
id32 = *id;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
current = ed->queue.current;
|
|
|
|
opath = ed->queue.table[current].path;
|
2009-07-17 07:44:11 -07:00
|
|
|
signal = dbus_message_new_signal
|
|
|
|
(opath, _ethumb_dbus_objects_interface, "generated");
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
dbus_message_iter_init_append(signal, &iter);
|
2009-07-09 12:26:16 -07:00
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &id32);
|
2009-06-04 14:21:43 -07:00
|
|
|
_ethumb_dbus_append_bytearray(&iter, thumb_path);
|
|
|
|
_ethumb_dbus_append_bytearray(&iter, thumb_key);
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &value);
|
|
|
|
|
|
|
|
e_dbus_message_send(ed->conn, signal, NULL, -1, NULL);
|
|
|
|
dbus_message_unref(signal);
|
|
|
|
}
|
|
|
|
|
2009-07-17 07:44:11 -07:00
|
|
|
static struct _Ethumb_DBus_Method_Table _ethumb_dbus_objects_methods[] = {
|
|
|
|
{"queue_add", "iayayayay", "i", _ethumb_dbus_queue_add_cb},
|
|
|
|
{"queue_remove", "i", "b", _ethumb_dbus_queue_remove_cb},
|
|
|
|
{"clear_queue", "", "", _ethumb_dbus_queue_clear_cb},
|
|
|
|
{"ethumb_setup", "a{sv}", "b", _ethumb_dbus_ethumb_setup_cb},
|
|
|
|
{"delete", "", "", _ethumb_dbus_delete_cb},
|
|
|
|
{NULL, NULL, NULL, NULL}
|
2009-06-04 14:21:43 -07:00
|
|
|
};
|
|
|
|
|
2009-07-17 07:44:11 -07:00
|
|
|
static struct _Ethumb_DBus_Signal_Table _ethumb_dbus_objects_signals[] = {
|
2009-10-19 07:05:54 -07:00
|
|
|
{"generated", "iayayb"},
|
2009-07-17 07:44:11 -07:00
|
|
|
{NULL, NULL}
|
2009-06-04 14:21:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
_ethumb_dbus_interface_elements_add(E_DBus_Interface *iface, struct _Ethumb_DBus_Method_Table *mtable, struct _Ethumb_DBus_Signal_Table *stable)
|
|
|
|
{
|
2009-07-17 07:44:11 -07:00
|
|
|
int i = -1;
|
|
|
|
while (mtable && mtable[++i].name != NULL)
|
|
|
|
if (!e_dbus_interface_method_add(iface,
|
|
|
|
mtable[i].name,
|
|
|
|
mtable[i].signature,
|
|
|
|
mtable[i].reply,
|
|
|
|
mtable[i].function))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
i = -1;
|
|
|
|
while (stable && stable[++i].name != NULL)
|
|
|
|
if (!e_dbus_interface_signal_add(iface,
|
|
|
|
stable[i].name,
|
|
|
|
stable[i].signature))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-07-17 07:44:11 -07:00
|
|
|
_ethumb_dbus_request_name_cb(void *data, DBusMessage *msg __UNUSED__, DBusError *err)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
|
|
|
E_DBus_Object *dbus_object;
|
|
|
|
struct _Ethumbd *ed = data;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (dbus_error_is_set(err))
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("request name error: %s", err->message);
|
2009-06-04 14:21:43 -07:00
|
|
|
dbus_error_free(err);
|
|
|
|
e_dbus_connection_close(ed->conn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_object = e_dbus_object_add(ed->conn, _ethumb_dbus_path, ed);
|
|
|
|
if (!dbus_object)
|
|
|
|
return;
|
|
|
|
ed->dbus_obj = dbus_object;
|
|
|
|
ed->eiface = e_dbus_interface_new(_ethumb_dbus_interface);
|
|
|
|
if (!ed->eiface)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not create interface.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
r = _ethumb_dbus_interface_elements_add(ed->eiface,
|
|
|
|
_ethumb_dbus_methods, NULL);
|
|
|
|
if (!r)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not add methods to the interface.");
|
2009-06-04 14:21:43 -07:00
|
|
|
e_dbus_interface_unref(ed->eiface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e_dbus_object_interface_attach(dbus_object, ed->eiface);
|
|
|
|
|
|
|
|
ed->objects_iface = e_dbus_interface_new(_ethumb_dbus_objects_interface);
|
|
|
|
if (!ed->objects_iface)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not create interface.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = _ethumb_dbus_interface_elements_add(ed->objects_iface,
|
|
|
|
_ethumb_dbus_objects_methods,
|
|
|
|
_ethumb_dbus_objects_signals);
|
|
|
|
if (!r)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("ERROR: could not setup objects interface methods.");
|
2009-06-04 14:21:43 -07:00
|
|
|
e_dbus_interface_unref(ed->objects_iface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ethumb_dbus_add_name_owner_changed_cb(ed);
|
|
|
|
|
|
|
|
_ethumbd_timeout_start(ed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_ethumb_dbus_setup(struct _Ethumbd *ed)
|
|
|
|
{
|
2009-07-17 07:44:11 -07:00
|
|
|
e_dbus_request_name
|
|
|
|
(ed->conn, _ethumb_dbus_bus_name, 0, _ethumb_dbus_request_name_cb, ed);
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ethumb_dbus_finish(struct _Ethumbd *ed)
|
|
|
|
{
|
|
|
|
_process_queue_stop(ed);
|
|
|
|
_ethumb_table_clear(ed);
|
|
|
|
e_dbus_signal_handler_del(ed->conn, ed->name_owner_changed_handler);
|
|
|
|
e_dbus_interface_unref(ed->objects_iface);
|
|
|
|
e_dbus_interface_unref(ed->eiface);
|
|
|
|
e_dbus_object_free(ed->dbus_obj);
|
|
|
|
free(ed->queue.table);
|
|
|
|
free(ed->queue.list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-12-01 05:34:09 -08:00
|
|
|
_ethumbd_slave_spawn(struct _Ethumbd *ed)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2009-12-01 05:34:09 -08:00
|
|
|
ed->slave.data_cb = ecore_event_handler_add(
|
|
|
|
ECORE_EXE_EVENT_DATA, _ethumbd_slave_data_read_cb, ed);
|
|
|
|
ed->slave.del_cb = ecore_event_handler_add(
|
|
|
|
ECORE_EXE_EVENT_DEL, _ethumbd_slave_del_cb, ed);
|
2009-06-04 14:21:43 -07:00
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
ed->slave.bufcmd = NULL;
|
|
|
|
ed->slave.scmd = 0;
|
2009-06-04 14:21:43 -07:00
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
ed->slave.exe = ecore_exe_pipe_run(
|
|
|
|
ETHUMB_LIBEXEC_DIR"/ethumbd_slave",
|
|
|
|
ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE, ed);
|
|
|
|
if (!ed->slave.exe)
|
2009-06-04 14:21:43 -07:00
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not create slave.");
|
2009-06-04 14:21:43 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
return 1;
|
2009-06-04 14:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
Eina_Bool quit_option = 0;
|
|
|
|
int exit_value = 0;
|
|
|
|
int arg_index;
|
2009-07-17 07:44:11 -07:00
|
|
|
struct _Ethumbd ed;
|
2009-06-04 14:21:43 -07:00
|
|
|
int child;
|
|
|
|
double timeout = -1;
|
|
|
|
|
2009-07-17 07:44:11 -07:00
|
|
|
memset(&ed, 0, sizeof(ed));
|
2009-06-04 14:21:43 -07:00
|
|
|
ecore_init();
|
2009-09-06 15:23:04 -07:00
|
|
|
eina_init();
|
2009-06-04 14:21:43 -07:00
|
|
|
|
|
|
|
ethumb_init();
|
|
|
|
|
2010-07-01 12:48:54 -07:00
|
|
|
if (_log_domain < 0)
|
|
|
|
{
|
|
|
|
_log_domain = eina_log_domain_register("ethumbd", NULL);
|
|
|
|
if (_log_domain < 0)
|
|
|
|
{
|
|
|
|
EINA_LOG_CRIT("could not register log domain 'ethumbd'");
|
|
|
|
exit_value = -7;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-01 05:34:09 -08:00
|
|
|
child = _ethumbd_slave_spawn(&ed);
|
2009-06-04 14:21:43 -07:00
|
|
|
if (!child)
|
|
|
|
{
|
|
|
|
exit_value = -6;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child == 2)
|
|
|
|
{
|
|
|
|
exit_value = 0;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!e_dbus_init())
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not init e_dbus.");
|
2009-06-04 14:21:43 -07:00
|
|
|
exit_value = -1;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ecore_Getopt_Value values[] = {
|
2009-07-17 07:44:11 -07:00
|
|
|
ECORE_GETOPT_VALUE_DOUBLE(timeout),
|
|
|
|
ECORE_GETOPT_VALUE_BOOL(quit_option),
|
|
|
|
ECORE_GETOPT_VALUE_BOOL(quit_option),
|
|
|
|
ECORE_GETOPT_VALUE_BOOL(quit_option),
|
|
|
|
ECORE_GETOPT_VALUE_BOOL(quit_option),
|
|
|
|
ECORE_GETOPT_VALUE_NONE
|
2009-06-04 14:21:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
arg_index = ecore_getopt_parse(&optdesc, values, argc, argv);
|
|
|
|
if (arg_index < 0)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("Could not parse arguments.");
|
2009-06-04 14:21:43 -07:00
|
|
|
exit_value = -2;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quit_option)
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
ed.conn = e_dbus_bus_get(DBUS_BUS_SESSION);
|
|
|
|
if (!ed.conn)
|
|
|
|
{
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not connect to session bus.");
|
2009-06-04 14:21:43 -07:00
|
|
|
exit_value = -3;
|
|
|
|
goto finish_edbus;
|
|
|
|
}
|
|
|
|
|
|
|
|
ed.timeout = timeout;
|
|
|
|
|
|
|
|
if (!_ethumb_dbus_setup(&ed))
|
|
|
|
{
|
|
|
|
e_dbus_connection_close(ed.conn);
|
2010-03-01 16:39:37 -08:00
|
|
|
ERR("could not setup dbus connection.");
|
2009-06-04 14:21:43 -07:00
|
|
|
exit_value = -5;
|
|
|
|
goto finish_edbus;
|
|
|
|
}
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
_ethumb_dbus_finish(&ed);
|
|
|
|
|
2009-07-17 07:44:11 -07:00
|
|
|
finish_edbus:
|
2010-07-01 12:48:54 -07:00
|
|
|
if (_log_domain >= 0)
|
|
|
|
{
|
|
|
|
eina_log_domain_unregister(_log_domain);
|
|
|
|
_log_domain = -1;
|
|
|
|
}
|
|
|
|
|
2009-06-04 14:21:43 -07:00
|
|
|
e_dbus_shutdown();
|
2009-07-17 07:44:11 -07:00
|
|
|
finish:
|
2009-12-01 05:34:09 -08:00
|
|
|
if (ed.slave.exe)
|
|
|
|
ecore_exe_quit(ed.slave.exe);
|
2009-06-04 14:21:43 -07:00
|
|
|
ethumb_shutdown();
|
2009-09-06 15:23:04 -07:00
|
|
|
eina_init();
|
2009-06-04 14:21:43 -07:00
|
|
|
ecore_shutdown();
|
|
|
|
return exit_value;
|
|
|
|
}
|