[Release] wrt_0.8.225
[platform/framework/web/wrt.git] / src / domain / prepare_external_storage.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       prepare_external_storage.cpp
18  * @author     Soyoung Kim (sy037.kim@samsung.com)
19  * @version    1.0
20  */
21
22 #include "prepare_external_storage.h"
23 #include <dpl/assert.h>
24 #include <dpl/log/log.h>
25 #include <dpl/singleton_impl.h>
26
27 IMPLEMENT_SINGLETON(PrepareExternalStorage)
28
29 PrepareExternalStorage::PrepareExternalStorage() :
30     m_handle(NULL),
31     m_pkdIdStr("") {
32 }
33
34 PrepareExternalStorage::~PrepareExternalStorage()
35 {
36     Deinitialize();
37 }
38
39 void PrepareExternalStorage::Initialize(const DPL::String &pkgId)
40 {
41     m_pkdIdStr = DPL::ToUTF8String(pkgId);
42     const char* id = m_pkdIdStr.c_str();
43
44     if (APP2EXT_SD_CARD == app2ext_get_app_location(id) && (NULL == m_handle))
45     {
46         m_handle = app2ext_init(APP2EXT_SD_CARD);
47         if (m_handle) {
48             int ret = m_handle->interface.enable(id);
49             if (0 < ret) {
50                 LogError("app2ext enable failed : " << ret);
51             } else {
52                 LogDebug("app2ext enable success");
53             }
54         } else {
55             LogError("app2ext init failed");
56         }
57     }
58 }
59
60 void PrepareExternalStorage::Deinitialize()
61 {
62     if (NULL != m_handle) {
63         if (0 < m_handle->interface.disable(m_pkdIdStr.c_str())) {
64             LogError("app2ext disable failed");
65         }
66         m_handle = NULL;
67     }
68 }