tizen 2.3.1 release
[framework/web/wearable/wrt-security.git] / ace / include / ace-dao-ro / AceDatabase.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    AceDatabase.h
18  * @author  Lukasz Marek (l.marek@samsung.com)
19  * @version 1.0
20  * @brief   This file contains the declaration of ace database
21  */
22
23 #ifndef WRT_ENGINE_SRC_ACCESS_CONTROL_ACE_DATABASE_H
24 #define WRT_ENGINE_SRC_ACCESS_CONTROL_ACE_DATABASE_H
25
26 #include <dpl/thread.h>
27 #include <dpl/mutex.h>
28
29 extern DPL::Mutex g_aceDbQueriesMutex;
30
31 #define ACE_DB_INTERNAL(tlsCommand, InternalType, interface)                 \
32     static DPL::ThreadLocalVariable<InternalType> *tlsCommand ## Ptr = NULL; \
33     {                                                                        \
34         DPL::Mutex::ScopedLock lock(&g_aceDbQueriesMutex);                   \
35         if (!tlsCommand ## Ptr) {                                            \
36             static DPL::ThreadLocalVariable<InternalType> tmp;               \
37             tlsCommand ## Ptr = &tmp;                                        \
38         }                                                                    \
39     }                                                                        \
40     DPL::ThreadLocalVariable<InternalType> &tlsCommand = *tlsCommand ## Ptr; \
41     if (tlsCommand.IsNull()) { tlsCommand = InternalType(interface); }
42
43 #define ACE_DB_SELECT(name, type, interface) \
44     ACE_DB_INTERNAL(name, type::Select, interface)
45
46 #define ACE_DB_INSERT(name, type, interface) \
47     ACE_DB_INTERNAL(name, type::Insert, interface)
48
49 #define ACE_DB_UPDATE(name, type, interface) \
50     ACE_DB_INTERNAL(name, type::Update, interface)
51
52 #define ACE_DB_DELETE(name, type, interface) \
53     ACE_DB_INTERNAL(name, type::Delete, interface)
54
55
56 #endif // WRT_ENGINE_SRC_ACCESS_CONTROL_ACE_DATABASE_H