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 <JSWebAPIErrorFactory.h>
21 #include <FilesystemUtils.h>
22 #include "SystemSettingAsyncCallbackManager.h"
25 using namespace DeviceAPI::Common;
26 using namespace WrtDeviceApis::Commons;
27 using namespace WrtDeviceApis::CommonsJavaScript;
30 namespace SystemSetting {
32 SystemSettingResponseDispatcher& SystemSettingResponseDispatcher::getInstance()
34 static SystemSettingResponseDispatcher instance;
38 SystemSettingResponseDispatcher::SystemSettingResponseDispatcher() :
39 SystemSettingSetWallpaperEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
40 SystemSettingSetRingtoneEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
41 SystemSettingSetSettingEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
42 SystemSettingGetSettingEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD)
46 SystemSettingResponseDispatcher::~SystemSettingResponseDispatcher()
50 void SystemSettingResponseDispatcher::OnAnswerReceived(const EventSetWallpaperPtr &event)
53 JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
55 if (!callbackManager) {
56 LoggerE("No listener callback!");
60 JSContextRef gContext = callbackManager->getContext();
61 JSValueRef error = NULL;
63 if (ExceptionCodes::None != event->getExceptionCode())
65 switch (event->getExceptionCode())
67 case ExceptionCodes::PlatformException:
68 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
70 case ExceptionCodes::NotFoundException:
71 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "record not found");
73 case ExceptionCodes::InvalidArgumentException:
74 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "DomainName is not setted");
76 case ExceptionCodes::ConversionException:
77 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong argument");
80 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown error");
83 LoggerD("callOnError");
84 callbackManager->callOnError(error);
87 LoggerD("callOnSuccess");
88 callbackManager->callOnSuccess();
92 void SystemSettingResponseDispatcher::OnAnswerReceived(const EventSetRingtonePtr &event)
95 JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
97 if (!callbackManager) {
98 LoggerE("No listener callback!");
102 JSContextRef gContext = callbackManager->getContext();
103 JSValueRef error = NULL;
105 if (ExceptionCodes::None != event->getExceptionCode())
107 switch (event->getExceptionCode())
109 case ExceptionCodes::PlatformException:
110 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
112 case ExceptionCodes::NotFoundException:
113 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "record not found");
115 case ExceptionCodes::InvalidArgumentException:
116 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "DomainName is not setted");
118 case ExceptionCodes::ConversionException:
119 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong argument");
122 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown error");
126 callbackManager->callOnError(error);
129 callbackManager->callOnSuccess();
132 void SystemSettingResponseDispatcher::OnAnswerReceived(const EventSetSettingPtr &event)
135 JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
137 if (!callbackManager) {
138 LoggerE("No listener callback!");
142 JSContextRef gContext = callbackManager->getContext();
143 JSValueRef error = NULL;
145 SystemSettingAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
147 if (ExceptionCodes::None != event->getExceptionCode())
149 switch (event->getExceptionCode())
151 case ExceptionCodes::PlatformException:
152 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
154 case ExceptionCodes::NotFoundException:
155 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "record not found");
157 case ExceptionCodes::InvalidArgumentException:
158 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "DomainName is not setted");
160 case ExceptionCodes::ConversionException:
161 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong argument");
164 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown error");
168 callbackManager->callOnError(error);
171 callbackManager->callOnSuccess();
174 void SystemSettingResponseDispatcher::OnAnswerReceived(const EventGetSettingPtr &event)
177 JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
179 if (!callbackManager) {
180 LoggerE("No listener callback!");
184 JSContextRef gContext = callbackManager->getContext();
185 JSValueRef error = NULL;
187 SystemSettingAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
189 Converter converter(gContext);
191 if (ExceptionCodes::None != event->getExceptionCode())
193 switch (event->getExceptionCode())
195 case ExceptionCodes::PlatformException:
196 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
198 case ExceptionCodes::NotFoundException:
199 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "record not found");
201 case ExceptionCodes::InvalidArgumentException:
202 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "DomainName is not setted");
204 case ExceptionCodes::ConversionException:
205 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong argument");
208 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown error");
212 callbackManager->callOnError(error);
215 LoggerD("gettingValue : " << event->getSettingValue());
217 std::string settingPath = event->getSettingValue();
218 LoggerD("RealSettingPath : " << settingPath);
220 if (settingPath.size() == 0)
222 error = JSWebAPIErrorFactory::makeErrorObject(gContext, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown error");
223 callbackManager->callOnError(error);
227 callbackManager->callOnSuccess(converter.toJSValueRef(settingPath));