Tizen 2.1 base
[framework/web/wrt-commons.git] / modules / vcore / src / vcore / VCore.cpp
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        VCore.cpp
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @brief
20  */
21
22 #include <vcore/VCorePrivate.h>
23 #include <vcore/Config.h>
24 #include <vcore/Database.h>
25 #include <openssl/ssl.h>
26 #include <database_checksum_vcore.h>
27 #include <glib.h>
28 #include <glib-object.h>
29
30 namespace {
31 DPL::DB::ThreadDatabaseSupport threadInterface(
32     VCoreDatabaseConnectionTraits::Address(),
33     VCoreDatabaseConnectionTraits::Flags());
34 } // namespace anonymous
35
36 namespace ValidationCore {
37
38 void AttachToThread(void){
39     threadInterface.AttachToThread();
40 }
41
42 void DetachFromThread(void){
43     threadInterface.DetachFromThread();
44 }
45
46 DPL::DB::ThreadDatabaseSupport& ThreadInterface(void) {
47     return threadInterface;
48 }
49
50 bool VCoreInit(const std::string& configFilePath,
51                const std::string& configSchemaPath,
52                const std::string& databasePath)
53 {
54     SSL_library_init();
55     g_thread_init(NULL);
56     g_type_init();
57
58     LogDebug("Initializing VCore");
59     Config &globalConfig = ConfigSingleton::Instance();
60     bool returnValue = globalConfig.setXMLConfigPath(configFilePath) &&
61         globalConfig.setXMLSchemaPath(configSchemaPath) &&
62         globalConfig.setDatabasePath(databasePath);
63
64     Assert(ThreadInterface().CheckTableExist(DB_CHECKSUM_STR) &&
65            "Not a valid vcore database version");
66
67     return returnValue;
68 }
69
70 } // namespace ValidationCore
71