2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
18 #include "SystemSettingResponseDispatcher.h"
19 #include <CommonsJavaScript/JSCallbackManager.h>
20 #include <JSTizenException.h>
21 #include <JSTizenExceptionFactory.h>
22 #include <FilesystemUtils.h>
23 #include "SystemSettingAsyncCallbackManager.h"
26 using namespace DeviceAPI::Common;
27 using namespace WrtDeviceApis::Commons;
28 using namespace WrtDeviceApis::CommonsJavaScript;
31 namespace SystemSetting {
33 SystemSettingResponseDispatcher& SystemSettingResponseDispatcher::getInstance()
35 static SystemSettingResponseDispatcher instance;
39 SystemSettingResponseDispatcher::SystemSettingResponseDispatcher() :
40 SystemSettingSetWallpaperEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
41 SystemSettingSetRingtoneEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
42 SystemSettingSetSettingEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
43 SystemSettingGetSettingEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD)
47 SystemSettingResponseDispatcher::~SystemSettingResponseDispatcher()
51 void SystemSettingResponseDispatcher::OnAnswerReceived(const EventSetWallpaperPtr &event)
54 JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
56 if (!callbackManager) {
57 LoggerE("No listener callback!");
61 JSContextRef gContext = callbackManager->getContext();
62 JSValueRef error = NULL;
64 if (ExceptionCodes::None != event->getExceptionCode())
66 switch (event->getExceptionCode())
68 case ExceptionCodes::PlatformException:
69 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
71 case ExceptionCodes::NotFoundException:
72 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
74 case ExceptionCodes::InvalidArgumentException:
75 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "DomainName is not setted");
77 case ExceptionCodes::ConversionException:
78 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
81 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
84 LoggerD("callOnError");
85 callbackManager->callOnError(error);
88 LoggerD("callOnSuccess");
89 callbackManager->callOnSuccess();
93 void SystemSettingResponseDispatcher::OnAnswerReceived(const EventSetRingtonePtr &event)
96 JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
98 if (!callbackManager) {
99 LoggerE("No listener callback!");
103 JSContextRef gContext = callbackManager->getContext();
104 JSValueRef error = NULL;
106 if (ExceptionCodes::None != event->getExceptionCode())
108 switch (event->getExceptionCode())
110 case ExceptionCodes::PlatformException:
111 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
113 case ExceptionCodes::NotFoundException:
114 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
116 case ExceptionCodes::InvalidArgumentException:
117 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "DomainName is not setted");
119 case ExceptionCodes::ConversionException:
120 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
123 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
127 callbackManager->callOnError(error);
130 callbackManager->callOnSuccess();
133 void SystemSettingResponseDispatcher::OnAnswerReceived(const EventSetSettingPtr &event)
136 JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
138 if (!callbackManager) {
139 LoggerE("No listener callback!");
143 JSContextRef gContext = callbackManager->getContext();
144 JSValueRef error = NULL;
146 SystemSettingAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
148 if (ExceptionCodes::None != event->getExceptionCode())
150 switch (event->getExceptionCode())
152 case ExceptionCodes::PlatformException:
153 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
155 case ExceptionCodes::NotFoundException:
156 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
158 case ExceptionCodes::InvalidArgumentException:
159 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "DomainName is not setted");
161 case ExceptionCodes::ConversionException:
162 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
165 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
169 callbackManager->callOnError(error);
172 callbackManager->callOnSuccess();
175 void SystemSettingResponseDispatcher::OnAnswerReceived(const EventGetSettingPtr &event)
178 JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
180 if (!callbackManager) {
181 LoggerE("No listener callback!");
185 JSContextRef gContext = callbackManager->getContext();
186 JSValueRef error = NULL;
188 SystemSettingAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
190 Converter converter(gContext);
192 if (ExceptionCodes::None != event->getExceptionCode())
194 switch (event->getExceptionCode())
196 case ExceptionCodes::PlatformException:
197 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
199 case ExceptionCodes::NotFoundException:
200 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
202 case ExceptionCodes::InvalidArgumentException:
203 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "DomainName is not setted");
205 case ExceptionCodes::ConversionException:
206 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
209 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
213 callbackManager->callOnError(error);
216 LoggerD("gettingValue : " << event->getSettingValue());
218 std::string settingPath = event->getSettingValue();
219 LoggerD("RealSettingPath : " << settingPath);
223 settingPath = DeviceAPI::Filesystem::Utils::toVirtualPath(gContext, settingPath);
224 LoggerD("VirtualSettingPath : " << settingPath);
226 Catch(WrtDeviceApis::Commons::ConversionException) {
227 LoggerD("not the virtual path");
228 LoggerD("RealSettingSettingPath : " << settingPath);
231 if (settingPath.size() == 0)
233 error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
234 callbackManager->callOnError(error);
237 // return converter.toJSValueRef(iconPath);
238 callbackManager->callOnSuccess(converter.toJSValueRef(settingPath));