2014-03-06 01:43:48 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ecore_drm_private.h"
|
|
|
|
|
|
|
|
/* local variables */
|
|
|
|
static int _ecore_drm_init_count = 0;
|
2014-07-15 06:28:03 -07:00
|
|
|
static char *sid;
|
2014-03-06 01:43:48 -08:00
|
|
|
|
|
|
|
/* external variables */
|
|
|
|
int _ecore_drm_log_dom = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup Ecore_Drm_Init_Group Drm Library Init and Shutdown Functions
|
|
|
|
*
|
|
|
|
* Functions that start and shutdown the Ecore_Drm Library.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the Ecore_Drm library
|
|
|
|
*
|
|
|
|
* @return The number of times the library has been initialized without
|
|
|
|
* being shut down. 0 is returned if an error occurs.
|
|
|
|
*
|
|
|
|
* @ingroup Ecore_Drm_Init_Group
|
|
|
|
*/
|
|
|
|
EAPI int
|
|
|
|
ecore_drm_init(void)
|
|
|
|
{
|
|
|
|
/* if we have already initialized, return the count */
|
|
|
|
if (++_ecore_drm_init_count != 1) return _ecore_drm_init_count;
|
|
|
|
|
|
|
|
/* try to init eina */
|
|
|
|
if (!eina_init()) return --_ecore_drm_init_count;
|
|
|
|
|
2014-03-10 01:26:53 -07:00
|
|
|
/* try to init ecore */
|
2014-03-06 01:43:48 -08:00
|
|
|
if (!ecore_init())
|
|
|
|
{
|
|
|
|
eina_shutdown();
|
|
|
|
return --_ecore_drm_init_count;
|
|
|
|
}
|
|
|
|
|
2014-03-10 01:26:53 -07:00
|
|
|
/* try to init ecore_event */
|
|
|
|
if (!ecore_event_init())
|
|
|
|
{
|
|
|
|
ecore_shutdown();
|
|
|
|
eina_shutdown();
|
|
|
|
return --_ecore_drm_init_count;
|
|
|
|
}
|
|
|
|
|
2014-03-06 01:43:48 -08:00
|
|
|
/* set logging level */
|
|
|
|
eina_log_level_set(EINA_LOG_LEVEL_DBG);
|
|
|
|
|
|
|
|
/* try to create logging domain */
|
|
|
|
_ecore_drm_log_dom =
|
|
|
|
eina_log_domain_register("ecore_drm", ECORE_DRM_DEFAULT_LOG_COLOR);
|
|
|
|
if (!_ecore_drm_log_dom)
|
|
|
|
{
|
|
|
|
EINA_LOG_ERR("Could not create log domain for Ecore_Drm");
|
|
|
|
goto log_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set default logging level for this domain */
|
|
|
|
if (!eina_log_domain_level_check(_ecore_drm_log_dom, EINA_LOG_LEVEL_DBG))
|
|
|
|
eina_log_domain_level_set("ecore_drm", EINA_LOG_LEVEL_DBG);
|
|
|
|
|
2014-07-15 06:28:03 -07:00
|
|
|
/* get sd-login properties we need */
|
2014-07-24 08:33:21 -07:00
|
|
|
if (sd_pid_get_session(getpid(), &sid) < 0) goto sd_err;
|
2014-03-06 01:43:48 -08:00
|
|
|
|
2014-07-15 06:28:03 -07:00
|
|
|
/* try to init dbus */
|
|
|
|
if (!_ecore_drm_dbus_init(sid)) goto dbus_err;
|
2014-03-06 01:43:48 -08:00
|
|
|
|
2014-09-23 07:34:00 -07:00
|
|
|
/* try to init eeze */
|
|
|
|
if (!eeze_init()) goto eeze_err;
|
2014-03-06 01:43:48 -08:00
|
|
|
|
|
|
|
/* return init count */
|
|
|
|
return _ecore_drm_init_count;
|
|
|
|
|
2014-09-23 07:34:00 -07:00
|
|
|
eeze_err:
|
2014-07-15 06:28:03 -07:00
|
|
|
_ecore_drm_dbus_shutdown();
|
|
|
|
dbus_err:
|
2014-07-24 08:33:21 -07:00
|
|
|
free(sid);
|
|
|
|
sd_err:
|
2014-03-06 01:43:48 -08:00
|
|
|
eina_log_domain_unregister(_ecore_drm_log_dom);
|
|
|
|
_ecore_drm_log_dom = -1;
|
|
|
|
log_err:
|
2014-07-24 08:33:21 -07:00
|
|
|
ecore_event_shutdown();
|
|
|
|
ecore_shutdown();
|
2014-03-06 01:43:48 -08:00
|
|
|
eina_shutdown();
|
|
|
|
return --_ecore_drm_init_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shutdown the Ecore_Drm library.
|
|
|
|
*
|
|
|
|
* @return The number of times the library has been initialized without
|
|
|
|
* being shutdown. 0 is returned if an error occurs.
|
|
|
|
*
|
|
|
|
* @ingroup Ecore_Drm_Init_Group
|
|
|
|
*/
|
|
|
|
EAPI int
|
|
|
|
ecore_drm_shutdown(void)
|
|
|
|
{
|
2014-10-23 06:04:29 -07:00
|
|
|
/* _ecore_drm_init_count should not go below zero. */
|
2014-10-23 07:32:59 -07:00
|
|
|
if (_ecore_drm_init_count < 1)
|
|
|
|
{
|
|
|
|
ERR("Ecore_Drm Shutdown called without Ecore_Drm Init");
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-23 06:04:29 -07:00
|
|
|
|
2014-03-06 01:43:48 -08:00
|
|
|
/* if we are still in use, decrement init count and get out */
|
|
|
|
if (--_ecore_drm_init_count != 0) return _ecore_drm_init_count;
|
|
|
|
|
2014-09-23 07:34:00 -07:00
|
|
|
/* close eeze */
|
|
|
|
eeze_shutdown();
|
2014-03-06 01:43:48 -08:00
|
|
|
|
2014-07-15 06:28:03 -07:00
|
|
|
/* cleanup dbus */
|
|
|
|
_ecore_drm_dbus_shutdown();
|
2014-03-06 01:43:48 -08:00
|
|
|
|
2014-03-10 01:26:53 -07:00
|
|
|
/* shutdown ecore_event */
|
|
|
|
ecore_event_shutdown();
|
|
|
|
|
|
|
|
/* shutdown ecore */
|
2014-03-06 01:43:48 -08:00
|
|
|
ecore_shutdown();
|
|
|
|
|
|
|
|
/* unregsiter log domain */
|
|
|
|
eina_log_domain_unregister(_ecore_drm_log_dom);
|
|
|
|
_ecore_drm_log_dom = -1;
|
|
|
|
|
|
|
|
/* shutdown eina */
|
|
|
|
eina_shutdown();
|
|
|
|
|
2014-07-15 06:28:03 -07:00
|
|
|
free(sid);
|
|
|
|
|
2014-03-06 01:43:48 -08:00
|
|
|
/* return init count */
|
|
|
|
return _ecore_drm_init_count;
|
|
|
|
}
|