2011-08-24 07:06:04 -07:00
|
|
|
#define _GNU_SOURCE 1
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dlfcn.h>
|
2012-03-12 09:36:15 -07:00
|
|
|
#include <execinfo.h>
|
2012-05-14 07:37:59 -07:00
|
|
|
#include <sys/socket.h>
|
2011-08-24 07:06:04 -07:00
|
|
|
|
|
|
|
#include <Eina.h>
|
|
|
|
#include <Ecore.h>
|
2012-05-14 07:38:31 -07:00
|
|
|
#include <Ecore_Ipc.h>
|
2011-08-24 07:06:04 -07:00
|
|
|
#include <Edje.h>
|
|
|
|
#include <Evas.h>
|
|
|
|
#include <Elementary.h>
|
|
|
|
|
2012-05-14 07:37:49 -07:00
|
|
|
#include "helper.h"
|
2011-08-25 04:12:09 -07:00
|
|
|
#include "libclouseau.h"
|
2012-05-14 07:38:21 -07:00
|
|
|
#include "eet_dump.h"
|
2011-08-25 04:12:09 -07:00
|
|
|
|
2012-05-14 07:37:49 -07:00
|
|
|
static Eina_Bool _lib_init = EINA_FALSE;
|
2012-05-14 07:37:59 -07:00
|
|
|
|
2011-08-24 07:06:04 -07:00
|
|
|
static void
|
2012-05-14 07:37:59 -07:00
|
|
|
libclouseau_item_add(Evas_Object *o, Tree_Item *parent)
|
2011-08-24 07:06:04 -07:00
|
|
|
{
|
|
|
|
Eina_List *children, *tmp;
|
|
|
|
Evas_Object *child;
|
|
|
|
Tree_Item *treeit;
|
2011-08-25 07:54:22 -07:00
|
|
|
char buf[1024];
|
2011-08-24 07:06:04 -07:00
|
|
|
|
|
|
|
treeit = calloc(1, sizeof(*treeit));
|
2011-08-25 07:54:22 -07:00
|
|
|
treeit->ptr = o;
|
2011-08-25 07:54:30 -07:00
|
|
|
treeit->is_obj = EINA_TRUE;
|
2012-05-06 07:41:25 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s", evas_object_type_get(o));
|
|
|
|
|
2011-08-25 07:54:22 -07:00
|
|
|
treeit->name = eina_stringshare_add(buf);
|
|
|
|
treeit->is_clipper = !!evas_object_clipees_get(o);
|
|
|
|
treeit->is_visible = evas_object_visible_get(o);
|
2012-05-14 07:39:23 -07:00
|
|
|
treeit->info = obj_information_get(treeit);
|
2011-08-25 07:54:22 -07:00
|
|
|
|
2011-08-24 07:06:04 -07:00
|
|
|
parent->children = eina_list_append(parent->children, treeit);
|
|
|
|
|
|
|
|
children = evas_object_smart_members_get(o);
|
|
|
|
EINA_LIST_FOREACH(children, tmp, child){
|
2012-05-14 07:37:59 -07:00
|
|
|
libclouseau_item_add(child, treeit);
|
2011-08-24 07:06:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-14 07:39:23 -07:00
|
|
|
static Eina_List *
|
2012-05-14 07:37:59 -07:00
|
|
|
_load_list(void)
|
2011-08-24 07:06:04 -07:00
|
|
|
{
|
2012-05-14 07:39:23 -07:00
|
|
|
Eina_List *tree = NULL;
|
2011-08-24 07:32:15 -07:00
|
|
|
Eina_List *ees, *eeitr;
|
2012-05-14 07:37:59 -07:00
|
|
|
Ecore_Evas *ee;
|
2011-08-24 07:06:04 -07:00
|
|
|
|
|
|
|
|
|
|
|
ees = ecore_evas_ecore_evas_list_get();
|
|
|
|
|
2011-08-24 07:32:15 -07:00
|
|
|
EINA_LIST_FOREACH(ees, eeitr, ee)
|
2011-08-24 07:06:04 -07:00
|
|
|
{
|
2011-08-24 07:32:15 -07:00
|
|
|
Eina_List *objs, *objitr;
|
|
|
|
Evas_Object *obj;
|
2011-08-24 07:06:04 -07:00
|
|
|
Tree_Item *treeit;
|
|
|
|
|
|
|
|
Evas *e;
|
|
|
|
int w, h;
|
2011-08-24 07:32:15 -07:00
|
|
|
|
2011-08-24 07:06:04 -07:00
|
|
|
e = ecore_evas_get(ee);
|
|
|
|
evas_output_size_get(e, &w, &h);
|
|
|
|
|
|
|
|
treeit = calloc(1, sizeof(*treeit));
|
2011-08-25 07:54:22 -07:00
|
|
|
treeit->name = eina_stringshare_add(ecore_evas_title_get(ee));
|
|
|
|
treeit->ptr = ee;
|
2011-08-24 07:06:04 -07:00
|
|
|
|
|
|
|
tree = eina_list_append(tree, treeit);
|
|
|
|
|
2011-08-24 07:32:15 -07:00
|
|
|
objs = evas_objects_in_rectangle_get(e, SHRT_MIN, SHRT_MIN,
|
2011-08-24 07:06:04 -07:00
|
|
|
USHRT_MAX, USHRT_MAX, EINA_TRUE, EINA_TRUE);
|
2011-08-24 07:32:15 -07:00
|
|
|
EINA_LIST_FOREACH(objs, objitr, obj)
|
|
|
|
{
|
2012-05-14 07:37:59 -07:00
|
|
|
libclouseau_item_add(obj, treeit);
|
2011-08-24 07:32:15 -07:00
|
|
|
}
|
2012-05-14 07:37:59 -07:00
|
|
|
}
|
2012-05-14 07:39:23 -07:00
|
|
|
|
|
|
|
return tree; /* User has to call item_tree_free() */
|
2011-08-24 07:06:04 -07:00
|
|
|
}
|
|
|
|
|
2012-05-14 07:38:02 -07:00
|
|
|
Eina_Bool
|
2012-05-14 07:38:31 -07:00
|
|
|
_add(void *data __UNUSED__, int type __UNUSED__, Ecore_Ipc_Event_Server_Add *ev)
|
2012-05-14 07:38:02 -07:00
|
|
|
{
|
2012-05-14 07:38:09 -07:00
|
|
|
void *p;
|
2012-05-14 07:38:27 -07:00
|
|
|
char *msg="hello! - sent from the APP";
|
2012-05-14 07:38:35 -07:00
|
|
|
int size = 0;
|
2012-05-14 07:38:31 -07:00
|
|
|
|
2012-05-14 07:38:39 -07:00
|
|
|
ecore_ipc_server_data_size_max_set(ev->server, -1);
|
|
|
|
|
2012-05-14 07:38:35 -07:00
|
|
|
ack_st t = { msg };
|
2012-05-14 07:38:49 -07:00
|
|
|
p = packet_compose(APP_ACK, &t, sizeof(t), &size);
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
ecore_ipc_server_send(ev->server, 0,0,0,0,EINA_FALSE, p, size);
|
|
|
|
ecore_ipc_server_flush(ev->server);
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
2012-05-14 07:38:02 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
2012-05-14 07:38:31 -07:00
|
|
|
_del(void *data __UNUSED__, int type __UNUSED__, Ecore_Ipc_Event_Server_Del *ev)
|
2012-05-14 07:38:02 -07:00
|
|
|
{
|
|
|
|
if (!ev->server)
|
|
|
|
{
|
|
|
|
printf("Failed to establish connection to the server.\nExiting.\n");
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
|
2012-05-14 07:38:31 -07:00
|
|
|
printf("Lost server with ip %s!\n", ecore_ipc_server_ip_get(ev->server));
|
2012-05-14 07:38:02 -07:00
|
|
|
|
2012-05-14 07:38:31 -07:00
|
|
|
ecore_ipc_server_del(ev->server);
|
2012-05-14 07:38:02 -07:00
|
|
|
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
2012-05-14 07:38:31 -07:00
|
|
|
_data(void *data __UNUSED__, int type __UNUSED__, Ecore_Ipc_Event_Server_Data *ev)
|
2012-05-14 07:38:02 -07:00
|
|
|
{
|
|
|
|
char fmt[128];
|
|
|
|
|
2012-05-14 07:38:35 -07:00
|
|
|
printf("Received %i bytes from server:\n"
|
2012-05-14 07:38:02 -07:00
|
|
|
">>>>>\n"
|
|
|
|
"%%.%is\n"
|
|
|
|
">>>>>\n",
|
|
|
|
ev->size, ev->size);
|
|
|
|
|
2012-05-14 07:38:49 -07:00
|
|
|
Variant_st *v = packet_info_get(ev->data, ev->size);
|
2012-05-14 07:38:35 -07:00
|
|
|
if (v)
|
|
|
|
{
|
|
|
|
ack_st *ack = v->data;
|
|
|
|
printf("APP <%s> got <%s> from daemon.\n", __func__, ack->text);
|
2012-05-14 07:38:49 -07:00
|
|
|
variant_free(v);
|
2012-05-14 07:38:35 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("APP <%s> failed to decode packet from daemon.\n", __func__);
|
2012-05-14 07:38:02 -07:00
|
|
|
|
2012-05-14 07:38:35 -07:00
|
|
|
char *msg="Reply to DATA in APP";
|
|
|
|
int size = 0;
|
|
|
|
|
2012-05-14 07:39:23 -07:00
|
|
|
Eina_List *tree = _load_list();
|
2012-05-14 07:38:35 -07:00
|
|
|
Tree_Item *t = eina_list_nth(tree, 0);
|
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
printf("Trying to send tree\n");
|
2012-05-14 07:38:46 -07:00
|
|
|
_item_tree_item_string(t);
|
2012-05-14 07:38:49 -07:00
|
|
|
void *p = packet_compose(APP_TREE_DATA, t, sizeof(*t), &size);
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
ecore_ipc_server_send(ev->server, 0,0,0,0,EINA_FALSE, p, size);
|
|
|
|
ecore_ipc_server_flush(ev->server);
|
|
|
|
free(p);
|
|
|
|
}
|
2012-05-14 07:38:35 -07:00
|
|
|
}
|
2012-05-14 07:38:15 -07:00
|
|
|
|
2012-05-14 07:39:23 -07:00
|
|
|
|
|
|
|
item_tree_free(tree);
|
2012-05-14 07:38:02 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_connect_to_daemon(void)
|
|
|
|
{
|
2012-05-14 07:38:31 -07:00
|
|
|
Ecore_Ipc_Server *svr;
|
2012-05-14 07:38:02 -07:00
|
|
|
const char *address = LOCALHOST;
|
|
|
|
|
|
|
|
eina_init();
|
|
|
|
ecore_init();
|
2012-05-14 07:38:31 -07:00
|
|
|
ecore_ipc_init();
|
2012-05-14 07:38:02 -07:00
|
|
|
|
2012-05-14 07:38:31 -07:00
|
|
|
if (!(svr = ecore_ipc_server_connect(ECORE_IPC_REMOTE_SYSTEM, LOCALHOST, PORT, NULL)))
|
2012-05-14 07:38:02 -07:00
|
|
|
{
|
|
|
|
printf("could not connect to the server: %s, port %d.\n",
|
2012-05-14 07:38:31 -07:00
|
|
|
address, PORT);
|
2012-05-14 07:38:02 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-14 07:38:39 -07:00
|
|
|
ecore_ipc_server_data_size_max_set(svr, -1);
|
|
|
|
|
2012-05-14 07:38:02 -07:00
|
|
|
/* set event handler for server connect */
|
2012-05-14 07:39:23 -07:00
|
|
|
ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD,
|
|
|
|
(Ecore_Event_Handler_Cb)_add, NULL);
|
2012-05-14 07:38:02 -07:00
|
|
|
/* set event handler for server disconnect */
|
2012-05-14 07:39:23 -07:00
|
|
|
ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL,
|
|
|
|
(Ecore_Event_Handler_Cb)_del, NULL);
|
2012-05-14 07:38:02 -07:00
|
|
|
/* set event handler for receiving server data */
|
2012-05-14 07:39:23 -07:00
|
|
|
ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA,
|
|
|
|
(Ecore_Event_Handler_Cb)_data, NULL);
|
2012-05-14 07:38:02 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
2011-08-24 07:06:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Hook on the main loop
|
|
|
|
* We only do something here if we didn't already go into elm_init,
|
|
|
|
* which probably means we are not using elm. */
|
|
|
|
void
|
|
|
|
ecore_main_loop_begin(void)
|
|
|
|
{
|
|
|
|
Eina_Bool _is_init = _lib_init;
|
|
|
|
void (*_ecore_main_loop_begin)(void) =
|
|
|
|
dlsym(RTLD_NEXT, "ecore_main_loop_begin");
|
|
|
|
|
|
|
|
if (!_is_init)
|
|
|
|
{
|
2011-11-15 05:34:28 -08:00
|
|
|
char *margv[] = { "clouseau" };
|
2011-08-24 07:06:04 -07:00
|
|
|
/* Make sure we init elementary, wouldn't be needed once we
|
|
|
|
* take away the ui to another proc. */
|
2011-11-15 05:34:28 -08:00
|
|
|
elm_init(1, margv);
|
2011-08-24 07:06:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_lib_init = EINA_TRUE;
|
2012-05-14 07:39:23 -07:00
|
|
|
if(!_connect_to_daemon())
|
|
|
|
{
|
|
|
|
printf("Failed to connect to server.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-24 07:06:04 -07:00
|
|
|
_ecore_main_loop_begin();
|
|
|
|
|
2012-05-14 07:39:26 -07:00
|
|
|
data_descriptors_shutdown();
|
2011-08-24 07:06:04 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-12 09:36:15 -07:00
|
|
|
#define EINA_LOCK_DEBUG_BT_NUM 64
|
|
|
|
typedef void (*Eina_Lock_Bt_Func) ();
|
|
|
|
|
|
|
|
Evas_Object *
|
|
|
|
evas_object_new(Evas *e)
|
|
|
|
{
|
|
|
|
Eina_Lock_Bt_Func lock_bt[EINA_LOCK_DEBUG_BT_NUM];
|
|
|
|
int lock_bt_num;
|
|
|
|
Evas_Object *(*_evas_object_new)(Evas *e) = dlsym(RTLD_NEXT, "evas_object_new");
|
|
|
|
Eina_Strbuf *str;
|
|
|
|
Evas_Object *r;
|
|
|
|
char **strings;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
r = _evas_object_new(e);
|
|
|
|
if (!r) return NULL;
|
|
|
|
|
|
|
|
lock_bt_num = backtrace((void **)lock_bt, EINA_LOCK_DEBUG_BT_NUM);
|
|
|
|
strings = backtrace_symbols((void **)lock_bt, lock_bt_num);
|
|
|
|
|
|
|
|
str = eina_strbuf_new();
|
|
|
|
|
|
|
|
for (i = 1; i < lock_bt_num; ++i)
|
|
|
|
eina_strbuf_append_printf(str, "%s\n", strings[i]);
|
|
|
|
|
|
|
|
evas_object_data_set(r, ".clouseau.bt", eina_stringshare_add(eina_strbuf_string_get(str)));
|
|
|
|
|
|
|
|
free(strings);
|
|
|
|
eina_strbuf_free(str);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_object_free(Evas_Object *obj, int clean_layer)
|
|
|
|
{
|
|
|
|
void (*_evas_object_free)(Evas_Object *obj, int clean_layer) = dlsym(RTLD_NEXT, "evas_object_free");
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
tmp = evas_object_data_get(obj, ".clouseau.bt");
|
|
|
|
eina_stringshare_del(tmp);
|
|
|
|
|
|
|
|
_evas_object_free(obj, clean_layer);
|
|
|
|
}
|
|
|
|
|