b28a21db82c86b45461503296ec82698036a1299
[platform/core/uifw/efl-assist.git] / src / lib / efl_assist.c
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 #include "efl_assist.h"
19 #include "efl_assist_private.h"
20
21 /*===========================================================================*
22  *                                 Local                                     *
23  *===========================================================================*/
24
25 Ea _ea;
26
27 static void
28 ea_init(void)
29 {
30    memset(&_ea, 0x00, sizeof(_ea));
31
32    _ea.ea_log_dom = eina_log_domain_register("efl-assist",
33                                              EINA_COLOR_LIGHTBLUE);
34    if (!_ea.ea_log_dom)
35      {
36         EINA_LOG_ERR("could not register efl-assist log domain");
37         _ea.ea_log_dom = EINA_LOG_DOMAIN_GLOBAL;
38      }
39 }
40
41 static void
42 ea_shutdown(void)
43 {
44    Eina_List *l;
45    Ea_Event_Mgr *event_mgr;
46
47    //Remove Event Managers
48    EINA_LIST_FOREACH(_ea.event_mgrs, l, event_mgr)
49      ea_event_mgr_clear(event_mgr);
50    _ea.event_mgrs = eina_list_free(_ea.event_mgrs);
51
52    if ((_ea.ea_log_dom > - 1) && (_ea.ea_log_dom != EINA_LOG_DOMAIN_GLOBAL))
53      {
54         eina_log_domain_unregister(_ea.ea_log_dom);
55         _ea.ea_log_dom = -1;
56      }
57 }
58
59 static const char *
60 _magic_string_get(ea_magic m)
61 {
62         switch (m) {
63         case EA_MAGIC_NONE:
64                 return "None (Freed Object)";
65
66         case EA_MAGIC_CUTLINK:
67                 return "cutlink";
68
69         default:
70                 return "<UNKNOWN>";
71      }
72 }
73
74 __CONSTRUCTOR__ static void
75 ea_mod_init(void)
76 {
77         ea_init();
78
79         DBG("loaded");
80 }
81
82 __DESTRUCTOR__ static void
83 ea_mod_shutdown(void)
84 {
85         DBG("unloaded");
86
87         ea_shutdown();
88 }
89
90
91 /*===========================================================================*
92  *                                Global                                     *
93  *===========================================================================*/
94
95 void
96 _ea_magic_fail(const void *d, ea_magic m, ea_magic req_m, const char *fname)
97 {
98         ERR("\n*** MAGIC FAIL (%s) ***\n", fname);
99
100         if (!d)
101                 ERR("  Input handle pointer is NULL!");
102         else if (m == EA_MAGIC_NONE)
103                 ERR("  Input handle has already been freed!");
104         else if (m != req_m)
105                 ERR("  Input handle is wrong type\n"
106                     "    Expected: %08x - %s\n"
107                     "    Supplied: %08x - %s",
108                     (unsigned int)req_m, _magic_string_get(req_m),
109                     (unsigned int)m, _magic_string_get(m));
110
111    if (getenv("EA_ERROR_ABORT")) abort();
112 }
113
114 /*===========================================================================*
115  *                                  API                                      *
116  *===========================================================================*/
117