tizen 2.4 release
[framework/web/wrt-commons.git] / modules / widget_dao / include / dpl / wrt-dao-ro / webruntime_database.h
1 /*
2  * Copyright (c) 2011 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  * @file    webruntime_database.h
18  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version 1.0
20  * @brief   This file contains the declaration of webruntime database
21  */
22 #ifndef WRT_ENGINE_SRC_CONFIGURATION_WEBRUNTIME_DATABASE_H
23 #define WRT_ENGINE_SRC_CONFIGURATION_WEBRUNTIME_DATABASE_H
24
25 #include <dpl/thread.h>
26 #include <mutex>
27
28 extern std::mutex g_wrtDbQueriesMutex;
29
30 #define WRT_DB_INTERNAL(tlsCommand, InternalType, interface)                  \
31     static DPL::ThreadLocalVariable<InternalType> *tlsCommand##Ptr = NULL;    \
32     {                                                                         \
33         std::lock_guard<std::mutex> lock(g_wrtDbQueriesMutex);                \
34         if (!tlsCommand##Ptr) {                                               \
35             static DPL::ThreadLocalVariable<InternalType> tmp;                \
36             tlsCommand##Ptr = &tmp;                                           \
37         }                                                                     \
38     }                                                                         \
39     DPL::ThreadLocalVariable<InternalType> &tlsCommand = *tlsCommand##Ptr;    \
40     if (!tlsCommand) { tlsCommand = InternalType(interface); }
41
42 #define WRT_DB_SELECT(name, type, interface) WRT_DB_INTERNAL(name,            \
43                                                              type::Select,    \
44                                                              interface)
45
46 #define WRT_DB_INSERT(name, type, interface) WRT_DB_INTERNAL(name,            \
47                                                              type::Insert,    \
48                                                              interface)
49
50 #define WRT_DB_UPDATE(name, type, interface) WRT_DB_INTERNAL(name,            \
51                                                              type::Update,    \
52                                                              interface)
53
54 #define WRT_DB_DELETE(name, type, interface) WRT_DB_INTERNAL(name,            \
55                                                              type::Delete,    \
56                                                              interface)
57
58 #endif // WRT_ENGINE_SRC_CONFIGURATION_WEBRUNTIME_DATABASE_H