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 "YesNoPopup.h"
28 #include "InfoPopup.h"
29 #include "YesNoCheckPopup.h"
33 bool WrtPopup::openPipes()
38 LogError("Wrong arguments!");
41 m_input.Open(m_argv[1]);
43 m_output.Open(m_argv[2]);
45 DPL::WaitableHandleWatchSupport::InheritedContext()->
46 AddWaitableHandleWatch(this,
47 m_input.WaitableReadHandle(),
54 LogError("cannot open pipes");
59 void WrtPopup::closePipes()
64 DPL::WaitableHandleWatchSupport::InheritedContext()->
65 RemoveWaitableHandleWatch(this,
66 m_input.WaitableReadHandle(),
70 m_pipesOpened = false;
75 LogError("cannot close pipes");
79 void WrtPopup::OnEventReceived(const QuitEvent & /* event */)
86 void WrtPopup::OnWaitableHandleEvent(DPL::WaitableHandle waitableHandle,
87 DPL::WaitMode::Type /*mode*/)
89 if (waitableHandle == m_input.WaitableReadHandle()) {
94 void WrtPopup::readInputData()
96 DPL::BinaryQueueAutoPtr data =
97 m_input.Read(std::numeric_limits<std::size_t>::max());
98 int popupType = PopupSerializer::getIntArg(*data);
99 LogDebug("popup type " << popupType);
102 m_popup.reset(new YesNoPopup());
103 m_popup->show(data, this);
106 m_popup.reset(new InfoPopup());
107 m_popup->show(data, this);
109 case YES_NO_CHECK_PROMPT:
110 m_popup.reset(new YesNoCheckPopup());
111 m_popup->show(data, this);
118 void WrtPopup::response(DPL::BinaryQueue result)
120 m_output.Write(result, result.Size());
121 PostEvent(QuitEvent());
124 void WrtPopup::OnStop()
129 void WrtPopup::OnCreate()
132 PostEvent(QuitEvent());
134 LogDebug("On Create");
137 void WrtPopup::OnResume()
139 LogDebug("OnResume");
142 void WrtPopup::OnPause()
147 void WrtPopup::OnReset(bundle */*b*/)
152 void WrtPopup::OnTerminate()
154 LogDebug("Wrt Shutdown now");
157 WrtPopup::WrtPopup(int argc, char **argv) :
158 Application(argc, argv, "wrt-popup", false),
162 Renderer::PopupControllerSingleton::Instance().Touch();
163 Renderer::PopupManagerSingleton::Instance().Initialize(
164 Renderer::PopupRendererPtr(new Renderer::PopupRenderer));
165 LogDebug("App Created");
168 WrtPopup::~WrtPopup()
170 Renderer::PopupManagerSingleton::Instance().Deinitialize();
171 LogDebug("App Finished");
176 int main(int argc, char *argv[])
178 UNHANDLED_EXCEPTION_HANDLER_BEGIN
180 // Output on stdout will be flushed after every newline character,
181 // even if it is redirected to a pipe. This is useful for running
182 // from a script and parsing output.
183 // (Standard behavior of stdlib is to use full buffering when
184 // redirected to a pipe, which means even after an end of line
185 // the output may not be flushed).
188 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-POPUP");
189 Wrt::Popup::WrtPopup app(argc, argv);
190 int ret = app.Exec();
191 LogDebug("App returned: " << ret);
194 UNHANDLED_EXCEPTION_HANDLER_END