f4a5d17682c69427785732f16fa7a28ed9822403
[platform/core/security/cert-svc.git] / vcore / src / vcore / 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 VCORE_SRC_VCORE_DATABASE_H
23 #define VCORE_SRC_VCORE_DATABASE_H
24
25 #include <dpl/db/thread_database_support.h>
26 #include <dpl/db/sql_connection.h>
27 #include <dpl/thread.h>
28 #include <mutex>
29
30 extern std::mutex g_vcoreDbQueriesMutex;
31
32 #define VCORE_DB_INTERNAL(tlsCommand, InternalType, interface)               \
33     static VcoreDPL::ThreadLocalVariable<InternalType> *tlsCommand ## Ptr = NULL; \
34     {                                                                        \
35         std::lock_guard<std::mutex> lock(g_vcoreDbQueriesMutex);             \
36         if (!tlsCommand ## Ptr) {                                            \
37             static VcoreDPL::ThreadLocalVariable<InternalType> tmp;          \
38             tlsCommand ## Ptr = &tmp;                                        \
39         }                                                                    \
40     }                                                                        \
41     VcoreDPL::ThreadLocalVariable<InternalType> &tlsCommand = *tlsCommand ## Ptr; \
42     if (tlsCommand.IsNull()) { tlsCommand = InternalType(interface); }
43
44 #define VCORE_DB_SELECT(name, type, interface) \
45     VCORE_DB_INTERNAL(name, type::Select, interface)
46
47 #define VCORE_DB_INSERT(name, type, interface) \
48     VCORE_DB_INTERNAL(name, type::Insert, interface)
49
50 #define VCORE_DB_UPDATE(name, type, interface) \
51     VCORE_DB_INTERNAL(name, type::Update, interface)
52
53 #define VCORE_DB_DELETE(name, type, interface) \
54     VCORE_DB_INTERNAL(name, type::Delete, interface)
55
56 #endif // define VCORE_SRC_VCORE_DATABASE_H