--- /dev/null
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-system-usb-accessory")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(dependents "dlog vconf capi-base-common aul")
+SET(pc_dependents "capi-base-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+FOREACH(flag ${${fw_name}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DTIZEN_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+
+aux_source_directory(src SOURCES)
+ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+SET_TARGET_PROPERTIES(${fw_name}
+ PROPERTIES
+ VERSION ${FULLVER}
+ SOVERSION ${MAJORVER}
+ CLEAN_DIRECT_OUTPUT 1
+)
+
+
+INSTALL(TARGETS ${fw_name} DESTINATION lib)
+INSTALL(
+ DIRECTORY ${INC_DIR}/ DESTINATION include/system
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "${INC_DIR}/*.h"
+ )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_dependents})
+SET(PC_LDFLAGS -l${fw_name})
+
+CONFIGURE_FILE(
+ ${fw_name}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig)
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+ DEPENDS clean
+ COMMENT "distribution clean"
+ COMMAND find
+ ARGS .
+ -not -name config.cmake -and \(
+ -name tester.c -or
+ -name Testing -or
+ -name CMakeFiles -or
+ -name cmake.depends -or
+ -name cmake.check_depends -or
+ -name CMakeCache.txt -or
+ -name cmake.check_cache -or
+ -name *.cmake -or
+ -name Makefile -or
+ -name core -or
+ -name core.* -or
+ -name gmon.out -or
+ -name install_manifest.txt -or
+ -name *.pc -or
+ -name *~ \)
+ | grep -v TC | xargs rm -rf
+ TARGET distclean
+ VERBATIM
+)
+
+ENDIF(UNIX)
+
--- /dev/null
+#!/bin/sh
+
+. ./config
+export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH # tetware root path
+export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path
+export PATH=$TET_TARGET_PATH/bin:$PATH
+export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH
+export TET_ROOT=$TET_TARGET_PATH
--- /dev/null
+#!/bin/sh
+. ./config
+export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path
+export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target
+export PATH=$TET_TARGET_PATH/bin:$PATH
+export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH
+export TET_ROOT=$TET_TARGET_PATH
--- /dev/null
+#!/bin/sh
+
+. ./_export_env.sh # setting environment variables
+
+export TET_SUITE_ROOT=`pwd`
+FILE_NAME_EXTENSION=`date +%s`
+
+RESULT_DIR=results
+HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html
+JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal
+
+mkdir -p $RESULT_DIR
+
+tcc -c -p ./
+tcc -b -j $JOURNAL_RESULT -p ./
+grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT
--- /dev/null
+#!/bin/sh
+
+. ./_export_env.sh # setting environment variables
+
+export TET_SUITE_ROOT=`pwd`
+RESULT_DIR=results
+
+tcc -c -p ./ # executing tcc, with clean option (-c)
+rm -r $RESULT_DIR
+rm -r tet_tmp_dir
+rm testcase/tet_captured
--- /dev/null
+TET_INSTALL_HOST_PATH=/home/idkiller/work/tetware/TETware
+TET_INSTALL_TARGET_PATH=/mnt/nfs/tetware/TETware
--- /dev/null
+#!/bin/sh
+
+. ./_export_target_env.sh # setting environment variables
+
+export TET_SUITE_ROOT=`pwd`
+FILE_NAME_EXTENSION=`date +%s`
+
+RESULT_DIR=results
+HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html
+JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal
+
+mkdir -p $RESULT_DIR
+
+tcc -e -j $JOURNAL_RESULT -p ./
+grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT
--- /dev/null
+CC = gcc
+
+C_FILES = $(shell ls *.c)
+
+PKGS = dlog capi-system-usb-accessory
+
+#TET_ROOT = /home/idkiller/work/tetware/TETware/tetware-target
+
+LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o
+LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s
+LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s
+LDFLAGS += `pkg-config --libs $(PKGS)`
+
+CFLAGS += `pkg-config --cflags $(PKGS)`
+CFLAGS += -I.
+CFLAGS += -I$(TET_ROOT)/inc/tet3
+CFLAGS += -Wall
+
+#TARGETS = $(C_FILES:%.c=tc-%)
+TCS := $(shell ls -1 *.c | cut -d. -f1)
+
+all: $(TCS)
+
+%: %.c
+ $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)
+
+clean:
+ rm -f $(TCS)
--- /dev/null
+/testcase/utc_system_usb_accessory.c
--- /dev/null
+all
+ ^TEST
+##### Scenarios for TEST #####
+
+# Test scenario
+TEST
+ :include:/testcase/tslist
--- /dev/null
+TET_OUTPUT_CAPTURE=True # capture option for build operation checking
+TET_BUILD_TOOL=make # build with using make command
+TET_BUILD_FILE=-f Makefile # execution file (Makefile) for build
+TET_API_COMPLIANT=True # use TET API in Test Case ?
+TET_PASS_TC_NAME=True # report passed TC name in Journal file?
--- /dev/null
+TET_OUTPUT_CAPTURE=True # capture option
+TET_CLEAN_TOOL= make clean # clean tool
+TET_CLEAN_FILE= Makefile # file for clean
+TET_API_COMPLIANT=True # TET API useage
+TET_PASS_TC_NAME=True # showing name , passed TC
--- /dev/null
+TET_OUTPUT_CAPTURE=True # capturing execution or not
+TET_EXEC_TOOL= # ex) exec : execution tool set up/ Optional
+TET_EXEC_FILE= # ex) exectool : execution file/ Optional
+TET_API_COMPLIANT=True # Test case or Tool usesTET API?
+TET_PASS_TC_NAME=True # showing Passed TC name ?
--- /dev/null
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=/usr/include/system
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
+
--- /dev/null
+/usr/include/*
+/usr/include/*/*
+/usr/lib/pkgconfig/*.pc
+
--- /dev/null
+/usr/lib/lib*.so*
+#/opt/apps/acc_test/bin/acc_test
+#/opt/share/applications/acc_test.desktop
--- /dev/null
+capi-system-usb-accessory (0.0.1-1) unstable; urgency=low
+
+ * Initial release.
+ * Git: slp-source.sec.samsung.net:slp/api/usb-accessory
+ * Tag: capi-system-usb-accessory_0.0.1-1
+
+ -- pius lee <pius.lee@samsung.com> Tue, 05 Jun 2012 00:19:00 +0900
--- /dev/null
+
+Source: capi-system-usb-accessory
+Section: libs
+Priority: extra
+Maintainer: pius lee <pius.lee@samsung.com>
+Build-Depends: debhelper (>= 5), dlog-dev, libglib2.0-dev, capi-base-common-dev, libvconf-dev
+
+Package: capi-system-usb-accessory
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: A Device library in Tizen Native API
+
+Package: capi-system-usb-accessory-dev
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, capi-system-usb-accessory (= ${Source-Version}), dlog-dev, capi-base-common-dev, libvconf-dev
+Description: A Device library in Tizen Native API (DEV)
+
+Package: capi-system-usb-accessory-dbg
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, capi-system-usb-accessory (= ${Source-Version})
+Description: A Device library in Tizen Native API (DBG)
+
--- /dev/null
+#!/usr/bin/make -f
+
+FULLVER ?= $(shell dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2 | cut -d '-' -f 1)
+MAJORVER ?= $(shell echo $(FULLVER) | cut -d '.' -f 1)
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+else
+ CFLAGS += -O2
+endif
+CMAKE_ROOT_DIR ?= $(CURDIR)
+CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp
+
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER}
+ touch configure-stamp
+
+
+build: build-stamp
+build-stamp: configure-stamp
+ dh_testdir
+ cd $(CMAKE_BUILD_DIR) && $(MAKE)
+ touch $@
+
+clean:
+ cd $(CMAKE_ROOT_DIR)
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+ rm -f `find . -name *.pc`
+# rm -f `find . -name *.desktop`
+ rm -rf $(CMAKE_BUILD_DIR)
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+binary-indep: build install
+
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_installexamples
+ dh_install --sourcedir=debian/tmp
+ dh_installman
+ dh_link
+ dh_strip --dbg-package=capi-system-usb-accessory-dbg
+ dh_fixperms
+ dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
+
--- /dev/null
+/*
+ * Copyright (c) 2011 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_SYSTEM_USB_ACCESSORY_H__
+#define __TIZEN_SYSTEM_USB_ACCESSORY_H__
+
+#include <stdio.h>
+#include <tizen.h>
+
+/**
+ * @addtogroup CAPI_SYSTEM_USB_ACCESSORY_MODULE
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumerations of error code for usb accessory.
+ */
+typedef enum
+{
+ USB_ERROR_NONE = TIZEN_ERROR_NONE,
+ 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_e;
+
+/**
+ * @brief The USB Accessory handle.
+ */
+typedef struct usb_accessory_s* usb_accessory_h;
+
+/**
+ * @brief Called when the usb accessory is connected or disconnected.
+ *
+ * @remark
+ * the handle of accessory will be free after end of usb_accessory_connection_cb()
+ *
+ * @param[in] accessory The handle of the attached usb accessory.
+ * @param[in] is_connected True when connected or False when connection is lost.
+ * @param[in] data The user data passed from the register function.
+ *
+ * @see usb_accessory_connection_set_cb()
+ */
+typedef void (*usb_accessory_connection_changed_cb)(usb_accessory_h accessory, bool is_connected, void *data);
+
+/**
+ * @brief Called when the permission of usb accessory is granted.
+ *
+ * @remark
+ * the handle of accessory will be free after end of usb_accessory_request_permission_cb()
+ *
+ * @param[in] accessory The handle of the attached usb accessory.
+ * @param[in] is_granted The permission of usb accessory.
+ *
+ * @see usb_accessory_request_permission()
+ */
+typedef void (*usb_accessory_permission_response_cb)(usb_accessory_h accessory, bool is_granted);
+
+/**
+ * @brief Called to retrieve the handles of usb accessory.
+ *
+ * @remark
+ * the handle of accessory will be free after end of usb_accessory_attached_cb()
+ *
+ * @param[in] handle The handle of the attached usb accessory.
+ * @param[in] data The user data passed from the foreach function.
+ *
+ * @return @c true to continue with the next iteration of the loop, \n
+ * @c false to break out of the loop.
+ *
+ * @see usb_accessory_foreach_attached()
+ */
+typedef bool (*usb_accessory_attached_cb)(usb_accessory_h handle, void *data);
+
+/**
+ * @brief Clone the handle of usb accessory.
+ *
+ * @remark
+ * the cloned handle must be destroyed by #usb_accessory_destroy()
+ *
+ * @param[in] handle The usb accessory handle that want to copy.
+ * @param[out] cloned_handle The cloned usb accessory handle.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see usb_accessory_destroy()
+ */
+int usb_accessory_clone(usb_accessory_h handle, usb_accessory_h* cloned_handle);
+
+/**
+ * @brief Destroy the handle of usb accessory.
+ *
+ * @param[in] handle The handle of the attached usb accessory.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_destroy(usb_accessory_h handle);
+
+/**
+ * @brief Retrieves every attached usb accessory handles.
+ * @details
+ * usb_accessory_attached_cb() will be called once for each handle of attached usb accessory.
+ * if usb_accessory_attached_cb() callback function returns false, then iteration will be finished.
+ *
+ * @remark
+ * the handle of accessory will be free after end of usb_accessory_attached_cb().
+ *
+ * @param[in] callback The iteration callback function.
+ * @param[in] user_data The user data to be passed to the callback function.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_foreach_attached(usb_accessory_attached_cb callback, void *user_data);
+
+/**
+ * @brief Register callback function to be invoked when usb accessory connected or disconnected.
+ * @details
+ * The handle of attached usb accessory handle will be passed to usb_accessory_connection_cb().
+ * And status of connection will be also passed to callback function.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ * @param[in] callback The callback function to register.
+ * @param[in] user_data The user data to be passed to the callback function.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see usb_accessory_connection_unset_cb()
+ *
+ */
+int usb_accessory_set_connection_changed_cb(usb_accessory_connection_changed_cb callback, void* user_data);
+
+/**
+ * @brief Unregister the usb accessory connection callback function.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see usb_accessory_connection_set_cb()
+ */
+int usb_accessory_connection_unset_cb(void);
+
+/**
+ * @brief Check whether or not the accessory has permission to access to the host.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ * @param[out] is_granted The permission to access to the host.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_has_permission(usb_accessory_h accessory, bool *is_granted);
+
+/**
+ * @brief opens a file descriptor for reading and writing data to the usb accessory.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ * @param[out] fd opened File descriptor for usb accessory.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_open(usb_accessory_h accessory, FILE **fd);
+
+/**
+ * @brief Get description of the accessory.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ * @param[out] description The description of the usbaccessory.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_get_description(usb_accessory_h accessory, char** description);
+
+/**
+ * @brief Get manufacturer name of the accessory.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ * @param[out] manufacturer The name of manufacturer.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_get_manufacturer(usb_accessory_h accessory, char** manufacturer);
+
+/**
+ * @brief Get model name of the accessory.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ * @param[out] model The model name of usb accessory.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_get_model(usb_accessory_h accessory, char** model);
+
+/**
+ * @brief Get unique serial number of the accessory.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ * @param[out] serial The serial of usb accessory.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_get_serial(usb_accessory_h accessory, char** serial);
+
+/**
+ * @brief Get version of the accessory.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ * @param[out] version The version of usb accessory.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_get_version(usb_accessory_h accessory, char** version);
+
+/**
+ * @brief Check whether or not the connection of the usb accessory.
+ *
+ * @param[in] accessory The usb accessory handle to check.
+ * @param[out] is_connected The connection status.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ */
+int usb_accessory_is_connected(usb_accessory_h accessory, bool *is_connected);
+
+/**
+ * @brief Request permission to user for usb accessory.
+ * @details
+ * The usb accessory handle and boolean passed to callback function that indicating whether permission was granted by the user.
+ *
+ * @param[in] accessory The attached usb accessory handle.
+ * @param[in] callback The callback function to register.
+ * @param[in] user_data The user data to be passed to the callback function.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #USB_ERROR_NONE Successful
+ * @retval #USB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #USB_ERROR_OPERATION_FAILED Operation failed
+ *
+ */
+int usb_accessory_request_permission(usb_accessory_h accessory, usb_accessory_permission_response_cb callback, void* user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif // __TIZEN_SYSTEM_USB_ACCESSORY_H__
+
--- /dev/null
+/*
+ * Copyright (c) 2011 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_SYSTEM_USB_ACCESSORY_PRIVATE_H__
+#define __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__
+
+#include <stdio.h>
+#include <libintl.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <dlog.h>
+#include <unistd.h>
+#include <aul.h>
+#include <vconf.h>
+#include <stdlib.h>
+//#include <Ecore.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__)
+
+#define FREE(arg) \
+ do { \
+ if(arg) { \
+ free((void *)arg); \
+ arg = NULL; \
+ } \
+ } 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,
+ IPC_SUCCESS
+} 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
+} 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];
+};
+
+struct usb_accessory_list {
+ struct usb_accessory_s *accessory;
+ struct usb_accessory_list *next;
+};
+
+struct AccCbData {
+ void *user_data;
+ void (*connection_cb_func)(struct usb_accessory_s *accessory, bool is_connected, void *data);
+ void (*request_perm_cb_func)(struct usb_accessory_s *accessory, bool is_granted);
+ 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);
+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);
+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);
+#endif /* __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__ */
+
--- /dev/null
+Name: capi-system-usb-accessory
+Summary: A usb accessory library in TIZEN C API
+Version: 0.0.1
+Release: 3
+Group: TO_BE/FILLED_IN
+License: TO BE FILLED IN
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(aul)
+#BuildRequires: pkgconfig(ecore-x)
+#BuildRequires: pkgconfig(elementary)
+#BuildRequires: pkgconfig(appcore-efl)
+
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description
+
+
+%package devel
+Summary: A accessory library in TIZEN C API (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+
+
+
+%prep
+%setup -q
+
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+#%post -p /sbin/ldconfig
+%post
+/sbin/ldconfig
+#chown 5000:5000 /opt/apps/acc_test/bin/acc_test
+
+#%postun -p /sbin/ldconfig
+%postun
+/sbin/ldconfig
+
+
+%files
+%{_libdir}/libcapi-system-usb-accessory.so.*
+#%attr(644,root,root) /opt/share/applications/acc_test.desktop
+#%attr(555,root,root) /opt/apps/acc_test/bin/acc_test
+
+%files devel
+%{_includedir}/system/usb_accessory.h
+%{_libdir}/pkgconfig/*.pc
+%{_libdir}/libcapi-system-usb-accessory.so
+
+
--- /dev/null
+/*
+ * Copyright (c) 2011 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 "usb_accessory.h"
+#include "usb_accessory_private.h"
+
+struct AccCbData *accCbData;
+
+int usb_accessory_clone(usb_accessory_h handle, usb_accessory_h* cloned_handle)
+{
+ __USB_FUNC_ENTER__ ;
+ 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);
+
+ (*cloned_handle)->accPermission = false;
+
+ __USB_FUNC_EXIT__ ;
+ return USB_ERROR_NONE;
+}
+
+int usb_accessory_destroy(usb_accessory_h handle)
+{
+ __USB_FUNC_ENTER__ ;
+ if (!handle) return USB_ERROR_INVALID_PARAMETER;
+ FREE(handle);
+ __USB_FUNC_EXIT__ ;
+ return USB_ERROR_NONE;
+}
+
+int usb_accessory_foreach_attached(usb_accessory_attached_cb callback, void *user_data)
+{
+ __USB_FUNC_ENTER__ ;
+ struct usb_accessory_list *accList = NULL;
+ struct usb_accessory_list *tmpList = NULL;
+ bool ret = false;
+ ret = getAccList(&accList);
+ um_retvm_if(ret == false, -1, "FAIL: getAccList(accList)\n");
+ um_retvm_if(accList == NULL, -1, "ERROR: accList == NULL\n");
+
+ ret = true;
+ tmpList = accList;
+ while (ret) {
+ if (tmpList == NULL || tmpList->accessory == NULL) {
+ break;
+ }
+ ret = callback(tmpList->accessory, user_data);
+ if (ret) {
+ tmpList = tmpList->next;
+ }
+ }
+
+ ret = freeAccList(accList);
+ um_retvm_if(ret == false, USB_ERROR_OPERATION_FAILED, "FAIL: freeAccList(accList)\n");
+
+ __USB_FUNC_EXIT__ ;
+ return USB_ERROR_NONE;
+}
+
+
+int usb_accessory_set_connection_changed_cb(usb_accessory_connection_changed_cb callback, void* user_data)
+{
+ __USB_FUNC_ENTER__ ;
+ int ret = -1;
+ accCbData = (struct AccCbData *)malloc(sizeof(struct AccCbData));
+ 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");
+ __USB_FUNC_EXIT__ ;
+ return USB_ERROR_NONE;
+}
+
+
+int usb_accessory_connection_unset_cb()
+{
+ __USB_FUNC_ENTER__ ;
+ 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");
+ }
+ __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;
+ if (accessory->accPermission == true) {
+ __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_PERMISSION_DENIED, "FAIL: ipc_request_client_init(&sock_remote)\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 = ipc_request_client_close(&sock_remote);
+ um_retvm_if(ret < 0, USB_ERROR_PERMISSION_DENIED, "FAIL: ipc_request_client_close(&sock_remote)\n");
+
+ FREE(app_id);
+
+ 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;
+ }
+}
+
+
+int usb_accessory_open(usb_accessory_h accessory, FILE **fd)
+{
+ __USB_FUNC_ENTER__ ;
+ if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+ if (accessory->accPermission == true) {
+ *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;
+}
+
+
+int usb_accessory_get_description(usb_accessory_h accessory, char** description)
+{
+ __USB_FUNC_ENTER__ ;
+ if (!accessory) return USB_ERROR_INVALID_PARAMETER;
+ *description = strdup(accessory->description);
+ __USB_FUNC_ENTER__ ;
+ 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;
+ *manufacturer = strdup(accessory->manufacturer);
+ __USB_FUNC_ENTER__ ;
+ 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;
+ *model = strdup(accessory->model);
+ __USB_FUNC_ENTER__ ;
+ 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;
+ *serial = strdup(accessory->serial);
+ __USB_FUNC_ENTER__ ;
+ 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;
+ *version = strdup(accessory->version);
+ __USB_FUNC_ENTER__ ;
+ return USB_ERROR_NONE;
+}
+
+
+int usb_accessory_is_connected(usb_accessory_h accessory, bool* is_connected)
+{
+ __USB_FUNC_ENTER__ ;
+ 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");
+ switch (val) {
+ case VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED:
+ *is_connected = true;
+ break;
+ case VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED:
+ *is_connected = false;
+ break;
+ }
+ __USB_FUNC_EXIT__ ;
+ return USB_ERROR_NONE;
+}
+
+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 = -1;
+ guint g_ret = 0;
+ int sock_remote;
+ char buf[SOCK_STR_LEN];
+ char *app_id = get_app_id();
+ accCbData->user_data = accessory;
+ accCbData->request_perm_cb_func = callback;
+ accCbData->accessory = accessory;
+ GError *err;
+ GIOStatus gio_ret;
+
+ int fd = ipc_noti_client_init();
+ GIOChannel *g_io_ch = g_io_channel_unix_new(fd);
+ g_ret = g_io_add_watch(g_io_ch, G_IO_IN, ipc_noti_client_cb, (gpointer)accCbData);
+ um_retvm_if (0 == g_ret, USB_ERROR_PERMISSION_DENIED, "FAIL: g_io_add_watch(g_io_ch, G_IO_IN)\n");
+
+ 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);
+ FREE(app_id);
+ return USB_ERROR_PERMISSION_DENIED;
+ }
+
+ ret = request_to_usb_server(sock_remote, REQUEST_PERMISSION, buf, app_id);
+ if(ret < 0) {
+ USB_LOG("FAIL: request_to_usb_server(REQUEST_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_PERMISSION_DENIED;
+ }
+
+ FREE(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_PERMISSION_DENIED;
+ }
+
+ __USB_FUNC_EXIT__ ;
+ return USB_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2011 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 "usb_accessory_private.h"
+
+/* This function initializes socket for ipc with usb-server */
+int ipc_request_client_init(int *sock_remote)
+{
+ __USB_FUNC_ENTER__ ;
+ if (!sock_remote) return -1;
+ int len;
+ struct sockaddr_un remote;
+
+ if (((*sock_remote) = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+ perror("socket");
+ USB_LOG("FAIL: socket(AF_UNIX, SOCK_STREAM, 0)");
+ 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);
+
+ if (connect((*sock_remote), (struct sockaddr *)&remote, len) == -1) {
+ perror("connect");
+ USB_LOG("FAIL: connect((*sock_remote), (struct sockaddr *)&remote, len)");
+ 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;
+}
+
+/* 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)
+{
+ __USB_FUNC_ENTER__ ;
+ int t;
+ char str[SOCK_STR_LEN];
+
+ 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");
+ return -1;
+ }
+ if ((t = recv(sock_remote, answer, SOCK_STR_LEN, 0)) > 0) {
+ answer[t] = '\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_FUNC_EXIT__ ;
+ return 0;
+}
+
+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);
+
+ switch (input) {
+ case REQ_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:
+ permCbData->accessory->accPermission = false;
+ permCbData->request_perm_cb_func((struct usb_accessory_s*)(permCbData->user_data), false);
+ break;
+ default:
+ break;
+ }
+ __USB_FUNC_EXIT__ ;
+ return 0;
+}
+
+static int read_message(int fd, char *str, int len)
+{
+ __USB_FUNC_ENTER__;
+ int ret = -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 {
+ __USB_FUNC_EXIT__;
+ return 0;
+ }
+ }
+}
+
+int ipc_noti_client_init(void)
+{
+ __USB_FUNC_ENTER__ ;
+ int sock_local;
+ int ret = -1;
+ int len;
+ 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");
+ 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);
+ 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");
+ return -1;
+ }
+
+ ret = chown(ACC_SOCK_PATH, 5000, 5000);
+ if (ret < 0) USB_LOG("FAIL: chown(ACC_SOCK_PATH, 5000, 5000)");
+ ret = chmod(ACC_SOCK_PATH, 0777);
+ if (ret < 0) USB_LOG("FAIL: chmod(ACC_SOCK_PATH, 0777);");
+
+ if (listen (sock_local, 5) == -1) {
+ perror("listen");
+ USB_LOG("FAIL: listen (sock_local, 5)\n");
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__ ;
+ return sock_local;
+}
+
+int ipc_noti_client_close(int *sock_remote)
+{
+ __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];
+ GError *err;
+ GIOStatus gio_ret;
+
+ 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);
+ return FALSE;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+ 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_FUNC_EXIT__ ;
+ return FALSE;
+}
+
+/* This function returns the app id.
+ * After calling this function, the memory space should be freed */
+char *get_app_id()
+{
+ __USB_FUNC_ENTER__ ;
+ int pid = getpid();
+ USB_LOG("pid: %d\n", pid);
+ 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");
+ __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)
+{
+ __USB_FUNC_ENTER__ ;
+ if (attAcc == NULL) return -1;
+ struct usb_accessory_list *accList = NULL;
+ bool ret = getAccList(&accList);
+ um_retvm_if(ret == false, -1, "FAIL: getAccList(&accList)\n");
+ um_retvm_if(accList == NULL, -1, "accList == NULL\n");
+ *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);
+ ret = freeAccList(accList);
+ um_retvm_if(ret == false, -1, "FAIL: freeAccList(accList)\n");
+
+ __USB_FUNC_EXIT__ ;
+ return 0;
+}
+
+/* This func release memory of an accessory attached just now */
+static int freeChangedAcc (struct usb_accessory_s **attAcc)
+{
+ __USB_FUNC_ENTER__ ;
+ if (attAcc == NULL) return -1;
+ FREE(*attAcc);
+ __USB_FUNC_EXIT__ ;
+ return 0;
+}
+
+/* Callback function which is called when accessory vconf key is changed */
+void accessory_status_changed_cb(keynode_t *in_key, void* data)
+{
+ __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");
+
+ 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);
+ break;
+ case VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED:
+ conCbData->connection_cb_func(changedAcc, true, conCbData->user_data);
+ 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__ ;
+}
+
+/* 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++;
+ }
+ }
+ __USB_FUNC_EXIT__ ;
+ return false;
+}
+
+/* Get all element separated from a string which has all information of an accessory */
+static int getAccInfo(char *totalInfo[], struct usb_accessory_s **accessory)
+{
+ __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");
+ __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_s **accList)
+bool getAccList(struct usb_accessory_list **accList)
+{
+ __USB_FUNC_ENTER__ ;
+ if (*accList != NULL) return false;
+ *accList = (struct usb_accessory_list *)malloc(sizeof(struct usb_accessory_list));
+ 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");
+
+ 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);
+
+ ret = ipc_request_client_close(&sock_remote);
+ um_retvm_if(ret < 0, false, "FAIL: ipc_request_client_close(&sock_remote)\n");
+
+ char *tempInfo = buf;
+ ret = getAccInfo(&tempInfo, &((*accList)->accessory));
+ um_retvm_if(ret < 0, false, "FAIL: getAccInfo(&tempInfo, accList)\n");
+
+ 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);
+
+ __USB_FUNC_EXIT__ ;
+ return true;
+}
+
+/* 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);
+ }
+ __USB_FUNC_EXIT__ ;
+ return true;
+}
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(acc_test C)
+SET(SRCS acc_test.c)
+pkg_check_modules(pkgs REQUIRED eina elementary ecore-x appcore-efl aul capi-system-usb-accessory)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g ")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+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 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/)
--- /dev/null
+
+#include "usb_accessory.h"
+#include <Elementary.h>
+#include <dlog.h>
+
+#define USB_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 FREE(arg) \
+ do { \
+ if(arg) { \
+ free((void *)arg); \
+ arg = NULL; \
+ } \
+ } while (0);
+
+usb_accessory_h usbAcc;
+unsigned char input[3];
+unsigned char output[3];
+
+Evas_Object *win = NULL;
+Evas_Object *bg = NULL;
+Evas_Object *btn1 = NULL;
+Evas_Object *btn2 = NULL;
+Evas_Object *btn3 = NULL;
+Evas_Object *btn4 = NULL;
+Evas_Object *popup = NULL;
+
+static void unload_popup();
+
+static void _block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ ACC_LOG("ENTER: _block_clicked_cb()");
+ unload_popup();
+ ACC_LOG("EXIT: _block_clicked_cb()");
+}
+
+static void _timeout_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ ACC_LOG("ENTER: _timeout_cb()");
+ unload_popup();
+ ACC_LOG("EXIT: _timeout_cb()");
+}
+
+static void unload_popup()
+{
+ ACC_LOG("ENTER: unload_popup()");
+ evas_object_smart_callback_del(popup, "block,clicked", _block_clicked_cb);
+ evas_object_smart_callback_del(popup, "timeout", _timeout_cb);
+ if (popup) {
+ evas_object_del(popup);
+ popup = NULL;
+ }
+ ACC_LOG("EXIT: unload_popup()");
+}
+
+static void launch_popup(char *str)
+{
+ ACC_LOG("ENTER: launch_popup(char *str)");
+ if (!win) return;
+ if (popup) {
+ evas_object_del(popup);
+ popup = NULL;
+ }
+ popup = elm_popup_add(win);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_text_set(popup, str);
+ evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb, NULL);
+ elm_popup_timeout_set(popup, 3.0);
+ evas_object_smart_callback_add(popup, "timeout", _timeout_cb, NULL);
+ evas_object_show(popup);
+ ACC_LOG("EXIT: launch_popup(char *str)");
+}
+
+void connect_acc_cb(void *data)
+{
+ ACC_LOG("ENTER: connect_acc_cb()\n");
+ ACC_LOG("EXIT: connect_acc_cb()\n");
+}
+
+void disconnect_acc_cb(void *data)
+{
+ ACC_LOG("ENTER: disconnect_acc_cb()\n");
+ int ret = usb_accessory_connection_unset_cb();
+ if (ret < 0) {
+ ACC_LOG("FAIL: usb_accessory_connection_unset_cb()\n");
+ }
+ ret = usb_accessory_destroy(usbAcc);
+ if (ret < 0){
+ ACC_LOG("FAIL: usb_accessory_destroy(&usbAcc)\n");
+ }
+ elm_exit();
+ ACC_LOG("EXIT: disconnect_acc_cb()\n");
+}
+
+void connection_cb_func(usb_accessory_h accessory, bool isConnected, void *data)
+{
+ ACC_LOG("ENTER: connection_cb_func()\n");
+ if (isConnected == true) {
+ connect_acc_cb(accessory);
+ } else {
+ disconnect_acc_cb(accessory);
+ }
+ ACC_LOG("EXIT: connection_cb_func()\n");
+}
+
+static void send_request()
+{
+ ACC_LOG("ENTER: send_request()\n");
+ char str[64];
+ FILE *fp = NULL;
+ int ret = usb_accessory_open(usbAcc, &fp);
+ if (ret < 0) {
+ ACC_LOG("FAIL: usb_accessory_open(usbAcc, fp)\n");
+ return ;
+ }
+ ACC_LOG("fd : %d\n", (int)fp);
+ if (fp <= 0) {
+ disconnect_acc_cb(usbAcc);
+ }
+
+ ret = fwrite(input, 3, 1, fp);
+ if (ret < 0) {
+ ACC_LOG("FAIL: fwrite(input, 1, 3, fp)\n");
+ return ;
+ }
+ ret = fread(output, 3, 1, fp);
+ if (ret < 0) {
+ ACC_LOG("FAIL: fread(output, 1, 3, fp)\n");
+ 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]);
+ launch_popup(str);
+ ret = fclose(fp);
+ if (0 != ret) {
+ ACC_LOG("FAIL: fclose(fp)\n");
+ return ;
+ }
+ ACC_LOG("EXIT: send_request()\n");
+}
+
+static void on_click_1(void *data, Evas_Object *obj, void *event_info)
+{
+ ACC_LOG("ENTER: on_click_1()\n");
+ input[0] = 0x2;
+ input[1] = 0x1;
+ input[2] = 0x1;
+ send_request();
+ ACC_LOG("EXIT: on_click_1()\n");
+}
+
+static void on_click_2(void *data, Evas_Object *obj, void *event_info)
+{
+ ACC_LOG("ENTER: on_click_2()\n");
+ input[0] = 0x2;
+ input[1] = 0x2;
+ input[2] = 0x1;
+ send_request();
+ ACC_LOG("EXIT: on_click_2()\n");
+}
+
+static void on_click_3(void *data, Evas_Object *obj, void *event_info)
+{
+ ACC_LOG("ENTER: on_click_3()\n");
+ input[0] = 0x2;
+ input[1] = 0x3;
+ input[2] = 0x1;
+ send_request();
+ ACC_LOG("EXIT: on_click_3()\n");
+}
+
+static void on_click_4(void *data, Evas_Object *obj, void *event_info)
+{
+ ACC_LOG("ENTER: on_click_4()\n");
+ disconnect_acc_cb(usbAcc);
+ ACC_LOG("EXIT: on_click_4()\n");
+}
+
+static void register_btn_cb(usb_accessory_h accessory, bool isGranted)
+{
+ ACC_LOG("ENTER: register_btn_cb()\n");
+ if (isGranted != true) {
+ disconnect_acc_cb(usbAcc);
+ return ;
+ }
+ evas_object_smart_callback_add(btn1, "clicked", on_click_1, NULL);
+ evas_object_smart_callback_add(btn2, "clicked", on_click_2, NULL);
+ evas_object_smart_callback_add(btn3, "clicked", on_click_3, NULL);
+ evas_object_smart_callback_add(btn4, "clicked", on_click_4, NULL);
+ ACC_LOG("EXIT: register_btn_cb()\n");
+}
+
+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;
+ ret = usb_accessory_get_manufacturer(handle, &manufacturer);
+ if (ret < 0) {
+ ACC_LOG("FAIL: usb_accessory_get_manufacturer(handle, &manufacturer)\n");
+ return true;
+ }
+ ret = usb_accessory_get_model(handle, &model);
+ if (ret < 0) {
+ ACC_LOG("FAIL: usb_accessory_get_model(handle, &model)\n");
+ return true;
+ }
+ ret = usb_accessory_get_version(handle, &version);
+ if (ret < 0) {
+ ACC_LOG("FAIL: usb_accessory_get_version(handle, &version)");
+ return true;
+ }
+
+ if (!strncmp(manufacturer, "Google, Inc.", strlen("Google, Inc."))
+ && !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;
+ }
+ } else {
+ ret_val = true;
+ }
+ FREE(manufacturer);
+ FREE(model);
+ FREE(version);
+
+ ACC_LOG("EXIT: foreach_cb()\n");
+ return ret_val;
+}
+
+int main(int argc, char **argv)
+{
+ ACC_LOG("ENTER: MAIN()");
+ bool ret = false;
+ 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");
+ 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");
+ return -1;
+ }
+ if (connected == false) {
+ ACC_LOG("Accessory is not connected\n");
+ 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");
+ disconnect_acc_cb(NULL);
+ return -1;
+ }
+ if (usbAcc == NULL) {
+ ACC_LOG("Accessory is NULL\n");
+ 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");
+ return -1;
+ }
+
+ elm_init(argc, argv);
+ win = elm_win_add(NULL, "Accessory", ELM_WIN_BASIC);
+ elm_win_title_set(win, "Usb Accessory Test");
+ elm_win_autodel_set(win, EINA_TRUE);
+ elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
+ evas_object_resize(win, 240, 60);
+ evas_object_show(win);
+
+ bg = elm_bg_add(win);
+ evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(win, bg);
+ evas_object_show(bg);
+
+ btn1 = elm_button_add(win);
+ elm_object_text_set(btn1, "Type 1");
+ evas_object_resize(btn1, 300, 200);
+ evas_object_move(btn1, 100, 200);
+ evas_object_show(btn1);
+
+ btn2 = elm_button_add(win);
+ elm_object_text_set(btn2, "Type 2");
+ evas_object_resize(btn2, 300, 200);
+ evas_object_move(btn2, 100,450);
+ evas_object_show(btn2);
+
+ btn3 = elm_button_add(win);
+ elm_object_text_set(btn3, "Type 3");
+ evas_object_resize(btn3, 300, 200);
+ evas_object_move(btn3, 100, 700);
+ evas_object_show(btn3);
+
+ btn4 = elm_button_add(win);
+ elm_object_text_set(btn4, "Exit");
+ evas_object_resize(btn4, 300, 200);
+ evas_object_move(btn4, 100, 950);
+ evas_object_show(btn4);
+
+ if (perm == true) {
+ register_btn_cb(usbAcc, true);
+ } else {
+ ret = usb_accessory_request_permission(usbAcc, register_btn_cb, NULL);
+ if (ret < 0) {
+ disconnect_acc_cb(NULL);
+ }
+ }
+
+ elm_run();
+
+ elm_shutdown();
+ return 0;
+}
--- /dev/null
+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
--- /dev/null
+/usr/lib/lib*.so*
+/opt/apps/acc_test/bin/acc_test
+/opt/share/applications/acc_test.desktop
--- /dev/null
+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
+
+ -- Taeyoung Kim <ty317.kim@samsung.com> Tue, 05 Jun 2012 00:19:00 +0900
--- /dev/null
+
+Source: acc_test
+Section: tools
+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
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: A test package for usb accessory
+
+Package: acc-test-dbg
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, acc-test (= ${Source-Version})
+Description: A test package for testing usb accessory
+
--- /dev/null
+#!/usr/bin/make -f
+
+FULLVER ?= $(shell dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2 | cut -d '-' -f 1)
+MAJORVER ?= $(shell echo $(FULLVER) | cut -d '.' -f 1)
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+else
+ CFLAGS += -O2
+endif
+CMAKE_ROOT_DIR ?= $(CURDIR)
+CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp
+
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER}
+ touch configure-stamp
+
+
+build: build-stamp
+build-stamp: configure-stamp
+ dh_testdir
+ cd $(CMAKE_BUILD_DIR) && $(MAKE)
+ touch $@
+
+clean:
+ cd $(CMAKE_ROOT_DIR)
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+ rm -f `find . -name *.desktop`
+ rm -rf $(CMAKE_BUILD_DIR)
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+binary-indep: build install
+
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_installexamples
+ dh_install --sourcedir=debian/tmp
+ dh_installman
+ dh_link
+ dh_strip --dbg-package=acc-test-dbg
+ dh_fixperms
+ dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
+
--- /dev/null
+Name: acc-test
+Summary: A test program for usb accessory
+Version: 0.0.1
+Release: 1
+Group: TO_BE/FILLED_IN
+License: TO BE FILLED IN
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(capi-system-usb-accessory)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(ecore-x)
+BuildRequires: pkgconfig(elementary)
+BuildRequires: pkgconfig(appcore-efl)
+
+%prep
+%setup -q
+
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post
+chown 5000:5000 /opt/apps/acc_test/bin/acc_test
+
+
+%files
+%attr(644,root,root) /opt/share/applications/acc_test.desktop
+%attr(555,root,root) /opt/apps/acc_test/bin/acc_test