Add 3.0 APIs and sync APIs same as 2.4 94/41894/1 submit/tizen/20150619.054506
authorYongjin Kim <youth.kim@samsung.com>
Fri, 19 Jun 2015 02:16:48 +0000 (11:16 +0900)
committerYongjin Kim <youth.kim@samsung.com>
Fri, 19 Jun 2015 02:16:48 +0000 (11:16 +0900)
Change-Id: Ib874d7a4a26a65bd151f3c7cecb1ebfec0f3ae67
Signed-off-by: Yongjin Kim <youth.kim@samsung.com>
84 files changed:
CMakeLists.txt
adaptor/CMakeLists.txt
adaptor/auth-adaptor/auth_adaptor.c
adaptor/auth-adaptor/auth_adaptor.h
adaptor/auth-adaptor/oauth1_service.c [new file with mode: 0644]
adaptor/auth-adaptor/oauth1_service.h [new file with mode: 0644]
adaptor/auth-adaptor/oauth2_service.c [new file with mode: 0644]
adaptor/auth-adaptor/oauth2_service.h [new file with mode: 0644]
adaptor/resource-adaptor/resource_adaptor.c [new file with mode: 0644]
adaptor/resource-adaptor/resource_adaptor.h [new file with mode: 0644]
adaptor/storage-adaptor/cloud_service.c [new file with mode: 0644]
adaptor/storage-adaptor/cloud_service.h [new file with mode: 0644]
adaptor/storage-adaptor/posix_service.h [new file with mode: 0644]
adaptor/storage-adaptor/storage_adaptor.c
adaptor/storage-adaptor/storage_adaptor.h
client/CMakeLists.txt
client/sal_auth_provider.c [new file with mode: 0644]
client/sal_auth_provider.h [new file with mode: 0644]
client/sal_core_api.c [deleted file]
client/sal_core_api.h [deleted file]
client/sal_plugin_api.c [deleted file]
client/sal_restful_api.c [deleted file]
client/sal_service_adaptor.c [new file with mode: 0644]
client/sal_service_adaptor.h [new file with mode: 0644]
client/sal_service_adaptor_internal.h [new file with mode: 0644]
client/sal_service_auth.c [new file with mode: 0644]
client/sal_service_auth.h [new file with mode: 0644]
client/sal_service_auth_internal.h [new file with mode: 0644]
client/sal_service_provider.c [new file with mode: 0644]
client/sal_service_provider.h [new file with mode: 0644]
client/sal_service_storage.c [new file with mode: 0644]
client/sal_service_storage.h [new file with mode: 0644]
client/sal_service_storage_internal.h [new file with mode: 0644]
client/sal_service_task.c [new file with mode: 0644]
client/sal_service_task.h [new file with mode: 0644]
client/sal_service_task_internal.h [new file with mode: 0644]
client/sal_storage_provider.c [new file with mode: 0644]
client/sal_storage_provider.h [new file with mode: 0644]
common/CMakeLists.txt
common/ipc-client/sal_ipc_client.c [new file with mode: 0644]
common/ipc-client/sal_ipc_client.h [new file with mode: 0644]
common/ipc-client/sal_ipc_client_auth.c [new file with mode: 0644]
common/ipc-client/sal_ipc_client_auth.h [new file with mode: 0644]
common/ipc-client/sal_ipc_client_core.c [new file with mode: 0644]
common/ipc-client/sal_ipc_client_core.h [new file with mode: 0644]
common/ipc-client/sal_ipc_client_storage.c [new file with mode: 0644]
common/ipc-client/sal_ipc_client_storage.h [new file with mode: 0644]
common/ipc-server/sal_ipc_server.c [new file with mode: 0644]
common/ipc-server/sal_ipc_server.h [moved from common/ipc/sal_ipc.h with 76% similarity]
common/ipc-server/sal_ipc_server_auth.c [new file with mode: 0644]
common/ipc-server/sal_ipc_server_auth.h [new file with mode: 0644]
common/ipc-server/sal_ipc_server_core.c [new file with mode: 0644]
common/ipc-server/sal_ipc_server_core.h [new file with mode: 0644]
common/ipc-server/sal_ipc_server_storage.c [new file with mode: 0644]
common/ipc-server/sal_ipc_server_storage.h [new file with mode: 0644]
common/ipc/sal_ipc.c [deleted file]
common/sal_common.c [deleted file]
common/sal_ipc.c [new file with mode: 0644]
common/sal_ipc.h [new file with mode: 0644]
include/service_adaptor.h
include/service_adaptor_internal.h
include/service_adaptor_types.h
include/service_provider.h [new file with mode: 0644]
packaging/org.tizen.serviceadaptor.client.conf [new file with mode: 0644]
packaging/org.tizen.serviceadaptor.client.service [new file with mode: 0644]
packaging/service-adaptor.service
packaging/service-adaptor.spec
server/CMakeLists.txt
server/sal.h
server/sal_auth.c
server/sal_auth.h
server/sal_contact.c
server/sal_contact.h
server/sal_main.c
server/sal_observer.c
server/sal_observer.h
server/sal_resource.c [new file with mode: 0644]
server/sal_resource.h [new file with mode: 0644]
server/sal_storage.c
server/sal_storage.h
service-adaptor.manifest
service-adaptor.pc.in
test/CMakeLists.txt
test/test.c

index 8a55c90..6584338 100644 (file)
@@ -15,14 +15,14 @@ MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
 
 
 ##########################################################
 
 
 ##########################################################
-# Define BASE LIB
+# Define Adaptor
 ##########################################################
 ##########################################################
-ADD_SUBDIRECTORY(common)
+ADD_SUBDIRECTORY(adaptor)
 
 ##########################################################
 
 ##########################################################
-# Define Adaptor
+# Define BASE LIB
 ##########################################################
 ##########################################################
-ADD_SUBDIRECTORY(adaptor)
+ADD_SUBDIRECTORY(common)
 
 ##########################################################
 # Define Adaptor API
 
 ##########################################################
 # Define Adaptor API
index c435db1..cf3e86f 100644 (file)
@@ -15,30 +15,35 @@ MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
 
