2bfa7fd6a1d133205f71ae67821e1a8c28fbeabb
[platform/framework/web/wrt.git] / src / view / common / application_data.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    application_data.cpp
18  * @author  Yunchan Cho (yunchan.cho@samsung.com)
19  * @version 1.0
20  * @brief   implementation file for application_data.h
21  */
22
23 #include "application_data.h"
24 #include <dpl/singleton_impl.h>
25 #include <dpl/log/log.h>
26 #include <bundle.h>
27
28 IMPLEMENT_SINGLETON(ApplicationData)
29
30 ApplicationData::ApplicationData() :
31     m_originBundle(NULL),
32     m_encodedBundle(NULL)
33 {
34 }
35
36 ApplicationData::~ApplicationData()
37 {
38 }
39
40 bundle* ApplicationData::getBundle() const
41 {
42     return m_originBundle;
43 }
44
45 const char* ApplicationData::getEncodedBundle() const
46 {
47     return (const char *)m_encodedBundle;
48 }
49
50 bool ApplicationData::setBundle(bundle *originBundle)
51 {
52     if (!originBundle)
53     {
54         LogError("Bundle is empty!");
55         return false;
56     }
57
58     freeBundle();
59
60     m_originBundle = originBundle;
61     return true;
62 }
63
64 bool ApplicationData::setEncodedBundle(bundle* originBundle)
65 {
66     int len, ret;
67     if (!originBundle)
68     {
69         LogError("Bundle is empty!");
70         return false;
71     }
72
73     freeEncodedBundle();
74
75     ret = bundle_encode(originBundle, &m_encodedBundle, &len);
76     if(ret == -1)
77     {
78         LogError("Failed to encode bundle data");
79         return false;
80     }
81
82     LogInfo("Encoded Bundle : " << m_encodedBundle);
83     return true;
84 }
85
86 void ApplicationData::freeBundle()
87 {
88     if (!m_originBundle)
89     {
90         return;
91     }
92
93     if(!bundle_free(m_originBundle))
94     {
95         LogDebug("Bundle data freed for new bundle data");
96         m_originBundle = NULL;
97     }
98 }
99
100 void ApplicationData::freeEncodedBundle()
101 {
102     if (!m_encodedBundle)
103     {
104         return;
105     }
106
107     if(m_encodedBundle)
108     {
109         if(!bundle_free_encoded_rawdata(
110                     &m_encodedBundle))
111         {
112             LogDebug("Bundle data freed for new bundle data");
113             m_encodedBundle = NULL;
114         }
115     }
116 }
117