2 * Copyright (c) 2012 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 _CUSTOM_HANDLER_DATABASE_H_
18 #define _CUSTOM_HANDLER_DATABASE_H_
20 #include <dpl/thread.h>
21 #include <dpl/mutex.h>
22 #include <dpl/db/thread_database_support.h>
24 namespace CustomHandlerDB {
26 void attachDatabaseRO();
27 void attachDatabaseRW();
28 void detachDatabase();
30 extern DPL::Mutex g_dbQueriesMutex;
31 extern DPL::DB::ThreadDatabaseSupport g_dbInterface;
32 } // namespace Interface
33 } // namespace CustomHandlerDB
35 #define CUSTOM_HANDLER_DB_INTERNAL(tlsCommand, InternalType) \
36 static DPL::ThreadLocalVariable<InternalType> *tlsCommand##Ptr = NULL; \
38 DPL::Mutex::ScopedLock lock( \
39 &CustomHandlerDB::Interface::g_dbQueriesMutex); \
40 if (!tlsCommand##Ptr) { \
41 static DPL::ThreadLocalVariable<InternalType> tmp; \
42 tlsCommand##Ptr = &tmp; \
45 DPL::ThreadLocalVariable<InternalType> &tlsCommand = *tlsCommand##Ptr; \
46 if (tlsCommand.IsNull()) \
48 tlsCommand = InternalType(&CustomHandlerDB::Interface::g_dbInterface); \
51 #define CUSTOM_HANDLER_DB_SELECT(name, type) \
52 CUSTOM_HANDLER_DB_INTERNAL(name, type::Select)
54 #define CUSTOM_HANDLER_DB_INSERT(name, type) \
55 CUSTOM_HANDLER_DB_INTERNAL(name, type::Insert)
57 #define CUSTOM_HANDLER_DB_UPDATE(name, type) \
58 CUSTOM_HANDLER_DB_INTERNAL(name, type::Update)
60 #define CUSTOM_HANDLER_DB_DELETE(name, type) \
61 CUSTOM_HANDLER_DB_INTERNAL(name, type::Delete)
63 #endif /* _CUSTOM_HANDLER_DATABASE_H_ */