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 #include <Commons/Exception.h>
20 #include <app_service.h>
21 #include <app_manager.h>
22 #include "RequestedApplicationControl.h"
25 namespace Application {
27 using namespace WrtDeviceApis::Commons;
29 RequestedApplicationControl::RequestedApplicationControl() :
37 RequestedApplicationControl::~RequestedApplicationControl()
42 ApplicationControlPtr RequestedApplicationControl::getAppControl() const
48 // TODO: Should I add & or not?
49 void RequestedApplicationControl::setAppControl(ApplicationControlPtr &appControl)
51 m_appControl = appControl;
54 std::string RequestedApplicationControl::getCallerAppId() const
59 void RequestedApplicationControl::setCallerAppId(const std::string &id)
64 void RequestedApplicationControl::replyResult(std::vector<ApplicationControlDataPtr> &appControlDataArray)
67 service_create(&reply);
69 if (!appControlDataArray.empty())
71 const char** arr = NULL;
73 LogDebug("appControlDataArray.size() : "<<appControlDataArray.size());
74 for (size_t i = 0; i < appControlDataArray.size(); ++i) {
75 std::vector<std::string> valueArray = appControlDataArray.at(i)->getValue();
77 arr = (const char**) calloc (sizeof(char*), valueArray.size());
80 for (size_t j = 0; j < valueArray.size(); j++) {
81 arr[j] = valueArray.at(j).c_str();
82 LogDebug("== value : " << arr[j]);
85 service_add_extra_data_array(reply, appControlDataArray.at(i)->getKey().c_str(), arr, valueArray.size());
91 LogError("[replyResult] appControlDataArray is empty");
94 // temporal code to check caller liveness
95 if (m_callerAppId.empty()) {
96 LogDebug("m_callerAppId is empty. means caller is dead");
97 ThrowMsg(NotFoundException, "Cannot find caller");
100 int ret = app_manager_is_running(m_callerAppId.c_str(), &running);
101 if ((ret != APP_MANAGER_ERROR_NONE) || !running) {
102 LogDebug("caller is not running");
103 ThrowMsg(NotFoundException, "Cannot find caller");
107 if (service_reply_to_launch_request(reply, m_appControl->getService_h(), SERVICE_RESULT_SUCCEEDED) != SERVICE_ERROR_NONE) {
108 ThrowMsg(NotFoundException, "Cannot find caller");
111 service_destroy(reply);
114 void RequestedApplicationControl::replyFailure()
117 service_create(&reply);
119 LogError("[replyFailure] enter RequestedApplicationControl::replyFailure");
121 // temporal code to check caller liveness
122 if (m_callerAppId.empty()) {
123 LogDebug("m_callerAppId is empty. means caller is dead");
124 ThrowMsg(NotFoundException, "Cannot find caller");
126 bool running = false;
127 int ret = app_manager_is_running(m_callerAppId.c_str(), &running);
128 if ((ret != APP_MANAGER_ERROR_NONE) || !running) {
129 LogDebug("caller is not running");
130 ThrowMsg(NotFoundException, "Cannot find caller");
134 if (service_reply_to_launch_request(reply, m_appControl->getService_h(), SERVICE_RESULT_FAILED) != SERVICE_ERROR_NONE) {
135 ThrowMsg(NotFoundException, "Cannot find caller");
138 service_destroy(reply);