From: Janos Kovacs Date: Thu, 13 Jun 2013 07:56:27 +0000 (+0300) Subject: ivi-resource-manager: basic framework for screen resource X-Git-Tag: accepted/tizen/ivi/20150112.012920~442 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a28c2f3923199e42deaf5915b9bb2acc51488c13;p=profile%2Fivi%2Fmurphy.git ivi-resource-manager: basic framework for screen resource --- diff --git a/src/Makefile.am b/src/Makefile.am index bf3c842..e6284e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1333,7 +1333,9 @@ endif # IVI resource manager plugin if BUILD_RESOURCES PLUGIN_IVI_RESOURCE_MANAGER_REGULAR_SOURCES = \ - plugins/ivi-resource-manager/plugin-ivi-resource-manager.c + plugins/ivi-resource-manager/plugin-ivi-resource-manager.c \ + plugins/ivi-resource-manager/class.c \ + plugins/ivi-resource-manager/screen.c PLUGIN_IVI_RESOURCE_MANAGER_SOURCES = \ $(PLUGIN_IVI_RESOURCE_MANAGER_REGULAR_SOURCES) \ plugin-ivi-resource-manager-func-info.c diff --git a/src/plugins/ivi-resource-manager/class.c b/src/plugins/ivi-resource-manager/class.c new file mode 100644 index 0000000..75509e2 --- /dev/null +++ b/src/plugins/ivi-resource-manager/class.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2012, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include + +#include + +#include "class.h" + + +mrp_resmgr_class_t *mrp_resmgr_class_create(mrp_list_hook_t *classes, + mrp_application_class_t *ac) +{ + mrp_resmgr_class_t *rc; + + if (ac) { + if ((rc = mrp_allocz(sizeof(*rc)))) { + rc->class = ac; + mrp_list_init(&rc->resources); + + mrp_list_append(classes, &rc->link); + + return rc; + } + } + + return NULL; +} + + +void mrp_resmgr_class_destroy(mrp_resmgr_class_t *rc) +{ + if (rc) { + mrp_list_delete(&rc->link); + mrp_free(rc); + } +} + + +mrp_resmgr_class_t *mrp_resmgr_class_find(mrp_list_hook_t *classes, + mrp_application_class_t *ac) +{ + mrp_list_hook_t *entry, *n; + mrp_resmgr_class_t *rc; + + if (ac) { + mrp_list_foreach(classes, entry, n) { + rc = mrp_list_entry(entry, mrp_resmgr_class_t, link); + + if (ac == rc->class) + return rc; + } + } + + return NULL; +} + + + + + + +/* + * Local Variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * + */ diff --git a/src/plugins/ivi-resource-manager/class.h b/src/plugins/ivi-resource-manager/class.h new file mode 100644 index 0000000..d0c0074 --- /dev/null +++ b/src/plugins/ivi-resource-manager/class.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2012, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MURPHY_IVI_RESOURCE_MANAGER_CLASS_H__ +#define __MURPHY_IVI_RESOURCE_MANAGER_CLASS_H__ + +#include + +#include "plugin-ivi-resource-manager.h" + +struct mrp_resmgr_class_s { + mrp_list_hook_t link; + mrp_application_class_t *class; + mrp_list_hook_t resources; +}; + + +mrp_resmgr_class_t *mrp_resmgr_class_create(mrp_list_hook_t *, + mrp_application_class_t *); + +void mrp_resmgr_class_destroy(mrp_resmgr_class_t *); + +mrp_resmgr_class_t *mrp_resmgr_class_find(mrp_list_hook_t *, + mrp_application_class_t *); + + +#endif /* __MURPHY_IVI_RESOURCE_MANAGER_CLASS_H__ */ + +/* + * Local Variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * + */ diff --git a/src/plugins/ivi-resource-manager/plugin-ivi-resource-manager.c b/src/plugins/ivi-resource-manager/plugin-ivi-resource-manager.c index 0af7e1a..c69811d 100644 --- a/src/plugins/ivi-resource-manager/plugin-ivi-resource-manager.c +++ b/src/plugins/ivi-resource-manager/plugin-ivi-resource-manager.c @@ -34,11 +34,7 @@ #include #include -#include -#include -#include -#include -#include +#include #include #include #include @@ -52,91 +48,56 @@ #include #include +#include "screen.h" -typedef struct { - mrp_plugin_t *plugin; - mrp_event_watch_t *w; -} manager_data_t; +struct mrp_resmgr_data_s { + mrp_plugin_t *plugin; + mrp_event_watch_t *w; + mrp_resmgr_screen_t *screen; + mrp_htbl_t *resources; +}; -static void resource_event_handler(uint32_t, mrp_resource_set_t *, void *); +void mrp_resmgr_insert_resource(mrp_resmgr_data_t *data, + mrp_resource_t *key, + void *resource) +{ + MRP_ASSERT(data && key && resource, "invalid argument"); + MRP_ASSERT(data->resources, "uninitialised data structure"); + mrp_htbl_insert(data->resources, key, resource); +} +void *mrp_resmgr_remove_resource(mrp_resmgr_data_t *data, mrp_resource_t *key) +{ + MRP_ASSERT(data && key, "invalid argument"); + MRP_ASSERT(data->resources, "uninitialised data structure"); -#if 0 -static int set_default_configuration(void) + return mrp_htbl_remove(data->resources, key, FALSE); +} + +void *mrp_resmgr_lookup_resource(mrp_resmgr_data_t *data, mrp_resource_t *key) { - typedef struct { - const char *name; - bool share; - mrp_attr_def_t *attrs; - } resdef_t; - - static const char *zones[] = { - "driver", - "front-passenger", - "rear-left-passenger", - "rear-right-passenger", - NULL - }; - - static const char *classes[] = { - "implicit", - "player", - "game", - "phone", - "navigator", - NULL - }; - - static mrp_attr_def_t audio_attrs[] = { - { "role", MRP_RESOURCE_RW, mqi_string , .value.string="music" }, - { NULL , 0 , mqi_unknown, .value.string=NULL } - }; - - static resdef_t resources[] = { - { "audio_playback" , true , audio_attrs }, - { "audio_recording", true , NULL }, - { "video_playback" , false, NULL }, - { "video_recording", false, NULL }, - { NULL , false, NULL } - }; - - const char *name; - resdef_t *rdef; - uint32_t i; - - mrp_zone_definition_create(NULL); - - for (i = 0; (name = zones[i]); i++) - mrp_zone_create(name, NULL); - - for (i = 0; (name = classes[i]); i++) - mrp_application_class_create(name, i); - - for (i = 0; (rdef = resources + i)->name; i++) { - mrp_resource_definition_create(rdef->name, rdef->share, rdef->attrs, - NULL, NULL); - } + MRP_ASSERT(data && key, "invalid argument"); + MRP_ASSERT(data->resources, "uninitialised data structure"); - return 0; + return mrp_htbl_lookup(data->resources, key); } -#endif static void event_cb(mrp_event_watch_t *w, int id, mrp_msg_t *event_data, void *user_data) { - mrp_plugin_t *plugin = (mrp_plugin_t *)user_data; + mrp_plugin_t *plugin = (mrp_plugin_t *)user_data; #if 0 - mrp_plugin_arg_t *args = plugin->args; + mrp_plugin_arg_t *args = plugin->args; #endif - manager_data_t *data = (manager_data_t *)plugin->data; - const char *event = mrp_get_event_name(id); - uint16_t tag_inst = MRP_PLUGIN_TAG_INSTANCE; - uint16_t tag_name = MRP_PLUGIN_TAG_PLUGIN; - const char *inst; - const char *name; - int success; + mrp_resmgr_data_t *data = (mrp_resmgr_data_t *)plugin->data; + const char *event = mrp_get_event_name(id); + uint16_t tag_inst = MRP_PLUGIN_TAG_INSTANCE; + uint16_t tag_name = MRP_PLUGIN_TAG_PLUGIN; + const char *inst; + const char *name; + int success; MRP_UNUSED(w); @@ -150,11 +111,7 @@ static void event_cb(mrp_event_watch_t *w, int id, mrp_msg_t *event_data, MRP_MSG_END); if (success) { if (!strcmp(inst, plugin->instance)) { -#if 0 - set_default_configuration(); - mrp_log_info("%s: built-in default configuration " - "is in use", plugin->instance); -#endif + data->screen = mrp_resmgr_screen_create(data); } } } /* if PLUGIN_STARTED */ @@ -164,8 +121,8 @@ static void event_cb(mrp_event_watch_t *w, int id, mrp_msg_t *event_data, static int subscribe_events(mrp_plugin_t *plugin) { - manager_data_t *data = (manager_data_t *)plugin->data; - mrp_event_mask_t events; + mrp_resmgr_data_t *data = (mrp_resmgr_data_t *)plugin->data; + mrp_event_mask_t events; mrp_set_named_events(&events, MRP_PLUGIN_EVENT_LOADED, @@ -184,7 +141,7 @@ static int subscribe_events(mrp_plugin_t *plugin) static void unsubscribe_events(mrp_plugin_t *plugin) { - manager_data_t *data = (manager_data_t *)plugin->data; + mrp_resmgr_data_t *data = (mrp_resmgr_data_t *)plugin->data; if (data->w) { mrp_del_event_watch(data->w); @@ -193,17 +150,38 @@ static void unsubscribe_events(mrp_plugin_t *plugin) } +static int hash_compare(const void *key1, const void *key2) +{ + if (key1 < key2) + return -1; + if (key1 > key2) + return 1; + return 0; +} + +static uint32_t hash_function(const void *key) +{ + return (uint32_t)(((uint64_t)key >> 4) & 0xffffffff); +} + static int manager_init(mrp_plugin_t *plugin) { #if 0 - mrp_plugin_arg_t *args = plugin->args; + mrp_plugin_arg_t *args = plugin->args; #endif - manager_data_t *data; + mrp_resmgr_data_t *data; + mrp_htbl_config_t cfg; mrp_log_info("%s() called for IVI resource manager instance '%s'...", __FUNCTION__, plugin->instance); + cfg.nentry = 256; + cfg.comp = hash_compare; + cfg.hash = hash_function; + cfg.free = NULL; + cfg.nbucket = cfg.nentry / 4; + if (!(data = mrp_allocz(sizeof(*data)))) { mrp_log_error("Failed to allocate private data for IVI resource " "manager plugin instance %s.", plugin->instance); @@ -211,6 +189,7 @@ static int manager_init(mrp_plugin_t *plugin) } data->plugin = plugin; + data->resources = mrp_htbl_create(&cfg); plugin->data = data; @@ -222,10 +201,16 @@ static int manager_init(mrp_plugin_t *plugin) static void manager_exit(mrp_plugin_t *plugin) { + mrp_resmgr_data_t *data; + mrp_log_info("%s() called for IVI resource manager instance '%s'...", __FUNCTION__, plugin->instance); unsubscribe_events(plugin); + + if ((data = plugin->data)) { + mrp_resmgr_screen_destroy(data->screen); + } } diff --git a/src/plugins/ivi-resource-manager/plugin-ivi-resource-manager.h b/src/plugins/ivi-resource-manager/plugin-ivi-resource-manager.h new file mode 100644 index 0000000..463ac20 --- /dev/null +++ b/src/plugins/ivi-resource-manager/plugin-ivi-resource-manager.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MURPHY_IVI_RESOURCE_MANAGER_H__ +#define __MURPHY_IVI_RESOURCE_MANAGER_H__ + +typedef struct mrp_resmgr_data_s mrp_resmgr_data_t; +typedef struct mrp_resmgr_screen_s mrp_resmgr_screen_t; +typedef struct mrp_resmgr_class_s mrp_resmgr_class_t; + +void mrp_resmgr_insert_resource(mrp_resmgr_data_t *, mrp_resource_t *,void *); +void *mrp_resmgr_remove_resource(mrp_resmgr_data_t *, mrp_resource_t *); +void *mrp_resmgr_lookup_resource(mrp_resmgr_data_t *, mrp_resource_t *); + +#endif /* __MURPHY_IVI_RESOURCE_MANAGER_H__ */ + +/* + * Local Variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * + */ diff --git a/src/plugins/ivi-resource-manager/screen.c b/src/plugins/ivi-resource-manager/screen.c new file mode 100644 index 0000000..33ac1c9 --- /dev/null +++ b/src/plugins/ivi-resource-manager/screen.c @@ -0,0 +1,384 @@ +/* + * Copyright (c) 2012, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include +#include + +#include "screen.h" +#include "class.h" + +#define ATTRIBUTE(n,t,v) {n, MRP_RESOURCE_RW, mqi_##t, {.t=v}} +#define ATTR_END {NULL, 0, 0, {.string=NULL}} + +typedef struct screen_resource_s screen_resource_t; + +struct mrp_resmgr_screen_s { + mrp_resmgr_data_t *data; + uint32_t resid; + mrp_list_hook_t classes[MRP_ZONE_MAX]; +}; + +struct screen_resource_s { + mrp_list_hook_t link; + mrp_resource_t *res; + mrp_resmgr_screen_t *screen; + mrp_resmgr_class_t *class; + bool active; + uint32_t key; +}; + + +static screen_resource_t *screen_resource_create(mrp_resmgr_screen_t *, + mrp_zone_t *,mrp_resource_t *, + mrp_application_class_t *); +static void screen_resource_destroy(mrp_resmgr_screen_t *, mrp_resource_t *); +static screen_resource_t *screen_resource_lookup(mrp_resmgr_screen_t *, + mrp_resource_t *); + +static void resource_class_move_resource(mrp_resmgr_class_t *, + screen_resource_t *); +static uint32_t resource_key(mrp_resource_t *); + + +static void screen_notify(mrp_resource_event_t, mrp_zone_t *, + mrp_application_class_t *, mrp_resource_t *, void *); +static void screen_init(mrp_zone_t *, void *); +static bool screen_allocate(mrp_zone_t *, mrp_resource_t *, void *); +static void screen_free(mrp_zone_t *, mrp_resource_t *, void *); +static bool screen_advice(mrp_zone_t *, mrp_resource_t *, void *); +static void screen_commit(mrp_zone_t *, void *); + + +#define PRIORITY_ATTRIDX 0 +#define CATHEGORY_ATTRIDX 1 +#define APPID_ATTRIDX 2 + +static mrp_attr_def_t screen_attrs[] = { + ATTRIBUTE("priority" , integer, 0 ), + ATTRIBUTE("cathegory", integer, 0 ), + ATTRIBUTE("appid" , string , ""), + ATTR_END +}; + + +static mrp_resource_mgr_ftbl_t screen_ftbl = { + screen_notify, + screen_init, + screen_allocate, + screen_free, + screen_advice, + screen_commit +}; + + + +mrp_resmgr_screen_t *mrp_resmgr_screen_create(mrp_resmgr_data_t *data) +{ + mrp_resmgr_screen_t *screen; + uint32_t resid; + uint32_t i; + + if ((screen = mrp_allocz(sizeof(*screen)))) { + resid = mrp_resource_definition_create("screen", true, screen_attrs, + &screen_ftbl, screen); + mrp_lua_resclass_create_from_c(resid); + + screen->data = data; + screen->resid = resid; + + for (i = 0; i < MRP_ZONE_MAX; i++) + mrp_list_init(screen->classes + i); + } + + return screen; +} + + +void mrp_resmgr_screen_destroy(mrp_resmgr_screen_t *screen) +{ + if (screen) { + + mrp_free(screen); + } +} + +static screen_resource_t *screen_resource_create(mrp_resmgr_screen_t *screen, + mrp_zone_t *zone, + mrp_resource_t *res, + mrp_application_class_t *ac) +{ + uint32_t zone_id; + mrp_list_hook_t *classes; + mrp_resmgr_class_t *rc; + screen_resource_t *sr; + + MRP_ASSERT(screen && zone && res && ac, "invalid argument"); + MRP_ASSERT(screen->data, "confused with data structures"); + + zone_id = mrp_zone_get_id(zone); + classes = screen->classes + zone_id; + + if (!(rc = mrp_resmgr_class_find(classes, ac)) && + !(rc = mrp_resmgr_class_create(classes, ac)) ) + { + mrp_log_error("ivi-resource-manager: can't obtain resmgr class"); + } + else { + if ((sr = mrp_allocz(sizeof(*sr)))) { + mrp_list_init(&sr->link); + sr->res = res; + sr->screen = screen; + sr->class = rc; + sr->key = resource_key(res); + + printf("*** key 0x%08x\n", sr->key); + + resource_class_move_resource(rc, sr); + + mrp_resmgr_insert_resource(screen->data, res, sr); + } + } + + return sr; +} + + +static void screen_resource_destroy(mrp_resmgr_screen_t *screen, + mrp_resource_t *res) +{ + screen_resource_t *sr; + + MRP_ASSERT(res && screen, "invalid argument"); + MRP_ASSERT(screen->data, "confused with data structures"); + + if ((sr = mrp_resmgr_remove_resource(screen->data, res))) { + mrp_list_delete(&sr->link); + mrp_free(sr); + } +} + + +static screen_resource_t *screen_resource_lookup(mrp_resmgr_screen_t *screen, + mrp_resource_t *res) +{ + screen_resource_t *sr; + + MRP_ASSERT(res && screen, "invalid argument"); + MRP_ASSERT(screen->data, "confused with data structures"); + + sr = mrp_resmgr_lookup_resource(screen->data, res); + + return sr; +} + +static void resource_class_move_resource(mrp_resmgr_class_t *class, + screen_resource_t *resource) +{ + mrp_list_hook_t *list, *entry, *n, *insert_before; + screen_resource_t *sr; + + mrp_list_delete(&resource->link); + + list = insert_before = &class->resources; + + mrp_list_foreach_back(list, entry, n) { + sr = mrp_list_entry(entry, screen_resource_t, link); + + if (resource->key >= sr->key) + break; + + insert_before = entry; + } + + mrp_list_append(insert_before, &resource->link); +} + +static uint32_t resource_key(mrp_resource_t *res) +{ + mrp_attr_t attr; + uint32_t priority; + uint32_t cathegory; + uint32_t key = 0; + + do { + if (!res) + break; + + if (!mrp_resource_read_attribute(res, PRIORITY_ATTRIDX, &attr)) + break; + if (attr.type != mqi_integer || attr.value.integer < 0) + break; + + priority = attr.value.integer; + + if (!mrp_resource_read_attribute(res, CATHEGORY_ATTRIDX, &attr)) + break; + if (attr.type != mqi_integer || attr.value.integer < 0) + break; + + cathegory = attr.value.integer; + + key = ((cathegory & 0xffff) << 16) | (priority & 0xffff); + + return key; + + } while(0); + + return key; +} + + + +static void screen_notify(mrp_resource_event_t event, + mrp_zone_t *zone, + mrp_application_class_t *ac, + mrp_resource_t *res, + void *userdata) +{ + mrp_resmgr_screen_t *screen = (mrp_resmgr_screen_t *)userdata; + const char *zone_name = mrp_zone_get_name(zone); + screen_resource_t *sr; + + MRP_ASSERT(zone && ac && res && screen, "invalid argument"); + + switch (event) { + + case MRP_RESOURCE_EVENT_CREATED: + mrp_log_info("screen resource in zone '%s' created", zone_name); + screen_resource_create(screen, zone, res, ac); + break; + + case MRP_RESOURCE_EVENT_DESTROYED: + mrp_log_info("screen resource in zone '%s' destroyed", zone_name); + screen_resource_destroy(screen, res); + break; + + case MRP_RESOURCE_EVENT_ACQUIRE: + mrp_log_info("screen resource in zone '%s' is acquiring", zone_name); + if (!(sr = screen_resource_lookup(screen, res))) + goto no_screen_resource; + else { + sr->active = true; + } + break; + + case MRP_RESOURCE_EVENT_RELEASE: + mrp_log_info("screen resource in zone '%s' is released", zone_name); + if (!(sr = screen_resource_lookup(screen, res))) + goto no_screen_resource; + else { + sr->active = false; + } + break; + + no_screen_resource: + mrp_log_error("ivi-resource-manager: can't find screen resource " + "in zone '%s'", zone_name); + break; + + default: + mrp_log_error("ivi-resource-manager: invalid event %d at screen " + "notification (zone '%s')", event, zone_name); + break; + } +} + +static void screen_init(mrp_zone_t *zone, void *userdata) +{ + mrp_resmgr_screen_t *screen = (mrp_resmgr_screen_t *)userdata; + const char *zone_name = mrp_zone_get_name(zone); + + MRP_ASSERT(screen, "invalid argument"); + + mrp_log_info("screen init in zone '%s'", zone_name); +} + +static bool screen_allocate(mrp_zone_t *zone, + mrp_resource_t *res, + void *userdata) +{ + mrp_resmgr_screen_t *screen = (mrp_resmgr_screen_t *)userdata; + const char *zone_name = mrp_zone_get_name(zone); + + MRP_UNUSED(res); + + MRP_ASSERT(screen, "invalid argument"); + + mrp_log_info("screen allocate in zone '%s'", zone_name); + + return TRUE; +} + + +static void screen_free(mrp_zone_t *zone, mrp_resource_t *res, void *userdata) +{ + mrp_resmgr_screen_t *screen = (mrp_resmgr_screen_t *)userdata; + const char *zone_name = mrp_zone_get_name(zone); + + MRP_UNUSED(res); + + MRP_ASSERT(screen, "invalid argument"); + + mrp_log_info("screen allocation free in zone '%s'", zone_name); +} + +static bool screen_advice(mrp_zone_t *zone,mrp_resource_t *res,void *userdata) +{ + mrp_resmgr_screen_t *screen = (mrp_resmgr_screen_t *)userdata; + const char *zone_name = mrp_zone_get_name(zone); + + MRP_UNUSED(res); + + MRP_ASSERT(screen, "invalid argument"); + + mrp_log_info("screen advice in zone '%s'", zone_name); + + return TRUE; +} + +static void screen_commit(mrp_zone_t *zone, void *userdata) +{ + mrp_resmgr_screen_t *screen = (mrp_resmgr_screen_t *)userdata; + const char *zone_name = mrp_zone_get_name(zone); + + MRP_ASSERT(screen, "invalid argument"); + + mrp_log_info("screen commit in zone '%s'", zone_name); +} + + +/* + * Local Variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * + */ diff --git a/src/plugins/ivi-resource-manager/screen.h b/src/plugins/ivi-resource-manager/screen.h new file mode 100644 index 0000000..b6e4df9 --- /dev/null +++ b/src/plugins/ivi-resource-manager/screen.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MURPHY_IVI_RESOURCE_MANAGER_SCREEN_H__ +#define __MURPHY_IVI_RESOURCE_MANAGER_SCREEN_H__ + +#include "plugin-ivi-resource-manager.h" + +mrp_resmgr_screen_t *mrp_resmgr_screen_create(mrp_resmgr_data_t *); +void mrp_resmgr_screen_destroy(mrp_resmgr_screen_t *); + + +#endif /* __MURPHY_IVI_RESOURCE_MANAGER_SCREEN_H__ */ + +/* + * Local Variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * + */