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";
35 PopupInvoker::PopupInvoker() :
36 m_inputName(tmpnam(NULL)),
37 m_outputName(tmpnam(NULL))
41 m_input.Create(m_inputName);
42 m_output.Create(m_outputName);
43 LogDebug("Pipes created");
45 Catch (DPL::Exception)
47 LogError("Cannot create pipes");
51 PopupInvoker::~PopupInvoker()
55 m_input.Destroy(m_inputName);
56 m_output.Destroy(m_outputName);
57 LogDebug("Pipes destroyed");
59 Catch (DPL::Exception)
61 LogError("Cannot destroy pipes");
65 bool PopupInvoker::askYesNo(const std::string& title, const std::string& message)
69 DPL::BinaryQueue data;
70 PopupSerializer::appendArg(YES_NO_PROMPT, data);
71 PopupSerializer::appendArg(title, data);
72 PopupSerializer::appendArg(message, data);
73 DPL::NamedInputPipe tmp;
74 tmp.Open(m_outputName);
75 m_output.Open(m_outputName);
76 m_input.Open(m_inputName);
77 m_output.Write(data, data.Size());
81 //Result from popup application is available. Read it.
82 DPL::BinaryQueueAutoPtr resultData =
83 m_input.Read(std::numeric_limits<std::size_t>::max());
84 const int result = PopupSerializer::getIntArg(*resultData);
86 LogDebug("Popup result is: " << result);
88 Assert(resultData->Empty());
98 LogError("error occured");
104 void PopupInvoker::executePopup()
110 LogError("Cannot display popup!");
116 int ret = execl(POPUP_EXEC,
118 m_outputName.c_str(),
122 //execl returns -1 on error
123 LogError("Cannot display popup!");
128 DPL::WaitableHandle handle = m_input.WaitableReadHandle();
129 DPL::WaitForSingleHandle(handle);