Revert "[Tizen] Add codes for Dali Windows Backend"
[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) 2018 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 /*
24  * Definitions for shared library support.
25  *
26  * If a library is configured with --enable-exportall or --enable-debug
27  * then HIDE_DALI_INTERNALS is not defined, and nothing is hidden.
28  * If it is configured without these options (the default), then HIDE_INTERNALS
29  * is defined when building the library, visibility is automatically hidden, and the explicit
30  * defines below come into use.
31  * When building a library that uses DALI, HIDE_DALI_INTERNALS.
32  */
33 #if __GNUC__ >= 4
34 #  ifndef HIDE_DALI_INTERNALS
35 #    define DALI_EXPORT_API
36 #    define DALI_IMPORT_API
37 #    define DALI_CORE_API
38 #    define DALI_INTERNAL
39 #  else
40 #    define DALI_EXPORT_API __attribute__ ((visibility ("default")))
41 #    define DALI_IMPORT_API __attribute__ ((visibility ("default")))
42 #    define DALI_CORE_API   __attribute__ ((visibility ("default")))
43 #    define DALI_INTERNAL   __attribute__ ((visibility ("hidden")))
44 #  endif
45 #else
46 /** Visibility attribute to show method definitions */
47 #  define DALI_EXPORT_API
48 /** Visibility attribute to show declarations */
49 #  define DALI_IMPORT_API
50 /** Visibility attribute to show declarations */
51 #  define DALI_CORE_API
52 /** Visibility attribute to hide declarations */
53 #  define DALI_INTERNAL
54 #endif
55
56 #ifdef DEPRECATION_WARNING
57 #define DALI_DEPRECATED_API __attribute__((__visibility__("default"), deprecated))
58 #else
59 #define DALI_DEPRECATED_API
60 #endif
61
62 #if defined (__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
63 // C++0x support
64 #define _CPP11
65 #else
66 // C++0x not supported
67 #endif
68
69 /**
70  * @brief Two macros to provide branch predictor information.
71  * DALI_LIKELY should be used when a branch is taken in almost all cases so the
72  * branch predictor can avoid pre-fetching. The code for else branch
73  * DALI_UNLIKELY should be used when a branch is almost never taken.
74  * @SINCE_1_0.0
75  */
76 #define DALI_LIKELY(expression)   __builtin_expect( !!(expression), 1 )
77 #define DALI_UNLIKELY(expression) __builtin_expect( !!(expression), 0 )
78
79 /**
80  * @brief The DALi namespace.
81  * @SINCE_1_0.0
82  */
83 namespace Dali
84 {
85 /**
86  * @addtogroup dali_core_common
87  * @{
88  */
89
90 /**
91  * @brief Method to log assertion message in DALI_ASSERT_ALWAYS macro below.
92  *
93  * @SINCE_1_0.0
94  * @param[in] location Where the assertion occurred
95  * @param[in] condition The assertion condition
96  */
97 DALI_CORE_API void DaliAssertMessage( const char* location, const char* condition );
98
99 /**
100  * @brief Exception class for Dali Core library - Raised by assertions in codebase.
101  * @SINCE_1_0.0
102  */
103 class DALI_CORE_API DaliException
104 {
105 public:
106   /**
107    * @brief Constructor.
108    *
109    * Will always display a backtrace when raised in a debug build.
110    *
111    * @SINCE_1_0.0
112    * @param[in] location The location of the assertion
113    * @param[in] condition The assertion condition
114    */
115   DaliException( const char* location, const char* condition );
116
117   const char* location;
118   const char* condition;
119 };
120
121 /**
122  * @}
123  */
124 }// Dali
125
126 /**
127  * @brief An invariant concurrent assertion to ensure its argument always evaluates TRUE.
128  *
129  * Use this for rules that must always be true regardless of build options.
130  * For example, Actor must only ever have one parent.
131  * To be clear, this test remains compiled into release builds that are deployed
132  * on the platform.
133  * Semantically, a failure of this test is signalling that dali is giving up and
134  * quitting.
135  * Since we don't catch the exception, a failure on any thread other than event
136  * will propagate up the call stack and kill that thread.
137  * A failure on the event thread may give the application an opportunity to
138  * recover if there is an application-written exception handler on the call
139  * stack between the throw site and the thread root and the application is built
140  * with a compatible ABI.
141  * Handle this macro with care at the level you would if it expanded to:
142  *    if(!cond) { exit(EXIT_FAILURE); }
143  * (which it is often equivalent to in effect).
144  * It should not be used for simple parameter validation for instance.
145  */
146
147 /**
148  * @brief Strip assert location for release builds, assert text is descriptive enough.
149  * This is to save space for low spec devices.
150  * @SINCE_1_0.0
151  */
152 #if defined(DEBUG_ENABLED)
153 #define ASSERT_LOCATION __PRETTY_FUNCTION__
154 #else
155 #define ASSERT_LOCATION NULL
156 #endif
157
158 #define DALI_ASSERT_ALWAYS(cond)                \
159   if(DALI_UNLIKELY(!(cond))) \
160   { \
161     Dali::DaliAssertMessage( ASSERT_LOCATION, #cond );   \
162     throw Dali::DaliException( ASSERT_LOCATION, #cond );  \
163   }
164
165 #define DALI_ABORT(message)                \
166   { \
167     Dali::DaliAssertMessage( ASSERT_LOCATION, message );   \
168     throw Dali::DaliException( ASSERT_LOCATION, message );  \
169   }
170
171 /**
172  * @brief An invariant concurrent assertion to ensure its argument evaluates TRUE in debug builds.
173  *
174  * Use this to sanity check algorithms and prevent internal programming errors.
175  * @SINCE_1_0.0
176  */
177 #if defined(DEBUG_ENABLED)
178 #define DALI_ASSERT_DEBUG(cond) DALI_ASSERT_ALWAYS(cond)
179 #else
180 #define DALI_ASSERT_DEBUG(cond)
181 #endif
182
183 #endif // __DALI_COMMON_H__