Merge "Addition of build flag "-Wl,-Bsymbolic-functions" for launching performance...
[platform/core/uifw/dali-core.git] / dali / public-api / common / dali-common.h
1 #ifndef __DALI_COMMON_H__
2 #define __DALI_COMMON_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22
23 #ifdef EMSCRIPTEN
24 #include <emscripten/emscripten.h>
25 #endif
26 /*
27  * Definitions for shared library support
28  *
29  * If a library is configured with --enable-exportall or --enable-debug
30  * then HIDE_DALI_INTERNALS is not defined, and nothing is hidden.
31  * If it is configured without these options (the default), then HIDE_INTERNALS
32  * is defined when building the library, visibility is automatically hidden, and the explicit
33  * defines below come into use.
34  * When building a library that uses DALI, HIDE_DALI_INTERNALS
35  */
36 #if __GNUC__ >= 4
37 #  ifndef HIDE_DALI_INTERNALS
38 #    define DALI_EXPORT_API
39 #    define DALI_IMPORT_API
40 #    define DALI_INTERNAL
41 #  else
42 #    define DALI_EXPORT_API __attribute__ ((visibility ("default")))
43 #    define DALI_IMPORT_API __attribute__ ((visibility ("default")))
44 #    define DALI_INTERNAL   __attribute__ ((visibility ("hidden")))
45 #  endif
46 #else
47 /** Visibility attribute to show method definitions */
48 #  define DALI_EXPORT_API
49 /** Visibility attribute to show declarations */
50 #  define DALI_IMPORT_API
51 /** Visibility attribute to hide declarations */
52 #  define DALI_INTERNAL
53 #endif
54
55 #if defined (__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
56 // C++0x support
57 #define _CPP11
58 #else
59 // C++0x not supported
60 #endif
61
62 #ifdef EMSCRIPTEN
63
64 #ifndef __clang__
65 # error not clang?
66 #endif
67
68 // clang cpp11 check is per feature
69 #if !__has_feature(cxx_constexpr)
70 # error constexpr needed for compile-time-math. Use -std=c+11
71 #endif
72
73 #define _CPP11
74
75 #endif
76
77 /**
78  * @brief The DALi namespace
79  */
80 namespace Dali
81 {
82
83 /**
84  * @brief Method to log assertion message in DALI_ASSERT_ALWAYS macro below.
85  *
86  * @param[in] location Where the assertion occurred
87  * @param[in] condition The assertion condition
88  */
89 DALI_IMPORT_API void DaliAssertMessage( const char* location, const char* condition );
90
91 /**
92  * @brief Exception class for Dali Core library - Raised by assertions in codebase.
93  */
94 class DALI_IMPORT_API DaliException
95 {
96 public:
97   /**
98    * @brief Constructor.
99    *
100    * Will always display a backtrace when raised in a debug build.
101    *
102    * @param[in] location  - the location of the assertion
103    * @param[in] condition - The assertion condition
104    */
105   DaliException( const char* location, const char* condition );
106
107   const char* location;
108   const char* condition;
109 };
110
111 }// Dali
112
113 /**
114  * @brief An invariant concurrent assertion to ensure its argument always evaluates TRUE.
115  *
116  * Use this for rules that must always be true regardless of build options.
117  * For example, Actor must only ever have one parent.
118  * To be clear, this test remains compiled into release builds that are deployed
119  * on the platform.
120  * Semantically, a failure of this test is signalling that dali is giving up and
121  * quitting.
122  * Since we don't catch the exception, a failure on any thread other than event
123  * will propagate up the call stack and kill that thread.
124  * A failure on the event thread may give the application an opportunity to
125  * recover if there is an application-written exception handler on the call
126  * stack between the throw site and the thread root and the application is built
127  * with a compatible ABI.
128  * Handle this macro with care at the level you would if it expanded to:
129  *    if(!cond) { exit(EXIT_FAILURE); }
130  * (which it is often equivalent to in effect).
131  * It should not be used for simple parameter validation for instance.
132  */
133
134 /**
135  * Strip assert location for release builds, assert text is descriptive enough
136  * This is to save space for low spec devices
137  */
138 #if defined(DEBUG_ENABLED)
139 #define ASSERT_LOCATION __PRETTY_FUNCTION__
140 #else
141 #define ASSERT_LOCATION NULL
142 #endif
143
144 #ifdef EMSCRIPTEN
145
146 #define DALI_ASSERT_ALWAYS(cond)                \
147   if(!(cond)) \
148   { \
149     Dali::DaliAssertMessage( ASSERT_LOCATION, #cond );   \
150     throw Dali::DaliException( ASSERT_LOCATION, #cond );  \
151     EM_ASM(print(new Error().stack)); \
152   }
153 #else
154
155 #define DALI_ASSERT_ALWAYS(cond)                \
156   if(!(cond)) \
157   { \
158     Dali::DaliAssertMessage( ASSERT_LOCATION, #cond );   \
159     throw Dali::DaliException( ASSERT_LOCATION, #cond );  \
160   }
161 #endif
162
163 /**
164  * @brief An invariant concurrent assertion to ensure its argument evaluates TRUE in debug builds.
165  *
166  * Use this to sanity check algorithms and prevent internal programming errors
167  */
168 #if defined(DEBUG_ENABLED)
169 #define DALI_ASSERT_DEBUG(cond) DALI_ASSERT_ALWAYS(cond)
170 #else
171 #define DALI_ASSERT_DEBUG(cond)
172 #endif
173
174 #endif // __DALI_COMMON_H__