2 * Service Plugin Client
4 * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include "service_adaptor_errors.h"
27 #include "service_adaptor_internal.h"
28 #include "sal_service_provider.h"
30 API int service_provider_create(service_provider_h *provider)
34 service_provider_h service_provider = (service_provider_h) g_malloc0(sizeof(service_provider_s));
36 service_provider->connect = NULL;
37 service_provider->disconnect = NULL;
39 *provider = service_provider;
41 return SERVICE_ADAPTOR_ERROR_NONE;
44 API int service_provider_destroy(service_provider_h provider)
48 // TODO: free internal value of provider
51 return SERVICE_ADAPTOR_ERROR_NONE;
54 API int service_provider_set_auth_provider(service_provider_h provider, auth_provider_h auth_provider)
58 RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
59 RETV_IF(NULL == auth_provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
61 provider->auth_provider = auth_provider;
63 return SERVICE_ADAPTOR_ERROR_NONE;
66 API int service_provider_unset_auth_provider(service_provider_h provider)
70 RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
72 provider->auth_provider = NULL;
74 return SERVICE_ADAPTOR_ERROR_NONE;
77 API int service_provider_set_storage_provider(service_provider_h provider, storage_provider_h storage_provider)
81 RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
82 RETV_IF(NULL == storage_provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
84 provider->storage_provider = storage_provider;
86 return SERVICE_ADAPTOR_ERROR_NONE;
89 API int service_provider_unset_storage_provider(service_provider_h provider)
93 RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
95 provider->storage_provider = NULL;
97 return SERVICE_ADAPTOR_ERROR_NONE;
100 API int service_provider_message(service_provider_h provider, app_control_h app_control, void *user_data)
104 RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
106 char *operation = NULL;
107 app_control_get_operation(app_control, &operation);
109 RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
111 int ret = SERVICE_ADAPTOR_ERROR_NONE;
113 app_control_h reply = NULL;
115 if (0 == strcmp(operation, PLUGIN_CONNECT_URI))
117 app_control_create(&reply);
118 ret = provider->connect();
120 if (SERVICE_ADAPTOR_ERROR_NONE != ret)
122 SAL_ERR("connect() Fail (%d)", ret);
123 app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_FAILURE);
127 app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_SUCCESS);
129 auth_provider_add_extra_data(provider->auth_provider, reply);
130 storage_provider_add_extra_data(provider->storage_provider, reply);
132 // TODO: another adaptor
134 else if (0 == strcmp(operation, PLUGIN_DISCONNECT_URI))
136 app_control_create(&reply);
137 ret = provider->disconnect();
139 if (SERVICE_ADAPTOR_ERROR_NONE != ret)
141 SAL_ERR("connect() Fail (%d)", ret);
142 app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_FAILURE);
146 app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_SUCCESS);
150 reply = auth_provider_message(provider->auth_provider, operation, app_control);
151 TRY_IF(NULL != reply, "auth_plugin_client_message() Finded");
153 reply = storage_provider_message(provider->storage_provider, operation, app_control);
154 TRY_IF(NULL != reply, "storage_plugin_client_message() Finded");
158 app_control_reply_to_launch_request(reply, app_control, APP_CONTROL_RESULT_SUCCEEDED);
159 app_control_destroy(reply);
161 return SERVICE_ADAPTOR_ERROR_NONE;