From: nazib.ullah Date: Mon, 5 Sep 2016 11:15:47 +0000 (+0600) Subject: [TBT][tizen_3.0_wearable][stt, tts, smartcard module added; smartcard_test_app_signed... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f6a8363b8a461f3d98da6688f454902b16326cc6;p=test%2Ftct%2Fnative%2Fbehavior.git [TBT][tizen_3.0_wearable][stt, tts, smartcard module added; smartcard_test_app_signed and smartcard_test_app_unsigned apps added] Change-Id: I43d68145f314fda2014b6fa008165ce88654116e --- diff --git a/release/binary-arm/install.sh b/release/binary-arm/install.sh index 26123f4..0de241d 100644 --- a/release/binary-arm/install.sh +++ b/release/binary-arm/install.sh @@ -31,6 +31,8 @@ sdb install org.tizen.coretbt_uiapp-1.0.0-arm.tpk sdb install org.tizen.tbt_hcetestappa-1.0.0-arm.tpk sdb install org.tizen.tbt_hcetestappb-1.0.0-arm.tpk sdb install org.tizen.tbt_nfcesetestapp-1.0.0-arm.tpk +sdb install org.tizen.smartcard.actestapp-1.0.0-arm.tpk +sdb install org.tizen.smartcard.actestapp_signed-1.0.0-arm.tpk sdb install org.tizen.operationpickviewapp-1.0.0-arm.tpk sdb install org.tizen.coretbtwidgetapp-1.0.0-arm.tpk sdb install org.tizen.tbtcoreapp-1.0.0-arm.tpk diff --git a/release/binary-arm/org.tizen.smartcard.actestapp-1.0.0-arm.tpk b/release/binary-arm/org.tizen.smartcard.actestapp-1.0.0-arm.tpk new file mode 100644 index 0000000..2948b3f Binary files /dev/null and b/release/binary-arm/org.tizen.smartcard.actestapp-1.0.0-arm.tpk differ diff --git a/release/binary-arm/org.tizen.smartcard.actestapp_signed-1.0.0-arm.tpk b/release/binary-arm/org.tizen.smartcard.actestapp_signed-1.0.0-arm.tpk new file mode 100644 index 0000000..2987502 Binary files /dev/null and b/release/binary-arm/org.tizen.smartcard.actestapp_signed-1.0.0-arm.tpk differ diff --git a/release/binary-arm/org.tizen.tbtcoreapp-1.0.0-arm.tpk b/release/binary-arm/org.tizen.tbtcoreapp-1.0.0-arm.tpk index ed57e7e..b1d99bf 100644 Binary files a/release/binary-arm/org.tizen.tbtcoreapp-1.0.0-arm.tpk and b/release/binary-arm/org.tizen.tbtcoreapp-1.0.0-arm.tpk differ diff --git a/release/binary-x86/install.sh b/release/binary-x86/install.sh index 22fa9a7..caf7503 100644 --- a/release/binary-x86/install.sh +++ b/release/binary-x86/install.sh @@ -31,6 +31,8 @@ sdb install org.tizen.coretbt_uiapp-1.0.0-i386.tpk sdb install org.tizen.tbt_hcetestappa-1.0.0-i386.tpk sdb install org.tizen.tbt_hcetestappb-1.0.0-i386.tpk sdb install org.tizen.tbt_nfcesetestapp-1.0.0-i386.tpk +sdb install org.tizen.smartcard.actestapp-1.0.0-i386.tpk +sdb install org.tizen.smartcard.actestapp_signed-1.0.0-i386.tpk sdb install org.tizen.operationpickviewapp-1.0.0-i386.tpk sdb install org.tizen.coretbtwidgetapp-1.0.0-i386.tpk sdb install org.tizen.tbtcoreapp-1.0.0-i386.tpk diff --git a/release/binary-x86/org.tizen.smartcard.actestapp-1.0.0-i386.tpk b/release/binary-x86/org.tizen.smartcard.actestapp-1.0.0-i386.tpk new file mode 100644 index 0000000..5a713b8 Binary files /dev/null and b/release/binary-x86/org.tizen.smartcard.actestapp-1.0.0-i386.tpk differ diff --git a/release/binary-x86/org.tizen.smartcard.actestapp_signed-1.0.0-i386.tpk b/release/binary-x86/org.tizen.smartcard.actestapp_signed-1.0.0-i386.tpk new file mode 100644 index 0000000..f2be608 Binary files /dev/null and b/release/binary-x86/org.tizen.smartcard.actestapp_signed-1.0.0-i386.tpk differ diff --git a/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk b/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk index 2ca367d..eb5d3c4 100644 Binary files a/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk and b/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk differ diff --git a/tbt_smartcardtestapp/.cproject b/tbt_smartcardtestapp/.cproject new file mode 100755 index 0000000..785be8b --- /dev/null +++ b/tbt_smartcardtestapp/.cproject @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tbt_smartcardtestapp/.exportMap b/tbt_smartcardtestapp/.exportMap new file mode 100755 index 0000000..43e310e --- /dev/null +++ b/tbt_smartcardtestapp/.exportMap @@ -0,0 +1,4 @@ +{ + global: main; + local: *; +}; diff --git a/tbt_smartcardtestapp/.project b/tbt_smartcardtestapp/.project new file mode 100644 index 0000000..d5c02c9 --- /dev/null +++ b/tbt_smartcardtestapp/.project @@ -0,0 +1,26 @@ + + + tbt_smartcardtestapp + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/tbt_smartcardtestapp/.rds_delta b/tbt_smartcardtestapp/.rds_delta new file mode 100755 index 0000000..f676049 --- /dev/null +++ b/tbt_smartcardtestapp/.rds_delta @@ -0,0 +1,6 @@ +#delete +#add +#modify +author-signature.xml +signature1.xml +tizen-manifest.xml diff --git a/tbt_smartcardtestapp/.sdk_delta.info b/tbt_smartcardtestapp/.sdk_delta.info new file mode 100644 index 0000000..40aeb54 Binary files /dev/null and b/tbt_smartcardtestapp/.sdk_delta.info differ diff --git a/tbt_smartcardtestapp/.sign/.manifest.tmp b/tbt_smartcardtestapp/.sign/.manifest.tmp new file mode 100644 index 0000000..2853eb1 --- /dev/null +++ b/tbt_smartcardtestapp/.sign/.manifest.tmp @@ -0,0 +1,4 @@ +bin/smartcardactestapp__DEL__0vkPyP3B2Lk6dLYkSEE52MoL9VHiR2iYRFnYq5ZfSdk= +shared/res/smartcardactestapp.png__DEL__1d0oEZHqPn+QzNzGIHwj9ODby6x9ggFs9uOsav6jPNs= +tizen-manifest.xml__DEL__7iwdXKh5PEfas13h2rco0GKAzsuvKJvKL2KFKo18Okc= +author-signature.xml__DEL__43/92UCva8IvsOpShYX952Rm7cJlV2bLRDpey6c18H4= diff --git a/tbt_smartcardtestapp/.sign/author-signature.xml b/tbt_smartcardtestapp/.sign/author-signature.xml new file mode 100644 index 0000000..2fd2a93 --- /dev/null +++ b/tbt_smartcardtestapp/.sign/author-signature.xml @@ -0,0 +1,66 @@ + + + + + + +0vkPyP3B2Lk6dLYkSEE52MoL9VHiR2iYRFnYq5ZfSdk= + + + +1d0oEZHqPn+QzNzGIHwj9ODby6x9ggFs9uOsav6jPNs= + + + +7iwdXKh5PEfas13h2rco0GKAzsuvKJvKL2KFKo18Okc= + + + + + + +lpo8tUDs054eLlBQXiDPVDVKfw30ZZdtkRs1jd7H5K8= + + + +wOL+a+AqybQ+w4wfZteRNnHuUHL6MRsTqZj5uyxi59FQegtBl4zjdvLMsJtoaRg4xdYAqOz2OqRT +s8NNOW7fYgEokcVwuDXqq8NYji0yNzzYEfYoDKA0IH3F+ANCfJB2f2bGIl1AGc4ctS3nk9u3Qk/O +YVbmb5pxL5h+k3WALvg= + + + + +MIIClTCCAX2gAwIBAgIGAVbp/WX9MA0GCSqGSIb3DQEBBQUAMFYxGjAYBgNVBAoMEVRpemVuIEFz +c29jaWF0aW9uMRowGAYDVQQLDBFUaXplbiBBc3NvY2lhdGlvbjEcMBoGA1UEAwwTVGl6ZW4gRGV2 +ZWxvcGVycyBDQTAeFw0xMjExMDEwMDAwMDBaFw0xOTAxMDEwMDAwMDBaMBExDzANBgNVBAMMBmF1 +dGhvcjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAweEr+c8HpAsgNvMMrLM3R/L8xOqQ3ZRg +Sk99w1pKVbwq3QYcTHoJD4ZAU3JJTZZkzpAzgzvjYSadNwq/j8U28iesa1kA/vawNzVLpcquRcXH +OwGn1iiSdqBgjUdkJoM5qi9QHF09uuQa+wLr4wyGct1RBzAPxsMSn5wXcm4P3JECAwEAAaMyMDAw +DAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwDQYJKoZIhvcN +AQEFBQADggEBABD7PHc7p3bdMYZXrzdyPEHbyGTmanG/LBe/dhowemWmRt93lERemifixdWaU85f +mksVT5VnuGC+tFX/p4pMwNQwNL+cZKIplDbX5NCtwJMag17K8VVtQ4aeMZeAtkvnspp84mAkzNTs +vEtMuLDIYfkfMWUczb7w2qP0z/OxHVciFDyY3Rs1GxVtyGDFq+dSCK4y7kxQWPts52lueoodsY5A +xzWNblo3dFa3ZRCZiA0Z+sBkQI8Vv/VOn7mMx2AGyE/qoqTajusSCGOckJseuXe9HSW7CW2d7FA2 +RT9/5Voslhm/ZFduUMYopMF/Oi/SUpUfV/z3+B40XpB5ivf8Wek= + + +MIIDOTCCAiGgAwIBAgIBATANBgkqhkiG9w0BAQUFADBYMRowGAYDVQQKDBFUaXplbiBBc3NvY2lh +dGlvbjEaMBgGA1UECwwRVGl6ZW4gQXNzb2NpYXRpb24xHjAcBgNVBAMMFVRpemVuIERldmVsb3Bl +cnMgUm9vdDAeFw0xMjAxMDEwMDAwMDBaFw0yNzAxMDEwMDAwMDBaMFYxGjAYBgNVBAoMEVRpemVu +IEFzc29jaWF0aW9uMRowGAYDVQQLDBFUaXplbiBBc3NvY2lhdGlvbjEcMBoGA1UEAwwTVGl6ZW4g +RGV2ZWxvcGVycyBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANVGhRGmMIUyBA7o +PCz8Sxut6z6HNkF4oDIuzuKaMzRYPeWodwe9O0gmqAkToQHfwg2giRhE5GoPld0fq+OYMMwSasCu +g8dwODx1eDeSYVuOLWRxpAmbTXOsSFi6VoWeyaPEm18JBHvZBsU5YQtgZ6Kp7MqzvQg3pXOxtajj +vyHxiatJl+xXrHgcXC1wgyG3buty7u/Fi2mvKXJ0PRJcCjjK81dqe/Vr20sRUCrbk02zbm5ggFt/ +jIEhV8wbFRQpliobc7J4dSTKhFfrqGM8rdd54LYhD7gSI1CFSe16pUXfcVR7FhJztRaiGLnCrwBE +dyTZ248+D4L/qR/D0axb3jcCAwEAAaMQMA4wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOC +AQEAnOXXQ/1O/QTDHyrmQDtFziqPY3xWlJBqJtEqXiT7Y+Ljpe66e+Ee/OjQMlZe8gu21/8cKklH +95RxjopMWCVedXDUbWdvS2+CdyvVW/quT2E0tjqIzXDekUTYwwhlPWlGxvfj3VsxqSFq3p8Brl04 +1Gx5RKAGyKVsMfTLhbbwSWwApuBUxYfcNpKwLWGPXkysu+HctY03OKv4/xKBnVWiN8ex/Sgesi0M ++OBAOMdZMPK32uJBTeKFx1xZgTLIhk45V0hPOomPjZloiv0LSS11eyd451ufjW0iHRE7WlpR6EvI +W6TFyZgMpQq+kg4hWl2SBTf3s2VI8Ygz7gj8TMlClg== + + + + + \ No newline at end of file diff --git a/tbt_smartcardtestapp/.sign/signature1.xml b/tbt_smartcardtestapp/.sign/signature1.xml new file mode 100644 index 0000000..5105877 --- /dev/null +++ b/tbt_smartcardtestapp/.sign/signature1.xml @@ -0,0 +1,68 @@ + + + + + + +43/92UCva8IvsOpShYX952Rm7cJlV2bLRDpey6c18H4= + + + +0vkPyP3B2Lk6dLYkSEE52MoL9VHiR2iYRFnYq5ZfSdk= + + + +1d0oEZHqPn+QzNzGIHwj9ODby6x9ggFs9uOsav6jPNs= + + + +7iwdXKh5PEfas13h2rco0GKAzsuvKJvKL2KFKo18Okc= + + + + + + +u/jU3U4Zm5ihTMSjKGlGYbWzDfRkGphPPHx3gJIYEJ4= + + + +JEQHzw9h6bSUumUTxf29o8Opu5Vu8xhKXrk6qOIiRRIcooDFKwVLDbr/EB1irUo2Qs1vJZuD3xtT +RVpHqdltRtxIOlRVrNNbr4gl/WH/43WpNSLOGHc4BpOE1hAOwrh6jSuGuLa6op3IkONfrgGadsKY +KyK58Iu+KZt+HCr06Fc= + + + + +MIICmzCCAgQCCQDXI7WLdVZwiTANBgkqhkiG9w0BAQUFADCBjzELMAkGA1UEBhMCS1IxDjAMBgNV +BAgMBVN1d29uMQ4wDAYDVQQHDAVTdXdvbjEWMBQGA1UECgwNVGl6ZW4gVGVzdCBDQTEiMCAGA1UE +CwwZVGl6ZW4gRGlzdHJpYnV0b3IgVGVzdCBDQTEkMCIGA1UEAwwbVGl6ZW4gUHVibGljIERpc3Ry +aWJ1dG9yIENBMB4XDTEyMTAyOTEzMDMwNFoXDTIyMTAyNzEzMDMwNFowgZMxCzAJBgNVBAYTAktS +MQ4wDAYDVQQIDAVTdXdvbjEOMAwGA1UEBwwFU3V3b24xFjAUBgNVBAoMDVRpemVuIFRlc3QgQ0Ex +IjAgBgNVBAsMGVRpemVuIERpc3RyaWJ1dG9yIFRlc3QgQ0ExKDAmBgNVBAMMH1RpemVuIFB1Ymxp +YyBEaXN0cmlidXRvciBTaWduZXIwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALtMvlc5hENK +90ZdA+y66+Sy0enD1gpZDBh5T9RP0oRsptJv5jjNTseQbQi0SZOdOXb6J7iQdlBCtR343RpIEz8H +mrBy7mSY7mgwoU4EPpp4CTSUeAuKcmvrNOngTp5Hv7Ngf02TTHOLK3hZLpGayaDviyNZB5PdqQdB +hokKjzAzAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvGp1gxxAIlFfhJH1efjb9BJK/rtRkbYn9+Ez +GEbEULg1svsgnyWisFimI3uFvgI/swzr1eKVY3Sc8MQ3+Fdy3EkbDZ2+WAubhcEkorTWjzWz2fL1 +vKaYjeIsuEX6TVRUugHWudPzcEuQRLQf8ibZWjbQdBmpeQYBMg5x+xKLCJc= + + +MIICtDCCAh2gAwIBAgIJAMDbehElPNKvMA0GCSqGSIb3DQEBBQUAMIGVMQswCQYDVQQGEwJLUjEO +MAwGA1UECAwFU3V3b24xDjAMBgNVBAcMBVN1d29uMRYwFAYDVQQKDA1UaXplbiBUZXN0IENBMSMw +IQYDVQQLDBpUVGl6ZW4gRGlzdHJpYnV0b3IgVGVzdCBDQTEpMCcGA1UEAwwgVGl6ZW4gUHVibGlj +IERpc3RyaWJ1dG9yIFJvb3QgQ0EwHhcNMTIxMDI5MTMwMjUwWhcNMjIxMDI3MTMwMjUwWjCBjzEL +MAkGA1UEBhMCS1IxDjAMBgNVBAgMBVN1d29uMQ4wDAYDVQQHDAVTdXdvbjEWMBQGA1UECgwNVGl6 +ZW4gVGVzdCBDQTEiMCAGA1UECwwZVGl6ZW4gRGlzdHJpYnV0b3IgVGVzdCBDQTEkMCIGA1UEAwwb +VGl6ZW4gUHVibGljIERpc3RyaWJ1dG9yIENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDe +OTS/3nXvkDEmsFCJIvRlQ3RKDcxdWJJp625pFqHdmoJBdV+x6jl1raGK2Y1sp2Gdvpjc/z92yzAp +bE/UVLPh/tRNZPeGhzU4ejDDm7kzdr2f7Ia0U98K+OoY12ucwg7TYNItj9is7Cj4blGfuMDzd2ah +2AgnCGlwNwV/pv+uVQIDAQABoxAwDjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBACqJ +KO33YdoGudwanZIxMdXuxnnD9R6u72ltKk1S4zPfMJJv482CRGCI4FK6djhlsI4i0Lt1SVIJEed+ +yc3qckGm19dW+4xdlkekon7pViEBWuyHw8OWv3RXtTum1+PGHjBJ2eYY4ZKIpz73U/1NC16sTB/0 +VhfnkHwPltmrpYVe + + + + + \ No newline at end of file diff --git a/tbt_smartcardtestapp/.tproject b/tbt_smartcardtestapp/.tproject new file mode 100755 index 0000000..de5a150 --- /dev/null +++ b/tbt_smartcardtestapp/.tproject @@ -0,0 +1,12 @@ + + + + + wearable-3.0 + + + + + + + diff --git a/tbt_smartcardtestapp/inc/logger.h b/tbt_smartcardtestapp/inc/logger.h new file mode 100644 index 0000000..772ceab --- /dev/null +++ b/tbt_smartcardtestapp/inc/logger.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2014 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. + *******************************************************************************/ + +/** + * @file logger.h + * @brief This file provide necessary macro for logging information. + * @since_tizen 2.3 + * @author Amlan Chowdhury (amlan.c@samsung.com) + * @date October, 2014 + * @bug + * @credit + */ +#ifndef __LOGGER_H__ +#define __LOGGER_H__ + +#include + +#define LOG_TAG_CORE "[TBT_CORE]_" + +#define DLOG(prio, fmt, arg...) dlog_print(prio, LOG_TAG_CORE, "%s (Line: %d) > " fmt, __func__, __LINE__, ##arg) +#define DBG(fmt, arg...) DLOG(DLOG_DEBUG, fmt, ##arg) +#define ERR(fmt, arg...) DLOG(DLOG_ERROR, fmt, ##arg) + +#define RETM_IF(expr, fmt, arg...) \ +{ \ + if (expr) \ + { \ + ERR(fmt, ##arg); \ + return; \ + } \ +} + +#define RETVM_IF(expr, val, fmt, arg...) \ +{ \ + if (expr) \ + { \ + ERR(fmt, ##arg); \ + return (val); \ + } \ +} + +#define SAFE_DELETE(a) if( (a) != NULL ) free (a); (a) = NULL; + +#endif /* __LOGGER_H__ */ diff --git a/tbt_smartcardtestapp/inc/smartcardactestapp.h b/tbt_smartcardtestapp/inc/smartcardactestapp.h new file mode 100755 index 0000000..fdf0e8b --- /dev/null +++ b/tbt_smartcardtestapp/inc/smartcardactestapp.h @@ -0,0 +1,15 @@ +#ifndef __smartcardactestapp_H__ +#define __smartcardactestapp_H__ + +#include +#include +#include +#include +#include "logger.h" + + +#if !defined(PACKAGE) +#define PACKAGE "org.tizen.smartcard.actestapp" +#endif + +#endif /* __smartcardactestapp_H__ */ diff --git a/tbt_smartcardtestapp/project_def.prop b/tbt_smartcardtestapp/project_def.prop new file mode 100755 index 0000000..cc93b41 --- /dev/null +++ b/tbt_smartcardtestapp/project_def.prop @@ -0,0 +1,11 @@ +APPNAME = smartcardactestapp + +type = app +profile = wearable-3.0 + +USER_SRCS = src/smartcardactestapp.c +USER_DEFS = +USER_INC_DIRS = inc +USER_OBJS = +USER_LIBS = +USER_EDCS = diff --git a/tbt_smartcardtestapp/shared/res/smartcardactestapp.png b/tbt_smartcardtestapp/shared/res/smartcardactestapp.png new file mode 100755 index 0000000..9765b1b Binary files /dev/null and b/tbt_smartcardtestapp/shared/res/smartcardactestapp.png differ diff --git a/tbt_smartcardtestapp/src/smartcardactestapp.c b/tbt_smartcardtestapp/src/smartcardactestapp.c new file mode 100755 index 0000000..ed141e6 --- /dev/null +++ b/tbt_smartcardtestapp/src/smartcardactestapp.c @@ -0,0 +1,253 @@ +#include "smartcardactestapp.h" +#include + +typedef struct appdata { + Evas_Object *win; + Evas_Object *conform; + Evas_Object *label; +} appdata_s; + +static char* get_smartcard_error(smartcard_error_e error); + +static void +win_delete_request_cb(void *data, Evas_Object *obj, void *event_info) +{ + ui_app_exit(); +} + +static void +win_back_cb(void *data, Evas_Object *obj, void *event_info) +{ + appdata_s *ad = data; + /* Let window go to hide state. */ + elm_win_lower(ad->win); +} + +static void +create_base_gui(appdata_s *ad) +{ + /* Window */ + /* Create and initialize elm_win. + elm_win is mandatory to manipulate window. */ + ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE); + elm_win_autodel_set(ad->win, EINA_TRUE); + + if (elm_win_wm_rotation_supported_get(ad->win)) { + int rots[4] = { 0, 90, 180, 270 }; + elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4); + } + + evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL); + eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad); + + /* Conformant */ + /* Create and initialize elm_conformant. + elm_conformant is mandatory for base gui to have proper size + when indicator or virtual keypad is visible. */ + ad->conform = elm_conformant_add(ad->win); + elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW); + elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE); + evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(ad->win, ad->conform); + evas_object_show(ad->conform); + + /* Label */ + /* Create an actual view of the base gui. + Modify this part to change the view. */ + ad->label = elm_label_add(ad->conform); + + int ret; + + ret = smartcard_initialize(); + DBG("smartcard_initialize : %s", get_smartcard_error(ret)); + if (ret == SMARTCARD_ERROR_NONE) { + int reader_length; + int* readers; + + ret = smartcard_get_readers(&readers, &reader_length); + DBG("smartcard_get_readers : %s", get_smartcard_error(ret)); + if (ret == SMARTCARD_ERROR_NONE && reader_length > 0) { + int session; + ret = smartcard_reader_open_session(readers[0], &session); + DBG("smartcard_reader_open_session : %s", get_smartcard_error(ret)); + if (ret == SMARTCARD_ERROR_NONE) { + int channel; + unsigned char aid[] = {0x43, 0x4F, 0x4E, 0x56, 0x45, 0x52, 0x47, 0x45, 0x4E, 0x43, 0x45, 0x4E, 0x46, 0x43}; + ret = smartcard_session_open_basic_channel(session, aid, 14, 0x00, &channel); + DBG("smartcard_session_open_basic_channel : %s", get_smartcard_error(ret)); + if (ret == SMARTCARD_ERROR_NONE) { + ret = SMARTCARD_ERROR_NONE; + } + } + } else { + ret = SMARTCARD_ERROR_GENERAL; + } + } + + /* Label */ + /* Create an actual view of the base gui. + Modify this part to change the view. */ + ad->label = elm_label_add(ad->conform); + if (ret == SMARTCARD_ERROR_NONE) { + elm_object_text_set(ad->label, "Passed"); + } else { + elm_object_text_set(ad->label, "Failed"); + } + + evas_object_size_hint_weight_set(ad->label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_content_set(ad->conform, ad->label); + + /* Show window after base gui is set up */ + evas_object_show(ad->win); +} + +static bool +app_create(void *data) +{ + /* Hook to take necessary actions before main event loop starts + Initialize UI resources and application's data + If this function returns true, the main loop of application starts + If this function returns false, the application is terminated */ + appdata_s *ad = data; + + create_base_gui(ad); + + return true; +} + +static void +app_control(app_control_h app_control, void *data) +{ + /* Handle the launch request. */ +} + +static void +app_pause(void *data) +{ + /* Take necessary actions when application becomes invisible. */ +} + +static void +app_resume(void *data) +{ + /* Take necessary actions when application becomes visible. */ +} + +static void +app_terminate(void *data) +{ + /* Release all resources. */ +} + +static void +ui_app_lang_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LANGUAGE_CHANGED*/ + char *locale = NULL; + system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale); + elm_language_set(locale); + free(locale); + return; +} + +static void +ui_app_orient_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/ + return; +} + +static void +ui_app_region_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_REGION_FORMAT_CHANGED*/ +} + +static void +ui_app_low_battery(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_BATTERY*/ +} + +static void +ui_app_low_memory(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_MEMORY*/ +} + +int +main(int argc, char *argv[]) +{ + appdata_s ad = {0,}; + int ret = 0; + + ui_app_lifecycle_callback_s event_callback = {0,}; + app_event_handler_h handlers[5] = {NULL, }; + + event_callback.create = app_create; + event_callback.terminate = app_terminate; + event_callback.pause = app_pause; + event_callback.resume = app_resume; + event_callback.app_control = app_control; + + ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad); + ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad); + ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad); + ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad); + ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad); + + ret = ui_app_main(argc, argv, &event_callback, &ad); + if (ret != APP_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret); + } + + return ret; +} + +static char* get_smartcard_error(smartcard_error_e error) +{ + char* err_msg; + switch (error) { + + case SMARTCARD_ERROR_NONE: + err_msg = "SMARTCARD_ERROR_NONE"; + break; + case SMARTCARD_ERROR_GENERAL: + err_msg = "SMARTCARD_ERROR_GENERAL"; + break; + case SMARTCARD_ERROR_IO_ERROR: + err_msg = "SMARTCARD_ERROR_IO_ERROR"; + break; + case SMARTCARD_ERROR_NO_SUCH_ELEMENT: + err_msg = "SMARTCARD_ERROR_NO_SUCH_ELEMENT"; + break; + case SMARTCARD_ERROR_ILLEGAL_STATE: + err_msg = "SMARTCARD_ERROR_ILLEGAL_STATE"; + break; + case SMARTCARD_ERROR_INVALID_PARAMETER: + err_msg = "SMARTCARD_ERROR_INVALID_PARAMETER"; + break; + case SMARTCARD_ERROR_ILLEGAL_REFERENCE: + err_msg = "SMARTCARD_ERROR_ILLEGAL_REFERENCE"; + break; + case SMARTCARD_ERROR_OPERATION_NOT_SUPPORTED: + err_msg = "SMARTCARD_ERROR_OPERATION_NOT_SUPPORTED"; + break; + case SMARTCARD_ERROR_PERMISSION_DENIED: + err_msg = "SMARTCARD_ERROR_PERMISSION_DENIED"; + break; + case SMARTCARD_ERROR_CHANNEL_NOT_AVAILABLE: + err_msg = "SMARTCARD_ERROR_CHANNEL_NOT_AVAILABLE"; + break; + case SMARTCARD_ERROR_NOT_INITIALIZED: + err_msg = "SMARTCARD_ERROR_NOT_INITIALIZED"; + break; + case SMARTCARD_ERROR_NOT_SUPPORTED: + err_msg = "SMARTCARD_ERROR_NOT_SUPPORTED"; + break; + default: + err_msg = "UNKNOWN_ERROR"; + break; + } + return err_msg; +} diff --git a/tbt_smartcardtestapp/tizen-manifest.xml b/tbt_smartcardtestapp/tizen-manifest.xml new file mode 100755 index 0000000..2294d3e --- /dev/null +++ b/tbt_smartcardtestapp/tizen-manifest.xml @@ -0,0 +1,13 @@ + + + + + + smartcardactestapp.png + + + http://tizen.org/privilege/nfc.cardemulation + http://tizen.org/privilege/nfc + http://tizen.org/privilege/secureelement + + diff --git a/tbt_smartcardtestapp_signed/.cproject b/tbt_smartcardtestapp_signed/.cproject new file mode 100755 index 0000000..e024f6f --- /dev/null +++ b/tbt_smartcardtestapp_signed/.cproject @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tbt_smartcardtestapp_signed/.exportMap b/tbt_smartcardtestapp_signed/.exportMap new file mode 100755 index 0000000..43e310e --- /dev/null +++ b/tbt_smartcardtestapp_signed/.exportMap @@ -0,0 +1,4 @@ +{ + global: main; + local: *; +}; diff --git a/tbt_smartcardtestapp_signed/.project b/tbt_smartcardtestapp_signed/.project new file mode 100644 index 0000000..eaf5145 --- /dev/null +++ b/tbt_smartcardtestapp_signed/.project @@ -0,0 +1,26 @@ + + + tbt_smartcardtestapp_signed + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/tbt_smartcardtestapp_signed/.rds_delta b/tbt_smartcardtestapp_signed/.rds_delta new file mode 100755 index 0000000..fff12c7 --- /dev/null +++ b/tbt_smartcardtestapp_signed/.rds_delta @@ -0,0 +1,6 @@ +#delete +#add +#modify +author-signature.xml +signature1.xml +bin/smartcardactestapp_signed diff --git a/tbt_smartcardtestapp_signed/.sdk_delta.info b/tbt_smartcardtestapp_signed/.sdk_delta.info new file mode 100644 index 0000000..ff05527 Binary files /dev/null and b/tbt_smartcardtestapp_signed/.sdk_delta.info differ diff --git a/tbt_smartcardtestapp_signed/.sign/.manifest.tmp b/tbt_smartcardtestapp_signed/.sign/.manifest.tmp new file mode 100644 index 0000000..b40d997 --- /dev/null +++ b/tbt_smartcardtestapp_signed/.sign/.manifest.tmp @@ -0,0 +1,4 @@ +bin/smartcardactestapp_signed__DEL__8TPA4i2kFe0kIIQxpEXNBIBXA3NpkgRnqlnf+5iKbO4= +shared/res/smartcardactestapp.png__DEL__1d0oEZHqPn+QzNzGIHwj9ODby6x9ggFs9uOsav6jPNs= +tizen-manifest.xml__DEL__JJf6NE9HOgcJ3fhjfgET4Qcr8mvoiElVwJT9hIM0v9Y= +author-signature.xml__DEL__+Jm7Nkw4XTqhE/5iTabSWmorJFU9Xa6qcO4Pf8K6rqo= diff --git a/tbt_smartcardtestapp_signed/.sign/author-signature.xml b/tbt_smartcardtestapp_signed/.sign/author-signature.xml new file mode 100644 index 0000000..7a7e768 --- /dev/null +++ b/tbt_smartcardtestapp_signed/.sign/author-signature.xml @@ -0,0 +1,66 @@ + + + + + + +8TPA4i2kFe0kIIQxpEXNBIBXA3NpkgRnqlnf+5iKbO4= + + + +1d0oEZHqPn+QzNzGIHwj9ODby6x9ggFs9uOsav6jPNs= + + + +JJf6NE9HOgcJ3fhjfgET4Qcr8mvoiElVwJT9hIM0v9Y= + + + + + + +lpo8tUDs054eLlBQXiDPVDVKfw30ZZdtkRs1jd7H5K8= + + + +LG+2J4du7dmNzhqiEZ0hkGqaP8YPK5HqlS7VLsOJqZgSil8a3lmp2++B7ZJDZN39p5IaaOaDM2SI +73YP6UTOxZSWWTORjz9brtpv5MfiAAZIS+hmqfwBs4O6QIU5M5VHnE2GqcbTy2ka9jjw0xgY+OGt +N+IdtiBCB+0zaCWcDjw= + + + + +MIICpjCCAY6gAwIBAgIGAVbbHLCfMA0GCSqGSIb3DQEBBQUAMFYxGjAYBgNVBAoMEVRpemVuIEFz +c29jaWF0aW9uMRowGAYDVQQLDBFUaXplbiBBc3NvY2lhdGlvbjEcMBoGA1UEAwwTVGl6ZW4gRGV2 +ZWxvcGVycyBDQTAeFw0xMjExMDEwMDAwMDBaFw0xOTAxMDEwMDAwMDBaMCIxIDAeBgNVBAMMF2po +ODgwMS5qdW5nQHNhbXN1bmcuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCiSEksJVtQ +UDYwzKcH2UG0Hq+hycJ/Pviq1z8JsecqGPCH4z8a4wqRKlan8QT4xXcEiYrwhYKTiGu8PoDNBnWN ++l2DTWL7tUSpklWLjU+n9Omiq8OAtGb3T5Iz7oumhKX47ol4+aou4ObjD3ZPmOS50kPdymhfKJVj +DdmdQhDQqQIDAQABozIwMDAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggr +BgEFBQcDAzANBgkqhkiG9w0BAQUFAAOCAQEAS4eY0vQIENJj1Va59ZAeHt6mUozCvcwF5F1jk4Da +LE6PXBWxgCAc4eTXUL3UGfVgLi9v+dVb29Dx2x+IjX0roZGmAiVLynMjlZoXerxS8GBjFDqi3Cmc +j1xdecycTHXMC3tJeXHjGfANEt449pDm5aY+oKCulHUtQvv+zasI2kehahvrG2O+PmA3PZ6I9rdR +tCIpfLHHuC3x1alqrcxOSFcjuqLPPfxq7igc1Qib6pDkIBeJwwSEry5bKbGVTLu22pmm4GZSJp8V +YTWi+p1YXAg1dH+GhsUGpmzmx7n2s8TWJxy7OQK0BU+owUtH/x92iKYMGBAYz+erdZY4s89SHA== + + +MIIDOTCCAiGgAwIBAgIBATANBgkqhkiG9w0BAQUFADBYMRowGAYDVQQKDBFUaXplbiBBc3NvY2lh +dGlvbjEaMBgGA1UECwwRVGl6ZW4gQXNzb2NpYXRpb24xHjAcBgNVBAMMFVRpemVuIERldmVsb3Bl +cnMgUm9vdDAeFw0xMjAxMDEwMDAwMDBaFw0yNzAxMDEwMDAwMDBaMFYxGjAYBgNVBAoMEVRpemVu +IEFzc29jaWF0aW9uMRowGAYDVQQLDBFUaXplbiBBc3NvY2lhdGlvbjEcMBoGA1UEAwwTVGl6ZW4g +RGV2ZWxvcGVycyBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANVGhRGmMIUyBA7o +PCz8Sxut6z6HNkF4oDIuzuKaMzRYPeWodwe9O0gmqAkToQHfwg2giRhE5GoPld0fq+OYMMwSasCu +g8dwODx1eDeSYVuOLWRxpAmbTXOsSFi6VoWeyaPEm18JBHvZBsU5YQtgZ6Kp7MqzvQg3pXOxtajj +vyHxiatJl+xXrHgcXC1wgyG3buty7u/Fi2mvKXJ0PRJcCjjK81dqe/Vr20sRUCrbk02zbm5ggFt/ +jIEhV8wbFRQpliobc7J4dSTKhFfrqGM8rdd54LYhD7gSI1CFSe16pUXfcVR7FhJztRaiGLnCrwBE +dyTZ248+D4L/qR/D0axb3jcCAwEAAaMQMA4wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOC +AQEAnOXXQ/1O/QTDHyrmQDtFziqPY3xWlJBqJtEqXiT7Y+Ljpe66e+Ee/OjQMlZe8gu21/8cKklH +95RxjopMWCVedXDUbWdvS2+CdyvVW/quT2E0tjqIzXDekUTYwwhlPWlGxvfj3VsxqSFq3p8Brl04 +1Gx5RKAGyKVsMfTLhbbwSWwApuBUxYfcNpKwLWGPXkysu+HctY03OKv4/xKBnVWiN8ex/Sgesi0M ++OBAOMdZMPK32uJBTeKFx1xZgTLIhk45V0hPOomPjZloiv0LSS11eyd451ufjW0iHRE7WlpR6EvI +W6TFyZgMpQq+kg4hWl2SBTf3s2VI8Ygz7gj8TMlClg== + + + + + \ No newline at end of file diff --git a/tbt_smartcardtestapp_signed/.sign/signature1.xml b/tbt_smartcardtestapp_signed/.sign/signature1.xml new file mode 100644 index 0000000..cd85bfc --- /dev/null +++ b/tbt_smartcardtestapp_signed/.sign/signature1.xml @@ -0,0 +1,68 @@ + + + + + + ++Jm7Nkw4XTqhE/5iTabSWmorJFU9Xa6qcO4Pf8K6rqo= + + + +8TPA4i2kFe0kIIQxpEXNBIBXA3NpkgRnqlnf+5iKbO4= + + + +1d0oEZHqPn+QzNzGIHwj9ODby6x9ggFs9uOsav6jPNs= + + + +JJf6NE9HOgcJ3fhjfgET4Qcr8mvoiElVwJT9hIM0v9Y= + + + + + + +u/jU3U4Zm5ihTMSjKGlGYbWzDfRkGphPPHx3gJIYEJ4= + + + +BiUyrQbk2vLsTvG/hwH7Ypea0Cmd3g8VIZsYKzmogZH3tCcI8UdsZIXB7pmR8WvM/3q0JNOH5j3e +Fm/R0O461EvVGOXY4XM78EV+ddTba7Z6PJEp6sKZLWYGqIa3eoIWtAYT7WhUrxHM+6GJbBLDvC6M +P4NxpFWP6ltLzk6yIWc= + + + + +MIICmzCCAgQCCQDXI7WLdVZwiTANBgkqhkiG9w0BAQUFADCBjzELMAkGA1UEBhMCS1IxDjAMBgNV +BAgMBVN1d29uMQ4wDAYDVQQHDAVTdXdvbjEWMBQGA1UECgwNVGl6ZW4gVGVzdCBDQTEiMCAGA1UE +CwwZVGl6ZW4gRGlzdHJpYnV0b3IgVGVzdCBDQTEkMCIGA1UEAwwbVGl6ZW4gUHVibGljIERpc3Ry +aWJ1dG9yIENBMB4XDTEyMTAyOTEzMDMwNFoXDTIyMTAyNzEzMDMwNFowgZMxCzAJBgNVBAYTAktS +MQ4wDAYDVQQIDAVTdXdvbjEOMAwGA1UEBwwFU3V3b24xFjAUBgNVBAoMDVRpemVuIFRlc3QgQ0Ex +IjAgBgNVBAsMGVRpemVuIERpc3RyaWJ1dG9yIFRlc3QgQ0ExKDAmBgNVBAMMH1RpemVuIFB1Ymxp +YyBEaXN0cmlidXRvciBTaWduZXIwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALtMvlc5hENK +90ZdA+y66+Sy0enD1gpZDBh5T9RP0oRsptJv5jjNTseQbQi0SZOdOXb6J7iQdlBCtR343RpIEz8H +mrBy7mSY7mgwoU4EPpp4CTSUeAuKcmvrNOngTp5Hv7Ngf02TTHOLK3hZLpGayaDviyNZB5PdqQdB +hokKjzAzAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvGp1gxxAIlFfhJH1efjb9BJK/rtRkbYn9+Ez +GEbEULg1svsgnyWisFimI3uFvgI/swzr1eKVY3Sc8MQ3+Fdy3EkbDZ2+WAubhcEkorTWjzWz2fL1 +vKaYjeIsuEX6TVRUugHWudPzcEuQRLQf8ibZWjbQdBmpeQYBMg5x+xKLCJc= + + +MIICtDCCAh2gAwIBAgIJAMDbehElPNKvMA0GCSqGSIb3DQEBBQUAMIGVMQswCQYDVQQGEwJLUjEO +MAwGA1UECAwFU3V3b24xDjAMBgNVBAcMBVN1d29uMRYwFAYDVQQKDA1UaXplbiBUZXN0IENBMSMw +IQYDVQQLDBpUVGl6ZW4gRGlzdHJpYnV0b3IgVGVzdCBDQTEpMCcGA1UEAwwgVGl6ZW4gUHVibGlj +IERpc3RyaWJ1dG9yIFJvb3QgQ0EwHhcNMTIxMDI5MTMwMjUwWhcNMjIxMDI3MTMwMjUwWjCBjzEL +MAkGA1UEBhMCS1IxDjAMBgNVBAgMBVN1d29uMQ4wDAYDVQQHDAVTdXdvbjEWMBQGA1UECgwNVGl6 +ZW4gVGVzdCBDQTEiMCAGA1UECwwZVGl6ZW4gRGlzdHJpYnV0b3IgVGVzdCBDQTEkMCIGA1UEAwwb +VGl6ZW4gUHVibGljIERpc3RyaWJ1dG9yIENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDe +OTS/3nXvkDEmsFCJIvRlQ3RKDcxdWJJp625pFqHdmoJBdV+x6jl1raGK2Y1sp2Gdvpjc/z92yzAp +bE/UVLPh/tRNZPeGhzU4ejDDm7kzdr2f7Ia0U98K+OoY12ucwg7TYNItj9is7Cj4blGfuMDzd2ah +2AgnCGlwNwV/pv+uVQIDAQABoxAwDjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBACqJ +KO33YdoGudwanZIxMdXuxnnD9R6u72ltKk1S4zPfMJJv482CRGCI4FK6djhlsI4i0Lt1SVIJEed+ +yc3qckGm19dW+4xdlkekon7pViEBWuyHw8OWv3RXtTum1+PGHjBJ2eYY4ZKIpz73U/1NC16sTB/0 +VhfnkHwPltmrpYVe + + + + + \ No newline at end of file diff --git a/tbt_smartcardtestapp_signed/.tproject b/tbt_smartcardtestapp_signed/.tproject new file mode 100755 index 0000000..de5a150 --- /dev/null +++ b/tbt_smartcardtestapp_signed/.tproject @@ -0,0 +1,12 @@ + + + + + wearable-3.0 + + + + + + + diff --git a/tbt_smartcardtestapp_signed/SmartcardPKCS12.p12 b/tbt_smartcardtestapp_signed/SmartcardPKCS12.p12 new file mode 100755 index 0000000..ad55540 Binary files /dev/null and b/tbt_smartcardtestapp_signed/SmartcardPKCS12.p12 differ diff --git a/tbt_smartcardtestapp_signed/inc/logger.h b/tbt_smartcardtestapp_signed/inc/logger.h new file mode 100644 index 0000000..772ceab --- /dev/null +++ b/tbt_smartcardtestapp_signed/inc/logger.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2014 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. + *******************************************************************************/ + +/** + * @file logger.h + * @brief This file provide necessary macro for logging information. + * @since_tizen 2.3 + * @author Amlan Chowdhury (amlan.c@samsung.com) + * @date October, 2014 + * @bug + * @credit + */ +#ifndef __LOGGER_H__ +#define __LOGGER_H__ + +#include + +#define LOG_TAG_CORE "[TBT_CORE]_" + +#define DLOG(prio, fmt, arg...) dlog_print(prio, LOG_TAG_CORE, "%s (Line: %d) > " fmt, __func__, __LINE__, ##arg) +#define DBG(fmt, arg...) DLOG(DLOG_DEBUG, fmt, ##arg) +#define ERR(fmt, arg...) DLOG(DLOG_ERROR, fmt, ##arg) + +#define RETM_IF(expr, fmt, arg...) \ +{ \ + if (expr) \ + { \ + ERR(fmt, ##arg); \ + return; \ + } \ +} + +#define RETVM_IF(expr, val, fmt, arg...) \ +{ \ + if (expr) \ + { \ + ERR(fmt, ##arg); \ + return (val); \ + } \ +} + +#define SAFE_DELETE(a) if( (a) != NULL ) free (a); (a) = NULL; + +#endif /* __LOGGER_H__ */ diff --git a/tbt_smartcardtestapp_signed/inc/smartcardactestapp.h b/tbt_smartcardtestapp_signed/inc/smartcardactestapp.h new file mode 100755 index 0000000..fdf0e8b --- /dev/null +++ b/tbt_smartcardtestapp_signed/inc/smartcardactestapp.h @@ -0,0 +1,15 @@ +#ifndef __smartcardactestapp_H__ +#define __smartcardactestapp_H__ + +#include +#include +#include +#include +#include "logger.h" + + +#if !defined(PACKAGE) +#define PACKAGE "org.tizen.smartcard.actestapp" +#endif + +#endif /* __smartcardactestapp_H__ */ diff --git a/tbt_smartcardtestapp_signed/project_def.prop b/tbt_smartcardtestapp_signed/project_def.prop new file mode 100755 index 0000000..cc93b41 --- /dev/null +++ b/tbt_smartcardtestapp_signed/project_def.prop @@ -0,0 +1,11 @@ +APPNAME = smartcardactestapp + +type = app +profile = wearable-3.0 + +USER_SRCS = src/smartcardactestapp.c +USER_DEFS = +USER_INC_DIRS = inc +USER_OBJS = +USER_LIBS = +USER_EDCS = diff --git a/tbt_smartcardtestapp_signed/shared/res/smartcardactestapp.png b/tbt_smartcardtestapp_signed/shared/res/smartcardactestapp.png new file mode 100755 index 0000000..9765b1b Binary files /dev/null and b/tbt_smartcardtestapp_signed/shared/res/smartcardactestapp.png differ diff --git a/tbt_smartcardtestapp_signed/src/smartcardactestapp.c b/tbt_smartcardtestapp_signed/src/smartcardactestapp.c new file mode 100755 index 0000000..36806e9 --- /dev/null +++ b/tbt_smartcardtestapp_signed/src/smartcardactestapp.c @@ -0,0 +1,254 @@ +#include "smartcardactestapp.h" +#include + +typedef struct appdata { + Evas_Object *win; + Evas_Object *conform; + Evas_Object *label; +} appdata_s; + +static char* get_smartcard_error(smartcard_error_e error); + +static void +win_delete_request_cb(void *data, Evas_Object *obj, void *event_info) +{ + ui_app_exit(); +} + +static void +win_back_cb(void *data, Evas_Object *obj, void *event_info) +{ + appdata_s *ad = data; + /* Let window go to hide state. */ + elm_win_lower(ad->win); +} + +static void +create_base_gui(appdata_s *ad) +{ + DBG("create_base_gui"); + /* Window */ + /* Create and initialize elm_win. + elm_win is mandatory to manipulate window. */ + ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE); + elm_win_autodel_set(ad->win, EINA_TRUE); + + if (elm_win_wm_rotation_supported_get(ad->win)) { + int rots[4] = { 0, 90, 180, 270 }; + elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4); + } + + evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL); + eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad); + + /* Conformant */ + /* Create and initialize elm_conformant. + elm_conformant is mandatory for base gui to have proper size + when indicator or virtual keypad is visible. */ + ad->conform = elm_conformant_add(ad->win); + elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW); + elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE); + evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(ad->win, ad->conform); + evas_object_show(ad->conform); + + /* Label */ + /* Create an actual view of the base gui. + Modify this part to change the view. */ + ad->label = elm_label_add(ad->conform); + + DBG("smartcard_initialize"); + int ret; + ret = smartcard_initialize(); + DBG("smartcard_initialize : %s", get_smartcard_error(ret)); + if (ret == SMARTCARD_ERROR_NONE) { + int reader_length; + int* readers; + + ret = smartcard_get_readers(&readers, &reader_length); + DBG("smartcard_get_readers : %s", get_smartcard_error(ret)); + if (ret == SMARTCARD_ERROR_NONE && reader_length > 0) { + int session; + ret = smartcard_reader_open_session(readers[0], &session); + DBG("smartcard_reader_open_session : %s", get_smartcard_error(ret)); + if (ret == SMARTCARD_ERROR_NONE) { + int channel; + unsigned char aid[] = {0x43, 0x4F, 0x4E, 0x56, 0x45, 0x52, 0x47, 0x45, 0x4E, 0x43, 0x45, 0x4E, 0x46, 0x43}; + ret = smartcard_session_open_basic_channel(session, aid, 14, 0x00, &channel); + DBG("smartcard_session_open_basic_channel : %s", get_smartcard_error(ret)); + if (ret == SMARTCARD_ERROR_NONE) { + ret = SMARTCARD_ERROR_NONE; + } + } + } else { + ret = SMARTCARD_ERROR_GENERAL; + } + } + + /* Label */ + /* Create an actual view of the base gui. + Modify this part to change the view. */ + ad->label = elm_label_add(ad->conform); + if (ret == SMARTCARD_ERROR_NONE) { + elm_object_text_set(ad->label, "Passed"); + } else { + elm_object_text_set(ad->label, "Failed"); + } + + evas_object_size_hint_weight_set(ad->label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_content_set(ad->conform, ad->label); + + /* Show window after base gui is set up */ + evas_object_show(ad->win); +} + +static bool +app_create(void *data) +{ + /* Hook to take necessary actions before main event loop starts + Initialize UI resources and application's data + If this function returns true, the main loop of application starts + If this function returns false, the application is terminated */ + appdata_s *ad = data; + + create_base_gui(ad); + + return true; +} + +static void +app_control(app_control_h app_control, void *data) +{ + /* Handle the launch request. */ +} + +static void +app_pause(void *data) +{ + /* Take necessary actions when application becomes invisible. */ +} + +static void +app_resume(void *data) +{ + /* Take necessary actions when application becomes visible. */ +} + +static void +app_terminate(void *data) +{ + /* Release all resources. */ +} + +static void +ui_app_lang_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LANGUAGE_CHANGED*/ + char *locale = NULL; + system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale); + elm_language_set(locale); + free(locale); + return; +} + +static void +ui_app_orient_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/ + return; +} + +static void +ui_app_region_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_REGION_FORMAT_CHANGED*/ +} + +static void +ui_app_low_battery(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_BATTERY*/ +} + +static void +ui_app_low_memory(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_MEMORY*/ +} + +int +main(int argc, char *argv[]) +{ + appdata_s ad = {0,}; + int ret = 0; + + ui_app_lifecycle_callback_s event_callback = {0,}; + app_event_handler_h handlers[5] = {NULL, }; + + event_callback.create = app_create; + event_callback.terminate = app_terminate; + event_callback.pause = app_pause; + event_callback.resume = app_resume; + event_callback.app_control = app_control; + + ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad); + ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad); + ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad); + ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad); + ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad); + + ret = ui_app_main(argc, argv, &event_callback, &ad); + if (ret != APP_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret); + } + + return ret; +} + +static char* get_smartcard_error(smartcard_error_e error) +{ + char* err_msg; + switch (error) { + + case SMARTCARD_ERROR_NONE: + err_msg = "SMARTCARD_ERROR_NONE"; + break; + case SMARTCARD_ERROR_GENERAL: + err_msg = "SMARTCARD_ERROR_GENERAL"; + break; + case SMARTCARD_ERROR_IO_ERROR: + err_msg = "SMARTCARD_ERROR_IO_ERROR"; + break; + case SMARTCARD_ERROR_NO_SUCH_ELEMENT: + err_msg = "SMARTCARD_ERROR_NO_SUCH_ELEMENT"; + break; + case SMARTCARD_ERROR_ILLEGAL_STATE: + err_msg = "SMARTCARD_ERROR_ILLEGAL_STATE"; + break; + case SMARTCARD_ERROR_INVALID_PARAMETER: + err_msg = "SMARTCARD_ERROR_INVALID_PARAMETER"; + break; + case SMARTCARD_ERROR_ILLEGAL_REFERENCE: + err_msg = "SMARTCARD_ERROR_ILLEGAL_REFERENCE"; + break; + case SMARTCARD_ERROR_OPERATION_NOT_SUPPORTED: + err_msg = "SMARTCARD_ERROR_OPERATION_NOT_SUPPORTED"; + break; + case SMARTCARD_ERROR_PERMISSION_DENIED: + err_msg = "SMARTCARD_ERROR_PERMISSION_DENIED"; + break; + case SMARTCARD_ERROR_CHANNEL_NOT_AVAILABLE: + err_msg = "SMARTCARD_ERROR_CHANNEL_NOT_AVAILABLE"; + break; + case SMARTCARD_ERROR_NOT_INITIALIZED: + err_msg = "SMARTCARD_ERROR_NOT_INITIALIZED"; + break; + case SMARTCARD_ERROR_NOT_SUPPORTED: + err_msg = "SMARTCARD_ERROR_NOT_SUPPORTED"; + break; + default: + err_msg = "UNKNOWN_ERROR"; + break; + } + return err_msg; +} diff --git a/tbt_smartcardtestapp_signed/tizen-manifest.xml b/tbt_smartcardtestapp_signed/tizen-manifest.xml new file mode 100755 index 0000000..1ee26d6 --- /dev/null +++ b/tbt_smartcardtestapp_signed/tizen-manifest.xml @@ -0,0 +1,13 @@ + + + + + + smartcardactestapp.png + + + http://tizen.org/privilege/nfc.cardemulation + http://tizen.org/privilege/nfc + http://tizen.org/privilege/secureelement + + diff --git a/tbtcoreapp/inc/model/tbt-info.h b/tbtcoreapp/inc/model/tbt-info.h index 878fe23..ad8abaf 100644 --- a/tbtcoreapp/inc/model/tbt-info.h +++ b/tbtcoreapp/inc/model/tbt-info.h @@ -75,6 +75,7 @@ typedef enum { TBT_APP_BT_PBAP_ALL_VCARDS, TBT_APP_BLE_GATT_CLIENT, + TBT_APP_BLE_GATT_SERVER, TBT_APP_BT_CALLBACK_CREATE_BOND_TEST, TBT_APP_BT_CALLBACK_DESTROY_BOND_TEST, @@ -242,7 +243,15 @@ typedef enum { TBT_APP_D2D_CLIENT, - TBT_APP_D2D_SERVER + TBT_APP_D2D_SERVER, + + TBT_APP_TTS, + + TBT_APP_STT, + + TBT_APP_STT_ERROR, + + TBT_APP_SMARTCARD } tbt_app_type_e; diff --git a/tbtcoreapp/inc/utils/app_module_config.h b/tbtcoreapp/inc/utils/app_module_config.h index 259e181..bca8a8b 100644 --- a/tbtcoreapp/inc/utils/app_module_config.h +++ b/tbtcoreapp/inc/utils/app_module_config.h @@ -43,6 +43,7 @@ //#define TBT_MODULE_BLE //#define TBT_MODULE_BLE_GATT_CLIENT +//#define TBT_MODULE_BLE_GATT_SERVER #define TBT_MODULE_BT_CALLBACK_TEST #define TBT_MODULE_APP_BT_CALLBACK_CREATE_BOND_TEST @@ -240,4 +241,13 @@ #define TBT_MODULE_APP_D2D_CLIENT #define TBT_MODULE_APP_D2D_SERVER +#define TBT_MODULE_TTS +#define TBT_MODULE_APP_TTS +#define TBT_MODULE_STT +#define TBT_MODULE_APP_STT +#define TBT_MODULE_APP_STT_ERROR + +#define TBT_MODULE_SMARTCARD +#define TBT_MODULE_APP_SMARTCARD + #endif diff --git a/tbtcoreapp/inc/utils/config.h b/tbtcoreapp/inc/utils/config.h index 61587a2..56525e0 100644 --- a/tbtcoreapp/inc/utils/config.h +++ b/tbtcoreapp/inc/utils/config.h @@ -95,6 +95,9 @@ extern bool __is_efl_test_running; #define PICK_VIEW_APP_PACKAGE_NAME "org.tizen.coretbt_uiapp"; #define PICK_VIEW_SERVICEAPP_PACKAGE_NAME "org.tizen.coretbt_serviceapp"; +#define SMARTCARD_SIGNED_APPID "org.tizen.smartcard.actestapp_signed" +#define SMARTCARD_UNSIGNED_APPID "org.tizen.smartcard.actestapp" + #define PICK_VIEW_URL_HTTP "http://www.tizen.org" #define PICK_VIEW_URL_HTTPS "https://www.tizen.org/" @@ -112,6 +115,8 @@ extern bool __is_efl_test_running; #define PICK_VIEW_VIDEO_3GP "video/sampleH263.3gp" #define PICK_VIEW_VIDEO_MP4 "video/sampleMPEG4.mp4" +#define STT_START_RECORDING_SOUND "sounds/start_record.wav" + diff --git a/tbtcoreapp/inc/view/tbt-smartcard-view.h b/tbtcoreapp/inc/view/tbt-smartcard-view.h new file mode 100644 index 0000000..c1ec38e --- /dev/null +++ b/tbtcoreapp/inc/view/tbt-smartcard-view.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2014 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. + * + *******************************************************************************/ +/** + * @file tbt-smartcard-view.h + * @brief smartcard single and multiple item. + * @since_tizen 2.3 + * @author Muntasir Kabir (mk.chy@samsung.com) + * @date October, 2014 + * @bug no known bug + * @credit Tizen SDK Version 2.3.0 Sample Example + * + */ + +#ifndef __TBT_SMARTCARD_VIEW_H__ +#define __TBT_SMARTCARD_VIEW_H__ + +#include "utils/app_module_config.h" +#ifdef TBT_MODULE_APP + +#include +#include "model/tbt-list.h" + + +/** + * @typedef smartcard_view + * @since_tizen 2.3 + * @brief A smartcard viewer view handle. + */ +typedef struct _smartcard_view smartcard_view; + +/** + * @brief Add smartcard view + * @since_tizen 2.3 + * @param[in] app The pointer to _app_data instance + * @param[in] navi The naviframe object + * @return smartcard view data + */ +smartcard_view *smartcard_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item *item); + +#endif +#endif // __TBT_PCIK_VIEW_H__ diff --git a/tbtcoreapp/inc/view/tbt-stt-view.h b/tbtcoreapp/inc/view/tbt-stt-view.h new file mode 100644 index 0000000..4f86030 --- /dev/null +++ b/tbtcoreapp/inc/view/tbt-stt-view.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2014 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. + * + *******************************************************************************/ +/** + * @file tbt-stt-view.h + * @brief covers speech to text recognition + * + * @author A. B. M. Nazibullah(nazib.ullah@samsung.com) + * @date August, 2016 + * @bug + * @credit + * + */ + +#ifndef __TBT_STT_VIEW_H__ +#define __TBT_STT_VIEW_H__ + +#include "utils/app_module_config.h" +#ifdef TBT_MODULE_STT + +#include +#include "model/tbt-list.h" + + +/** + * @typedef stt_viewer_view + * @since_tizen 2.3 + * @brief A stt viewer view handle. + */ +typedef struct _stt_view stt_view; + +/** + * @brief Create stt view + * @since_tizen 2.3 + * @param[in] navi Parent naviframe + * @param[in] custom structute to hold tbt application information + * @param[in] item of the main tbt menu + * @return Pointer of stt on success, otherwise NULL + */ +stt_view *stt_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item *item); + +#endif +#endif // __TBT_STT_VIEW_H__ diff --git a/tbtcoreapp/inc/view/tbt-tts-view.h b/tbtcoreapp/inc/view/tbt-tts-view.h new file mode 100644 index 0000000..c9db2ea --- /dev/null +++ b/tbtcoreapp/inc/view/tbt-tts-view.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2014 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. + * + *******************************************************************************/ +/** + * @file tbt-tts-view.h + * @brief coverst text to speech operations + * + * @author A. B. M. Nazibullah (nazib.ullah@samsung.com) + * @date August, 2016 + * @bug + * @credit + * + */ + +#ifndef __TBT_TTS_VIEW_H__ +#define __TBT_TTS_VIEW_H__ + +#include "utils/app_module_config.h" +#ifdef TBT_MODULE_TTS + +#include +#include "model/tbt-list.h" + + +/** + * @typedef tts_viewer_view + * @since_tizen 2.3 + * @brief A tts viewer view handle. + */ +typedef struct _tts_view tts_view; + +/** + * @brief Create tts camera view + * @since_tizen 2.3 + * @param[in] navi Parent naviframe + * @param[in] custom structute to hold tbt application information + * @param[in] item of the main tbt menu + * @return Pointer of tts on success, otherwise NULL + */ +tts_view *tts_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item *item); + +#endif +#endif // __TBT_TTS_VIEW_H__ diff --git a/tbtcoreapp/res/edje/2.3.1/wearable_360_360/bluetooth_le_viewer.edc b/tbtcoreapp/res/edje/2.3.1/wearable_360_360/bluetooth_le_viewer.edc index 2042707..e72fc93 100755 --- a/tbtcoreapp/res/edje/2.3.1/wearable_360_360/bluetooth_le_viewer.edc +++ b/tbtcoreapp/res/edje/2.3.1/wearable_360_360/bluetooth_le_viewer.edc @@ -1,77 +1,108 @@ /* - * Copyright (c) 2014 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. - */ - -#define TEXT_HEIGHT 0.08 -#define CONTENT_X_PAD 0.15 - -#include "wearable_circle_toolbar.edc" - +* Copyright (c) 2014 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. +*/ collections { - base_scale: 1.8; - group - { - name: "bluetoothle_viewer"; - parts{ - part{ - name: "bluetoothle_text"; - type: SWALLOW; - description{ - state: "default" 0.0; - align: 0.0 0.0; - visible: 1; - rel1 {relative: 0.0 0.0; } - rel2 {relative: 1.0 TEXT_HEIGHT; } - } + base_scale: 1.33; + group + { + name: "bluetoothle_viewer"; + parts{ + part{ + name: "bluetoothle_text"; + type: SWALLOW; + description{ + state: "default" 0.0; + align: 0.0 0.0; + visible: 1; + rel1 { + relative: 0.0 0.0; + } + rel2 { + relative: 1.0 0.10; + } } - - part{ - name: "bluetoothle_list"; - type: SWALLOW; - description{ - state: "default" 0.0; - align: 0.0 0.0; - visible: 1; - rel1{ - relative: 0.0 1.0; - to_y: "bluetoothle_text"; - } - rel2{ - relative: 1.0 0.43; - } - } + } + part{ + name: "bluetoothle_list"; + type: SWALLOW; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 0.10; + } + rel2 { + relative: 1.0 0.60; + } + visible: 1; } - - part{ - name: "controlr_part"; - type: SWALLOW; - description { - state: "default" 0.0; - rel1 { - relative: 0.0 1.0; - to_y: "bluetoothle_list"; - } - rel2 { - relative: 1.0 63; - } - visible: 1; - } - } - - WEARABLE_TOOLBAR_PART - } - } + } + part { name: "padding"; + type: SPACER; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 0.60; + } + rel2 { + relative: 1.0 0.65; + } + fixed: 1 0; + } + } + part{ + name: "controlr_part"; + type: SWALLOW; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 0.65; + } + rel2 { + relative: 1.0 0.70; + } + visible: 1; + } + } + part { name: "padding2"; + type: SPACER; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 0.70; + } + rel2 { + relative: 1.0 1.0; + } + fixed: 1 0; + } + } + part { name: "wearable_toolbar"; + type: SWALLOW; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 1.0; + } + rel2 { + relative: 1.0 1.0; + } + visible: 1; + } + } + } + } + } diff --git a/tbtcoreapp/res/edje/2.3.1/wearable_360_360/stt_viewer.edc b/tbtcoreapp/res/edje/2.3.1/wearable_360_360/stt_viewer.edc new file mode 100644 index 0000000..fe66528 --- /dev/null +++ b/tbtcoreapp/res/edje/2.3.1/wearable_360_360/stt_viewer.edc @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2014 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. +*/ +collections +{ + base_scale: 1.40; + group + { + name: "stt_viewer"; + parts{ + part{ + name: "txt_part_1"; + type: SWALLOW; + description{ + state: "default" 0.0; + align: 0.0 0.0; + visible: 1; + rel1 { + relative: 0.0 0.0; + } + rel2 { + relative: 1.0 0.12; + } + } + } + part{ + name: "list_part"; + type: SWALLOW; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 0.25; + } + rel2 { + relative: 1.0 0.50; + } + visible: 1; + } + } + part { name: "padding"; + type: SPACER; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 0.50; + } + rel2 { + relative: 1.0 0.55; + } + fixed: 1 0; + } + } + part{ + name: "btn_part"; + type: SWALLOW; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 0.55; + } + rel2 { + relative: 1.0 0.70; + } + visible: 1; + } + } + part { name: "padding2"; + type: SPACER; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 0.70; + } + rel2 { + relative: 1.0 1.0; + } + fixed: 1 0; + } + } + part { name: "wearable_toolbar"; + type: SWALLOW; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 1.0; + } + rel2 { + relative: 1.0 1.0; + } + visible: 1; + } + } + } + } +} \ No newline at end of file diff --git a/tbtcoreapp/res/edje/2.3.1/wearable_360_360/tts_viewer.edc b/tbtcoreapp/res/edje/2.3.1/wearable_360_360/tts_viewer.edc new file mode 100644 index 0000000..8d6b9ea --- /dev/null +++ b/tbtcoreapp/res/edje/2.3.1/wearable_360_360/tts_viewer.edc @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2014 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. +*/ +#define TEXT_HEIGHT 0.08 +collections +{ + base_scale: 1.8; + group + { + name: "tts_viewer"; + parts{ + part{ + name: "txt_part"; + type: SWALLOW; + description{ + state: "default" 0.0; + align: 0.0 0.0; + visible: 1; + rel1 { + relative: 0.0 0.0; + } + rel2 { + relative: 1.0 TEXT_HEIGHT; + } + } + } + part{ + name: "btn_part"; + type: SWALLOW; + description{ + state: "default" 0.0; + align: 0.0 0.0; + visible: 1; + rel1 { + relative: 0.0 0.40; + } + rel2 { + relative: 1.0 0.55; + } + } + } + part { name: "padding"; + type: SPACER; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 0.55; + } + rel2 { + relative: 1.0 1.0; + } + fixed: 1 0; + } + } + part { name: "wearable_toolbar"; + type: SWALLOW; + description { + state: "default" 0.0; + rel1 { + relative: 0.0 1.0; + } + rel2 { + relative: 1.0 1.0; + } + visible: 1; + } + } + } + } +} \ No newline at end of file diff --git a/tbtcoreapp/res/sounds/start_record.wav b/tbtcoreapp/res/sounds/start_record.wav new file mode 100644 index 0000000..725a86b Binary files /dev/null and b/tbtcoreapp/res/sounds/start_record.wav differ diff --git a/tbtcoreapp/src/model/tbt-list.c b/tbtcoreapp/src/model/tbt-list.c index 0e89fd2..4d7f72d 100644 --- a/tbtcoreapp/src/model/tbt-list.c +++ b/tbtcoreapp/src/model/tbt-list.c @@ -147,20 +147,37 @@ static tbt_info tbtapps[] = #endif #endif + #ifdef TBT_MODULE_BLE - //Bluetooth LE Gatt Client - { - .name = "Gatt Client", - .parent = "Bluetooth LE", - .apptype = TBT_APP_BLE_GATT_CLIENT, - .icon_name = "dummy", - .info = "Bluetooth LE Gatt Cleint", - .result = 0, - .required_features_count = 1, - .features_required = {16} - }, + #ifdef TBT_MODULE_BLE_GATT_CLIENT + //Bluetooth LE Gatt Client + { + .name = "Gatt Client", + .parent = "Bluetooth LE", + .apptype = TBT_APP_BLE_GATT_CLIENT, + .icon_name = "dummy", + .info = "Bluetooth LE Gatt Cleint", + .result = 0, + .required_features_count = 2, + .features_required = {16,65} + }, + #endif + #ifdef TBT_MODULE_BLE_GATT_SERVER + //Bluetooth LE Gatt Server + { + .name = "Gatt Server", + .parent = "Bluetooth LE", + .apptype = TBT_APP_BLE_GATT_SERVER, + .icon_name = "dummy", + .info = "Bluetooth LE Gatt Cleint", + .result = 0, + .required_features_count = 2, + .features_required = {16,65} + }, + #endif #endif + #ifdef TBT_MODULE_BT #ifdef TBT_MODULE_APP_BT_CLIENT_PAIRED @@ -2091,7 +2108,54 @@ static tbt_info tbtapps[] = .icon_name = "dummy", .info = "Check D2d server service
", .result = 0 - } + }, + #endif +#endif + +#ifdef TBT_MODULE_TTS + #ifdef TBT_MODULE_APP_TTS + { + .name = "TTS", + .parent = "TTS/STT", + .apptype = TBT_APP_TTS, + .icon_name = "dummy", + .info = "Text to speech
", + .result = 0 + }, + #endif +#endif +#ifdef TBT_MODULE_STT + #ifdef TBT_MODULE_APP_STT + { + .name = "STT", + .parent = "TTS/STT", + .apptype = TBT_APP_STT, + .icon_name = "dummy", + .info = "Speech to text
", + .result = 0 + }, + #endif + #ifdef TBT_MODULE_APP_STT_ERROR + { + .name = "STT Error", + .parent = "TTS/STT", + .apptype = TBT_APP_STT_ERROR, + .icon_name = "dummy", + .info = "Speech to text
Error callback check", + .result = 0 + }, + #endif +#endif +#ifdef TBT_MODULE_SMARTCARD + #ifdef TBT_MODULE_APP_SMARTCARD + { + .name = "Smartcard", + .parent = "Smartcard", + .apptype = TBT_APP_SMARTCARD, + .icon_name = "dummy", + .info = "Smartcard signed
unsigned app check", + .result = 0 + }, #endif #endif }; diff --git a/tbtcoreapp/src/view/tbt-bluetoothle-view.c b/tbtcoreapp/src/view/tbt-bluetoothle-view.c index 1f05243..e15c2c6 100644 --- a/tbtcoreapp/src/view/tbt-bluetoothle-view.c +++ b/tbtcoreapp/src/view/tbt-bluetoothle-view.c @@ -40,17 +40,18 @@ typedef enum { SERVICE_LISTED, -SERVICE_SELECTED, SERVICE_EXPANDED, -CHARACTERISTICS_LISTED, -CHARACTERISTIC_SELECTED, -CHARACTERISTIC_READ, -CHARACTERISTIC_WRITTEN, -CHARACTERISTIC_EXPANDED, -DESCRIPTORS_LISTED, -DESCRIPTORS_SELECTED, -DESCRIPTORS_READ, -DESCRIPTORS_WRITTEN +BATTERY_CHARACTERISTIC_SELECTED, +BATTERY_CHARACTERISTIC_READ, +BATTERY_CHARACTERISTIC_EXPANDED, +BATTERY_DESCRIPTORS_LISTED, +BATTERY_DESCRIPTORS_SELECTED, +BATTERY_DESCRIPTORS_READ, +BATTERY_DESCRIPTORS_WRITTEN, + +LINK_LOSS_CHARACTERISTIC_SELECTED, +LINK_LOSS_CHARACTERISTIC_READ, +LINK_LOSS_CHARACTERISTIC_WRITTEN }ctrl_btn_state_e; @@ -63,17 +64,18 @@ struct _bluetoothle_view Evas_Object *write_btn; Evas_Object *expand_btn; Evas_Object *bluetoothle_btn2; + Evas_Object *disconnect_btn; bt_adapter_state_e adapter_state; bt_adapter_visibility_mode_e visibility_mode; common_view* view; bt_adapter_le_device_scan_result_info_s *scan_info; - bt_adapter_le_device_discovery_state_e discovery_state; + bt_adapter_device_discovery_state_e discovery_state; Elm_Object_Item *selected_device_item; GList *devices_list; - GList *log_list; + GList *services_list; bt_gatt_client_h client; bt_gatt_h gatt_handle; bt_gatt_h characterstic_h, service_h, descriptor_h; @@ -83,7 +85,29 @@ struct _bluetoothle_view int n_characteristics; bt_gatt_type_e type; - bool is_int; + + bt_gatt_server_h server_handle; + bt_gatt_h battery_service; + bt_gatt_h battery_characteristic; + bt_gatt_h battery_descriptor; + bt_gatt_h battery_descriptor2; + bt_gatt_h link_loss_service; + bt_gatt_h link_loss_characteristic; + + bt_advertiser_h advertiser; + + bool service_exists; + bool will_back_cb_removed; + + bool is_battery_svc_selected; + bool is_link_loss_svc_selected; + + char* remote_server_address; + + Evas_Object* notify_btn; + char* client_address; + + bool is_bonded; }; @@ -91,6 +115,8 @@ static void _app_destroy_cb(void* this); static void init_bluetooth(void* user_data); static void _adapter_state_changed_cb(int result, bt_adapter_state_e adapter_state, void *user_data); static void discover_bluetooth_le(void* user_data); +static void start_bluetooth_le_server(void* user_data); +static void make_service(void* user_data); static void _bt_adapter_le_scan_result_cb(int result, bt_adapter_le_device_scan_result_info_s *info, void *user_data); static bool is_new_scanned_device_found(bluetoothle_view *this, bt_adapter_le_device_scan_result_info_s *discovery_info); static gint bluetooth_list_find_func_cb(gconstpointer a, gconstpointer b); @@ -120,6 +146,18 @@ static bool _bt_gatt_foreach_descriptors_cb(int total, int index, bt_gatt_h gatt static void _bt_gatt_client_characteristic_value_changed_cb(bt_gatt_h characteristic, char *value, int len, void *user_data); static void log_list_free_func_cb(gpointer data); +static void _adapter_device_bond_destroyed_cb(int result, char *remote_address, void *data); +static void _bt_device_bond_created_cb(int result, bt_device_info_s *device_info, void *user_data); +static void _disconnect_button_pressed_cb(void *user_data, Evas_Object *obj, void *event_info); +static void bluetooth_le_advertise(void* user_data); +static void _bt_gatt_server_read_value_requested_cb(const char *remote_address, int request_id, bt_gatt_server_h server, bt_gatt_h gatt_handle, int offset, void *user_data); +static void _bt_gatt_server_characteristic_notification_state_changed_cb(bool notify, bt_gatt_server_h server, bt_gatt_h gatt_handle, void *user_data); +static void _bt_gatt_server_write_value_requested_cb(const char *remote_address, int request_id, bt_gatt_server_h server, bt_gatt_h gatt_handle, int offset, const char *value, int len, void *user_data); +static void _bt_adapter_le_advertising_state_changed_cb(int result, bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data); +static void services_list_show(bluetoothle_view *this); +static void on_hardware_back_button_pressed(void *user_data, Evas_Object *obj, void *event_info); +static void _notify_button_pressed_cb(void *user_data, Evas_Object *obj, void *event_info); +static void _bt_gatt_server_notification_sent_cb(int result, const char *remote_address, bt_gatt_server_h server, bt_gatt_h characteristic, bool completed, void *user_data); /** * @function bluetoothle_view_add @@ -130,6 +168,8 @@ static void log_list_free_func_cb(gpointer data); */ bluetoothle_view *bluetoothle_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item *item) { + DBG("bluetoothle_view_add"); + RETVM_IF(NULL == navi, NULL, "navi is null"); bluetoothle_view *this = NULL; @@ -142,6 +182,18 @@ bluetoothle_view *bluetoothle_view_add(Evas_Object *navi, tbt_info *tbt_info, El this->view = calloc(1, sizeof(common_view)); RETVM_IF(!this->view, NULL, "calloc failed"); + + // + this->server_handle = NULL; + this->battery_service = NULL; + this->battery_characteristic = NULL; + this->battery_descriptor = NULL; + this->link_loss_service = NULL; + this->link_loss_characteristic = NULL; + this->is_bonded = false; + + // + tbt_info->layout_group = "bluetoothle_viewer"; tbt_info->layout_file = get_edje_path("bluetooth_le_viewer.edj"); @@ -151,7 +203,6 @@ bluetoothle_view *bluetoothle_view_add(Evas_Object *navi, tbt_info *tbt_info, El this->scan_info = NULL; this->is_read_completed = true; - this->is_int = true; //Add Label, Button and List this->bluetoothle_label = ui_utils_label_add(this->view->layout, "BLE"); @@ -165,14 +216,37 @@ bluetoothle_view *bluetoothle_view_add(Evas_Object *navi, tbt_info *tbt_info, El Evas_Object *control = add_control_layout(this, this->view->layout); elm_object_part_content_set(this->view->layout, "controlr_part", control); - //Initialize Bluetooth init_bluetooth(this); + if(this->view->tbt_info->apptype == TBT_APP_BLE_GATT_CLIENT) + { + eext_object_event_callback_add(this->view->layout, EEXT_CALLBACK_BACK, on_hardware_back_button_pressed, this); + } return this; } +static void on_hardware_back_button_pressed(void *user_data, Evas_Object *obj, void *event_info) +{ + DBG("on_hardware_back_button_pressed"); + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + + DBG("service_exists %d will_back_cb_removed %d", this->service_exists,this->will_back_cb_removed); + + if(this->service_exists) + { + if(this->will_back_cb_removed) + { + eext_object_event_callback_del(this->view->layout, EEXT_CALLBACK_BACK, on_hardware_back_button_pressed); + this->will_back_cb_removed = true; + } + services_list_show(this); + } +} + /** * @function discover_bluetooth_le * @since_tizen 2.3 @@ -182,6 +256,7 @@ bluetoothle_view *bluetoothle_view_add(Evas_Object *navi, tbt_info *tbt_info, El */ static void discover_bluetooth_le(void* user_data) { + DBG("discover_bluetooth_le"); int result; bluetoothle_view *this = NULL; this = (bluetoothle_view*)user_data; @@ -194,7 +269,146 @@ static void discover_bluetooth_le(void* user_data) RETM_IF(result != BT_ERROR_NONE, "bt_adapter_le_start_scan failed --> error: %s", get_bluetooth_error(result)); } +static void start_bluetooth_le_server(void* user_data) +{ + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + + this->server_handle = NULL; + + make_service(this); + +} + + +static void make_service(void* user_data) +{ + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)user_data; + RETM_IF(NULL == this, "view is NULL") + + char *battery_service_uuid = "180f"; // Battery Service + char *battery_char_uuid = "2a19"; // Battery Level + char *battery_desc_uuid = "2902"; // CCCD + char *battery_desc_uuid2 = "2904"; //characteristic format + char battery_char_value[1] = {80}; // 80% + char battery_desc_value[2] = {0, 0}; // Notification & Indication disabled + int battery_permissions = BT_GATT_PERMISSION_READ; + int battery_properties = BT_GATT_PROPERTY_READ | BT_GATT_PROPERTY_NOTIFY; + + char *link_loss_service_uuid = "1803"; /* Link Loss Service */ + char *link_loss_char_uuid = "2a06"; /* Alert Level */ + char link_loss_char_value[1] = {2}; /* high alert */ + int link_loss_permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE; + int link_loss_properties = BT_GATT_PROPERTY_READ | BT_GATT_PROPERTY_WRITE; + + int ret; + if(this->adapter_state == BT_ADAPTER_ENABLED) + { + //create server + ret = bt_gatt_server_initialize(); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_initialize failed --> error: %s", get_bluetooth_error(ret)); + if(this->server_handle == NULL) + { + ret = bt_gatt_server_create(&this->server_handle); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_create failed --> error: %s", get_bluetooth_error(ret)); + } + + + //create battery service + ret = bt_gatt_service_create(battery_service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &this->battery_service); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_service_create failed --> error: %s", get_bluetooth_error(ret)); + + ret = bt_gatt_characteristic_create(battery_char_uuid, battery_permissions, battery_properties, battery_char_value, sizeof(battery_char_value), &this->battery_characteristic); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_characteristic_create failed --> error: %s", get_bluetooth_error(ret)); + + // register callbacks + ret = bt_gatt_server_set_read_value_requested_cb(this->battery_characteristic, _bt_gatt_server_read_value_requested_cb, this); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_set_read_value_requested_cb failed --> error: %s", get_bluetooth_error(ret)); + ret = bt_gatt_server_set_characteristic_notification_state_change_cb(this->battery_characteristic, _bt_gatt_server_characteristic_notification_state_changed_cb, this); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_set_characteristic_notification_state_change_cb failed --> error: %s", get_bluetooth_error(ret)); + + ret = bt_gatt_service_add_characteristic(this->battery_service, this->battery_characteristic); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_service_add_characteristic failed --> error: %s", get_bluetooth_error(ret)); + + battery_permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE; + ret = bt_gatt_descriptor_create(battery_desc_uuid, battery_permissions, battery_desc_value, sizeof(battery_desc_value), &this->battery_descriptor); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_descriptor_create failed --> error: %s", get_bluetooth_error(ret)); + + ret = bt_gatt_descriptor_create(battery_desc_uuid2, battery_permissions, battery_desc_value, sizeof(battery_desc_value), &this->battery_descriptor2); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_descriptor_create failed --> error: %s", get_bluetooth_error(ret)); + + + ret = bt_gatt_server_set_read_value_requested_cb(this->battery_descriptor2, _bt_gatt_server_read_value_requested_cb, this); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_set_read_value_requested_cb failed --> error: %s", get_bluetooth_error(ret)); + ret = bt_gatt_server_set_write_value_requested_cb(this->battery_descriptor2, _bt_gatt_server_write_value_requested_cb, this); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_set_write_value_requested_cb failed --> error: %s", get_bluetooth_error(ret)); + + ret = bt_gatt_characteristic_add_descriptor(this->battery_characteristic, this->battery_descriptor); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_characteristic_add_descriptor failed --> error: %s", get_bluetooth_error(ret)); + ret = bt_gatt_characteristic_add_descriptor(this->battery_characteristic, this->battery_descriptor2); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_characteristic_add_descriptor failed --> error: %s", get_bluetooth_error(ret)); + + + + //create link loss service + ret = bt_gatt_service_create(link_loss_service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &this->link_loss_service); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_service_create failed --> error: %s", get_bluetooth_error(ret)); + + ret = bt_gatt_characteristic_create(link_loss_char_uuid, link_loss_permissions, link_loss_properties, link_loss_char_value, sizeof(link_loss_char_value), &this->link_loss_characteristic); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_characteristic_create failed --> error: %s", get_bluetooth_error(ret)); + + // register callbacks + ret = bt_gatt_server_set_read_value_requested_cb(this->link_loss_characteristic, _bt_gatt_server_read_value_requested_cb, this); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_set_read_value_requested_cb failed --> error: %s", get_bluetooth_error(ret)); + ret = bt_gatt_server_set_write_value_requested_cb(this->link_loss_characteristic, _bt_gatt_server_write_value_requested_cb, this); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_set_write_value_requested_cb failed --> error: %s", get_bluetooth_error(ret)); + ret = bt_gatt_server_set_characteristic_notification_state_change_cb(this->link_loss_characteristic, _bt_gatt_server_characteristic_notification_state_changed_cb, this); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_set_characteristic_notification_state_change_cb failed --> error: %s", get_bluetooth_error(ret)); + + ret = bt_gatt_service_add_characteristic(this->link_loss_service, this->link_loss_characteristic); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_service_add_characteristic failed --> error: %s", get_bluetooth_error(ret)); + + + //register services + ret = bt_gatt_server_register_service(this->server_handle, this->battery_service); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_register_service failed --> error: %s", get_bluetooth_error(ret)); + + ret = bt_gatt_server_register_service(this->server_handle, this->link_loss_service); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_register_service failed --> error: %s", get_bluetooth_error(ret)); + + ret = bt_gatt_server_start(); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_start failed --> error: %s", get_bluetooth_error(ret)); + + bluetooth_le_advertise(this); + } +} + +static void _adapter_device_bond_destroyed_cb(int result, char *remote_address, void *data) +{ + DBG("_adapter_device_bond_destroyed_cb"); + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)data; + this->is_bonded = false; +} + +static void _bt_device_bond_created_cb(int result_recieved, bt_device_info_s *device_info, void *user_data) +{ + DBG("_bt_device_bond_created_cb %d", result_recieved); + + int result; + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + result = bt_gatt_connect(device_info->remote_address, false); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_connect failed --> error: %s", get_bluetooth_error(result)); + elm_object_text_set(this->bluetoothle_label, "gatt connecting..."); + elm_object_disabled_set(this->bluetoothle_btn, EINA_TRUE); + elm_object_disabled_set(this->disconnect_btn, EINA_FALSE); + this->is_bonded = device_info->is_bonded; +} /** * @function register_callback * @since_tizen 2.3 @@ -212,6 +426,12 @@ static void register_callback(void* user_data) result = bt_adapter_set_state_changed_cb(_adapter_state_changed_cb , this); RETM_IF(result != BT_ERROR_NONE, "bt_adapter_set_state_changed_cb Failed"); + result = bt_device_set_bond_created_cb(_bt_device_bond_created_cb, this); + RETM_IF(result != BT_ERROR_NONE, "bt_device_set_bond_created_cb Failed"); + + result = bt_device_set_bond_destroyed_cb(_adapter_device_bond_destroyed_cb, this); + RETM_IF(result != BT_ERROR_NONE, "bt_device_set_bond_destroyed_cb Failed"); + result = bt_gatt_set_connection_state_changed_cb(_bt_gatt_connection_state_changed_cb, this); RETM_IF(result != BT_ERROR_NONE, "bt_gatt_set_connection_state_changed_cb failed --> error: %s", get_bluetooth_error(result)); @@ -331,7 +551,12 @@ static Evas_Object *add_control_layout(bluetoothle_view *this, Evas_Object *pare if(this->view->tbt_info->apptype == TBT_APP_BLE_GATT_CLIENT) { this->bluetoothle_btn = ui_utils_push_button_add(this, table, "Discover", _control_button_pressed_cb); - elm_table_pack(table, this->bluetoothle_btn, 0, 0, 3, 1); + elm_table_pack(table, this->bluetoothle_btn, 0, 0, 1, 1); + + this->disconnect_btn = ui_utils_push_button_add(this, table, "Disconnect", _disconnect_button_pressed_cb); + elm_table_pack(table, this->disconnect_btn, 1, 0, 1, 1); + + elm_object_disabled_set(this->disconnect_btn, EINA_TRUE); this->read_btn = ui_utils_push_button_add(this, table, "Read", _read_button_pressed_cb); elm_table_pack(table, this->read_btn, 0, 1, 1, 1); @@ -344,10 +569,50 @@ static Evas_Object *add_control_layout(bluetoothle_view *this, Evas_Object *pare set_control_btn_state(SERVICE_LISTED, this); } + else if(this->view->tbt_info->apptype == TBT_APP_BLE_GATT_SERVER) + { + //Gatt Server control layout + this->bluetoothle_btn = ui_utils_push_button_add(this, table, "Start Server", _control_button_pressed_cb); + elm_table_pack(table, this->bluetoothle_btn, 0, 0, 3, 1); + + this->notify_btn = ui_utils_push_button_add(this, table, "Notify", _notify_button_pressed_cb); + elm_table_pack(table, this->notify_btn, 0, 1, 3, 1); + + } return table; } +static void _notify_button_pressed_cb(void *user_data, Evas_Object *obj, void *event_info) +{ + DBG("_notify_button_pressed_cb"); + RETM_IF(NULL == user_data, "data is NULL"); + RETM_IF(NULL == obj, "obj is NULL"); + + + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + + char char_value[1] = {1 + (rand()%100)}; + + int ret; + + ret = bt_gatt_set_value(this->battery_characteristic, char_value, 1); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_set_value failed --> error: %s", get_bluetooth_error(ret)); + DBG("Value[%d], returns %s\n", char_value[0], get_bluetooth_error(ret)); + + /* notify only client remote_addr */ + ret = bt_gatt_server_notify_characteristic_changed_value(this->battery_characteristic, + _bt_gatt_server_notification_sent_cb, + this->client_address, this); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_server_notify_characteristic_changed_value failed --> error: %s", get_bluetooth_error(ret)); + +} +static void _bt_gatt_server_notification_sent_cb(int result, const char *remote_address, bt_gatt_server_h server, bt_gatt_h characteristic, bool completed, void *user_data) +{ + DBG("_bt_gatt_server_notification_sent_cb"); +} /** * @function _control_button_pressed_cb @@ -367,10 +632,35 @@ static void _control_button_pressed_cb(void *user_data, Evas_Object *obj, void * bluetoothle_view *this = NULL; this = (bluetoothle_view*)user_data; RETM_IF(NULL == this, "view is NULL"); - //Discover Bluetooth LE Devices - discover_bluetooth_le(this); + if(this->view->tbt_info->apptype == TBT_APP_BLE_GATT_CLIENT) + { + //Discover Bluetooth LE Devices + discover_bluetooth_le(this); + } + else if(this->view->tbt_info->apptype == TBT_APP_BLE_GATT_SERVER) + { + //Start Server + start_bluetooth_le_server(this); + } + } +static void _disconnect_button_pressed_cb(void *user_data, Evas_Object *obj, void *event_info) +{ + DBG("_disconnect_button_pressed_cb"); + + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + + int result; + + DBG("remote_server_address %s", this->remote_server_address); + result = bt_gatt_disconnect(this->remote_server_address); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_disconnect failed --> error: %s", get_bluetooth_error(result)); + + +} /** * @function _read_button_pressed_cb @@ -395,53 +685,23 @@ static void _read_button_pressed_cb(void *user_data, Evas_Object *obj, void *eve if(type == BT_GATT_TYPE_SERVICE) { - + DBG("reading services..."); } else if(type == BT_GATT_TYPE_CHARACTERISTIC) { + DBG("reading characteristics..."); result = bt_gatt_client_read_value(this->gatt_handle, _bt_gatt_client_read_request_completed_cb, this); - RETM_IF(result != BT_ERROR_NONE, "bt_gatt_client_set_characteristic_value_changed_cb error: %s", get_bluetooth_error(result)); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_client_read_value error: %s", get_bluetooth_error(result)); } else if(type == BT_GATT_TYPE_DESCRIPTOR) { - int value; - int result; - char* str; - float f_val; - - if(this->descriptor_h == NULL){DBG("THIS IS NULL");} - if(this->is_int) - { - result = bt_gatt_get_int_value(this->descriptor_h, BT_DATA_TYPE_UINT8, 0, &value); - RETM_IF(result != BT_ERROR_NONE, "bt_gatt_get_int_value failed --> error: %s", get_bluetooth_error(result)); - - str = format_string("Descriptor value %d", value); - elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); - SAFE_DELETE(str); - - elm_list_go(this->bluetoothle_list); - evas_object_show(this->bluetoothle_list); - - set_control_btn_state(DESCRIPTORS_SELECTED, this); - elm_object_text_set(this->read_btn, "Read float"); - elm_object_text_set(this->write_btn, "Write float"); - this->is_int = false; - } - else - { - result = bt_gatt_get_float_value(this->descriptor_h, BT_DATA_TYPE_FLOAT, 0, &f_val); - RETM_IF(result != BT_ERROR_NONE, "bt_gatt_get_float_value error: %s", get_bluetooth_error(result)); - str = format_string("Descriptor float value %f", f_val); - elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); - SAFE_DELETE(str); - elm_list_go(this->bluetoothle_list); - evas_object_show(this->bluetoothle_list); + DBG("reading descriptor..."); - set_control_btn_state(DESCRIPTORS_READ, this); - } + result = bt_gatt_client_read_value(this->gatt_handle, _bt_gatt_client_read_request_completed_cb, this); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_client_read_value error: %s", get_bluetooth_error(result)); } @@ -475,7 +735,8 @@ static void _write_button_pressed_cb(void *user_data, Evas_Object *obj, void *ev } else if(type == BT_GATT_TYPE_CHARACTERISTIC) { - result = bt_gatt_set_value(this->gatt_handle, "Nazib", 5); + DBG("writing characteristics"); + result = bt_gatt_set_value(this->gatt_handle, "Hello", 5); RETM_IF(result != BT_ERROR_NONE, "bt_gatt_set_value error: %s", get_bluetooth_error(result)); result = bt_gatt_client_write_value(this->gatt_handle, _bt_gatt_client_write_request_completed_cb, this); @@ -484,19 +745,19 @@ static void _write_button_pressed_cb(void *user_data, Evas_Object *obj, void *ev } else if(type == BT_GATT_TYPE_DESCRIPTOR) { - if(this->is_int) - { - result = bt_gatt_set_int_value(this->descriptor_h, BT_DATA_TYPE_UINT8, 25, 0); - RETM_IF(result != BT_ERROR_NONE, "bt_gatt_set_int_value error: %s", get_bluetooth_error(result)); + DBG("writing descriptor"); + DBG("writing int"); + result = bt_gatt_set_int_value(this->gatt_handle, BT_DATA_TYPE_UINT8, 25, 0); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_set_int_value error: %s", get_bluetooth_error(result)); - } - else - { - result = bt_gatt_set_float_value(this->descriptor_h, BT_DATA_TYPE_FLOAT, 152, 2, 0); - RETM_IF(result != BT_ERROR_NONE, "bt_gatt_set_int_value error: %s", get_bluetooth_error(result)); - } + DBG("writing float"); + result = bt_gatt_set_float_value(this->gatt_handle, BT_DATA_TYPE_FLOAT, 152, 2, 0); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_set_int_value error: %s", get_bluetooth_error(result)); - set_control_btn_state(DESCRIPTORS_WRITTEN, this); + result = bt_gatt_client_write_value(this->gatt_handle, _bt_gatt_client_write_request_completed_cb, this); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_client_write_value error: %s", get_bluetooth_error(result)); + + set_control_btn_state(BATTERY_DESCRIPTORS_WRITTEN, this); } } @@ -539,7 +800,7 @@ static void _expand_button_pressed_cb(void *user_data, Evas_Object *obj, void *e result = bt_gatt_characteristic_foreach_descriptors(this->characterstic_h, _bt_gatt_foreach_descriptors_cb, this); RETM_IF(result != BT_ERROR_NONE,"bt_gatt_characteristic_foreach_descriptors error: %s", get_bluetooth_error(result)); - set_control_btn_state(CHARACTERISTIC_EXPANDED, this); + set_control_btn_state(BATTERY_CHARACTERISTIC_EXPANDED, this); } else if(type == BT_GATT_TYPE_DESCRIPTOR) { @@ -560,7 +821,6 @@ static void set_control_btn_state(ctrl_btn_state_e state, void* user_data) RETM_IF(NULL == user_data, "data is NULL"); bluetoothle_view *this = NULL; this = (bluetoothle_view*)user_data; - RETM_IF(NULL == this, "view is NULL"); switch(state) @@ -572,6 +832,7 @@ switch(state) elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; } + case SERVICE_EXPANDED: { elm_object_text_set(this->bluetoothle_label, "Characteristics.."); @@ -580,30 +841,40 @@ switch(state) elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; } - case SERVICE_SELECTED: + + + case LINK_LOSS_CHARACTERISTIC_SELECTED: + { + elm_object_disabled_set(this->read_btn, EINA_FALSE); + elm_object_disabled_set(this->write_btn, EINA_TRUE); + elm_object_disabled_set(this->expand_btn, EINA_TRUE); + break; + } + case LINK_LOSS_CHARACTERISTIC_READ: { - elm_object_text_set(this->bluetoothle_label, "Services.."); + elm_object_text_set(this->bluetoothle_label, "Read Successfully"); elm_object_disabled_set(this->read_btn, EINA_TRUE); - elm_object_disabled_set(this->write_btn, EINA_TRUE); - elm_object_disabled_set(this->expand_btn, EINA_FALSE); + elm_object_disabled_set(this->write_btn, EINA_FALSE); + elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; } - case CHARACTERISTICS_LISTED: - { elm_object_text_set(this->bluetoothle_label, "Characteristics.."); + case LINK_LOSS_CHARACTERISTIC_WRITTEN: + { elm_object_text_set(this->bluetoothle_label, "Written Successfully"); elm_object_disabled_set(this->read_btn, EINA_TRUE); elm_object_disabled_set(this->write_btn, EINA_TRUE); elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; } - case CHARACTERISTIC_SELECTED: + + case BATTERY_CHARACTERISTIC_SELECTED: { - elm_object_text_set(this->bluetoothle_label, "Characteristics.."); - elm_object_disabled_set(this->read_btn, EINA_TRUE); - elm_object_disabled_set(this->write_btn, EINA_FALSE); - elm_object_disabled_set(this->expand_btn, EINA_FALSE); + elm_object_disabled_set(this->read_btn, EINA_FALSE); + elm_object_disabled_set(this->write_btn, EINA_TRUE); + elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; } - case CHARACTERISTIC_READ: + + case BATTERY_CHARACTERISTIC_READ: { elm_object_text_set(this->bluetoothle_label, "Read Successfully"); elm_object_disabled_set(this->read_btn, EINA_TRUE); @@ -611,47 +882,42 @@ switch(state) elm_object_disabled_set(this->expand_btn, EINA_FALSE); break; } - case CHARACTERISTIC_WRITTEN: - { elm_object_text_set(this->bluetoothle_label, "Written Successfully"); - elm_object_disabled_set(this->read_btn, EINA_FALSE); - elm_object_disabled_set(this->write_btn, EINA_TRUE); - elm_object_disabled_set(this->expand_btn, EINA_FALSE); - break; - } - case CHARACTERISTIC_EXPANDED: + + + case BATTERY_CHARACTERISTIC_EXPANDED: { elm_object_text_set(this->bluetoothle_label, "Descriptors.."); elm_object_disabled_set(this->read_btn, EINA_TRUE); elm_object_disabled_set(this->write_btn, EINA_TRUE); elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; } - case DESCRIPTORS_LISTED: + case BATTERY_DESCRIPTORS_LISTED: { elm_object_text_set(this->bluetoothle_label, "Descriptors.."); elm_object_disabled_set(this->read_btn, EINA_TRUE); elm_object_disabled_set(this->write_btn, EINA_TRUE); elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; } - case DESCRIPTORS_SELECTED: + case BATTERY_DESCRIPTORS_SELECTED: { elm_object_text_set(this->bluetoothle_label, "Descriptors.."); - elm_object_disabled_set(this->read_btn, EINA_TRUE); - elm_object_disabled_set(this->write_btn, EINA_FALSE); + elm_object_disabled_set(this->read_btn, EINA_FALSE); + elm_object_disabled_set(this->write_btn, EINA_TRUE); elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; } - case DESCRIPTORS_READ: + case BATTERY_DESCRIPTORS_READ: { elm_object_text_set(this->bluetoothle_label, "Read Successfully"); elm_object_disabled_set(this->read_btn, EINA_TRUE); - elm_object_disabled_set(this->write_btn, EINA_TRUE); + elm_object_disabled_set(this->write_btn, EINA_FALSE); elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; } - case DESCRIPTORS_WRITTEN: + case BATTERY_DESCRIPTORS_WRITTEN: { elm_object_text_set(this->bluetoothle_label, "Written Successfully"); - elm_object_disabled_set(this->read_btn, EINA_FALSE); + elm_object_disabled_set(this->read_btn, EINA_TRUE); elm_object_disabled_set(this->write_btn, EINA_TRUE); elm_object_disabled_set(this->expand_btn, EINA_TRUE); break; @@ -749,8 +1015,8 @@ static void _bt_adapter_le_scan_result_cb(int result, bt_adapter_le_device_scan if (is_new_scanned_device_found(this, info) == true) { - bt_adapter_le_device_discovery_info_s * device_info; - device_info = malloc(sizeof(bt_adapter_device_discovery_info_s)); + bt_adapter_le_device_scan_result_info_s * device_info; + device_info = malloc(sizeof(bt_adapter_le_device_scan_result_info_s)); DBG("BLE remote_address: %s", info->remote_address); if (device_info != NULL) { @@ -785,25 +1051,12 @@ static bool _bt_gatt_foreach_services_cb(int total, int index, bt_gatt_h gatt_ha RETVM_IF(NULL == gatt_handle,false, "gatt_handle is NULL"); this->gatt_handle = gatt_handle; - - g_list_free_full(this->log_list, log_list_free_func_cb); - this->log_list = NULL; - int result; - - result = bt_gatt_service_get_client(gatt_handle, &this->service_h); - RETVM_IF(result != BT_ERROR_NONE,false, "bt_gatt_service_get_client error: %s", get_bluetooth_error(result)); - char* uuid; result = bt_gatt_get_uuid(gatt_handle, &uuid); RETVM_IF(result != BT_ERROR_NONE,false, "bt_gatt_get_uuid error: %s", get_bluetooth_error(result)); DBG("uuid: %s", uuid); - - char* str; - str = format_string("Service UUID: %s",uuid); - elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, _sevice_selected_cb, gatt_handle); - SAFE_DELETE(str); - + this->services_list = g_list_append(this->services_list, (gpointer) gatt_handle); return true; } @@ -859,7 +1112,6 @@ static bool _bt_gatt_foreach_characterstics_cb(int total, int index, bt_gatt_h g char* str; int result; RETVM_IF(NULL == gatt_handle,false, "gatt_handle is NULL"); - this->gatt_handle = gatt_handle; bt_gatt_write_type_e write_type; result = bt_gatt_characteristic_get_write_type(gatt_handle, &write_type); @@ -871,7 +1123,6 @@ static bool _bt_gatt_foreach_characterstics_cb(int total, int index, bt_gatt_h g bt_gatt_h service; result = bt_gatt_characteristic_get_service(gatt_handle, &service); RETVM_IF(result != BT_ERROR_NONE,false, "bt_gatt_characteristic_get_service error: %s", get_bluetooth_error(result)); - this->service_h = service; this->n_characteristics = total; this->all_characteristics[index] = gatt_handle; @@ -885,19 +1136,11 @@ static bool _bt_gatt_foreach_characterstics_cb(int total, int index, bt_gatt_h g elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, _characteristic_selected_cb, uuid); SAFE_DELETE(str); - result = bt_gatt_client_set_characteristic_value_changed_cb(gatt_handle, _bt_gatt_client_characteristic_value_changed_cb,this); - RETVM_IF(result != BT_ERROR_NONE,false, "bt_gatt_client_set_characteristic_value_changed_cb error: %s", get_bluetooth_error(result)); - this->characterstic_h = gatt_handle; - - - char* service_uuid; result = bt_gatt_get_uuid(gatt_handle, &service_uuid); RETVM_IF(result != BT_ERROR_NONE,false, "bt_gatt_get_uuid error: %s", get_bluetooth_error(result)); DBG("characteristic %d service_uuid: %s",index, service_uuid); - DBG("Total: %d index: %d", total, index); - return true; } @@ -916,18 +1159,15 @@ static void _bt_gatt_client_characteristic_value_changed_cb(bt_gatt_h characteri bluetoothle_view *this = NULL; this = (bluetoothle_view*)user_data; RETM_IF(NULL == this, "view is NULL"); - DBG("value: %s, len %d", value, len); - char* str; - str = format_string("characteristics value changed"); elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); SAFE_DELETE(str); str = format_string("value %s length %d", value, len); elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); SAFE_DELETE(str); - + elm_list_go(this->bluetoothle_list); } @@ -974,7 +1214,6 @@ static bool _bt_gatt_foreach_descriptors_cb(int total, int index, bt_gatt_h gatt elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, _descriptor_selected_cb, descriptor_uuid); SAFE_DELETE(str); SAFE_DELETE(characteristic_uuid); - //SAFE_DELETE(descriptor_uuid); return true; } @@ -994,7 +1233,7 @@ static void _bt_gatt_client_write_request_completed_cb(int result, bt_gatt_h req this = (bluetoothle_view*)user_data; RETM_IF(NULL == this,"view is NULL"); - set_control_btn_state(CHARACTERISTIC_WRITTEN, this); + set_control_btn_state(LINK_LOSS_CHARACTERISTIC_WRITTEN, this); } @@ -1008,7 +1247,6 @@ static void _bt_gatt_client_write_request_completed_cb(int result, bt_gatt_h req static void _bt_gatt_client_read_request_completed_cb(int result, bt_gatt_h request_handle, void *user_data) { - DBG("_bt_gatt_client_read_request_completed_cb"); RETM_IF(NULL == user_data, "data is NULL"); bluetoothle_view *this = NULL; @@ -1017,17 +1255,49 @@ static void _bt_gatt_client_read_request_completed_cb(int result, bt_gatt_h requ this->is_read_completed = true; char* value; int value_length; + RETM_IF(NULL == request_handle,"request_handle is NULL"); result = bt_gatt_get_value(request_handle, &value, &value_length); RETM_IF(result != BT_ERROR_NONE, "bt_gatt_get_value failed --> error: %s", get_bluetooth_error(result)); - DBG("value: %s, value_length: %d", value, value_length); + + for(int i=0; ibluetoothle_list, str, NULL, NULL, NULL, NULL); SAFE_DELETE(str); + elm_list_go(this->bluetoothle_list); + evas_object_show(this->bluetoothle_list); + DBG("read completed"); - set_control_btn_state(CHARACTERISTIC_READ, this); + + bt_gatt_type_e type; + bt_gatt_get_type(this->gatt_handle, &type); + + if(this->is_battery_svc_selected) + { + if(type == BT_GATT_TYPE_CHARACTERISTIC) + { + set_control_btn_state(BATTERY_CHARACTERISTIC_READ, this); + } + else if(type == BT_GATT_TYPE_DESCRIPTOR) + { + set_control_btn_state(BATTERY_DESCRIPTORS_READ, this); + } + } + else if(this->is_link_loss_svc_selected) + { + set_control_btn_state(LINK_LOSS_CHARACTERISTIC_READ, this); + } } @@ -1104,6 +1374,65 @@ static void discovered_devices_list_show(bluetoothle_view *this) } +static void services_list_show(bluetoothle_view *this) +{ + DBG("services_list_show"); + + RETM_IF(NULL == this, "view is NULL"); + this->will_back_cb_removed = true; + elm_list_clear(this->bluetoothle_list); + + GList *l; + bt_gatt_h service_handle; + + int count = 0; + + this->is_battery_svc_selected = false; + this->is_link_loss_svc_selected = false; + + for(l = this->services_list; l != NULL; l = l->next) + { + count++; + service_handle = (bt_gatt_h)l->data; + + if(NULL != service_handle) + { + char* svc_uuid; + char* str; + + bt_gatt_get_uuid(service_handle, &svc_uuid); + + str = format_string("Service UUID: %s",svc_uuid); + + if(!strcmp(svc_uuid, "0000180f-0000-1000-8000-00805f9b34fb")) + { + str = format_string("Battery Service"); + } + else if(!strcmp(svc_uuid, "00001803-0000-1000-8000-00805f9b34fb")) + { + str = format_string("Link Loss Service"); + } + + + elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, _sevice_selected_cb, service_handle); + SAFE_DELETE(str); + } + } + + if(count > 0) + { + DBG("Count : %d", count); + this->service_exists = true; + } + + elm_list_go(this->bluetoothle_list); + evas_object_show(this->bluetoothle_list); + + set_control_btn_state(SERVICE_LISTED, this); +} + + + /** * @function _device_item_selected_cb * @since_tizen 2.3 @@ -1137,11 +1466,11 @@ static void _device_item_selected_cb(void *data, Evas_Object *obj, void *event_i result = bt_adapter_le_stop_scan(); RETM_IF(result != BT_ERROR_NONE, "bt_adapter_le_stop_scan fail > Error = %d", result); - result = bt_gatt_connect(device_info->remote_address, false); - DBG("bt_gatt_connect %s", get_bluetooth_error(result)); - RETM_IF(result != BT_ERROR_NONE, "bt_gatt_connect failed --> error: %s", get_bluetooth_error(result)); - elm_object_text_set(this->bluetoothle_label, "gatt connecting..."); - elm_object_disabled_set(this->bluetoothle_btn, EINA_TRUE); + this->remote_server_address = device_info->remote_address; + + result = bt_device_create_bond(this->remote_server_address); + RETM_IF(result != BT_ERROR_NONE, "bt_device_create_bond fail > Error = %s", get_bluetooth_error(result)); + } @@ -1164,16 +1493,40 @@ static void _sevice_selected_cb(void *data, Evas_Object *obj, void *event_info) this = evas_object_data_get(obj, "bluetooth_view"); RETM_IF(!this, "view is NULL"); + this->service_exists = true; + this->will_back_cb_removed = false; + elm_list_clear(this->bluetoothle_list); bt_gatt_h service_h = (bt_gatt_h)data; this->service_h = service_h; - DBG("gatt_handle type service"); - result = bt_gatt_service_foreach_characteristics(service_h, _bt_gatt_foreach_characterstics_cb, this); + char* uuid; + result = bt_gatt_get_uuid(service_h, &uuid); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_get_uuid error: %s", get_bluetooth_error(result)); + DBG("selected service uuid %s", uuid); + + if(!strcmp(uuid, "0000180f-0000-1000-8000-00805f9b34fb")) + { + DBG("Battery Service"); + this->is_battery_svc_selected = true; + } + else if(!strcmp(uuid, "00001803-0000-1000-8000-00805f9b34fb")) + { + DBG("Link Loss Service"); + this->is_link_loss_svc_selected = true; + } + else + { + DBG("NO Service"); + } + + + DBG("gatt_handle type battery_service"); + result = bt_gatt_service_foreach_characteristics(this->service_h, _bt_gatt_foreach_characterstics_cb, this); RETM_IF(result != BT_ERROR_NONE, "bt_gatt_service_foreach_characteristics failed --> error: %s", get_bluetooth_error(result)); - result = bt_gatt_service_foreach_included_services(service_h, _bt_gatt_foreach_included_service, this); + result = bt_gatt_service_foreach_included_services(this->service_h, _bt_gatt_foreach_included_service, this); RETM_IF(result != BT_ERROR_NONE, "bt_gatt_service_foreach_included_services failed --> error: %s", get_bluetooth_error(result)); set_control_btn_state(SERVICE_EXPANDED, this); @@ -1239,13 +1592,8 @@ static void _descriptor_selected_cb(void *data, Evas_Object *obj, void *event_in result = bt_gatt_characteristic_get_descriptor(this->characterstic_h, uuid, &descriptor); RETM_IF(result != BT_ERROR_NONE,"bt_gatt_characteristic_get_descriptor error: %s", get_bluetooth_error(result)); - this->descriptor_h = descriptor; - this->is_int = true; - - elm_object_text_set(this->read_btn, "Read int"); - elm_object_text_set(this->write_btn, "Write int"); - set_control_btn_state(DESCRIPTORS_SELECTED, this); - + this->gatt_handle = descriptor; + set_control_btn_state(BATTERY_DESCRIPTORS_SELECTED, this); SAFE_DELETE(uuid); } @@ -1262,7 +1610,7 @@ static void _characteristic_selected_cb(void *data, Evas_Object *obj, void *even DBG(" _characteristic_selected_cb "); RETM_IF(!data, "data is NULL"); - + int result; bluetoothle_view *this; @@ -1270,15 +1618,27 @@ static void _characteristic_selected_cb(void *data, Evas_Object *obj, void *even RETM_IF(!this, "view is NULL"); char* uuid = (char*)data; - bt_gatt_h characteristic_h; result = bt_gatt_service_get_characteristic(this->service_h, uuid, &characteristic_h); RETM_IF(result != BT_ERROR_NONE, "bt_gatt_service_get_characteristic error: %s", get_bluetooth_error(result)); + // + result = bt_gatt_client_set_characteristic_value_changed_cb(characteristic_h, _bt_gatt_client_characteristic_value_changed_cb,this); + DBG("bt_gatt_client_set_characteristic_value_changed_cb error: %s", get_bluetooth_error(result)); + + this->gatt_handle = characteristic_h; + this->characterstic_h = this->gatt_handle; - this->characterstic_h = characteristic_h; + DBG("Char Handle on select: %x", this->gatt_handle); - set_control_btn_state(CHARACTERISTIC_SELECTED, this); + if(this->is_battery_svc_selected) + { + set_control_btn_state(BATTERY_CHARACTERISTIC_SELECTED, this); + } + else if(this->is_link_loss_svc_selected) + { + set_control_btn_state(LINK_LOSS_CHARACTERISTIC_SELECTED, this); + } } @@ -1291,7 +1651,7 @@ static void _characteristic_selected_cb(void *data, Evas_Object *obj, void *even */ static void _bt_gatt_connection_state_changed_cb(int result, bool connected, const char *remote_address, void *user_data) { - DBG("_bt_gatt_connection_state_changed_cb: %d", result); + DBG("_bt_gatt_connection_state_changed_cb: %s", get_bluetooth_error(result)); RETM_IF(NULL == user_data, "data is NULL"); bluetoothle_view *this = NULL; this = (bluetoothle_view*)user_data; @@ -1307,30 +1667,59 @@ static void _bt_gatt_connection_state_changed_cb(int result, bool connected, con if(this->view->tbt_info->apptype == TBT_APP_BLE_GATT_CLIENT) { elm_list_clear(this->bluetoothle_list); + ret = bt_gatt_client_create(remote_address, &this->client); RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_client_create error: %s", get_bluetooth_error(ret)); set_control_btn_state(SERVICE_LISTED, this); + + g_list_free_full(this->services_list, log_list_free_func_cb); + this->services_list = NULL; + ret = bt_gatt_client_foreach_services(this->client, _bt_gatt_foreach_services_cb, this); RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_client_foreach_services error: %s", get_bluetooth_error(ret)); char* client_remote_address; ret = bt_gatt_client_get_remote_address(this->client, &client_remote_address); RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_client_get_remote_address error: %s", get_bluetooth_error(ret)); + DBG("remote_address : %s", remote_address); DBG("client_remote_address: %s", client_remote_address); char* str; str = format_string("remote address: %s", client_remote_address); - //DBG("3.............."); elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); SAFE_DELETE(str); + + services_list_show(this); + } + + else if(this->view->tbt_info->apptype == TBT_APP_BLE_GATT_SERVER) + { + this->client_address = (char*)remote_address; + } } else { - elm_object_text_set(this->bluetoothle_label, "gatt connection failed"); + elm_object_text_set(this->bluetoothle_label, "Disconnected"); + if(this->view->tbt_info->apptype == TBT_APP_BLE_GATT_CLIENT) + { + ret = bt_gatt_client_destroy(this->client); + RETM_IF(ret != BT_ERROR_NONE, "bt_gatt_client_destroy error: %s", get_bluetooth_error(ret)); + + if(this->is_bonded) + { + ret = bt_device_destroy_bond(this->remote_server_address); + RETM_IF(ret != BT_ERROR_NONE, "bt_device_destroy_bond error: %s", get_bluetooth_error(ret)); + + } + else + { + DBG("bond not created"); + } + } } @@ -1356,10 +1745,52 @@ void _app_destroy_cb(void* this) if(view->view->tbt_info->apptype == TBT_APP_BLE_GATT_CLIENT) { bt_adapter_le_stop_scan(); - result = bt_gatt_client_destroy(view->client); - RETM_IF(result != BT_ERROR_NONE, "bt_gatt_client_destroy error: %s", get_bluetooth_error(result)); - result = bt_gatt_client_unset_characteristic_value_changed_cb(view->characterstic_h); - RETM_IF(result != BT_ERROR_NONE, "bt_gatt_client_unset_characteristic_value_changed_cb error: %s", get_bluetooth_error(result)); + } + else if(view->view->tbt_info->apptype == TBT_APP_BLE_GATT_SERVER) + { + result = bt_adapter_le_stop_advertising(view->advertiser); + RETM_IF(result != BT_ERROR_NONE, "bt_adapter_le_stop_advertising error: %s", get_bluetooth_error(result)); + + + DBG("Destroying battery service"); + if(view->battery_descriptor != NULL) + { + result = bt_gatt_descriptor_destroy(view->battery_descriptor); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_descriptor_destroy error: %s", get_bluetooth_error(result)); + } + if(view->battery_characteristic != NULL) + { + result = bt_gatt_characteristic_destroy(view->battery_characteristic); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_characteristic_destroy error: %s", get_bluetooth_error(result)); + } + if(view->battery_service != NULL) + { + result = bt_gatt_service_destroy(view->battery_service); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_service_destroy error: %s", get_bluetooth_error(result)); + } + + DBG("Destroying link loss service"); + if(view->link_loss_characteristic != NULL) + { + result = bt_gatt_characteristic_destroy(view->link_loss_characteristic); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_characteristic_destroy error: %s", get_bluetooth_error(result)); + } + if(view->link_loss_service != NULL) + { + result = bt_gatt_service_destroy(view->link_loss_service); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_service_destroy error: %s", get_bluetooth_error(result)); + } + + if(view->server_handle != NULL) + { + result = bt_gatt_server_unregister_all_services(view->server_handle); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_server_unregister_all_services error: %s", get_bluetooth_error(result)); + + result = bt_gatt_server_destroy(view->server_handle); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_server_destroy error: %s", get_bluetooth_error(result)); + } + result = bt_gatt_server_deinitialize(); + RETM_IF(result != BT_ERROR_NONE, "bt_gatt_server_deinitialize error: %s", get_bluetooth_error(result)); } result = bt_gatt_unset_connection_state_changed_cb(); RETM_IF(result != BT_ERROR_NONE, "bt_gatt_unset_connection_state_changed_cb error: %s", get_bluetooth_error(result)); @@ -1368,7 +1799,124 @@ void _app_destroy_cb(void* this) SAFE_DELETE(view); } +static void bluetooth_le_advertise(void* user_data) +{ + DBG("bluetooth_le_advertise"); + RETM_IF(NULL == user_data, "data is NULL"); + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + + int result; + + result = bt_adapter_le_create_advertiser(&this->advertiser); + RETM_IF(result != BT_ERROR_NONE, "bt_adapter_le_create_advertiser error: %s", get_bluetooth_error(result)); + + int mode = BT_ADAPTER_LE_ADVERTISING_MODE_LOW_LATENCY; + result = bt_adapter_le_set_advertising_mode(this->advertiser, mode); + RETM_IF(result != BT_ERROR_NONE, "bt_adapter_le_set_advertising_mode error: %s", get_bluetooth_error(result)); + // + char* battery_svc_uuid_16 = "180f"; + char* link_loss_svc_uuid_16 = "1803"; + int appearance = 1000; + + result = bt_adapter_le_add_advertising_service_uuid(this->advertiser, BT_ADAPTER_LE_PACKET_ADVERTISING, link_loss_svc_uuid_16); + result = bt_adapter_le_add_advertising_service_uuid(this->advertiser, BT_ADAPTER_LE_PACKET_ADVERTISING, battery_svc_uuid_16); + result = bt_adapter_le_set_advertising_appearance(this->advertiser, BT_ADAPTER_LE_PACKET_ADVERTISING, appearance); + result = bt_adapter_le_set_advertising_tx_power_level(this->advertiser, BT_ADAPTER_LE_PACKET_ADVERTISING, true); + + + result = bt_adapter_le_start_advertising_new(this->advertiser, _bt_adapter_le_advertising_state_changed_cb, this); + RETM_IF(result != BT_ERROR_NONE, "bt_adapter_le_start_advertising_new error: %s", get_bluetooth_error(result)); +} + +static void _bt_adapter_le_advertising_state_changed_cb(int result, bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data) +{ + DBG("_bt_adapter_le_advertising_state_changed_cb"); +} + + +static void _bt_gatt_server_read_value_requested_cb(const char *remote_address, int request_id, bt_gatt_server_h server, bt_gatt_h gatt_handle, int offset, void *user_data) +{ + DBG("_bt_gatt_server_read_value_requested_cb"); + + RETM_IF(NULL == user_data, "data is NULL"); + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + + char* str = format_string("read requested"); + elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); + SAFE_DELETE(str); + + char char_value_1[4] = {65, 66, 67,0}; + int resp_status = BT_ERROR_NONE; + int result = bt_gatt_server_send_response(request_id, BLUETOOTH_GATT_REQUEST_TYPE_READ, offset, resp_status, char_value_1, 3 - offset); + DBG("bt_gatt_server_send_response %s", get_bluetooth_error(result)); + + str = format_string("response sent %s", char_value_1); + elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); + SAFE_DELETE(str); + + + elm_list_go(this->bluetoothle_list); +} + +static void _bt_gatt_server_characteristic_notification_state_changed_cb(bool notify, bt_gatt_server_h server, bt_gatt_h gatt_handle, void *user_data) +{ + DBG("_bt_gatt_server_characteristic_notification_state_changed_cb"); +} + +static void _bt_gatt_server_write_value_requested_cb(const char *remote_address, int request_id, bt_gatt_server_h server, bt_gatt_h gatt_handle, int offset, const char *value, int len, void *user_data) +{ + DBG("_bt_gatt_server_write_value_requested_cb"); + RETM_IF(NULL == user_data, "data is NULL"); + bluetoothle_view *this = NULL; + this = (bluetoothle_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + int i, resp_status = BT_ERROR_NONE; + + char* str = format_string("write requested"); + elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); + SAFE_DELETE(str); + + str = format_string("remote address: %s", remote_address); + elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); + SAFE_DELETE(str); + + str = format_string("offset: %d", offset); + elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); + SAFE_DELETE(str); + + str = format_string("length: %d", len); + elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); + SAFE_DELETE(str); + + + DBG("remote_address : %s", remote_address); + DBG("offset : %d", offset); + DBG("len [%d] : ", len); + + char val_str[128]={'\0',}; + + for (i = 0; i < len; i++) + { + DBG("%d ", value[i]); + snprintf(val_str, sizeof(val_str), "%d", value[i]); + + } + + str = format_string("value: %s", val_str); + elm_list_item_append(this->bluetoothle_list, str, NULL, NULL, NULL, NULL); + SAFE_DELETE(str); + + bt_gatt_server_send_response(request_id, + BLUETOOTH_GATT_REQUEST_TYPE_WRITE, offset, + resp_status, NULL, 0); + + elm_list_go(this->bluetoothle_list); +} /** * @function get_bluetooth_error * @since_tizen 2.3 diff --git a/tbtcoreapp/src/view/tbt-genlist-view.c b/tbtcoreapp/src/view/tbt-genlist-view.c index 89a497c..9e0c1cc 100644 --- a/tbtcoreapp/src/view/tbt-genlist-view.c +++ b/tbtcoreapp/src/view/tbt-genlist-view.c @@ -97,6 +97,9 @@ #include "view/tbt-d2d-view.h" #include "view/tbt-nfc-hce-preferred-view.h" #include "view/tbt-nfc-ese-view.h" +#include "view/tbt-tts-view.h" +#include "view/tbt-stt-view.h" +#include "view/tbt-smartcard-view.h" typedef struct @@ -755,11 +758,17 @@ static void _gl_item_selected_cb(void *data, Evas_Object *obj EINA_UNUSED, void #endif #ifdef TBT_MODULE_BLE + #ifdef TBT_MODULE_BLE_GATT_CLIENT case TBT_APP_BLE_GATT_CLIENT: bluetoothle_view_add(view->navi, info, it); break; + #endif + #ifdef TBT_MODULE_BLE_GATT_SERVER + case TBT_APP_BLE_GATT_SERVER: + bluetoothle_view_add(view->navi, info, it); + break; + #endif #endif - #ifdef TBT_MODULE_BT_CALLBACK_TEST case TBT_APP_BT_CALLBACK_CREATE_BOND_TEST: bluetooth_callback_view_add(view->navi, info, it); @@ -1212,6 +1221,28 @@ static void _gl_item_selected_cb(void *data, Evas_Object *obj EINA_UNUSED, void break; #endif + #ifdef TBT_MODULE_TTS + case TBT_APP_TTS: + tts_view_add(view->navi, info, it); + break; + #endif + #ifdef TBT_MODULE_STT + case TBT_APP_STT: + stt_view_add(view->navi, info, it); + break; + + case TBT_APP_STT_ERROR: + stt_view_add(view->navi, info, it); + break; + #endif + #ifdef TBT_MODULE_SMARTCARD + #ifdef TBT_MODULE_APP_SMARTCARD + case TBT_APP_SMARTCARD: + smartcard_view_add(view->navi, info, it); + break; + #endif + #endif + default: assert(false); break; diff --git a/tbtcoreapp/src/view/tbt-smartcard-view.c b/tbtcoreapp/src/view/tbt-smartcard-view.c new file mode 100644 index 0000000..07fdbf9 --- /dev/null +++ b/tbtcoreapp/src/view/tbt-smartcard-view.c @@ -0,0 +1,249 @@ +/******************************************************************************* + * Copyright (c) 2014 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. + *******************************************************************************/ +/** + * @file tbt-smartcard-view.c + * @brief Launch smartcard test app signed and unsigned versions + * + * @author A. B. M. Nazibullah + * @date September, 2016 + * @bug no known bug + * @credit + * + */ + +#include "utils/app_module_config.h" +#ifdef TBT_MODULE_APP + +#include + +#include "utils/logger.h" +#include "utils/config.h" +#include "utils/ui-utils.h" +#include "view/tbt-smartcard-view.h" +#include "view/tbt-common-view.h" + + + +struct _smartcard_view +{ + common_view* view; + + Evas_Object *label; + + Evas_Object* btn_signed_app; + Evas_Object* btn_unsigned_app; + + app_control_h service; +}; + + +static Evas_Object *add_control_layout(smartcard_view *this, Evas_Object *parent); + +static void _app_destroy_cb(void* this); +static void signed_app_launch_button_pressed_cb(void *data, Evas_Object *obj, void *event_info); +static void unsigned_app_launch_button_pressed_cb(void *data, Evas_Object *obj, void *event_info); +static void app_control_view_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *data); + + +static char* get_app_control_error(int ret) +{ + char* error = NULL; + + switch (ret) { + case APP_CONTROL_ERROR_NONE: + error = "APP_CONTROL_ERROR_NONE"; + break; + case APP_CONTROL_ERROR_INVALID_PARAMETER: + error = "APP_CONTROL_ERROR_INVALID_PARAMETER"; + break; + case APP_CONTROL_ERROR_OUT_OF_MEMORY: + error = "APP_CONTROL_ERROR_OUT_OF_MEMORY"; + break; + case APP_CONTROL_ERROR_APP_NOT_FOUND: + error = "APP_CONTROL_ERROR_APP_NOT_FOUND"; + break; + case APP_CONTROL_ERROR_KEY_NOT_FOUND: + error = "APP_CONTROL_ERROR_KEY_NOT_FOUND"; + break; + case APP_CONTROL_ERROR_KEY_REJECTED: + error = "APP_CONTROL_ERROR_KEY_REJECTED"; + break; + case APP_CONTROL_ERROR_INVALID_DATA_TYPE: + error = "APP_CONTROL_ERROR_INVALID_DATA_TYPE"; + break; + case APP_CONTROL_ERROR_LAUNCH_REJECTED: + error = "APP_CONTROL_ERROR_LAUNCH_REJECTED"; + break; + case APP_CONTROL_ERROR_PERMISSION_DENIED: + error = "APP_CONTROL_ERROR_PERMISSION_DENIED"; + break; + case APP_CONTROL_ERROR_LAUNCH_FAILED: + error = "APP_CONTROL_ERROR_LAUNCH_FAILED"; + break; + case APP_CONTROL_ERROR_TIMED_OUT: + error = "APP_CONTROL_ERROR_TIMED_OUT"; + break; +#ifdef TIZEN_3_0 + case APP_CONTROL_ERROR_IO_ERROR: + error = "APP_CONTROL_ERROR_IO_ERROR"; + break; +#endif +#ifdef TIZEN_2_4 + case APP_CONTROL_ERROR_IO_ERROR: + error = "APP_CONTROL_ERROR_IO_ERROR"; + break; +#endif + default: + error = "Unknown Error"; + break; + } + return error; +} + + +smartcard_view *smartcard_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item *item) +{ + DBG("smartcard_view_add"); + RETVM_IF(NULL == navi, NULL, "navi is null"); + + smartcard_view *this = NULL; + this = calloc(1, sizeof(smartcard_view)); + RETVM_IF(!this, NULL, "calloc failed"); + + this->view = calloc(1, sizeof(common_view)); + RETVM_IF(!this->view, NULL, "calloc failed"); + + + tbt_info->layout_group = "4_part_txt_cnt_btn_btn"; + tbt_info->layout_file = get_edje_path("4_part_txt_cnt2_btn_btn.edj"); + + common_view_add(navi, tbt_info, item, this->view, _app_destroy_cb, this); + RETVM_IF(NULL == this->view, NULL, "navi is null"); + + this->label = ui_utils_label_add(this->view->layout, ""); + RETVM_IF(!this->label, NULL, "elm_list_add failed"); + ui_utils_label_set_text(this->label, "press button to launch app", "left"); + elm_object_part_content_set(this->view->layout, "1txt", this->label); + + + Evas_Object *control = add_control_layout(this, this->view->layout); + elm_object_part_content_set(this->view->layout, "1txt_2cnt_3btn", control); + + return this; +} + + +static Evas_Object *add_control_layout(smartcard_view *this, Evas_Object *parent) +{ + RETVM_IF(NULL == this, NULL, "view is NULL"); + + Evas_Object *table = elm_table_add(parent); + + evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(table); + + elm_table_padding_set(table, 0, 0); + + + this->btn_signed_app = ui_utils_push_button_add(this, table, "Signed", signed_app_launch_button_pressed_cb); + elm_table_pack(table, this->btn_signed_app, 0, 0, 1, 1); + + this->btn_unsigned_app = ui_utils_push_button_add(this, table, "Unsigned", unsigned_app_launch_button_pressed_cb); + elm_table_pack(table, this->btn_unsigned_app, 1, 0, 1, 1); + + return table; +} + + +static void signed_app_launch_button_pressed_cb(void *data, Evas_Object *obj, void *event_info) +{ + RETM_IF(NULL == data, "data is NULL"); + + smartcard_view *view = NULL; + view = (smartcard_view*)data; + RETM_IF(NULL == view, "view is NULL"); + + char *appid = SMARTCARD_SIGNED_APPID; + int ret = app_control_create(&view->service); + RETM_IF(APP_CONTROL_ERROR_NONE != ret, "app_control_create failed :%s", get_app_control_error(ret)); + RETM_IF(NULL == view->service, "Service NULL! "); + ret = app_control_set_app_id(view->service, appid); + RETM_IF(APP_CONTROL_ERROR_NONE != ret, "app_control_set_app_id failed :%s", get_app_control_error(ret)); + ret = app_control_send_launch_request(view->service , app_control_view_reply_cb, view); + RETM_IF(APP_CONTROL_ERROR_NONE != ret, "app_control_send_launch_request failed :%s", get_app_control_error(ret)); + ui_utils_label_set_text(view->label, "App launch requested.", "left"); +} + + +static void unsigned_app_launch_button_pressed_cb(void *data, Evas_Object *obj, void *event_info) +{ + RETM_IF(NULL == data, "data is NULL"); + + smartcard_view *view = NULL; + view = (smartcard_view*)data; + RETM_IF(NULL == view, "view is NULL"); + + char *appid = SMARTCARD_UNSIGNED_APPID; + int ret = app_control_create(&view->service); + RETM_IF(APP_CONTROL_ERROR_NONE != ret, "app_control_create failed :%s", get_app_control_error(ret)); + RETM_IF(NULL == view->service, "Service NULL! "); + ret = app_control_set_app_id(view->service, appid); + RETM_IF(APP_CONTROL_ERROR_NONE != ret, "app_control_set_app_id failed :%s", get_app_control_error(ret)); + ret = app_control_send_launch_request(view->service , app_control_view_reply_cb, view); + RETM_IF(APP_CONTROL_ERROR_NONE != ret, "app_control_send_launch_request failed :%s", get_app_control_error(ret)); + ui_utils_label_set_text(view->label, "App launch requested.", "left"); +} + + +static void app_control_view_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *data) +{ + RETM_IF(NULL == data, "data is NULL"); + + smartcard_view *view = NULL; + view = (smartcard_view*)data; + RETM_IF(NULL == view, "view is NULL"); + + if(result == APP_CONTROL_RESULT_SUCCEEDED) + { + int result; + char *app_id; + + if(reply != NULL) + { + result = app_control_get_app_id(reply, &app_id); + RETM_IF(APP_CONTROL_ERROR_NONE != result, "app_control_create failed :%s", get_app_control_error(result)); + DBG("app_id is %s", app_id); + + ui_utils_label_set_text(view->label, "App launched successfully.", "left"); + } + } +} + + +static void _app_destroy_cb(void* this) +{ + RETM_IF(NULL == this, "data is NULL"); + + smartcard_view *view = NULL; + view = (smartcard_view*)this; + RETM_IF(NULL == view, "view is NULL"); + app_control_destroy(view->service); + SAFE_DELETE(view->view); + SAFE_DELETE(view); +} + +#endif diff --git a/tbtcoreapp/src/view/tbt-stt-view.c b/tbtcoreapp/src/view/tbt-stt-view.c new file mode 100644 index 0000000..474d34e --- /dev/null +++ b/tbtcoreapp/src/view/tbt-stt-view.c @@ -0,0 +1,485 @@ +/******************************************************************************* + * Copyright (c) 2014 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. + *******************************************************************************/ +/** + * @file tbt-stt-view.c + * @brief covers speech to text recognition + * + * @author A. B. M. Nazibullah(nazib.ullah@samsung.com) + * @date August, 2016 + * @bug + * @credit + * + */ + +#include "utils/app_module_config.h" +#ifdef TBT_MODULE_STT + +#include +#include +#include "utils/logger.h" +#include "utils/config.h" +#include "utils/ui-utils.h" +#include "view/tbt-stt-view.h" +#include "view/tbt-common-view.h" + +struct _stt_view +{ + common_view* view; + + Evas_Object *input_text; + Evas_Object *recognized_text; + Evas_Object *btn_stt; + Evas_Object *list; + + stt_h stt_handle; + bool is_recognition_completed; + bool is_unprepared; + + char* res_path; +}; + +static void _app_destroy_cb(void* this); +static char* get_stt_error(stt_error_e err); +static void _btn_stt_pressed_cb(void *data, Evas_Object *obj, void *event_info); +static char* get_stt_state_str(stt_state_e state); +static void _stt_state_changed_cb(stt_h stt, stt_state_e previous, stt_state_e current, void* user_data); +static void _stt_recognition_result_cb(stt_h stt, stt_result_event_e event, const char** data, int data_count, const char* msg, void *user_data); +static bool _stt_result_time_cb(stt_h stt, int index, stt_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data); +static bool _stt_supported_language_cb(stt_h stt, const char* language, void* user_data); +static void _stt_error_cb(stt_h stt, stt_error_e reason, void *user_data); + + +#ifdef USE_GENLIST +typedef struct +{ + int index; + Elm_Object_Item *item; + char* text; +}item_data; + +static void _gl_del_cb(void *data, Evas_Object *obj EINA_UNUSED); +static char *_gl_text_get_cb(void *data, Evas_Object *obj, const char *part); +Elm_Object_Item* _stt_elm_genlist_item_append(Evas_Object *this, char *item_text, void* data); +#endif + + + +#ifdef USE_GENLIST +static void _gl_del_cb(void *data, Evas_Object *obj EINA_UNUSED) +{ + DBG("_gl_del_cb"); + item_data *id = data; + RETM_IF(!id, "item is NULL"); + SAFE_DELETE(id); +} + +static char *_gl_text_get_cb(void *data, Evas_Object *obj, const char *part) +{ + DBG("_gl_text_get_cb"); + item_data *id = data; + //const Elm_Genlist_Item_Class *itc = elm_genlist_item_item_class_get(id->item); + + //if(itc->item_style && !strcmp(itc->item_style, "default")) + { + + if(part && !strcmp(part, "elm.text")) + { + char buf[1024]; + snprintf(buf, 1023,"%s", id->text); + return strdup(buf); + } + } + return NULL; +} + +Elm_Object_Item* _stt_elm_genlist_item_append(Evas_Object* list, char *item_text, void* data) +{ + + DBG("_pick_elm_genlist_item_append%s:", item_text); + static int index = 1; + Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new(); + + itc->item_style = "default"; + itc->func.text_get = _gl_text_get_cb; + itc->func.content_get = NULL; + itc->func.del = _gl_del_cb; + + item_data *id = calloc(sizeof(item_data), 1); + id->index = index++; + id->text = strdup(item_text); + + elm_scroller_single_direction_set(list, ELM_SCROLLER_SINGLE_DIRECTION_HARD); + + //HOMOGENEOUS MODE + //If item height is same when each style name is same, Use homogeneous mode. + elm_genlist_homogeneous_set(list, EINA_TRUE); + + //COMPRESS MODE + //For the Mobile view, because it has full window, compresse mode should be used. + elm_genlist_mode_set(list, ELM_LIST_COMPRESS); + + Elm_Object_Item *item = elm_genlist_item_append(list, itc,id, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + id->item = item; + + elm_genlist_item_class_free(itc); + + return item; +} +#endif + + +/** + * @function stt_view_add + * @since_tizen 2.3 + * @description Gps View Add + * @parameter Evas_Object*: Evas Object Pointer, tbt_info*: Tbt Info Pointer, Elm_Object_Item*: Elm Object Item Pointer + * @return stt_view* + */ +stt_view *stt_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item *item) +{ + RETVM_IF(NULL == navi, NULL, "navi is null"); + + stt_view *this = NULL; + this = calloc(1, sizeof(stt_view)); + RETVM_IF(!this, NULL, "calloc failed"); + this->view = calloc(1, sizeof(common_view)); + RETVM_IF(!this->view, NULL, "calloc failed"); + + tbt_info->layout_group = "stt_viewer"; + tbt_info->layout_file = get_edje_path("stt_viewer.edj"); + + common_view_add(navi, tbt_info, item, this->view, _app_destroy_cb, this); + + RETVM_IF(NULL == this->view, NULL, "navi is null"); + + this->is_recognition_completed = false; + this->is_unprepared = false; + + this->res_path = app_get_resource_path(); + + this->input_text = ui_utils_label_add(this->view->layout, ""); + + if(this->view->tbt_info->apptype == TBT_APP_STT) + { + ui_utils_label_set_text(this->input_text, "Make sure Internet is connected", "left"); + + + #ifdef USE_GENLIST + this->list = elm_genlist_add(this->view->layout); + RETVM_IF(!this->list, NULL, "elm_genlist_add failed"); + #else + this->list = elm_list_add(this->view->layout); + RETVM_IF(!this->list, NULL, "elm_list_add failed"); + #endif + + evas_object_data_set(this->list, "view_data", this); + elm_object_part_content_set(this->view->layout, "list_part", this->list); + + } + else if(this->view->tbt_info->apptype == TBT_APP_STT_ERROR) + { + ui_utils_label_set_text(this->input_text, "Disconnect Internet, Then press Speak button", "left"); + } + + elm_object_part_content_set(this->view->layout, "txt_part_1", this->input_text); + + Evas_Object *table = elm_table_add(this->view->layout); + evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(table); + + this->btn_stt = ui_utils_push_button_add(this, table, "Speak", _btn_stt_pressed_cb); + elm_table_pack(table, this->btn_stt, 0, 0, 1, 1); + elm_object_part_content_set(this->view->layout, "btn_part", table); + elm_object_text_set(this->btn_stt, ui_utils_text_add("Speak", NULL)); + +// this->btn_stt = ui_utils_push_button_add(this, this->view->layout, "Speak", _btn_stt_pressed_cb); +// elm_object_part_content_set(this->view->layout, "btn_part", this->btn_stt); + + + return this; +} + +static void _btn_stt_pressed_cb(void *data, Evas_Object *obj, void *event_info) +{ + DBG("_btn_stt_pressed_cb"); + stt_view *this = NULL; + this = (stt_view*)data; + RETM_IF(NULL == this, "view is NULL"); + int ret; + ret = stt_create(&this->stt_handle); + RETM_IF(ret != STT_ERROR_NONE, "stt_create fail > Error = %s", get_stt_error(ret)); + ret = stt_set_state_changed_cb(this->stt_handle, _stt_state_changed_cb, this); + RETM_IF(ret != STT_ERROR_NONE, "stt_set_state_changed_cb fail > Error = %s", get_stt_error(ret)); + ret = stt_set_recognition_result_cb(this->stt_handle, _stt_recognition_result_cb, this); + RETM_IF(ret != STT_ERROR_NONE, "stt_set_recognition_result_cb fail > Error = %s", get_stt_error(ret)); + ret = stt_foreach_supported_languages(this->stt_handle, _stt_supported_language_cb, this); + RETM_IF(ret != STT_ERROR_NONE, "stt_foreach_supported_languages fail > Error = %s", get_stt_error(ret)); + ret = stt_set_error_cb(this->stt_handle, _stt_error_cb, this); + RETM_IF(ret != STT_ERROR_NONE, "stt_set_error_cb fail > Error = %s", get_stt_error(ret)); + ret = stt_prepare(this->stt_handle); + RETM_IF(ret != STT_ERROR_NONE, "stt_prepare fail > Error = %s", get_stt_error(ret)); + elm_object_disabled_set(this->btn_stt, EINA_TRUE); +} + +static void _stt_state_changed_cb(stt_h stt, stt_state_e previous, stt_state_e current, void* user_data) +{ + DBG("_stt_state_changed_cb previous: %s current %s", get_stt_state_str(previous), get_stt_state_str(current)); + stt_view *this = NULL; + this = (stt_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + int ret; + if(current == STT_STATE_CREATED) + { + if(this->is_unprepared) + { + ret = stt_unset_state_changed_cb(this->stt_handle); + RETM_IF(ret != STT_ERROR_NONE, "stt_unset_state_changed_cb fail > Error = %s", get_stt_error(ret)); + ret = stt_unset_recognition_result_cb(this->stt_handle); + RETM_IF(ret != STT_ERROR_NONE, "stt_unset_recognition_result_cb fail > Error = %s", get_stt_error(ret)); + ret = stt_unset_error_cb(this->stt_handle); + RETM_IF(ret != STT_ERROR_NONE, "stt_unset_error_cb fail > Error = %s", get_stt_error(ret)); + this->is_unprepared = false; + } + + } + else if(current ==STT_STATE_READY) + { + if(this->is_recognition_completed) + { + ret = stt_unprepare(this->stt_handle); + this->is_unprepared = true; + RETM_IF(ret != STT_ERROR_NONE, "stt_unprepare fail > Error = %s", get_stt_error(ret)); + this->is_recognition_completed = false; + } + else + { + char* file_name = format_string("%s%s", this->res_path, STT_START_RECORDING_SOUND); + ret = stt_set_start_sound(this->stt_handle, file_name); + DBG("stt_set_start_sound %s", get_stt_error(ret)); + SAFE_DELETE(file_name); + + ret = stt_set_silence_detection(this->stt_handle, STT_OPTION_SILENCE_DETECTION_TRUE); + DBG("stt_set_silence_detection %s", get_stt_error(ret)); + ret = stt_start(this->stt_handle, "en_US", STT_RECOGNITION_TYPE_FREE); + DBG("stt_start %s", get_stt_error(ret)); + } + } + else if(current == STT_STATE_RECORDING) + { + DBG("recording"); + ui_utils_label_set_text(this->input_text, "Recording...", "left"); + } + else if(current == STT_STATE_PROCESSING) + { + DBG("processing"); + ui_utils_label_set_text(this->input_text, "Processing...", "left"); + } + +} +static void _stt_error_cb(stt_h stt, stt_error_e reason, void *user_data) +{ + DBG("_stt_error_cb %s", get_stt_error(reason)); + stt_view *this = NULL; + this = (stt_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + char* str; + int ret = stt_get_error_message(stt, &str); + RETM_IF(ret != STT_ERROR_NONE, "stt_get_error_message fail > Error = %s", get_stt_error(ret)); + ui_utils_label_set_text(this->input_text, str, "left"); + SAFE_DELETE(str); +} + +static bool _stt_supported_language_cb(stt_h stt, const char* language, void* user_data) +{ + DBG("language %s", language); + return true; +} + +static bool _stt_result_time_cb(stt_h stt, int index, stt_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data) +{ + DBG("_stt_result_time_cb"); + stt_view *this = NULL; + this = (stt_view*)user_data; + RETVM_IF(NULL == this,false, "view is NULL"); + + DBG("Text: %s, start_time: %ld end_time: %ld", text, start_time, end_time); + char *str = format_string("%s => start:%ld end:%ld", text, start_time, end_time); + elm_list_item_append(this->list, str, NULL, NULL, NULL, NULL); + + #ifdef USE_GENLIST + _stt_elm_genlist_item_append(this->list, str,NULL); + #else + elm_list_item_append(this->list, str, NULL, NULL, NULL, NULL); + #endif + + SAFE_DELETE(str); + + return true; +} + +static void _stt_recognition_result_cb(stt_h stt, stt_result_event_e event, const char** data, int data_count, const char* msg, void *user_data) +{ + DBG("_stt_recognition_result_cb"); + + stt_view *this = NULL; + this = (stt_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + + if(data_count) + { + this->is_recognition_completed = true; + } + + int ret = stt_foreach_detailed_result(stt, _stt_result_time_cb, this); + DBG("stt_foreach_detailed_result fail > Error = %s", get_stt_error(ret)); + + for(int i=0; iinput_text, str, "left"); + elm_object_disabled_set(this->btn_stt, EINA_FALSE); + SAFE_DELETE(str); + } + + elm_list_go(this->list); + evas_object_show(this->list); + +} + +/** + * @function _app_destroy_cb + * @since_tizen 2.3 + * @description App Destroy Cb + * @parameter void*: Void Pointer + * @return static void + */ +static void _app_destroy_cb(void* this) +{ + RETM_IF(NULL == this, "data is NULL"); + + stt_view *view = NULL; + view = (stt_view*)this; + RETM_IF(NULL == view, "view is NULL"); + + int ret; + ret = stt_destroy(view->stt_handle); + DBG("stt_destroy %s", get_stt_error(ret)); + + SAFE_DELETE(view->view); + SAFE_DELETE(view); +} + +static char* get_stt_error(stt_error_e err) +{ + char* err_msg; + + switch(err) + { + case STT_ERROR_NONE: + err_msg = "STT_ERROR_NONE"; + break; + case STT_ERROR_OUT_OF_MEMORY: + err_msg = "STT_ERROR_OUT_OF_MEMORY"; + break; + case STT_ERROR_IO_ERROR: + err_msg = "STT_ERROR_IO_ERROR"; + break; + case STT_ERROR_INVALID_PARAMETER: + err_msg = "STT_ERROR_INVALID_PARAMETER"; + break; + case STT_ERROR_TIMED_OUT: + err_msg = "STT_ERROR_TIMED_OUT"; + break; + case STT_ERROR_RECORDER_BUSY: + err_msg = "STT_ERROR_RECORDER_BUSY"; + break; + case STT_ERROR_OUT_OF_NETWORK: + err_msg = "STT_ERROR_OUT_OF_NETWORK"; + break; + case STT_ERROR_PERMISSION_DENIED: + err_msg = "STT_ERROR_PERMISSION_DENIED"; + break; + case STT_ERROR_NOT_SUPPORTED: + err_msg = "STT_ERROR_NOT_SUPPORTED"; + break; + case STT_ERROR_INVALID_STATE: + err_msg = "STT_ERROR_INVALID_STATE"; + break; + case STT_ERROR_INVALID_LANGUAGE: + err_msg = "STT_ERROR_INVALID_LANGUAGE"; + break; + case STT_ERROR_ENGINE_NOT_FOUND: + err_msg = "STT_ERROR_ENGINE_NOT_FOUND"; + break; + case STT_ERROR_OPERATION_FAILED: + err_msg = "STT_ERROR_OPERATION_FAILED"; + break; + case STT_ERROR_NOT_SUPPORTED_FEATURE: + err_msg = "STT_ERROR_NOT_SUPPORTED_FEATURE"; + break; + case STT_ERROR_RECORDING_TIMED_OUT: + err_msg = "STT_ERROR_RECORDING_TIMED_OUT"; + break; + case STT_ERROR_NO_SPEECH: + err_msg = "STT_ERROR_NO_SPEECH"; + break; + case STT_ERROR_IN_PROGRESS_TO_READY: + err_msg = "STT_ERROR_IN_PROGRESS_TO_READY"; + break; + case STT_ERROR_IN_PROGRESS_TO_RECORDING: + err_msg = "STT_ERROR_IN_PROGRESS_TO_RECORDING"; + break; + case STT_ERROR_IN_PROGRESS_TO_PROCESSING: + err_msg = "STT_ERROR_IN_PROGRESS_TO_PROCESSING"; + break; + case STT_ERROR_SERVICE_RESET: + err_msg = "STT_ERROR_SERVICE_RESET"; + break; + default: + err_msg = "UNKNOWN_ERROR"; + break; + } +return err_msg; +} + + +static char* get_stt_state_str(stt_state_e state) +{ + char* state_str; + switch (state) + { + case STT_STATE_CREATED: + state_str = "STT_STATE_CREATED"; + break; + case STT_STATE_READY: + state_str = "STT_STATE_READY"; + break; + case STT_STATE_RECORDING: + state_str = "STT_STATE_RECORDING"; + break; + case STT_STATE_PROCESSING: + state_str = "STT_STATE_PROCESSING"; + break; + default: + state_str = "UNKNOWN_STATE"; + break; + } + return state_str; +} + +#endif diff --git a/tbtcoreapp/src/view/tbt-tts-view.c b/tbtcoreapp/src/view/tbt-tts-view.c new file mode 100644 index 0000000..914b1d4 --- /dev/null +++ b/tbtcoreapp/src/view/tbt-tts-view.c @@ -0,0 +1,302 @@ +/******************************************************************************* + * Copyright (c) 2014 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. + *******************************************************************************/ +/** + * @file tbt-tts-view.c + * @brief coverst text to speech operations + * + * @author A. B. M. Nazibullah (nazib.ullah@samsung.com) + * @date August, 2016 + * @bug + * @credit + * + */ + +#include "utils/app_module_config.h" +#ifdef TBT_MODULE_TTS + +#include +#include +#include "utils/logger.h" +#include "utils/config.h" +#include "utils/ui-utils.h" +#include "view/tbt-tts-view.h" +#include "view/tbt-common-view.h" + +struct _tts_view +{ + common_view* view; + Evas_Object *txt_label; + Evas_Object* btn_tts; + + tts_h tts_handle; + bool is_utterance_completed; + bool is_tts_btn_pressed; +}; + +static void _app_destroy_cb(void* this); +static void _btn_tts_pressed_cb(void *data, Evas_Object *obj, void *event_info); +static char* get_tts_error(tts_error_e err); +static void _tts_state_changed_cb(tts_h tts, tts_state_e previous, tts_state_e current, void* user_data); +static bool _tts_supported_voice_cb(tts_h tts, const char* language, int voice_type, void* user_data); +static char* get_tts_state_str(tts_state_e state); +static void _tts_utterance_completed_cb(tts_h tts, int utt_id, void *user_data); + + +/** + * @function tts_view_add + * @since_tizen 2.3 + * @description Gps View Add + * @parameter Evas_Object*: Evas Object Pointer, tbt_info*: Tbt Info Pointer, Elm_Object_Item*: Elm Object Item Pointer + * @return tts_view* + */ +tts_view *tts_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item *item) +{ + RETVM_IF(NULL == navi, NULL, "navi is null"); + + tts_view *this = NULL; + this = calloc(1, sizeof(tts_view)); + RETVM_IF(!this, NULL, "calloc failed"); + this->view = calloc(1, sizeof(common_view)); + RETVM_IF(!this->view, NULL, "calloc failed"); + + tbt_info->layout_group = "tts_viewer"; + tbt_info->layout_file = get_edje_path("tts_viewer.edj"); + + common_view_add(navi, tbt_info, item, this->view, _app_destroy_cb, this); + + RETVM_IF(NULL == this->view, NULL, "navi is null"); + + this->is_utterance_completed = false; + this->is_tts_btn_pressed = false; + + this->txt_label = ui_utils_label_add(this->view->layout, ""); + ui_utils_label_set_text(this->txt_label, "Text: The quick brown fox jumps over the lazy dog", "left"); + elm_object_part_content_set(this->view->layout, "txt_part", this->txt_label); + + this->btn_tts = ui_utils_push_button_add(this, this->view->layout, "Text to Speech", _btn_tts_pressed_cb); + elm_object_part_content_set(this->view->layout, "btn_part", this->btn_tts); + + Evas_Object *table = elm_table_add(this->view->layout); + evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(table); + + this->btn_tts = ui_utils_push_button_add(this, table, "Text to Speech", _btn_tts_pressed_cb); + elm_table_pack(table, this->btn_tts, 0, 0, 1, 1); + elm_object_part_content_set(this->view->layout, "btn_part", table); + elm_object_text_set(this->btn_tts, ui_utils_text_add("Text to Speech", NULL)); + + return this; +} +static bool _tts_supported_voice_cb(tts_h tts, const char* language, int voice_type, void* user_data) +{ + DBG("_tts_supported_voice_cb: %s %d", language, voice_type); + return true; +} + +static void _tts_state_changed_cb(tts_h tts, tts_state_e previous, tts_state_e current, void* data) +{ + DBG("prev state %s current state: %s", get_tts_state_str(previous), get_tts_state_str(current)); + + tts_view *this = NULL; + this = (tts_view*)data; + RETM_IF(NULL == this, "view is NULL"); + + int ret; + if(current == TTS_STATE_CREATED) + { + if(this->is_utterance_completed) + { + ret = tts_unset_state_changed_cb(this->tts_handle); + RETM_IF(ret != TTS_ERROR_NONE, "tts_unset_state_changed_cb fail > Error = %s", get_tts_error(ret)); + ret = tts_unset_utterance_completed_cb(this->tts_handle); + RETM_IF(ret != TTS_ERROR_NONE, "tts_unset_utterance_completed_cb fail > Error = %s", get_tts_error(ret)); + this->is_utterance_completed = false; + + } + } + else if (current == TTS_STATE_READY) + { + if(this->is_tts_btn_pressed) + { + int utt_id; + ret = tts_add_text(this->tts_handle, "The quick brown fox jumps over the lazy dog", NULL, TTS_VOICE_TYPE_FEMALE, TTS_SPEED_AUTO, &utt_id); + RETM_IF(ret != TTS_ERROR_NONE, "tts_add_text fail > Error = %s", get_tts_error(ret)); + ret = tts_play(this->tts_handle); + RETM_IF(ret != TTS_ERROR_NONE, "tts_play fail > Error = %s", get_tts_error(ret)); + this->is_tts_btn_pressed = false; + } + else + { + ret = tts_unprepare(this->tts_handle); + RETM_IF(ret != TTS_ERROR_NONE, "tts_unprepare fail > Error = %s", get_tts_error(ret)); + + } + + } + else if(current == TTS_STATE_PLAYING) + { + + } + else if(current == TTS_STATE_PAUSED) + { + + } +} + +static void _tts_utterance_completed_cb(tts_h tts, int utt_id, void *user_data) +{ + DBG("_tts_utterance_completed_cb"); + tts_view *this = NULL; + this = (tts_view*)user_data; + RETM_IF(NULL == this, "view is NULL"); + int ret; + ret = tts_stop(this->tts_handle); + RETM_IF(ret != TTS_ERROR_NONE, "tts_stop fail > Error = %s", get_tts_error(ret)); + this->is_utterance_completed = true; + +} + +static char* get_tts_state_str(tts_state_e state) +{ + + char* state_str; + switch(state) + { + case TTS_STATE_CREATED: + state_str = "TTS_STATE_CREATED"; + break; + case TTS_STATE_READY: + state_str = "TTS_STATE_READY"; + break; + case TTS_STATE_PLAYING: + state_str = "TTS_STATE_PLAYING"; + break; + case TTS_STATE_PAUSED: + state_str = "TTS_STATE_PAUSED"; + break; + default: + state_str = "UNKNOWN_STATE"; + break; + } + return state_str; +} +static void _btn_tts_pressed_cb(void *data, Evas_Object *obj, void *event_info) +{ + DBG("_btn_tts_pressed_cb"); + tts_view *this = NULL; + this = (tts_view*)data; + RETM_IF(NULL == this, "view is NULL"); + this->is_tts_btn_pressed = true; + int ret; + ret = tts_create(&this->tts_handle); + RETM_IF(ret != TTS_ERROR_NONE, "tts_create fail > Error = %s", get_tts_error(ret)); + ret = tts_set_state_changed_cb(this->tts_handle, _tts_state_changed_cb, this); + RETM_IF(ret != TTS_ERROR_NONE, "tts_set_state_changed_cb fail > Error = %s", get_tts_error(ret)); + ret = tts_foreach_supported_voices(this->tts_handle, _tts_supported_voice_cb, this); + RETM_IF(ret != TTS_ERROR_NONE, "tts_foreach_supported_voices fail > Error = %s", get_tts_error(ret)); + ret = tts_set_utterance_completed_cb(this->tts_handle, _tts_utterance_completed_cb, this); + RETM_IF(ret != TTS_ERROR_NONE, "tts_set_utterance_completed_cb fail > Error = %s", get_tts_error(ret)); + ret = tts_prepare(this->tts_handle); + RETM_IF(ret != TTS_ERROR_NONE, "tts_prepare fail > Error = %s", get_tts_error(ret)); + +} + + +/** + * @function _app_destroy_cb + * @since_tizen 2.3 + * @description App Destroy Cb + * @parameter void*: Void Pointer + * @return static void + */ +static void _app_destroy_cb(void* this) +{ + RETM_IF(NULL == this, "data is NULL"); + + tts_view *view = NULL; + view = (tts_view*)this; + RETM_IF(NULL == view, "view is NULL"); + + int ret; + ret = tts_destroy(view->tts_handle); + RETM_IF(ret != TTS_ERROR_NONE, "tts_destroy fail > Error = %s", get_tts_error(ret)); + + SAFE_DELETE(view->view); + SAFE_DELETE(view); +} + +static char* get_tts_error(tts_error_e err) +{ + char* err_msg; + + switch(err) + { + case TTS_ERROR_NONE: + err_msg = "TTS_ERROR_NONE"; + break; + case TTS_ERROR_OUT_OF_MEMORY: + err_msg = "TTS_ERROR_OUT_OF_MEMORY"; + break; + case TTS_ERROR_IO_ERROR: + err_msg = "TTS_ERROR_IO_ERROR"; + break; + case TTS_ERROR_INVALID_PARAMETER: + err_msg = "TTS_ERROR_INVALID_PARAMETER"; + break; + case TTS_ERROR_OUT_OF_NETWORK: + err_msg = "TTS_ERROR_OUT_OF_NETWORK"; + break; + case TTS_ERROR_TIMED_OUT: + err_msg = "TTS_ERROR_TIMED_OUT"; + break; + case TTS_ERROR_PERMISSION_DENIED: + err_msg = "TTS_ERROR_PERMISSION_DENIED"; + break; + case TTS_ERROR_NOT_SUPPORTED: + err_msg = "TTS_ERROR_NOT_SUPPORTED"; + break; + case TTS_ERROR_INVALID_STATE: + err_msg = "TTS_ERROR_INVALID_STATE"; + break; + case TTS_ERROR_INVALID_VOICE: + err_msg = "TTS_ERROR_INVALID_VOICE"; + break; + case TTS_ERROR_ENGINE_NOT_FOUND: + err_msg = "TTS_ERROR_ENGINE_NOT_FOUND"; + break; + case TTS_ERROR_OPERATION_FAILED: + err_msg = "TTS_ERROR_OPERATION_FAILED"; + break; + case TTS_ERROR_AUDIO_POLICY_BLOCKED: + err_msg = "TTS_ERROR_AUDIO_POLICY_BLOCKED"; + break; + case TTS_ERROR_NOT_SUPPORTED_FEATURE: + err_msg = "TTS_ERROR_NOT_SUPPORTED_FEATURE"; + break; + case TTS_ERROR_SERVICE_RESET: + err_msg = "TTS_ERROR_SERVICE_RESET"; + break; + default: + err_msg = "UNKNOWN_ERROR"; + break; + } + + return err_msg; + +} + +#endif