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.
17 #include "PopupInvoker.h"
21 #include <dpl/log/log.h>
22 #include <dpl/waitable_handle.h>
23 #include <dpl/binary_queue.h>
24 #include <dpl/serialization.h>
27 #include "PopupEnum.h"
28 #include "PopupSerializer.h"
31 const char *POPUP_EXEC = "/usr/bin/wrt-popup-wrt-runtime";
37 PopupInvoker::PopupInvoker() :
38 m_inputName(tmpnam(NULL)),
39 m_outputName(tmpnam(NULL))
43 m_input.Create(m_inputName);
44 m_output.Create(m_outputName);
45 LogDebug("Pipes created");
47 Catch (DPL::Exception)
49 LogError("Cannot create pipes");
53 PopupInvoker::~PopupInvoker()
57 m_input.Destroy(m_inputName);
58 m_output.Destroy(m_outputName);
59 LogDebug("Pipes destroyed");
61 Catch (DPL::Exception)
63 LogError("Cannot destroy pipes");
67 bool PopupInvoker::askYesNo(const std::string& title, const std::string& message)
71 DPL::BinaryQueue data;
72 PopupSerializer::appendArg(YES_NO_PROMPT, data);
73 PopupSerializer::appendArg(title, data);
74 PopupSerializer::appendArg(message, data);
75 DPL::NamedInputPipe tmp;
76 tmp.Open(m_outputName);
77 m_output.Open(m_outputName);
78 m_input.Open(m_inputName);
79 m_output.Write(data, data.Size());
83 //Result from popup application is available. Read it.
84 DPL::BinaryQueueAutoPtr resultData =
85 m_input.Read(std::numeric_limits<std::size_t>::max());
86 const int result = PopupSerializer::getIntArg(*resultData);
88 LogDebug("Popup result is: " << result);
90 Assert(resultData->Empty());
100 LogError("error occured");
106 void PopupInvoker::executePopup()
112 LogError("Cannot display popup!");
118 int ret = execl(POPUP_EXEC,
120 m_outputName.c_str(),
124 //execl returns -1 on error
125 LogError("Cannot display popup!");
130 DPL::WaitableHandle handle = m_input.WaitableReadHandle();
131 DPL::WaitForSingleHandle(handle);