3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.tizenopensource.org/license
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
24 #include "AppConfig.h"
25 #include "SafeMacros.h"
27 #define SECT_MEDIA L"sectMedia"
28 #define ENTRY_HTTP_AUDIO0 L"entryHttpAudio0"
29 #define ENTRY_HTTP_VIDEO0 L"entryHttpVideo0"
30 #define ENTRY_RTSP_AUDIO0 L"entryRtspAudio0"
31 #define ENTRY_RTSP_VIDEO0 L"entryRtspVideo0"
33 using namespace Osp::Base;
34 using namespace Osp::Io;
35 using namespace Osp::App;
37 AppConfig* AppConfig::__pInst = null;
38 AutoDeleteT< AppConfig > AppConfig::__autoDelete(&AppConfig::__pInst);
41 AppConfig::AppConfig()
45 AppConfig::~AppConfig()
50 AppConfig::Construct(const Osp::Base::String& configFile)
53 r = __reg.Construct(configFile, false);
54 TryReturn(r == E_SUCCESS, r , "Constructor failed: %s", GetErrorMessage(r));
55 __contentRoot = App::GetInstance()->GetAppRootPath() + GetString(L"global", L"ContentRoot");
60 AppConfig::GetInstance(void)
65 __pInst = new (std::nothrow) AppConfig();
66 r = __pInst->Construct(App::GetInstance()->GetAppRootPath() + L"data/config.ini");
67 TryCatch(r == E_SUCCESS, , "pInst->Construct failed:%s", GetErrorMessage(r));
70 AppLog("Get Instance done");
74 AppLog("Get Instance failed");
81 AppConfig::ShowAllTc(void)
86 r = __reg.GetValue(L"global", L"ShowAll", showAll);
87 TryReturn(r == E_SUCCESS, false, "GetValue failed: %s", GetErrorMessage(r));
99 AppConfig::GetTcEnabled(const Osp::Base::String& name) const
101 result r = E_SUCCESS;
103 r = __reg.GetValue(L"tclist", name, ret);
120 AppConfig::GetValue(const Osp::Base::String& section, const Osp::Base::String& key, int& val) const
122 return __reg.GetValue(section, key, val);
126 AppConfig::SetValue(const Osp::Base::String& section, const Osp::Base::String& key, int val)
128 result r = E_SUCCESS;
130 r = __reg.SetValue(section, key, val);
131 if (r == E_KEY_NOT_FOUND)
133 r = __reg.AddValue(section, key, val);
140 AppConfig::SetValue(const Osp::Base::String& section, const Osp::Base::String& key, const Osp::Base::String val)
142 result r = E_SUCCESS;
144 r = __reg.SetValue(section, key, val);
145 if (r == E_KEY_NOT_FOUND)
147 r = __reg.AddValue(section, key, val);
153 const Osp::Base::Collection::IList*
154 AppConfig::GetTsListN(void) const
156 String tsList = GetString("tclist", "tslist");
157 Osp::Base::Utility::StringTokenizer strTok(tsList, "|");
158 Osp::Base::Collection::ArrayList* pList = new (std::nothrow) Osp::Base::Collection::ArrayList();
161 TryCatch(pList, , "ArrayList alloc failed:%s", GetErrorMessage(GetLastResult()));
162 TryCatch(strTok.GetTokenCount() != 0, , "token count is 0");
164 while (strTok.HasMoreTokens())
166 strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
167 if (!token.IsEmpty())
169 pList->Add(*(new String(token)));
183 AppConfig::GetString(const Osp::Base::String& sectString, const Osp::Base::String& entryString) const
185 result r = E_SUCCESS;
188 AppLog("before sectString is %ls, entryString is %ls",sectString.GetPointer(),entryString.GetPointer());
190 r = __reg.GetValue(sectString, entryString, retValue);
193 AppLog("reg.GetValue failed:%s", GetErrorMessage(r));
206 AppConfig::GetMediaStremingUri(const AppConfig::MediaStreamingType streamingType) const
208 result r = E_SUCCESS;
212 switch (streamingType)
215 retValue = GetString(SECT_MEDIA, ENTRY_HTTP_AUDIO0);
219 retValue = GetString(SECT_MEDIA, ENTRY_HTTP_VIDEO0);
223 retValue = GetString(SECT_MEDIA, ENTRY_RTSP_AUDIO0);
227 retValue = GetString(SECT_MEDIA, ENTRY_RTSP_VIDEO0);
234 AppLog("Return Value : %ls", retValue.GetPointer());
241 AppConfig::GetContentPath(const Osp::Base::String& sectString, const Osp::Base::String& entryString) const
247 path = GetString(sectString, entryString);
249 if (path.StartsWith("http:", 0) || path.StartsWith("rtsp:", 0))
253 else if (path.StartsWith("buffer:", 0))
255 path.SubString(sizeof("buffer:") - 1, tmp);
257 str += __contentRoot + tmp;
260 str = __contentRoot + path;
266 AppConfig::GetContentPath(const Osp::Base::String& sectString, const char* format, ...) const
272 va_start(ap, format);
273 vsnprintf(text, sizeof(text), format, ap);
276 return GetContentPath(sectString, keyStr);
280 AppConfig::GetString(const Osp::Base::String& sectString, const char* pFormat, ...) const
285 AppLog("sectString is %ls",sectString.GetPointer());
287 va_start(ap, pFormat);
288 vsnprintf(text, sizeof(text), pFormat, ap);
291 return GetString(sectString, keyStr);
296 AppConfig::GetInt(int defaultVal, const Osp::Base::String& sec, const Osp::Base::String& key) const
299 result r = E_SUCCESS;
300 r = GetValue(sec, key, val);
309 AppConfig::GetInt(int defaultVal, const Osp::Base::String& sec, const char* format, ...) const
315 va_start(ap, format);
316 vsnprintf(text, sizeof(text), format, ap);
319 return GetInt(defaultVal, sec, keyStr);
323 AppConfig::GetValue(const Osp::Base::String& section, const Osp::Base::String& key, Osp::Base::ByteBuffer& retVal) const
325 result r = __reg.GetValue(section, key, retVal);
329 int size = retVal.GetCapacity();
330 memset((byte*) retVal.GetPointer(), 0, size);