ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
ADD_DEFINITIONS("-DTIZEN_DEBUG")
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
aux_source_directory(src SOURCES)
ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
)
-INSTALL(TARGETS ${fw_name} DESTINATION lib)
+INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
INSTALL(
DIRECTORY ${INC_DIR}/ DESTINATION include/system
FILES_MATCHING
${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
@ONLY
)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
IF(UNIX)
Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
Except as noted, This software is licensed under Apache License, Version 2.
-Please, see the LICENSE.APLv2 file for Apache License terms and conditions.
+Please, see the LICENSE.Apache_v2 file for Apache License terms and conditions.
#define _GNU_SOURCE
#include <stdio.h>
-#include <libintl.h>
#include <stdbool.h>
-#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <glib.h>
-#define ACC_ELEMENT_LEN 256
#define SOCK_PATH "/tmp/usb_server_sock"
#define ACC_SOCK_PATH "/tmp/usb_acc_sock"
#define USB_ACCESSORY_NODE "/dev/usb_accessory"
#define APP_ID_LEN 64
#define SOCK_STR_LEN 1542
-#define USB_TAG "USB_ACCESSORY"
-#define USB_LOG(format, args...) \
- LOG(LOG_VERBOSE, USB_TAG, "[%s][Ln: %d] " format, \
- (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args)
-
-#define USB_LOG_ERROR(format, args...) \
- LOG(LOG_ERROR, USB_TAG, "[%s][Ln: %d] " format, \
- (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args)
-
-#define __USB_FUNC_ENTER__ \
- USB_LOG("Entering: %s()\n", __func__)
-
-#define __USB_FUNC_EXIT__ \
- USB_LOG("Exit: %s()\n", __func__)
+#undef LOG_TAG
+#define LOG_TAG "USB_ACCESSORY"
+#define USB_LOG(fmt, args...) SLOGD(fmt, ##args)
+#define USB_LOG_ERROR(fmt, args...) SLOGE(fmt, ##args)
+#define __USB_FUNC_ENTER__ USB_LOG("ENTER")
+#define __USB_FUNC_EXIT__ USB_LOG("EXIT")
#define FREE(arg) \
do { \
} \
} while (0);
-#define um_retvm_if(expr, val, fmt, arg...) \
- do { \
- if(expr) { \
- USB_LOG_ERROR(fmt, ##arg); \
- return (val); \
- } \
- } while (0);
-
-#define um_retm_if(expr, fmt, arg...) \
- do { \
- if(expr) { \
- USB_LOG_ERROR(fmt, ##arg); \
- return; \
- } \
- } while (0);
-
typedef enum {
IPC_ERROR = 0,
IPC_FAIL,
REQ_HOST_CONNECTION
} REQUEST_TO_USB_MANGER;
-
-typedef enum {
- ACC_MANUFACTURER = 0,
- ACC_MODEL,
- ACC_DESCRIPTION,
- ACC_VERSION,
- ACC_URI,
- ACC_SERIAL
-} ACCESSORY_INFO;
-
struct usb_accessory_s {
- bool accPermission;
-
- char manufacturer[ACC_ELEMENT_LEN];
- char model[ACC_ELEMENT_LEN];
- char description[ACC_ELEMENT_LEN];
- char version[ACC_ELEMENT_LEN];
- char uri[ACC_ELEMENT_LEN];
- char serial[ACC_ELEMENT_LEN];
+ bool accPermission;
+
+ char *manufacturer;
+ char *model;
+ char *description;
+ char *version;
+ char *uri;
+ char *serial;
};
struct usb_accessory_list {
struct usb_accessory_s *accessory;
};
-int ipc_request_client_init(int *sock_remote);
-int ipc_request_client_close(int *sock_remote);
-int request_to_usb_server(int sock_remote, int request, char *answer, char *pkgName);
+int ipc_request_client_init();
+int request_to_usb_server(int sockRemote, int request, void *data, char *answer, int answerLen);
char *get_app_id();
-void accessory_status_changed_cb(keynode_t *in_key, void* data);
-bool getAccList(struct usb_accessory_list **accList);
-bool freeAccList(struct usb_accessory_list *accList);
+void accessory_status_changed_cb(keynode_t *key, void* data);
+bool get_acc_list(struct usb_accessory_list **accList);
+void free_accessory(struct usb_accessory_s *accessory);
+void free_acc_list(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);
+gboolean ipc_noti_client_cb(GIOChannel *gioCh, GIOCondition condition, gpointer data);
bool is_emul_bin();
+
#endif /* __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__ */
Name: capi-system-usb-accessory
Summary: A usb accessory library in TIZEN C API
-Version: 0.0.6
+Version: 0.0.9
Release: 1
-Group: framework-api
-License: APLv2
+Group: framework/api
+License: Apache License, Version 2.0
Source0: %{name}-%{version}.tar.gz
Source1: capi-system-usb-accessory.manifest
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(aul)
-
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
%description devel
-
%prep
%setup -q
%build
cp %{SOURCE1} .
MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
make %{?jobs:-j%jobs}
%install
-rm -rf %{buildroot}
%make_install
%post
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;
+
+ if (!handle)
+ return USB_ERROR_INVALID_PARAMETER;
+
+ 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);
- snprintf((*cloned_handle)->model, strlen(handle->model), "%s", handle->model);
- snprintf((*cloned_handle)->description, strlen(handle->description), "%s", handle->description);
- snprintf((*cloned_handle)->version, strlen(handle->version), "%s", handle->version);
- snprintf((*cloned_handle)->uri, strlen(handle->uri), "%s", handle->uri);
- snprintf((*cloned_handle)->serial, strlen(handle->serial), "%s", handle->serial);
+ if (!(*cloned_handle)) {
+ USB_LOG("FAIL: malloc()");
+ return USB_ERROR_OPERATION_FAILED;
+ }
+ (*cloned_handle)->manufacturer = strdup(handle->manufacturer);
+ (*cloned_handle)->model = strdup(handle->model);
+ (*cloned_handle)->description = strdup(handle->description);
+ (*cloned_handle)->version = strdup(handle->version);
+ (*cloned_handle)->uri = strdup(handle->uri);
+ (*cloned_handle)->serial = strdup(handle->serial);
(*cloned_handle)->accPermission = false;
__USB_FUNC_EXIT__ ;
int usb_accessory_destroy(usb_accessory_h handle)
{
- __USB_FUNC_ENTER__ ;
- if (!handle) return USB_ERROR_INVALID_PARAMETER;
+ __USB_FUNC_ENTER__ ;
+
if (is_emul_bin()) {
USB_LOG("FAIL:USB Accessory is not available with emulator.");
return USB_ERROR_NOT_SUPPORTED;
}
- FREE(handle);
+
+ if (!handle)
+ return USB_ERROR_INVALID_PARAMETER;
+
+ free_accessory(handle);
+
__USB_FUNC_EXIT__ ;
return USB_ERROR_NONE;
}
int usb_accessory_foreach_attached(usb_accessory_attached_cb callback, void *user_data)
{
__USB_FUNC_ENTER__ ;
- if (callback == NULL) return USB_ERROR_INVALID_PARAMETER;
+
+ struct usb_accessory_list *accList;
+ struct usb_accessory_list *tmpList;
+ bool ret;
+
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;
+
+ if (!callback)
+ return USB_ERROR_INVALID_PARAMETER;
+
accList = (struct usb_accessory_list *)malloc(sizeof(struct usb_accessory_list));
if (!accList) {
USB_LOG("FAIL: malloc()");
return USB_ERROR_OPERATION_FAILED;
}
- ret = getAccList(&accList);
- if (ret == false) {
- USB_LOG("FAIL: getAccList(accList)");
- FREE(accList);
- return -1;
+
+ ret = get_acc_list(&accList);
+ if (!ret) {
+ USB_LOG("FAIL: getAccList()");
+ free_acc_list(accList);
+ return USB_ERROR_OPERATION_FAILED;
}
ret = true;
tmpList = accList;
while (ret) {
- if (tmpList == NULL || tmpList->accessory == NULL) {
+ if (!tmpList || !(tmpList->accessory)) {
break;
}
ret = callback(tmpList->accessory, user_data);
}
}
- FREE(accList);
+ free_acc_list(accList);
__USB_FUNC_EXIT__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_NONE;
}
-
-int usb_accessory_set_connection_changed_cb(usb_accessory_connection_changed_cb callback, void* user_data)
+int usb_accessory_set_connection_changed_cb(usb_accessory_connection_changed_cb callback,
+ void* user_data)
{
__USB_FUNC_ENTER__ ;
+
+ int ret;
+
if (is_emul_bin()) {
USB_LOG("FAIL:USB Accessory is not available with emulator.");
return USB_ERROR_NOT_SUPPORTED;
}
- int ret = -1;
+
+ if (!callback)
+ return USB_ERROR_INVALID_PARAMETER;
+
accCbData = (struct AccCbData *)malloc(sizeof(struct AccCbData));
+ if (!accCbData) {
+ USB_LOG("FAIL: malloc()");
+ return USB_ERROR_OPERATION_FAILED;
+ }
+
accCbData->user_data = user_data;
accCbData->connection_cb_func = callback;
- ret = vconf_notify_key_changed(VCONFKEY_USB_ACCESSORY_STATUS, accessory_status_changed_cb, accCbData);
- um_retvm_if(ret < 0, USB_ERROR_OPERATION_FAILED, "FAIL: vconf_notify_key_changed(VCONFKEY_USB_ACCESSORY_STATUS)\n");
+
+ ret = vconf_notify_key_changed(VCONFKEY_USB_ACCESSORY_STATUS,
+ accessory_status_changed_cb, accCbData);
+ if (ret < 0) {
+ USB_LOG("FAIL: vconf_notify_key_changed()");
+ return USB_ERROR_OPERATION_FAILED;
+ }
+
__USB_FUNC_EXIT__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_NONE;
}
-
int usb_accessory_connection_unset_cb()
{
__USB_FUNC_ENTER__ ;
+
+ int ret;
+
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);
- um_retvm_if(ret < 0, USB_ERROR_OPERATION_FAILED, "FAIL: vconf_ignore_key_changed(VCONFKEY_USB_ACCESSORY_status");
+
+ FREE(accCbData);
+
+ ret = vconf_ignore_key_changed(VCONFKEY_USB_ACCESSORY_STATUS, accessory_status_changed_cb);
+ if (ret < 0) {
+ USB_LOG("FAIL: vconf_ignore_key_changed()");
+ return USB_ERROR_OPERATION_FAILED;
}
- __USB_FUNC_EXIT__ ;
- return USB_ERROR_NONE;
+ __USB_FUNC_EXIT__ ;
+ return USB_ERROR_NONE;
}
-
int usb_accessory_has_permission(usb_accessory_h accessory, bool* is_granted)
{
__USB_FUNC_ENTER__ ;
- if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+
+ int ret;
+ int ipcResult;
+ int sockRemote;
+ char buf[SOCK_STR_LEN];
+ char *appId;
+
if (is_emul_bin()) {
USB_LOG("FAIL:USB Accessory is not available with emulator.");
return USB_ERROR_NOT_SUPPORTED;
}
- if (accessory->accPermission == true) {
+
+ if (!accessory)
+ return USB_ERROR_INVALID_PARAMETER;
+
+ if (accessory->accPermission) {
__USB_FUNC_EXIT__ ;
return USB_ERROR_NONE;
- } else {
- int ret = -1;
- int ipc_result = -1;
- int sock_remote;
- char buf[SOCK_STR_LEN];
- char *app_id = get_app_id();
- if(app_id == NULL) {
- USB_LOG("FAIL: get_app_id()\n");
- *is_granted = false;
- return USB_ERROR_NONE;
- }
+ }
- ret = ipc_request_client_init(&sock_remote);
- um_retvm_if(ret < 0, USB_ERROR_IPC_FAILED, "FAIL: ipc_request_client_init()\n");
+ appId = get_app_id();
+ if(!appId) {
+ USB_LOG("FAIL: get_app_id()");
+ *is_granted = false;
+ return USB_ERROR_NONE;
+ }
- ret = request_to_usb_server(sock_remote, HAS_ACC_PERMISSION, buf, app_id);
- um_retvm_if(ret < 0, USB_ERROR_IPC_FAILED, "FAIL: request_to_usb_server()\n");
+ sockRemote = ipc_request_client_init();
+ if (sockRemote < 0) {
+ USB_LOG("FAIL: ipc_request_client_init()");
+ FREE(appId);
+ return USB_ERROR_IPC_FAILED;
+ }
- ret = ipc_request_client_close(&sock_remote);
- um_retvm_if(ret < 0, USB_ERROR_IPC_FAILED, "FAIL: ipc_request_client_close()\n");
+ ret = request_to_usb_server(sockRemote, HAS_ACC_PERMISSION, appId, buf, sizeof(buf));
+ if (ret < 0) {
+ USB_LOG("FAIL: request_to_usb_server()");
+ close(sockRemote);
+ FREE(appId);
+ return USB_ERROR_IPC_FAILED;
+ }
- FREE(app_id);
+ close(sockRemote);
+ FREE(appId);
- USB_LOG("Permission: %s\n", buf);
- ipc_result = atoi(buf);
- if (IPC_SUCCESS == ipc_result) {
- accessory->accPermission = true;
- *is_granted = true;
- } else {
- accessory->accPermission = false;
- *is_granted = false;
- }
- __USB_FUNC_EXIT__ ;
- return USB_ERROR_NONE;
+ USB_LOG("Permission: %s", buf);
+ ipcResult = atoi(buf);
+ if (IPC_SUCCESS == ipcResult) {
+ accessory->accPermission = true;
+ *is_granted = true;
+ } else {
+ accessory->accPermission = false;
+ *is_granted = false;
}
+ __USB_FUNC_EXIT__ ;
+ return USB_ERROR_NONE;
}
-
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) {
+
+ if (!accessory)
+ return USB_ERROR_INVALID_PARAMETER;
+
+ if (accessory->accPermission) {
*fd = fopen(USB_ACCESSORY_NODE, "r+");
USB_LOG("file pointer: %d", *fd);
} else {
USB_LOG("Permission is not allowed");
*fd = NULL;
}
+
__USB_FUNC_EXIT__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_NONE;
}
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;
}
+
+ if (!accessory)
+ return USB_ERROR_INVALID_PARAMETER;
+
*description = strdup(accessory->description);
+
__USB_FUNC_ENTER__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_NONE;
}
int usb_accessory_get_manufacturer(usb_accessory_h accessory, char** manufacturer)
{
__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)
+ return USB_ERROR_INVALID_PARAMETER;
+
*manufacturer = strdup(accessory->manufacturer);
+
__USB_FUNC_ENTER__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_NONE;
}
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;
}
+
+ if (!accessory)
+ return USB_ERROR_INVALID_PARAMETER;
+
*model = strdup(accessory->model);
+
__USB_FUNC_ENTER__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_NONE;
}
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;
}
+
+ if (!accessory)
+ return USB_ERROR_INVALID_PARAMETER;
+
*serial = strdup(accessory->serial);
+
__USB_FUNC_ENTER__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_NONE;
}
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;
}
+
+ if (!accessory)
+ return USB_ERROR_INVALID_PARAMETER;
+
*version = strdup(accessory->version);
+
__USB_FUNC_ENTER__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_NONE;
}
-
int usb_accessory_is_connected(usb_accessory_h accessory, bool* is_connected)
{
__USB_FUNC_ENTER__ ;
+
+ int ret;
+ int val;
+
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);
- um_retvm_if(ret < 0, USB_ERROR_OPERATION_FAILED, "FAIL: vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS)\n");
+ if (ret < 0) {
+ USB_LOG("FAIL: vconf_get_int()");
+ return USB_ERROR_OPERATION_FAILED;
+ }
+
switch (val) {
case VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED:
*is_connected = true;
case VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED:
*is_connected = false;
break;
+ default:
+ USB_LOG("vconf key value is improper");
+ return USB_ERROR_OPERATION_FAILED;
}
+
__USB_FUNC_EXIT__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_NONE;
}
-int usb_accessory_request_permission(usb_accessory_h accessory, usb_accessory_permission_response_cb callback, void* user_data)
+int usb_accessory_request_permission(usb_accessory_h accessory,
+ usb_accessory_permission_response_cb callback,
+ void* user_data)
{
__USB_FUNC_ENTER__ ;
- if (!accessory) return USB_ERROR_INVALID_PARAMETER;
- if (!callback) return USB_ERROR_INVALID_PARAMETER;
+
+ int ret;
+ guint gret;
+ int fd;
+ int sockRemote;
+ char buf[SOCK_STR_LEN];
+ char *appId;
+ GError *err;
+ GIOStatus gioret;
+ GIOChannel *gioCh;
+
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;
- char buf[SOCK_STR_LEN];
- char *app_id = NULL;
+
+ if (!accessory)
+ return USB_ERROR_INVALID_PARAMETER;
+ if (!callback)
+ return USB_ERROR_INVALID_PARAMETER;
+ if (!accCbData)
+ return USB_ERROR_INVALID_PARAMETER;
+
accCbData->user_data = accessory;
accCbData->request_perm_cb_func = callback;
accCbData->accessory = accessory;
- GError *err;
- GIOStatus gio_ret;
- int fd = ipc_noti_client_init();
+ fd = ipc_noti_client_init();
if (fd < 0) {
USB_LOG("FAIL: ipc_noti_client_init()");
- return USB_ERROR_IPC_FAILED;
+ goto out_ipc_fail;
}
- GIOChannel *g_io_ch = g_io_channel_unix_new(fd);
- if (!g_io_ch) {
+ gioCh = g_io_channel_unix_new(fd);
+ if (!gioCh) {
USB_LOG("FAIL: g_io_channel_unix_new()");
- ret = ipc_noti_client_close(&fd);
- if (ret < 0) USB_LOG("FAIL: ipc_noti_client_close(&fd)\n");
- return USB_ERROR_IPC_FAILED;
+ goto out_ipc_noti;
}
- g_ret = g_io_add_watch(g_io_ch, G_IO_IN, ipc_noti_client_cb, (gpointer)accCbData);
- if (g_ret == 0) {
- USB_LOG("FAIL: g_io_add_watch(g_io_ch, G_IO_IN)\n");
- ret = ipc_noti_client_close(&fd);
- if (ret < 0) USB_LOG("FAIL: ipc_noti_client_close(&fd)\n");
- gio_ret = g_io_channel_shutdown(g_io_ch, TRUE, &err);
- if (G_IO_STATUS_ERROR == gio_ret) USB_LOG("ERROR: g_io_channel_shutdown(g_io_ch)\n");
- g_io_channel_unref(g_io_ch);
- return USB_ERROR_IPC_FAILED;
+ gret = g_io_add_watch(gioCh, G_IO_IN, ipc_noti_client_cb, (gpointer)accCbData);
+ if (gret == 0) {
+ USB_LOG("FAIL: g_io_add_watch(g_io_ch, G_IO_IN)");
+ goto out_gio_unref;
}
- ret = ipc_request_client_init(&sock_remote);
- if(ret < 0) {
- USB_LOG("FAIL: ipc_request_client_init(&sock_remote)\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);
- if (ret < 0) USB_LOG("FAIL: ipc_noti_client_close(&fd)\n");
- gio_ret = g_io_channel_shutdown(g_io_ch, TRUE, &err);
- if (G_IO_STATUS_ERROR == gio_ret) USB_LOG("ERROR: g_io_channel_shutdown(g_io_ch)\n");
- g_io_channel_unref(g_io_ch);
- return USB_ERROR_IPC_FAILED;
+ sockRemote = ipc_request_client_init();
+ if(sockRemote < 0) {
+ USB_LOG("FAIL: ipc_request_client_init(&sock_remote)");
+ goto out_gio_unref;
}
- app_id = get_app_id();
- USB_LOG("App ID: %s", app_id);
- if (!app_id) {
+ appId = get_app_id();
+ USB_LOG("App ID: %s", appId);
+ if (!appId) {
USB_LOG("FAIL: get_app_id()");
- 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);
- if (ret < 0) USB_LOG("FAIL: ipc_noti_client_close(&fd)\n");
- gio_ret = g_io_channel_shutdown(g_io_ch, TRUE, &err);
- if (G_IO_STATUS_ERROR == gio_ret) USB_LOG("ERROR: g_io_channel_shutdown(g_io_ch)\n");
- g_io_channel_unref(g_io_ch);
- return USB_ERROR_OPERATION_FAILED;
+ goto out_ipc_request;
}
- ret = request_to_usb_server(sock_remote, REQ_ACC_PERMISSION, buf, app_id);
+ ret = request_to_usb_server(sockRemote, REQ_ACC_PERMISSION, appId, buf, sizeof(buf));
if(ret < 0) {
- 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);
- if (ret < 0) USB_LOG("FAIL: ipc_noti_client_close(&fd)\n");
- gio_ret = g_io_channel_shutdown(g_io_ch, TRUE, &err);
- if (G_IO_STATUS_ERROR == gio_ret) USB_LOG("ERROR: g_io_channel_shutdown(g_io_ch)\n");
- g_io_channel_unref(g_io_ch);
- FREE(app_id);
- return USB_ERROR_IPC_FAILED;
+ USB_LOG("FAIL: request_to_usb_server(REQ_ACC_PERMISSION)");
+ goto out_app_id;
}
- FREE(app_id);
+ FREE(appId);
+ close(sockRemote);
- 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);
- if (ret < 0) USB_LOG("FAIL: ipc_noti_client_close(&fd)\n");
- gio_ret = g_io_channel_shutdown(g_io_ch, TRUE, &err);
- if (G_IO_STATUS_ERROR == gio_ret) USB_LOG("ERROR: g_io_channel_shutdown(g_io_ch)\n");
- g_io_channel_unref(g_io_ch);
- return USB_ERROR_IPC_FAILED;
- }
+ __USB_FUNC_EXIT__ ;
+ return USB_ERROR_NONE;
+out_app_id:
+ FREE(appId);
+out_ipc_request:
+ close(sockRemote);
+out_gio_unref:
+ gioret = g_io_channel_shutdown(gioCh, TRUE, &err);
+ if (G_IO_STATUS_ERROR == gioret)
+ USB_LOG("ERROR: g_io_channel_shutdown()");
+ g_io_channel_unref(gioCh);
+out_ipc_noti:
+ close(fd);
+out_ipc_fail:
__USB_FUNC_EXIT__ ;
- return USB_ERROR_NONE;
+ return USB_ERROR_IPC_FAILED;
}
#include "usb_accessory_private.h"
+#define NUM_ACC_INFO_SEPARATOR 5
+
+static void show_acc_info(struct usb_accessory_s *accessory)
+{
+ __USB_FUNC_ENTER__ ;
+ if (!accessory)
+ return;
+
+ USB_LOG("*******************************");
+ USB_LOG("** Acc manufacturer: %s", accessory->manufacturer);
+ USB_LOG("** Acc model : %s", accessory->model);
+ USB_LOG("** Acc description : %s", accessory->description);
+ USB_LOG("** Acc version : %s", accessory->version);
+ USB_LOG("** Acc uri : %s", accessory->uri);
+ USB_LOG("** Acc serial : %s", accessory->serial);
+ USB_LOG("*******************************");
+ __USB_FUNC_EXIT__ ;
+}
+
+void free_accessory(struct usb_accessory_s *accessory)
+{
+ __USB_FUNC_ENTER__ ;
+
+ if (accessory) {
+ FREE(accessory->manufacturer);
+ FREE(accessory->model);
+ FREE(accessory->description);
+ FREE(accessory->version);
+ FREE(accessory->uri);
+ FREE(accessory->serial);
+ FREE(accessory);
+ }
+ __USB_FUNC_EXIT__ ;
+}
+
+/* Release memory of accessory list */
+void free_acc_list(struct usb_accessory_list *accList)
+{
+ __USB_FUNC_ENTER__ ;
+
+ struct usb_accessory_list *tmpList;
+ struct usb_accessory_s *accessory;
+
+ if (!accList)
+ return;
+
+ while (accList) {
+ tmpList = accList;
+ accList = accList->next;
+ accessory = tmpList->accessory;
+
+ free_accessory(accessory);
+ FREE(tmpList);
+ }
+
+ __USB_FUNC_EXIT__ ;
+}
+
/* This function initializes socket for ipc with usb-server */
-int ipc_request_client_init(int *sock_remote)
+int ipc_request_client_init()
{
__USB_FUNC_ENTER__ ;
- if (!sock_remote) return -1;
- int len;
+
+ int sock;
struct sockaddr_un remote;
- if (((*sock_remote) = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
- perror("socket");
+ if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
USB_LOG("FAIL: socket(AF_UNIX, SOCK_STREAM, 0)");
- return -1;;
+ return -1;
}
+
remote.sun_family = AF_UNIX;
- strncpy(remote.sun_path, SOCK_PATH, strlen(SOCK_PATH)+1);
- len = strlen(remote.sun_path) + sizeof(remote.sun_family);
+ strncpy(remote.sun_path, SOCK_PATH, sizeof(remote.sun_path));
- if (connect((*sock_remote), (struct sockaddr *)&remote, len) == -1) {
- perror("connect");
- USB_LOG("FAIL: connect((*sock_remote), (struct sockaddr *)&remote, len)");
+ if (connect(sock, (struct sockaddr *)&remote, sizeof(remote)) == -1) {
+ USB_LOG("FAIL: connect(sock, (struct sockaddr *)&remote, len)");
+ close(sock);
return -1;
}
- __USB_FUNC_EXIT__ ;
- return 0;
-}
-/* This function closes socket for ipc with usb-server */
-int ipc_request_client_close(int *sock_remote)
-{
- __USB_FUNC_ENTER__ ;
- if (!sock_remote) return -1;
- close (*sock_remote);
__USB_FUNC_EXIT__ ;
- return 0;
+ return sock;
}
/* This function requests something to usb-server by ipc with socket and gets the results */
-int request_to_usb_server(int sock_remote, int request, char *answer, char *pkgName)
+int request_to_usb_server(int sockRemote, int request, void *data, char *answer, int answerLen)
{
__USB_FUNC_ENTER__ ;
+
int t;
char str[SOCK_STR_LEN];
+ char *pkgName;
- USB_LOG("request: %d, pkgName: %s\n", request, pkgName);
- snprintf(str, SOCK_STR_LEN, "%d|%s", request, pkgName);
- if (send (sock_remote, str, strlen(str)+1, 0) == -1) {
- USB_LOG("FAIL: send (sock_remote, str, strlen(str)+1, 0)\n");
+ if (!answer)
return -1;
+
+ switch (request) {
+ case REQ_ACC_PERMISSION:
+ case HAS_ACC_PERMISSION:
+ pkgName = (char *)data;
+ USB_LOG("request: %d, pkgName: %s", request, pkgName);
+ snprintf(str, sizeof(str), "%d|%s", request, pkgName);
+ break;
+ default:
+ USB_LOG("request: %d", request);
+ snprintf(str, sizeof(str), "%d|", request);
+ break;
}
- if ((t = recv(sock_remote, answer, SOCK_STR_LEN, 0)) > 0) {
- if (t < SOCK_STR_LEN) {
+
+ if (send (sockRemote, str, strlen(str)+1, 0) == -1) {
+ USB_LOG("FAIL: send (sock_remote, str, strlen(str)+1, 0)");
+ return -1;
+ }
+
+ if ((t = recv(sockRemote, answer, answerLen, 0)) > 0) {
+ if (t < answerLen) {
answer[t] = '\0';
- } else { /* t == SOCK_STR_LEN */
- answer[SOCK_STR_LEN-1] = '\0';
+ } else { /* t == answerLen */
+ answer[answerLen-1] = '\0';
}
- USB_LOG("[CLIENT] Received value: %s\n", answer);
- } else {
- USB_LOG("FAIL: recv(sock_remote, str, SOCK_STR_LEN, 0)\n");
- return -1;
+ USB_LOG("[CLIENT] Received value: %s", answer);
+
+ __USB_FUNC_EXIT__ ;
+ return 0;
}
+
+ USB_LOG("FAIL: recv(sock_remote, str, answerLen, 0)");
+
__USB_FUNC_EXIT__ ;
- return 0;
+ return -1;
}
-int handle_input_to_server(void *data, char *buf)
+static int handle_input_to_server(void *data, char *buf)
{
__USB_FUNC_ENTER__ ;
- if (!data) return -1;
- if (!buf) return -1;
- struct AccCbData *permCbData = (struct AccCbData *)data;
- int input = atoi(buf);
- USB_LOG("Input: %d\n", input);
+
+ struct AccCbData *permCbData;
+ int input;
+
+ if (!data)
+ return -1;
+ if (!buf)
+ return -1;
+
+ permCbData = (struct AccCbData *)data;
+ input = atoi(buf);
+ USB_LOG("Input: %d", input);
switch (input) {
case REQ_ACC_PERM_NOTI_YES_BTN:
permCbData->accessory->accPermission = true;
- permCbData->request_perm_cb_func((struct usb_accessory_s*)(permCbData->user_data), true);
+ permCbData->request_perm_cb_func(
+ (struct usb_accessory_s*)(permCbData->user_data), true);
break;
case REQ_ACC_PERM_NOTI_NO_BTN:
permCbData->accessory->accPermission = false;
- permCbData->request_perm_cb_func((struct usb_accessory_s*)(permCbData->user_data), false);
+ permCbData->request_perm_cb_func(
+ (struct usb_accessory_s*)(permCbData->user_data), false);
break;
default:
- break;
+ USB_LOG("FAIL: buf (%s) is improper", buf);
+ return -1;
}
__USB_FUNC_EXIT__ ;
return 0;
static int read_message(int fd, char *str, int len)
{
__USB_FUNC_ENTER__;
- int ret = -1;
+ int ret;
+
+ if (!str)
+ return -1;
+
while(1) {
ret = read(fd, str, len);
- if (ret < 0) {
- if (EINTR == errno) {
- USB_LOG("Re-read for error(EINTR)\n");
- continue;
- } else {
- USB_LOG("FAIL: read(fd, str, len)\n");
- return -1;
- }
- } else {
+ if (ret >= 0) {
__USB_FUNC_EXIT__;
return 0;
}
+
+ if (EINTR == errno) {
+ USB_LOG("Re-read for error(EINTR)");
+ continue;
+ }
+
+ USB_LOG("FAIL: read(fd, str, len)");
+ return -1;
}
}
{
__USB_FUNC_ENTER__ ;
int sock_local;
- int ret = -1;
- int len;
+ int ret;
struct sockaddr_un serveraddr;
sock_local = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock_local < 0) {
- perror("socket");
- USB_LOG("FAIL: socket(AF_UNIX, SOCK_STREAM, 0)\n");
+ USB_LOG("FAIL: socket(AF_UNIX, SOCK_STREAM, 0)");
return -1;
}
+
serveraddr.sun_family = AF_UNIX;
strncpy(serveraddr.sun_path, ACC_SOCK_PATH, strlen(ACC_SOCK_PATH)+1);
- USB_LOG("socket file name: %s\n", serveraddr.sun_path);
+ USB_LOG("socket file name: %s", serveraddr.sun_path);
+
unlink(serveraddr.sun_path);
- len = strlen(serveraddr.sun_path) + sizeof(serveraddr.sun_family);
- if (bind (sock_local, (struct sockaddr *)&serveraddr, len) < 0) {
- perror("bind");
- USB_LOG("FAIL: bind (sock_local, (struct sockaddr_un *)serveraddr)\n");
+ if (bind (sock_local, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0) {
+ USB_LOG("FAIL: bind (sock_local, (struct sockaddr_un *)serveraddr)");
close(sock_local);
return -1;
}
ret = chown(ACC_SOCK_PATH, 5000, 5000);
- if (ret < 0) USB_LOG("FAIL: chown(ACC_SOCK_PATH, 5000, 5000)");
+ if (ret < 0) {
+ USB_LOG("FAIL: chown(ACC_SOCK_PATH, 5000, 5000)");
+ close(sock_local);
+ return -1;
+ }
+
ret = chmod(ACC_SOCK_PATH, 0777);
- if (ret < 0) USB_LOG("FAIL: chmod(ACC_SOCK_PATH, 0777);");
+ if (ret < 0) {
+ USB_LOG("FAIL: chmod(ACC_SOCK_PATH, 0777);");
+ close(sock_local);
+ return -1;
+ }
if (listen (sock_local, 5) == -1) {
- perror("listen");
- USB_LOG("FAIL: listen (sock_local, 5)\n");
+ USB_LOG("FAIL: listen (sock_local, 5)");
close(sock_local);
return -1;
}
return sock_local;
}
-int ipc_noti_client_close(int *sock_remote)
+gboolean ipc_noti_client_cb(GIOChannel *gioCh, GIOCondition condition, gpointer data)
{
__USB_FUNC_ENTER__ ;
- close(*sock_remote);
- __USB_FUNC_EXIT__ ;
- return 0;
-}
-gboolean ipc_noti_client_cb(GIOChannel *g_io_ch, GIOCondition condition, gpointer data)
-{
- __USB_FUNC_ENTER__ ;
- if (!data) return FALSE;
- if (!g_io_ch) return FALSE;
int fd;
- int ret = -1;
- struct sockaddr_un client_address;
- int client_sockfd;
- int client_len;
- char input_buf[SOCK_STR_LEN];
- char output_buf[SOCK_STR_LEN];
+ int ret;
+ int clientlen;
+ struct sockaddr_un clientaddr;
+ int sockfd;
+ char inbuf[SOCK_STR_LEN];
+ char outbuf[SOCK_STR_LEN];
GError *err;
- GIOStatus gio_ret;
+ GIOStatus gret;
- fd = g_io_channel_unix_get_fd(g_io_ch);
- if (fd < 0) {
- USB_LOG("FAIL: g_io_channel_unix_get_fd(g_io_ch)\n");
- gio_ret = g_io_channel_shutdown(g_io_ch, TRUE, &err);
- if (G_IO_STATUS_ERROR == gio_ret) USB_LOG("ERROR: g_io_channel_shutdown(g_io_ch)\n");
- g_io_channel_unref(g_io_ch);
+ if (!data)
return FALSE;
+ if (!gioCh)
+ return FALSE;
+
+ fd = g_io_channel_unix_get_fd(gioCh);
+ if (fd < 0) {
+ USB_LOG("FAIL: g_io_channel_unix_get_fd()");
+ goto out_gio_unref;
}
- client_len = sizeof(client_address);
- client_sockfd = accept(fd, (struct sockaddr *)&client_address, (socklen_t *)&client_len);
- if (client_sockfd == -1) {
- perror("accept");
- USB_LOG("FAIL: accept(fd, (struct sockaddr *)&client_address, (socklen_t *)&client_len)\n");
- gio_ret = g_io_channel_shutdown(g_io_ch, TRUE, &err);
- if (G_IO_STATUS_ERROR == gio_ret) USB_LOG("ERROR: g_io_channel_shutdown(g_io_ch)\n");
- g_io_channel_unref(g_io_ch);
- ret = ipc_noti_client_close(&client_sockfd);
- if (ret < 0) USB_LOG("FAIL: ipc_noti_client_close(client_sockfd)\n");
- return FALSE;
+ clientlen = sizeof(clientaddr);
+ sockfd = accept(fd, (struct sockaddr *)&clientaddr, (socklen_t *)&clientlen);
+ if (sockfd == -1) {
+ USB_LOG("FAIL: accept()");
+ goto out_ipc_fd;
}
- if(read_message(client_sockfd, input_buf, sizeof(input_buf)) < 0) {
- USB_LOG("FAIL: read_message(client_sockfd, &buf)\n");
- snprintf(output_buf, strlen("FAIL"), "%d", IPC_FAIL);
- ret = write(client_sockfd, &output_buf, sizeof(output_buf));
- if (ret < 0) USB_LOG("FAIL: write(client_sockfd, &output_buf, sizeof(output_buf))\n");
- gio_ret = g_io_channel_shutdown(g_io_ch, TRUE, &err);
- if (G_IO_STATUS_ERROR == gio_ret) USB_LOG("ERROR: g_io_channel_shutdown(g_io_ch)\n");
- g_io_channel_unref(g_io_ch);
- ret = ipc_noti_client_close(&client_sockfd);
- if (ret < 0) USB_LOG("FAIL: ipc_noti_client_close(client_sockfd)\n");
- return FALSE;
+ if(read_message(sockfd, inbuf, sizeof(inbuf)) < 0) {
+ USB_LOG("FAIL: read_message()");
+ snprintf(outbuf, sizeof(outbuf), "%d", IPC_FAIL);
+ if (0 > write(sockfd, &outbuf, sizeof(outbuf)))
+ USB_LOG("FAIL: write()");
+ goto out_ipc_fd;
}
- USB_LOG("read(): %s\n", input_buf);
- snprintf(output_buf, SOCK_STR_LEN, "%d", IPC_SUCCESS);
- ret = write(client_sockfd, &output_buf, sizeof(output_buf));
- if (ret < 0) USB_LOG("FAIL: write(client_sockfd, &output_buf, sizeof(output_buf))\n");
- gio_ret = g_io_channel_shutdown(g_io_ch, TRUE, &err);
- if (G_IO_STATUS_ERROR == gio_ret) USB_LOG("ERROR: g_io_channel_shutdown(g_io_ch)\n");
- g_io_channel_unref(g_io_ch);
- ret = ipc_noti_client_close(&client_sockfd);
- if (ret < 0) USB_LOG("FAIL: ipc_noti_client_close(client_sockfd)\n");
- ret = handle_input_to_server((void *)data, input_buf);
- if (ret < 0) USB_LOG("FAIL: handle_input_to_server(input_buf, data)\n");
+ USB_LOG("read(): %s", inbuf);
+ snprintf(outbuf, sizeof(outbuf), "%d", IPC_SUCCESS);
+ ret = write(sockfd, &outbuf, sizeof(outbuf));
+ if (ret < 0)
+ USB_LOG("FAIL: write()");
+
+ ret = handle_input_to_server((void *)data, inbuf);
+ if (ret < 0)
+ USB_LOG("FAIL: handle_input_to_server()");
+
+out_ipc_fd:
+ close(sockfd);
+out_gio_unref:
+ gret = g_io_channel_shutdown(gioCh, TRUE, &err);
+ if (G_IO_STATUS_ERROR == gret)
+ USB_LOG("ERROR: g_io_channel_shutdown(gioCh)");
+ g_io_channel_unref(gioCh);
__USB_FUNC_EXIT__ ;
return FALSE;
char *get_app_id()
{
__USB_FUNC_ENTER__ ;
- int pid = getpid();
- USB_LOG("pid: %d\n", pid);
+
+ int ret;
char appId[APP_ID_LEN];
- int ret = aul_app_get_appid_bypid(getpid(), appId, APP_ID_LEN);
- um_retvm_if(AUL_R_OK != ret, NULL, "FAIL: aul_app_get_appid_bypid(getpid(), appId)\n");
+
+ ret = aul_app_get_appid_bypid(getpid(), appId, sizeof(appId));
+ if (ret != AUL_R_OK) {
+ USB_LOG("FAIL: aul_app_get_appid_bypid()");
+ return NULL;
+ }
+
+ USB_LOG("appId: %s", appId);
+
__USB_FUNC_EXIT__ ;
return strdup(appId);
}
-/* This function find an accessory attached just now
- * Currently This function supports just one accessory */
-static int getChangedAcc (struct usb_accessory_s **attAcc)
+/* Get an element from a string which has all information of an accessory */
+static bool get_acc_element(char **totalInfo, char **info)
{
__USB_FUNC_ENTER__ ;
- if (attAcc == NULL) return -1;
- struct usb_accessory_list *accList = NULL;
- bool ret;
- accList = (struct usb_accessory_list *)malloc(sizeof(struct usb_accessory_list));
- um_retvm_if(!accList, -1, "accList == NULL");
+ char *finder;
- ret = getAccList(&accList);
- if (ret == false) {
- USB_LOG("FAIL: getAccList(&accList)");
- FREE(accList);
- return -1;
- }
+ if (!totalInfo || !(*totalInfo))
+ return false;
+ if (!info)
+ return false;
+
+ finder = *totalInfo;
- *attAcc = (struct usb_accessory_s *)malloc(sizeof(struct usb_accessory_s));
- snprintf((*attAcc)->manufacturer, ACC_ELEMENT_LEN, "%s", accList->accessory->manufacturer);
- snprintf((*attAcc)->model, ACC_ELEMENT_LEN, "%s", accList->accessory->model);
- snprintf((*attAcc)->description, ACC_ELEMENT_LEN, "%s", accList->accessory->description);
- snprintf((*attAcc)->version, ACC_ELEMENT_LEN, "%s", accList->accessory->version);
- snprintf((*attAcc)->uri, ACC_ELEMENT_LEN, "%s", accList->accessory->uri);
- snprintf((*attAcc)->serial, ACC_ELEMENT_LEN, "%s", accList->accessory->serial);
+ while (finder) {
+ if (*finder != '|' && *finder != '\0') {
+ finder++;
+ continue;
+ }
- FREE(accList);
+ *finder = '\0';
+ *info = strdup(*totalInfo);
+ USB_LOG("Info: %s", *info);
+ *totalInfo = ++finder;
+ __USB_FUNC_EXIT__ ;
+ return true;
+ }
__USB_FUNC_EXIT__ ;
- return 0;
+ return false;
}
-/* This func release memory of an accessory attached just now */
-static int freeChangedAcc (struct usb_accessory_s **attAcc)
+/* Get all element separated from a string which has all information of an accessory */
+static int get_acc_info(char *totalInfo, struct usb_accessory_s **accessory)
{
__USB_FUNC_ENTER__ ;
- if (attAcc == NULL) return -1;
- FREE(*attAcc);
+
+ bool ret;
+ char *tmpInfo;
+ int numSepBar;
+
+ if (!totalInfo)
+ goto out_fail;
+ if (!accessory || !(*accessory))
+ goto out_fail;
+
+ /* Check whether or not the format of the accessory info is correct to parse */
+ tmpInfo = totalInfo;
+ numSepBar = 0;
+ while(*tmpInfo != '\0') {
+ if (*tmpInfo == '|')
+ numSepBar++;
+ tmpInfo++;
+ }
+ if (numSepBar != NUM_ACC_INFO_SEPARATOR) {
+ USB_LOG("FAIL: Format of string (%s) is improper", totalInfo);
+ goto out_fail;
+ }
+
+ tmpInfo = totalInfo;
+
+ ret = get_acc_element(&tmpInfo, &((*accessory)->manufacturer));
+ if (!ret)
+ goto out_fail;
+
+ ret = get_acc_element(&tmpInfo, &((*accessory)->model));
+ if (!ret)
+ goto out_release_manufacturer;
+
+ ret = get_acc_element(&tmpInfo, &((*accessory)->description));
+ if (!ret)
+ goto out_release_model;
+
+ ret = get_acc_element(&tmpInfo, &((*accessory)->version));
+ if (!ret)
+ goto out_release_description;
+
+ ret = get_acc_element(&tmpInfo, &((*accessory)->uri));
+ if (!ret)
+ goto out_release_version;
+
+ ret = get_acc_element(&tmpInfo, &((*accessory)->serial));
+ if (!ret)
+ goto out_release_uri;
+
+ (*accessory)->accPermission = false;
+
__USB_FUNC_EXIT__ ;
return 0;
+
+out_release_uri:
+ FREE((*accessory)->uri);
+out_release_version:
+ FREE((*accessory)->version);
+out_release_description:
+ FREE((*accessory)->description);
+out_release_model:
+ FREE((*accessory)->model);
+out_release_manufacturer:
+ FREE((*accessory)->manufacturer);
+out_fail:
+ __USB_FUNC_EXIT__ ;
+ return -1;
}
-/* Callback function which is called when accessory vconf key is changed */
-void accessory_status_changed_cb(keynode_t *in_key, void* data)
+/* This function finds a list which contain all accessories attached
+ * Currently, Tizen usb accessory is designed for just one accessory */
+bool get_acc_list(struct usb_accessory_list **accList)
{
__USB_FUNC_ENTER__ ;
- if (!data) return ;
- struct AccCbData *conCbData = (struct AccCbData *)data;
- struct usb_accessory_s *changedAcc = NULL;
- int ret = -1;
- int val = -1;
- ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &val);
- um_retm_if(ret < 0, "FAIL: vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS)\n");
- switch (val) {
- case VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED:
- 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");
+ struct usb_accessory_s *accessory;
+ int ret;
+ int sock_remote;
+ char buf[SOCK_STR_LEN];
- conCbData->connection_cb_func(changedAcc, true, conCbData->user_data);
+ if (!accList || !(*accList))
+ return false;
- 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;
+ sock_remote = ipc_request_client_init();
+ if (sock_remote < 0) {
+ USB_LOG("FAIL: ipc_request_client_init()");
+ return false;
}
- __USB_FUNC_EXIT__ ;
-}
-/* Get an element from a string which has all information of an accessory */
-static bool getAccElement(char *totalInfo[], char accInfo[])
-{
- __USB_FUNC_ENTER__ ;
- if (!totalInfo) return false;
- if (!accInfo) return false;
-
- char *finder = *totalInfo;
-
- if (*totalInfo) {
- while (1) {
- if (finder == NULL) {
- USB_LOG("ERROR: finder == NULL");
- __USB_FUNC_EXIT__ ;
- return false;
- }
- if (*finder == '|' || *finder == '\0') {
- *finder = '\0';
- snprintf(accInfo, ACC_ELEMENT_LEN, "%s", *totalInfo);
- USB_LOG("Info: %s", accInfo);
- *totalInfo = ++finder;
- __USB_FUNC_EXIT__ ;
- return true;
- }
- finder++;
- }
+ ret = request_to_usb_server(sock_remote, GET_ACC_INFO, NULL, buf, sizeof(buf));
+ if (ret < 0) {
+ USB_LOG("FAIL: request_to_usb_server(GET_ACC_INFO)");
+ close(sock_remote);
+ return false;
+ }
+ USB_LOG("GET_ACC_INFO: %s", buf);
+
+ close(sock_remote);
+
+ accessory = (struct usb_accessory_s *)malloc(sizeof(struct usb_accessory_s));
+ if (!accessory) {
+ USB_LOG("FAIL: malloc()");
+ return false;
}
+
+ ret = get_acc_info(buf, &accessory);
+ if (0 > ret) {
+ USB_LOG("FAIL: get_acc_info()");
+ return false;
+ }
+
+ (*accList)->next = NULL;
+ (*accList)->accessory = accessory;
+
+ show_acc_info((*accList)->accessory);
+
__USB_FUNC_EXIT__ ;
- return false;
+ return true;
}
-/* Get all element separated from a string which has all information of an accessory */
-static int getAccInfo(char *totalInfo[], struct usb_accessory_s **accessory)
+/* This function find an accessory attached just now
+ * Currently This function supports just one accessory */
+static int get_changed_acc (struct usb_accessory_s *attAcc)
{
__USB_FUNC_ENTER__ ;
- bool ret = getAccElement(totalInfo, (*accessory)->manufacturer);
- um_retvm_if(ret == false, -1, "FAIL: getAccElement(totalInfo, manufacturer)\n");
- ret = getAccElement(totalInfo, (*accessory)->model);
- um_retvm_if(ret == false, -1, "FAIL: getAccElement(totalInfo, model)\n");
- ret = getAccElement(totalInfo, (*accessory)->description);
- um_retvm_if(ret == false, -1, "FAIL: getAccElement(totalInfo, description)\n");
- ret = getAccElement(totalInfo, (*accessory)->version);
- um_retvm_if(ret == false, -1, "FAIL: getAccElement(totalInfo, version)\n");
- ret = getAccElement(totalInfo, (*accessory)->uri);
- um_retvm_if(ret == false, -1, "FAIL: getAccElement(totalInfo, uri)\n");
- ret = getAccElement(totalInfo, (*accessory)->serial);
- um_retvm_if(ret == false, -1, "FAIL: getAccElement(totalInfo, serial)\n");
+
+ struct usb_accessory_list *accList;
+ bool ret;
+
+ if (!attAcc)
+ return -1;
+
+ accList = (struct usb_accessory_list *)malloc(sizeof(struct usb_accessory_list));
+ if (!accList) {
+ USB_LOG("FAIL: malloc()");
+ return -1;
+ }
+
+ ret = get_acc_list(&accList);
+ if (!ret) {
+ USB_LOG("FAIL: get_acc_list()");
+ free_acc_list(accList);
+ return -1;
+ }
+
+ if (!(accList->accessory)) {
+ USB_LOG("FAIL: accList->accessory == NULL");
+ free_acc_list(accList);
+ return -1;
+ }
+
+ attAcc->manufacturer = strdup(accList->accessory->manufacturer);
+ attAcc->model = strdup(accList->accessory->model);
+ attAcc->description = strdup(accList->accessory->description);
+ attAcc->version = strdup(accList->accessory->version);
+ attAcc->uri = strdup(accList->accessory->uri);
+ attAcc->serial = strdup(accList->accessory->serial);
+
+ free_acc_list(accList);
__USB_FUNC_EXIT__ ;
return 0;
}
-/* This function finds a list which contain all accessories attached
- * Currently, Tizen usb accessory is designed for just one accessory */
-bool getAccList(struct usb_accessory_list **accList)
+/* Callback function which is called when accessory vconf key is changed */
+void accessory_status_changed_cb(keynode_t *key, void* data)
{
__USB_FUNC_ENTER__ ;
- if (accList == NULL || *accList == NULL) return false;
- struct usb_accessory_s *accessory = NULL;
- accessory = (struct usb_accessory_s *)malloc(sizeof(struct usb_accessory_s));
- (*accList)->next = NULL;
- (*accList)->accessory = accessory;
- accessory->accPermission = false;
- int ret = -1;
- int sock_remote;
- char buf[SOCK_STR_LEN];
- ret = ipc_request_client_init(&sock_remote);
- um_retvm_if(ret < 0, false, "FAIL: ipc_request_client_init(&sock_remote)\n");
+ struct AccCbData *conCbData;
+ struct usb_accessory_s *changedAcc;
+ int ret;
+ int val;
+
+ if (!data)
+ return;
- ret = request_to_usb_server(sock_remote, GET_ACC_INFO, buf, NULL);
- um_retvm_if(ret < 0, false, "FAIL: request_to_usb_server(GET_ACC_INFO)\n");
- USB_LOG("GET_ACC_INFO: %s\n", buf);
+ conCbData = (struct AccCbData *)data;
+
+ ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &val);
+ if (0 > ret) {
+ USB_LOG("FAIL: vconf_get_int()");
+ return ;
+ }
+
+ switch (val) {
+ case VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED:
+ conCbData->connection_cb_func(NULL, false, conCbData->user_data);
+ break;
- ret = ipc_request_client_close(&sock_remote);
- um_retvm_if(ret < 0, false, "FAIL: ipc_request_client_close(&sock_remote)\n");
+ case VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED:
+ changedAcc = (struct usb_accessory_s *)malloc(sizeof(struct usb_accessory_s));
+ if (!changedAcc) {
+ USB_LOG("FAIL: malloc()");
+ return;
+ }
- char *tempInfo = buf;
- ret = getAccInfo(&tempInfo, &((*accList)->accessory));
- um_retvm_if(ret < 0, false, "FAIL: getAccInfo(&tempInfo, accList)\n");
+ ret = get_changed_acc(changedAcc);
+ if (ret < 0) {
+ USB_LOG("FAIL: get_changed_acc()");
+ free_accessory(changedAcc);
+ return;
+ }
- USB_LOG("Acc manufacturer: %s\n", (*accList)->accessory->manufacturer);
- USB_LOG("Acc model: %s\n", (*accList)->accessory->model);
- USB_LOG("Acc description: %s\n", (*accList)->accessory->description);
- USB_LOG("Acc version: %s\n", (*accList)->accessory->version);
- USB_LOG("Acc uri: %s\n", (*accList)->accessory->uri);
- USB_LOG("Acc serial: %s\n", (*accList)->accessory->serial);
+ conCbData->connection_cb_func(changedAcc, true, conCbData->user_data);
- __USB_FUNC_EXIT__ ;
- return true;
-}
+ free_accessory(changedAcc);
-/* Release memory of accessory list */
-bool freeAccList(struct usb_accessory_list *accList)
-{
- __USB_FUNC_ENTER__ ;
- if (accList == NULL) return true;
- struct usb_accessory_list *tmpList = NULL;
- while (accList) {
- tmpList = accList;
- accList = accList->next;
- FREE(tmpList->accessory);
- FREE(tmpList);
+ break;
+ default:
+ USB_LOG("ERROR: The value of VCONFKEY_USB_ACCESSORY_STATUS is invalid");
+ break;
}
__USB_FUNC_EXIT__ ;
- return true;
}
bool is_emul_bin()
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;
- }
}
+ USB_LOG("Machine name: %s", name.machine);
+ if (strcasestr(name.machine, "emul")) {
+ __USB_FUNC_EXIT__ ;
+ return true;
+ } else {
+ __USB_FUNC_EXIT__ ;
+ return false;
+ }
}
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)
+pkg_check_modules(pkgs REQUIRED elementary ecore-x appcore-efl aul capi-system-usb-accessory)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
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(TARGETS acc_test DESTINATION /opt/usr/apps/acc_test/bin)
# install manifest file
INSTALL(FILES ${CMAKE_SOURCE_DIR}/acc_test.xml DESTINATION /opt/share/packages/)
#include <Elementary.h>
#include <dlog.h>
-#define USB_TAG "USB_ACC_TEST"
+#undef LOG_TAG
+#define LOG_TAG "USB_ACC_TEST"
-#define ACC_LOG(format, args...) \
- LOG(LOG_VERBOSE, USB_TAG, "[%s][Ln: %d] " format, \
- (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args)
-
-#define ACC_LOG_ERROR(format, args...) \
- LOG(LOG_ERROR, USB_TAG, "[%s][Ln: %d] " format, \
- (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args)
-
-#define __ACC_FUNC_ENTER__ \
- ACC_LOG("Entering: %s()\n", __func__)
-
-#define __ACC_FUNC_EXIT__ \
- ACC_LOG("Exit: %s()\n", __func__)
+#define ACC_LOG(fmt, args...) SLOGD(fmt, ##args)
#define FREE(arg) \
do { \
} while (0);
usb_accessory_h usbAcc;
-unsigned char input[3];
-unsigned char output[3];
Evas_Object *win = NULL;
Evas_Object *bg = NULL;
void connect_acc_cb(void *data)
{
- ACC_LOG("ENTER: connect_acc_cb()\n");
- ACC_LOG("EXIT: connect_acc_cb()\n");
+ ACC_LOG("ENTER: connect_acc_cb()");
+ ACC_LOG("EXIT: connect_acc_cb()");
}
void disconnect_acc_cb(void *data)
{
- ACC_LOG("ENTER: disconnect_acc_cb()\n");
+ ACC_LOG("ENTER: disconnect_acc_cb()");
int ret = usb_accessory_connection_unset_cb();
if (ret < 0) {
- ACC_LOG("FAIL: usb_accessory_connection_unset_cb()\n");
+ ACC_LOG("FAIL: usb_accessory_connection_unset_cb()");
}
ret = usb_accessory_destroy(usbAcc);
if (ret < 0){
- ACC_LOG("FAIL: usb_accessory_destroy(&usbAcc)\n");
+ ACC_LOG("FAIL: usb_accessory_destroy(&usbAcc)");
}
elm_exit();
- ACC_LOG("EXIT: disconnect_acc_cb()\n");
+ ACC_LOG("EXIT: disconnect_acc_cb()");
}
void connection_cb_func(usb_accessory_h accessory, bool isConnected, void *data)
{
- ACC_LOG("ENTER: connection_cb_func()\n");
+ ACC_LOG("ENTER: connection_cb_func()");
if (isConnected == true) {
connect_acc_cb(accessory);
} else {
disconnect_acc_cb(accessory);
}
- ACC_LOG("EXIT: connection_cb_func()\n");
+ ACC_LOG("EXIT: connection_cb_func()");
}
-static void send_request()
+static void send_request(unsigned char input[], int len)
{
- ACC_LOG("ENTER: send_request()\n");
+ ACC_LOG("ENTER: send_request()");
char str[64];
- FILE *fp = NULL;
- int ret = usb_accessory_open(usbAcc, &fp);
+ FILE *fp;
+ int ret;
+ unsigned char output[3];
+
+ ret = usb_accessory_open(usbAcc, &fp);
if (ret < 0) {
- ACC_LOG("FAIL: usb_accessory_open(usbAcc, fp)\n");
+ ACC_LOG("FAIL: usb_accessory_open(usbAcc, fp)");
return ;
}
- ACC_LOG("fd : %d\n", (int)fp);
- if (fp <= 0) {
+ if (!fp) {
disconnect_acc_cb(usbAcc);
+ return ;
}
- ret = fwrite(input, 3, 1, fp);
+ ACC_LOG("Before fwrite(), len: %d", len);
+
+ ret = fwrite(input, len, 1, fp);
if (ret < 0) {
- ACC_LOG("FAIL: fwrite(input, 1, 3, fp)\n");
+ ACC_LOG("FAIL: fwrite()");
return ;
}
- ret = fread(output, 3, 1, fp);
+
+ ACC_LOG("After fwrite()");
+
+ ret = fread(output, sizeof(output), 1, fp);
if (ret < 0) {
- ACC_LOG("FAIL: fread(output, 1, 3, fp)\n");
+ ACC_LOG("FAIL: fread()");
return ;
}
- ACC_LOG("OUTPUT: %d, %d, %d\n", output[0], output[1], output[2]);
- snprintf(str, 64, "Input: Type %d<br>Output: %d, %d, %d", input[1], output[0], output[1], output[2]);
+
+ ACC_LOG("OUTPUT: %d, %d, %d", output[0], output[1], output[2]);
+ snprintf(str, sizeof(str), "Input: Type %d<br>Output: %d, %d, %d",
+ input[1], output[0], output[1], output[2]);
launch_popup(str);
+
ret = fclose(fp);
if (0 != ret) {
- ACC_LOG("FAIL: fclose(fp)\n");
+ ACC_LOG("FAIL: fclose()");
return ;
}
- ACC_LOG("EXIT: send_request()\n");
+
+ ACC_LOG("EXIT: send_request()");
}
static void on_click_1(void *data, Evas_Object *obj, void *event_info)
{
- ACC_LOG("ENTER: on_click_1()\n");
+ ACC_LOG("ENTER: on_click_1()");
+ unsigned char input[3];
+
input[0] = 0x2;
input[1] = 0x1;
input[2] = 0x1;
- send_request();
- ACC_LOG("EXIT: on_click_1()\n");
+
+ send_request(input, sizeof(input));
+ ACC_LOG("EXIT: on_click_1()");
}
static void on_click_2(void *data, Evas_Object *obj, void *event_info)
{
- ACC_LOG("ENTER: on_click_2()\n");
+ ACC_LOG("ENTER: on_click_2()");
+ unsigned char input[3];
+
input[0] = 0x2;
input[1] = 0x2;
input[2] = 0x1;
- send_request();
- ACC_LOG("EXIT: on_click_2()\n");
+
+ send_request(input, sizeof(input));
+ ACC_LOG("EXIT: on_click_2()");
}
static void on_click_3(void *data, Evas_Object *obj, void *event_info)
{
- ACC_LOG("ENTER: on_click_3()\n");
+ ACC_LOG("ENTER: on_click_3()");
+ unsigned char input[3];
+
input[0] = 0x2;
input[1] = 0x3;
input[2] = 0x1;
- send_request();
- ACC_LOG("EXIT: on_click_3()\n");
+
+ send_request(input, sizeof(input));
+ ACC_LOG("EXIT: on_click_3()");
}
static void on_click_4(void *data, Evas_Object *obj, void *event_info)
{
- ACC_LOG("ENTER: on_click_4()\n");
+ ACC_LOG("ENTER: on_click_4()");
disconnect_acc_cb(usbAcc);
- ACC_LOG("EXIT: on_click_4()\n");
+ ACC_LOG("EXIT: on_click_4()");
}
static void register_btn_cb(usb_accessory_h accessory, bool isGranted)
{
- ACC_LOG("ENTER: register_btn_cb()\n");
- if (isGranted != true) {
+ ACC_LOG("ENTER: register_btn_cb()");
+ if (!isGranted) {
disconnect_acc_cb(usbAcc);
return ;
}
bool foreach_cb(usb_accessory_h handle, void *data)
{
- ACC_LOG("ENTER: foreach_cb()\n");
- if (!handle) return false;
- bool ret_val = true;
- int ret = -1;
- char *manufacturer = NULL;
- char *model = NULL;
- char *version = NULL;
+ ACC_LOG("ENTER: foreach_cb()");
+ int ret;
+ char *manufacturer;
+ char *model;
+ char *version;
+
+ if (!handle)
+ return false;
+
ret = usb_accessory_get_manufacturer(handle, &manufacturer);
if (ret < 0) {
- ACC_LOG("FAIL: usb_accessory_get_manufacturer(handle, &manufacturer)\n");
- return true;
+ ACC_LOG("FAIL: usb_accessory_get_manufacturer()");
+ goto out_manufacturer;
}
+
ret = usb_accessory_get_model(handle, &model);
if (ret < 0) {
- ACC_LOG("FAIL: usb_accessory_get_model(handle, &model)\n");
- return true;
+ ACC_LOG("FAIL: usb_accessory_get_model()");
+ goto out_model;
}
+
ret = usb_accessory_get_version(handle, &version);
if (ret < 0) {
- ACC_LOG("FAIL: usb_accessory_get_version(handle, &version)");
- return true;
+ ACC_LOG("FAIL: usb_accessory_get_version()");
+ goto out_version;
}
- if (!strncmp(manufacturer, "Google, Inc.", strlen("Google, Inc."))
- && !strncmp(model, "DemoKit", strlen("DemoKit"))
- && !strncmp(version, "1.0", strlen("1.0"))) {
+ ACC_LOG("Manufacturer(%s), model(%s), version(%s)", manufacturer, model, version);
+
+ if (!strncmp(manufacturer, "Tizen", strlen("Tizen"))
+ && !strncmp(model, "DemoKit", strlen("DemoKit"))
+ && !strncmp(version, "1.0", strlen("1.0"))) {
ret = usb_accessory_clone(handle, &usbAcc);
- if (ret != USB_ERROR_NONE) {
- ACC_LOG("FAIL: usb_accessory_clone(handle, &usbAcc)\n");
- ret_val = true;
- } else {
- ret_val = false;
+ if (ret == USB_ERROR_NONE) {
+ FREE(version);
+ FREE(model);
+ FREE(manufacturer);
+ ACC_LOG("EXIT: foreach_cb()");
+ return false;
}
- } else {
- ret_val = true;
}
- FREE(manufacturer);
- FREE(model);
+
+out_version:
FREE(version);
+out_model:
+ FREE(model);
+out_manufacturer:
+ FREE(manufacturer);
- ACC_LOG("EXIT: foreach_cb()\n");
- return ret_val;
+ ACC_LOG("EXIT: foreach_cb()");
+ return true;
}
int main(int argc, char **argv)
{
ACC_LOG("ENTER: MAIN()");
- bool ret = false;
+ bool ret;
+ bool connected;
+ bool perm;
usbAcc = NULL;
ret = usb_accessory_set_connection_changed_cb(connection_cb_func, usbAcc);
if (ret < 0) {
- ACC_LOG("FAIL: usb_accessory_set_connection_changed_cb()\n");
+ ACC_LOG("FAIL: usb_accessory_set_connection_changed_cb()");
return -1;
}
+
/* Check whether or not accessory is connected */
- bool connected;
ret = usb_accessory_is_connected(NULL, &connected);
if (ret < 0) {
- ACC_LOG("FAIL: usb_accessory_is_connected(NULL, &connected)\n");
+ ACC_LOG("FAIL: usb_accessory_is_connected(NULL, &connected)");
return -1;
}
- if (connected == false) {
- ACC_LOG("Accessory is not connected\n");
+ if (!connected) {
+ ACC_LOG("Accessory is not connected");
disconnect_acc_cb(NULL);
exit(0);
}
/* Retrieve an accessory which is one of the accessories connected and matches to this app */
ret = usb_accessory_foreach_attached(foreach_cb, &usbAcc);
if (ret < 0) {
- ACC_LOG("FAIL: usb_accessory_foreach_attached(foreach_cb, usbAcc)\n");
+ ACC_LOG("FAIL: usb_accessory_foreach_attached(foreach_cb, usbAcc)");
disconnect_acc_cb(NULL);
return -1;
}
- if (usbAcc == NULL) {
- ACC_LOG("Accessory is NULL\n");
+ if (!usbAcc) {
+ ACC_LOG("Accessory is NULL");
disconnect_acc_cb(NULL);
return -1;
}
/* Check whether or not this app has permission to open the accessory */
- bool perm;
ret = usb_accessory_has_permission(usbAcc, &perm);
if (ret < 0) {
- ACC_LOG("FAIL: usb_accessory_has_permission(usbAcc)\n");
+ ACC_LOG("FAIL: usb_accessory_has_permission(usbAcc)");
return -1;
}
evas_object_move(btn4, 100, 950);
evas_object_show(btn4);
- if (perm == true) {
+ if (perm) {
register_btn_cb(usbAcc, true);
} else {
ret = usb_accessory_request_permission(usbAcc, register_btn_cb, NULL);
<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">
+ <ui-application appid="acc_test" exec="/opt/usr/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>
--- /dev/null
+<manifest>
+<request>
+ <domain name="_"/>
+</request>
+</manifest>
Name: acc_test
Summary: A test program for usb accessory
-Version: 0.0.1
+Version: 0.0.2
Release: 1
Group: TO_BE/FILLED_IN
License: TO BE FILLED IN
Source0: %{name}-%{version}.tar.gz
+Source1: acc_test.manifest
BuildRequires: cmake
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(capi-system-usb-accessory)
%install
rm -rf %{buildroot}
+
+cp %{SOURCE1} .
+
%make_install
%post
-chown 5000:5000 /opt/apps/acc_test/bin/acc_test
+chown 5000:5000 /opt/usr/apps/acc_test/bin/acc_test
%files
+%manifest acc_test.manifest
%attr(644,root,root) /opt/share/packages/acc_test.xml
-%attr(555,root,root) /opt/apps/acc_test/bin/acc_test
+%attr(555,root,root) /opt/usr/apps/acc_test/bin/acc_test