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.
19 * @file MessagePortManagerController.cpp
20 * @author Kisub Song (kisubs.song@samsung.com)
25 #include "LocalMessagePortController.h"
26 #include <CommonsJavaScript/JSCallbackManager.h>
27 #include "MessagePortDataItem.h"
28 #include "MessagePortJSUtil.h"
32 namespace MessagePort {
34 using namespace DeviceAPI::Common;
35 using namespace WrtDeviceApis::Commons;
36 using namespace WrtDeviceApis::CommonsJavaScript;
38 LocalMessagePortController::LocalMessagePortController(JSContextRef context, LocalMessagePortPtr localMessagePort) :
39 EventLocalMessagePortListenerListener(ThreadEnum::NULL_THREAD),
40 LocalMessagePortPrivObject(context, localMessagePort)
42 LoggerD("LocalMessagePortController constructed : " << this);
43 if (!localMessagePort) {
44 LoggerW("controller has no localMessagePort object");
48 LocalMessagePortController::~LocalMessagePortController()
50 LoggerD("LocalMessagePortController destructed : " << this);
53 void LocalMessagePortAsyncAnswerHandler::localMessagePortListener(const EventLocalMessagePortListenerPtr &event)
58 JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
61 LoggerE("no callback manager");
65 JSContextRef gContext = cbm->getContext();
67 if(!event->getDataIsSet())
69 LoggerE("No data items");
75 result[0] = MessagePortJSUtil::toJSValueRef(gContext, event->getData());
77 catch(BasePlatformException &e)
79 LoggerE("Fail to convert MessagePortDataItemMap");
85 if(event->getRemoteMessagePortIsSet())
86 result[1] = MessagePortJSUtil::toJSValueRef(gContext, event->getRemoteMessagePort());
88 result[1] = JSValueMakeNull(gContext);
90 catch(BasePlatformException &e)
92 LoggerE("Fail to convert RemoteMessagePort");
96 cbm->callOnSuccess(result, 2);
99 void LocalMessagePortController::onAnswerReceived(const EventLocalMessagePortListenerPtr &event)
103 LoggerE("wrong event");
107 LocalMessagePortAsyncAnswerHandler::localMessagePortListener(event);