Return error when using the apis with emulator 2.0alpha master 2.0_alpha submit/master/20120920.151034
authorTaeyoung Kim <ty317.kim@samsung.com>
Thu, 30 Aug 2012 01:08:59 +0000 (10:08 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Tue, 4 Sep 2012 12:17:48 +0000 (21:17 +0900)
Change-Id: Id6f3b55448546c05b1f223f768ab93e52a06b40a

13 files changed:
include/usb_accessory.h
include/usb_accessory_private.h
src/usb_accessory.c
src/usb_accessory_private.c
test/CMakeLists.txt
test/acc_test.c
test/acc_test.desktop.in [deleted file]
test/acc_test.xml [new file with mode: 0644]
test/debian/acc_test.install
test/debian/changelog
test/debian/control
test/debian/rules
test/packaging/acc_test.spec [moved from test/packaging/acc-test.spec with 89% similarity]

index e69907c..bef34e1 100644 (file)
@@ -38,7 +38,8 @@ typedef enum
     USB_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,
     USB_ERROR_NOT_CONNECTED     = TIZEN_ERROR_ENDPOINT_NOT_CONNECTED,
        USB_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,
-    USB_ERROR_OPERATION_FAILED  = TIZEN_ERROR_SYSTEM_CLASS | 0x62
+    USB_ERROR_OPERATION_FAILED  = TIZEN_ERROR_SYSTEM_CLASS | 0x62,
+       USB_ERROR_NOT_SUPPORTED         = TIZEN_ERROR_NOT_SUPPORT_API
 } usb_error_e;
 
 /**
index 715d6ef..7ce8d12 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__
 #define __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <libintl.h>
 #include <stdbool.h>
@@ -32,7 +33,7 @@
 #include <aul.h>
 #include <vconf.h>
 #include <stdlib.h>
-//#include <Ecore.h>
+#include <sys/utsname.h>
 #include <glib.h>
 
 #define ACC_ELEMENT_LEN 256
@@ -89,15 +90,17 @@ typedef enum {
 } IPC_SIMPLE_RESULT;
 
 typedef enum {
-       LAUNCH_APP = 0,
-       REQUEST_PERMISSION,
-       HAS_PERMISSION,
-       REQ_PERM_NOTI_YES_BTN,
-       REQ_PERM_NOTI_NO_BTN,
-       GET_ACC_INFO,
-       ERROR_POPUP_OK_BTN,
-       KIESWIFI_POPUP_YES_BTN,
-       KIESWIFI_POPUP_NO_BTN
+       /* General */
+       ERROR_POPUP_OK_BTN = 0,
+       IS_EMUL_BIN,
+
+       /* for Accessory */
+       LAUNCH_APP_FOR_ACC = 20,
+       REQ_ACC_PERMISSION,
+       HAS_ACC_PERMISSION,
+       REQ_ACC_PERM_NOTI_YES_BTN,
+       REQ_ACC_PERM_NOTI_NO_BTN,
+       GET_ACC_INFO
 } REQUEST_TO_USB_MANGER;
 
 typedef enum {
@@ -142,5 +145,6 @@ bool freeAccList(struct usb_accessory_list *accList);
 int ipc_noti_client_init(void);
 int ipc_noti_client_close(int *sock_remote);
 gboolean ipc_noti_client_cb(GIOChannel *g_io_ch, GIOCondition condition, gpointer data);
+bool is_emul_bin();
 #endif /* __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__ */
 
index a22ab2e..055a90f 100644 (file)
@@ -23,6 +23,10 @@ int usb_accessory_clone(usb_accessory_h handle, usb_accessory_h* cloned_handle)
 {
        __USB_FUNC_ENTER__ ;
        if (!handle) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        if (!cloned_handle || *cloned_handle) return USB_ERROR_INVALID_PARAMETER;
        *cloned_handle = (usb_accessory_h)malloc(sizeof(struct usb_accessory_s));
        snprintf((*cloned_handle)->manufacturer, strlen(handle->manufacturer), "%s", handle->manufacturer);
@@ -42,6 +46,10 @@ int usb_accessory_destroy(usb_accessory_h handle)
 {
     __USB_FUNC_ENTER__ ;
        if (!handle) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        FREE(handle);
        __USB_FUNC_EXIT__ ;
        return USB_ERROR_NONE;
@@ -50,6 +58,11 @@ int usb_accessory_destroy(usb_accessory_h handle)
 int usb_accessory_foreach_attached(usb_accessory_attached_cb callback, void *user_data)
 {
        __USB_FUNC_ENTER__ ;
+       if (callback == NULL) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        struct usb_accessory_list *accList = NULL;
        struct usb_accessory_list *tmpList = NULL;
        bool ret = false;
@@ -80,6 +93,10 @@ int usb_accessory_foreach_attached(usb_accessory_attached_cb callback, void *use
 int usb_accessory_set_connection_changed_cb(usb_accessory_connection_changed_cb callback, void* user_data)
 {
        __USB_FUNC_ENTER__ ;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        int ret = -1;
        accCbData = (struct AccCbData *)malloc(sizeof(struct AccCbData));
        accCbData->user_data = user_data;
@@ -94,6 +111,10 @@ int usb_accessory_set_connection_changed_cb(usb_accessory_connection_changed_cb
 int usb_accessory_connection_unset_cb()
 {
        __USB_FUNC_ENTER__ ;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        if (accCbData != NULL) {
                FREE(accCbData);
                int ret = vconf_ignore_key_changed(VCONFKEY_USB_ACCESSORY_STATUS, accessory_status_changed_cb);
@@ -109,6 +130,10 @@ int usb_accessory_has_permission(usb_accessory_h accessory, bool* is_granted)
 {
        __USB_FUNC_ENTER__ ;
        if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        if (accessory->accPermission == true) {
                __USB_FUNC_EXIT__ ;
                return USB_ERROR_NONE;
@@ -125,13 +150,13 @@ int usb_accessory_has_permission(usb_accessory_h accessory, bool* is_granted)
                }
 
                ret = ipc_request_client_init(&sock_remote);
-               um_retvm_if(ret < 0, USB_ERROR_PERMISSION_DENIED, "FAIL: ipc_request_client_init(&sock_remote)\n");
+               um_retvm_if(ret < 0, USB_ERROR_PERMISSION_DENIED, "FAIL: ipc_request_client_init()\n");
 
-               ret = request_to_usb_server(sock_remote, HAS_PERMISSION, buf, app_id);
-               um_retvm_if(ret < 0, USB_ERROR_PERMISSION_DENIED, "FAIL: request_to_usb_server(HAS_PERMISSION)\n");
+               ret = request_to_usb_server(sock_remote, HAS_ACC_PERMISSION, buf, app_id);
+               um_retvm_if(ret < 0, USB_ERROR_PERMISSION_DENIED, "FAIL: request_to_usb_server()\n");
 
                ret = ipc_request_client_close(&sock_remote);
-               um_retvm_if(ret < 0, USB_ERROR_PERMISSION_DENIED, "FAIL: ipc_request_client_close(&sock_remote)\n");
+               um_retvm_if(ret < 0, USB_ERROR_PERMISSION_DENIED, "FAIL: ipc_request_client_close()\n");
 
                FREE(app_id);
 
@@ -154,6 +179,10 @@ int usb_accessory_open(usb_accessory_h accessory, FILE **fd)
 {
        __USB_FUNC_ENTER__ ;
        if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        if (accessory->accPermission == true) {
                *fd = fopen(USB_ACCESSORY_NODE, "r+");
                USB_LOG("file pointer: %d", *fd);
@@ -170,6 +199,10 @@ int usb_accessory_get_description(usb_accessory_h accessory, char** description)
 {
        __USB_FUNC_ENTER__ ;
        if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        *description = strdup(accessory->description);
        __USB_FUNC_ENTER__ ;
     return USB_ERROR_NONE;
@@ -180,6 +213,10 @@ int usb_accessory_get_manufacturer(usb_accessory_h accessory, char** manufacture
 {
        __USB_FUNC_ENTER__ ;
        if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        *manufacturer = strdup(accessory->manufacturer);
        __USB_FUNC_ENTER__ ;
     return USB_ERROR_NONE;
@@ -190,6 +227,10 @@ int usb_accessory_get_model(usb_accessory_h accessory, char** model)
 {
        __USB_FUNC_ENTER__ ;
        if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        *model = strdup(accessory->model);
        __USB_FUNC_ENTER__ ;
     return USB_ERROR_NONE;
@@ -200,6 +241,10 @@ int usb_accessory_get_serial(usb_accessory_h accessory, char** serial)
 {
        __USB_FUNC_ENTER__ ;
        if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        *serial = strdup(accessory->serial);
        __USB_FUNC_ENTER__ ;
     return USB_ERROR_NONE;
@@ -210,6 +255,10 @@ int usb_accessory_get_version(usb_accessory_h accessory, char** version)
 {
        __USB_FUNC_ENTER__ ;
        if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        *version = strdup(accessory->version);
        __USB_FUNC_ENTER__ ;
     return USB_ERROR_NONE;
@@ -219,6 +268,10 @@ int usb_accessory_get_version(usb_accessory_h accessory, char** version)
 int usb_accessory_is_connected(usb_accessory_h accessory, bool* is_connected)
 {
        __USB_FUNC_ENTER__ ;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        int ret = -1;
        int val = -1;
        ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &val);
@@ -240,6 +293,10 @@ int usb_accessory_request_permission(usb_accessory_h accessory, usb_accessory_pe
        __USB_FUNC_ENTER__ ;
        if (!accessory) return USB_ERROR_INVALID_PARAMETER;
        if (!callback) return USB_ERROR_INVALID_PARAMETER;
+       if (is_emul_bin()) {
+               USB_LOG("FAIL:USB Accessory is not available with emulator.");
+               return USB_ERROR_NOT_SUPPORTED;
+       }
        int ret = -1;
        guint g_ret = 0;
        int sock_remote;
@@ -270,9 +327,9 @@ int usb_accessory_request_permission(usb_accessory_h accessory, usb_accessory_pe
                return USB_ERROR_PERMISSION_DENIED;
        }
 
-       ret = request_to_usb_server(sock_remote, REQUEST_PERMISSION, buf, app_id);
+       ret = request_to_usb_server(sock_remote, REQ_ACC_PERMISSION, buf, app_id);
        if(ret < 0) {
-               USB_LOG("FAIL: request_to_usb_server(REQUEST_PERMISSION)\n");
+               USB_LOG("FAIL: request_to_usb_server(REQ_ACC_PERMISSION)\n");
                ret = ipc_request_client_close(&sock_remote);
                if (ret < 0) USB_LOG("FAIL: ipc_request_client_close(&sock_remote)\n");
                ret = ipc_noti_client_close(&fd);
index 9e796ef..9308e4c 100644 (file)
@@ -86,11 +86,11 @@ int handle_input_to_server(void *data, char *buf)
        USB_LOG("Input: %d\n", input);
 
        switch (input) {
-       case REQ_PERM_NOTI_YES_BTN:
+       case REQ_ACC_PERM_NOTI_YES_BTN:
                permCbData->accessory->accPermission = true;
                permCbData->request_perm_cb_func((struct usb_accessory_s*)(permCbData->user_data), true);
                break;
-       case REQ_PERM_NOTI_NO_BTN:
+       case REQ_ACC_PERM_NOTI_NO_BTN:
                permCbData->accessory->accPermission = false;
                permCbData->request_perm_cb_func((struct usb_accessory_s*)(permCbData->user_data), false);
                break;
@@ -297,23 +297,23 @@ void accessory_status_changed_cb(keynode_t *in_key, void* data)
        ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &val);
        um_retm_if(ret < 0, "FAIL: vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS)\n");
 
-       ret = getChangedAcc(&changedAcc);
-       um_retm_if(ret < 0, "FAIL: getChangedAcc(&changedAcc)\n");
-
        switch (val) {
        case VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED:
-               conCbData->connection_cb_func(changedAcc, false, conCbData->user_data);
+               conCbData->connection_cb_func(NULL, false, conCbData->user_data);
                break;
        case VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED:
+               ret = getChangedAcc(&changedAcc);
+               um_retm_if(ret < 0, "FAIL: getChangedAcc(&changedAcc)\n");
+
                conCbData->connection_cb_func(changedAcc, true, conCbData->user_data);
+
+               ret = freeChangedAcc(&changedAcc);
+               um_retm_if(ret < 0, "FAIL: freeChangedAcc(&changedAcc)\n");
                break;
        default:
                USB_LOG("ERROR: The value of VCONFKEY_USB_ACCESSORY_STATUS is invalid\n");
                break;
        }
-       ret = freeChangedAcc(&changedAcc);
-       um_retm_if(ret < 0, "FAIL: freeChangedAcc(&changedAcc)\n");
-
        __USB_FUNC_EXIT__ ;
 }
 
@@ -425,3 +425,25 @@ bool freeAccList(struct usb_accessory_list *accList)
        __USB_FUNC_EXIT__ ;
        return true;
 }
+
+bool is_emul_bin()
+{
+       __USB_FUNC_ENTER__ ;
+       int ret = -1;
+       struct utsname name;
+       ret = uname(&name);
+       if (ret < 0) {
+               __USB_FUNC_EXIT__ ;
+               return true;
+       } else {
+               USB_LOG("Machine name: %s", name.machine);
+               if (strcasestr(name.machine, "emul")) {
+                       __USB_FUNC_EXIT__ ;
+                       return true;
+               } else {
+                       __USB_FUNC_EXIT__ ;
+                       return false;
+               }
+       }
+
+}
index 974fa72..7000e30 100644 (file)
@@ -1,7 +1,11 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 PROJECT(acc_test C)
 SET(SRCS acc_test.c)
+INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED eina elementary ecore-x appcore-efl aul capi-system-usb-accessory)
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
 
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g ")
@@ -12,6 +16,5 @@ ADD_EXECUTABLE(acc_test acc_test.c)
 TARGET_LINK_LIBRARIES(acc_test ${pkgs_LDFLAGS} capi-system-usb-accessory)
 INSTALL(TARGETS acc_test DESTINATION /opt/apps/acc_test/bin)
 
-# install desktop file
-CONFIGURE_FILE(acc_test.desktop.in ${CMAKE_CURRENT_SOURCE_DIR}/acc_test.desktop)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/acc_test.desktop DESTINATION /opt/share/applications/)
+# install manifest file
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/acc_test.xml DESTINATION /opt/share/packages/)
index bcd8f5b..8124435 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "usb_accessory.h"
+#include <usb_accessory.h>
 #include <Elementary.h>
 #include <dlog.h>
 
diff --git a/test/acc_test.desktop.in b/test/acc_test.desktop.in
deleted file mode 100644 (file)
index faa25f5..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-Name=Acc_test
-Exec=/opt/apps/acc_test/bin/acc_test
-Type=Application
-Comment=Usb accessory test application
-NoDisplay=true
-X-TIZEN-Removable=true
-X-TIZEN-TaskManage=true
-Version=0.1.0-0
diff --git a/test/acc_test.xml b/test/acc_test.xml
new file mode 100644 (file)
index 0000000..13a046a
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<manifest xmlns="http://tizen.org/ns/packages" package="acc_test" version="0.0.1" install-location="internal-only">
+       <label>acc_test</label>
+       <author email="ty317.kim@samsung.com" href="www.samsung.com">Taeyoung Kim</author>
+       <description>USB accessory test application</description>
+       <ui-application appid="acc_test" exec="/opt/apps/acc_test/bin/acc_test" nodisplay="true" multiple="false" type="capp" taskmanage="false">
+               <label>acc_test</label>
+               <label xml:lang="en-us">acc_test</label>
+       </ui-application>
+</manifest>
index d3f2459..74eb165 100644 (file)
@@ -1,3 +1,3 @@
 /usr/lib/lib*.so*
 /opt/apps/acc_test/bin/acc_test
-/opt/share/applications/acc_test.desktop
+/opt/share/packages/acc_test.xml
index 5a1da74..9cbe29d 100644 (file)
@@ -1,7 +1,7 @@
-acc-test (0.0.1-1) unstable; urgency=low
+acc_test (0.0.1-1) unstable; urgency=low
 
   * Initial release.
   * Git: slp-source.sec.samsung.net:slp/api/usb-accessory
-  * Tag: acc-test_0.0.1-1
+  * Tag: acc_test_0.0.1-1
 
  -- Taeyoung Kim <ty317.kim@samsung.com>  Tue, 05 Jun 2012 00:19:00 +0900
index b44a5c8..6f08b8f 100644 (file)
@@ -5,13 +5,13 @@ Priority: extra
 Maintainer: Taeyoung Kim <ty317.kim@samsung.com> Taesoo Jun <steve.jun@samsung.com>
 Build-Depends: debhelper (>= 5), dlog-dev, libglib2.0-dev, capi-system-usb-accessory-dev, libelm-dev, libappcore-efl-dev, libecore-dev, libevas-dev
 
-Package: acc-test
+Package: acc_test
 Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends}
 Description: A test package for usb accessory 
 
-Package: acc-test-dbg
+Package: acc_test-dbg
 Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}, acc-test (= ${Source-Version})
+Depends: ${shlibs:Depends}, ${misc:Depends}, acc_test (= ${Source-Version})
 Description: A test package for testing usb accessory
 
index c4ade04..76d57f8 100755 (executable)
@@ -54,7 +54,7 @@ binary-arch: build install
        dh_install --sourcedir=debian/tmp
        dh_installman
        dh_link
-       dh_strip --dbg-package=acc-test-dbg
+       dh_strip --dbg-package=acc_test-dbg
        dh_fixperms
        dh_makeshlibs
        dh_installdeb
similarity index 89%
rename from test/packaging/acc-test.spec
rename to test/packaging/acc_test.spec
index 202f05d..94ece95 100644 (file)
@@ -1,4 +1,4 @@
-Name:       acc-test
+Name:       acc_test
 Summary:    A test program for usb accessory
 Version:       0.0.1
 Release:    1
@@ -13,6 +13,8 @@ BuildRequires:  pkgconfig(ecore-x)
 BuildRequires:  pkgconfig(elementary)
 BuildRequires:  pkgconfig(appcore-efl)
 
+%description
+
 %prep
 %setup -q
 
@@ -32,5 +34,5 @@ chown 5000:5000 /opt/apps/acc_test/bin/acc_test
 
 
 %files
-%attr(644,root,root) /opt/share/applications/acc_test.desktop
+%attr(644,root,root) /opt/share/packages/acc_test.xml
 %attr(555,root,root) /opt/apps/acc_test/bin/acc_test