From 1ed957f31c3ea40f8004c2e91496076a453297b2 Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Wed, 13 Mar 2013 01:46:20 +0900 Subject: [PATCH] Tizen 2.1 base --- AUTHORS | 2 + CMakeLists.txt | 96 ++++++ LICENSE.APLv2 | 202 +++++++++++ NOTICE | 3 + TC/_export_env.sh | 8 + TC/_export_target_env.sh | 7 + TC/build.sh | 16 + TC/clean.sh | 11 + TC/config | 2 + TC/execute.sh | 15 + TC/testcase/Makefile | 28 ++ TC/testcase/tslist | 1 + TC/tet_scen | 7 + TC/tetbuild.cfg | 5 + TC/tetclean.cfg | 5 + TC/tetexec.cfg | 5 + capi-system-usb-accessory.pc.in | 15 + debian/README | 0 debian/capi-system-usb-accessory-dev.install | 4 + debian/capi-system-usb-accessory-dev.postinst | 1 + debian/capi-system-usb-accessory.install | 3 + debian/capi-system-usb-accessory.postinst | 1 + debian/changelog | 7 + debian/compat | 1 + debian/control | 22 ++ debian/rules | 69 ++++ include/usb_accessory.h | 308 +++++++++++++++++ include/usb_accessory_private.h | 160 +++++++++ packaging/capi-system-accessory.spec | 60 ++++ packaging/capi-system-usb-accessory.manifest | 5 + src/usb_accessory.c | 400 ++++++++++++++++++++++ src/usb_accessory_private.c | 464 ++++++++++++++++++++++++++ test/CMakeLists.txt | 20 ++ test/acc_test.c | 348 +++++++++++++++++++ test/acc_test.xml | 10 + test/debian/README | 0 test/debian/acc_test.install | 3 + test/debian/acc_test.postinst | 1 + test/debian/changelog | 7 + test/debian/compat | 1 + test/debian/control | 17 + test/debian/rules | 68 ++++ test/packaging/acc_test.spec | 38 +++ 43 files changed, 2446 insertions(+) create mode 100644 AUTHORS create mode 100755 CMakeLists.txt create mode 100644 LICENSE.APLv2 create mode 100644 NOTICE create mode 100755 TC/_export_env.sh create mode 100755 TC/_export_target_env.sh create mode 100755 TC/build.sh create mode 100755 TC/clean.sh create mode 100644 TC/config create mode 100755 TC/execute.sh create mode 100755 TC/testcase/Makefile create mode 100644 TC/testcase/tslist create mode 100755 TC/tet_scen create mode 100644 TC/tetbuild.cfg create mode 100644 TC/tetclean.cfg create mode 100644 TC/tetexec.cfg create mode 100644 capi-system-usb-accessory.pc.in create mode 100644 debian/README create mode 100644 debian/capi-system-usb-accessory-dev.install create mode 100644 debian/capi-system-usb-accessory-dev.postinst create mode 100644 debian/capi-system-usb-accessory.install create mode 100644 debian/capi-system-usb-accessory.postinst create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100755 debian/rules create mode 100644 include/usb_accessory.h create mode 100644 include/usb_accessory_private.h create mode 100644 packaging/capi-system-accessory.spec create mode 100644 packaging/capi-system-usb-accessory.manifest create mode 100644 src/usb_accessory.c create mode 100644 src/usb_accessory_private.c create mode 100644 test/CMakeLists.txt create mode 100644 test/acc_test.c create mode 100644 test/acc_test.xml create mode 100644 test/debian/README create mode 100644 test/debian/acc_test.install create mode 100644 test/debian/acc_test.postinst create mode 100644 test/debian/changelog create mode 100644 test/debian/compat create mode 100644 test/debian/control create mode 100755 test/debian/rules create mode 100644 test/packaging/acc_test.spec diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..f034086 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Taeyoung Kim +Suchang Woo diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..ace01c2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,96 @@ + +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) + diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..08a1d59 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +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. diff --git a/TC/_export_env.sh b/TC/_export_env.sh new file mode 100755 index 0000000..72a11ec --- /dev/null +++ b/TC/_export_env.sh @@ -0,0 +1,8 @@ +#!/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 diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh new file mode 100755 index 0000000..5ddaa53 --- /dev/null +++ b/TC/_export_target_env.sh @@ -0,0 +1,7 @@ +#!/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 diff --git a/TC/build.sh b/TC/build.sh new file mode 100755 index 0000000..72aad6c --- /dev/null +++ b/TC/build.sh @@ -0,0 +1,16 @@ +#!/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 diff --git a/TC/clean.sh b/TC/clean.sh new file mode 100755 index 0000000..29743e0 --- /dev/null +++ b/TC/clean.sh @@ -0,0 +1,11 @@ +#!/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 diff --git a/TC/config b/TC/config new file mode 100644 index 0000000..8b68019 --- /dev/null +++ b/TC/config @@ -0,0 +1,2 @@ +TET_INSTALL_HOST_PATH=/home/idkiller/work/tetware/TETware +TET_INSTALL_TARGET_PATH=/mnt/nfs/tetware/TETware diff --git a/TC/execute.sh b/TC/execute.sh new file mode 100755 index 0000000..a4f6095 --- /dev/null +++ b/TC/execute.sh @@ -0,0 +1,15 @@ +#!/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 diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile new file mode 100755 index 0000000..ac696fc --- /dev/null +++ b/TC/testcase/Makefile @@ -0,0 +1,28 @@ +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) diff --git a/TC/testcase/tslist b/TC/testcase/tslist new file mode 100644 index 0000000..0eeb137 --- /dev/null +++ b/TC/testcase/tslist @@ -0,0 +1 @@ +/testcase/utc_system_usb_accessory.c diff --git a/TC/tet_scen b/TC/tet_scen new file mode 100755 index 0000000..03f029a --- /dev/null +++ b/TC/tet_scen @@ -0,0 +1,7 @@ +all + ^TEST +##### Scenarios for TEST ##### + +# Test scenario +TEST + :include:/testcase/tslist diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg new file mode 100644 index 0000000..f7eda55 --- /dev/null +++ b/TC/tetbuild.cfg @@ -0,0 +1,5 @@ +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? diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg new file mode 100644 index 0000000..02d7030 --- /dev/null +++ b/TC/tetclean.cfg @@ -0,0 +1,5 @@ +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 diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg new file mode 100644 index 0000000..ef3e452 --- /dev/null +++ b/TC/tetexec.cfg @@ -0,0 +1,5 @@ +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 ? diff --git a/capi-system-usb-accessory.pc.in b/capi-system-usb-accessory.pc.in new file mode 100644 index 0000000..d0610b9 --- /dev/null +++ b/capi-system-usb-accessory.pc.in @@ -0,0 +1,15 @@ + +# 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} + diff --git a/debian/README b/debian/README new file mode 100644 index 0000000..e69de29 diff --git a/debian/capi-system-usb-accessory-dev.install b/debian/capi-system-usb-accessory-dev.install new file mode 100644 index 0000000..761a28b --- /dev/null +++ b/debian/capi-system-usb-accessory-dev.install @@ -0,0 +1,4 @@ +/usr/include/* +/usr/include/*/* +/usr/lib/pkgconfig/*.pc + diff --git a/debian/capi-system-usb-accessory-dev.postinst b/debian/capi-system-usb-accessory-dev.postinst new file mode 100644 index 0000000..1a24852 --- /dev/null +++ b/debian/capi-system-usb-accessory-dev.postinst @@ -0,0 +1 @@ +#!/bin/sh diff --git a/debian/capi-system-usb-accessory.install b/debian/capi-system-usb-accessory.install new file mode 100644 index 0000000..eeb34e5 --- /dev/null +++ b/debian/capi-system-usb-accessory.install @@ -0,0 +1,3 @@ +/usr/lib/lib*.so* +#/opt/apps/acc_test/bin/acc_test +#/opt/share/applications/acc_test.desktop diff --git a/debian/capi-system-usb-accessory.postinst b/debian/capi-system-usb-accessory.postinst new file mode 100644 index 0000000..1a24852 --- /dev/null +++ b/debian/capi-system-usb-accessory.postinst @@ -0,0 +1 @@ +#!/bin/sh diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..fee7656 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,7 @@ +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 Tue, 05 Jun 2012 00:19:00 +0900 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..0f1a390 --- /dev/null +++ b/debian/control @@ -0,0 +1,22 @@ + +Source: capi-system-usb-accessory +Section: libs +Priority: extra +Maintainer: pius lee +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) + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..7b8742b --- /dev/null +++ b/debian/rules @@ -0,0 +1,69 @@ +#!/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 + diff --git a/include/usb_accessory.h b/include/usb_accessory.h new file mode 100644 index 0000000..a8e3206 --- /dev/null +++ b/include/usb_accessory.h @@ -0,0 +1,308 @@ +/* + * usb-accessory + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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 +#include + +/** + * @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_IPC_FAILED = TIZEN_ERROR_PROTOCOL_NOT_AVALIABLE, + USB_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORT_API +} 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__ + diff --git a/include/usb_accessory_private.h b/include/usb_accessory_private.h new file mode 100644 index 0000000..09dc114 --- /dev/null +++ b/include/usb_accessory_private.h @@ -0,0 +1,160 @@ +/* + * usb-accessory + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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__ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 { + /* General */ + ERROR_POPUP_OK_BTN = 0, + IS_EMUL_BIN, + + /* for Accessory */ + LAUNCH_APP_FOR_ACC = 20, + REQ_ACC_PERMISSION, + HAS_ACC_PERMISSION, + REQ_ACC_PERM_NOTI_YES_BTN, + REQ_ACC_PERM_NOTI_NO_BTN, + GET_ACC_INFO, + + /* for Host */ + LAUNCH_APP_FOR_HOST = 40, + REQ_HOST_PERMISSION, + HAS_HOST_PERMISSION, + REQ_HOST_PERM_NOTI_YES_BTN, + REQ_HOST_PERM_NOTI_NO_BTN, + 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]; +}; + +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); +bool is_emul_bin(); +#endif /* __TIZEN_SYSTEM_USB_ACCESSORY_PRIVATE_H__ */ + diff --git a/packaging/capi-system-accessory.spec b/packaging/capi-system-accessory.spec new file mode 100644 index 0000000..74d9d32 --- /dev/null +++ b/packaging/capi-system-accessory.spec @@ -0,0 +1,60 @@ +Name: capi-system-usb-accessory +Summary: A usb accessory library in TIZEN C API +Version: 0.0.6 +Release: 1 +Group: framework-api +License: APLv2 +Source0: %{name}-%{version}.tar.gz +Source1: capi-system-usb-accessory.manifest +BuildRequires: cmake +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(aul) + +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 +cp %{SOURCE1} . +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 +/sbin/ldconfig + +%postun +/sbin/ldconfig + + +%files +%manifest capi-system-usb-accessory.manifest +%{_libdir}/libcapi-system-usb-accessory.so.* + +%files devel +%{_includedir}/system/usb_accessory.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/libcapi-system-usb-accessory.so diff --git a/packaging/capi-system-usb-accessory.manifest b/packaging/capi-system-usb-accessory.manifest new file mode 100644 index 0000000..b631abe --- /dev/null +++ b/packaging/capi-system-usb-accessory.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/src/usb_accessory.c b/src/usb_accessory.c new file mode 100644 index 0000000..25b1c0c --- /dev/null +++ b/src/usb_accessory.c @@ -0,0 +1,400 @@ +/* + * usb-accessory + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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 (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + if (!cloned_handle || *cloned_handle) return USB_ERROR_INVALID_PARAMETER; + *cloned_handle = (usb_accessory_h)malloc(sizeof(struct usb_accessory_s)); + snprintf((*cloned_handle)->manufacturer, strlen(handle->manufacturer), "%s", handle->manufacturer); + 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; + if (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + FREE(handle); + __USB_FUNC_EXIT__ ; + return USB_ERROR_NONE; +} + +int usb_accessory_foreach_attached(usb_accessory_attached_cb callback, void *user_data) +{ + __USB_FUNC_ENTER__ ; + if (callback == NULL) return USB_ERROR_INVALID_PARAMETER; + if (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + struct usb_accessory_list *accList = NULL; + struct usb_accessory_list *tmpList = NULL; + bool ret = false; + 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 = true; + tmpList = accList; + while (ret) { + if (tmpList == NULL || tmpList->accessory == NULL) { + break; + } + ret = callback(tmpList->accessory, user_data); + if (ret) { + tmpList = tmpList->next; + } + } + + FREE(accList); + + __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__ ; + if (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + int ret = -1; + accCbData = (struct AccCbData *)malloc(sizeof(struct AccCbData)); + accCbData->user_data = user_data; + 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 (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"); + } + __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 (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + if (accessory->accPermission == true) { + __USB_FUNC_EXIT__ ; + return USB_ERROR_NONE; + } 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"); + + 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"); + + ret = ipc_request_client_close(&sock_remote); + um_retvm_if(ret < 0, USB_ERROR_IPC_FAILED, "FAIL: ipc_request_client_close()\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 (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + if (accessory->accPermission == true) { + *fd = fopen(USB_ACCESSORY_NODE, "r+"); + USB_LOG("file pointer: %d", *fd); + } 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; + if (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + *description = strdup(accessory->description); + __USB_FUNC_ENTER__ ; + return USB_ERROR_NONE; +} + + +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; + } + *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; + if (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + *model = strdup(accessory->model); + __USB_FUNC_ENTER__ ; + return USB_ERROR_NONE; +} + + +int usb_accessory_get_serial(usb_accessory_h accessory, char** serial) +{ + __USB_FUNC_ENTER__ ; + if (!accessory) return USB_ERROR_INVALID_PARAMETER; + if (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + *serial = strdup(accessory->serial); + __USB_FUNC_ENTER__ ; + return USB_ERROR_NONE; +} + + +int usb_accessory_get_version(usb_accessory_h accessory, char** version) +{ + __USB_FUNC_ENTER__ ; + if (!accessory) return USB_ERROR_INVALID_PARAMETER; + if (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + *version = strdup(accessory->version); + __USB_FUNC_ENTER__ ; + return USB_ERROR_NONE; +} + + +int usb_accessory_is_connected(usb_accessory_h accessory, bool* is_connected) +{ + __USB_FUNC_ENTER__ ; + if (is_emul_bin()) { + USB_LOG("FAIL:USB Accessory is not available with emulator."); + return USB_ERROR_NOT_SUPPORTED; + } + int ret = -1; + int val = -1; + ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &val); + 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; + 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; + accCbData->user_data = accessory; + accCbData->request_perm_cb_func = callback; + accCbData->accessory = accessory; + GError *err; + GIOStatus gio_ret; + + int fd = ipc_noti_client_init(); + if (fd < 0) { + USB_LOG("FAIL: ipc_noti_client_init()"); + return USB_ERROR_IPC_FAILED; + } + + GIOChannel *g_io_ch = g_io_channel_unix_new(fd); + if (!g_io_ch) { + 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; + } + + 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; + } + + 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; + } + + app_id = get_app_id(); + USB_LOG("App ID: %s", app_id); + if (!app_id) { + 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; + } + + ret = request_to_usb_server(sock_remote, REQ_ACC_PERMISSION, buf, app_id); + 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; + } + + 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_IPC_FAILED; + } + + __USB_FUNC_EXIT__ ; + return USB_ERROR_NONE; +} diff --git a/src/usb_accessory_private.c b/src/usb_accessory_private.c new file mode 100644 index 0000000..925885f --- /dev/null +++ b/src/usb_accessory_private.c @@ -0,0 +1,464 @@ +/* + * usb-accessory + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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) { + if (t < SOCK_STR_LEN) { + answer[t] = '\0'; + } else { /* t == SOCK_STR_LEN */ + answer[SOCK_STR_LEN-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_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_ACC_PERM_NOTI_YES_BTN: + permCbData->accessory->accPermission = true; + permCbData->request_perm_cb_func((struct usb_accessory_s*)(permCbData->user_data), true); + break; + case REQ_ACC_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"); + close(sock_local); + 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"); + close(sock_local); + 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; + + accList = (struct usb_accessory_list *)malloc(sizeof(struct usb_accessory_list)); + um_retvm_if(!accList, -1, "accList == NULL"); + + ret = getAccList(&accList); + if (ret == false) { + USB_LOG("FAIL: getAccList(&accList)"); + FREE(accList); + return -1; + } + + *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); + + FREE(accList); + + __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"); + + 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"); + + conCbData->connection_cb_func(changedAcc, true, conCbData->user_data); + + ret = freeChangedAcc(&changedAcc); + um_retm_if(ret < 0, "FAIL: freeChangedAcc(&changedAcc)\n"); + break; + default: + USB_LOG("ERROR: The value of VCONFKEY_USB_ACCESSORY_STATUS is invalid\n"); + break; + } + __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_list **accList) +{ + __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"); + + 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; +} + +bool is_emul_bin() +{ + __USB_FUNC_ENTER__ ; + int ret = -1; + struct utsname name; + ret = uname(&name); + if (ret < 0) { + __USB_FUNC_EXIT__ ; + return true; + } else { + USB_LOG("Machine name: %s", name.machine); + if (strcasestr(name.machine, "emul")) { + __USB_FUNC_EXIT__ ; + return true; + } else { + __USB_FUNC_EXIT__ ; + return false; + } + } + +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..7000e30 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,20 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(acc_test C) +SET(SRCS acc_test.c) +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED eina elementary ecore-x appcore-efl aul capi-system-usb-accessory) +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g ") +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 manifest file +INSTALL(FILES ${CMAKE_SOURCE_DIR}/acc_test.xml DESTINATION /opt/share/packages/) diff --git a/test/acc_test.c b/test/acc_test.c new file mode 100644 index 0000000..8124435 --- /dev/null +++ b/test/acc_test.c @@ -0,0 +1,348 @@ + +#include +#include +#include + +#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
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; +} diff --git a/test/acc_test.xml b/test/acc_test.xml new file mode 100644 index 0000000..13a046a --- /dev/null +++ b/test/acc_test.xml @@ -0,0 +1,10 @@ + + + + Taeyoung Kim + USB accessory test application + + + + + diff --git a/test/debian/README b/test/debian/README new file mode 100644 index 0000000..e69de29 diff --git a/test/debian/acc_test.install b/test/debian/acc_test.install new file mode 100644 index 0000000..74eb165 --- /dev/null +++ b/test/debian/acc_test.install @@ -0,0 +1,3 @@ +/usr/lib/lib*.so* +/opt/apps/acc_test/bin/acc_test +/opt/share/packages/acc_test.xml diff --git a/test/debian/acc_test.postinst b/test/debian/acc_test.postinst new file mode 100644 index 0000000..1a24852 --- /dev/null +++ b/test/debian/acc_test.postinst @@ -0,0 +1 @@ +#!/bin/sh diff --git a/test/debian/changelog b/test/debian/changelog new file mode 100644 index 0000000..9cbe29d --- /dev/null +++ b/test/debian/changelog @@ -0,0 +1,7 @@ +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 Tue, 05 Jun 2012 00:19:00 +0900 diff --git a/test/debian/compat b/test/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/test/debian/compat @@ -0,0 +1 @@ +5 diff --git a/test/debian/control b/test/debian/control new file mode 100644 index 0000000..6f08b8f --- /dev/null +++ b/test/debian/control @@ -0,0 +1,17 @@ + +Source: acc_test +Section: tools +Priority: extra +Maintainer: Taeyoung Kim Taesoo Jun +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 + diff --git a/test/debian/rules b/test/debian/rules new file mode 100755 index 0000000..76d57f8 --- /dev/null +++ b/test/debian/rules @@ -0,0 +1,68 @@ +#!/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 + diff --git a/test/packaging/acc_test.spec b/test/packaging/acc_test.spec new file mode 100644 index 0000000..94ece95 --- /dev/null +++ b/test/packaging/acc_test.spec @@ -0,0 +1,38 @@ +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) + +%description + +%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/packages/acc_test.xml +%attr(555,root,root) /opt/apps/acc_test/bin/acc_test -- 2.7.4