2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _SECURITY_ORIGIN_DATABASE_H_
18 #define _SECURITY_ORIGIN_DATABASE_H_
20 #include <dpl/thread.h>
21 #include <dpl/mutex.h>
23 extern DPL::Mutex g_securityOriginDBQueriesMutex;
25 #define SECURITY_ORIGIN_DB_INTERNAL(tlsCommand, InternalType, interface) \
26 static DPL::ThreadLocalVariable<InternalType> *tlsCommand ## Ptr = NULL; \
28 DPL::Mutex::ScopedLock lock(&g_securityOriginDBQueriesMutex); \
29 if (!tlsCommand ## Ptr) { \
30 static DPL::ThreadLocalVariable<InternalType> tmp; \
31 tlsCommand ## Ptr = &tmp; \
34 DPL::ThreadLocalVariable<InternalType> &tlsCommand = *tlsCommand ## Ptr; \
35 if (tlsCommand.IsNull()) { tlsCommand = InternalType(interface); }
37 #define SECURITY_ORIGIN_DB_SELECT(name, type, interface) \
38 SECURITY_ORIGIN_DB_INTERNAL(name, type::Select, interface)
40 #define SECURITY_ORIGIN_DB_INSERT(name, type, interface) \
41 SECURITY_ORIGIN_DB_INTERNAL(name, type::Insert, interface)
43 #define SECURITY_ORIGIN_DB_UPDATE(name, type, interface) \
44 SECURITY_ORIGIN_DB_INTERNAL(name, type::Update, interface)
46 #define SECURITY_ORIGIN_DB_DELETE(name, type, interface) \
47 SECURITY_ORIGIN_DB_INTERNAL(name, type::Delete, interface)
49 #endif // _SECURITY_ORIGIN_DATABASE_H_