Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_mobile / i18n / dao / include / wrt-commons / i18n-dao-ro / i18n_database.h
1 /*
2  * Copyright (c) 2012 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 #ifndef _I18N_DATABASE_H_
18 #define _I18N_DATABASE_H_
19
20 #include <dpl/thread.h>
21 #include <dpl/mutex.h>
22 #include <dpl/db/thread_database_support.h>
23
24 namespace I18n {
25 namespace DB {
26 namespace Interface {
27 void attachDatabaseRO();
28 void detachDatabase();
29
30 extern DPL::Mutex g_dbQueriesMutex;
31 extern DPL::DB::ThreadDatabaseSupport g_dbInterface;
32 } // namespace Interface
33 } // namespace DB
34 } // namespace I18n
35
36 #define I18N_DB_INTERNAL(tlsCommand, InternalType)                             \
37     static DPL::ThreadLocalVariable<InternalType> *tlsCommand##Ptr = NULL;     \
38     {                                                                          \
39         DPL::Mutex::ScopedLock lock(                                           \
40             &I18n::DB::Interface::g_dbQueriesMutex);                           \
41         if (!tlsCommand##Ptr) {                                                \
42             static DPL::ThreadLocalVariable<InternalType> tmp;                 \
43             tlsCommand##Ptr = &tmp;                                            \
44         }                                                                      \
45     }                                                                          \
46     DPL::ThreadLocalVariable<InternalType> &tlsCommand = *tlsCommand##Ptr;     \
47     if (tlsCommand.IsNull())                                                   \
48     {                                                                          \
49         tlsCommand = InternalType(&I18n::DB::Interface::g_dbInterface);        \
50     }
51
52 #define I18N_DB_SELECT(name, type) \
53     I18N_DB_INTERNAL(name, type::Select)
54
55 #endif /* _I18N_DATABASE_H_ */
56