2 * Copyright (c) 2017 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
18 * @file askuser-notification-client.cpp
19 * @author Piotr Sawicki <p.sawicki2@partner.samsung.com>
20 * @brief This file contains the implementation of the askuser-notification client API.
26 #include <askuser-notification-client.h>
27 #include <attributes/attributes.h>
29 #include <ApiInterface.h>
30 #include <ApiInterfaceImpl.h>
31 #include <PopupCallbackClosure.h>
32 #include <StatusCallbackClosure.h>
35 struct askuser_client {
36 AskUser::Client::ApiInterface *impl;
38 explicit askuser_client(AskUser::Client::ApiInterface *_impl) : impl(_impl) {
47 int askuser_client_initialize(askuser_client **pp_client,
48 askuser_status_callback status_callback, void *p_user_data)
51 return ASKUSER_API_INVALID_PARAM;
56 return AskUser::Client::tryCatch([&]() {
57 AskUser::Client::StatusCallbackClosure closure(status_callback, p_user_data);
59 std::unique_ptr<AskUser::Client::ApiInterface> ptr;
60 ptr.reset(new AskUser::Client::ApiInterfaceImpl(closure));
62 *pp_client = new askuser_client(ptr.get());
66 return ASKUSER_API_SUCCESS;
71 void askuser_client_finalize(askuser_client *p_client)
77 AskUser::Client::tryCatch([&]() {
79 return ASKUSER_API_SUCCESS;
84 int askuser_client_process(askuser_client *p_client, int fd, int events)
87 return ASKUSER_API_INVALID_PARAM;
90 return AskUser::Client::tryCatch([&]() {
91 return p_client->impl->process(fd, events);
96 int askuser_client_check_privilege(askuser_client *p_client,
97 const char *privilege, askuser_check_result *p_result)
99 if (!p_client || !privilege || !p_result) {
100 return ASKUSER_API_INVALID_PARAM;
103 return AskUser::Client::tryCatch([&]() {
104 *p_result = p_client->impl->checkPrivilege(privilege);
105 return ASKUSER_API_SUCCESS;
110 int askuser_client_popup_request(askuser_client *p_client, const char *privilege,
111 askuser_popup_response_callback response_callback,
112 void *p_user_data, int *p_request_id)
114 if (!p_client || !privilege || !response_callback) {
115 return ASKUSER_API_INVALID_PARAM;
118 return AskUser::Client::tryCatch([&]() {
119 if (p_client->impl->popupRequestInProgress(privilege)) {
120 return ASKUSER_API_ALREADY_IN_PROGRESS;
123 AskUser::Client::PopupCallbackClosure closure(response_callback, privilege, p_user_data);
124 AskUser::Client::RequestId id = p_client->impl->popupRequest(closure, privilege);
130 return ASKUSER_API_SUCCESS;