efl
1/* Portions of this code have been derived from Weston
2*
3* Copyright © 2008-2012 Kristian Høgsberg
4* Copyright © 2010-2012 Intel Corporation
5* Copyright © 2010-2011 Benjamin Franzke
6* Copyright © 2011-2012 Collabora, Ltd.
7* Copyright © 2010 Red Hat <mjg@redhat.com>
8*
9* Permission is hereby granted, free of charge, to any person obtaining a
10* copy of this software and associated documentation files (the "Software"),
11* to deal in the Software without restriction, including without limitation
12* the rights to use, copy, modify, merge, publish, distribute, sublicense,
13* and/or sell copies of the Software, and to permit persons to whom the
14* Software is furnished to do so, subject to the following conditions:
15*
16* The above copyright notice and this permission notice (including the next
17* paragraph) shall be included in all copies or substantial portions of the
18* Software.
19*
20* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26* DEALINGS IN THE SOFTWARE.
27*/
28
29#include "ecore_drm_private.h"30
31/* local variables */
32static int _ecore_drm_init_count = 0;33
34/* external variables */
35int _ecore_drm_log_dom = -1;36
37EAPI int ECORE_DRM_EVENT_ACTIVATE = 0;38
39static void40_ecore_drm_event_activate_free(void *data EINA_UNUSED, void *event)41{
42free(event);43}
44
45void
46_ecore_drm_event_activate_send(Eina_Bool active)47{
48Ecore_Drm_Event_Activate *e;49
50if (!(e = calloc(1, sizeof(Ecore_Drm_Event_Activate)))) return;51
52e->active = active;53ecore_event_add(ECORE_DRM_EVENT_ACTIVATE, e,54_ecore_drm_event_activate_free, NULL);55}
56
57/**
58* @defgroup Ecore_Drm_Init_Group Drm Library Init and Shutdown Functions
59*
60* Functions that start and shutdown the Ecore_Drm Library.
61*/
62
63/**
64* Initialize the Ecore_Drm library
65*
66* @return The number of times the library has been initialized without
67* being shut down. 0 is returned if an error occurs.
68*
69* @ingroup Ecore_Drm_Init_Group
70*/
71EAPI int72ecore_drm_init(void)73{
74/* if we have already initialized, return the count */75if (++_ecore_drm_init_count != 1) return _ecore_drm_init_count;76
77/* try to init eina */78if (!eina_init()) return --_ecore_drm_init_count;79
80/* try to init ecore */81if (!ecore_init())82{83eina_shutdown();84return --_ecore_drm_init_count;85}86
87/* try to init ecore_event */88if (!ecore_event_init())89{90ecore_shutdown();91eina_shutdown();92return --_ecore_drm_init_count;93}94
95/* set logging level */96/* eina_log_level_set(EINA_LOG_LEVEL_DBG); */97
98/* try to create logging domain */99_ecore_drm_log_dom =100eina_log_domain_register("ecore_drm", ECORE_DRM_DEFAULT_LOG_COLOR);101if (!_ecore_drm_log_dom)102{103EINA_LOG_ERR("Could not create log domain for Ecore_Drm");104goto log_err;105}106
107/* try to init eeze */108if (!eeze_init()) goto eeze_err;109
110_ecore_drm_inputs_init();111
112ECORE_DRM_EVENT_ACTIVATE = ecore_event_type_new();113ECORE_DRM_EVENT_OUTPUT = ecore_event_type_new();114ECORE_DRM_EVENT_SEAT_ADD = ecore_event_type_new();115
116/* return init count */117return _ecore_drm_init_count;118
119eeze_err:120eina_log_domain_unregister(_ecore_drm_log_dom);121_ecore_drm_log_dom = -1;122log_err:123ecore_event_shutdown();124ecore_shutdown();125eina_shutdown();126return --_ecore_drm_init_count;127}
128
129/**
130* Shutdown the Ecore_Drm library.
131*
132* @return The number of times the library has been initialized without
133* being shutdown. 0 is returned if an error occurs.
134*
135* @ingroup Ecore_Drm_Init_Group
136*/
137EAPI int138ecore_drm_shutdown(void)139{
140Eina_List *lists;141Ecore_Drm_Device *dev;142
143/* _ecore_drm_init_count should not go below zero. */144if (_ecore_drm_init_count < 1)145{146ERR("Ecore_Drm Shutdown called without Ecore_Drm Init");147return 0;148}149
150/* if we are still in use, decrement init count and get out */151if (--_ecore_drm_init_count != 0) return _ecore_drm_init_count;152
153ecore_event_type_flush(ECORE_DRM_EVENT_ACTIVATE,154ECORE_DRM_EVENT_OUTPUT,155ECORE_DRM_EVENT_SEAT_ADD);156
157/* free the list of devices */158lists = eina_list_clone(ecore_drm_devices_get());159EINA_LIST_FREE(lists, dev)160{161ecore_drm_device_free(dev);162}163
164_ecore_drm_inputs_shutdown();165
166/* close eeze */167eeze_shutdown();168
169/* shutdown ecore_event */170ecore_event_shutdown();171
172/* shutdown ecore */173ecore_shutdown();174
175/* unregsiter log domain */176eina_log_domain_unregister(_ecore_drm_log_dom);177_ecore_drm_log_dom = -1;178
179/* shutdown eina */180eina_shutdown();181
182/* return init count */183return _ecore_drm_init_count;184}
185