wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Filesystem / StorageStaticController.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include <JavaScriptCore/JavaScript.h>
19 #include <dpl/shared_ptr.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include <CommonsJavaScript/JSCallbackManager.h>
22 #include <CommonsJavaScript/Converter.h>
23 #include <Commons/IEvent.h>
24 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
25 #include "EventStorageStateChanged.h"
26 #include "StorageStaticController.h"
27 #include "JSStorage.h"
28 #include "Converter.h"
29 #include <Logger.h>
30
31 using namespace WrtDeviceApis;
32 using namespace WrtDeviceApis::Commons;
33 using namespace WrtDeviceApis::CommonsJavaScript;
34
35 namespace DeviceAPI {
36 namespace Filesystem {
37 StorageStaticController& StorageStaticController::getInstance()
38 {
39         static StorageStaticController controller;
40         return controller;
41 }
42
43 StorageStaticController::StorageStaticController() :
44         EventListener<EventStorageStateChanged>(ThreadEnum::NULL_THREAD)
45 {
46 }
47
48 void StorageStaticController::onAnswerReceived(
49         const EventStorageStateChangedPtr& event)
50 {
51         JSCallbackManagerPtr callbackManager =
52                 DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
53
54         JSContextRef context = callbackManager->getContext();
55         Converter converter(context);
56         try {
57                 JSValueRef result = converter.toJSValueRef(event->getResult(), context);
58                 callbackManager->callOnSuccess(result);
59         } catch(Commons::ConversionException) {
60                 LoggerE("Conversion exception while processing EventStorageStateChanged");
61         }
62 }
63
64 }
65 }