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.
16 #include "client_service_support.h"
19 #include <dpl/log/log.h>
20 #include <dpl/exception.h>
22 namespace ClientModule {
27 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
28 DECLARE_EXCEPTION_TYPE(Base, ServiceHandleCreateError)
29 DECLARE_EXCEPTION_TYPE(Base, ServiceHandleSetError)
31 bool isError(int error);
33 bool isError(int error) {
34 if (SERVICE_ERROR_NONE == error) {
37 LogError("Service error [" << error << "]");
43 bool ServiceSupport::launchViewService(unsigned int windowHandle,
44 const std::string& url)
46 if (url.empty() || url.size() == 0) {
47 LogError("Input url is invalid");
51 service_h serviceHandle = NULL;
53 int error = SERVICE_ERROR_NONE;
54 error = service_create(&serviceHandle);
56 Throw(Exception::ServiceHandleCreateError);
59 error = service_set_operation(serviceHandle, SERVICE_OPERATION_VIEW);
61 ThrowMsg(Exception::ServiceHandleSetError,
62 "service_set_operation error");
65 error = service_set_uri(serviceHandle, url.c_str());
67 ThrowMsg(Exception::ServiceHandleSetError,
68 "service_set_uri error");
71 if (windowHandle != 0) {
72 error = service_set_window(serviceHandle, windowHandle);
74 ThrowMsg(Exception::ServiceHandleSetError,
75 "service_set_window error");
79 error = service_send_launch_request(serviceHandle, NULL, NULL);
81 ThrowMsg(Exception::ServiceHandleSetError,
82 "service_send_launch_request error");
84 service_destroy(serviceHandle);
85 } Catch(Exception::ServiceHandleCreateError) {
86 LogError("Fail to create service handle");
88 } Catch(Exception::ServiceHandleSetError) {
89 LogError(_rethrown_exception.GetMessage());
90 service_destroy(serviceHandle);
92 } Catch(DPL::Exception) {
93 LogError(_rethrown_exception.GetMessage());
100 bool ServiceSupport::launchShareService(unsigned int windowHandle,
101 const std::string& url)
103 if (url.empty() || url.size() == 0) {
104 LogError("Input url is invalid");
108 service_h serviceHandle = NULL;
110 int error = SERVICE_ERROR_NONE;
111 error = service_create(&serviceHandle);
112 if (isError(error)) {
113 Throw(Exception::ServiceHandleCreateError);
116 error = service_set_operation(serviceHandle,
117 SERVICE_OPERATION_SHARE_TEXT);
118 if (isError(error)) {
119 ThrowMsg(Exception::ServiceHandleSetError,
120 "service_set_operation error");
123 if (windowHandle != 0) {
124 error = service_set_window(serviceHandle, windowHandle);
125 if (isError(error)) {
126 ThrowMsg(Exception::ServiceHandleSetError,
127 "service_set_window error");
131 error = service_add_extra_data(serviceHandle,
134 if (isError(error)) {
135 ThrowMsg(Exception::ServiceHandleSetError,
136 "service_add_extra_data error");
139 error = service_send_launch_request(serviceHandle, NULL, NULL);
140 if (isError(error)) {
141 ThrowMsg(Exception::ServiceHandleSetError,
142 "service_send_launch_request error");
144 service_destroy(serviceHandle);
145 } Catch(Exception::ServiceHandleCreateError) {
146 LogError("Fail to create service handle");
148 } Catch(Exception::ServiceHandleSetError) {
149 LogError(_rethrown_exception.GetMessage());
150 service_destroy(serviceHandle);
152 } Catch(DPL::Exception) {
153 LogError(_rethrown_exception.GetMessage());