diff --git a/src/bin/Makefile.mk b/src/bin/Makefile.mk index 78e5c3a5d..3dc6cbf21 100644 --- a/src/bin/Makefile.mk +++ b/src/bin/Makefile.mk @@ -214,6 +214,7 @@ src/bin/e_zone.h if HAVE_WAYLAND_CLIENTS ENLIGHTENMENTHEADERS += \ +src/bin/e_uuid_store.h \ src/bin/e_comp_wl.h endif @@ -386,6 +387,7 @@ endif if HAVE_WAYLAND_CLIENTS enlightenment_src += \ +src/bin/e_uuid_store.c \ src/bin/e_comp_wl.c endif diff --git a/src/bin/e_includes.h b/src/bin/e_includes.h index 959c213ea..084ab350b 100644 --- a/src/bin/e_includes.h +++ b/src/bin/e_includes.h @@ -155,3 +155,6 @@ #include "e_comp_canvas.h" #include "e_utils.h" #include "e_hints.h" +#ifdef HAVE_WAYLAND_CLIENTS +# include "e_uuid_store.h" +#endif diff --git a/src/bin/e_uuid_store.c b/src/bin/e_uuid_store.c new file mode 100644 index 000000000..3be21b696 --- /dev/null +++ b/src/bin/e_uuid_store.c @@ -0,0 +1,144 @@ +/* vim:ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 + */ + +/* 1. Create mmaped memory blob, name the memory object + * 2. Fill in table and keep it up-to-date + * 3. (optional) Write the whole blob into a file on disk for later use) + */ + +#include +#include +#include +#include + +#include + +#include + +/* Use anonymous mapping if we don't want a persistent file on the disk */ +#define OBJECT_NAME "/e_uuid_store" +#define TABLE_SIZE 10*eina_cpu_page_size() + +struct uuid_store *store; + +EINTERN int +e_uuid_store_init(void) + { + /* FIXME think about refcounting here */ + eina_init(); + + store = calloc(1, sizeof(struct uuid_store)); + if (store == NULL) return 0; + + store->shmfd = shm_open(OBJECT_NAME, O_CREAT | O_RDWR, S_IRWXU | S_IRWXG); + if (store->shmfd < 0) + { + ERR("shm_open failed"); + return 0; + } + + /* Adjust in memory blob to our given table size */ + /* FIXME: How can we make sure we have the right size for our given table? */ + ftruncate(store->shmfd, TABLE_SIZE); + + store->table = (struct uuid_table *)mmap(NULL, TABLE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, store->shmfd, 0); + if (store->table == NULL) + { + ERR("mmap failed"); + return 0; + } + + INF("mmaped blob with size %i created", TABLE_SIZE); + return 1; + } + +EINTERN int +e_uuid_store_shutdown(void) + { + /* Cleanup for shutdown */ + if (shm_unlink(OBJECT_NAME) != 0) + { + ERR("shm_unlink failed"); + return 0; + } + + free(store); + eina_shutdown(); + return 1; + } + +Eina_Bool +e_uuid_store_reload(void) + { + /* After crash reload the table with its POSIX object name from memory */ + return EINA_FALSE; + } + +Eina_Bool +e_uuid_store_entry_del(long uuid) + { + struct uuid_table *table; + struct table_entry *entry; + Eina_List *l; + + if (store == NULL) return EINA_FALSE; + + table = store->table; + if (table == NULL) return EINA_FALSE; + + /* Search through uuid list and delete if found */ + EINA_LIST_FOREACH(table->entries, l, entry) + { + if (entry->uuid == uuid) + { + table->entries = eina_list_remove(table->entries, entry); + free(entry); + DBG("Removed entry with UUID %li", uuid); + return EINA_TRUE; + } + } + DBG("NOT removed entry with UUID %li. Entry not found.", uuid); + return EINA_FALSE; + } + +/* FIXME: Think about having _add and _update functions instead only update */ + +Eina_Bool +e_uuid_store_entry_update(long uuid, E_Client *ec) + { + struct uuid_table *table; + struct table_entry *entry; + Eina_List *l; + + if (store == NULL) return EINA_FALSE; + + table = store->table; + if (table == NULL) return EINA_FALSE; + + /* Search through uuid list if it already exist if yes update */ + EINA_LIST_FOREACH(table->entries, l, entry) + { + if (entry->uuid == uuid) + { + entry->x = ec->x; + entry->y = ec->y; + entry->width = ec->client.w; + entry->heigth = ec->client.h; + DBG("Updated entry with UUID %li", uuid); + return EINA_TRUE; + } + } + + /* We do not have this UUID in the table yet. Create it */ + entry = calloc(1, sizeof(struct table_entry)); + entry->uuid = uuid; + entry->x = ec->x; + entry->y = ec->y; + entry->width = ec->client.w; + entry->heigth = ec->client.h; + table->entries = eina_list_append(table->entries, entry); + table->entry_count = eina_list_count(table->entries); + DBG("Created entry with UUID %li", uuid); + + return EINA_TRUE; + } diff --git a/src/bin/e_uuid_store.h b/src/bin/e_uuid_store.h new file mode 100644 index 000000000..376b6467e --- /dev/null +++ b/src/bin/e_uuid_store.h @@ -0,0 +1,33 @@ +#ifndef E_UUID_STORE_H +#define E_UUID_STORE_H + +/* vim:ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 + */ + +struct uuid_table { + int version; /* Version to allow future extensions */ + unsigned int entry_count; /* Entry counter to allow excat memory consuptions needs? */ + /* Global settings like current virtual desktop, screen setup, etc */ + Eina_List *entries; +}; + +struct table_entry { + long uuid; + /* data structure for per application properties */ + Evas_Coord x, y; + Evas_Coord width, heigth; + unsigned int virtual_desktop; + int flags; +}; + +struct uuid_store { + struct uuid_table *table; + int shmfd; +}; + +EINTERN int e_uuid_store_init(void); +EINTERN int e_uuid_store_shutdown(void); +EAPI Eina_Bool e_uuid_store_reload(void); +EAPI Eina_Bool e_uuid_store_entry_del(long uuid); +EAPI Eina_Bool e_uuid_store_entry_update(long uuid, E_Client *ec); +#endif