summaryrefslogtreecommitdiff
path: root/src/lib/embryo/embryo_main.c
blob: 4b2af3c5e554119e5aa0e944d7ad3ce38608278f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "Embryo.h"
#include "embryo_private.h"

static Embryo_Version _version = { VMAJ, VMIN, VMIC, VREV };
EAPI Embryo_Version * embryo_version = &_version;

static int _embryo_init_count = 0;
int _embryo_default_log_dom = -1;

/*** EXPORTED CALLS ***/

EAPI int
embryo_init(void)
{
   if (++_embryo_init_count != 1)
     return _embryo_init_count;

   srand(time(NULL));

   if (!eina_init())
     return --_embryo_init_count;

   _embryo_default_log_dom = eina_log_domain_register
       ("embryo", EMBRYO_DEFAULT_LOG_COLOR);
   if (_embryo_default_log_dom < 0)
     {
        EINA_LOG_ERR("Embryo Can not create a general log domain.");
        goto shutdown_eina;
     }

   eina_log_timing(_embryo_default_log_dom,
                   EINA_LOG_STATE_STOP,
                   EINA_LOG_STATE_INIT);

   return _embryo_init_count;

shutdown_eina:
   eina_shutdown();
   return --_embryo_init_count;
}

EAPI int
embryo_shutdown(void)
{
   if (_embryo_init_count <= 0)
     {
        printf("%s:%i Init count not greater than 0 in shutdown.", __FUNCTION__, __LINE__);
        return 0;
     }
   if (--_embryo_init_count != 0)
     return _embryo_init_count;

   eina_log_timing(_embryo_default_log_dom,
                   EINA_LOG_STATE_START,
                   EINA_LOG_STATE_SHUTDOWN);

   eina_log_domain_unregister(_embryo_default_log_dom);
   _embryo_default_log_dom = -1;
   eina_shutdown();

   return _embryo_init_count;
}