e4fc832c65e58d44322fb1702d13d111f1a5a7d7
[platform/framework/web/wrt.git] / src / view / common / view_logic_storage_support.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    view_logic_storage_support.cpp
18  * @author  Pawel Sikorski (p.sikorski@samsung.com)
19  * @brief   Implementation file of StorageSupport API used by ViewLogic
20  */
21 #include "view_logic_storage_support.h"
22
23 #include <string>
24 #include <dpl/assert.h>
25 #include <dpl/exception.h>
26 #include <dpl/log/log.h>
27 #include <dpl/string.h>
28 #include <dpl/utils/wrt_utility.h>
29 #include <widget_model.h>
30
31 namespace ViewModule {
32 namespace StorageSupport {
33
34 namespace
35 { //anonymous
36     const mode_t TEMPORARY_STORAGE_MODE = 0700;
37 }
38
39 void initializeStorage(WidgetModel *widgetModel)
40 {
41     LogDebug("initializeStorage");
42     Assert(widgetModel && "Passed widgetModel is NULL!");
43
44     // create temporary storage
45     std::string path =
46             DPL::ToUTF8String(widgetModel->TemporaryStoragePath.Get());
47     if(!WrtUtilMakeDir(path, TEMPORARY_STORAGE_MODE)){
48         ThrowMsg(DPL::CommonException::InternalError,
49                    "Fail to initialize temporary storage");
50     }
51 }
52
53 void deinitializeStorage(WidgetModel *widgetModel)
54 {
55     LogDebug("deinitializeStorage");
56     Assert(widgetModel && "Passed widgetModel is NULL!");
57
58     // remove temporary storage
59     std::string path =
60             DPL::ToUTF8String(widgetModel->TemporaryStoragePath.Get());
61     if(!WrtUtilRemove(path)){
62         ThrowMsg(DPL::CommonException::InternalError,
63                    "Fail to deinitialize temporary storage");
64     }
65 }
66
67 } // namespace StorageSupport
68 } // namespace ViewModule