+ADD_DEFINITIONS("-DSERVICE_ADAPTOR_DEBUGGING")
+ADD_DEFINITIONS("-D_SERVICE_ADAPTOR_IPC_SERVER")
+
 ##########################################################
 # Define auth adaptor lib
 ##########################################################
 
 SET(AUTH-LIB "auth-adaptor")
 SET(AUTH-SRCS
 ##########################################################
 # Define auth adaptor lib
 ##########################################################
 
 SET(AUTH-LIB "auth-adaptor")
 SET(AUTH-SRCS
+        ./auth-adaptor/oauth1_service.c
+        ./auth-adaptor/oauth2_service.c
         ./auth-adaptor/auth_adaptor.c
 )
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
         ./auth-adaptor/auth_adaptor.c
 )
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
-        ${CMAKE_SOURCE_DIR}/common
+        ${CMAKE_SOURCE_DIR}/client
         ${CMAKE_SOURCE_DIR}/adaptor/auth-adaptor
 )
 
 INCLUDE(FindPkgConfig)
         ${CMAKE_SOURCE_DIR}/adaptor/auth-adaptor
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(auth_pkgs REQUIRED dlog glib-2.0)
+pkg_check_modules(auth_pkgs REQUIRED dlog glib-2.0 capi-appfw-application)
 
 set(EXTRA_CFLAGS "")
 FOREACH(flag ${auth_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
 
 set(EXTRA_CFLAGS "")
 FOREACH(flag ${auth_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
 
 #message(">>> extra_cflags ${EXTRA_CFLAGS}")
 #message(">>> result ${CMAKE_C_FLAGS}")
 
 #message(">>> extra_cflags ${EXTRA_CFLAGS}")
 #message(">>> result ${CMAKE_C_FLAGS}")
@@ -47,7 +52,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${AUTH-LIB} SHARED ${AUTH-SRCS})
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${AUTH-LIB} SHARED ${AUTH-SRCS})
-TARGET_LINK_LIBRARIES(${AUTH-LIB} ${auth_pkgs_LDFLAGS} sal-common)
+TARGET_LINK_LIBRARIES(${AUTH-LIB} ${auth_pkgs_LDFLAGS})
 SET_TARGET_PROPERTIES(${AUTH-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${AUTH-LIB} PROPERTIES VERSION ${VERSION})
 
 SET_TARGET_PROPERTIES(${AUTH-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${AUTH-LIB} PROPERTIES VERSION ${VERSION})
 
@@ -65,19 +70,18 @@ SET(CONTACT-SRCS
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
-        ${CMAKE_SOURCE_DIR}/common
         ${CMAKE_SOURCE_DIR}/adaptor/contact-adaptor
 )
 
 INCLUDE(FindPkgConfig)
         ${CMAKE_SOURCE_DIR}/adaptor/contact-adaptor
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(contact_pkgs REQUIRED dlog glib-2.0)
+pkg_check_modules(contact_pkgs REQUIRED dlog glib-2.0 capi-appfw-application)
 
 set(EXTRA_CFLAGS "")
 FOREACH(flag ${contact_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
 
 set(EXTRA_CFLAGS "")
 FOREACH(flag ${contact_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
 
 #message(">>> extra_cflags ${EXTRA_CFLAGS}")
 #message(">>> result ${CMAKE_C_FLAGS}")
 
 #message(">>> extra_cflags ${EXTRA_CFLAGS}")
 #message(">>> result ${CMAKE_C_FLAGS}")
@@ -86,7 +90,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${CONTACT-LIB} SHARED ${CONTACT-SRCS})
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${CONTACT-LIB} SHARED ${CONTACT-SRCS})
-TARGET_LINK_LIBRARIES(${CONTACT-LIB} ${contact_pkgs_LDFLAGS} sal-common)
+TARGET_LINK_LIBRARIES(${CONTACT-LIB} ${contact_pkgs_LDFLAGS})
 SET_TARGET_PROPERTIES(${CONTACT-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${CONTACT-LIB} PROPERTIES VERSION ${VERSION})
 
 SET_TARGET_PROPERTIES(${CONTACT-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${CONTACT-LIB} PROPERTIES VERSION ${VERSION})
 
@@ -100,23 +104,23 @@ INSTALL(TARGETS ${CONTACT-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
 SET(STORAGE-LIB "storage-adaptor")
 SET(STORAGE-SRCS
         ./storage-adaptor/storage_adaptor.c
 SET(STORAGE-LIB "storage-adaptor")
 SET(STORAGE-SRCS
         ./storage-adaptor/storage_adaptor.c
+        ./storage-adaptor/cloud_service.c
 )
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
 )
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
-        ${CMAKE_SOURCE_DIR}/common
         ${CMAKE_SOURCE_DIR}/adaptor/storage-adaptor
 )
 
 INCLUDE(FindPkgConfig)
         ${CMAKE_SOURCE_DIR}/adaptor/storage-adaptor
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(storage_pkgs REQUIRED dlog glib-2.0)
+pkg_check_modules(storage_pkgs REQUIRED dlog glib-2.0 capi-appfw-application)
 
 set(EXTRA_CFLAGS "")
 FOREACH(flag ${storage_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
 
 set(EXTRA_CFLAGS "")
 FOREACH(flag ${storage_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
 
 #message(">>> extra_cflags ${EXTRA_CFLAGS}")
 #message(">>> result ${CMAKE_C_FLAGS}")
 
 #message(">>> extra_cflags ${EXTRA_CFLAGS}")
 #message(">>> result ${CMAKE_C_FLAGS}")
@@ -125,8 +129,45 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${STORAGE-LIB} SHARED ${STORAGE-SRCS})
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${STORAGE-LIB} SHARED ${STORAGE-SRCS})
-TARGET_LINK_LIBRARIES(${STORAGE-LIB} ${storage_pkgs_LDFLAGS} sal-common)
+TARGET_LINK_LIBRARIES(${STORAGE-LIB} ${storage_pkgs_LDFLAGS})
 SET_TARGET_PROPERTIES(${STORAGE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${STORAGE-LIB} PROPERTIES VERSION ${VERSION})
 
 INSTALL(TARGETS ${STORAGE-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
 SET_TARGET_PROPERTIES(${STORAGE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${STORAGE-LIB} PROPERTIES VERSION ${VERSION})
 
 INSTALL(TARGETS ${STORAGE-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
+##########################################################
+# Define resource adaptor lib
+##########################################################
+
+SET(RESOURCE-LIB "resource-adaptor")
+SET(RESOURCE-SRCS
+        ./resource-adaptor/resource_adaptor.c
+)
+
+INCLUDE_DIRECTORIES(
+        ${CMAKE_SOURCE_DIR}/include
+        ${CMAKE_SOURCE_DIR}/adaptor/resource-adaptor
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(resource_pkgs REQUIRED dlog glib-2.0 capi-appfw-application)
+
+set(EXTRA_CFLAGS "")
+FOREACH(flag ${resource_pkgs_CFLAGS})
+        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
+
+#message(">>> extra_cflags ${EXTRA_CFLAGS}")
+#message(">>> result ${CMAKE_C_FLAGS}")
+#message(">>> ld flag ${resource_pkgs_LDFLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${RESOURCE-LIB} SHARED ${RESOURCE-SRCS})
+TARGET_LINK_LIBRARIES(${RESOURCE-LIB} ${resource_pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${RESOURCE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${RESOURCE-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${RESOURCE-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
index ccc4d73..450be97 100644 (file)
+/*
+ * Auth Adaptor
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
 #include <stdio.h>
 #include <glib.h>
 
 #include "auth_adaptor.h"
 #include "service_adaptor_internal.h"
 
 #include <stdio.h>
 #include <glib.h>
 
 #include "auth_adaptor.h"
 #include "service_adaptor_internal.h"
 
-auth_adaptor_h auth_adaptor_create()
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+static void _auth_adaptor_free_plugin(auth_plugin_h plugin)
+{
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API auth_adaptor_h auth_adaptor_create()
 {
 {
+       SAL_FN_CALL;
+
        auth_adaptor_h auth = (auth_adaptor_h) g_malloc0(sizeof(auth_adaptor_s));
 
        auth_adaptor_h auth = (auth_adaptor_h) g_malloc0(sizeof(auth_adaptor_s));
 
+       g_mutex_init(&auth->mutex);
+
        return auth;
 }
 
        return auth;
 }
 
-service_adaptor_error_e auth_adaptor_destroy(auth_adaptor_h auth)
+API service_adaptor_error_e auth_adaptor_destroy(auth_adaptor_h auth)
 {
 {
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       g_mutex_lock(&auth->mutex);
+
+       if (0 != auth->start)
+       {
+               auth_adaptor_stop(auth);
+       }
+
        SAL_FREE(auth);
 
        SAL_FREE(auth);
 
+       g_mutex_unlock(&auth->mutex);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e auth_adaptor_start(auth_adaptor_h auth)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       g_mutex_lock(&auth->mutex);
+
+       auth->start = 1;
+
+       g_mutex_unlock(&auth->mutex);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e auth_adaptor_stop(auth_adaptor_h auth)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       // TODO: notify auth adaptor stop to each plugin
+
+       g_mutex_lock(&auth->mutex);
+
+       auth->start = 0;
+
+       g_mutex_unlock(&auth->mutex);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e auth_adaptor_register_listener(auth_adaptor_h auth, auth_adaptor_listener_h listener)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == listener, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       // TODO: register insert/ update/ delete callback for service-adaptor
+
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
-service_adaptor_error_e auth_adaptor_start(auth_adaptor_h auth)
+API service_adaptor_error_e auth_adaptor_unregister_listener(auth_adaptor_h auth, auth_adaptor_listener_h listener)
 {
 {
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == listener, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       // TODO: unregister insert/ update/ delete callback for service-adaptor
+
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
-service_adaptor_error_e auth_adaptor_stop(auth_adaptor_h auth)
+API service_adaptor_error_e auth_adaptor_create_plugin(const char *uri, const char *name, const char *package, auth_plugin_h *plugin)
 {
 {
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == name, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == package, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       auth_plugin_h auth_plugin = (auth_plugin_h) g_malloc0(sizeof(auth_plugin_s));
+       auth_plugin->uri = strdup(uri);
+       auth_plugin->name = strdup(name);
+       auth_plugin->package = strdup(package);
+
+       g_mutex_init(&auth_plugin->mutex);
+       g_cond_init(&auth_plugin->cond);
+
+       *plugin = auth_plugin;
+
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
-service_adaptor_error_e auth_adaptor_register_listener(auth_adaptor_h auth, auth_adaptor_listener_h listener)
+API service_adaptor_error_e auth_adaptor_destroy_plugin(auth_plugin_h plugin)
 {
 {
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       SAL_FREE(plugin->uri);
+       SAL_FREE(plugin->name);
+       SAL_FREE(plugin);
+
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
-service_adaptor_error_e auth_adaptor_unregister_listener(auth_adaptor_h auth, auth_adaptor_listener_h listener)
+API service_adaptor_error_e auth_adaptor_register_plugin_service(auth_plugin_h plugin, GHashTable *service)
 {
 {
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == service, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       plugin->oauth1 = (oauth1_service_h) g_malloc0(sizeof(oauth1_service_s));
+       ret = oauth1_register_service(plugin->oauth1, service);
+
+       if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+       {
+               SAL_INFO("could not find the function for oauth 1.0");
+               SAL_FREE(plugin->oauth1);
+       }
+
+       plugin->oauth2 = (oauth2_service_h) g_malloc0(sizeof(oauth2_service_s));
+       ret = oauth2_register_service(plugin->oauth2, service);
+
+       if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+       {
+               SAL_INFO("could not find the function for oauth 2.0");
+               SAL_FREE(plugin->oauth2);
+       }
+
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
+
+API service_adaptor_error_e auth_adaptor_unregister_plugin_service(auth_plugin_h plugin)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       if (NULL != plugin->oauth1)
+       {
+               oauth1_unregister_service(plugin->oauth1);
+               SAL_FREE(plugin->oauth1);
+       }
+
+       if (NULL != plugin->oauth2)
+       {
+               oauth2_unregister_service(plugin->oauth2);
+               SAL_FREE(plugin->oauth2);
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e auth_adaptor_add_plugin(auth_adaptor_h auth, auth_plugin_h plugin)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       g_mutex_lock(&auth->mutex);
+
+       auth->plugins = g_list_append(auth->plugins, plugin);
+
+       g_mutex_unlock(&auth->mutex);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e auth_adaptor_remove_plugin(auth_adaptor_h auth, auth_plugin_h plugin)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       g_mutex_lock(&auth->mutex);
+
+       RETV_IF(NULL == g_list_find(auth->plugins, plugin), SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       auth->plugins = g_list_remove(auth->plugins, plugin);
+
+       _auth_adaptor_free_plugin(plugin);
+
+       g_mutex_unlock(&auth->mutex);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API auth_plugin_h auth_adaptor_get_plugin(auth_adaptor_h auth, const char *uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, NULL);
+       RETV_IF(NULL == uri, NULL);
+
+       g_mutex_lock(&auth->mutex);
+
+       auth_plugin_h plugin = NULL;
+
+       for (GList *list = g_list_first(auth->plugins); list != NULL; list = list->next)
+       {
+               auth_plugin_h this = (auth_plugin_h) list->data;
+
+               if (0 == strcmp(this->uri, uri))
+               {
+                       plugin = this;
+                       break;
+               }
+       }
+
+       g_mutex_unlock(&auth->mutex);
+
+       return plugin;
+}
+
+API char *auth_adaptor_get_uri(auth_adaptor_h auth, const char *package)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, NULL);
+       RETV_IF(NULL == package, NULL);
+
+       g_mutex_lock(&auth->mutex);
+
+       char *uri = NULL;
+
+       for (GList *list = g_list_first(auth->plugins); list != NULL; list = list->next)
+       {
+               auth_plugin_h this = (auth_plugin_h) list->data;
+
+               if (0 == strcmp(this->package, package))
+               {
+                       uri = this->uri;
+                       break;
+               }
+       }
+
+       g_mutex_unlock(&auth->mutex);
+
+       return uri;
+}
+
+API service_adaptor_error_e auth_adaptor_ref_plugin(auth_adaptor_h auth, const char *uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       g_mutex_lock(&auth->mutex);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NO_DATA;
+
+       for (GList *list = g_list_first(auth->plugins); list != NULL; list = list->next)
+       {
+               auth_plugin_h this = (auth_plugin_h) list->data;
+
+               if (0 == strcmp(this->uri, uri))
+               {
+                       ret = SERVICE_ADAPTOR_ERROR_NONE;
+                       // TODO: increase ref count
+                       break;
+               }
+       }
+
+       g_mutex_unlock(&auth->mutex);
+
+       return ret;
+}
+
+API service_adaptor_error_e auth_adaptor_unref_plugin(auth_adaptor_h auth, const char *uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       g_mutex_lock(&auth->mutex);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NO_DATA;
+
+       for (GList *list = g_list_first(auth->plugins); list != NULL; list = list->next)
+       {
+               auth_plugin_h this = (auth_plugin_h) list->data;
+
+               if (0 == strcmp(this->uri, uri))
+               {
+                       ret = SERVICE_ADAPTOR_ERROR_NONE;
+                       // TODO: decrease ref count
+                       break;
+               }
+       }
+
+       g_mutex_unlock(&auth->mutex);
+
+       return ret;
+}
index 616dc63..c883d73 100644 (file)
@@ -30,7 +30,13 @@ extern "C"
 #endif
 
 #include <stdio.h>
 #endif
 
 #include <stdio.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <glib-unix.h>
+
 #include "service_adaptor_errors.h"
 #include "service_adaptor_errors.h"
+#include "oauth1_service.h"
+#include "oauth2_service.h"
 
 /**
  * @file auth_adaptor.h
 
 /**
  * @file auth_adaptor.h
@@ -49,24 +55,74 @@ extern "C"
  * @{
  */
 
  * @{
  */
 
+#define URI_AUTH       "auth"
+#define URI_OAUTH1_0   "auth/oauth1.0"
+#define URI_OAUTH2_0   "auth/oauth2.0"
+
+/**
+ * @brief Describes infromation about Auth Spec
+ */
+typedef enum _auth_spec_e
+{
+       AUTH_SPEC_OAUTH1_0      = (1 << 0),
+       AUTH_SPEC_OAUTH2_0      = (1 << 1),
+} auth_spec_e;
+
+/**
+ * @brief Describes infromation about Auth Plugin
+ */
+typedef struct _auth_plugin_s
+{
+       char *uri;
+       char *name;
+       char *package;
+
+       oauth1_service_h oauth1;
+       oauth2_service_h oauth2;
+
+       GMutex mutex;
+       GCond cond;
+       int login;
+} auth_plugin_s;
+typedef struct _auth_plugin_s *auth_plugin_h;
+
+/**
+ * @brief Describes infromation about Auth Adaptor
+ */
 typedef struct _auth_adaptor_s
 {
 typedef struct _auth_adaptor_s
 {
-       int i;
+       GList *plugins;         // auth_plugin_h
+
+       GMutex mutex;
+       int start;
 } auth_adaptor_s;
 } auth_adaptor_s;
-typedef struct auth_adaptor_s *auth_adaptor_h;
+typedef struct _auth_adaptor_s *auth_adaptor_h;
 
 
+/**
+ * @brief Describes infromation about Auth Adaptor Listener
+ */
 typedef struct _auth_adaptor_listener_s
 {
 typedef struct _auth_adaptor_listener_s
 {
-       int i;
+       void (*login_cb)(const char *uri, void *user_data);
 } auth_adaptor_listener_s;
 } auth_adaptor_listener_s;
-typedef struct auth_adaptor_listener_s *auth_adaptor_listener_h;
-
-API auth_adaptor_h auth_adaptor_create();
-API service_adaptor_error_e auth_adaptor_destroy(auth_adaptor_h auth);
-API service_adaptor_error_e auth_adaptor_start(auth_adaptor_h auth);
-API service_adaptor_error_e auth_adaptor_stop(auth_adaptor_h auth);
-API service_adaptor_error_e auth_adaptor_register_listener(auth_adaptor_h auth, auth_adaptor_listener_h listener);
-API service_adaptor_error_e auth_adaptor_unregister_listener(auth_adaptor_h auth, auth_adaptor_listener_h listener);
+typedef struct _auth_adaptor_listener_s *auth_adaptor_listener_h;
+
+auth_adaptor_h auth_adaptor_create();
+service_adaptor_error_e auth_adaptor_destroy(auth_adaptor_h auth);
+service_adaptor_error_e auth_adaptor_start(auth_adaptor_h auth);
+service_adaptor_error_e auth_adaptor_stop(auth_adaptor_h auth);
+service_adaptor_error_e auth_adaptor_register_listener(auth_adaptor_h auth, auth_adaptor_listener_h listener);
+service_adaptor_error_e auth_adaptor_unregister_listener(auth_adaptor_h auth, auth_adaptor_listener_h listener);
+service_adaptor_error_e auth_adaptor_create_plugin(const char *uri, const char *name, const char *package,  auth_plugin_h *plugin);
+service_adaptor_error_e auth_adaptor_destroy_plugin(auth_plugin_h plugin);
+service_adaptor_error_e auth_adaptor_register_plugin_service(auth_plugin_h plugin, GHashTable *service);
+service_adaptor_error_e auth_adaptor_unregister_plugin_service(auth_plugin_h plugin);
+service_adaptor_error_e auth_adaptor_add_plugin(auth_adaptor_h auth, auth_plugin_h plugin);
+service_adaptor_error_e auth_adaptor_remove_plugin(auth_adaptor_h auth, auth_plugin_h plugin);
+auth_plugin_h auth_adaptor_get_plugin(auth_adaptor_h auth, const char *uri);
+char *auth_adaptor_get_uri(auth_adaptor_h auth, const char *package);
+service_adaptor_error_e auth_adaptor_ref_plugin(auth_adaptor_h auth, const char *uri);
+service_adaptor_error_e auth_adaptor_unref_plugin(auth_adaptor_h auth, const char *uri);
 
 /**
  * @}
 
 /**
  * @}
diff --git a/adaptor/auth-adaptor/oauth1_service.c b/adaptor/auth-adaptor/oauth1_service.c
new file mode 100644 (file)
index 0000000..0ff7afc
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * oAuth 1.0 Service
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <glib.h>
+
+#include <app.h>
+
+#include "oauth1_service.h"
+#include "auth_adaptor.h"
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+
+#include "sal_service_provider.h"
+#include "sal_auth_provider.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+typedef struct _app_control_user_data_s
+{
+       void *callback;
+       void *user_data;
+} app_control_user_data_s;
+typedef struct _app_control_user_data_s *app_control_user_data_h;
+
+typedef int (*_get_access_token)(void *plugin, oauth1_cb callback, void *user_data);
+typedef int (*_get_extra_data)(void *plugin, const char *key, oauth1_cb callback, void *user_data);
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+/**
+ * @brief callback of service plugin
+ *
+ * @return      void.
+ */
+static void _oauth1_get_access_token_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RET_IF(APP_CONTROL_RESULT_FAILED == result);
+       RET_IF(NULL == user_data);
+
+       char *ret_str = NULL;
+       app_control_get_extra_data(reply, PLUGIN_RESULT_KEY, &ret_str);
+
+       char *access_token = NULL;
+       app_control_get_extra_data(reply, OAUTH1_0_ACCESS_TOKEN_KEY, &access_token);
+
+       app_control_user_data_h app_control_user_data = (app_control_user_data_h) user_data;
+       oauth1_cb callback = (oauth1_cb) app_control_user_data->callback;
+
+       RET_IF(NULL == callback);
+
+       // TODO: move this function for chaning result enum to general
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       if (0 == strcmp(PLUGIN_RESULT_VALUE_FAILURE, ret_str))
+       {
+               ret = SERVICE_ADAPTOR_ERROR_INTERNAL;
+       }
+
+       oauth1_h oauth1 = (oauth1_h) g_malloc0(sizeof(oauth1_s));
+       oauth1->access_token = strdup(access_token);
+
+       callback(ret, oauth1, app_control_user_data->user_data);
+
+       SAL_FN_END;
+}
+
+static int _oauth1_get_access_token(auth_plugin_h plugin, oauth1_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       app_control_h request;
+       app_control_create(&request);
+
+       app_control_set_app_id(request, plugin->uri);
+       app_control_set_operation(request, OAUTH1_0_GET_ACCESS_TOKEN_URI);
+
+       app_control_user_data_h app_control_user_data = (app_control_user_data_h) g_malloc0(sizeof(app_control_user_data_s));
+       app_control_user_data->callback = (void *) callback;
+       app_control_user_data->user_data = user_data;
+
+       int res = app_control_send_launch_request(request, _oauth1_get_access_token_cb, app_control_user_data);
+
+       if (APP_CONTROL_ERROR_NONE != res)
+       {
+               return SERVICE_ADAPTOR_ERROR_SYSTEM;
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+static int _oauth1_get_extra_data(auth_plugin_h plugin, const char *key, oauth1_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int oauth1_register_service(oauth1_service_h oauth1, GHashTable *service)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NO_DATA;
+       GHashTableIter iter;
+       gpointer iter_key, iter_value;
+
+       g_hash_table_iter_init(&iter, service);
+       while (g_hash_table_iter_next(&iter, &iter_key, &iter_value))
+       {
+               if (0 == strcmp(iter_key, OAUTH1_0_GET_ACCESS_TOKEN_URI))
+               {
+                       oauth1->oauth1_get_access_token = (_get_access_token) _oauth1_get_access_token;
+                       ret = SERVICE_ADAPTOR_ERROR_NONE;
+               }
+               else if (0 == strcmp(iter_key, OAUTH1_0_GET_EXTRA_DATA_URI))
+               {
+                       oauth1->oauth1_get_extra_data = (_get_extra_data) _oauth1_get_extra_data;
+                       ret = SERVICE_ADAPTOR_ERROR_NONE;
+               }
+       }
+
+       return ret;
+}
+
+API int oauth1_unregister_service(oauth1_service_h oauth1)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       oauth1->oauth1_get_access_token = NULL;
+       oauth1->oauth1_get_extra_data = NULL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/adaptor/auth-adaptor/oauth1_service.h b/adaptor/auth-adaptor/oauth1_service.h
new file mode 100644 (file)
index 0000000..f24bf64
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * oAuth 1.0 Service
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __OAUTH1_SERVICE_H__
+#define __OAUTH1_SERVICE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdio.h>
+#include <glib.h>
+
+/**
+ * @brief Describes infromation about oAuth1 Service
+ * @key name, ...
+ */
+typedef struct _oauth1_s
+{
+       char *access_token;
+       char *operation;
+} oauth1_s;
+typedef struct _oauth1_s *oauth1_h;
+
+/**
+* @brief Callback for oauth1 API
+*
+* @param[in]    access_token
+* @param[in]    user_data       Passed data from #oauth1_get_access_token()
+* @remarks
+* @pre  oauth1() will invoke this callback.
+*/
+typedef void (*oauth1_cb)(int result, oauth1_h oauth1, void *user_data);
+
+/**
+ * @brief Describes infromation about oAuth 1.0 Service
+ * @key access token, ...
+ */
+typedef struct _oauth1_service_s
+{
+       int (*oauth1_get_access_token)(void *plugin, oauth1_cb callback, void *user_data);
+       int (*oauth1_get_extra_data)(void *plugin, const char *key, oauth1_cb callback, void *user_data);
+} oauth1_service_s;
+typedef struct _oauth1_service_s *oauth1_service_h;
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+/**
+* @brief Register oAuth 1.0 Service
+* @since_tizen 3.0
+*
+* @param[in]   oauth1  The oAuth 1.0 service handle
+* @param[in]   service
+* @remarks
+* @see         oauth1_unregister_service()
+* @return 0 on success, otherwise a negative error value
+* @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+* @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+*/
+int oauth1_register_service(oauth1_service_h oauth1, GHashTable *service);
+
+/**
+* @brief Unregister oAuth 1.0 Service
+* @since_tizen 3.0
+*
+* @param[in]   oauth1  The oAuth 1.0 service handle
+* @remarks
+* @see         oauth1_register_service()
+* @return 0 on success, otherwise a negative error value
+* @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+* @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+*/
+int oauth1_unregister_service(oauth1_service_h oauth1);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OAUTH1_SERVICE_H__ */
diff --git a/adaptor/auth-adaptor/oauth2_service.c b/adaptor/auth-adaptor/oauth2_service.c
new file mode 100644 (file)
index 0000000..409089e
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * oAuth 2.0 Service
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <glib.h>
+
+#include <app.h>
+
+#include "oauth2_service.h"
+#include "auth_adaptor.h"
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+
+#include "sal_auth_provider.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+typedef struct _app_control_user_data_s
+{
+       void *callback;
+       void *user_data;
+} app_control_user_data_s;
+typedef struct _app_control_user_data_s *app_control_user_data_h;
+
+typedef int (*_get_access_token)(void *plugin, char **access_token, void *user_data);
+typedef int (*_get_extra_data)(void *plugin, const char *key, char **value, void *user_data);
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+static int _oauth2_get_access_token(auth_plugin_h plugin, char **access_token, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+static int _oauth2_get_extra_data(auth_plugin_h plugin, const char *key, char **value, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int oauth2_register_service(oauth2_service_h oauth2, GHashTable *service)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth2, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NO_DATA;
+       GHashTableIter iter;
+       gpointer iter_key, iter_value;
+
+       g_hash_table_iter_init(&iter, service);
+       while (g_hash_table_iter_next(&iter, &iter_key, &iter_value))
+       {
+               if (0 == strcmp(iter_key, OAUTH2_0_GET_ACCESS_TOKEN_URI))
+               {
+                       oauth2->oauth2_get_access_token = (_get_access_token) _oauth2_get_access_token;
+                       ret = SERVICE_ADAPTOR_ERROR_NONE;
+               }
+               else if (0 == strcmp(iter_key, OAUTH2_0_GET_EXTRA_DATA_URI))
+               {
+                       oauth2->oauth2_get_extra_data = (_get_extra_data) _oauth2_get_extra_data;
+                       ret = SERVICE_ADAPTOR_ERROR_NONE;
+               }
+       }
+
+       return ret;
+}
+
+API int oauth2_unregister_service(oauth2_service_h oauth2)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth2, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       oauth2->oauth2_get_access_token = NULL;
+       oauth2->oauth2_get_extra_data = NULL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/adaptor/auth-adaptor/oauth2_service.h b/adaptor/auth-adaptor/oauth2_service.h
new file mode 100644 (file)
index 0000000..201f807
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * oAuth 2.0 Service
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __OAUTH2_SERVICE_H__
+#define __OAUTH2_SERVICE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdio.h>
+#include <glib.h>
+
+/**
+* @brief Callback for oauth2_get_access_token API
+*
+* @param[in]    access_token
+* @param[in]    user_data       Passed data from #oauth2_get_access_token()
+* @remarks
+* @pre  oauth2_get_access_token() will invoke this callback.
+*/
+typedef void (*oauth2_get_access_token_cb)(const char *access_token, void *user_data);
+
+/**
+* @brief Callback for oauth2_get_extra_data API
+*
+* @param[in]    value
+* @param[in]    user_data       Passed data from #oauth2_get_access_token()
+* @remarks
+* @pre  oauth2_get_extra_data() will invoke this callback.
+*/
+typedef void (*oauth2_get_extra_data_cb)(const char *value, void *user_data);
+
+/**
+ * @brief Describes infromation about oAuth 2.0 Service
+ * @key access token, ...
+ */
+typedef struct _oauth2_service_s
+{
+       int (*oauth2_get_access_token)(void *plugin, char **access_token, void *user_data);
+       int (*oauth2_get_extra_data)(void *plugin, const char *key, char **value, void *user_data);
+} oauth2_service_s;
+typedef struct _oauth2_service_s *oauth2_service_h;
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+/**
+* @brief Register oAuth 2.0 Service
+* @since_tizen 3.0
+*
+* @param[in]   oauth2  The oAuth 2.0 service handle
+* @param[in]   service
+* @remarks
+* @see         oauth2_unregister_service()
+* @return 0 on success, otherwise a negative error value
+* @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+* @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+*/
+int oauth2_register_service(oauth2_service_h oauth2, GHashTable *service);
+
+/**
+* @brief Unregister oAuth 2.0 Service
+* @since_tizen 3.0
+*
+* @param[in]   oauth2  The oAuth 2.0 service handle
+* @remarks
+* @see         oauth2_register_service()
+* @return 0 on success, otherwise a negative error value
+* @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+* @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+*/
+int oauth2_unregister_service(oauth2_service_h oauth2);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OAUTH2_SERVICE_H__ */
diff --git a/adaptor/resource-adaptor/resource_adaptor.c b/adaptor/resource-adaptor/resource_adaptor.c
new file mode 100644 (file)
index 0000000..78e7cca
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Resource Adaptor
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <glib.h>
+
+#include "resource_adaptor.h"
+#include "service_adaptor_internal.h"
+
+API resource_adaptor_h resource_adaptor_create()
+{
+       resource_adaptor_h resource = (resource_adaptor_h) g_malloc0(sizeof(resource_adaptor_s));
+
+       return resource;
+}
+
+API service_adaptor_error_e resource_adaptor_destroy(resource_adaptor_h resource)
+{
+       SAL_FREE(resource);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e resource_adaptor_start(resource_adaptor_h resource)
+{
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e resource_adaptor_stop(resource_adaptor_h resource)
+{
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e resource_adaptor_register_listener(resource_adaptor_h resource, resource_adaptor_listener_h listener)
+{
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e resource_adaptor_unregister_listener(resource_adaptor_h resource, resource_adaptor_listener_h listener)
+{
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/adaptor/resource-adaptor/resource_adaptor.h b/adaptor/resource-adaptor/resource_adaptor.h
new file mode 100644 (file)
index 0000000..bb4081e
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Resource Adaptor
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __RESOURCE_ADAPTOR_H__
+#define __RESOURCE_ADAPTOR_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdio.h>
+#include <glib.h>
+
+#include "service_adaptor_errors.h"
+
+/**
+ * @file resource_adaptor.h
+ */
+
+/**
+ * @ingroup
+ * @defgroup
+ *
+ * @brief
+ *
+ * @section
+ *  \#include <resource_adaptor.h>
+ *
+ * <BR>
+ * @{
+ */
+
+/**
+ * @brief Handle of Resource Plugin
+ */
+typedef struct resource_plugin_s *resource_plugin_h;
+
+/**
+ * @brief Describes infromation about SmartThings Service
+ * @key access token, ...
+ */
+ typedef struct _resource_plugin_smartthings_service_s
+ {
+       int (*smartthings_get_resource)(resource_plugin_h plugin, char **resource_uri, void *user_data);
+ } resource_plugin_smartthings_service_s;
+ typedef struct resource_plugin_smartthings_service_s *resource_plugin_smartthings_service_h;
+
+/**
+ * @brief Describes infromation about Resource Plugin
+ */
+typedef struct _resource_plugin_s
+{
+       char *uri;
+       char *name;
+
+       resource_plugin_smartthings_service_h smartthings;
+
+       GMutex mutex;
+       int start;
+} resource_plugin_s;
+
+/**
+ * @brief Describes infromation about Resource Adaptor
+ */
+typedef struct _resource_adaptor_s
+{
+       GList *plugins;         // resource_plugin_h
+
+       GMutex mutex;
+       int start;
+} resource_adaptor_s;
+typedef struct resource_adaptor_s *resource_adaptor_h;
+
+/**
+ * @brief Describes infromation about Resource Adaptor Listener
+ */
+typedef struct _resource_adaptor_listener_s
+{
+       void (*login_cb)(char *uri, void *user_data);
+} resource_adaptor_listener_s;
+typedef struct resource_adaptor_listener_s *resource_adaptor_listener_h;
+
+resource_adaptor_h resource_adaptor_create();
+service_adaptor_error_e resource_adaptor_destroy(resource_adaptor_h resource);
+service_adaptor_error_e resource_adaptor_start(resource_adaptor_h resource);
+service_adaptor_error_e resource_adaptor_stop(resource_adaptor_h resource);
+service_adaptor_error_e resource_adaptor_register_listener(resource_adaptor_h resource, resource_adaptor_listener_h listener);
+service_adaptor_error_e resource_adaptor_unregister_listener(resource_adaptor_h resource, resource_adaptor_listener_h listener);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __RESOURCE_ADAPTOR_H__ */
diff --git a/adaptor/storage-adaptor/cloud_service.c b/adaptor/storage-adaptor/cloud_service.c
new file mode 100644 (file)
index 0000000..1f86904
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Storage Adaptor
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <glib.h>
+
+#include <app.h>
+
+#include "cloud_service.h"
+#include "storage_adaptor.h"
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+
+#include "sal_service_provider.h"
+#include "sal_storage_provider.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+typedef struct _app_control_user_data_s
+{
+       cloud_file_h file;
+
+       void *callback;
+       void *user_data;
+} app_control_user_data_s;
+typedef struct _app_control_user_data_s *app_control_user_data_h;
+
+typedef int (*_remove_file)(void *plugin, const char *cloud_path, cloud_file_cb callback, void *user_data);
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+int _make_cloud_file_by_local(const char *local_path, cloud_file_h *file)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == local_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       struct stat file_info;
+       RETV_IF(0 != stat(local_path, &file_info), SERVICE_ADAPTOR_ERROR_INTERNAL);
+
+       char *path_tmp = strdup(local_path);
+       char *dir_path = dirname(path_tmp);
+
+       cloud_file_h cloud_file = (cloud_file_h) g_malloc0(sizeof(cloud_file_s));
+       cloud_file->dir_path = dir_path;
+       cloud_file->local_path = strdup(local_path);
+       cloud_file->cloud_path = NULL;
+       cloud_file->size = file_info.st_size;
+
+       if(S_ISDIR(file_info.st_mode))
+       {
+               cloud_file->is_dir = true;
+       }
+
+       *file = cloud_file;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+int _make_cloud_file_by_cloud(const char *cloud_path, cloud_file_h *file)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == cloud_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       cloud_file_h cloud_file = (cloud_file_h) g_malloc0(sizeof(cloud_file_s));
+       cloud_file->cloud_path = strdup(cloud_path);
+
+       *file = cloud_file;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+/**
+ * @brief callback of service plugin
+ *
+ * @return      void.
+ */
+static void _cloud_remove_file_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RET_IF(APP_CONTROL_RESULT_FAILED == result);
+       RET_IF(NULL == user_data);
+
+       char *ret_str = NULL;
+       app_control_get_extra_data(reply, PLUGIN_RESULT_KEY, &ret_str);
+
+       app_control_user_data_h app_control_user_data = (app_control_user_data_h) user_data;
+       cloud_file_cb callback = (cloud_file_cb) app_control_user_data->callback;
+
+       RET_IF(NULL == callback);
+
+       // TODO: move this function for chaning result enum to general
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       if (0 == strcmp(PLUGIN_RESULT_VALUE_FAILURE, ret_str))
+       {
+               ret = SERVICE_ADAPTOR_ERROR_INTERNAL;
+       }
+
+       callback(ret, app_control_user_data->file, app_control_user_data->user_data);
+
+       SAL_FN_END;
+}
+
+static int _cloud_remove_file(storage_plugin_h plugin, const char *cloud_path, cloud_file_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cloud_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       app_control_h request;
+       app_control_create(&request);
+
+       app_control_set_app_id(request, plugin->uri);
+       app_control_set_operation(request, CLOUD_REMOVE_FILE_URI);
+
+       app_control_add_extra_data(request, CLOUD_CLOUD_PATH_KEY, cloud_path);
+
+       cloud_file_h file = NULL;
+       _make_cloud_file_by_cloud(cloud_path, &file);
+       file->operation = strdup(CLOUD_REMOVE_FILE_URI);
+
+       app_control_user_data_h app_control_user_data = (app_control_user_data_h) g_malloc0(sizeof(app_control_user_data_s));
+       app_control_user_data->file = file;
+       app_control_user_data->callback = (void *) callback;
+       app_control_user_data->user_data = user_data;
+
+       int res = app_control_send_launch_request(request, _cloud_remove_file_cb, app_control_user_data);
+
+       if (APP_CONTROL_ERROR_NONE != res)
+       {
+               return SERVICE_ADAPTOR_ERROR_SYSTEM;
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int cloud_register_service(cloud_service_h cloud, GHashTable *service)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == cloud, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NO_DATA;
+       GHashTableIter iter;
+       gpointer iter_key, iter_value;
+
+       g_hash_table_iter_init(&iter, service);
+       while (g_hash_table_iter_next(&iter, &iter_key, &iter_value))
+       {
+               if (0 == strcmp(iter_key, CLOUD_REMOVE_FILE_URI))
+               {
+                       cloud->cloud_remove_file = (_remove_file) _cloud_remove_file;
+                       ret = SERVICE_ADAPTOR_ERROR_NONE;
+               }
+       }
+
+       return ret;
+}
+
+API int cloud_unregister_service(cloud_service_h cloud)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == cloud, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       cloud->cloud_remove_file = NULL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/adaptor/storage-adaptor/cloud_service.h b/adaptor/storage-adaptor/cloud_service.h
new file mode 100644 (file)
index 0000000..731cfc7
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Cloud Service
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CLOUD_SERVICE_H__
+#define __CLOUD_SERVICE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+
+/**
+ * @brief Describes infromation about Cloud Service
+ * @key name, ...
+ */
+typedef struct _cloud_file_s
+{
+       bool is_dir;
+       char *dir_path;
+       char *local_path;
+       char *cloud_path;
+       unsigned long long size;
+       char *operation;
+
+       GList *files;
+} cloud_file_s;
+typedef struct _cloud_file_s *cloud_file_h;
+
+/**
+* @brief Callback for Cloud File Operation API
+*
+* @param[in]    plugin
+* @param[in]    path
+* @param[in]    callback
+* @param[in]    user_data       Passed data from #oauth1_get_access_token()
+* @remarks
+* @pre  cloud_remove_file() will invoke this callback.
+*/
+typedef void (*cloud_file_cb)(int result, cloud_file_h cloud_file, void *user_data);
+
+/**
+ * @brief Describes infromation about Cloud Service
+ * @key name, ...
+ */
+typedef struct _cloud_service_s
+{
+       int (*cloud_remove_file)(void *plugin, const char *cloud_path, cloud_file_cb callback, void *user_data);
+       int (*cloud_download_file)(void *plugin, const char *cloud_path, const char *local_path, cloud_file_cb callback, void *user_data);
+       int (*cloud_upload_file)(void *plugin, const char *local_path, const char *cloud_path, cloud_file_cb callback, void *user_data);
+       int (*cloud_download_file_thumbnail)(void *plugin, const char *cloud_path, const char *local_path, cloud_file_cb callback, void *user_data);
+       int (*cloud_get_file_list)(void *plugin, const char *cloud_path, const char *local_path, cloud_file_cb callback, void *user_data);
+} cloud_service_s;
+typedef struct _cloud_service_s *cloud_service_h;
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+/**
+* @brief Register Cloud Service
+* @since_tizen 3.0
+*
+* @param[in]    cloud  The Cloud service handle
+* @param[in]    service
+* @remarks
+* @see          cloud_unregister_service()
+* @return 0 on success, otherwise a negative error value
+* @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+* @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+*/
+int cloud_register_service(cloud_service_h cloud, GHashTable *service);
+
+/**
+* @brief Unregister Cloud Service
+* @since_tizen 3.0
+*
+* @param[in]    cloud  The Cloud service handle
+* @remarks
+* @see          cloud_register_service()
+* @return 0 on success, otherwise a negative error value
+* @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+* @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+*/
+int cloud_unregister_service(cloud_service_h cloud);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CLOUD_SERVICE_H__ */
diff --git a/adaptor/storage-adaptor/posix_service.h b/adaptor/storage-adaptor/posix_service.h
new file mode 100644 (file)
index 0000000..880292b
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * POSIX Service
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __POSIX_SERVICE_H__
+#define __POSIX_SERVICE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+
+/**
+ * @brief Describes infromation about Cloud Service
+ * @key name, ...
+ */
+typedef struct _posix_service_s
+{
+       int (*posix_open_service)(void *plugin,
+                       const char *path,
+                       int flags,
+                       void *user_data);
+
+       int (*posix_read_service)(void *plugin,
+                       const char *path,
+                       char **buf,
+                       size_t size,
+                       off_t offset,
+                       void *user_data);
+
+       int (*posix_write_service)(void *plugin,
+                       const char *path,
+                       const char *buf,
+                       size_t size,
+                       off_t offset,
+                       void *user_data);
+
+       int (*posix_close_service)(void *plugin,
+                       const char *path,
+                       int flags,
+                       void *user_data);
+} posix_service_s;
+typedef struct _posix_service_s *posix_service_h;
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+/**
+* @brief Register Posix Service
+* @since_tizen 3.0
+*
+* @param[in]    cloud  The Cloud service handle
+* @param[in]    service
+* @remarks
+* @see          cloud_unregister_service()
+* @return 0 on success, otherwise a negative error value
+* @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+* @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+*/
+int posix_register_service(posix_service_h posix, GHashTable *service);
+
+/**
+* @brief Unregister Cloud Service
+* @since_tizen 3.0
+*
+* @param[in]    cloud  The Cloud service handle
+* @remarks
+* @see          cloud_register_service()
+* @return 0 on success, otherwise a negative error value
+* @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+* @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+*/
+int posix_unregister_service(posix_service_h posix);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __POSIX_SERVICE_H__ */
index 2244d3d..5321fa0 100644 (file)
+/*
+ * Storage Adaptor
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
 #include <stdio.h>
 #include <glib.h>
 
 #include "storage_adaptor.h"
 #include "service_adaptor_internal.h"
 
 #include <stdio.h>
 #include <glib.h>
 
 #include "storage_adaptor.h"
 #include "service_adaptor_internal.h"
 
-storage_adaptor_h storage_adaptor_create()
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+static void _storage_adaptor_free_plugin(storage_plugin_h plugin)
+{
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API storage_adaptor_h storage_adaptor_create()
 {
 {
-       storage_adaptor_h storage = (storage_adaptor_h) g_malloc0(sizeof(storage_adaptor_s));
+       SAL_FN_CALL;
+
+        storage_adaptor_h storage = (storage_adaptor_h) g_malloc0(sizeof(storage_adaptor_s));
+
+        g_mutex_init(&storage->mutex);
 
        return storage;
 }
 
 
        return storage;
 }
 
-service_adaptor_error_e storage_adaptor_destroy(storage_adaptor_h storage)
+API service_adaptor_error_e storage_adaptor_destroy(storage_adaptor_h storage)
 {
 {
-       SAL_FREE(storage);
+       SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        g_mutex_lock(&storage->mutex);
+
+        if (0 != storage->start)
+        {
+                storage_adaptor_stop(storage);
+        }
+
+        SAL_FREE(storage);
+
+        g_mutex_unlock(&storage->mutex);
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
-service_adaptor_error_e storage_adaptor_start(storage_adaptor_h storage)
+API service_adaptor_error_e storage_adaptor_start(storage_adaptor_h storage)
 {
 {
+       SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        g_mutex_lock(&storage->mutex);
+
+        storage->start = 1;
+
+        g_mutex_unlock(&storage->mutex);
+
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
-service_adaptor_error_e storage_adaptor_stop(storage_adaptor_h storage)
+API service_adaptor_error_e storage_adaptor_stop(storage_adaptor_h storage)
 {
 {
+       SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        // TODO: notify storage adaptor stop to each plugin
+
+        g_mutex_lock(&storage->mutex);
+
+        storage->start = 0;
+
+        g_mutex_unlock(&storage->mutex);
+
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
-service_adaptor_error_e storage_adaptor_register_listener(storage_adaptor_h storage, storage_adaptor_listener_h listener)
+API service_adaptor_error_e storage_adaptor_register_listener(storage_adaptor_h storage, storage_adaptor_listener_h listener)
 {
 {
+       SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+        RETV_IF(NULL == listener, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        // TODO: register insert/ update/ delete callback for service-adaptor
+
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
-service_adaptor_error_e storage_adaptor_unregister_listener(storage_adaptor_h storage, storage_adaptor_listener_h listener)
+API service_adaptor_error_e storage_adaptor_unregister_listener(storage_adaptor_h storage, storage_adaptor_listener_h listener)
 {
 {
+       SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+        RETV_IF(NULL == listener, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        // TODO: unregister insert/ update/ delete callback for service-adaptor
+
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
+
+API service_adaptor_error_e storage_adaptor_create_plugin(const char *uri, const char *name, const char *package, storage_plugin_h *plugin)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+        RETV_IF(NULL == name, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+        RETV_IF(NULL == package, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        storage_plugin_h storage_plugin = (storage_plugin_h) g_malloc0(sizeof(storage_plugin_s));
+        storage_plugin->uri = strdup(uri);
+        storage_plugin->name = strdup(name);
+        storage_plugin->package = strdup(package);
+
+        g_mutex_init(&storage_plugin->mutex);
+        g_cond_init(&storage_plugin->cond);
+
+        *plugin = storage_plugin;
+
+        return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e storage_adaptor_destroy_plugin(storage_plugin_h plugin)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        SAL_FREE(plugin->uri);
+        SAL_FREE(plugin->name);
+        SAL_FREE(plugin);
+
+        return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e storage_adaptor_register_plugin_service(storage_plugin_h plugin, GHashTable *service)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+        RETV_IF(NULL == service, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+        plugin->cloud = (cloud_service_h) g_malloc0(sizeof(cloud_service_s));
+        ret = cloud_register_service(plugin->cloud, service);
+
+        if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+        {
+                SAL_INFO("could not find the function for cloud");
+                SAL_FREE(plugin->cloud);
+        }
+/*
+        plugin->posix = (posix_service_h) g_malloc0(sizeof(posix_service_s));
+        ret = posix_register_service(plugin->posix, service);
+
+        if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+        {
+                SAL_INFO("could not find the function for posix");
+                SAL_FREE(plugin->posix);
+        }
+*/
+        return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e storage_adaptor_unregister_plugin_service(storage_plugin_h plugin)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        if (NULL != plugin->cloud)
+        {
+                cloud_unregister_service(plugin->cloud);
+                SAL_FREE(plugin->cloud);
+        }
+/*
+        if (NULL != plugin->posix)
+        {
+                posix_unregister_service(plugin->posix);
+                SAL_FREE(plugin->posix);
+        }
+*/
+        return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e storage_adaptor_add_plugin(storage_adaptor_h storage, storage_plugin_h plugin)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+        RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        g_mutex_lock(&storage->mutex);
+
+        storage->plugins = g_list_append(storage->plugins, plugin);
+
+        g_mutex_unlock(&storage->mutex);
+
+        return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e storage_adaptor_remove_plugin(storage_adaptor_h storage, storage_plugin_h plugin)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+        RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        g_mutex_lock(&storage->mutex);
+
+        RETV_IF(NULL == g_list_find(storage->plugins, plugin), SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        storage->plugins = g_list_remove(storage->plugins, plugin);
+
+        _storage_adaptor_free_plugin(plugin);
+
+        g_mutex_unlock(&storage->mutex);
+
+        return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API storage_plugin_h storage_adaptor_get_plugin(storage_adaptor_h storage, const char *uri)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, NULL);
+        RETV_IF(NULL == uri, NULL);
+
+        g_mutex_lock(&storage->mutex);
+
+        storage_plugin_h plugin = NULL;
+
+        for (GList *list = g_list_first(storage->plugins); list != NULL; list = list->next)
+        {
+                storage_plugin_h this = (storage_plugin_h) list->data;
+
+                if (0 == strcmp(this->uri, uri))
+                {
+                        plugin = this;
+                        break;
+                }
+        }
+
+        g_mutex_unlock(&storage->mutex);
+
+        return plugin;
+}
+
+API char *storage_adaptor_get_uri(storage_adaptor_h storage, const char *package)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, NULL);
+        RETV_IF(NULL == package, NULL);
+
+        g_mutex_lock(&storage->mutex);
+
+        char *uri = NULL;
+
+        for (GList *list = g_list_first(storage->plugins); list != NULL; list = list->next)
+        {
+                storage_plugin_h this = (storage_plugin_h) list->data;
+
+                if (0 == strcmp(this->package, package))
+                {
+                        uri = this->uri;
+                        break;
+                }
+        }
+
+        g_mutex_unlock(&storage->mutex);
+
+        return uri;
+}
+
+API service_adaptor_error_e storage_adaptor_ref_plugin(storage_adaptor_h storage, const char *uri)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+        RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        g_mutex_lock(&storage->mutex);
+
+        int ret = SERVICE_ADAPTOR_ERROR_NO_DATA;
+
+        for (GList *list = g_list_first(storage->plugins); list != NULL; list = list->next)
+        {
+                storage_plugin_h this = (storage_plugin_h) list->data;
+
+                if (0 == strcmp(this->uri, uri))
+                {
+                        ret = SERVICE_ADAPTOR_ERROR_NONE;
+                        // TODO: increase ref count
+                        break;
+                }
+        }
+
+        g_mutex_unlock(&storage->mutex);
+
+        return ret;
+}
+
+API service_adaptor_error_e storage_adaptor_unref_plugin(storage_adaptor_h storage, const char *uri)
+{
+        SAL_FN_CALL;
+
+        RETV_IF(NULL == storage, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+        RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+        g_mutex_lock(&storage->mutex);
+
+        int ret = SERVICE_ADAPTOR_ERROR_NO_DATA;
+
+        for (GList *list = g_list_first(storage->plugins); list != NULL; list = list->next)
+        {
+                storage_plugin_h this = (storage_plugin_h) list->data;
+
+                if (0 == strcmp(this->uri, uri))
+                {
+                        ret = SERVICE_ADAPTOR_ERROR_NONE;
+                        // TODO: decrease ref count
+                        break;
+                }
+        }
+
+        g_mutex_unlock(&storage->mutex);
+
+        return ret;
+}
index 5b52a87..fa08897 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Auth Adaptor
+ * Storage Adaptor
  *
  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
  *
  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
@@ -30,7 +30,11 @@ extern "C"
 #endif
 
 #include <stdio.h>
 #endif
 
 #include <stdio.h>
+#include <glib.h>
+
 #include "service_adaptor_errors.h"
 #include "service_adaptor_errors.h"
+#include "cloud_service.h"
+//#include "posix_service.h"
 
 /**
  * @file storage_adaptor.h
 
 /**
  * @file storage_adaptor.h
@@ -49,24 +53,73 @@ extern "C"
  * @{
  */
 
  * @{
  */
 
+#define URI_STORAGE    "storage"
+#define URI_CLOUD      "storage/cloud"
+#define URI_POSIX      "storage/posix"
+
+/**
+ * @brief Describes infromation about Storage Spec
+ */
+typedef enum _storage_spec_e
+{
+       STORAGE_SPEC_CLOUD      = (1 << 0),
+       STORAGE_SPEC_POSIX      = (1 << 1),
+} storage_spec_e;
+
+/**
+ * @brief Describes infromation about Storage Plugin
+ */
+typedef struct _storage_plugin_s
+{
+       char *uri;
+       char *name;
+       char *package;
+
+       cloud_service_h cloud;
+//     posix_service_h posix;
+
+       GMutex mutex;
+       GCond cond;
+} storage_plugin_s;
+typedef struct _storage_plugin_s *storage_plugin_h;
+
+/**
+ * @brief Describes infromation about Storage Adaptor
+ */
 typedef struct _storage_adaptor_s
 {
 typedef struct _storage_adaptor_s
 {
-       int i;
+       GList *plugins;         // storage_plugin_h
+
+       GMutex mutex;
+       int start;
 } storage_adaptor_s;
 typedef struct _storage_adaptor_s *storage_adaptor_h;
 
 } storage_adaptor_s;
 typedef struct _storage_adaptor_s *storage_adaptor_h;
 
+/**
+ * @brief Describes infromation about Storage Adaptor Listener
+ */
 typedef struct _storage_adaptor_listener_s
 {
 typedef struct _storage_adaptor_listener_s
 {
-       int i;
+       void (*create_file_cb)(const char *uri, const char *path, void *user_data);
 } storage_adaptor_listener_s;
 typedef struct _storage_adaptor_listener_s *storage_adaptor_listener_h;
 
 } storage_adaptor_listener_s;
 typedef struct _storage_adaptor_listener_s *storage_adaptor_listener_h;
 
-API storage_adaptor_h storage_adaptor_create();
-API service_adaptor_error_e storage_adaptor_destroy(storage_adaptor_h storage);
-API service_adaptor_error_e storage_adaptor_start(storage_adaptor_h storage);
-API service_adaptor_error_e storage_adaptor_stop(storage_adaptor_h storage);
-API service_adaptor_error_e storage_adaptor_register_listener(storage_adaptor_h storage, storage_adaptor_listener_h listener);
-API service_adaptor_error_e storage_adaptor_unregister_listener(storage_adaptor_h storage, storage_adaptor_listener_h listener);
+storage_adaptor_h storage_adaptor_create();
+service_adaptor_error_e storage_adaptor_destroy(storage_adaptor_h storage);
+service_adaptor_error_e storage_adaptor_start(storage_adaptor_h storage);
+service_adaptor_error_e storage_adaptor_stop(storage_adaptor_h storage);
+service_adaptor_error_e storage_adaptor_register_listener(storage_adaptor_h storage, storage_adaptor_listener_h listener);
+service_adaptor_error_e storage_adaptor_unregister_listener(storage_adaptor_h storage, storage_adaptor_listener_h listener);
+service_adaptor_error_e storage_adaptor_create_plugin(const char *uri, const char *name, const char *package, storage_plugin_h *plugin);
+service_adaptor_error_e storage_adaptor_destroy_plugin(storage_plugin_h plugin);
+service_adaptor_error_e storage_adaptor_register_plugin_service(storage_plugin_h plugin, GHashTable *service);
+service_adaptor_error_e storage_adaptor_unregister_plugin_service(storage_plugin_h plugin);
+service_adaptor_error_e storage_adaptor_add_plugin(storage_adaptor_h storage, storage_plugin_h plugin);
+service_adaptor_error_e storage_adaptor_remove_plugin(storage_adaptor_h storage, storage_plugin_h plugin);
+storage_plugin_h storage_adaptor_get_plugin(storage_adaptor_h storage, const char *uri);
+char *storage_adaptor_get_uri(storage_adaptor_h storage, const char *package);
+service_adaptor_error_e storage_adaptor_ref_plugin(storage_adaptor_h storage, const char *uri);
+service_adaptor_error_e storage_adaptor_unref_plugin(storage_adaptor_h storage, const char *uri);
 
 /**
  * @}
 
 /**
  * @}
index b421dab..59925a8 100644 (file)
@@ -15,19 +15,25 @@ SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
 
+ADD_DEFINITIONS("-DSERVICE_ADAPTOR_DEBUGGING")
+ADD_DEFINITIONS("-D_SERVICE_ADAPTOR_IPC_CLIENT")
+
 ##########################################################
 # Define Service Adaptor CLIENT
 ##########################################################
 
 ##########################################################
 # Define Service Adaptor CLIENT
 ##########################################################
 
-SET(CLIENT-LIB "sal-client")
-SET(CLIENT-SRCS
-        ${CMAKE_SOURCE_DIR}/client/sal_core_api.c
+SET(ADAPTOR-CLIENT-LIB "service-adaptor")
+SET(ADAPTOR-CLIENT-SRCS
+        ${CMAKE_SOURCE_DIR}/client/sal_service_adaptor.c
+        ${CMAKE_SOURCE_DIR}/client/sal_service_task.c
+        ${CMAKE_SOURCE_DIR}/client/sal_service_auth.c
+        ${CMAKE_SOURCE_DIR}/client/sal_service_storage.c
 )
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
         ${CMAKE_SOURCE_DIR}/common
 )
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
         ${CMAKE_SOURCE_DIR}/common
-        ${CMAKE_SOURCE_DIR}/common/ipc
+        ${CMAKE_SOURCE_DIR}/common/ipc-client
         ${CMAKE_SOURCE_DIR}/client
         ${CMAKE_SOURCE_DIR}/adaptor/auth-adaptor
         ${CMAKE_SOURCE_DIR}/adaptor/contact-adaptor
         ${CMAKE_SOURCE_DIR}/client
         ${CMAKE_SOURCE_DIR}/adaptor/auth-adaptor
         ${CMAKE_SOURCE_DIR}/adaptor/contact-adaptor
@@ -35,29 +41,83 @@ INCLUDE_DIRECTORIES(
 )
 
 INCLUDE(FindPkgConfig)
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(client_pkgs REQUIRED dlog glib-2.0)
+pkg_check_modules(adaptor_client_pkgs REQUIRED dlog glib-2.0 capi-appfw-application)
 
 
-FOREACH(flag ${client_pkgs_CFLAGS})
+FOREACH(flag ${adaptor_client_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
-ADD_LIBRARY(${CLIENT-LIB} SHARED ${CLIENT-SRCS})
+ADD_LIBRARY(${ADAPTOR-CLIENT-LIB} SHARED ${ADAPTOR-CLIENT-SRCS})
 
 
-TARGET_LINK_LIBRARIES(${CLIENT-LIB} ${client_pkgs_LDFLAGS} sal-common)
-SET_TARGET_PROPERTIES(${CLIENT-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
-SET_TARGET_PROPERTIES(${CLIENT-LIB} PROPERTIES VERSION ${VERSION})
+TARGET_LINK_LIBRARIES(${ADAPTOR-CLIENT-LIB} ${adaptor_client_pkgs_LDFLAGS} sal-common-client)
+SET_TARGET_PROPERTIES(${ADAPTOR-CLIENT-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${ADAPTOR-CLIENT-LIB} PROPERTIES VERSION ${VERSION})
 
 
-INSTALL(TARGETS ${CLIENT-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+INSTALL(TARGETS ${ADAPTOR-CLIENT-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
 
 
-SET(SAL-CLIENT-HEADERS
+SET(SAL-ADAPTOR-CLIENT-HEADERS
         ${CMAKE_SOURCE_DIR}/include/service_adaptor.h
         ${CMAKE_SOURCE_DIR}/include/service_adaptor_types.h
         ${CMAKE_SOURCE_DIR}/include/service_adaptor_errors.h
         ${CMAKE_SOURCE_DIR}/include/service_adaptor_internal.h
         ${CMAKE_SOURCE_DIR}/include/service_adaptor.h
         ${CMAKE_SOURCE_DIR}/include/service_adaptor_types.h
         ${CMAKE_SOURCE_DIR}/include/service_adaptor_errors.h
         ${CMAKE_SOURCE_DIR}/include/service_adaptor_internal.h
+        ${CMAKE_SOURCE_DIR}/client/sal_service_adaptor.h
+        ${CMAKE_SOURCE_DIR}/client/sal_service_task.h
+        ${CMAKE_SOURCE_DIR}/client/sal_service_auth.h
+        ${CMAKE_SOURCE_DIR}/client/sal_service_storage.h
+        ${CMAKE_SOURCE_DIR}/common/sal_ipc.h
+        ${CMAKE_SOURCE_DIR}/common/ipc-client/sal_ipc_client.h
+        ${CMAKE_SOURCE_DIR}/common/ipc-client/sal_ipc_client_core.h
+        ${CMAKE_SOURCE_DIR}/common/ipc-client/sal_ipc_client_auth.h
+        ${CMAKE_SOURCE_DIR}/common/ipc-client/sal_ipc_client_storage.h
+)
+
+INSTALL(FILES ${SAL-ADAPTOR-CLIENT-HEADERS} DESTINATION include/service-adaptor)
+
+##########################################################
+# Define Service Provider CLIENT
+##########################################################
+
+SET(PLUGIN-CLIENT-LIB "service-provider")
+SET(PLUGIN-CLIENT-SRCS
+        ${CMAKE_SOURCE_DIR}/client/sal_service_provider.c
+        ${CMAKE_SOURCE_DIR}/client/sal_auth_provider.c
+        ${CMAKE_SOURCE_DIR}/client/sal_storage_provider.c
+)
+
+INCLUDE_DIRECTORIES(
+        ${CMAKE_SOURCE_DIR}/include
+        ${CMAKE_SOURCE_DIR}/client
+        ${CMAKE_SOURCE_DIR}/adaptor/auth-adaptor
+        ${CMAKE_SOURCE_DIR}/adaptor/contact-adaptor
+        ${CMAKE_SOURCE_DIR}/adaptor/storage-adaptor
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(plugin_client_pkgs REQUIRED dlog glib-2.0 capi-appfw-application)
+
+FOREACH(flag ${plugin_client_pkgs_CFLAGS})
+        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${PLUGIN-CLIENT-LIB} SHARED ${PLUGIN-CLIENT-SRCS})
+
+TARGET_LINK_LIBRARIES(${PLUGIN-CLIENT-LIB} ${plugin_client_pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${PLUGIN-CLIENT-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${PLUGIN-CLIENT-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${PLUGIN-CLIENT-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
+SET(SAL-PLUGIN-CLIENT-HEADERS
+        ${CMAKE_SOURCE_DIR}/include/service_provider.h
+        ${CMAKE_SOURCE_DIR}/client/sal_service_provider.h
+        ${CMAKE_SOURCE_DIR}/client/sal_auth_provider.h
+        ${CMAKE_SOURCE_DIR}/client/sal_storage_provider.h
 )
 
 )
 
-INSTALL(FILES ${SAL-CLIENT-HEADERS} DESTINATION include/service-adaptor)
+INSTALL(FILES ${SAL-PLUGIN-CLIENT-HEADERS} DESTINATION include/service-provider)
diff --git a/client/sal_auth_provider.c b/client/sal_auth_provider.c
new file mode 100644 (file)
index 0000000..f1cccbd
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Auth Plugin Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+#include <app.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_service_provider.h"
+#include "sal_auth_provider.h"
+
+API int auth_provider_create(auth_provider_h *provider)
+{
+       SAL_FN_CALL;
+
+       auth_provider_h auth_provider = (auth_provider_h) g_malloc0(sizeof(auth_provider_s));
+
+       auth_provider->oauth1_get_access_token = NULL;
+       auth_provider->oauth1_get_extra_data = NULL;
+
+       auth_provider->oauth2_get_access_token = NULL;
+       auth_provider->oauth2_get_extra_data = NULL;
+
+       *provider = auth_provider;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API app_control_h auth_provider_message(auth_provider_h provider, const char *operation, void *user_data)
+{
+       SAL_FN_CALL;
+
+       app_control_h reply = NULL;
+
+       RETV_IF(NULL == provider, reply);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       if (0 == strcmp(operation, OAUTH1_0_GET_ACCESS_TOKEN_URI))
+       {
+               app_control_create(&reply);
+
+               char *access_token = NULL;
+               ret = provider->oauth1_get_access_token(&access_token);
+
+               if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+               {
+                       SAL_ERR("oauth1_get_access_token() Fail (%d)", ret);
+                       app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_FAILURE);
+                       return reply;
+               }
+
+               app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_SUCCESS);
+               app_control_add_extra_data(reply, OAUTH1_0_ACCESS_TOKEN_KEY, access_token);
+       }
+
+       return reply;
+}
+
+API int auth_provider_add_extra_data(auth_provider_h provider, app_control_h reply)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == reply, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       app_control_add_extra_data(reply, PLUGIN_KEY_AUTH, PLUGIN_VALUE_TRUE);
+
+       if (NULL != provider->oauth1_get_access_token)
+       {
+               app_control_add_extra_data(reply, OAUTH1_0_GET_ACCESS_TOKEN_URI, PLUGIN_VALUE_TRUE);
+       }
+
+       if (NULL != provider->oauth1_get_extra_data)
+       {
+               app_control_add_extra_data(reply, OAUTH1_0_GET_EXTRA_DATA_URI, PLUGIN_VALUE_TRUE);
+       }
+
+       if (NULL != provider->oauth2_get_access_token)
+       {
+               app_control_add_extra_data(reply, OAUTH2_0_GET_ACCESS_TOKEN_URI, PLUGIN_VALUE_TRUE);
+       }
+
+       if (NULL != provider->oauth2_get_extra_data)
+       {
+               app_control_add_extra_data(reply, OAUTH2_0_GET_EXTRA_DATA_URI, PLUGIN_VALUE_TRUE);
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/client/sal_auth_provider.h b/client/sal_auth_provider.h
new file mode 100644 (file)
index 0000000..2c91809
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Auth Plugin Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __AUTH_PLUGIN_CLIENT_H__
+#define __AUTH_PLUGIN_CLIENT_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <app.h>
+
+#include "service_adaptor_errors.h"
+
+#define OAUTH1_0_ACCESS_TOKEN_KEY      "access_token"
+
+#define OAUTH1_0_GET_ACCESS_TOKEN_URI  "http://tizen.org/service-adaptor/auth/oauth1.0/get_access_token"
+#define OAUTH1_0_GET_EXTRA_DATA_URI    "http://tizen.org/service-adaptor/auth/oauth1.0/get_extra_data"
+
+#define OAUTH2_0_GET_ACCESS_TOKEN_URI  "http://tizen.org/service-adaptor/auth/oauth2.0/get_access_token"
+#define OAUTH2_0_GET_EXTRA_DATA_URI    "http://tizen.org/service-adaptor/auth/oauth2.0/get_extra_data"
+
+/**
+ * @brief Describes infromation about Auth Plugin Handle
+ */
+typedef struct _auth_provider_s
+{
+       // oAuth 1.0
+       service_adaptor_error_e (*oauth1_get_access_token)(char **access_token);
+       service_adaptor_error_e (*oauth1_get_extra_data)(const char *key, char **value);
+
+       // oAuth 2.0
+       service_adaptor_error_e (*oauth2_get_access_token)(char **access_token);
+       service_adaptor_error_e (*oauth2_get_extra_data)(const char *key, char **value);
+} auth_provider_s;
+typedef struct _auth_provider_s *auth_provider_h;
+
+int auth_provider_create(auth_provider_h *provider);
+app_control_h auth_provider_message(auth_provider_h provider, const char *operation, void *user_data);
+int auth_provider_add_extra_data(auth_provider_h provider, app_control_h reply);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUTH_PLUGIN_CLIENT_H__ */
diff --git a/client/sal_core_api.c b/client/sal_core_api.c
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/client/sal_core_api.h b/client/sal_core_api.h
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/client/sal_plugin_api.c b/client/sal_plugin_api.c
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/client/sal_restful_api.c b/client/sal_restful_api.c
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/client/sal_service_adaptor.c b/client/sal_service_adaptor.c
new file mode 100644 (file)
index 0000000..971c316
--- /dev/null
@@ -0,0 +1,307 @@
+/*
+ * Service Adaptor
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include <app.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_service_adaptor.h"
+#include "sal_service_task.h"
+#include "sal_service_task_internal.h"
+#include "sal_ipc_client.h"
+#include "sal_ipc_client_core.h"
+#include "sal_ipc_client_auth.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+/**
+ * @brief Describes infromation about Adaptor Handle
+ */
+typedef struct _service_adaptor_s
+{
+       char *uri;
+
+       GList *plugins;         /* char **plugins (uri) */
+       GList *started_plugins; /* service_plugin_h **started_plugins */
+} service_adaptor_s;
+typedef struct _service_adaptor_s *service_adaptor_h;
+
+/**
+ * @brief Describes infromation about Plugin Handle
+ */
+typedef struct _service_plugin_s
+{
+       char *uri;
+} service_plugin_s;
+
+service_adaptor_h service_adaptor = NULL;
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int service_adaptor_connect()
+{
+       SAL_FN_CALL;
+
+       service_adaptor = (service_adaptor_h) g_malloc0(sizeof(service_adaptor_s));
+
+       char *uri = NULL;
+
+       app_get_id(&uri);
+
+       if (NULL == uri)
+       {
+               char path[1024] = {0,};
+               int path_len = 0;
+
+               path_len = readlink("/proc/self/exe", path, 1024);
+               RETV_IF(0 == path_len, SERVICE_ADAPTOR_ERROR_SYSTEM);
+
+               uri = strndup(path, path_len);
+       }
+
+       service_adaptor->uri = strdup(uri);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+       ret = sal_ipc_client_init();
+       RETV_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL);
+
+       GList *plugins = NULL;
+       ret = ipc_service_adaptor_connect(uri, &plugins);
+       RETV_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL);
+
+       ret = service_task_connect();
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "service_task_connect() Failed");
+
+       service_adaptor->plugins = plugins;
+
+       SAL_FREE(uri);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_adaptor_disconnect()
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+       ret = service_task_disconnect();
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "service_task_disconnect() Failed");
+
+       ret = ipc_service_adaptor_disconnect(service_adaptor->uri);
+       RETV_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL);
+
+       ret = sal_ipc_client_deinit();
+       RETV_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL);
+
+       // TODO: free memory in adaptor
+       SAL_FREE(service_adaptor);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_adaptor_foreach_plugin(service_adaptor_plugin_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       RETV_IF(0 == g_list_length(service_adaptor->plugins), SERVICE_ADAPTOR_ERROR_NO_DATA);
+
+       for (GList *list = g_list_first(service_adaptor->plugins); list != NULL; list = list->next)
+       {
+               char * uri = (char *) list->data;
+
+               bool ret = callback(uri, 0, user_data);
+               RETV_IF(false == ret, SERVICE_ADAPTOR_ERROR_NONE);
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_adaptor_get_last_result(int *err)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == err, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_adaptor_get_last_error_message(char **message)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == message, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_plugin_create(const char *uri, service_plugin_h *plugin)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = ipc_service_plugin_create(uri);
+       RETV_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       service_plugin_h service_plugin = (service_plugin_h) g_malloc0(sizeof(service_plugin_s));
+
+       service_plugin->uri = strdup(uri);
+
+       *plugin = service_plugin;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_plugin_destroy(service_plugin_h plugin)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = ipc_service_plugin_destroy(plugin->uri);
+       RETV_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       // TODO: free memeory of plugin
+       SAL_FREE(plugin);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_plugin_add_property(service_plugin_h plugin, const char *key, const char *value)
+{
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == key, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == value, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_plugin_remove_property(service_plugin_h plugin, const char *key)
+{
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == key, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_plugin_get_property(service_plugin_h plugin, const char *key, char **value)
+{
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == key, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == value, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_plugin_login(service_plugin_h plugin, service_plugin_login_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       // TODO: login this plugin via service adaptor (dbus)
+
+       callback(SERVICE_ADAPTOR_ERROR_NONE, user_data);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_plugin_start(service_plugin_h plugin)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       // TODO: check this plugin via service adaptor (dbus), use or not use?, must be logined.
+
+       service_adaptor->started_plugins = g_list_append(service_adaptor->started_plugins, plugin);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_plugin_stop(service_plugin_h plugin)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       // TODO: notify to stop this plugin to service adaptor (dbus)
+
+       for (GList *list = g_list_first(service_adaptor->started_plugins); list != NULL; list = list->next)
+       {
+               service_plugin_h service_plugin = (service_plugin_h) list->data;
+
+               if (0 == strcmp(service_plugin->uri, plugin->uri))
+               {
+                       service_adaptor->started_plugins = g_list_remove(service_adaptor->started_plugins, list);
+
+                       return SERVICE_ADAPTOR_ERROR_NONE;
+               }
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+int service_plugin_get_uri(service_plugin_h plugin, char **uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == g_list_find(service_adaptor->started_plugins, plugin), SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       *uri = strdup(plugin->uri);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/client/sal_service_adaptor.h b/client/sal_service_adaptor.h
new file mode 100644 (file)
index 0000000..4116eee
--- /dev/null
@@ -0,0 +1,376 @@
+/*
+ * Service Adaptor
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SERVICE_ADAPTOR_H__
+#define __SERVICE_ADAPTOR_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+
+/**
+ * @addtogroup  SERVICE_ADAPTOR_MODULE
+ * @{
+ */
+
+/**
+ * @brief Type of service in plugin
+ */
+typedef enum _service_plugin_type_e
+{
+       SERVICE_PLUGIN_AUTH     = (0x01 << 0),          /**< Auth service type flag */
+       SERVICE_PLUGIN_STORAGE  = (0x01 << 1),          /**< Storage service type flag */
+} service_plugin_type_e;
+
+/**
+ * @brief Definition for the service_plugin property: The application id be issued from service provider for 3rd party developer.
+ * @since_tizen 2.4
+ * @see service_plugin_add_property()
+ * @see service_plugin_remove_property()
+ * @see service_plugin_get_property()
+ */
+#define SERVICE_PLUGIN_PROPERTY_APP_KEY                "http://tizen.org/service-adaptor/plugin/property/app_key"
+
+/**
+ * @brief Definition for the service_plugin property: The application password be issued from service provider for 3rd party developer.
+ * @since_tizen 2.4
+ * @see service_plugin_add_property()
+ * @see service_plugin_remove_property()
+ * @see service_plugin_get_property()
+ */
+#define SERVICE_PLUGIN_PROPERTY_APP_SECRET     "http://tizen.org/service-adaptor/plugin/property/app_secret"
+
+/**
+ * @brief Definition for the service_plugin property: The user id for using specific service.
+ * @since_tizen 2.4
+ * @see service_plugin_add_property()
+ * @see service_plugin_remove_property()
+ * @see service_plugin_get_property()
+ */
+#define SERVICE_PLUGIN_PROPERTY_USER_ID                "http://tizen.org/service-adaptor/plugin/property/user_id"
+
+/**
+ * @brief The handle for connection and managing handle of Service Plugin
+ * @details The handle can be created by service_plugin_create()<br>
+ *  When a handle is no longer needed, use service_plugin_destroy()
+ * @see #service_plugin_create()
+ * @see #service_plugin_destroy()
+ */
+typedef struct _service_plugin_s *service_plugin_h;
+
+/**
+ * @brief Callback for service_adaptor_foreach_plugin API
+ *
+ * @param[in]    uri      The service plugin's unique uri, this value be set by plugin
+ * @param[in]    service_mask    Masked value for <b>installed</b> service plugins, this value can be masked multiple enum (#service_plugin_service_type_e)
+ * @param[in]    user_data       Passed data from #service_adaptor_foreach_plugin()
+ * @remarks      @a service_mask check using 'bit and' operation with #service_plugin_service_type_e
+ * @remarks      - for example,
+ * @remarks      &nbsp;&nbsp;&nbsp;&nbsp;        if(@a service_mask & SERVICE_PLUGIN_SERVICE_STORAGE)
+ * @remarks      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        { @a USING_STORAGE_CODE }
+ * @remarks Do not release memory of @a plugin_uri
+ * @see          service_plugin_service_type_e
+ * @return @c true to continue with the next iteration of the loop,
+ *         otherwise @c false to break out of the loop
+ * @pre  service_adaptor_foreach_plugin() will invoke this callback.
+ */
+typedef bool (*service_adaptor_plugin_cb)(const char *uri,
+               int service_mask,
+               void *user_data);
+
+/**
+ * @brief Callback for service_plugin_login API
+ *
+ * @param[in]    result
+ * @param[in]    user_data       Passed data from #service_plugin_login()
+ * @remarks
+ * @return void
+ * @pre  service_plugin_login() will invoke this callback.
+ */
+typedef void (*service_plugin_login_cb)(int result,
+               void *user_data);
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+/**
+ * @brief Create Service Adaptor
+ * @since_tizen        2.4
+ *
+ * @param[out] service_adaptor The Service Adaptor handle
+ * @remarks    @a service_adaptor must be released memory using service_adaptor_destroy(), when a program no longer needs any function of Service Adaptor
+ * @see                service_adaptor_destroy()
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ */
+int service_adaptor_connect();
+
+/**
+ * @brief      Destroy Service Adaptor
+ * @details    It must called after a program no longer needs any function of Service Adaptor
+ * @since_tizen        2.4
+ *
+ * @param[in]  service_adaptor The handle of Service Adaptor
+ * @see                service_adaptor_create()
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ * @pre  @a service_adaptor must be issued by service_adaptor_create()
+ */
+int service_adaptor_disconnect();
+
+/**
+ * @brief Foreach the list of plugin
+ * @details Iterate to all installed plugin
+ * @since_tizen 2.4
+ *
+ * @param[in]    callback        The callback for foreach plugin
+ * @param[in]    user_data       Passed data to callback
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_NO_DATA There is no available plugins
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ * @pre  @a service_adaptor must be issued by service_adaptor_create()
+ */
+int service_adaptor_foreach_plugin(service_adaptor_plugin_cb callback,
+               void *user_data);
+
+/**
+ * @brief Gets service specfic last result
+ * @details This function retrieves the last error code that be issued from plugin.<br>
+ *  When if API function returns #SERVICE_ADAPTOR_ERROR_PLUGIN_FAILED, gets using this function.
+ * @since_tizen 2.4
+ *
+ * @param[out]   err     The error number that is defined service plugin SPEC
+ * @remarks      Thread safe functions
+ * @remarks      The result number's detail specification is defined service plugin or provider.
+ * @remarks      The detail error message can be got using service_adaptor_get_last_error_message()
+ * @see          service_adaptor_get_last_error_message()
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_NO_DATA There is no result
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ */
+int service_adaptor_get_last_result(int *err);
+
+/**
+ * @brief Gets service specfic last result error message
+ * @details This function retrieves the last error code that be issued from plugin.<br>
+ *  When if API function returns #SERVICE_ADAPTOR_ERROR_PLUGIN_FAILED, gets using this function.
+ * @since_tizen 2.4
+ *
+ * @param[out]   message The error message that is defined service plugin SPEC
+ * @remarks      @a message must be released using free()
+ * @remarks      Thread safe functions
+ * @remarks      The result string's detail specification is defined service plugin or provider.
+ * @see          service_adaptor_get_last_result()
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_NO_DATA There is no error message
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ */
+int service_adaptor_get_last_error_message(char **message);
+
+/*
+int service_adaptor_add_plugin(service_adaptor_h adaptor_client, const char *plugin_uri);
+int service_adaptor_remove_plugin(service_adaptor_h adaptor_client, const char *plugin_uri);
+int service_adaptor_get_auth(service_adaptor_h adaptor_client, const char *uri, service_auth_h *auth);
+*/
+
+/**
+ * @brief Create service plugin handle
+ * @details Create plugin handle using @a plugin_uri
+ * @since_tizen 2.4
+ *
+ * @param[in]    service_adaptor The handle of Service Adaptor
+ * @param[in]    plugin_uri      The specfic string for use plugin, this values are set by plugin
+ * @param[out]   plugin          The handle for use Plugin APIs
+ * @remarks      @a plugin must be released memory using service_plugin_destroy() when you no longer needs plugin's API
+ * @see          service_plugin_destroy()
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ * @pre  @a service_adaptor must be issued by service_adaptor_create()
+ */
+int service_plugin_create(const char *uri, service_plugin_h *plugin);
+
+/**
+ * @brief        Destroy service plugin handle
+ * @details      It must called after a program no longer needs APIs of specfic plugin
+ * @since_tizen 2.4
+ *
+ * @param[in]    plugin  The handle for use Plugin APIs
+ * @see  service_adaptor_create_plugin()
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ * @pre  @a plugin must be issued by service_adaptor_create_plugin()
+ */
+int service_plugin_destroy(service_plugin_h plugin);
+
+/**
+ * @brief Add Plugin Property
+ * @details The plguin property is used for plugin's basic or optional requirement.<br>
+ *  This value is not used in Adaptor layer, but it can be uesd to important Key for plugin with service provider.<br>
+ * @since_tizen 2.4
+ *
+ * @param[in]    plugin  The handle for use Plugin APIs
+ * @param[in]    key     The key of plugin property
+ * @param[in]    value   The value of plugin property that matched @a key
+ * @remarks      Some kind of property key(Not mandatory) is defined in this API (That is named to SERVICE_PLUGIN_PROPERTY_XXX)
+ * @remarks      If the @a key already exists in the property its current value is replaced with the new @a value.
+ * @remarks      @a plugin must be released memory using #service_plugin_destroy() when you no longer needs plugin's API
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ * @see  SERVICE_PLUGIN_PROPERTY_APP_KEY
+ * @see  SERVICE_PLUGIN_PROPERTY_APP_SECRET
+ * @see  SERVICE_PLUGIN_PROPERTY_USER_ID
+ * @pre  @a plugin must be issued by service_adaptor_create_plugin()
+ */
+int service_plugin_add_property(service_plugin_h plugin,
+               const char *key,
+               const char *value);
+
+/**
+ * @brief Remove Plugin Property
+ * @since_tizen 2.4
+ *
+ * @param[in]    plugin  The handle for use Plugin APIs
+ * @param[in]    key     The key of plugin property
+ * @remarks      Some kind of property key(Not mandatory) is defined in this API (That is named to SERVICE_PLUGIN_PROPERTY_XXX)
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ * @see  SERVICE_PLUGIN_PROPERTY_APP_KEY
+ * @see  SERVICE_PLUGIN_PROPERTY_APP_SECRET
+ * @see  SERVICE_PLUGIN_PROPERTY_USER_ID
+ */
+int service_plugin_remove_property(service_plugin_h plugin,
+               const char *key);
+
+/**
+ * @brief Gets Plugin Property
+ * @since_tizen 2.4
+ *
+ * @param[in]    plugin  The handle for use Plugin APIs
+ * @param[in]    key     The key of plugin property
+ * @param[out]   value   The value of plugin property that matched @a key
+ * @remarks      Some kind of property key(Not mandatory) is defined in this API (That is named to SERVICE_PLUGIN_PROPERTY_XXX)
+ * @remarks      @a value must be released using free()
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_NO_DATA There is no property
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ * @see  SERVICE_PLUGIN_PROPERTY_APP_KEY
+ * @see  SERVICE_PLUGIN_PROPERTY_APP_SECRET
+ * @see  SERVICE_PLUGIN_PROPERTY_USER_ID
+ * @pre  The function get property already set by service_adaptor_set_plugin_property()
+ */
+int service_plugin_get_property(service_plugin_h plugin,
+               const char *key,
+               char **value);
+
+/**
+ * @brief Logins Plugin using Property
+ * @since_tizen 3.0
+ *
+ * @param[in]    plugin  The handle for use Plugin APIs
+ * @param[in]    callback        The callback for login
+ * @param[in]    user_data       Passed data to callback
+ * @remarks
+ * @remarks      @a value must be released using free()
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_NO_DATA There is no property
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ * @pre  The function get property already set by service_adaptor_set_plugin_property()
+ */
+int service_plugin_login(service_plugin_h plugin, service_plugin_login_cb callback, void *user_data);
+
+/**
+ * @brief Requests start initalization for service plugin
+ * @since_tizen 2.4
+ *
+ * @param[in]    plugin          The handle for use Plugin APIs
+ * @remarks      @a service_mask must be input using 'bit or' operation with #service_plugin_service_type_e
+ * @remarks      - for example,
+ * @remarks      &nbsp;&nbsp;&nbsp;&nbsp;        <b>int</b> @a service_mask |= SERVIE_PLUGIN_SERVICE_AUTH;
+ * @remarks      &nbsp;&nbsp;&nbsp;&nbsp;        @a service_mask |= SERVICE_PLUGIN_SERVICE_STORAGE;
+ * @remarks      &nbsp;&nbsp;&nbsp;&nbsp;        <b>int</b> ret = service_plugin_start(@a m_plugin, @a service_mask);
+ * @remarks      If a program needs to stop plugin manually, use #service_plugin_stop(). <br>But in #service_plugin_destroy(), automatically stop service plugin
+ * @see          service_plugin_service_type_e
+ * @see          service_plugin_stop()
+ * @return 0 on success, otherwise a negative error value
+ * @return If return value is #SERVICE_ADAPTOR_ERROR_NOT_AUTHOLIZED, request signup to autholization application
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SERVICE_ADAPTOR_ERROR_NOT_AUTHOLIZED Need atholization
+ * @retval #SERVICE_ADAPTOR_ERROR_TIMED_OUT Timed out
+ * @retval #SERVICE_ADAPTOR_ERROR_IPC_UNSTABLE IPC failed with Service Adaptor Daemon
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ */
+int service_plugin_start(service_plugin_h plugin);
+/**
+ * @brief Requests stop manually for service plugin
+ * @since_tizen 2.4
+ *
+ * @param[in]    plugin          The handle for use Plugin APIs
+ * @remarks      If a program needs to stop plugin manually, use this function. <br>But in #service_plugin_destroy(), automatically stop service plugin
+ * @remarks      @a plugin must be released memory using #service_plugin_destroy() when you no longer needs plugin's API
+ * @see          service_plugin_start()
+ * @see          service_plugin_destroy()
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SERVICE_ADAPTOR_ERROR_NONE Successful
+ * @retval #SERVICE_ADAPTOR_ERROR_TIMED_OUT Timed out
+ * @retval #SERVICE_ADAPTOR_ERROR_IPC_UNSTABLE IPC failed with Service Adaptor Daemon
+ * @retval #SERVICE_ADAPTOR_ERROR_UNKNOWN Unknown error
+ * @pre  service_plugin_start()
+ */
+int service_plugin_stop(service_plugin_h plugin);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_ADAPTOR_H__ */
diff --git a/client/sal_service_adaptor_internal.h b/client/sal_service_adaptor_internal.h
new file mode 100644 (file)
index 0000000..1b04bf4
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Service Adaptor Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SERVICE_ADAPTOR_CLIENT_INTERNAL_H__
+#define __SERVICE_ADAPTOR_CLIENT_INTERNAL_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "sal_service_adaptor.h"
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+int service_plugin_get_uri(service_plugin_h plugin, char **uri);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_ADAPTOR_CLIENT_INTERNAL_H__ */
diff --git a/client/sal_service_auth.c b/client/sal_service_auth.c
new file mode 100644 (file)
index 0000000..72ce859
--- /dev/null
@@ -0,0 +1,228 @@
+/*
+ * Auth Adaptor Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this oauth1 except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+#include <app.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_service_adaptor.h"
+#include "sal_service_adaptor_internal.h"
+#include "sal_service_task.h"
+#include "sal_service_task_internal.h"
+#include "sal_service_auth.h"
+#include "sal_service_auth_internal.h"
+#include "sal_ipc_client_auth.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+int service_auth_oauth1_start(service_auth_oauth1_h oauth1)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == oauth1->plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+       char *uri = NULL;
+
+       ret = service_plugin_get_uri(oauth1->plugin, &uri);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "service_plugin_get_uri() Failed(%d)", ret);
+
+       service_auth_oauth1_h auth_oauth1 = NULL;
+       ret = ipc_service_auth_oauth1(uri, oauth1, &auth_oauth1);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_service_auth_oauth1() Failed(%d)", ret);
+
+       RETV_IF(NULL == oauth1->callback, SERVICE_ADAPTOR_ERROR_NONE);
+
+       oauth1->callback(SERVICE_ADAPTOR_ERROR_NONE, auth_oauth1, oauth1->user_data);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+int service_auth_oauth1_stop(service_auth_oauth1_h oauth1)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int service_auth_oauth1_create(service_plugin_h plugin, service_auth_oauth1_h *oauth1)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       service_auth_oauth1_h auth_oauth1 = (service_auth_oauth1_h) g_malloc0(sizeof(service_auth_oauth1_s));
+       auth_oauth1->plugin = plugin;
+
+       *oauth1 = auth_oauth1;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_oauth1_clone(service_auth_oauth1_h src_oauth1, service_auth_oauth1_h *dst_oauth1)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == src_oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == dst_oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       service_auth_oauth1_h auth_oauth1 = (service_auth_oauth1_h) g_malloc0(sizeof(service_auth_oauth1_s));
+       auth_oauth1->plugin = src_oauth1->plugin;
+       auth_oauth1->callback = src_oauth1->callback;
+       auth_oauth1->access_token = strdup(src_oauth1->access_token);
+       auth_oauth1->operation = strdup(src_oauth1->operation);
+
+       *dst_oauth1 = auth_oauth1;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_oauth1_destroy(service_auth_oauth1_h oauth1)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       SAL_FREE(oauth1->access_token);
+       SAL_FREE(oauth1->operation);
+       SAL_FREE(oauth1);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_set_callback(service_auth_oauth1_h oauth1, service_auth_oauth1_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       oauth1->callback = callback;
+       oauth1->user_data = user_data;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_unset_callback(service_auth_oauth1_h oauth1)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       oauth1->callback = NULL;
+       oauth1->user_data = NULL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_set_access_token(service_auth_oauth1_h oauth1, const char *access_token)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == access_token, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       oauth1->access_token = strdup(access_token);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_get_access_token(service_auth_oauth1_h oauth1, char **access_token)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == access_token, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       *access_token = strdup(oauth1->access_token);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_set_operation(service_auth_oauth1_h oauth1, const char *operation)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       oauth1->operation = strdup(operation);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_get_operation(service_auth_oauth1_h oauth1, char **operation)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       *operation = strdup(oauth1->operation);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_create_task(service_auth_oauth1_h oauth1, service_task_h *task)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       service_task_h service_task = (service_task_h) g_malloc0(sizeof(service_task_s));
+       service_task->oauth1 = oauth1;
+
+       *task = service_task;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_auth_oauth1_destroy_task(service_task_h task)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       SAL_FREE(task);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/client/sal_service_auth.h b/client/sal_service_auth.h
new file mode 100644 (file)
index 0000000..97a5a3a
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Service Auth
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this oauth1 except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SERVICE_AUTH_H__
+#define __SERVICE_AUTH_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "sal_service_adaptor.h"
+#include "sal_service_task.h"
+
+#define SERVICE_AUTH_OAUTH1_0_GET_ACCESS_TOKEN_URI     "http://tizen.org/service-adaptor/auth/oauth1.0/get_access_token"
+#define SERVICE_AUTH_OAUTH1_0_GET_EXTRA_DATA_URI       "http://tizen.org/service-adaptor/auth/oauth1.0/get_extra_data"
+
+#define SERVICE_AUTH_OAUTH2_0_GET_ACCESS_TOKEN_URI     "http://tizen.org/service-adaptor/auth/oauth2.0/get_access_token"
+#define SERVICE_AUTH_OAUTH2_0_GET_EXTRA_DATA_URI       "http://tizen.org/service-adaptor/auth/oauth2.0/get_extra_data"
+
+typedef struct _service_auth_oauth1_s *service_auth_oauth1_h;
+
+typedef void (*service_auth_oauth1_cb)(int result, service_auth_oauth1_h oauth1, void *user_data);
+typedef void (*service_auth_oauth1_get_access_token_cb)(int result, const char *access_token, void *user_data);
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+int service_auth_oauth1_create(service_plugin_h plugin, service_auth_oauth1_h *oauth1);
+int service_auth_oauth1_clone(service_auth_oauth1_h src_oauth1, service_auth_oauth1_h *dst_oauth1);
+int service_auth_oauth1_destroy(service_auth_oauth1_h oauth1);
+int service_auth_oauth1_set_callback(service_auth_oauth1_h oauth1, service_auth_oauth1_cb callback, void *user_data);
+int service_auth_oauth1_unset_callback(service_auth_oauth1_h oauth1);
+int service_auth_oauth1_set_access_token(service_auth_oauth1_h oauth1, const char *access_token);
+int service_auth_oauth1_get_access_token(service_auth_oauth1_h oauth1, char **access_token);
+int service_auth_oauth1_set_operation(service_auth_oauth1_h oauth1, const char *operation);
+int service_auth_oauth1_get_operation(service_auth_oauth1_h oauth1, char **operation);
+int service_auth_oauth1_create_task(service_auth_oauth1_h oauth1, service_task_h *task);
+int service_auth_oauth1_destroy_task(service_task_h task);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_AUTH_H__ */
diff --git a/client/sal_service_auth_internal.h b/client/sal_service_auth_internal.h
new file mode 100644 (file)
index 0000000..8dbfae1
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Service Auth Internal
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SERVICE_AUTH_INTERNAL_H__
+#define __SERVICE_AUTH_INTERNAL_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+
+#include "sal_service_adaptor.h"
+#include "sal_service_auth.h"
+
+typedef struct _service_auth_oauth1_s
+{
+       service_plugin_h plugin;
+       service_auth_oauth1_cb callback;
+       void *user_data;
+
+       char *access_token;
+       char *operation;
+} service_auth_oauth1_s;
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+int service_auth_oauth1_start(service_auth_oauth1_h oauth1);
+int service_auth_oauth1_stop(service_auth_oauth1_h oauth1);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_AUTH_INTERNAL_H__ */
diff --git a/client/sal_service_provider.c b/client/sal_service_provider.c
new file mode 100644 (file)
index 0000000..5bef6b9
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * Service Plugin Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+#include <app.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_service_provider.h"
+
+API int service_provider_create(service_provider_h *provider)
+{
+       SAL_FN_CALL;
+
+       service_provider_h service_provider = (service_provider_h) g_malloc0(sizeof(service_provider_s));
+
+       service_provider->connect = NULL;
+       service_provider->disconnect = NULL;
+
+       *provider = service_provider;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_provider_destroy(service_provider_h provider)
+{
+       SAL_FN_CALL;
+
+       // TODO: free internal value of provider
+       SAL_FREE(provider);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_provider_set_auth_provider(service_provider_h provider, auth_provider_h auth_provider)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == auth_provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       provider->auth_provider = auth_provider;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_provider_unset_auth_provider(service_provider_h provider)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       provider->auth_provider = NULL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_provider_set_storage_provider(service_provider_h provider, storage_provider_h storage_provider)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == storage_provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       provider->storage_provider = storage_provider;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_provider_unset_storage_provider(service_provider_h provider)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       provider->storage_provider = NULL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_provider_message(service_provider_h provider, app_control_h app_control, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       char *operation = NULL;
+       app_control_get_operation(app_control, &operation);
+
+       RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       app_control_h reply = NULL;
+
+       if (0 == strcmp(operation, PLUGIN_CONNECT_URI))
+       {
+               app_control_create(&reply);
+               ret = provider->connect();
+
+               if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+               {
+                       SAL_ERR("connect() Fail (%d)", ret);
+                       app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_FAILURE);
+                       goto catch;
+               }
+
+               app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_SUCCESS);
+
+               auth_provider_add_extra_data(provider->auth_provider, reply);
+               storage_provider_add_extra_data(provider->storage_provider, reply);
+
+               // TODO: another adaptor
+       }
+       else if (0 == strcmp(operation, PLUGIN_DISCONNECT_URI))
+       {
+               app_control_create(&reply);
+               ret = provider->disconnect();
+
+               if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+               {
+                       SAL_ERR("connect() Fail (%d)", ret);
+                       app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_FAILURE);
+                       goto catch;
+               }
+
+               app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_SUCCESS);
+       }
+       else
+       {
+               reply = auth_provider_message(provider->auth_provider, operation, app_control);
+               TRY_IF(NULL != reply, "auth_plugin_client_message() Finded");
+
+               reply = storage_provider_message(provider->storage_provider, operation, app_control);
+               TRY_IF(NULL != reply, "storage_plugin_client_message() Finded");
+       }
+
+catch:
+       app_control_reply_to_launch_request(reply, app_control, APP_CONTROL_RESULT_SUCCEEDED);
+       app_control_destroy(reply);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/client/sal_service_provider.h b/client/sal_service_provider.h
new file mode 100644 (file)
index 0000000..bbdad47
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Service Plugin Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SERVICE_PLUGIN_CLIENT_H__
+#define __SERVICE_PLUGIN_CLIENT_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <app.h>
+
+#include "sal_auth_provider.h"
+#include "sal_storage_provider.h"
+
+#define PLUGIN_RESULT_KEY              "result"
+#define PLUGIN_RESULT_VALUE_SUCCESS    "success"
+#define PLUGIN_RESULT_VALUE_FAILURE    "failure"
+
+#define PLUGIN_KEY_AUTH                        "auth_plugin"
+#define PLUGIN_KEY_STORAGE             "storage_plugin"
+#define PLUGIN_VALUE_TRUE              "true"
+#define PLUGIN_VALUE_FALSE             "false"
+
+#define PLUGIN_CONNECT_URI             "connect"
+#define PLUGIN_DISCONNECT_URI          "disconnect"
+
+/**
+ * @brief Describes infromation about Plugin Handle
+ */
+typedef struct _service_provider_s
+{
+       service_adaptor_error_e (*connect)(void);
+       service_adaptor_error_e (*disconnect)(void);
+
+       auth_provider_h auth_provider;
+       storage_provider_h storage_provider;
+
+       char *uri;
+       char *name;
+} service_provider_s;
+typedef struct _service_provider_s *service_provider_h;
+
+int service_provider_create(service_provider_h *provider);
+int service_provider_destroy(service_provider_h provider);
+int service_provider_set_auth_provider(service_provider_h provider, auth_provider_h auth_provider);
+int service_provider_unset_auth_provider(service_provider_h provider);
+int service_provider_set_storage_provider(service_provider_h provider, storage_provider_h storage_provider);
+int service_provider_unset_storage_provider(service_provider_h provider);
+int service_provider_message(service_provider_h provider, app_control_h app_control, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_PLUGIN_CLIENT_H__ */
diff --git a/client/sal_service_storage.c b/client/sal_service_storage.c
new file mode 100644 (file)
index 0000000..02422cf
--- /dev/null
@@ -0,0 +1,313 @@
+/*
+ * Service Storage
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+#include <app.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_service_adaptor.h"
+#include "sal_service_adaptor_internal.h"
+#include "sal_service_task.h"
+#include "sal_service_task_internal.h"
+#include "sal_service_storage.h"
+#include "sal_service_storage_internal.h"
+#include "sal_ipc_client_storage.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+int service_storage_cloud_start(service_storage_cloud_file_h file)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == file->plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+       char *uri = NULL;
+
+       ret = service_plugin_get_uri(file->plugin, &uri);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "service_plugin_get_uri() Failed(%d)", ret);
+
+       service_storage_cloud_file_h cloud_file = NULL;
+       ret = ipc_service_storage_cloud_file(uri, file, &cloud_file);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_service_storage_cloud_file() Failed(%d)", ret);
+
+       RETV_IF(NULL == file->callback, SERVICE_ADAPTOR_ERROR_NONE);
+
+       file->callback(SERVICE_ADAPTOR_ERROR_NONE, cloud_file,  file->user_data);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+int service_storage_cloud_stop(service_storage_cloud_file_h file)
+{
+       SAL_FN_CALL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int service_storage_cloud_file_create(service_plugin_h plugin, service_storage_cloud_file_h *file)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       service_storage_cloud_file_h cloud_file = (service_storage_cloud_file_h) g_malloc0(sizeof(service_storage_cloud_file_s));
+       cloud_file->plugin = plugin;
+
+       *file = cloud_file;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_clone(service_storage_cloud_file_h src_file, service_storage_cloud_file_h *dst_file)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == src_file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       service_storage_cloud_file_h cloud_file = (service_storage_cloud_file_h) g_malloc0(sizeof(service_storage_cloud_file_s));
+       cloud_file->plugin = src_file->plugin;
+       cloud_file->callback = src_file->callback;
+       cloud_file->is_dir = src_file->is_dir;
+       cloud_file->dir_path = strdup(src_file->dir_path);
+       cloud_file->local_path = strdup(src_file->local_path);
+       cloud_file->cloud_path = strdup(src_file->cloud_path);
+       cloud_file->size = src_file->size;
+       cloud_file->operation = strdup(src_file->operation);
+       // TODO: g_list_copy_deep()
+       cloud_file->files = g_list_copy(src_file->files);
+
+       *dst_file = cloud_file;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_destroy(service_storage_cloud_file_h file)
+{
+       SAL_FN_CALL;
+
+       SAL_FREE(file->dir_path);
+       SAL_FREE(file->local_path);
+       SAL_FREE(file->cloud_path);
+       SAL_FREE(file->operation);
+       SAL_FREE(file);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_set_callback(service_storage_cloud_file_h file, service_storage_cloud_file_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       file->callback = callback;
+       file->user_data = user_data;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_unset_callback(service_storage_cloud_file_h file)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       file->callback = NULL;
+       file->user_data = NULL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_set_cloud_path(service_storage_cloud_file_h file, const char *cloud_path)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cloud_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       file->cloud_path = strdup(cloud_path);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_get_cloud_path(service_storage_cloud_file_h file, char **cloud_path)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == cloud_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       *cloud_path = strdup(file->cloud_path);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_set_local_path(service_storage_cloud_file_h file, const char *local_path)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == local_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       file->local_path = strdup(local_path);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_get_local_path(service_storage_cloud_file_h file, char **local_path)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == local_path, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       *local_path = strdup(file->local_path);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_set_size(service_storage_cloud_file_h file, unsigned long long size)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(0 > size, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       file->size = size;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_get_size(service_storage_cloud_file_h file, unsigned long long *size)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == size, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       *size = file->size;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_set_operation(service_storage_cloud_file_h file, const char *operation)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       file->operation = strdup(operation);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_get_operation(service_storage_cloud_file_h file, char **operation)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       *operation = strdup(file->operation);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_is_directory(service_storage_cloud_file_h file, bool *is_dir)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == is_dir, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       *is_dir = file->is_dir;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_foreach_file(service_storage_cloud_file_h file, service_storage_cloud_file_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       RETV_IF(false == file->is_dir, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       RETV_IF(0 == g_list_length(file->files), SERVICE_ADAPTOR_ERROR_NO_DATA);
+
+       for (GList *list = g_list_first(file->files); list != NULL; list = list->next)
+       {
+               service_storage_cloud_file_h file_data = (service_storage_cloud_file_h) list->data;
+
+               bool ret = callback(SERVICE_ADAPTOR_ERROR_NONE, file_data, user_data);
+               RETV_IF(false == ret, SERVICE_ADAPTOR_ERROR_NONE);
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_create_task(service_storage_cloud_file_h file, service_task_h *task)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       service_task_h service_task = (service_task_h) g_malloc0(sizeof(service_task_s));
+       service_task->cloud_file = file;
+
+       *task = service_task;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_storage_cloud_file_destroy_task(service_task_h task)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       SAL_FREE(task);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/client/sal_service_storage.h b/client/sal_service_storage.h
new file mode 100644 (file)
index 0000000..a8c10e0
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Service Storage
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SERVICE_STORAGE_H__
+#define __SERVICE_STORAGE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "sal_service_adaptor.h"
+#include "sal_service_task.h"
+
+#define SERVICE_STORAGE_CLOUD_REMOVE_FILE_URI   "http://tizen.org/service-adaptor/storage/cloud/remove_file"
+#define SERVICE_STORAGE_CLOUD_DOWNLOAD_FILE_URI "http://tizen.org/service-adaptor/storage/cloud/download_file"
+#define SERVICE_STORAGE_CLOUD_UPLOAD_FILE_URI   "http://tizen.org/service-adaptor/storage/cloud/upload_file"
+#define SERVICE_STORAGE_CLOUD_DOWNLOAD_FILE_THUMBNAIL_URI       "http://tizen.org/service-adaptor/storage/cloud/download_file_thumbnail"
+#define SERVICE_STORAGE_CLOUD_GET_FILE_LIST_URI "http://tizen.org/service-adaptor/storage/cloud/get_file_list"
+
+typedef struct _service_storage_cloud_file_s *service_storage_cloud_file_h;
+
+typedef bool (*service_storage_cloud_file_cb)(int result, service_storage_cloud_file_h file, void *user_data);
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+int service_storage_cloud_file_create(service_plugin_h plugin, service_storage_cloud_file_h *file);
+int service_storage_cloud_file_clone(service_storage_cloud_file_h src_file, service_storage_cloud_file_h *dst_file);
+
+int service_storage_cloud_file_destroy(service_storage_cloud_file_h file);
+int service_storage_cloud_file_set_callback(service_storage_cloud_file_h file, service_storage_cloud_file_cb callback, void *user_data);
+int service_storage_cloud_file_unset_callback(service_storage_cloud_file_h file);
+int service_storage_cloud_file_set_cloud_path(service_storage_cloud_file_h file, const char *cloud_path);
+int service_storage_cloud_file_get_cloud_path(service_storage_cloud_file_h file, char **cloud_path);
+int service_storage_cloud_file_set_local_path(service_storage_cloud_file_h file, const char *local_path);
+int service_storage_cloud_file_get_local_path(service_storage_cloud_file_h file, char **local_path);
+int service_storage_cloud_file_set_size(service_storage_cloud_file_h file, unsigned long long size);
+int service_storage_cloud_file_get_size(service_storage_cloud_file_h file, unsigned long long *size);
+int service_storage_cloud_file_set_operation(service_storage_cloud_file_h file, const char *operation);
+int service_storage_cloud_file_get_operation(service_storage_cloud_file_h file, char **operation);
+int service_storage_cloud_file_is_directory(service_storage_cloud_file_h file, bool *is_dir);
+int service_storage_cloud_file_foreach_file(service_storage_cloud_file_h file, service_storage_cloud_file_cb callback, void *user_data);
+int service_storage_cloud_file_create_task(service_storage_cloud_file_h file, service_task_h *task);
+int service_storage_cloud_file_destroy_task(service_task_h task);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_STORAGE_H__ */
diff --git a/client/sal_service_storage_internal.h b/client/sal_service_storage_internal.h
new file mode 100644 (file)
index 0000000..4e2a024
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Service Storage Internal
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SERVICE_STORAGE_INTERNAL_H__
+#define __SERVICE_STORAGE_INTERNAL_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+
+#include "sal_service_adaptor.h"
+#include "sal_service_storage.h"
+
+typedef struct _service_storage_cloud_file_s
+{
+       service_plugin_h plugin;
+       service_storage_cloud_file_cb callback;
+       void *user_data;
+
+       bool is_dir;
+       char *dir_path;
+       char *local_path;
+       char *cloud_path;
+       unsigned long long size;
+       char *operation;
+
+       GList *files;
+} service_storage_cloud_file_s;
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+int service_storage_cloud_start(service_storage_cloud_file_h file);
+int service_storage_cloud_stop(service_storage_cloud_file_h file);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_STORAGE_INTERNAL_H__ */
diff --git a/client/sal_service_task.c b/client/sal_service_task.c
new file mode 100644 (file)
index 0000000..4bbd229
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * Service Task
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <app.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_service_adaptor.h"
+#include "sal_service_adaptor_internal.h"
+#include "sal_service_task.h"
+#include "sal_service_task_internal.h"
+#include "sal_service_auth_internal.h"
+#include "sal_service_storage_internal.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+GList *service_tasks = NULL;
+GThreadPool *thread_pool = NULL;
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+static void _service_task_async_func(gpointer data, gpointer user_data)
+{
+       service_task_h task = (service_task_h) data;
+
+       if (NULL != task->oauth1)
+       {
+               service_auth_oauth1_start(task->oauth1);
+       }
+       else if (NULL != task->cloud_file)
+       {
+               service_storage_cloud_start(task->cloud_file);
+       }
+       else
+       {
+               return;
+       }
+
+       service_tasks = g_list_append(service_tasks, task);
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int service_task_connect()
+{
+       SAL_FN_CALL;
+
+       thread_pool = g_thread_pool_new(_service_task_async_func, NULL, -1, FALSE, NULL);
+       RETVM_IF(NULL == thread_pool, SERVICE_ADAPTOR_ERROR_SYSTEM, "g_thread_pool_new() Failed");
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_task_disconnect()
+{
+       SAL_FN_CALL;
+
+       // TODO: stop current stated task
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_task_start(service_task_h task)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       g_thread_pool_push(thread_pool, (gpointer) task, NULL);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_task_stop(service_task_h task)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       if (NULL != task->cloud_file)
+       {
+               service_storage_cloud_stop(task->cloud_file);
+       }
+       else
+       {
+               return SERVICE_ADAPTOR_ERROR_NO_DATA;
+       }
+
+       service_tasks = g_list_remove(service_tasks, task);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_task_set_uri(service_task_h task, const char *uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       task->uri = strdup(uri);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_task_get_uri(service_task_h task, char **uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       *uri = strdup(task->uri);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_task_set_progress_callback(service_task_h task, service_task_progress_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       task->progress_callback = callback;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_task_unset_progress_callback(service_task_h task)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       task->progress_callback = NULL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int service_task_set_state_changed_callback(service_task_h task, service_task_state_changed_cb callback, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       task->state_callback = callback;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int  service_task_unset_state_changed_callback(service_task_h task)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       task->state_callback = NULL;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/client/sal_service_task.h b/client/sal_service_task.h
new file mode 100644 (file)
index 0000000..6f038e2
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Service Task
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SERVICE_TASK_H__
+#define __SERVICE_TASK_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef enum _service_task_state_e
+{
+       SERVICE_TASK_IN_PROGRESS        = 1,
+       SERVICE_TASK_COMPLETED          = 2,
+       SERVICE_TASK_CANCELED           = 3,
+       SERVICE_TASK_FAILED             = 4
+} service_task_state_e;
+
+typedef struct _service_task_s *service_task_h;
+
+typedef void (*service_task_progress_cb)(service_task_h task, unsigned long long progress, unsigned long long total, void *user_data);
+
+typedef void (*service_task_state_changed_cb)(service_task_h task, service_task_state_e state, void *user_data);
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+int service_task_start(service_task_h task);
+int service_task_stop(service_task_h task);
+int service_task_set_uri(service_task_h task, const char *uri);
+int service_task_get_uri(service_task_h task, char **uri);
+int service_task_set_progress_callback(service_task_h task, service_task_progress_cb callback, void *user_data);
+int service_task_unset_progress_callback(service_task_h task);
+int service_task_set_state_changed_callback(service_task_h task, service_task_state_changed_cb callback, void *user_data);
+int service_task_unset_state_changed_callback(service_task_h task);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_TASK_H__ */
diff --git a/client/sal_service_task_internal.h b/client/sal_service_task_internal.h
new file mode 100644 (file)
index 0000000..f2a4c58
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Service Task Internal
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SERVICE_TASK_INTERNAL_H__
+#define __SERVICE_TASK_INTERNAL_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "sal_service_task.h"
+#include "sal_service_auth.h"
+#include "sal_service_storage.h"
+
+typedef struct _service_task_s
+{
+       char *uri;
+       service_task_progress_cb progress_callback;
+       service_task_state_changed_cb state_callback;
+
+       service_auth_oauth1_h oauth1;
+       service_storage_cloud_file_h cloud_file;
+} service_task_s;
+
+/*==================================================================================================
+                                         FUNCTION PROTOTYPES
+==================================================================================================*/
+
+int service_task_connect();
+int service_task_disconnect();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_TASK_INTERNAL_H__ */
diff --git a/client/sal_storage_provider.c b/client/sal_storage_provider.c
new file mode 100644 (file)
index 0000000..f511241
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Storage Plugin Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+#include <app.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "cloud_service.h"
+#include "sal_service_provider.h"
+#include "sal_storage_provider.h"
+
+API int storage_provider_create(storage_provider_h *provider)
+{
+       SAL_FN_CALL;
+
+       storage_provider_h storage_provider = (storage_provider_h) g_malloc0(sizeof(storage_provider_s));
+
+       storage_provider->cloud_remove_file = NULL;
+
+       *provider = storage_provider;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API app_control_h storage_provider_message(storage_provider_h provider, const char *operation, void *user_data)
+{
+       SAL_FN_CALL;
+
+       app_control_h reply = NULL;
+
+       RETV_IF(NULL == provider, reply);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       if (0 == strcmp(operation, CLOUD_REMOVE_FILE_URI))
+       {
+               app_control_create(&reply);
+
+               char *cloud_path = NULL;
+               app_control_get_extra_data((app_control_h) user_data, CLOUD_CLOUD_PATH_KEY, &cloud_path);
+
+               ret = provider->cloud_remove_file(cloud_path);
+
+               if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+               {
+                       SAL_ERR("cloud_remove_file() Fail (%d)", ret);
+                       app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_FAILURE);
+                       return reply;
+               }
+
+               app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_SUCCESS);
+       }
+
+       return reply;
+}
+
+API int storage_provider_add_extra_data(storage_provider_h provider, app_control_h reply)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == reply, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       app_control_add_extra_data(reply, PLUGIN_KEY_STORAGE, PLUGIN_VALUE_TRUE);
+
+       if (NULL != provider->cloud_remove_file)
+       {
+               app_control_add_extra_data(reply, CLOUD_REMOVE_FILE_URI, PLUGIN_VALUE_TRUE);
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/client/sal_storage_provider.h b/client/sal_storage_provider.h
new file mode 100644 (file)
index 0000000..3053fce
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Storage Plugin Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __STORAGE_PLUGIN_CLIENT_H__
+#define __STORAGE_PLUGIN_CLIENT_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <app.h>
+
+#include "service_adaptor_errors.h"
+
+#define CLOUD_LOCAL_PATH_KEY   "local_path"
+#define CLOUD_CLOUD_PATH_KEY   "cloud_path"
+
+/**
+ * @brief Describes infromation about Cloud Service
+ * @key name, ...
+ */
+#define CLOUD_REMOVE_FILE_URI   "http://tizen.org/service-adaptor/storage/cloud/remove_file"
+#define CLOUD_DOWNLOAD_FILE_URI "http://tizen.org/service-adaptor/storage/cloud/download_file"
+#define CLOUD_UPLOAD_FILE_URI   "http://tizen.org/service-adaptor/storage/cloud/upload_file"
+#define CLOUD_DOWNLOAD_FILE_THUMBNAIL_URI       "http://tizen.org/service-adaptor/storage/cloud/download_file_thumbnail"
+#define CLOUD_GET_FILE_LIST_URI "http://tizen.org/service-adaptor/storage/cloud/get_file_list"
+
+/**
+ * @brief Describes infromation about Storage Plugin Handle
+ */
+typedef struct _storage_provider_s
+{
+       // Cloud
+       service_adaptor_error_e (*cloud_remove_file)(const char *cloud_path);
+
+       // Posix
+} storage_provider_s;
+typedef struct _storage_provider_s *storage_provider_h;
+
+int storage_provider_create(storage_provider_h *provider);
+app_control_h storage_provider_message(storage_provider_h provider, const char *operation, void *user_data);
+int storage_provider_add_extra_data(storage_provider_h provider, app_control_h reply);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STORAGE_PLUGIN_CLIENT_H__ */
index b3187b1..c755981 100644 (file)
@@ -14,35 +14,123 @@ MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
 
-SET(COMMON-LIB "sal-common")
-SET(COMMON-SRCS
-        ${CMAKE_SOURCE_DIR}/common/sal_common.c
-        ${CMAKE_SOURCE_DIR}/common/ipc/sal_ipc.c
+ADD_DEFINITIONS("-DSERVICE_ADAPTOR_DEBUGGING")
+
+##########################################################
+# Define common base
+##########################################################
+
+SET(COMMON-BASE-LIB "sal-common-base")
+SET(COMMON-BASE-SRCS
+        ${CMAKE_SOURCE_DIR}/common/sal_ipc.c
+)
+
+INCLUDE_DIRECTORIES(
+        ${CMAKE_SOURCE_DIR}/include
+        ${CMAKE_SOURCE_DIR}/common
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(common_base_pkgs REQUIRED dlog glib-2.0 gio-2.0)
+
+FOREACH(flag ${common_base_pkgs_CFLAGS})
+        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
+#message(">>>[${COMMON-BASE-LIB}] extra_cflags ${EXTRA_CFLAGS}")
+#message(">>>[${COMMON-BASE-LIB}] common_base_pkgs_cflags ${common_base_pkgs_CFLAGS}")
+#message(">>>[${COMMON-BASE-LIB}] result ${CMAKE_C_FLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${COMMON-BASE-LIB} SHARED ${COMMON-BASE-SRCS})
+TARGET_LINK_LIBRARIES(${COMMON-BASE-LIB} ${common_base_pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${COMMON-BASE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${COMMON-BASE-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${COMMON-BASE-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
+##########################################################
+# Define common server
+##########################################################
+
+SET(COMMON-SERVER-LIB "sal-common-server")
+SET(COMMON-SERVER-SRCS
+        ${CMAKE_SOURCE_DIR}/common/ipc-server/sal_ipc_server.c
+       ${CMAKE_SOURCE_DIR}/common/ipc-server/sal_ipc_server_core.c
+       ${CMAKE_SOURCE_DIR}/common/ipc-server/sal_ipc_server_auth.c
+       ${CMAKE_SOURCE_DIR}/common/ipc-server/sal_ipc_server_storage.c
+)
+
+INCLUDE_DIRECTORIES(
+        ${CMAKE_SOURCE_DIR}/include
+        ${CMAKE_SOURCE_DIR}/adaptor/auth-adaptor
+        ${CMAKE_SOURCE_DIR}/adaptor/contact-adaptor
+        ${CMAKE_SOURCE_DIR}/adaptor/storage-adaptor
+        ${CMAKE_SOURCE_DIR}/adaptor/resource-adaptor
+        ${CMAKE_SOURCE_DIR}/common
+        ${CMAKE_SOURCE_DIR}/common/ipc-server
+        ${CMAKE_SOURCE_DIR}/server
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(common_server_pkgs REQUIRED dlog glib-2.0 gio-2.0)
+
+FOREACH(flag ${common_server_pkgs_CFLAGS})
+        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
+#message(">>>[${COMMON-SERVER-LIB}] extra_cflags ${EXTRA_CFLAGS}")
+#message(">>>[${COMMON-SERVER-LIB}] common_server_pkgs_cflags ${common_server_pkgs_CFLAGS}")
+#message(">>>[${COMMON-SERVER-LIB}] result ${CMAKE_C_FLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${COMMON-SERVER-LIB} SHARED ${COMMON-SERVER-SRCS})
+TARGET_LINK_LIBRARIES(${COMMON-SERVER-LIB} ${common_server_pkgs_LDFLAGS} sal-common-base auth-adaptor storage-adaptor)
+SET_TARGET_PROPERTIES(${COMMON-SERVER-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${COMMON-SERVER-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${COMMON-SERVER-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
+##########################################################
+# Define common client
+##########################################################
+
+SET(COMMON-CLIENT-LIB "sal-common-client")
+SET(COMMON-CLIENT-SRCS
+        ${CMAKE_SOURCE_DIR}/common/ipc-client/sal_ipc_client.c
+        ${CMAKE_SOURCE_DIR}/common/ipc-client/sal_ipc_client_core.c
+        ${CMAKE_SOURCE_DIR}/common/ipc-client/sal_ipc_client_auth.c
+        ${CMAKE_SOURCE_DIR}/common/ipc-client/sal_ipc_client_storage.c
 )
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
         ${CMAKE_SOURCE_DIR}/common
 )
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
         ${CMAKE_SOURCE_DIR}/common
-        ${CMAKE_SOURCE_DIR}/common/ipc
+        ${CMAKE_SOURCE_DIR}/common/ipc-client
+        ${CMAKE_SOURCE_DIR}/client
 )
 
 INCLUDE(FindPkgConfig)
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(common_pkgs REQUIRED dlog glib-2.0)
+pkg_check_modules(common_client_pkgs REQUIRED dlog glib-2.0 gio-2.0)
 
 
-FOREACH(flag ${common_pkgs_CFLAGS})
+FOREACH(flag ${common_client_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-#message(">>>[${COMMON-LIB}] extra_cflags ${EXTRA_CFLAGS}")
-#message(">>>[${COMMON-LIB}] common_pkgs_cflags ${common_pkgs_CFLAGS}")
-#message(">>>[${COMMON-LIB}] result ${CMAKE_C_FLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
+#message(">>>[${COMMON-CLIENT-LIB}] extra_cflags ${EXTRA_CFLAGS}")
+#message(">>>[${COMMON-CLIENT-LIB}] common_client_pkgs_cflags ${common_client_pkgs_CFLAGS}")
+#message(">>>[${COMMON-CLIENT-LIB}] result ${CMAKE_C_FLAGS}")
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
-ADD_LIBRARY(${COMMON-LIB} SHARED ${COMMON-SRCS})
-TARGET_LINK_LIBRARIES(${COMMON-LIB} ${common_pkgs_LDFLAGS})
-SET_TARGET_PROPERTIES(${COMMON-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
-SET_TARGET_PROPERTIES(${COMMON-LIB} PROPERTIES VERSION ${VERSION})
+ADD_LIBRARY(${COMMON-CLIENT-LIB} SHARED ${COMMON-CLIENT-SRCS})
+TARGET_LINK_LIBRARIES(${COMMON-CLIENT-LIB} ${common_client_pkgs_LDFLAGS} sal-common-base)
+SET_TARGET_PROPERTIES(${COMMON-CLIENT-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${COMMON-CLIENT-LIB} PROPERTIES VERSION ${VERSION})
 
 
-INSTALL(TARGETS ${COMMON-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+INSTALL(TARGETS ${COMMON-CLIENT-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
diff --git a/common/ipc-client/sal_ipc_client.c b/common/ipc-client/sal_ipc_client.c
new file mode 100644 (file)
index 0000000..03df9db
--- /dev/null
@@ -0,0 +1,453 @@
+/*
+ * Service Adaptor IPC Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_ipc.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+/**
+ * Service Adaptor D-Bus client thread data
+ */
+typedef struct _dbus_client_thread_data_s
+{
+       GMutex connection_mutex;        // Mutex used to protect connection status data
+       GCond connection_cond;          // Conditional variable used to signal that connection was established
+       int connection_cond_signaled;   // Additional variable used to signal that connection was established
+} dbus_client_thread_data_s;
+typedef struct _dbus_client_thread_data_s *dbus_client_thread_data_h;
+
+/**
+ * D-Bus client thread.
+ */
+static GThread *dbus_client_thread = NULL;
+
+/**
+ * D-Bus client thread main loop context.
+ */
+static GMainContext *dbus_client_context = NULL;
+
+/**
+ * D-Bus client thread main loop.
+ */
+static GMainLoop *dbus_client_loop = NULL;
+
+/**
+ * Service Adaptor D-Bus bus watcher id.
+ */
+static guint watcher_id = 0;
+
+/**
+ * D-Bus connection to vService Channel
+ */
+static GDBusConnection *connection = NULL;
+
+/**
+ * D-Bus proxy to Service Adaptor Client interface
+ */
+static GDBusProxy *interface_proxy = NULL;
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+static gpointer _dbus_client_thread_func(gpointer data);
+
+static service_adaptor_error_e _dbus_client_start(dbus_client_thread_data_h thread_data);
+
+static service_adaptor_error_e _dbus_client_stop();
+
+static void _on_name_appeared(GDBusConnection *connection,
+               const gchar *name,
+               const gchar *name_owner,
+               gpointer user_data);
+
+static void _on_name_vanished(GDBusConnection *connection,
+               const gchar *name,
+               gpointer user_data);
+
+static void _on_signal(GDBusProxy *proxy,
+               gchar *sender_name,
+               gchar *signal_name,
+               GVariant *parameters,
+               gpointer user_data);
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+/**
+ * @brief D-Bus client thread function.
+ *
+ * D-Bus client thread function. It initialises all client D-Bus interfaces.
+ * @param data Data passed to thread.
+ * @return Result data from thread (always NULL in this implementation).
+ */
+static gpointer _dbus_client_thread_func(gpointer data)
+{
+       SAL_FN_CALL;
+
+       int ret = 0;
+
+       dbus_client_context = g_main_context_new();
+       dbus_client_loop = g_main_loop_new(dbus_client_context, FALSE);
+       g_main_context_push_thread_default(dbus_client_context);
+
+       ret = _dbus_client_start(data);
+
+       if (SERVICE_ADAPTOR_ERROR_NONE == ret)
+       {
+               g_main_loop_run(dbus_client_loop);
+       }
+
+       _dbus_client_stop();
+
+       g_main_context_pop_thread_default(dbus_client_context);
+       g_main_loop_unref(dbus_client_loop);
+       dbus_client_loop = NULL;
+       g_main_context_unref(dbus_client_context);
+       dbus_client_context = NULL;
+
+       free(data);
+
+       return NULL;
+}
+
+/**
+ * @brief Initialises Service Adaptor D-Bus client internal structures.
+ *
+ * Initialises Service Adaptor D-Bus client internal structures.
+ * @param thread_data Pointer to thread data used to signal that connection was successfully established.
+ * @return 0 on success, error code when some structures could not be initialised.
+ */
+static service_adaptor_error_e _dbus_client_start(dbus_client_thread_data_h thread_data)
+{
+       SAL_FN_CALL;
+
+       GError *error = NULL;
+
+       RETV_IF(NULL != connection, SERVICE_ADAPTOR_ERROR_INTERNAL);
+       RETV_IF(NULL != interface_proxy, SERVICE_ADAPTOR_ERROR_INTERNAL);
+
+       connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+
+       if (NULL == connection)
+       {
+               g_error_free(error);
+
+               return SERVICE_ADAPTOR_ERROR_INTERNAL;
+       }
+
+       interface_proxy = g_dbus_proxy_new_sync(connection,
+                       G_DBUS_PROXY_FLAGS_NONE,
+                       NULL,
+                       SERVICE_ADAPTOR_BUS_NAME,
+                       SERVICE_ADAPTOR_OBJECT_PATH,
+                       SERVICE_ADAPTOR_INTERFACE,
+                       NULL,
+                       &error);
+
+       if (NULL == interface_proxy)
+       {
+               g_error_free(error);
+
+               g_object_unref(connection);
+               connection = NULL;
+
+               return SERVICE_ADAPTOR_ERROR_INTERNAL;
+       }
+
+       watcher_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       SERVICE_ADAPTOR_BUS_NAME,
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
+                       _on_name_appeared,
+                       _on_name_vanished,
+                       thread_data,
+                       NULL);
+
+       if (0 == watcher_id)
+       {
+               g_object_unref(interface_proxy);
+               interface_proxy = NULL;
+
+               g_object_unref(connection);
+               connection = NULL;
+
+               return SERVICE_ADAPTOR_ERROR_INTERNAL;
+       }
+
+       int res = g_signal_connect(interface_proxy,
+                       "g-signal",
+                       G_CALLBACK(_on_signal),
+                       NULL);
+
+       if (0 == res)
+       {
+               g_object_unref(interface_proxy);
+               interface_proxy = NULL;
+
+               g_object_unref(connection);
+               connection = NULL;
+
+               g_bus_unwatch_name(watcher_id);
+               watcher_id = 0;
+
+               return SERVICE_ADAPTOR_ERROR_INTERNAL;
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+/**
+ * @brief Deinitialises Service Adaptor D-Bus client internal structures.
+ *
+ * Deinitialises Service Adaptor D-Bus client internal structures.
+ */
+static service_adaptor_error_e _dbus_client_stop()
+{
+       SAL_FN_CALL;
+
+       if (NULL != interface_proxy)
+       {
+               g_object_unref(interface_proxy);
+               interface_proxy = NULL;
+       }
+
+       if (NULL != connection)
+       {
+               g_object_unref(connection);
+               connection = NULL;
+       }
+
+       if (0 != watcher_id)
+       {
+               g_bus_unwatch_name(watcher_id);
+               watcher_id = 0;
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+/**
+ * @brief Service Adaptor availability callback function.
+ *
+ * Service Adaptor availability callback function. Called when Service Adaptor appears at D-Bus bus.
+ * @param connection D-Bus connection.
+ * @param name The name being watched.
+ * @param name_owner Unique name of the owner of the name being watched.
+ * @param user_data User data passed to g_bus_watch_name().
+ */
+static void _on_name_appeared(GDBusConnection *connection,
+               const gchar *name,
+               const gchar *name_owner,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       dbus_client_thread_data_h thread_data = (dbus_client_thread_data_h) user_data;
+
+       if (NULL != thread_data)
+       {
+               g_mutex_lock(&thread_data->connection_mutex);
+               thread_data->connection_cond_signaled = 1;
+               g_cond_signal(&thread_data->connection_cond);
+               g_mutex_unlock(&thread_data->connection_mutex);
+       }
+}
+
+/**
+ * @brief Service Adaptor availability callback function.
+ *
+ * Service Adaptor availability callback function. Called when Service Adaptor disappears from D-Bus bus.
+ * @param connection D-Bus connection.
+ * @param name he name being watched.
+ * @param user_data User data passed to g_bus_watch_name().
+ */
+static void _on_name_vanished(GDBusConnection *connection,
+               const gchar *name,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       if (NULL != interface_proxy)
+       {
+               g_object_unref(interface_proxy);
+               interface_proxy = NULL;
+       }
+
+       if (NULL != connection)
+       {
+               g_object_unref(connection);
+               connection = NULL;
+       }
+
+       if (0 != watcher_id)
+       {
+               g_bus_unwatch_name(watcher_id);
+               watcher_id = 0;
+       }
+}
+
+/**
+ * @brief Service Adaptor signals handler.
+ *
+ * Service Adaptor signals handler. It is called when Service Adaptor sends signal over D-Bus.
+ * @param proxy D-Bus proxy object.
+ * @param sender_name The unique bus name of the remote caller.
+ * @param signal_name Signal name.
+ * @param parameters Signal parameters.
+ * @param user_data The user_data gpointer.
+ */
+static void _on_signal(GDBusProxy *proxy,
+               gchar *sender_name,
+               gchar *signal_name,
+               GVariant *parameters,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       if (0 == strncmp(signal_name, DBUS_SERVICE_ADAPTOR, DBUS_NAME_LENGTH))
+       {
+               // TODO:
+/*
+               on_service_signal(proxy,
+                               sender_name,
+                               signal_name,
+                               parameters,
+                               user_data);
+*/
+       }
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API service_adaptor_error_e sal_ipc_client_get_interface(GDBusProxy **interface)
+{
+       SAL_FN_CALL;
+
+       *interface = interface_proxy;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e sal_ipc_client_init()
+{
+       SAL_FN_CALL;
+
+#if !GLIB_CHECK_VERSION(2,32,0)
+       g_thread_init(NULL);
+#endif
+#if !GLIB_CHECK_VERSION(2,35,0)
+       g_type_init();
+#endif
+
+       RETVM_IF(NULL != dbus_client_thread, SERVICE_ADAPTOR_ERROR_INTERNAL, "D-Bus client thread is already running");
+
+       dbus_client_thread_data_h thread_data =
+                       (dbus_client_thread_data_h) malloc(sizeof(dbus_client_thread_data_s));
+
+       g_mutex_init(&thread_data->connection_mutex);
+       g_cond_init(&thread_data->connection_cond);
+       thread_data->connection_cond_signaled = 0;
+
+       dbus_client_thread = g_thread_new("Service Adaptor D-Bus Client", _dbus_client_thread_func, thread_data);
+
+       gint64 timeout = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
+       g_mutex_lock(&thread_data->connection_mutex );
+       while (!thread_data->connection_cond_signaled)
+       {
+               if (!g_cond_wait_until(&thread_data->connection_cond, &thread_data->connection_mutex, timeout))
+               {
+                       g_mutex_unlock(&thread_data->connection_mutex);
+                       return SERVICE_ADAPTOR_ERROR_INTERNAL;
+               }
+       }
+
+       g_mutex_unlock(&thread_data->connection_mutex);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e sal_ipc_client_deinit()
+{
+       SAL_FN_CALL;
+
+       if (NULL != dbus_client_loop)
+       {
+               if (g_main_loop_is_running(dbus_client_loop))
+               {
+                       g_main_loop_quit(dbus_client_loop);
+               }
+       }
+
+       if (NULL != dbus_client_thread)
+       {
+               g_thread_join(dbus_client_thread);
+               dbus_client_thread = NULL;
+       }
+
+       if (NULL != dbus_client_loop)
+       {
+               g_main_loop_unref(dbus_client_loop);
+               dbus_client_loop = NULL;
+       }
+
+       if (NULL != dbus_client_context)
+       {
+               g_main_context_pop_thread_default(dbus_client_context);
+               g_main_context_unref(dbus_client_context);
+               dbus_client_context = NULL;
+       }
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int sal_ipc_client_call_request(const char *request_method, GVariant *request_data, const char *reply_type, GVariant **reply_info)
+{
+       GError *error = NULL;
+       GVariant *reply = NULL;
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       GDBusProxy *interface_proxy = NULL;
+       ret = sal_ipc_client_get_interface(&interface_proxy);
+       RETV_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL);
+
+       reply = g_dbus_proxy_call_sync(interface_proxy,
+                       request_method,
+                       request_data,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       G_MAXINT,
+                       NULL,
+                       &error);
+
+       RETVM_IF(NULL == reply, SERVICE_ADAPTOR_ERROR_INTERNAL, "IPC Request Failed: %s", error->message);
+       RETV_IF(false == g_variant_is_of_type(reply, (GVariantType *) ipc_make_return_type(reply_type)), SERVICE_ADAPTOR_ERROR_INTERNAL);
+
+       *reply_info = reply;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
diff --git a/common/ipc-client/sal_ipc_client.h b/common/ipc-client/sal_ipc_client.h
new file mode 100644 (file)
index 0000000..b88fd99
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Service Adaptor Client IPC
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yongjin Kim <youth.kim@samsung.com>
+ *          Jinhyeong Ahn <jinh.ahn@samsung.com>
+ *          Jiwon Kim <jiwon177.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_H__
+#define __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "sal_ipc.h"
+
+service_adaptor_error_e sal_ipc_client_init();
+service_adaptor_error_e sal_ipc_client_deinit();
+service_adaptor_error_e sal_ipc_client_get_interface(GDBusProxy **interface);
+int sal_ipc_client_call_request(const char *request_method, GVariant *request_data, const char *reply_type, GVariant **reply_info);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_H__ */
+
diff --git a/common/ipc-client/sal_ipc_client_auth.c b/common/ipc-client/sal_ipc_client_auth.c
new file mode 100644 (file)
index 0000000..051837d
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Service Adaptor IPC Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_ipc_client.h"
+#include "sal_ipc_client_auth.h"
+#include "sal_service_auth.h"
+#include "sal_service_auth_internal.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+int _get_oauth1(GVariant *reply_info, service_auth_oauth1_h *oauth1)
+{
+       service_auth_oauth1_h auth_oauth1 = (service_auth_oauth1_h) g_malloc0(sizeof(service_auth_oauth1_s));
+
+       int info_size = service_auth_oauth1_res_s_type_length;
+       GVariant *info[info_size];
+       ipc_create_variant_info(reply_info, info_size, (GVariant ***) &info);
+
+       int idx = 0;
+       int auth_info_size = service_auth_oauth1_s_type_length;
+       GVariant *auth_info[auth_info_size];
+       ipc_create_variant_info(info[idx++], auth_info_size, (GVariant ***) &auth_info);
+
+       int idx2 = 0;
+       auth_oauth1->access_token = ipc_insure_g_variant_dup_string(auth_info[idx2++]);
+       auth_oauth1->operation = ipc_insure_g_variant_dup_string(auth_info[idx2++]);
+
+       ipc_destroy_variant_info(auth_info, auth_info_size);
+
+       ipc_destroy_variant_info(info, info_size);
+
+       *oauth1 = auth_oauth1;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int ipc_service_auth_oauth1(const char *uri, service_auth_oauth1_h req_oauth1, service_auth_oauth1_h *res_oauth1)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == req_oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       char *request_method = DBUS_SERVICE_AUTH_OAUTH1_METHOD;
+       GVariant *request_data = g_variant_new("(" service_auth_oauth1_req_s_type ")", uri, SAL_IPC_STR(req_oauth1->access_token), SAL_IPC_STR(req_oauth1->operation));
+
+       char *reply_type = service_auth_oauth1_res_s_type;
+       int reply_size = RETURN_LENGTH + 1;
+       GVariant *reply = NULL;
+
+       ret = sal_ipc_client_call_request(request_method, request_data, reply_type, &reply);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_client_call_request() Failed(%d)", ret);
+
+       GVariant *reply_info[reply_size];
+       ipc_create_variant_info(reply, reply_size, (GVariant ***) &reply_info);
+
+       int idx = 0;
+       service_auth_oauth1_h oauth1 = NULL;
+       _get_oauth1(reply_info[idx++], &oauth1);
+
+       int ipc_ret = g_variant_get_int32(reply_info[idx++]);
+       char *ipc_msg = ipc_insure_g_variant_dup_string(reply_info[idx++]);
+
+       ipc_destroy_variant_info(reply_info, reply_size);
+
+       g_variant_unref(reply);
+
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ipc_ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "IPC Result Failed(%d): %s", ipc_ret, ipc_msg);
+
+       *res_oauth1 = oauth1;
+
+       SAL_FREE(ipc_msg);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/common/ipc-client/sal_ipc_client_auth.h b/common/ipc-client/sal_ipc_client_auth.h
new file mode 100644 (file)
index 0000000..56b553f
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Service Adaptor Client Auth IPC
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yongjin Kim <youth.kim@samsung.com>
+ *          Jinhyeong Ahn <jinh.ahn@samsung.com>
+ *          Jiwon Kim <jiwon177.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_AUTH_H__
+#define __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_AUTH_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "sal_service_auth.h"
+
+int ipc_service_auth_oauth1(const char *uri, service_auth_oauth1_h req_oauth1, service_auth_oauth1_h *res_oauth1);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_AUTH_H__ */
+
diff --git a/common/ipc-client/sal_ipc_client_core.c b/common/ipc-client/sal_ipc_client_core.c
new file mode 100644 (file)
index 0000000..8759940
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Service Adaptor IPC Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_ipc_client.h"
+#include "sal_ipc_client_core.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int ipc_service_adaptor_connect(const char *uri, GList **plugins)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       char *request_method = DBUS_SERVICE_ADAPTOR_CONNECT_METHOD;
+       GVariant *request_data = g_variant_new("(" service_adaptor_connect_req_s_type ")", uri);
+
+       char *reply_type = service_adaptor_connect_res_s_type;
+       int reply_size = RETURN_LENGTH + 1;
+       GVariant *reply = NULL;
+
+       ret = sal_ipc_client_call_request(request_method, request_data, reply_type, &reply);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_client_call_request() Failed(%d)", ret);
+
+       GVariant *reply_info[reply_size];
+       ipc_create_variant_info(reply, reply_size, (GVariant ***) &reply_info);
+
+       int idx = 0;
+       int info_size = service_adaptor_connect_res_s_type_length;
+       GVariant *info[info_size];
+       ipc_create_variant_info(reply_info[idx++], info_size, (GVariant ***) &info);
+
+       int idx2 = 0;
+       GList *plugin_list = NULL;
+       gsize uri_info_size = g_variant_n_children(info[idx2]);
+
+       for (gsize i = 0; i < uri_info_size; i++)
+       {
+               GVariant *uri_info_struct;
+               GVariant *uri_info_entry_v = g_variant_get_child_value(info[idx2], i);
+               uri_info_struct = g_variant_get_child_value(uri_info_entry_v, 0);
+
+               plugin_list = g_list_append(plugin_list, ipc_insure_g_variant_dup_string(uri_info_struct));
+
+               g_variant_unref(uri_info_struct);
+       }
+
+       *plugins = plugin_list;
+
+       int ipc_ret = g_variant_get_int32(reply_info[idx++]);
+       char *ipc_msg = ipc_insure_g_variant_dup_string(reply_info[idx++]);
+
+       ipc_destroy_variant_info(reply_info, reply_size);
+
+       g_variant_unref(reply);
+
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ipc_ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "IPC Result Failed(%d): %s", ipc_ret, ipc_msg);
+
+       SAL_FREE(ipc_msg);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int ipc_service_adaptor_disconnect(const char *uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       char *request_method = DBUS_SERVICE_ADAPTOR_DISCONNECT_METHOD;
+       GVariant *request_data = g_variant_new("(" service_adaptor_disconnect_s_type ")", uri);
+
+       char *reply_type = NULL;
+       int reply_size = RETURN_LENGTH;
+       GVariant *reply = NULL;
+
+       ret = sal_ipc_client_call_request(request_method, request_data, reply_type, &reply);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_client_call_request() Failed(%d)", ret);
+
+       GVariant *reply_info[reply_size];
+       ipc_create_variant_info(reply, reply_size, (GVariant ***) &reply_info);
+
+       int idx = 0;
+       int ipc_ret = g_variant_get_int32(reply_info[idx++]);
+       char *ipc_msg = ipc_insure_g_variant_dup_string(reply_info[idx++]);
+
+       ipc_destroy_variant_info(reply_info, reply_size);
+
+       g_variant_unref(reply);
+
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ipc_ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "IPC Result Failed(%d): %s", ipc_ret, ipc_msg);
+
+       SAL_FREE(ipc_msg);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int ipc_service_plugin_create(const char *uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       char *request_method = DBUS_SERVICE_PLUGIN_CREATE_METHOD;
+       GVariant *request_data = g_variant_new("(" service_plugin_create_s_type ")", uri);
+
+       char *reply_type = NULL;
+       int reply_size = RETURN_LENGTH;
+       GVariant *reply = NULL;
+
+       ret = sal_ipc_client_call_request(request_method, request_data, reply_type, &reply);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_client_call_request() Failed(%d)", ret);
+
+       GVariant *reply_info[reply_size];
+       ipc_create_variant_info(reply, reply_size, (GVariant ***) &reply_info);
+
+       int idx = 0;
+       int ipc_ret = g_variant_get_int32(reply_info[idx++]);
+       char *ipc_msg = ipc_insure_g_variant_dup_string(reply_info[idx++]);
+
+       ipc_destroy_variant_info(reply_info, reply_size);
+
+       g_variant_unref(reply);
+
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ipc_ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "IPC Result Failed(%d): %s", ipc_ret, ipc_msg);
+
+       SAL_FREE(ipc_msg);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API int ipc_service_plugin_destroy(const char *uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       char *request_method = DBUS_SERVICE_PLUGIN_DESTROY_METHOD;
+       GVariant *request_data = g_variant_new("(" service_plugin_destroy_s_type ")", uri);
+
+       char *reply_type = NULL;
+       int reply_size = RETURN_LENGTH;
+       GVariant *reply = NULL;
+
+       ret = sal_ipc_client_call_request(request_method, request_data, reply_type, &reply);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_client_call_request() Failed(%d)", ret);
+
+       GVariant *reply_info[reply_size];
+       ipc_create_variant_info(reply, reply_size, (GVariant ***) &reply_info);
+
+       int idx = 0;
+       int ipc_ret = g_variant_get_int32(reply_info[idx++]);
+       char *ipc_msg = ipc_insure_g_variant_dup_string(reply_info[idx++]);
+
+       ipc_destroy_variant_info(reply_info, reply_size);
+
+       g_variant_unref(reply);
+
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ipc_ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "IPC Result Failed(%d): %s", ipc_ret, ipc_msg);
+
+       SAL_FREE(ipc_msg);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
diff --git a/common/ipc-client/sal_ipc_client_core.h b/common/ipc-client/sal_ipc_client_core.h
new file mode 100644 (file)
index 0000000..a4f1ea3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Service Adaptor Client Core IPC
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yongjin Kim <youth.kim@samsung.com>
+ *          Jinhyeong Ahn <jinh.ahn@samsung.com>
+ *          Jiwon Kim <jiwon177.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_CORE_H__
+#define __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_CORE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+
+int ipc_service_adaptor_connect(const char *uri, GList **plugins);
+int ipc_service_adaptor_disconnect(const char *uri);
+int ipc_service_plugin_create(const char *uri);
+int ipc_service_plugin_destroy(const char *uri);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_CORE_H__ */
+
diff --git a/common/ipc-client/sal_ipc_client_storage.c b/common/ipc-client/sal_ipc_client_storage.c
new file mode 100644 (file)
index 0000000..5dd6dfe
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Service Adaptor IPC Client
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_ipc_client.h"
+#include "sal_ipc_client_storage.h"
+#include "sal_service_storage.h"
+#include "sal_service_storage_internal.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+int _get_cloud_file(GVariant *reply_info, service_storage_cloud_file_h *file)
+{
+       service_storage_cloud_file_h cloud_file = (service_storage_cloud_file_h) g_malloc0(sizeof(service_storage_cloud_file_s));
+
+       int info_size = service_storage_cloud_file_res_s_type_length;
+       GVariant *info[info_size];
+       ipc_create_variant_info(reply_info, info_size, (GVariant ***) &info);
+
+       int idx = 0;
+       int file_info_size = service_storage_cloud_file_s_type_length;
+       GVariant *file_info[file_info_size];
+       ipc_create_variant_info(info[idx++], file_info_size, (GVariant ***) &file_info);
+
+       int idx2 = 0;
+       cloud_file->is_dir = g_variant_get_boolean(file_info[idx2++]);
+       cloud_file->dir_path = ipc_insure_g_variant_dup_string(file_info[idx2++]);
+       cloud_file->local_path = ipc_insure_g_variant_dup_string(file_info[idx2++]);
+       cloud_file->cloud_path = ipc_insure_g_variant_dup_string(file_info[idx2++]);
+       cloud_file->size = g_variant_get_uint64(file_info[idx2++]);
+       cloud_file->operation = ipc_insure_g_variant_dup_string(file_info[idx2++]);
+
+       ipc_destroy_variant_info(file_info, file_info_size);
+
+       gsize files_size = g_variant_n_children(info[idx]);
+
+       for (gsize i = 0; i < files_size; i++)
+       {
+               GVariant *files_struct;
+               GVariant *files_entry_v = g_variant_get_child_value(info[idx], i);
+               files_struct = g_variant_get_child_value(files_entry_v, 0);
+
+               cloud_file->files = g_list_append(cloud_file->files, ipc_insure_g_variant_dup_string(files_struct));
+
+               g_variant_unref(files_struct);
+       }
+
+       ipc_destroy_variant_info(info, info_size);
+
+       // TODO: reorder files because it is just serialized. it makes tree structure.
+
+       *file = cloud_file;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API int ipc_service_storage_cloud_file(const char *uri, service_storage_cloud_file_h req_file, service_storage_cloud_file_h *res_file)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == req_file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       char *request_method = DBUS_SERVICE_STORAGE_CLOUD_FILE_METHOD;
+       GVariant *request_data = g_variant_new("(" service_storage_cloud_file_req_s_type ")", uri, req_file->is_dir, SAL_IPC_STR(req_file->dir_path), SAL_IPC_STR(req_file->local_path), SAL_IPC_STR(req_file->cloud_path), req_file->size, SAL_IPC_STR(req_file->operation));
+
+       char *reply_type = service_storage_cloud_file_res_s_type;
+       int reply_size = RETURN_LENGTH + 1;
+       GVariant *reply = NULL;
+
+       ret = sal_ipc_client_call_request(request_method, request_data, reply_type, &reply);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_client_call_request() Failed(%d)", ret);
+
+       GVariant *reply_info[reply_size];
+       ipc_create_variant_info(reply, reply_size, (GVariant ***) &reply_info);
+
+       int idx = 0;
+       service_storage_cloud_file_h cloud_file = NULL;
+       _get_cloud_file(reply_info[idx++], &cloud_file);
+
+       int ipc_ret = g_variant_get_int32(reply_info[idx++]);
+       char *ipc_msg = ipc_insure_g_variant_dup_string(reply_info[idx++]);
+
+       ipc_destroy_variant_info(reply_info, reply_size);
+
+       g_variant_unref(reply);
+
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ipc_ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "IPC Result Failed(%d): %s", ipc_ret, ipc_msg);
+
+       *res_file = cloud_file;
+
+       SAL_FREE(ipc_msg);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
diff --git a/common/ipc-client/sal_ipc_client_storage.h b/common/ipc-client/sal_ipc_client_storage.h
new file mode 100644 (file)
index 0000000..ed25d22
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Service Adaptor Client Storage IPC
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yongjin Kim <youth.kim@samsung.com>
+ *          Jinhyeong Ahn <jinh.ahn@samsung.com>
+ *          Jiwon Kim <jiwon177.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_STORAGE_H__
+#define __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_STORAGE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "sal_service_storage.h"
+
+int ipc_service_storage_cloud_file(const char *uri, service_storage_cloud_file_h req_file, service_storage_cloud_file_h *res_file);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_CONVERGENCE_SAL_IPC_CLIENT_STORAGE_H__ */
+
diff --git a/common/ipc-server/sal_ipc_server.c b/common/ipc-server/sal_ipc_server.c
new file mode 100644 (file)
index 0000000..e4a9fbe
--- /dev/null
@@ -0,0 +1,517 @@
+/*
+ * Service Adaptor IPC Server
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_ipc.h"
+#include "sal_ipc_server_core.h"
+#include "sal_ipc_server_auth.h"
+#include "sal_ipc_server_storage.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+/**
+ * D-Bus server thread
+ */
+static GThread* dbus_server_thread = NULL;
+
+/**
+ * D-Bus server thread main loop context
+ */
+static GMainContext* dbus_server_context = NULL;
+
+/**
+ * D-Bus server thread main loop
+ */
+static GMainLoop* dbus_server_loop = NULL;
+
+/**
+ * D-Bus server thread pool
+ */
+static GThreadPool *thread_pool = NULL;
+
+/**
+ * Compiled introspection data describing D-Bus interface
+ */
+static GDBusNodeInfo *introspection_data = NULL;
+
+/**
+ * D-Bus server owner id
+ */
+static guint owner_id = 0;
+
+/**
+ * D-Bus connection used by server
+ */
+static GDBusConnection *dbus_connection = NULL;
+
+/**
+ * Introspection data describing D-Bus interface
+ */
+static const gchar introspection_xml[] =
+"<node>"
+"  <interface name='" SERVICE_ADAPTOR_INTERFACE "'>"
+"    <method name='" DBUS_SERVICE_ADAPTOR_CONNECT_METHOD "'>"
+"      <arg type='" service_adaptor_connect_req_s_type "' name='req' direction='in'/>"
+"      <arg type='" service_adaptor_connect_res_s_type "' name='res' direction='out'/>"
+"      <arg type='i' name='ret_code' direction='out'/>"
+"      <arg type='s' name='ret_msg' direction='out'/>"
+"    </method>"
+"    <method name='" DBUS_SERVICE_ADAPTOR_DISCONNECT_METHOD "'>"
+"      <arg type='" service_adaptor_disconnect_s_type "' name='req' direction='in'/>"
+"      <arg type='i' name='ret_code' direction='out'/>"
+"      <arg type='s' name='ret_msg' direction='out'/>"
+"    </method>"
+"    <method name='" DBUS_SERVICE_PLUGIN_CREATE_METHOD "'>"
+"      <arg type='" service_plugin_create_s_type "' name='req' direction='in'/>"
+"      <arg type='i' name='ret_code' direction='out'/>"
+"      <arg type='s' name='ret_msg' direction='out'/>"
+"    </method>"
+"    <method name='" DBUS_SERVICE_PLUGIN_DESTROY_METHOD "'>"
+"      <arg type='" service_plugin_destroy_s_type "' name='req' direction='in'/>"
+"      <arg type='i' name='ret_code' direction='out'/>"
+"      <arg type='s' name='ret_msg' direction='out'/>"
+"    </method>"
+"    <method name='" DBUS_SERVICE_AUTH_OAUTH1_METHOD "'>"
+"      <arg type='" service_auth_oauth1_req_s_type "' name='req' direction='in'/>"
+"      <arg type='" service_auth_oauth1_res_s_type "' name='res' direction='out'/>"
+"      <arg type='i' name='ret_code' direction='out'/>"
+"      <arg type='s' name='ret_msg' direction='out'/>"
+"    </method>"
+"    <method name='" DBUS_SERVICE_STORAGE_CLOUD_FILE_METHOD "'>"
+"      <arg type='" service_storage_cloud_file_req_s_type "' name='req' direction='in'/>"
+"      <arg type='" service_storage_cloud_file_res_s_type "' name='res' direction='out'/>"
+"      <arg type='i' name='ret_code' direction='out'/>"
+"      <arg type='s' name='ret_msg' direction='out'/>"
+"    </method>"
+"    <signal name='" DBUS_SERVICE_ADAPTOR_NOTIFY_SIGNAL "'>"
+"      <arg type='t' name='signal_code' direction='out'/>"
+"      <arg type='s' name='signal_msg' direction='out'/>"
+"    </signal>"
+"  </interface>"
+"</node>";
+
+/**
+ * information for method call
+ */
+typedef struct _method_call_s
+{
+       GDBusConnection *connection;
+       gchar *sender;
+       gchar *object_path;
+       gchar *interface_name;
+       gchar *method_name;
+       GVariant *parameters;
+       GDBusMethodInvocation *invocation;
+       gpointer user_data;
+} method_call_s;
+typedef struct _method_call_s *method_call_h;
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+static void _method_call_async_func(gpointer data, gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       method_call_h handle = data;
+
+       RET_IF(NULL == handle);
+
+       SAL_INFO("Call %s", handle->method_name);
+
+       if (0 == strncmp(handle->method_name, DBUS_SERVICE_ADAPTOR, DBUS_NAME_LENGTH))
+       {
+               service_adaptor_method_call(handle->connection,
+                               handle->sender,
+                               handle->object_path,
+                               handle->interface_name,
+                               handle->method_name,
+                               handle->parameters,
+                               handle->invocation,
+                               handle->user_data);
+       }
+       else if (0 == strncmp(handle->method_name, DBUS_SERVICE_PLUGIN, DBUS_NAME_LENGTH))
+       {
+               service_plugin_method_call(handle->connection,
+                               handle->sender,
+                               handle->object_path,
+                               handle->interface_name,
+                               handle->method_name,
+                               handle->parameters,
+                               handle->invocation,
+                               handle->user_data);
+       }
+       else if (0 == strncmp(handle->method_name, DBUS_SERVICE_AUTH, DBUS_NAME_LENGTH))
+       {
+               service_auth_method_call(handle->connection,
+                               handle->sender,
+                               handle->object_path,
+                               handle->interface_name,
+                               handle->method_name,
+                               handle->parameters,
+                               handle->invocation,
+                               handle->user_data);
+       }
+       else if (0 == strncmp(handle->method_name, DBUS_SERVICE_STORAGE, DBUS_NAME_LENGTH))
+       {
+               service_storage_method_call(handle->connection,
+                               handle->sender,
+                               handle->object_path,
+                               handle->interface_name,
+                               handle->method_name,
+                               handle->parameters,
+                               handle->invocation,
+                               handle->user_data);
+       }
+}
+
+/**
+ * @brief Service Adaptor D-Bus interface method call handler.
+ *
+ * Service Adaptor D-Bus interface method call handler. Called when client calls some function defined in
+ * Service Adaptor D-Bus interface.
+ * @param connection A GDBusConnection.
+ * @param sender The unique bus name of the remote caller.
+ * @param object_path The object path that the method was invoked on.
+ * @param interface_name The D-Bus interface name the method was invoked on.
+ * @param method_name The name of the method that was invoked.
+ * @param parameters A GVariant tuple with parameters.
+ * @param invocation A GDBusMethodInvocation object that can be used to return a value or error.
+ * @param user_data The user_data gpointer passed to g_dbus_connection_register_object().
+ */
+static void _handle_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       method_call_h handle = (method_call_h) g_malloc0(sizeof(method_call_s));
+
+       handle->connection = connection;
+       handle->sender = (gchar *) sender;
+       handle->object_path = (gchar *) object_path;
+       handle->interface_name = (gchar *) interface_name;
+       handle->method_name = (gchar *) method_name;
+       handle->parameters = parameters;
+       handle->invocation = invocation;
+       handle->user_data = user_data;
+
+       g_thread_pool_push(thread_pool, (gpointer) handle, NULL);
+}
+
+/**
+ * @brief Service Adaptor D-Bus interface get property call handler.
+ *
+ * Service Adaptor D-Bus interface get property call handler.
+ * @param connection A GDBusConnection.
+ * @param sender The unique bus name of the remote caller.
+ * @param object_path The object path that the method was invoked on.
+ * @param interface_name The D-Bus interface name for the property.
+ * @param property_name The name of the property to get the value of.
+ * @param error Return location for error.
+ * @param user_data The user_data gpointer passed to g_dbus_connection_register_object().
+ * @return A GVariant with the value for property_name or NULL if error is set. If the returned GVariant
+ *         is floating, it is consumed - otherwise its reference count is decreased by one.
+ */
+static GVariant *_handle_get_property(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *property_name,
+               GError **error,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       GVariant *ret = NULL;
+
+       return ret;
+}
+
+/**
+ * @brief Service Adaptor D-Bus interface set property call handler.
+ *
+ * Service Adaptor D-Bus interface set property call handler.
+ * @param connection A GDBusConnection.
+ * @param sender The unique bus name of the remote caller.
+ * @param object_path The object path that the method was invoked on.
+ * @param interface_name The D-Bus interface name for the property.
+ * @param property_name The name of the property to get the value of.
+ * @param value The value to set the property to.
+ * @param error Return location for error.
+ * @param user_data     The user_data gpointer passed to g_dbus_connection_register_object().
+ * @return TRUE if the property was set to value, FALSE if error is set.
+ */
+static gboolean _handle_set_property(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *property_name,
+               GVariant *value,
+               GError **error,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       gboolean ret = false;
+
+       if (NULL == *error)
+       {
+               ret = true;
+       }
+
+       return ret;
+}
+
+/**
+ * D-Bus handlers vtable.
+ */
+static const GDBusInterfaceVTable interface_vtable =
+{
+       _handle_method_call,
+       _handle_get_property,
+       _handle_set_property
+};
+
+/**
+ * @brief Callback function called when D-Bus bus name for Service Adaptor D-Bus server is acquired.
+ *
+ * Callback function called when D-Bus bus name for Service Adaptor D-Bus server is acquired.
+ * @param connection The GDBusConnection to a message bus.
+ * @param name The name that is requested to be owned.
+ * @param user_data User data passed to g_bus_own_name().
+ */
+static void _on_bus_acquired(GDBusConnection *connection,
+               const gchar *name,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       guint registration_id;
+
+       registration_id = g_dbus_connection_register_object(connection,
+                       SERVICE_ADAPTOR_OBJECT_PATH,
+                       introspection_data->interfaces[0],
+                       &interface_vtable,
+                       NULL, /* user_data */
+                       NULL, /* user_data_free_func */
+                       NULL); /* GError** */
+
+       g_assert(registration_id > 0);
+}
+
+/**
+ * @brief Callback function called when D-Bus name for Service Adaptor D-Bus server is acquired.
+ *
+ * Callback function called when D-Bus name for Service Adaptor D-Bus server is acquired.
+ * @param connection The GDBusConnection on which to acquired the name.
+ * @param name The name being owned.
+ * @param user_data User data passed to g_bus_own_name() or g_bus_own_name_on_connection().
+ */
+static void _on_name_acquired(GDBusConnection *connection,
+               const gchar *name,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       dbus_connection = connection;
+       g_object_ref(dbus_connection);
+}
+
+/**
+ * @brief Callback function called when the Service Adaptor D-Bus name is lost or connection has been closed.
+ *
+ * Callback function called when the Service Adaptor D-Bus name is lost or connection has been closed.
+ * @param connection The GDBusConnection on which to acquire the name or NULL if the connection was disconnected.
+ * @param name The name being owned.
+ * @param user_data User data passed to g_bus_own_name() or g_bus_own_name_on_connection().
+ */
+static void _on_name_lost(GDBusConnection *connection,
+               const gchar *name,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       if (NULL != dbus_connection)
+       {
+               g_object_unref(dbus_connection);
+               dbus_connection = NULL;
+       }
+
+       SAL_INFO("Unexpected D-bus bus name lost");
+
+       // Send SIGINT to main thread to stop File Manager process and cleanly close Service Adaptor
+       kill(getpid(), SIGINT);
+}
+
+service_adaptor_error_e _sal_ipc_server_start()
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL != introspection_data, SERVICE_ADAPTOR_ERROR_INTERNAL);
+       RETV_IF(0 != owner_id, SERVICE_ADAPTOR_ERROR_INTERNAL);
+
+       introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
+       RETVM_IF(NULL == introspection_data, SERVICE_ADAPTOR_ERROR_INTERNAL, "g_dbus_node_info_new_for_xml() Failed");
+
+       thread_pool = g_thread_pool_new(_method_call_async_func, NULL, -1, FALSE, NULL);
+       RETVM_IF(NULL == thread_pool, SERVICE_ADAPTOR_ERROR_SYSTEM, "g_thread_pool_new() Failed");
+
+       owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+                       SERVICE_ADAPTOR_BUS_NAME,
+                       G_BUS_NAME_OWNER_FLAGS_NONE,
+                       _on_bus_acquired,
+                       _on_name_acquired,
+                       _on_name_lost,
+                       NULL,
+                       NULL);
+
+       if (0 == owner_id)
+       {
+               g_dbus_node_info_unref(introspection_data);
+               introspection_data = NULL;
+
+               return SERVICE_ADAPTOR_ERROR_SYSTEM;
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+service_adaptor_error_e _sal_ipc_server_stop()
+{
+       SAL_FN_CALL;
+
+       if (NULL != thread_pool)
+       {
+               g_thread_pool_free(thread_pool, TRUE, TRUE);
+       }
+
+       if (0 != owner_id)
+       {
+               g_bus_unown_name(owner_id);
+               owner_id = 0;
+       }
+
+       if (NULL != introspection_data)
+       {
+               g_dbus_node_info_unref(introspection_data);
+               introspection_data = NULL;
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+/**
+ * @brief D-Bus server thread function.
+ *
+ * D-Bus server thread function. It initialises structures and callbacks needed to export D-Bus interfaces.
+ * @param data Data passed to thread.
+ * @return Result data from thread (always NULL in this implementation).
+ */
+static gpointer _dbus_server_thread_func(gpointer data)
+{
+       SAL_FN_CALL;
+
+       int ret = 0;
+
+       dbus_server_context = g_main_context_new();
+       dbus_server_loop = g_main_loop_new(dbus_server_context, FALSE);
+       g_main_context_push_thread_default(dbus_server_context);
+
+       ret = _sal_ipc_server_start();
+
+       if (SERVICE_ADAPTOR_ERROR_NONE == ret)
+       {
+               g_main_loop_run(dbus_server_loop);
+       }
+
+       _sal_ipc_server_stop();
+
+       g_main_context_pop_thread_default(dbus_server_context);
+       g_main_loop_unref(dbus_server_loop);
+       dbus_server_loop = NULL;
+       g_main_context_unref(dbus_server_context);
+       dbus_server_context = NULL;
+
+       return NULL;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API service_adaptor_error_e sal_ipc_server_init()
+{
+       SAL_FN_CALL;
+
+       RETVM_IF(NULL != dbus_server_thread, SERVICE_ADAPTOR_ERROR_INTERNAL, "IPC server thread is already running");
+
+       dbus_server_thread = g_thread_new("IPC Server", _dbus_server_thread_func, NULL);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e sal_ipc_server_deinit()
+{
+       SAL_FN_CALL;
+
+       if (NULL != dbus_server_loop)
+       {
+               if (g_main_loop_is_running(dbus_server_loop))
+               {
+                       g_main_loop_quit(dbus_server_loop);
+               }
+       }
+
+       if (NULL != dbus_server_thread)
+       {
+               g_thread_join(dbus_server_thread);
+               dbus_server_thread = NULL;
+       }
+
+       if (NULL != dbus_server_loop)
+       {
+               g_main_loop_unref(dbus_server_loop);
+               dbus_server_loop = NULL;
+       }
+
+       if (NULL != dbus_server_context)
+       {
+               g_main_context_pop_thread_default(dbus_server_context);
+               g_main_context_unref(dbus_server_context);
+               dbus_server_context = NULL;
+       }
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
similarity index 76%
rename from common/ipc/sal_ipc.h
rename to common/ipc-server/sal_ipc_server.h
index 009d59b..034d98b 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Service Adaptor
+ * Service Adaptor Server IPC
  *
  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
  *
  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
@@ -21,8 +21,8 @@
  *
  */
 
  *
  */
 
-#ifndef __TIZEN_CONVERGENCE_SAL_IPC_H__
-#define __TIZEN_CONVERGENCE_SAL_IPC_H__
+#ifndef __TIZEN_CONVERGENCE_SAL_IPC_SERVER_H__
+#define __TIZEN_CONVERGENCE_SAL_IPC_SERVER_H__
 
 #ifndef API
 #define API __attribute__ ((visibility("default")))
 
 #ifndef API
 #define API __attribute__ ((visibility("default")))
@@ -34,12 +34,14 @@ extern "C"
 #endif
 
 #include "service_adaptor_errors.h"
 #endif
 
 #include "service_adaptor_errors.h"
+#include "sal_ipc.h"
 
 
-API service_adaptor_error_e sal_ipc_init_server();
-API service_adaptor_error_e sal_ipc_deinit_server();
+service_adaptor_error_e sal_ipc_server_init();
+service_adaptor_error_e sal_ipc_server_deinit();
 
 #ifdef __cplusplus
 }
 #endif
 
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* __TIZEN_CONVERGENCE_SAL_IPC_H__ */
+#endif /* __TIZEN_CONVERGENCE_SAL_IPC_SERVER_H__ */
+
diff --git a/common/ipc-server/sal_ipc_server_auth.c b/common/ipc-server/sal_ipc_server_auth.c
new file mode 100644 (file)
index 0000000..22a8962
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * Service Adaptor IPC Server
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdint.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal.h"
+#include "sal_ipc_server.h"
+#include "sal_ipc_server_auth.h"
+#include "auth_adaptor.h"
+#include "sal_service_auth.h"
+#include "sal_service_auth_internal.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+void _oauth1_get_access_token_cb(int result, oauth1_h oauth1, void *user_data)
+{
+       SAL_FN_CALL;
+
+       ipc_reply_data_h reply = (ipc_reply_data_h) user_data;
+
+       int ipc_ret = SERVICE_ADAPTOR_ERROR_NONE;
+       char *ipc_msg = NULL;
+       GVariant *ipc_data = NULL;
+
+       ipc_create_error_msg(ipc_ret, &ipc_msg);
+       ipc_data = g_variant_new(ipc_make_return_type(reply->type), SAL_IPC_STR(oauth1->access_token), SAL_IPC_STR(oauth1->operation), ipc_ret, SAL_IPC_STR(ipc_msg));
+       g_dbus_method_invocation_return_value(reply->invocation, ipc_data);
+
+       SAL_FREE(ipc_msg);
+       ipc_free_reply_data(reply);
+}
+
+int _get_oauth1(GVariant *reply_info, service_auth_oauth1_h *oauth1)
+{
+       SAL_FN_CALL;
+
+       service_auth_oauth1_h auth_oauth1 = (service_auth_oauth1_h) g_malloc0(sizeof(service_auth_oauth1_s));
+
+       int info_size = service_auth_oauth1_s_type_length;
+       GVariant *info[info_size];
+       ipc_create_variant_info(reply_info, info_size, (GVariant ***) &info);
+
+       int idx = 0;
+       auth_oauth1->access_token = ipc_insure_g_variant_dup_string(info[idx++]);
+       auth_oauth1->operation = ipc_insure_g_variant_dup_string(info[idx++]);
+
+       ipc_destroy_variant_info(info, info_size);
+
+       *oauth1 = auth_oauth1;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+int _oauth1_execute_operation(auth_plugin_h plugin, service_auth_oauth1_h oauth1, ipc_reply_data_h reply)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin->oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       if (0 == strcmp(oauth1->operation, SERVICE_AUTH_OAUTH1_0_GET_ACCESS_TOKEN_URI))
+       {
+               ret = plugin->oauth1->oauth1_get_access_token(plugin, _oauth1_get_access_token_cb, reply);
+
+               return ret;
+       }
+       else if (0 == strcmp(oauth1->operation, SERVICE_AUTH_OAUTH1_0_GET_EXTRA_DATA_URI))
+       {
+               return ret;
+       }
+
+       return SERVICE_ADAPTOR_ERROR_INTERNAL;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API void service_auth_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       int ipc_ret = SERVICE_ADAPTOR_ERROR_NONE;
+       char *ipc_msg = NULL;
+       char *ipc_type = NULL;
+       GVariant *ipc_data = NULL;
+
+       char *uri = NULL;
+
+       GVariant *in_parameters = g_variant_get_child_value(parameters, 0);
+
+       if (0 == g_strcmp0(method_name, DBUS_SERVICE_AUTH_OAUTH1_METHOD))
+       {
+               int idx = 0;
+               int size = service_auth_oauth1_req_s_type_length;
+               GVariant *req_info[size];
+
+               ipc_create_variant_info(in_parameters, size, (GVariant ***) &req_info);
+
+               char *uri = ipc_insure_g_variant_dup_string(req_info[idx++]);
+               service_auth_oauth1_h oauth1 = NULL;
+               _get_oauth1(req_info[idx++], &oauth1);
+
+               SAL_INFO("uri: %s", uri);
+
+               ipc_ret = SERVICE_ADAPTOR_ERROR_INTERNAL;
+               ipc_type = strdup(service_auth_oauth1_res_s_type);
+
+               sal_h sal = sal_get_handle();
+               TRYVM_IF(NULL == sal, ipc_ret = SERVICE_ADAPTOR_ERROR_INTERNAL, "sal_get_handle() Failed");
+
+               auth_plugin_h plugin = auth_adaptor_get_plugin(sal->auth, uri);
+
+               ipc_reply_data_h reply = (ipc_reply_data_h) g_malloc0(sizeof(ipc_reply_data_s));
+               reply->invocation = invocation;
+               reply->type = strdup(ipc_type);
+
+               ipc_ret = _oauth1_execute_operation(plugin, oauth1, reply);
+               TRY_IF(SERVICE_ADAPTOR_ERROR_NONE == ipc_ret, "oauth1_execute_operation() Request Successed");
+
+               ipc_create_error_msg(ipc_ret, &ipc_msg);
+               ipc_data = g_variant_new(ipc_make_return_type(ipc_type), SAL_IPC_STR(NULL), SAL_IPC_STR(NULL), ipc_ret, SAL_IPC_STR(ipc_msg));
+
+               ipc_destroy_variant_info(req_info, size);
+       }
+
+       g_dbus_method_invocation_return_value(invocation, ipc_data);
+
+catch:
+       SAL_FREE(uri);
+       SAL_FREE(ipc_msg);
+       SAL_FREE(ipc_type);
+
+       SAL_FN_END;
+}
diff --git a/common/ipc-server/sal_ipc_server_auth.h b/common/ipc-server/sal_ipc_server_auth.h
new file mode 100644 (file)
index 0000000..9162034
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Service Adaptor Server Auth IPC
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yongjin Kim <youth.kim@samsung.com>
+ *          Jinhyeong Ahn <jinh.ahn@samsung.com>
+ *          Jiwon Kim <jiwon177.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SAL_IPC_SERVER_AUTH_H__
+#define __TIZEN_CONVERGENCE_SAL_IPC_SERVER_AUTH_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+#include <gio/gio.h>
+
+void service_auth_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_CONVERGENCE_SAL_IPC_SERVER_AUTH_H__ */
+
diff --git a/common/ipc-server/sal_ipc_server_core.c b/common/ipc-server/sal_ipc_server_core.c
new file mode 100644 (file)
index 0000000..1f5f471
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+ * Service Adaptor IPC Server
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdint.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal.h"
+#include "sal_ipc_server.h"
+#include "sal_ipc_server_core.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API void service_adaptor_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       int ipc_ret = SERVICE_ADAPTOR_ERROR_NONE;
+       char *ipc_msg = NULL;
+       char *ipc_type = NULL;
+       GVariant *ipc_data = NULL;
+
+       char *uri = NULL;
+
+       GVariant *in_parameters = g_variant_get_child_value(parameters, 0);
+
+       if (0 == g_strcmp0(method_name, DBUS_SERVICE_ADAPTOR_CONNECT_METHOD))
+       {
+               int idx = 0;
+               int size = service_adaptor_connect_req_s_type_length;
+               GVariant *req_info[size];
+
+               ipc_create_variant_info(in_parameters, size, (GVariant ***) &req_info);
+
+               char *uri = ipc_insure_g_variant_dup_string(req_info[idx++]);
+
+               SAL_INFO("uri: %s", uri);
+
+               ipc_type = strdup(service_adaptor_connect_res_s_type);
+               ipc_ret = sal_adaptor_connect(uri);
+
+               int plugins_size = 0;
+               char **plugins = NULL;
+               GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE(plugin_list_type));
+
+               ipc_ret = sal_adaptor_get_plugins(&plugins, &plugins_size);
+
+               for (gsize i = 0; i < plugins_size; i++)
+               {
+                       ipc_insure_g_variant_builder_add_array_string(builder, plugins[i]);
+               }
+
+               ipc_create_error_msg(ipc_ret, &ipc_msg);
+               ipc_data = g_variant_new(ipc_make_return_type(ipc_type), builder, ipc_ret, SAL_IPC_STR(ipc_msg));
+
+               g_variant_builder_unref(builder);
+               ipc_destroy_variant_info(req_info, size);
+       }
+       else if (0 == g_strcmp0(method_name, DBUS_SERVICE_ADAPTOR_DISCONNECT_METHOD))
+       {
+               int idx = 0;
+               int size = service_adaptor_disconnect_s_type_length;
+               GVariant *req_info[size];
+
+               ipc_create_variant_info(in_parameters, size, (GVariant ***) &req_info);
+
+               char *uri = ipc_insure_g_variant_dup_string(req_info[idx++]);
+
+               SAL_INFO("uri: %s", uri);
+
+               ipc_ret = sal_adaptor_disconnect(uri);
+
+               ipc_create_error_msg(ipc_ret, &ipc_msg);
+               ipc_data = g_variant_new(ipc_make_return_type(ipc_type), ipc_ret, SAL_IPC_STR(ipc_msg));
+
+               ipc_destroy_variant_info(req_info, size);
+       }
+
+       g_dbus_method_invocation_return_value(invocation, ipc_data);
+
+       SAL_FREE(uri);
+       SAL_FREE(ipc_msg);
+       SAL_FREE(ipc_type);
+
+       SAL_FN_END;
+}
+
+API void service_plugin_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       int ipc_ret = SERVICE_ADAPTOR_ERROR_NONE;
+       char *ipc_msg = NULL;
+       char *ipc_type = NULL;
+       GVariant *ipc_data = NULL;
+
+       char *uri = NULL;
+
+       GVariant *in_parameters = g_variant_get_child_value(parameters, 0);
+
+       if (0 == g_strcmp0(method_name, DBUS_SERVICE_PLUGIN_CREATE_METHOD))
+       {
+               int idx = 0;
+               int size = service_plugin_create_s_type_length;
+               GVariant *req_info[size];
+
+               ipc_create_variant_info(in_parameters, size, (GVariant ***) &req_info);
+
+               char *uri = ipc_insure_g_variant_dup_string(req_info[idx++]);
+
+               SAL_INFO("uri: %s", uri);
+
+               ipc_ret = SERVICE_ADAPTOR_ERROR_INTERNAL;
+
+               sal_h sal = sal_get_handle();
+
+               if (NULL != sal)
+               {
+                       ipc_ret = auth_adaptor_ref_plugin(sal->auth, uri);
+               }
+
+               ipc_create_error_msg(ipc_ret, &ipc_msg);
+               ipc_data = g_variant_new(ipc_make_return_type(ipc_type), ipc_ret, SAL_IPC_STR(ipc_msg));
+
+               ipc_destroy_variant_info(req_info, size);
+       }
+       else if (0 == g_strcmp0(method_name, DBUS_SERVICE_PLUGIN_DESTROY_METHOD))
+       {
+               int idx = 0;
+               int size = service_plugin_destroy_s_type_length;
+               GVariant *req_info[size];
+
+               ipc_create_variant_info(in_parameters, size, (GVariant ***) &req_info);
+
+               char *uri = ipc_insure_g_variant_dup_string(req_info[idx++]);
+
+               SAL_INFO("uri: %s", uri);
+
+               ipc_ret = SERVICE_ADAPTOR_ERROR_INTERNAL;
+
+               sal_h sal = sal_get_handle();
+
+               if (NULL != sal)
+               {
+                       ipc_ret = auth_adaptor_unref_plugin(sal->auth, uri);
+               }
+
+               ipc_create_error_msg(ipc_ret, &ipc_msg);
+               ipc_data = g_variant_new(ipc_make_return_type(ipc_type), ipc_ret, SAL_IPC_STR(ipc_msg));
+
+               ipc_destroy_variant_info(req_info, size);
+       }
+
+       g_dbus_method_invocation_return_value(invocation, ipc_data);
+
+       SAL_FREE(uri);
+       SAL_FREE(ipc_msg);
+       SAL_FREE(ipc_type);
+
+       SAL_FN_END;
+}
+/*
+service_adaptor_internal_error_code_e dbus_service_adaptor_signal_callback(service_adaptor_internal_signal_code_e signal_code,
+                                               const char *signal_msg)
+{
+       SAL_FN_CALL;
+
+       GError* error = NULL;
+       GDBusConnection *dbus_connection = dbus_get_connection();
+
+       if (NULL != dbus_connection)
+       {
+               GVariant *response = g_variant_new("(ts)", (uint64_t) signal_code, signal_msg);
+
+               g_dbus_connection_emit_signal(dbus_connection,
+                               NULL,
+                               SERVICE_ADAPTOR_OBJECT_PATH,
+                               SERVICE_ADAPTOR_INTERFACE,
+                               DBUS_SERVICE_ADAPTOR_SIGNAL,
+                               response,
+                               &error );
+
+               if (NULL != error)
+               {
+                       service_adaptor_debug("Unable to send msg: %s", error->message);
+                       return SERVICE_ADAPTOR_INTERNAL_ERROR_DBUS;
+               }
+       }
+
+       return SERVICE_ADAPTOR_INTERNAL_ERROR_NONE;
+}
+*/
diff --git a/common/ipc-server/sal_ipc_server_core.h b/common/ipc-server/sal_ipc_server_core.h
new file mode 100644 (file)
index 0000000..917743e
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Service Adaptor Server Core IPC
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yongjin Kim <youth.kim@samsung.com>
+ *          Jinhyeong Ahn <jinh.ahn@samsung.com>
+ *          Jiwon Kim <jiwon177.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SAL_IPC_SERVER_CORE_H__
+#define __TIZEN_CONVERGENCE_SAL_IPC_SERVER_CORE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+#include <gio/gio.h>
+
+void service_adaptor_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data);
+
+void service_plugin_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_CONVERGENCE_SAL_IPC_SERVER_CORE_H__ */
+
diff --git a/common/ipc-server/sal_ipc_server_storage.c b/common/ipc-server/sal_ipc_server_storage.c
new file mode 100644 (file)
index 0000000..e91fd70
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * Service Adaptor IPC Server
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdint.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal.h"
+#include "sal_ipc_server.h"
+#include "sal_ipc_server_storage.h"
+#include "storage_adaptor.h"
+#include "sal_service_storage.h"
+#include "sal_service_storage_internal.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+void _cloud_remove_file_cb(int result, cloud_file_h file, void *user_data)
+{
+       SAL_FN_CALL;
+
+       ipc_reply_data_h reply = (ipc_reply_data_h) user_data;
+
+       int ipc_ret = SERVICE_ADAPTOR_ERROR_NONE;
+       char *ipc_msg = NULL;
+       GVariant *ipc_data = NULL;
+
+       GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE(file_list_type));
+
+       ipc_create_error_msg(ipc_ret, &ipc_msg);
+       ipc_data = g_variant_new(ipc_make_return_type(reply->type), file->is_dir, SAL_IPC_STR(file->dir_path), SAL_IPC_STR(file->local_path), SAL_IPC_STR(file->cloud_path), file->size, SAL_IPC_STR(file->operation), builder, ipc_ret, SAL_IPC_STR(ipc_msg));
+       g_dbus_method_invocation_return_value(reply->invocation, ipc_data);
+
+       SAL_FREE(ipc_msg);
+       ipc_free_reply_data(reply);
+       g_variant_builder_unref(builder);
+
+       SAL_FN_END;
+}
+
+int _get_cloud_file(GVariant *reply_info, service_storage_cloud_file_h *file)
+{
+       SAL_FN_CALL;
+
+       service_storage_cloud_file_h cloud_file = (service_storage_cloud_file_h) g_malloc0(sizeof(service_storage_cloud_file_s));
+
+       int info_size = service_storage_cloud_file_s_type_length;
+       GVariant *info[info_size];
+       ipc_create_variant_info(reply_info, info_size, (GVariant ***) &info);
+
+       int idx = 0;
+       cloud_file->is_dir = g_variant_get_boolean(info[idx++]);
+       cloud_file->dir_path = ipc_insure_g_variant_dup_string(info[idx++]);
+       cloud_file->local_path = ipc_insure_g_variant_dup_string(info[idx++]);
+       cloud_file->cloud_path = ipc_insure_g_variant_dup_string(info[idx++]);
+       cloud_file->size = g_variant_get_uint64(info[idx++]);
+       cloud_file->operation = ipc_insure_g_variant_dup_string(info[idx++]);
+
+       ipc_destroy_variant_info(info, info_size);
+
+       *file = cloud_file;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+int _cloud_execute_operation(storage_plugin_h plugin, service_storage_cloud_file_h file, ipc_reply_data_h reply)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == plugin->cloud, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == file, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_REMOVE_FILE_URI))
+       {
+               ret = plugin->cloud->cloud_remove_file(plugin, file->cloud_path, _cloud_remove_file_cb, reply);
+
+               return ret;
+       }
+       else if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_DOWNLOAD_FILE_URI))
+       {
+               return ret;
+       }
+       else if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_UPLOAD_FILE_URI))
+       {
+               return ret;
+       }
+       else if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_DOWNLOAD_FILE_THUMBNAIL_URI))
+       {
+               return ret;
+       }
+       else if (0 == strcmp(file->operation, SERVICE_STORAGE_CLOUD_GET_FILE_LIST_URI))
+       {
+               return ret;
+       }
+
+       return SERVICE_ADAPTOR_ERROR_INTERNAL;
+}
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API void service_storage_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data)
+{
+       SAL_FN_CALL;
+
+       int ipc_ret = SERVICE_ADAPTOR_ERROR_NONE;
+       char *ipc_msg = NULL;
+       char *ipc_type = NULL;
+       GVariant *ipc_data = NULL;
+
+       char *uri = NULL;
+
+       GVariant *in_parameters = g_variant_get_child_value(parameters, 0);
+
+       if (0 == g_strcmp0(method_name, DBUS_SERVICE_STORAGE_CLOUD_FILE_METHOD))
+       {
+               int idx = 0;
+               int size = service_storage_cloud_file_req_s_type_length;
+               GVariant *req_info[size];
+
+               ipc_create_variant_info(in_parameters, size, (GVariant ***) &req_info);
+
+               char *uri = ipc_insure_g_variant_dup_string(req_info[idx++]);
+               service_storage_cloud_file_h file = NULL;
+               _get_cloud_file(req_info[idx++], &file);
+
+               SAL_INFO("uri: %s", uri);
+
+               ipc_ret = SERVICE_ADAPTOR_ERROR_INTERNAL;
+               ipc_type = strdup(service_storage_cloud_file_res_s_type);
+
+               sal_h sal = sal_get_handle();
+               TRYVM_IF(NULL == sal, ipc_ret = SERVICE_ADAPTOR_ERROR_INTERNAL, "sal_get_handle() Failed");
+
+               storage_plugin_h plugin = storage_adaptor_get_plugin(sal->storage, uri);
+
+               ipc_reply_data_h reply = (ipc_reply_data_h) g_malloc0(sizeof(ipc_reply_data_s));
+               reply->invocation = invocation;
+               reply->type = strdup(ipc_type);
+
+               ipc_ret = _cloud_execute_operation(plugin, file, reply);
+               TRY_IF(SERVICE_ADAPTOR_ERROR_NONE == ipc_ret, "cloud_execute_operation() Request Successed");
+
+               GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE(file_list_type));
+               ipc_create_error_msg(ipc_ret, &ipc_msg);
+               ipc_data = g_variant_new(ipc_make_return_type(ipc_type), false, "", "", 0, 0, builder, ipc_ret, SAL_IPC_STR(ipc_msg));
+
+               g_variant_builder_unref(builder);
+               ipc_destroy_variant_info(req_info, size);
+       }
+
+       g_dbus_method_invocation_return_value(invocation, ipc_data);
+
+catch:
+       SAL_FREE(uri);
+       SAL_FREE(ipc_msg);
+       SAL_FREE(ipc_type);
+
+       SAL_FN_END;
+}
diff --git a/common/ipc-server/sal_ipc_server_storage.h b/common/ipc-server/sal_ipc_server_storage.h
new file mode 100644 (file)
index 0000000..9289cd2
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Service Adaptor Server Storage IPC
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yongjin Kim <youth.kim@samsung.com>
+ *          Jinhyeong Ahn <jinh.ahn@samsung.com>
+ *          Jiwon Kim <jiwon177.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SAL_IPC_SERVER_STORAGE_H__
+#define __TIZEN_CONVERGENCE_SAL_IPC_SERVER_STORAGE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+#include <gio/gio.h>
+
+void service_storage_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_CONVERGENCE_SAL_IPC_SERVER_STORAGE_H__ */
+
diff --git a/common/ipc/sal_ipc.c b/common/ipc/sal_ipc.c
deleted file mode 100644 (file)
index fb83e28..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "sal_ipc.h"
-
-service_adaptor_error_e sal_ipc_init_server()
-{
-       return SERVICE_ADAPTOR_ERROR_NONE;
-}
-
-service_adaptor_error_e sal_ipc_deinit_server()
-{
-       return SERVICE_ADAPTOR_ERROR_NONE;
-}
diff --git a/common/sal_common.c b/common/sal_common.c
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/common/sal_ipc.c b/common/sal_ipc.c
new file mode 100644 (file)
index 0000000..814fdcf
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Service Adaptor IPC
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "service_adaptor_errors.h"
+#include "service_adaptor_internal.h"
+#include "sal_ipc.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+API char *ipc_insure_g_variant_dup_string(GVariant *string)
+{
+       char *ret = g_variant_dup_string(string, NULL);
+
+       if (0 == strcmp(ret, ""))
+       {
+               SAL_FREE(ret);
+       }
+
+       return ret;
+}
+
+API void ipc_insure_g_variant_builder_add_array_string(GVariantBuilder *builder, const char *str)
+{
+       if (NULL == str)
+       {
+               g_variant_builder_add(builder, "(s)", "");
+       }
+       else
+       {
+               g_variant_builder_add(builder, "(s)", str);
+       }
+}
+
+API char *ipc_make_return_type(const char *type)
+{
+       return g_strdup_printf("(%sis)", SAL_IPC_STR(type));
+}
+
+API void ipc_create_error_msg(int code, char **ipc_msg)
+{
+       switch (code)
+       {
+               case SERVICE_ADAPTOR_ERROR_NONE:
+               {
+                       *ipc_msg = NULL;
+                       break;
+               }
+               case SERVICE_ADAPTOR_ERROR_INTERNAL:
+               {
+                       *ipc_msg = strdup("SERVICE_ADAPTOR_ERROR_INTERNAL");
+                       break;
+               }
+               default:
+               {
+                       *ipc_msg = strdup("SERVICE_ADAPTOR_ERROR_UNKNOWN");
+                       break;
+               }
+       }
+}
+
+API void ipc_create_variant_info(GVariant *parameters, int size, GVariant ***var_info)
+{
+       for (size_t i = 0; i < size; i++)
+       {
+               *(var_info +i) = (GVariant **) g_variant_get_child_value(parameters, i);
+       }
+}
+
+API void ipc_destroy_variant_info(GVariant **var_info, int size)
+{
+       for (size_t i = 0; i < size; i++)
+       {
+               g_variant_unref(var_info[i]);
+       }
+}
+
+API void ipc_free_reply_data(ipc_reply_data_h reply)
+{
+       SAL_FN_CALL;
+
+       RET_IF(NULL == reply);
+
+       SAL_FREE(reply->type);
+       SAL_FREE(reply);
+
+       SAL_FN_END;
+}
diff --git a/common/sal_ipc.h b/common/sal_ipc.h
new file mode 100644 (file)
index 0000000..3561e01
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * Service Adaptor IPC
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yongjin Kim <youth.kim@samsung.com>
+ *          Jinhyeong Ahn <jinh.ahn@samsung.com>
+ *          Jiwon Kim <jiwon177.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SAL_IPC_H__
+#define __TIZEN_CONVERGENCE_SAL_IPC_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define SAL_IPC_STR(x) (x==NULL)?"":x
+
+/**
+ * Service Adaptor D-Bus server bus name.
+ */
+#define SERVICE_ADAPTOR_BUS_NAME "org.tizen.serviceadaptor.client"
+
+/**
+ * Service Adaptor D-Bus server object path.
+ */
+#define SERVICE_ADAPTOR_OBJECT_PATH "/org/tizen/serviceadaptor/client"
+
+/**
+ * Service Adaptor D-Bus interface.
+ */
+#define SERVICE_ADAPTOR_INTERFACE "org.tizen.serviceadaptor.client.interface"
+
+/**
+ * struct for dbus.
+ */
+#define service_adaptor_connect_req_s_type_length 1
+#define service_adaptor_connect_req_s_type \
+       "(" \
+       "s" /* char *uri */ \
+       ")"
+
+#define service_adaptor_connect_res_s_type_length 1
+#define service_adaptor_connect_res_s_type \
+       "(" \
+       "a(s)" /* char **uri */ \
+       ")"
+
+#define service_adaptor_disconnect_s_type_length 1
+#define service_adaptor_disconnect_s_type \
+       "(" \
+       "s" /* char *uri */ \
+       ")"
+
+#define service_plugin_create_s_type_length 1
+#define service_plugin_create_s_type \
+       "(" \
+       "s" /* char *uri */ \
+       ")"
+
+#define service_plugin_destroy_s_type_length 1
+#define service_plugin_destroy_s_type \
+       "(" \
+       "s" /* char *uri */ \
+       ")"
+
+#define service_auth_oauth1_s_type_length 2
+#define service_auth_oauth1_s_type \
+       "(" \
+       "s" /* char *access_token */ \
+       "s" /* char *operation */ \
+       ")"
+
+#define service_auth_oauth1_req_s_type_length 2
+#define service_auth_oauth1_req_s_type \
+       "(" \
+       "s" /* char *uri */ \
+       service_auth_oauth1_s_type /* service_auth_oauth1_s oauth1 */ \
+       ")"
+
+#define service_auth_oauth1_res_s_type_length 1
+#define service_auth_oauth1_res_s_type \
+       "(" \
+       service_auth_oauth1_s_type /* service_auth_oauth1_s oauth1 */ \
+       ")"
+
+#define service_storage_cloud_file_s_type_length 6
+#define service_storage_cloud_file_s_type \
+       "(" \
+       "b" /* bool is_dir */ \
+       "s" /* char *dir_path */ \
+       "s" /* char *local_path */ \
+       "s" /* char *cloud_path */ \
+       "t" /* uint64 size */ \
+       "s" /* char *operation */ \
+       ")"
+
+#define service_storage_cloud_file_req_s_type_length 2
+#define service_storage_cloud_file_req_s_type \
+       "(" \
+       "s" /* char *uri */ \
+       service_storage_cloud_file_s_type /* service_storage_cloud_file_s file */ \
+       ")"
+
+#define service_storage_cloud_file_res_s_type_length 2
+#define service_storage_cloud_file_res_s_type \
+       "(" \
+       service_storage_cloud_file_s_type /* service_storage_cloud_file_s file */ \
+       "a" service_storage_cloud_file_s_type /* GList *files */  \
+       ")"
+
+/**
+ * array of structures
+ */
+#define plugin_list_type                               "a(s)"
+#define file_list_type                                 "a" service_storage_cloud_file_s_type
+
+/**
+ * append error code to the type
+ */
+#define RETURN_LENGTH                                  2
+
+/**
+ * DBus APIs
+ */
+#define DBUS_SERVICE_ADAPTOR                           "dbus_00"
+#define DBUS_SERVICE_PLUGIN                            "dbus_01"
+#define DBUS_SERVICE_AUTH                              "dbus_02"
+#define DBUS_SERVICE_STORAGE                           "dbus_03"
+#define DBUS_NAME_LENGTH                               7
+
+#define DBUS_SERVICE_ADAPTOR_CONNECT_METHOD            DBUS_SERVICE_ADAPTOR "_service_adaptor_connect"
+#define DBUS_SERVICE_ADAPTOR_DISCONNECT_METHOD         DBUS_SERVICE_ADAPTOR "_service_adaptor_disconnect"
+
+#define DBUS_SERVICE_PLUGIN_CREATE_METHOD              DBUS_SERVICE_PLUGIN "_service_plugin_create"
+#define DBUS_SERVICE_PLUGIN_DESTROY_METHOD             DBUS_SERVICE_PLUGIN "_service_plugin_destroy"
+
+#define DBUS_SERVICE_AUTH_OAUTH1_METHOD                        DBUS_SERVICE_AUTH "_service_auth_oauth1"
+
+#define DBUS_SERVICE_STORAGE_CLOUD_FILE_METHOD         DBUS_SERVICE_STORAGE "_service_storage_cloud_file"
+
+#define DBUS_SERVICE_ADAPTOR_NOTIFY_SIGNAL             DBUS_SERVICE_ADAPTOR "_service_adaptor_signal_notify"
+
+typedef struct _ipc_reply_data_s
+{
+       GDBusMethodInvocation *invocation;
+       char *type;
+} ipc_reply_data_s;
+typedef struct _ipc_reply_data_s *ipc_reply_data_h;
+
+char *ipc_insure_g_variant_dup_string(GVariant *string);
+void ipc_insure_g_variant_builder_add_array_string(GVariantBuilder *builder, const char *str);
+char *ipc_make_return_type(const char *type);
+void ipc_create_error_msg(int code, char **ipc_msg);
+void ipc_create_variant_info(GVariant *parameters, int size, GVariant ***var_info);
+void ipc_destroy_variant_info(GVariant **var_info, int size);
+void ipc_free_reply_data(ipc_reply_data_h reply);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_CONVERGENCE_SAL_IPC_H__ */
index 0591e52..5c3cef1 100644 (file)
 #define __TIZEN_CONVERGENCE_SERVICE_ADAPTOR_H__
 
 #include <service_adaptor_errors.h>
 #define __TIZEN_CONVERGENCE_SERVICE_ADAPTOR_H__
 
 #include <service_adaptor_errors.h>
-#include <service_adaptor_types.h>
-#include <service_adaptor_internal.h>
+
+#include "sal_service_adaptor.h"
+#include "sal_service_task.h"
+#include "sal_service_auth.h"
+#include "sal_service_storage.h"
 
 #endif /* __TIZEN_CONVERGENCE_SERVICE_ADAPTOR_H__ */
 
 #endif /* __TIZEN_CONVERGENCE_SERVICE_ADAPTOR_H__ */
index d4e12a8..8bf04cc 100644 (file)
@@ -33,7 +33,7 @@
 #endif
 #define API __attribute__ ((visibility("default")))
 
 #endif
 #define API __attribute__ ((visibility("default")))
 
-#define LOG_TAG "SERVICE_ADAPTOR"
+#define LOG_TAG "SERVICE-ADAPTOR"
 #include <dlog.h>
 #define DLOG(prio, fmt, arg...) \
         do { SLOG(prio, LOG_TAG, fmt, ##arg); } while (0)
 #include <dlog.h>
 #define DLOG(prio, fmt, arg...) \
         do { SLOG(prio, LOG_TAG, fmt, ##arg); } while (0)
 #define IPC_ROLE "[LIB]"
 #endif
 
 #define IPC_ROLE "[LIB]"
 #endif
 
-#define INFO(fmt, arg...) SLOGI(IPC_ROLE" "fmt, ##arg)
-#define ERR(fmt, arg...) SLOGE(IPC_ROLE" "fmt, ##arg)
+/**
+ * Colors of font
+ */
+#define FONT_COLOR_RESET      "\033[0m"
+#define FONT_COLOR_BLACK      "\033[30m"             /* Black */
+#define FONT_COLOR_RED        "\033[31m"             /* Red */
+#define FONT_COLOR_GREEN      "\033[32m"             /* Green */
+#define FONT_COLOR_YELLOW     "\033[33m"             /* Yellow */
+#define FONT_COLOR_BLUE       "\033[34m"             /* Blue */
+#define FONT_COLOR_PURPLE     "\033[35m"             /* Purple */
+#define FONT_COLOR_CYAN       "\033[36m"             /* Cyan */
+#define FONT_COLOR_WHITE      "\033[37m"             /* White */
+#define FONT_COLOR_BOLDBLACK  "\033[1m\033[30m"      /* Bold Black */
+#define FONT_COLOR_BOLDRED    "\033[1m\033[31m"      /* Bold Red */
+#define FONT_COLOR_BOLDGREEN  "\033[1m\033[32m"      /* Bold Green */
+#define FONT_COLOR_BOLDYELLOW "\033[1m\033[33m"      /* Bold Yellow */
+#define FONT_COLOR_BOLDBLUE   "\033[1m\033[34m"      /* Bold Blue */
+#define FONT_COLOR_BOLDPURPLE "\033[1m\033[35m"      /* Bold Purple */
+#define FONT_COLOR_BOLDCYAN   "\033[1m\033[36m"      /* Bold Cyan */
+#define FONT_COLOR_BOLDWHITE  "\033[1m\033[37m"      /* Bold White */
+
+#define INFO(fmt, arg...) SLOGI(FONT_COLOR_YELLOW""IPC_ROLE" "fmt""FONT_COLOR_RESET, ##arg)
+#define ERR(fmt, arg...) SLOGE(FONT_COLOR_RED""IPC_ROLE" "fmt""FONT_COLOR_RESET, ##arg)
 #define DBG(fmt, arg...) SLOGD(IPC_ROLE" "fmt, ##arg)
 #define WARN(fmt, arg...) SLOGD(IPC_ROLE" "fmt, ##arg)
 #define VERBOSE(fmt, arg...) SLOGV(IPC_ROLE" "fmt, ##arg)
 #define DBG(fmt, arg...) SLOGD(IPC_ROLE" "fmt, ##arg)
 #define WARN(fmt, arg...) SLOGD(IPC_ROLE" "fmt, ##arg)
 #define VERBOSE(fmt, arg...) SLOGV(IPC_ROLE" "fmt, ##arg)
@@ -57,6 +78,8 @@
 
         #define SAL_FN_CALL DBG(">>>>>>>> called")
         #define SAL_FN_END DBG("<<<<<<<< ended")
 
         #define SAL_FN_CALL DBG(">>>>>>>> called")
         #define SAL_FN_END DBG("<<<<<<<< ended")
+//        #define SAL_FN_CALL INFO(">>>>>>>> called")
+//        #define SAL_FN_END INFO("<<<<<<<< ended")
 
         #define SAL_DBG(fmt, arg...) DBG(fmt, ##arg)
         #define SAL_WARN(fmt, arg...) WARN(fmt, ##arg)
 
         #define SAL_DBG(fmt, arg...) DBG(fmt, ##arg)
         #define SAL_WARN(fmt, arg...) WARN(fmt, ##arg)
                 return (val); \
         } \
 } while (0)
                 return (val); \
         } \
 } while (0)
+#define TRY_IF(expr, fmt, arg...) do { \
+        if (expr) { \
+                SAL_INFO(fmt, ##arg); \
+                goto catch; \
+        } \
+} while (0)
 #define TRYM_IF(expr, fmt, arg...) do { \
         if (expr) { \
                 SAL_ERR(fmt, ##arg); \
 #define TRYM_IF(expr, fmt, arg...) do { \
         if (expr) { \
                 SAL_ERR(fmt, ##arg); \
         } \
 } while (0)
 
         } \
 } while (0)
 
+#define SAL_STRDUP(dst, ptr) do { \
+       if (ptr) \
+               dst = strdup(ptr); \
+       ptr = NULL; \
+} while(0)
 
 #define SAL_FREE(ptr) do { \
        if (ptr) \
 
 #define SAL_FREE(ptr) do { \
        if (ptr) \
index e51c010..1a98384 100644 (file)
@@ -30,8 +30,7 @@
 #include "auth_adaptor.h"
 #include "contact_adaptor.h"
 #include "storage_adaptor.h"
 #include "auth_adaptor.h"
 #include "contact_adaptor.h"
 #include "storage_adaptor.h"
-
-#define FILE_PATH_LEN  256
+#include "resource_adaptor.h"
 
 typedef struct _service_adaptor_s
 {
 
 typedef struct _service_adaptor_s
 {
@@ -40,10 +39,12 @@ typedef struct _service_adaptor_s
        auth_adaptor_h                  auth;
        contact_adaptor_h               contact;
        storage_adaptor_h               storage;
        auth_adaptor_h                  auth;
        contact_adaptor_h               contact;
        storage_adaptor_h               storage;
+       resource_adaptor_h              resource;
 
        auth_adaptor_listener_h         auth_listener;
        contact_adaptor_listener_h      contact_listener;
        storage_adaptor_listener_h      storage_listener;
 
        auth_adaptor_listener_h         auth_listener;
        contact_adaptor_listener_h      contact_listener;
        storage_adaptor_listener_h      storage_listener;
+       resource_adaptor_listener_h      resource_listener;
 
        GMutex mutex;
        GCond cond;
 
        GMutex mutex;
        GCond cond;
@@ -51,5 +52,4 @@ typedef struct _service_adaptor_s
 } service_adaptor_s;
 typedef struct _service_adaptor_s *service_adaptor_h;
 
 } service_adaptor_s;
 typedef struct _service_adaptor_s *service_adaptor_h;
 
-
 #endif /* __TIZEN_CONVERGENCE_SERVICE_ADAPTOR_TYPES_H__ */
 #endif /* __TIZEN_CONVERGENCE_SERVICE_ADAPTOR_TYPES_H__ */
diff --git a/include/service_provider.h b/include/service_provider.h
new file mode 100644 (file)
index 0000000..509f236
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Service Provider
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SERVICE_PROVIDER_H__
+#define __TIZEN_CONVERGENCE_SERVICE_PROVIDER_H__
+
+#include "service_adaptor_errors.h"
+#include "sal_service_provider.h"
+#include "sal_auth_provider.h"
+
+#endif /* __TIZEN_CONVERGENCE_SERVICE_PROVIDER_H__ */
diff --git a/packaging/org.tizen.serviceadaptor.client.conf b/packaging/org.tizen.serviceadaptor.client.conf
new file mode 100644 (file)
index 0000000..d575a9d
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+    <policy user="system">
+        <allow own="org.tizen.serviceadaptor.client"/>
+    </policy>
+    <policy context="default">
+        <allow send_destination="org.tizen.serviceadaptor.client"/>
+    </policy>
+</busconfig>
diff --git a/packaging/org.tizen.serviceadaptor.client.service b/packaging/org.tizen.serviceadaptor.client.service
new file mode 100644 (file)
index 0000000..0f3d406
--- /dev/null
@@ -0,0 +1,6 @@
+[D-BUS Service]
+Name=org.tizen.serviceadaptor.client
+Exec=/bin/false
+SystemdService=service-adaptor.service
+User=system
+Group=system
index 925a7e4..6529108 100644 (file)
@@ -1,18 +1,17 @@
 [Unit]
 Description=Service Adaptor daemon
 [Unit]
 Description=Service Adaptor daemon
-Requires=dbus.socket
-After=dlog_logger.service tizen-runtime.target
+Requires=tizen-runtime.target
+After=tizen-runtime.target
 
 [Service]
 User=system
 Group=system
 SmackProcessLabel=service-adaptor
 Type=dbus
 
 [Service]
 User=system
 Group=system
 SmackProcessLabel=service-adaptor
 Type=dbus
-BusName=com.samsung.svcadaptor
-ExecStart=/usr/bin/service-adaptor
-Restart=none
-RestartSec=0
-KillMode=none
+BusName=org.tizen.serviceadaptor.client
+ExecStart=/usr/bin/service-adaptor-server
+Restart=always
+RestartSec=1
 
 [Install]
 WantedBy=multi-user.target
 
 [Install]
 WantedBy=multi-user.target
index 9003ff8..1cef723 100644 (file)
@@ -1,6 +1,6 @@
 Name:       service-adaptor
 Summary:    Service Adaptor Framework for Convergence
 Name:       service-adaptor
 Summary:    Service Adaptor Framework for Convergence
-Version:    0.0.1
+Version:    1.1.0
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
@@ -14,6 +14,7 @@ BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(gobject-2.0)
 BuildRequires:  pkgconfig(gthread-2.0)
 BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(gobject-2.0)
 BuildRequires:  pkgconfig(gthread-2.0)
 BuildRequires:  pkgconfig(capi-base-common)
+BuildRequires:  pkgconfig(capi-appfw-application)
 BuildRequires:  pkgconfig(capi-appfw-app-manager)
 BuildRequires:  pkgconfig(capi-appfw-package-manager)
 BuildRequires:  pkgconfig(libsmack)
 BuildRequires:  pkgconfig(capi-appfw-app-manager)
 BuildRequires:  pkgconfig(capi-appfw-package-manager)
 BuildRequires:  pkgconfig(libsmack)
@@ -59,6 +60,10 @@ mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
 install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/system/
 ln -sf ../service-adaptor.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/
 
 install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/system/
 ln -sf ../service-adaptor.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/
 
+mkdir -p %{buildroot}/usr/lib/systemd/user/tizen-middleware.target.wants
+cp %SOURCE1 %{buildroot}/usr/lib/systemd/user/service-adaptor.service
+ln -s ../service-adaptor.service %{buildroot}/usr/lib/systemd/user/tizen-middleware.target.wants/
+
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE.APLv2 %{buildroot}/usr/share/license/service-adaptor
 cp LICENSE.APLv2 %{buildroot}/usr/share/license/service-adaptor-devel
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE.APLv2 %{buildroot}/usr/share/license/service-adaptor
 cp LICENSE.APLv2 %{buildroot}/usr/share/license/service-adaptor-devel
@@ -70,17 +75,22 @@ cp LICENSE.APLv2 %{buildroot}/usr/share/license/service-adaptor-devel
 
 %files -n service-adaptor
 %manifest service-adaptor.manifest
 
 %files -n service-adaptor
 %manifest service-adaptor.manifest
-%defattr(-,system,system,-)
+#%defattr(-,system,system,-)
+%defattr(-,root,root,-)
 %{_libdir}/lib*.so.*
 %{_libdir}/lib*.so.*
-%{_bindir}/service-adaptor
+%{_bindir}/service-adaptor-server
 %{_bindir}/sal-test
 %{_bindir}/sal-test
+/usr/lib/systemd/user/service-adaptor.service
+/usr/lib/systemd/user/tizen-middleware.target.wants/service-adaptor.service
 %{_libdir}/systemd/system/service-adaptor.service
 %{_libdir}/systemd/system/multi-user.target.wants/service-adaptor.service
 /usr/share/license/%{name}
 
 %files -n service-adaptor-devel
 %{_libdir}/systemd/system/service-adaptor.service
 %{_libdir}/systemd/system/multi-user.target.wants/service-adaptor.service
 /usr/share/license/%{name}
 
 %files -n service-adaptor-devel
-%defattr(-,system,system,-)
+#%defattr(-,system,system,-)
+%defattr(-,root,root,-)
 %{_libdir}/lib*.so
 %{_libdir}/pkgconfig/service-adaptor.pc
 %{_includedir}/service-adaptor/*.h
 %{_libdir}/lib*.so
 %{_libdir}/pkgconfig/service-adaptor.pc
 %{_includedir}/service-adaptor/*.h
+%{_includedir}/service-provider/*.h
 /usr/share/license/%{name}-devel
 /usr/share/license/%{name}-devel
index 0a6ce71..a8ae0d3 100644 (file)
@@ -19,11 +19,12 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections -fPIE")
 # Define Execute File
 ##########################################################
 
 # Define Execute File
 ##########################################################
 
-SET(MAIN-EXE "service-adaptor")
+SET(MAIN-EXE "service-adaptor-server")
 SET(MAIN-SRCS
         ${CMAKE_SOURCE_DIR}/server/sal_auth.c
         ${CMAKE_SOURCE_DIR}/server/sal_contact.c
         ${CMAKE_SOURCE_DIR}/server/sal_storage.c
 SET(MAIN-SRCS
         ${CMAKE_SOURCE_DIR}/server/sal_auth.c
         ${CMAKE_SOURCE_DIR}/server/sal_contact.c
         ${CMAKE_SOURCE_DIR}/server/sal_storage.c
+        ${CMAKE_SOURCE_DIR}/server/sal_resource.c
         ${CMAKE_SOURCE_DIR}/server/sal_observer.c
         ${CMAKE_SOURCE_DIR}/server/sal_main.c
 )
         ${CMAKE_SOURCE_DIR}/server/sal_observer.c
         ${CMAKE_SOURCE_DIR}/server/sal_main.c
 )
@@ -31,26 +32,28 @@ SET(MAIN-SRCS
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
         ${CMAKE_SOURCE_DIR}/common
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
         ${CMAKE_SOURCE_DIR}/common
-        ${CMAKE_SOURCE_DIR}/common/ipc
+        ${CMAKE_SOURCE_DIR}/common/ipc-server
         ${CMAKE_SOURCE_DIR}/server
         ${CMAKE_SOURCE_DIR}/server
+        ${CMAKE_SOURCE_DIR}/client
         ${CMAKE_SOURCE_DIR}/adaptor/auth-adaptor
         ${CMAKE_SOURCE_DIR}/adaptor/contact-adaptor
         ${CMAKE_SOURCE_DIR}/adaptor/storage-adaptor
         ${CMAKE_SOURCE_DIR}/adaptor/auth-adaptor
         ${CMAKE_SOURCE_DIR}/adaptor/contact-adaptor
         ${CMAKE_SOURCE_DIR}/adaptor/storage-adaptor
+        ${CMAKE_SOURCE_DIR}/adaptor/resource-adaptor
 )
 
 INCLUDE(FindPkgConfig)
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(main_pkgs REQUIRED dlog glib-2.0 capi-base-common capi-appfw-app-manager capi-appfw-package-manager libsmack service-discovery service-federation)
+pkg_check_modules(main_pkgs REQUIRED dlog glib-2.0 capi-base-common capi-appfw-application capi-appfw-app-manager capi-appfw-package-manager libsmack service-discovery service-federation)
 
 FOREACH(flag ${main_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
 
 FOREACH(flag ${main_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=gnu99")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
 ADD_DEFINITIONS("-DSERVICE_ADAPTOR_DEBUGGING")
 ADD_DEFINITIONS("-D_SERVICE_ADAPTOR_IPC_SERVER")
 
 ADD_EXECUTABLE(${MAIN-EXE} ${MAIN-SRCS})
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
 ADD_DEFINITIONS("-DSERVICE_ADAPTOR_DEBUGGING")
 ADD_DEFINITIONS("-D_SERVICE_ADAPTOR_IPC_SERVER")
 
 ADD_EXECUTABLE(${MAIN-EXE} ${MAIN-SRCS})
-TARGET_LINK_LIBRARIES(${MAIN-EXE} ${main_pkgs_LDFLAGS} sal-common auth-adaptor contact-adaptor storage-adaptor)
+TARGET_LINK_LIBRARIES(${MAIN-EXE} ${main_pkgs_LDFLAGS} sal-common-server auth-adaptor contact-adaptor storage-adaptor resource-adaptor)
 INSTALL(TARGETS ${MAIN-EXE} DESTINATION bin)
 INSTALL(TARGETS ${MAIN-EXE} DESTINATION bin)
index 4d2a66e..3581e9e 100644 (file)
 #ifndef __TIZEN_CONVERGENCE_SAL_H__
 #define __TIZEN_CONVERGENCE_SAL_H__
 
 #ifndef __TIZEN_CONVERGENCE_SAL_H__
 #define __TIZEN_CONVERGENCE_SAL_H__
 
+#include <glib.h>
+
 #include "service_adaptor_errors.h"
 #include "service_adaptor_errors.h"
-#include "service_adaptor_types.h"
-#include "service_adaptor_internal.h"
 
 
-service_adaptor_h sal_get_handle();
+#include "auth_adaptor.h"
+#include "contact_adaptor.h"
+#include "storage_adaptor.h"
+#include "resource_adaptor.h"
+
+typedef struct _sal_s
+{
+       GList *svc_list;
+
+       auth_adaptor_h                  auth;
+       contact_adaptor_h               contact;
+       storage_adaptor_h               storage;
+       resource_adaptor_h              resource;
+
+       auth_adaptor_listener_h         auth_listener;
+       contact_adaptor_listener_h      contact_listener;
+       storage_adaptor_listener_h      storage_listener;
+       resource_adaptor_listener_h     resource_listener;
+
+       GMutex mutex;
+       GCond cond;
+       int start;
+} sal_s;
+typedef struct _sal_s *sal_h;
+
+typedef struct _provider_user_data_s
+{
+       char *uri;
+       char *name;
+       char *package;
+} provider_user_data_s;
+typedef struct _provider_user_data_s *provider_user_data_h;
+
+sal_h sal_get_handle();
 char *sal_get_root_path();
 char *sal_get_root_path();
-service_adaptor_error_e sal_connect(service_adaptor_h sal);
-service_adaptor_error_e sal_disconnect(service_adaptor_h sal);
+service_adaptor_error_e sal_adaptor_connect(const char *uri);
+service_adaptor_error_e sal_adaptor_disconnect(const char *uri);
+service_adaptor_error_e sal_adaptor_get_plugins(char ***plugins, int *plugins_size);
+service_adaptor_error_e sal_provider_connect(const char *uri, const char *name, const char *package);
+service_adaptor_error_e sal_provider_disconnect(const char *uri);
+char *sal_provider_get_uri(const char *package);
 
 #endif /* __TIZEN_CONVERGENCE_SAL_H__ */
 
 #endif /* __TIZEN_CONVERGENCE_SAL_H__ */
index 4cb12ac..4af6d1a 100644 (file)
 //******************************************************************************
 //* Private interface definition
 //******************************************************************************
 //******************************************************************************
 //* Private interface definition
 //******************************************************************************
+void _sal_auth_login_cb(const char *uri, void *user_data)
+{
+}
 
 //******************************************************************************
 //* Public interface definition
 //******************************************************************************
 
 
 //******************************************************************************
 //* Public interface definition
 //******************************************************************************
 
-auth_adaptor_h sal_auth_create_handle()
-{
-       auth_adaptor_h auth_adaptor = auth_adaptor_create();
-
-       return auth_adaptor;
-}
-
 auth_adaptor_listener_h sal_auth_register_listener(auth_adaptor_h auth)
 {
 auth_adaptor_listener_h sal_auth_register_listener(auth_adaptor_h auth)
 {
-       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+       SAL_FN_CALL;
 
        auth_adaptor_listener_h listener =
                        (auth_adaptor_listener_h) g_malloc0(sizeof(auth_adaptor_listener_s));
 
 
        auth_adaptor_listener_h listener =
                        (auth_adaptor_listener_h) g_malloc0(sizeof(auth_adaptor_listener_s));
 
-       ret = auth_adaptor_register_listener(auth, listener);
+       listener->login_cb = _sal_auth_login_cb;
+
+       int ret = auth_adaptor_register_listener(auth, listener);
 
        if (SERVICE_ADAPTOR_ERROR_NONE != ret)
        {
 
        if (SERVICE_ADAPTOR_ERROR_NONE != ret)
        {
index c2b61b1..4a37fd3 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "auth_adaptor.h"
 
 
 #include "auth_adaptor.h"
 
-auth_adaptor_h sal_auth_create_handle();
 auth_adaptor_listener_h sal_auth_register_listener(auth_adaptor_h auth);
 
 #endif /* __TIZEN_CONVERGENCE_SAL_AUTH_H__ */
 auth_adaptor_listener_h sal_auth_register_listener(auth_adaptor_h auth);
 
 #endif /* __TIZEN_CONVERGENCE_SAL_AUTH_H__ */
index 570c4e1..b8246cd 100644 (file)
 //* Public interface definition
 //******************************************************************************
 
 //* Public interface definition
 //******************************************************************************
 
-contact_adaptor_h sal_contact_create_handle()
-{
-       contact_adaptor_h contact_adaptor = contact_adaptor_create();
-
-       return contact_adaptor;
-}
-
 contact_adaptor_listener_h sal_contact_register_listener(contact_adaptor_h contact)
 {
        int ret = SERVICE_ADAPTOR_ERROR_NONE;
 contact_adaptor_listener_h sal_contact_register_listener(contact_adaptor_h contact)
 {
        int ret = SERVICE_ADAPTOR_ERROR_NONE;
index e7b5a06..7092783 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "contact_adaptor.h"
 
 
 #include "contact_adaptor.h"
 
-contact_adaptor_h sal_contact_create_handle();
 contact_adaptor_listener_h sal_contact_register_listener(contact_adaptor_h contact);
 
 #endif /* __TIZEN_CONVERGENCE_SAL_CONTACT_H__ */
 contact_adaptor_listener_h sal_contact_register_listener(contact_adaptor_h contact);
 
 #endif /* __TIZEN_CONVERGENCE_SAL_CONTACT_H__ */
index 7ef46c9..c75ddbf 100644 (file)
 #include <glib-object.h>
 #include <glib-unix.h>
 
 #include <glib-object.h>
 #include <glib-unix.h>
 
-#include "service_adaptor.h"
-#include "service_discovery.h"
-#include "service_federation.h"
+#include <app.h>
+
+#include "service_adaptor_internal.h"
+
 #include "sal.h"
 #include "sal.h"
-#include "sal_ipc.h"
 #include "sal_auth.h"
 #include "sal_contact.h"
 #include "sal_storage.h"
 #include "sal_auth.h"
 #include "sal_contact.h"
 #include "sal_storage.h"
+#include "sal_resource.h"
 #include "sal_observer.h"
 #include "sal_observer.h"
+#include "sal_ipc_server.h"
+#include "sal_service_provider.h"
+
+#include "service_discovery.h"
+#include "service_federation.h"
 
 //******************************************************************************
 //* Global variables and defines
 //******************************************************************************
 
 //******************************************************************************
 //* Global variables and defines
 //******************************************************************************
-#define SAL_PLUGIN_METADATA_KEY_ADAPTOR        "service-adaptor"
+#define FILE_PATH_LEN  256
 
 
-static service_adaptor_h g_service_adaptor = NULL;
+static sal_h g_service_adaptor = NULL;
 
 //******************************************************************************
 //* Private interface
 
 //******************************************************************************
 //* Private interface
@@ -47,11 +53,100 @@ static service_adaptor_h g_service_adaptor = NULL;
 //******************************************************************************
 
 /**
 //******************************************************************************
 
 /**
+ * @brief callback of app control
+ *
+ * @return      void.
+ */
+static bool _app_control_extra_data_cb(app_control_h app_control, const char *key, void *user_data)
+{
+       char *value = NULL;
+
+       app_control_get_extra_data(app_control, key, &value);
+       SAL_INFO("PLUGIN Key (%s): %s", key, value);
+
+       g_hash_table_insert((GHashTable *) user_data, (char *) key, value);
+
+       return true;
+}
+
+/**
+ * @brief callback of plugin connection
+ *
+ * @return      void.
+ */
+static void _provider_connect_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RET_IF(APP_CONTROL_RESULT_FAILED == result);
+
+       sal_h sal = sal_get_handle();
+       RETM_IF(NULL == sal, "sal_get_handle() Fail");
+
+       GHashTable *service = g_hash_table_new(g_str_hash, g_str_equal);
+       app_control_foreach_extra_data(reply, _app_control_extra_data_cb, (void *) service);
+
+       provider_user_data_h provider_user_data = (provider_user_data_h) user_data;
+
+       GHashTableIter iter;
+       gpointer iter_key, iter_value;
+
+       g_hash_table_iter_init(&iter, service);
+       while (g_hash_table_iter_next(&iter, &iter_key, &iter_value))
+       {
+               if (0 == strcmp(iter_key, PLUGIN_KEY_AUTH))
+               {
+                       auth_plugin_h plugin = NULL;
+                       auth_adaptor_create_plugin(provider_user_data->uri, provider_user_data->name, provider_user_data->package, &plugin);
+                       auth_adaptor_register_plugin_service(plugin, service);
+                       auth_adaptor_add_plugin(sal->auth, plugin);
+               }
+               else if (0 == strcmp(iter_key, PLUGIN_KEY_STORAGE))
+               {
+                       storage_plugin_h plugin = NULL;
+                       storage_adaptor_create_plugin(provider_user_data->uri, provider_user_data->name, provider_user_data->package, &plugin);
+                       storage_adaptor_register_plugin_service(plugin, service);
+                       storage_adaptor_add_plugin(sal->storage, plugin);
+               }
+       }
+
+       g_hash_table_destroy(service);
+
+       SAL_FN_END;
+}
+
+/**
+ * @brief callback of plugin disconnection
+ *
+ * @return      void.
+ */
+static void _provider_disconnect_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+       SAL_FN_CALL;
+
+       RET_IF(APP_CONTROL_RESULT_FAILED == result);
+
+       sal_h sal = sal_get_handle();
+       RETM_IF(NULL == sal, "sal_get_handle() Fail");
+
+       char *uri = (char *) user_data;
+
+       auth_plugin_h plugin = auth_adaptor_get_plugin(sal->auth, uri);
+       auth_adaptor_remove_plugin(sal->auth, plugin);
+       auth_adaptor_unregister_plugin_service(plugin);
+       auth_adaptor_destroy_plugin(plugin);
+
+       // TODO: destroy plugin of other adaptor
+
+       SAL_FN_END;
+}
+
+/**
  * @brief create spec file
  *
  * @return      void.
  */
  * @brief create spec file
  *
  * @return      void.
  */
-static service_adaptor_error_e _sal_create_spec_file(service_adaptor_h sal)
+static service_adaptor_error_e _sal_create_spec_file(sal_h sal)
 {
        SAL_FN_CALL;
 
 {
        SAL_FN_CALL;
 
@@ -66,7 +161,7 @@ static service_adaptor_error_e _sal_create_spec_file(service_adaptor_h sal)
  *
  * @return      void.
  */
  *
  * @return      void.
  */
-static service_adaptor_error_e _sal_destroy_spec_file(service_adaptor_h sal)
+static service_adaptor_error_e _sal_destroy_spec_file(sal_h sal)
 {
        SAL_FN_CALL;
 
 {
        SAL_FN_CALL;
 
@@ -81,7 +176,7 @@ static service_adaptor_error_e _sal_destroy_spec_file(service_adaptor_h sal)
  *
  * @return      void.
  */
  *
  * @return      void.
  */
-static service_adaptor_error_e _sal_start(service_adaptor_h sal)
+static service_adaptor_error_e _sal_start(sal_h sal)
 {
        SAL_FN_CALL;
 
 {
        SAL_FN_CALL;
 
@@ -97,6 +192,12 @@ static service_adaptor_error_e _sal_start(service_adaptor_h sal)
        ret = storage_adaptor_start(sal->storage);
        RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "storage_adaptor_start() Fail(%d)", ret);
 
        ret = storage_adaptor_start(sal->storage);
        RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "storage_adaptor_start() Fail(%d)", ret);
 
+       ret = resource_adaptor_start(sal->resource);
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "resource_adaptor_start() Fail(%d)", ret);
+
+       ret = sal_observer_register_existed_plugin();
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "sal_observer_register_existed_plugin() Fail(%d)", ret);
+
        g_mutex_lock(&sal->mutex);
        sal->start = sal->start + 1;
        g_cond_signal(&sal->cond);
        g_mutex_lock(&sal->mutex);
        sal->start = sal->start + 1;
        g_cond_signal(&sal->cond);
@@ -110,7 +211,7 @@ static service_adaptor_error_e _sal_start(service_adaptor_h sal)
  *
  * @return      void.
  */
  *
  * @return      void.
  */
-static service_adaptor_error_e _sal_stop(service_adaptor_h sal)
+static service_adaptor_error_e _sal_stop(sal_h sal)
 {
        SAL_FN_CALL;
 
 {
        SAL_FN_CALL;
 
@@ -121,6 +222,7 @@ static service_adaptor_error_e _sal_stop(service_adaptor_h sal)
        ret += auth_adaptor_stop(sal->auth);
        ret += contact_adaptor_stop(sal->contact);
        ret += storage_adaptor_stop(sal->storage);
        ret += auth_adaptor_stop(sal->auth);
        ret += contact_adaptor_stop(sal->contact);
        ret += storage_adaptor_stop(sal->storage);
+       ret += resource_adaptor_stop(sal->resource);
        RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "could not stop service adaptor(%d)", ret);
 
        sal->start = 0;
        RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "could not stop service adaptor(%d)", ret);
 
        sal->start = 0;
@@ -133,49 +235,58 @@ static service_adaptor_error_e _sal_stop(service_adaptor_h sal)
  *
  * @return      void.
  */
  *
  * @return      void.
  */
-static service_adaptor_h _sal_create()
+static sal_h _sal_create()
 {
        SAL_FN_CALL;
 
 {
        SAL_FN_CALL;
 
-       service_adaptor_h sal = NULL;
+       sal_h sal = NULL;
 
        // 1) create auth adaptor handle
 
        // 1) create auth adaptor handle
-       auth_adaptor_h auth = sal_auth_create_handle();
+       auth_adaptor_h auth = auth_adaptor_create();
        TRYM_IF(NULL == auth, "sal_auth_create_handle() Fail");
 
        // 2) create contact adaptor handle
        TRYM_IF(NULL == auth, "sal_auth_create_handle() Fail");
 
        // 2) create contact adaptor handle
-       contact_adaptor_h contact = sal_contact_create_handle();
+       contact_adaptor_h contact = contact_adaptor_create();
        TRYM_IF(NULL == contact, "sal_contact_create_handle() Fail");
 
        // 3) create storage adaptor handle
        TRYM_IF(NULL == contact, "sal_contact_create_handle() Fail");
 
        // 3) create storage adaptor handle
-       storage_adaptor_h storage = sal_storage_create_handle();
+       storage_adaptor_h storage = storage_adaptor_create();
        TRYM_IF(NULL == storage, "sal_storage_create_handle() Fail");
 
        TRYM_IF(NULL == storage, "sal_storage_create_handle() Fail");
 
-       // 4) register auth adaptor listener
+       // 4) create resource adaptor handle
+       resource_adaptor_h resource = resource_adaptor_create();
+       TRYM_IF(NULL == resource, "sal_resource_create_handle() Fail");
+
+       // 5) register auth adaptor listener
        auth_adaptor_listener_h auth_listener = sal_auth_register_listener(auth);
        TRYM_IF(NULL == auth_listener, "sal_auth_register_listener() Fail");
 
        auth_adaptor_listener_h auth_listener = sal_auth_register_listener(auth);
        TRYM_IF(NULL == auth_listener, "sal_auth_register_listener() Fail");
 
-       // 5) register contact adaptor listener
+       // 6) register contact adaptor listener
        contact_adaptor_listener_h contact_listener = sal_contact_register_listener(contact);
        TRYM_IF(NULL == contact_listener, "sal_contact_register_listener() Fail");
 
        contact_adaptor_listener_h contact_listener = sal_contact_register_listener(contact);
        TRYM_IF(NULL == contact_listener, "sal_contact_register_listener() Fail");
 
-       // 6) register storage adaptor listener
+       // 7) register storage adaptor listener
        storage_adaptor_listener_h storage_listener = sal_storage_register_listener(storage);
        TRYM_IF(NULL == storage_listener, "sal_storage_register_listener() Fail");
 
        storage_adaptor_listener_h storage_listener = sal_storage_register_listener(storage);
        TRYM_IF(NULL == storage_listener, "sal_storage_register_listener() Fail");
 
-       // 7) create service adaptor
-       sal = (service_adaptor_h) g_malloc0(sizeof(service_adaptor_s));
+       // 8) register resource adaptor listener
+       resource_adaptor_listener_h resource_listener = sal_resource_register_listener(resource);
+       TRYM_IF(NULL == resource_listener, "sal_resource_register_listener() Fail");
+
+       // 9) create service adaptor
+       sal = (sal_h) g_malloc0(sizeof(sal_s));
        TRYM_IF(NULL == sal, "could not create service adaptor");
 
        sal->auth = auth;
        sal->contact = contact;
        sal->storage = storage;
        TRYM_IF(NULL == sal, "could not create service adaptor");
 
        sal->auth = auth;
        sal->contact = contact;
        sal->storage = storage;
+       sal->resource = resource;
 
        g_mutex_init(&sal->mutex);
        g_cond_init(&sal->cond);
 
 catch:
 
        g_mutex_init(&sal->mutex);
        g_cond_init(&sal->cond);
 
 catch:
-       // free
+       // TODO: free
 
        return sal;
 }
 
        return sal;
 }
@@ -185,7 +296,7 @@ catch:
  *
  * @return      void.
  */
  *
  * @return      void.
  */
-static void _sal_destroy(service_adaptor_h sal)
+static void _sal_destroy(sal_h sal)
 {
        SAL_FN_CALL;
 
 {
        SAL_FN_CALL;
 
@@ -215,7 +326,7 @@ static service_adaptor_error_e _sal_init()
        int ret = SERVICE_ADAPTOR_ERROR_NONE;
 
        // 1) create adaptor (memory allocation)
        int ret = SERVICE_ADAPTOR_ERROR_NONE;
 
        // 1) create adaptor (memory allocation)
-       service_adaptor_h sal = _sal_create();
+       sal_h sal = _sal_create();
        RETVM_IF(NULL == sal, SERVICE_ADAPTOR_ERROR_INTERNAL, "_sal_create() Fail");
 
        // 2) start adaptor (plugin loading)
        RETVM_IF(NULL == sal, SERVICE_ADAPTOR_ERROR_INTERNAL, "_sal_create() Fail");
 
        // 2) start adaptor (plugin loading)
@@ -226,9 +337,9 @@ static service_adaptor_error_e _sal_init()
        ret = _sal_create_spec_file(sal);
        RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "_sal_create_spec_file() Fail(%d)", ret);
 
        ret = _sal_create_spec_file(sal);
        RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_INTERNAL, "_sal_create_spec_file() Fail(%d)", ret);
 
-       // 4) init dbus
-       ret = sal_ipc_init_server();
-       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_IPC_UNSTABLE, "sal_ipc_init_server() Fail(%d)", ret);
+       // 4) init dbus server
+       ret = sal_ipc_server_init();
+       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_IPC_UNSTABLE, "sal_ipc_server_init() Fail(%d)", ret);
 
        // 5) assign to global service adaptor handle
        g_service_adaptor = sal;
 
        // 5) assign to global service adaptor handle
        g_service_adaptor = sal;
@@ -254,13 +365,13 @@ static service_adaptor_error_e _sal_init()
  * @param[in]   service_adaptor         specifies handle of service adaptor
  * @return      void.
  */
  * @param[in]   service_adaptor         specifies handle of service adaptor
  * @return      void.
  */
-static void _sal_deinit(service_adaptor_h sal)
+static void _sal_deinit(sal_h sal)
 {
        SAL_FN_CALL;
 
        RET_IF(NULL == sal);
 
 {
        SAL_FN_CALL;
 
        RET_IF(NULL == sal);
 
-       sal_ipc_deinit_server();
+       sal_ipc_server_deinit();
 
        _sal_destroy_spec_file(sal);
 
 
        _sal_destroy_spec_file(sal);
 
@@ -324,7 +435,7 @@ int main(int argc, char *argv[])
        // cleanup after mainloop
        g_main_loop_unref(loop);
 
        // cleanup after mainloop
        g_main_loop_unref(loop);
 
-       service_adaptor_h sal = sal_get_handle();
+       sal_h sal = sal_get_handle();
        _sal_deinit(sal);
 
        return 0;
        _sal_deinit(sal);
 
        return 0;
@@ -334,14 +445,14 @@ int main(int argc, char *argv[])
 //* Public interface definition
 //******************************************************************************
 
 //* Public interface definition
 //******************************************************************************
 
-service_adaptor_h sal_get_handle()
+API sal_h sal_get_handle()
 {
        SAL_FN_CALL;
 
         return g_service_adaptor;
 }
 
 {
        SAL_FN_CALL;
 
         return g_service_adaptor;
 }
 
-char *sal_get_root_path()
+API char *sal_get_root_path()
 {
        SAL_FN_CALL;
 
 {
        SAL_FN_CALL;
 
@@ -355,20 +466,111 @@ char *sal_get_root_path()
         return root_path;
 }
 
         return root_path;
 }
 
-service_adaptor_error_e sal_connect(service_adaptor_h sal)
+API service_adaptor_error_e sal_adaptor_connect(const char *uri)
 {
        SAL_FN_CALL;
 
 {
        SAL_FN_CALL;
 
-       RETV_IF(NULL == sal, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       SAL_INFO("uri: %s", uri);
 
         return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
 
         return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
-service_adaptor_error_e sal_disconnect(service_adaptor_h sal)
+API service_adaptor_error_e sal_adaptor_disconnect(const char *uri)
 {
        SAL_FN_CALL;
 
 {
        SAL_FN_CALL;
 
-       RETV_IF(NULL == sal, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       SAL_INFO("uri: %s", uri);
 
         return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
         return SERVICE_ADAPTOR_ERROR_NONE;
 }
+
+API service_adaptor_error_e sal_adaptor_get_plugins(char ***plugins, int *plugins_size)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == g_service_adaptor, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == g_service_adaptor->auth, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       int size = g_list_length(g_service_adaptor->auth->plugins);
+       RETV_IF(0 == size, SERVICE_ADAPTOR_ERROR_NO_DATA);
+
+       int i = 0;
+       char **uri = (char **) g_malloc0(sizeof(char *) * size);
+
+       for (GList *list = g_list_first(g_service_adaptor->auth->plugins); list != NULL; list = list->next)
+       {
+               auth_plugin_h this = (auth_plugin_h) list->data;
+
+               uri[i] = strdup(this->uri);
+       }
+
+       *plugins = uri;
+       *plugins_size = size;
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e sal_provider_connect(const char *uri, const char *name, const char *package)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       app_control_h request;
+       app_control_create(&request);
+
+       app_control_set_app_id(request, uri);
+       app_control_set_operation(request, PLUGIN_CONNECT_URI);
+
+       provider_user_data_h provider_user_data = (provider_user_data_h) g_malloc0(sizeof(provider_user_data_s));
+       provider_user_data->uri = strdup(uri);
+       provider_user_data->name = strdup(name);
+       provider_user_data->package = strdup(package);
+
+       int ret = app_control_send_launch_request(request, _provider_connect_cb, provider_user_data);
+
+       RETVM_IF(APP_CONTROL_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_SYSTEM, "app_control_send_launch_request() Fail(%d)", ret);
+
+       app_control_destroy(request);
+
+        return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API service_adaptor_error_e sal_provider_disconnect(const char *uri)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == uri, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
+
+       app_control_h request;
+       app_control_create(&request);
+
+       app_control_set_app_id(request, uri);
+       app_control_set_operation(request, PLUGIN_DISCONNECT_URI);
+
+       int ret = app_control_send_launch_request(request, _provider_disconnect_cb, (void *) uri);
+
+       RETVM_IF(APP_CONTROL_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_SYSTEM, "app_control_send_launch_request() Fail(%d)", ret);
+
+       app_control_destroy(request);
+
+        return SERVICE_ADAPTOR_ERROR_NONE;
+}
+
+API char *sal_provider_get_uri(const char *package)
+{
+       SAL_FN_CALL;
+
+       RETV_IF(NULL == package, NULL);
+
+       sal_h sal = sal_get_handle();
+       RETVM_IF(NULL == sal, NULL, "sal_get_handle() Fail");
+
+       char *uri = auth_adaptor_get_uri(sal->auth, package);
+
+        return uri;
+}
index b012215..b2285b3 100644 (file)
  */
 
 #include <stdio.h>
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <glib.h>
 
 #include <tizen.h>
 #include <glib.h>
 
 #include <tizen.h>
+#include <app.h>
 #include <app_info.h>
 #include <package_manager.h>
 
 #include <app_info.h>
 #include <package_manager.h>
 
+#include "service_adaptor_internal.h"
+
 #include "sal.h"
 #include "sal_observer.h"
 #include "sal.h"
 #include "sal_observer.h"
+#include "auth_adaptor.h"
 
 //******************************************************************************
 //* Global variables and defines
 
 //******************************************************************************
 //* Global variables and defines
  */
 static bool _sal_app_meta_cb(const char *key, const char *value, void *user_data)
 {
  */
 static bool _sal_app_meta_cb(const char *key, const char *value, void *user_data)
 {
-       SAL_FN_CALL;
-
-       char **app_meta = (char **) user_data;
+       provider_user_data_h provider_user_data = (provider_user_data_h) user_data;
 
        if ((NULL != key) && (NULL != value))
        {
                if (0 == strncmp(SAL_PLUGIN_METADATA_KEY_ADAPTOR, key, strlen(SAL_PLUGIN_METADATA_KEY_ADAPTOR)))
                {
 
        if ((NULL != key) && (NULL != value))
        {
                if (0 == strncmp(SAL_PLUGIN_METADATA_KEY_ADAPTOR, key, strlen(SAL_PLUGIN_METADATA_KEY_ADAPTOR)))
                {
-                       app_meta[0] = strdup(value);
-                       SAL_INFO("SAL_PLUGIN_METADATA_KEY_ADAPTOR: %s", value);
+                       SAL_INFO("%s: %s", provider_user_data->uri, value);
+                       int ret = sal_provider_connect(provider_user_data->uri, value, provider_user_data->package);
+
+                       RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, false, "sal_plugin_connect() Fail(%d)", ret);
                }
        }
 
                }
        }
 
@@ -70,25 +75,20 @@ static bool _sal_app_meta_cb(const char *key, const char *value, void *user_data
  */
 static bool _sal_app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data)
 {
  */
 static bool _sal_app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data)
 {
-       SAL_FN_CALL;
-
        app_info_h app_info = NULL;
        int ret = PACKAGE_MANAGER_ERROR_NONE;
        app_info_h app_info = NULL;
        int ret = PACKAGE_MANAGER_ERROR_NONE;
-       char *pkg_path = (char *) user_data;
-       char **app_meta = (char **) g_malloc0(sizeof(char *) * 1);
+       char *package = (char *) user_data;
 
 
-       (void) pkg_path;
+       provider_user_data_h provider_user_data = (provider_user_data_h) g_malloc0(sizeof(provider_user_data_s));
+       provider_user_data->uri = strdup(app_id);
+       provider_user_data->package = strdup(package);
 
        app_info_create(app_id, &app_info);
 
        app_info_create(app_id, &app_info);
-       ret = app_info_foreach_metadata(app_info, _sal_app_meta_cb, (void *) app_meta);
+       ret = app_info_foreach_metadata(app_info, _sal_app_meta_cb, provider_user_data);
        RETVM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, false, "app_info_foreach_metadata() Fail(%d)", ret);
 
        app_info_destroy(app_info);
 
        RETVM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, false, "app_info_foreach_metadata() Fail(%d)", ret);
 
        app_info_destroy(app_info);
 
-       // TODO: using app_meta
-
-       SAL_FREE(app_meta);
-
        return true;
 }
 
        return true;
 }
 
@@ -105,31 +105,58 @@ static void _sal_package_event_cb(const char *type,
                 package_manager_error_e error,
                 void *user_data)
 {
                 package_manager_error_e error,
                 void *user_data)
 {
-        SAL_FN_CALL;
+        if ((PACKAGE_MANAGER_EVENT_TYPE_INSTALL == event_type) && (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state))
+        {
+               int ret = PACKAGE_MANAGER_ERROR_NONE;
+               package_info_h p_info = NULL;
+
+               ret = package_manager_get_package_info(package, &p_info);
+               RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_manager_get_package_info() Fail(%d)", ret);
 
 
-        if ((PACKAGE_MANAGER_EVENT_TYPE_INSTALL == event_type)
-                        && (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state))
+               ret = package_info_foreach_app_from_package(p_info, PACKAGE_INFO_ALLAPP, _sal_app_info_cb, (void *) package);
+               RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_info_foreach_app_from_package() Fail(%d)", ret);
+
+               ret = package_info_destroy(p_info);
+               RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_info_destroy() Fail(%d)", ret);
+       }
+        else if ((PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL == event_type) && (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state))
         {
         {
-                int ret = PACKAGE_MANAGER_ERROR_NONE;
-                package_info_h p_info = NULL;
+               sal_h sal = sal_get_handle();
+               RETM_IF(NULL == sal, "sal_get_handle() Fail");
+
+               char *uri = sal_provider_get_uri(package);
+
+               auth_plugin_h auth_plugin = auth_adaptor_get_plugin(sal->auth, uri);
+               auth_adaptor_remove_plugin(sal->auth, auth_plugin);
+               auth_adaptor_unregister_plugin_service(auth_plugin);
+               auth_adaptor_destroy_plugin(auth_plugin);
 
 
-                ret = package_manager_get_package_info(package, &p_info);
-                RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_manager_get_package_info() Fail(%d)", ret);
+               storage_plugin_h storage_plugin = storage_adaptor_get_plugin(sal->storage, uri);
+               storage_adaptor_remove_plugin(sal->storage, storage_plugin);
+               storage_adaptor_unregister_plugin_service(storage_plugin);
+               storage_adaptor_destroy_plugin(storage_plugin);
 
 
-                char *path = NULL;
-                ret = package_info_get_root_path(p_info, &path);
-                RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_info_get_root_path() Fail(%d)", ret);
+               // TODO: destroy plugin of other adaptor
+       }
+}
 
 
-                ret = package_info_foreach_app_from_package(p_info, PACKAGE_INFO_ALLAPP, _sal_app_info_cb, path);
-                RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_info_foreach_app_from_package() Fail(%d)", ret);
+/**
+ * @brief callback of package_manager_foreach_package_info()
+ *
+ * @return      void.
+ */
+static bool _sal_package_info_cb(package_info_h package_info, void *user_data)
+{
+       int ret = PACKAGE_MANAGER_ERROR_NONE;
 
 
-                ret = package_info_destroy(p_info);
-                RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_info_destroy() Fail(%d)", ret);
+       char *package = NULL;
+       ret = package_info_get_package(package_info, &package);
+       RETVM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, false, "package_info_get_package() Fail(%d)", ret);
 
 
-                SAL_FREE(path);
-        }
+       ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP, _sal_app_info_cb, package);
+       RETVM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, false, "package_info_foreach_app_from_package() Fail(%d)", ret);
 
 
-        SAL_FN_END;
+       return true;
 }
 
 //******************************************************************************
 }
 
 //******************************************************************************
@@ -153,3 +180,18 @@ service_adaptor_error_e sal_observer_start()
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
 
        return SERVICE_ADAPTOR_ERROR_NONE;
 }
+
+/**
+ * @brief register existing plugin using package manager
+ *
+ * @return      void.
+ */
+service_adaptor_error_e sal_observer_register_existed_plugin()
+{
+       int ret = PACKAGE_MANAGER_ERROR_NONE;
+
+       ret = package_manager_foreach_package_info(_sal_package_info_cb, NULL);
+       RETVM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_SYSTEM, "package_manager_foreach_package_info() Fail(%d)", ret);
+
+       return SERVICE_ADAPTOR_ERROR_NONE;
+}
index 1f87a3e..01c962e 100644 (file)
@@ -27,5 +27,6 @@
 #include "service_adaptor_errors.h"
 
 service_adaptor_error_e sal_observer_start();
 #include "service_adaptor_errors.h"
 
 service_adaptor_error_e sal_observer_start();
+service_adaptor_error_e sal_observer_register_existed_plugin();
 
 #endif /* __TIZEN_CONVERGENCE_SAL_OBSERVER_H__ */
 
 #endif /* __TIZEN_CONVERGENCE_SAL_OBSERVER_H__ */
diff --git a/server/sal_resource.c b/server/sal_resource.c
new file mode 100644 (file)
index 0000000..c465e0c
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Service Adaptor
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+
+#include "sal_resource.h"
+#include "service_adaptor_internal.h"
+
+//******************************************************************************
+//* Global variables and defines
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface
+//******************************************************************************
+
+//******************************************************************************
+//* Private interface definition
+//******************************************************************************
+
+//******************************************************************************
+//* Public interface definition
+//******************************************************************************
+
+resource_adaptor_listener_h sal_resource_register_listener(resource_adaptor_h resource)
+{
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       resource_adaptor_listener_h listener =
+                       (resource_adaptor_listener_h) g_malloc0(sizeof(resource_adaptor_listener_s));
+
+       ret = resource_adaptor_register_listener(resource, listener);
+
+       if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+       {
+               SAL_FREE(listener);
+       }
+
+       return listener;
+}
diff --git a/server/sal_resource.h b/server/sal_resource.h
new file mode 100644 (file)
index 0000000..e79c2f7
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Service Adaptor
+ *
+ * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yongjin Kim <youth.kim@samsung.com>
+ *          Jinhyeong Ahn <jinh.ahn@samsung.com>
+ *          Jiwon Kim <jiwon177.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_CONVERGENCE_SAL_RESOURCE_H__
+#define __TIZEN_CONVERGENCE_SAL_RESOURCE_H__
+
+#include "resource_adaptor.h"
+
+resource_adaptor_listener_h sal_resource_register_listener(resource_adaptor_h resource);
+
+#endif /* __TIZEN_CONVERGENCE_SAL_RESOURCE_H__ */
index cd7e901..64c0a4e 100644 (file)
 //* Public interface definition
 //******************************************************************************
 
 //* Public interface definition
 //******************************************************************************
 
-storage_adaptor_h sal_storage_create_handle()
-{
-       storage_adaptor_h storage_adaptor = storage_adaptor_create();
-
-       return storage_adaptor;
-}
-
 storage_adaptor_listener_h sal_storage_register_listener(storage_adaptor_h storage)
 {
        int ret = SERVICE_ADAPTOR_ERROR_NONE;
 storage_adaptor_listener_h sal_storage_register_listener(storage_adaptor_h storage)
 {
        int ret = SERVICE_ADAPTOR_ERROR_NONE;
index 9ee3680..b01955e 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "storage_adaptor.h"
 
 
 #include "storage_adaptor.h"
 
-storage_adaptor_h sal_storage_create_handle();
 storage_adaptor_listener_h sal_storage_register_listener(storage_adaptor_h storage);
 
 #endif /* __TIZEN_CONVERGENCE_SAL_STORAGE_H__ */
 storage_adaptor_listener_h sal_storage_register_listener(storage_adaptor_h storage);
 
 #endif /* __TIZEN_CONVERGENCE_SAL_STORAGE_H__ */
index ef546a3..fcb2a80 100644 (file)
@@ -1,9 +1,6 @@
 <manifest>
        <define>
                <domain name="service-adaptor" />
 <manifest>
        <define>
                <domain name="service-adaptor" />
-               <provide>
-                       <label name="service-adaptor::svc"/>
-               </provide>
                <permit>
                        <smack permit="system::use_internet" type="w" />
                </permit>
                <permit>
                        <smack permit="system::use_internet" type="w" />
                </permit>
@@ -22,6 +19,8 @@
                </request>
        </define>
        <assign>
                </request>
        </define>
        <assign>
+               <filesystem path="/usr/lib/systemd/system/service-adaptor.service" label="_"/>
+               <filesystem path="/usr/lib/systemd/system/multi-user.target.wants/service-adaptor.service" label="_"/>
        </assign>
        <request>
                <domain name="service-adaptor" />
        </assign>
        <request>
                <domain name="service-adaptor" />
index 73a9e12..f928be8 100644 (file)
@@ -4,6 +4,9 @@ includedir=${prefix}/include
 
 Name: service-adaptor library
 Description: service-adaptor library 1.0
 
 Name: service-adaptor library
 Description: service-adaptor library 1.0
-Version: $version
-Libs: -L${libdir} -lsal-common -lsal-client
-Cflags: -I${includedir}/service-adaptor
+
+Requires: capi-base-common
+Version: @VERSION@
+
+Libs: -L${libdir} -lsal-common-client -lservice-adaptor -lservice-provider
+Cflags: -I${includedir}/service-adaptor -I${includedir}/service-provider
index 437d198..4141487 100644 (file)
@@ -11,6 +11,8 @@ MESSAGE("")
 MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
 MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
 
 MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
 MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
 
+ADD_DEFINITIONS("-DSERVICE_ADAPTOR_DEBUGGING")
+
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
 
@@ -21,10 +23,11 @@ SET(TEST-SRCS
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
 
 INCLUDE_DIRECTORIES(
         ${CMAKE_SOURCE_DIR}/include
+        ${CMAKE_SOURCE_DIR}/client
 )
 
 INCLUDE(FindPkgConfig)
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0)
+pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0 capi-appfw-application)
 
 FOREACH(flag ${test_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 
 FOREACH(flag ${test_pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -39,5 +42,5 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
 ADD_EXECUTABLE(${TEST-EXE} ${TEST-SRCS})
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
 ADD_EXECUTABLE(${TEST-EXE} ${TEST-SRCS})
-TARGET_LINK_LIBRARIES(${TEST-EXE} ${test_pkgs_LDFLAGS} sal-client)
+TARGET_LINK_LIBRARIES(${TEST-EXE} ${test_pkgs_LDFLAGS} service-adaptor)
 INSTALL(TARGETS ${TEST-EXE} DESTINATION bin)
 INSTALL(TARGETS ${TEST-EXE} DESTINATION bin)
index 7fb1ab9..46d64f5 100644 (file)
@@ -1,6 +1,140 @@
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib-object.h>
+#include <glib-unix.h>
 
 
-int main()
+#include "service_adaptor.h"
+
+service_plugin_h service_plugin = NULL;
+
+void _service_auth_oauth1_cb(int result, service_auth_oauth1_h oauth1, void *user_data)
+{
+       char *access_token = NULL;
+       service_auth_oauth1_get_access_token(oauth1, &access_token);
+
+       printf("access_token = %s (%s)\n", access_token, (char *) user_data);
+}
+
+bool _service_storage_cloud_file_cb(int result, service_storage_cloud_file_h file, void *user_data)
+{
+       char *cloud_path = NULL;
+       service_storage_cloud_file_get_cloud_path(file, &cloud_path);
+
+       printf("cloud_path = %s (%s)\n", cloud_path, (char *) user_data);
+
+       return true;
+}
+
+void _service_plugin_login_callback(int result, void *user_data)
+{
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       ret = service_plugin_start(service_plugin);
+
+       if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+       {
+               printf("service_plugin_start Failed(%d)\n", ret);
+               return;
+       }
+
+       /* operation */
+       service_auth_oauth1_h oauth1 = NULL;
+       ret = service_auth_oauth1_create(service_plugin, &oauth1);
+       ret = service_auth_oauth1_set_callback(oauth1, _service_auth_oauth1_cb, NULL);
+       ret = service_auth_oauth1_set_operation(oauth1, SERVICE_AUTH_OAUTH1_0_GET_ACCESS_TOKEN_URI);
+
+       service_task_h auth_task = NULL;
+       ret = service_auth_oauth1_create_task(oauth1, &auth_task);
+       ret = service_task_start(auth_task);
+       if (SERVICE_ADAPTOR_ERROR_NONE == ret)
+       {
+               printf("service_auth_oauth1_get_access_token() Request Successed\n");
+       }
+
+       char *cloud_path = "/root/cloud";
+       service_storage_cloud_file_h file = NULL;
+       ret = service_storage_cloud_file_create(service_plugin, &file);
+       ret = service_storage_cloud_file_set_callback(file, _service_storage_cloud_file_cb, NULL);
+       ret = service_storage_cloud_file_set_cloud_path(file, cloud_path);
+       ret = service_storage_cloud_file_set_operation(file, SERVICE_STORAGE_CLOUD_REMOVE_FILE_URI);
+
+       service_task_h task = NULL;
+       ret = service_storage_cloud_file_create_task(file, &task);
+       ret = service_task_start(task);
+       if (SERVICE_ADAPTOR_ERROR_NONE == ret)
+       {
+               printf("service_storage_cloud_remove_file() Request Successed: %s\n", cloud_path);
+       }
+}
+
+bool _service_adaptor_plugin_callback(const char *uri, int service_mask, void *user_data)
+{
+       if (0 != strcmp(uri, "org.tizen.service-plugin-sample"))
+       {
+               return true;
+       }
+
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       ret = service_plugin_create(uri, &service_plugin);
+
+       if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+       {
+               printf("service_plugin_create(%s) Failed(%d)\n", uri, ret);
+               return true;
+       }
+
+       ret = service_plugin_login(service_plugin, _service_plugin_login_callback, NULL);
+
+       if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+       {
+               printf("service_plugin_login(%s) Failed(%d)\n", uri, ret);
+               return true;
+       }
+
+       return true;
+}
+
+static gint _sigterm_callback(void *data)
 {
 {
+       g_main_loop_quit((GMainLoop*)data);
+
        return 0;
 }
        return 0;
 }
+
+int main()
+{
+       GMainLoop *loop = NULL;
+
+#if !GLIB_CHECK_VERSION(2,32,0)
+       g_thread_init(NULL);
+#endif
+#if !GLIB_CHECK_VERSION(2,35,0)
+       g_type_init();
+#endif
+
+       /* init */
+       int ret = SERVICE_ADAPTOR_ERROR_NONE;
+
+       ret = service_adaptor_connect();
+       ret = service_adaptor_foreach_plugin(_service_adaptor_plugin_callback, NULL);
+
+       loop = g_main_loop_new(NULL, FALSE);
+
+       g_unix_signal_add_full(G_PRIORITY_HIGH, SIGINT,
+                       _sigterm_callback, loop, NULL );
+       g_unix_signal_add_full(G_PRIORITY_HIGH, SIGTERM,
+                       _sigterm_callback, loop, NULL );
+
+       g_main_loop_run(loop);
+
+       g_main_loop_unref(loop);
+
+       /* deinit */
+       ret = service_plugin_stop(service_plugin);
+       ret = service_plugin_destroy(service_plugin);
+       ret = service_adaptor_disconnect();
+
+       return ret;
+}