2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "wrt-popup.h"
21 #include <dpl/log/log.h>
22 #include <dpl/exception.h>
23 #include <dpl/assert.h>
25 #include "PopupEnum.h"
26 #include "PopupSerializer.h"
27 #include "InfoPopup.h"
28 #include "YesNoCheckPopup.h"
32 bool WrtPopup::openPipes()
37 LogError("Wrong arguments!");
40 m_input.Open(m_argv[1]);
42 m_output.Open(m_argv[2]);
44 DPL::WaitableHandleWatchSupport::InheritedContext()->
45 AddWaitableHandleWatch(this,
46 m_input.WaitableReadHandle(),
53 LogError("cannot open pipes");
58 void WrtPopup::closePipes()
63 DPL::WaitableHandleWatchSupport::InheritedContext()->
64 RemoveWaitableHandleWatch(this,
65 m_input.WaitableReadHandle(),
69 m_pipesOpened = false;
74 LogError("cannot close pipes");
78 void WrtPopup::OnEventReceived(const QuitEvent & /* event */)
85 void WrtPopup::OnWaitableHandleEvent(DPL::WaitableHandle waitableHandle,
86 DPL::WaitMode::Type /*mode*/)
88 if (waitableHandle == m_input.WaitableReadHandle()) {
93 void WrtPopup::readInputData()
95 DPL::BinaryQueueAutoPtr data =
96 m_input.Read(std::numeric_limits<std::size_t>::max());
97 int popupType = PopupSerializer::getIntArg(*data);
98 LogDebug("popup type " << popupType);
101 m_popup.reset(new InfoPopup());
102 m_popup->show(data, this);
104 case YES_NO_CHECK_PROMPT:
105 m_popup.reset(new YesNoCheckPopup());
106 m_popup->show(data, this);
113 void WrtPopup::response(DPL::BinaryQueue result)
115 m_output.Write(result, result.Size());
116 PostEvent(QuitEvent());
119 void WrtPopup::OnStop()
124 void WrtPopup::OnCreate()
127 PostEvent(QuitEvent());
129 LogDebug("On Create");
132 void WrtPopup::OnResume()
134 LogDebug("OnResume");
137 void WrtPopup::OnPause()
142 void WrtPopup::OnReset(bundle */*b*/)
147 void WrtPopup::OnTerminate()
149 LogDebug("Wrt Shutdown now");
152 WrtPopup::WrtPopup(int argc, char **argv) :
153 Application(argc, argv, "wrt-popup", false),
157 Renderer::PopupControllerSingleton::Instance().Touch();
158 Renderer::PopupManagerSingleton::Instance().Initialize(
159 Renderer::PopupRendererPtr(new Renderer::PopupRenderer));
160 LogDebug("App Created");
163 WrtPopup::~WrtPopup()
165 Renderer::PopupManagerSingleton::Instance().Deinitialize();
166 LogDebug("App Finished");
171 int main(int argc, char *argv[])
173 UNHANDLED_EXCEPTION_HANDLER_BEGIN
175 // Output on stdout will be flushed after every newline character,
176 // even if it is redirected to a pipe. This is useful for running
177 // from a script and parsing output.
178 // (Standard behavior of stdlib is to use full buffering when
179 // redirected to a pipe, which means even after an end of line
180 // the output may not be flushed).
183 Wrt::Popup::WrtPopup app(argc, argv);
184 int ret = app.Exec();
185 LogDebug("App returned: " << ret);
188 UNHANDLED_EXCEPTION_HANDLER_END