summaryrefslogtreecommitdiff
path: root/src/lib/eeze/eeze_main.c
blob: 1b2bfc2571b80305683175ec2ed9a18132d0ce1f (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <Ecore.h>
#include <Eeze.h>
#include <Eeze_Disk.h>
#include <Eeze_Sensor.h>
#include "eeze_udev_private.h"
#include "eeze_net_private.h"
#include "eeze_disk_private.h"

_udev *udev;

int _eeze_udev_log_dom = -1;
int _eeze_net_log_dom = -1;
EAPI int _eeze_sensor_log_dom = -1;
int _eeze_init_count = 0;

static Eeze_Version _version = { VMAJ, VMIN, VMIC, VREV };
EAPI Eeze_Version *eeze_version = &_version;

EAPI int
eeze_init(void)
{
   if (++_eeze_init_count != 1)
     return _eeze_init_count;

   if (!eina_init())
     return 0;

   _eeze_udev_log_dom = eina_log_domain_register("eeze_udev", EINA_COLOR_CYAN);
   if (_eeze_udev_log_dom < 0)
     {
        EINA_LOG_ERR("Could not register 'eeze_udev' log domain.");
        goto eina_fail;
     }
   _eeze_net_log_dom = eina_log_domain_register("eeze_net", EINA_COLOR_GREEN);
   if (_eeze_net_log_dom < 0)
     {
        EINA_LOG_ERR("Could not register 'eeze_net' log domain.");
        goto eina_net_fail;
     }

   _eeze_sensor_log_dom = eina_log_domain_register("eeze_sensor", EINA_COLOR_BLUE);
   if (_eeze_sensor_log_dom < 0)
     {
        EINA_LOG_ERR("Could not register 'eeze_sensor' log domain.");
        goto eina_sensor_fail;
     }

   if (!ecore_init())
     goto ecore_fail;
#ifdef HAVE_EEZE_MOUNT
   if (!eeze_disk_init())
     goto eeze_fail;
#endif
   if (!(udev = udev_new()))
     {
        EINA_LOG_ERR("Could not initialize udev library!");
        goto fail;
     }
   if (!eeze_net_init())
     {
        EINA_LOG_ERR("Error initializing eeze_net subsystems!");
        goto net_fail;
     }
   if (!eeze_sensor_init())
     {
        EINA_LOG_ERR("Error initializing eeze_sensor subsystems!");
        goto sensor_fail;
     }

   return _eeze_init_count;

sensor_fail:
   eeze_net_shutdown();
net_fail:
   udev_unref(udev);
fail:
#ifdef HAVE_EEZE_MOUNT
   eeze_disk_shutdown();
eeze_fail:
#endif
   ecore_shutdown();
ecore_fail:
   eina_log_domain_unregister(_eeze_sensor_log_dom);
   _eeze_sensor_log_dom = -1;
eina_sensor_fail:
   eina_log_domain_unregister(_eeze_net_log_dom);
   _eeze_net_log_dom = -1;
eina_net_fail:
   eina_log_domain_unregister(_eeze_udev_log_dom);
   _eeze_udev_log_dom = -1;
eina_fail:
   eina_shutdown();
   return 0;
}

EAPI int
eeze_shutdown(void)
{
   if (_eeze_init_count <= 0)
     {
        EINA_LOG_ERR("Init count not greater than 0 in shutdown.");
        return 0;
     }
   if (--_eeze_init_count != 0)
     return _eeze_init_count;

   udev_unref(udev);
#ifdef HAVE_EEZE_MOUNT
   eeze_disk_shutdown();
#endif
   eeze_sensor_shutdown();
   eeze_net_shutdown();
   ecore_shutdown();
   eina_log_domain_unregister(_eeze_udev_log_dom);
   _eeze_udev_log_dom = -1;
   eina_shutdown();
   return _eeze_init_count;
}