2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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.
19 #include <app_manager.h>
21 #include <DBusTypes.h>
22 #include "DBusServer.h"
23 #include "access_control/PeerCreds.h"
24 #include "ClientRequest.h"
26 ctx::ClientRequest::ClientRequest(int type, int reqId, const char *subj, const char *desc,
27 ctx::Credentials *creds, const char *sender, GDBusMethodInvocation *inv) :
28 RequestInfo(type, reqId, subj, desc),
35 ctx::ClientRequest::~ClientRequest()
38 g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", ERR_OPERATION_FAILED, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
43 const ctx::Credentials* ctx::ClientRequest::getCredentials()
48 const char* ctx::ClientRequest::getPackageId()
51 return __credentials->packageId;
56 const char* ctx::ClientRequest::getClient()
59 return __credentials->client;
64 bool ctx::ClientRequest::reply(int error)
66 IF_FAIL_RETURN(__invocation, true);
68 _I("Reply %#x", error);
70 g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
75 bool ctx::ClientRequest::reply(int error, ctx::CtxJson1& requestResult)
77 IF_FAIL_RETURN(__invocation, true);
78 IF_FAIL_RETURN(error != ERR_NONE || __type != REQ_READ_SYNC, true);
80 std::string result = requestResult.str();
81 IF_FAIL_RETURN(!result.empty(), false);
83 _I("Reply %#x", error);
84 _SD("Result: %s", result.c_str());
86 g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, result.c_str(), EMPTY_JSON_OBJECT));
92 bool ctx::ClientRequest::reply(int error, ctx::CtxJson1& requestResult, ctx::CtxJson1& dataRead)
94 if (__invocation == NULL) {
95 return publish(error, dataRead);
98 std::string result = requestResult.str();
99 std::string data = dataRead.str();
100 IF_FAIL_RETURN(!result.empty() && !data.empty(), false);
102 _I("Reply %#x", error);
103 _SD("Result: %s", result.c_str());
104 _SD("Data: %s", data.c_str());
106 g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, result.c_str(), data.c_str()));
112 bool ctx::ClientRequest::publish(int error, ctx::CtxJson1& data)
114 DBusServer::publish(__dbusSender, __reqId, __subject, error, data.str());