From 3091e199dd3990f1c8586f6ab63f189863c6812a Mon Sep 17 00:00:00 2001 From: HyungKyu Song Date: Sat, 16 Feb 2013 00:10:50 +0900 Subject: [PATCH] Tizen 2.0 Release --- AUTHORS | 2 + CMakeLists.txt | 98 ++++++++ LICENSE | 206 ++++++++++++++++ NOTICE | 3 + capi-media-radio.manifest | 5 + capi-media-radio.pc.in | 14 ++ include/radio.h | 384 +++++++++++++++++++++++++++++ include/radio_private.h | 47 ++++ packaging/capi-media-radio.spec | 57 +++++ src/radio.c | 525 ++++++++++++++++++++++++++++++++++++++++ 10 files changed, 1341 insertions(+) create mode 100644 AUTHORS create mode 100755 CMakeLists.txt create mode 100644 LICENSE create mode 100644 NOTICE create mode 100755 capi-media-radio.manifest create mode 100644 capi-media-radio.pc.in create mode 100644 include/radio.h create mode 100644 include/radio_private.h create mode 100644 packaging/capi-media-radio.spec create mode 100644 src/radio.c diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..68b49ae --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Kangho Hur +Seungkeun Lee diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..c99f3ec --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,98 @@ + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-media-radio") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +SET(dependents "dlog mm-radio capi-base-common") +SET(pc_dependents "capi-base-common") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +SET_TARGET_PROPERTIES(${fw_name} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 +) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/media + FILES_MATCHING + PATTERN "*_private.h" EXCLUDE + PATTERN "${INC_DIR}/*.h" + ) + +SET(PC_NAME ${fw_name}) +SET(PC_REQUIRED ${pc_dependents}) +SET(PC_LDFLAGS -l${fw_name}) +SET(PC_CFLAGS -I\${includedir}/media) + +CONFIGURE_FILE( + ${fw_name}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc + @ONLY +) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) + +#ADD_SUBDIRECTORY(test) + +IF(UNIX) + +ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) +ADD_CUSTOM_COMMAND( + DEPENDS clean + COMMENT "distribution clean" + COMMAND find + ARGS . + -not -name config.cmake -and \( + -name tester.c -or + -name Testing -or + -name CMakeFiles -or + -name cmake.depends -or + -name cmake.check_depends -or + -name CMakeCache.txt -or + -name cmake.check_cache -or + -name *.cmake -or + -name Makefile -or + -name core -or + -name core.* -or + -name gmon.out -or + -name install_manifest.txt -or + -name *.pc -or + -name *~ \) + | grep -v TC | xargs rm -rf + TARGET distclean + VERBATIM +) + +ENDIF(UNIX) + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bbe9d02 --- /dev/null +++ b/LICENSE @@ -0,0 +1,206 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..ccdad52 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE file for Apache License terms and conditions. diff --git a/capi-media-radio.manifest b/capi-media-radio.manifest new file mode 100755 index 0000000..a76fdba --- /dev/null +++ b/capi-media-radio.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/capi-media-radio.pc.in b/capi-media-radio.pc.in new file mode 100644 index 0000000..a77de18 --- /dev/null +++ b/capi-media-radio.pc.in @@ -0,0 +1,14 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/media + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} diff --git a/include/radio.h b/include/radio.h new file mode 100644 index 0000000..aa4000f --- /dev/null +++ b/include/radio.h @@ -0,0 +1,384 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __TIZEN_MEDIA_RADIO_H__ +#define __TIZEN_MEDIA_RADIO_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define RADIO_ERROR_CLASS TIZEN_ERROR_MULTIMEDIA_CLASS | 0x70 + +/** + * @file radio.h + * @brief This file contains the radio API. + */ + +/** + * @addtogroup CAPI_MEDIA_RADIO_MODULE + * @{ + */ + +/** + * @brief Radio handle type. + */ +typedef struct radio_s *radio_h; + +/** + * @brief Enumerations of radio state + */ +typedef enum +{ + RADIO_STATE_READY, /**< Ready to play or scan */ + RADIO_STATE_PLAYING, /**< Playing audio from the tuner */ + RADIO_STATE_SCANNING, /**< Scanning Searching for the next station signal starts from a given starting frequency */ +} radio_state_e; + +/** + * @brief Error codes for radio + */ +typedef enum +{ + RADIO_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + RADIO_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + RADIO_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + RADIO_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */ + RADIO_ERROR_INVALID_STATE = RADIO_ERROR_CLASS | 0x01 , /**< Invalid state */ + RADIO_ERROR_SOUND_POLICY = RADIO_ERROR_CLASS | 0x02 , /**< Sound policy error */ +} radio_error_e; + +/** + * @brief Enumerations of radio interrupted type + */ +typedef enum +{ + RADIO_INTERRUPTED_BY_MEDIA = 0, /**< Interrupted by non-resumable media application*/ + RADIO_INTERRUPTED_BY_CALL_START, /**< Interrupted by call starting*/ + RADIO_INTERRUPTED_BY_EARJACK_UNPLUG, /**< Interrupted by unplugging headphone*/ + RADIO_INTERRUPTED_BY_RESOURCE_CONFLICT, /**< Interrupted by resource conflict*/ + RADIO_INTERRUPTED_BY_ALARM_START, /**< Interrupted by alarm starting*/ + RADIO_INTERRUPTED_BY_ALARM_END, /**< Interrupted by alarm ending*/ + RADIO_INTERRUPTED_BY_EMERGENCY, /**< Interrupted by emergency*/ + RADIO_INTERRUPTED_BY_RESUMABLE_MEDIA, /**< Interrupted by resumable media application*/ +} radio_interrupted_code_e; + +/** + * @brief Called when the scan information is updated. + * @param[in] frequency The tuned radio frequency [87500 ~ 108000] (kHz) + * @param[in] user_data The user data passed from the callback registration function + * @pre It will be invoked by radio_scan_start() + * @see radio_scan_start() + */ +typedef void (*radio_scan_updated_cb)(int frequency, void *user_data); + +/** + * @brief Called when the radio scan is stopped. + * @param[in] user_data The user data passed from the callback registration function + * @pre It will be invoked when scan is stopped by radio_scan_stop() + * @see radio_scan_stop() + */ +typedef void (*radio_scan_stopped_cb)(void *user_data); + +/** + * @brief Called when the radio scan is completed. + * @param[in] user_data The user data passed from the callback registration function + * @pre It will be invoked when scan is completed if you register this callback using radio_set_scan_completed_cb() + * @see radio_scan_start() + * @see radio_set_scan_completed_cb() + * @see radio_unset_scan_completed_cb() + */ +typedef void (*radio_scan_completed_cb)(void *user_data); + +/** + * @brief Called when the radio seek is completed. + * @param[in] frequency The current frequency [87500 ~ 108000] (kHz) + * @param[in] user_data The user data passed from the callback registration function + * @pre It will be invoked when radio seek completed if you register this callback using radio_seek_up() or radio_seek_down() + * @see radio_seek_up() + * @see radio_seek_down() + */ +typedef void (*radio_seek_completed_cb)(int frequency, void *user_data); + +/** + * @brief Called when the radio is interrupted. + * @param[in] error_code The interrupted error code + * @param[in] user_data The user data passed from the callback registration function + * @see radio_set_interrupted_cb() + * @see radio_unset_interrupted_cb() + */ +typedef void (*radio_interrupted_cb)(radio_interrupted_code_e code, void *user_data); + +/** + * @brief Creates a radio handle. + * @remarks @a radio must be released radio_destroy() by you. + * @param[out] radio A new handle to radio + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_OUT_OF_MEMORY Out of memory + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @see radio_destroy() + */ +int radio_create(radio_h *radio); + +/** + * @brief Destroys the radio handle and releases all its resources. + * + * @remarks To completely shutdown radio operation, call this function with a valid radio handle. + * + * @param[in] radio The handle to radio to be destroyed + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @see radio_create() + */ +int radio_destroy(radio_h radio); + +/** + * @brief Gets the radio's current state. + * @param[in] radio The handle to radio + * @param[out] state The current state of the radio + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + */ +int radio_get_state(radio_h radio, radio_state_e *state); + +/** + * @brief Starts playing radio. + * + * @param[in] radio The handle to radio + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_STATE Invalid radio state + * @retval #RADIO_ERROR_SOUND_POLICY Sound policy error + * @pre The radio state must be #RADIO_STATE_READY by radio_create(). + * @post The radio state will be #RADIO_STATE_PLAYING. + * @see radio_stop() + */ +int radio_start(radio_h radio); + +/** + * @brief Stops playing radio. + * @param[in] radio The handle to radio + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid state + * @retval #RADIO_ERROR_INVALID_STATE Invalid radio state + * @pre The radio state must be either #RADIO_STATE_PLAYING by radio_start(). + * @post The radio state will be #RADIO_STATE_READY. + * @see radio_start() + * @see radio_scan_start() + */ +int radio_stop(radio_h radio); + +/** + * @brief Seeks up the effective frequency of radio, asynchronously. + * @param[in] radio The handle to radio + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @retval #RADIO_ERROR_INVALID_STATE Invalid radio state + * @pre The radio state must be #RADIO_STATE_PLAYING by radio_start(). + * @post It invokes radio_seek_completed_cb() when seek completes. + * @see radio_seek_down() + */ +int radio_seek_up(radio_h radio,radio_seek_completed_cb callback, void *user_data ); + +/** + * @brief Seeks down the effective frequency of radio, asynchronously. + * @param[in] radio The handle to radio + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @retval #RADIO_ERROR_INVALID_STATE Invalid radio state + * @pre The radio state must be #RADIO_STATE_PLAYING by radio_start(). + * @post It invokes radio_seek_completed_cb() when seek completes. + * @see radio_seek_up() + */ +int radio_seek_down(radio_h radio,radio_seek_completed_cb callback, void *user_data ); + +/** + * @brief Sets the radio frequency. + * @param[in] radio The handle to radio + * @param[in] percent The frequency to set [87500 ~ 108000] (kHz) + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @see radio_get_frequency() + */ +int radio_set_frequency(radio_h radio, int frequency); + +/** + * @brief Gets the current frequency of radio. + * @param[in] radio The handle to radio + * @param[out] frequency The current frequency [87500 ~ 108000] (kHz) + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @see radio_set_frequency() + */ +int radio_get_frequency(radio_h radio, int *frequency); + +/** + * @brief Gets the current signal strength of radio. + * @param[in] radio The handle to radio + * @param[out] strength The current signal strength [0 ~ 65535] (dbuV) + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + */ +int radio_get_signal_strength(radio_h radio, int *strength); + +/** + * @brief Starts scanning radio signals, asynchronously + * + * @param[in] radio The handle to radio + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @retval #RADIO_ERROR_INVALID_STATE Invalid radio state + * @pre The radio state must be #RADIO_STATE_READY by either radio_create() or radio_stop(). + * @post The radio state will be #RADIO_STATE_SCANNING during searching. After scan is completed, radio state will be #RADIO_STATE_READY. + * @post It invokes radio_scan_updated_cb() when the scan information updates. + * @post It invokes radio_scan_completed_cb() when scan completes, if you set a callback with radio_set_scan_completed_cb(). + * @see radio_scan_stop() + * @see radio_set_scan_completed_cb() + * @see radio_scan_completed_cb() + */ +int radio_scan_start(radio_h radio, radio_scan_updated_cb callback, void *user_data); + +/** + * @brief Stops scanning radio signals, asynchronously. + * @param[in] radio The handle to radio + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid state + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @retval #RADIO_ERROR_INVALID_STATE Invalid radio state + * @pre The radio state must be #RADIO_STATE_SCANNING by radio_scan_start(). + * @post It invokes radio_scan_stopped_cb() when the scan stops. + * @post The radio state will be #RADIO_STATE_READY. + * @see radio_scan_start() + */ +int radio_scan_stop(radio_h radio, radio_scan_stopped_cb callback, void *user_data); + +/** + * @brief Sets the radio's mute status. + * @details If the mute status is @c true, no sounds will be played. If @c false, sounds will be played. Until this function is called, by default the radio is not muted. + * @param[in] radio The handle to radio + * @param[in] muted New mute status: (@c true = mute, @c false = not muted) + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @see radio_is_muted() + */ +int radio_set_mute(radio_h radio, bool muted); + +/** + * @brief Gets the radio's mute status. + * @details If the mute status is @c true, no sounds are played. If @c false, sounds are played. + * @param[in] radio The handle to radio + * @param[out] muted The current mute status: (@c true = mute, @c false = not muted) + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @see radio_set_mute() + */ +int radio_is_muted(radio_h radio, bool *muted); + +/** + * @brief Registers a callback function to be invoked when the scan finishes. + * @param[in] radio The handle to radio + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @post radio_scan_completed_cb() will be invoked + * @see radio_unset_scan_completed_cb() + * @see radio_scan_completed_cb() + */ +int radio_set_scan_completed_cb(radio_h radio, radio_scan_completed_cb callback, void *user_data); + +/** + * @brief Unregisters the callback function. + * @param[in] radio The handle to radio + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @see radio_set_scan_completed_cb() + */ +int radio_unset_scan_completed_cb(radio_h radio); + +/** + * @brief Registers a callback function to be invoked when the radio is interrupted. + * @param[in] radio The handle to radio + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @post radio_interrupted_cb() will be invoked + * @see radio_unset_interrupted_cb() + * @see #radio_interrupted_code_e + * @see radio_interrupted_cb() + */ +int radio_set_interrupted_cb(radio_h radio, radio_interrupted_cb callback, void *user_data); + +/** + * @brief Unregisters the callback function. + * @param[in] radio The handle to radio + * @return 0 on success, otherwise a negative error value. + * @retval #RADIO_ERROR_NONE Successful + * @retval #RADIO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RADIO_ERROR_INVALID_OPERATION Invalid operation + * @see radio_set_interrupted_cb() + */ +int radio_unset_interrupted_cb(radio_h radio); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_MEDIA_RADIO_H__ */ diff --git a/include/radio_private.h b/include/radio_private.h new file mode 100644 index 0000000..b128372 --- /dev/null +++ b/include/radio_private.h @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __TIZEN_MEDIA_RADIO_PRIVATE_H__ +#define __TIZEN_MEDIA_RADIO_PRIVATE_H__ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + _RADIO_EVENT_TYPE_SCAN_INFO, + _RADIO_EVENT_TYPE_SCAN_STOP, + _RADIO_EVENT_TYPE_SCAN_FINISH, + _RADIO_EVENT_TYPE_SEEK_FINISH, + _RADIO_EVENT_TYPE_INTERRUPT, + _RADIO_EVENT_TYPE_NUM +}_radio_event_e; + +typedef struct _radio_s{ + MMHandleType mm_handle; + const void* user_cb[_RADIO_EVENT_TYPE_NUM]; + void* user_data[_RADIO_EVENT_TYPE_NUM]; + radio_state_e state; + bool mute; +} radio_s; + +#ifdef __cplusplus +} +#endif + +#endif //__TIZEN_MEDIA_RADIO_PRIVATE_H__ diff --git a/packaging/capi-media-radio.spec b/packaging/capi-media-radio.spec new file mode 100644 index 0000000..5584e45 --- /dev/null +++ b/packaging/capi-media-radio.spec @@ -0,0 +1,57 @@ +#sbs-git:slp/api/radio capi-media-radio 0.1.0 59dddd8ea3de373c44c66ce2a298ca81240305a8 +Name: capi-media-radio +Summary: A Radio library in Tizen Native API +Version: 0.1.0 +Release: 10 +Group: TO_BE_FILLED +License: TO_BE_FILLED +Source0: %{name}-%{version}.tar.gz +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(mm-radio) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: cmake +BuildRequires: gettext-devel + +%description +A Radio library in Tizen Native API + + +%package devel +Summary: A Radio library in Tizen Native API (Developement) +Group: TO_BE_FILLED +Requires: %{name} = %{version}-%{release} + +%description devel +A Radio library in Tizen Native API (Developement) + +%prep +%setup -q + +%build +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post + +%postun + + +%files +%manifest capi-media-radio.manifest +%defattr(-,root,root,-) +/usr/lib/libcapi-media-radio.so.* + +%files devel +%defattr(-,root,root,-) +/usr/include/media/radio.h +/usr/lib/pkgconfig/capi-media-radio.pc +/usr/lib/libcapi-media-radio.so diff --git a/src/radio.c b/src/radio.c new file mode 100644 index 0000000..4b085b3 --- /dev/null +++ b/src/radio.c @@ -0,0 +1,525 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include + + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_RADIO" + +/* +* Internal Macros +*/ +#define RADIO_CHECK_CONDITION(condition,error,msg) \ + if(condition) {} else \ + { LOGE("[%s] %s(0x%08x)",(char*)__FUNCTION__, msg,error); return error;}; \ + +#define RADIO_INSTANCE_CHECK(radio) \ + RADIO_CHECK_CONDITION(radio != NULL, RADIO_ERROR_INVALID_PARAMETER,"RADIO_ERROR_INVALID_PARAMETER") + +#define RADIO_STATE_CHECK(radio,expected_state) \ + RADIO_CHECK_CONDITION(radio->state == expected_state,RADIO_ERROR_INVALID_STATE,"RADIO_ERROR_INVALID_STATE") + +#define RADIO_NULL_ARG_CHECK(arg) \ + RADIO_CHECK_CONDITION(arg != NULL,RADIO_ERROR_INVALID_PARAMETER,"RADIO_ERROR_INVALID_PARAMETER") + +/* +* Internal Implementation +*/ +static int __convert_error_code(int code, char *func_name) +{ + int ret = RADIO_ERROR_NONE; + char* msg="RADIO_ERROR_NONE"; + switch(code) + { + case MM_ERROR_NONE: + ret = RADIO_ERROR_NONE; + msg = "RADIO_ERROR_NONE"; + break; + + case MM_ERROR_RADIO_NO_FREE_SPACE: + ret = RADIO_ERROR_OUT_OF_MEMORY; + msg = "RADIO_ERROR_OUT_OF_MEMORY"; + break; + case MM_ERROR_RADIO_NOT_INITIALIZED: + case MM_ERROR_RADIO_NO_OP: + ret = RADIO_ERROR_INVALID_STATE; + msg = "RADIO_ERROR_INVALID_STATE"; + break; + case MM_ERROR_COMMON_INVALID_ARGUMENT: + ret = RADIO_ERROR_INVALID_PARAMETER; + msg = "RADIO_ERROR_INVALID_PARAMETER"; + break; + case MM_ERROR_POLICY_BLOCKED: + case MM_ERROR_POLICY_INTERRUPTED: + case MM_ERROR_POLICY_INTERNAL: + case MM_ERROR_POLICY_DUPLICATED: + ret = RADIO_ERROR_SOUND_POLICY; + msg = "RADIO_ERROR_SOUND_POLICY"; + break; + case MM_ERROR_RADIO_INTERNAL: + case MM_ERROR_RADIO_RESPONSE_TIMEOUT: + case MM_ERROR_RADIO_DEVICE_NOT_OPENED: + case MM_ERROR_RADIO_DEVICE_NOT_FOUND: + default : + ret= RADIO_ERROR_INVALID_OPERATION; + msg = "RADIO_ERROR_INVALID_OPERATION"; + } + LOGE("[%s] %s(0x%08x) : core fw error(0x%x)",func_name,msg, ret, code); + return ret; +} + +static radio_state_e __convert_radio_state(MMRadioStateType state) +{ + int converted_state = RADIO_STATE_READY; + switch(state) + { + + case MM_RADIO_STATE_PLAYING: + converted_state = RADIO_STATE_PLAYING; + break; + case MM_RADIO_STATE_SCANNING: + converted_state = RADIO_STATE_SCANNING; + break; + case MM_RADIO_STATE_NULL: + case MM_RADIO_STATE_READY: + default: + converted_state = RADIO_STATE_READY; + break; + } + return converted_state; +} + +static int __set_callback(_radio_event_e type, radio_h radio, void* callback, void *user_data) +{ + RADIO_INSTANCE_CHECK(radio); + RADIO_NULL_ARG_CHECK(callback); + radio_s * handle = (radio_s *) radio; + handle->user_cb[type] = callback; + handle->user_data[type] = user_data; + LOGI("[%s] Event type : %d ",__FUNCTION__, type); + return RADIO_ERROR_NONE; +} + +static int __unset_callback(_radio_event_e type, radio_h radio) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + handle->user_cb[type] = NULL; + handle->user_data[type] = NULL; + LOGI("[%s] Event type : %d ",__FUNCTION__, type); + return RADIO_ERROR_NONE; +} + +static int __msg_callback(int message, void *param, void *user_data) +{ + radio_s * handle = (radio_s*)user_data; + MMMessageParamType *msg = (MMMessageParamType*)param; + LOGI("[%s] Got message type : 0x%x" ,__FUNCTION__, message); + switch(message) + { + case MM_MESSAGE_RADIO_SCAN_INFO: + if( handle->user_cb[_RADIO_EVENT_TYPE_SCAN_INFO] ) + { + ((radio_scan_updated_cb)handle->user_cb[_RADIO_EVENT_TYPE_SCAN_INFO])(msg->radio_scan.frequency,handle->user_data[_RADIO_EVENT_TYPE_SCAN_INFO]); + } + break; + case MM_MESSAGE_RADIO_SCAN_STOP: + if( handle->user_cb[_RADIO_EVENT_TYPE_SCAN_STOP] ) + { + ((radio_scan_stopped_cb)handle->user_cb[_RADIO_EVENT_TYPE_SCAN_STOP])(handle->user_data[_RADIO_EVENT_TYPE_SCAN_STOP]); + } + break; + case MM_MESSAGE_RADIO_SCAN_FINISH: + if( handle->user_cb[_RADIO_EVENT_TYPE_SCAN_FINISH] ) + { + ((radio_scan_completed_cb)handle->user_cb[_RADIO_EVENT_TYPE_SCAN_FINISH])(handle->user_data[_RADIO_EVENT_TYPE_SCAN_FINISH]); + } + break; + case MM_MESSAGE_RADIO_SEEK_FINISH: + if( handle->user_cb[_RADIO_EVENT_TYPE_SEEK_FINISH] ) + { + ((radio_seek_completed_cb)handle->user_cb[_RADIO_EVENT_TYPE_SEEK_FINISH])(msg->radio_scan.frequency, handle->user_data[_RADIO_EVENT_TYPE_SEEK_FINISH]); + } + break; + case MM_MESSAGE_STATE_INTERRUPTED: + if( handle->user_cb[_RADIO_EVENT_TYPE_INTERRUPT] ) + { + ((radio_interrupted_cb)handle->user_cb[_RADIO_EVENT_TYPE_INTERRUPT])(msg->code,handle->user_data[_RADIO_EVENT_TYPE_INTERRUPT]); + } + break; + case MM_MESSAGE_ERROR: + __convert_error_code(msg->code,(char*)__FUNCTION__); + break; + case MM_MESSAGE_RADIO_SCAN_START: + LOGI("[%s] Scan Started"); + break; + case MM_MESSAGE_STATE_CHANGED: + handle->state = __convert_radio_state(msg->state.current); + LOGI("[%s] State Changed --- from : %d , to : %d" ,__FUNCTION__, __convert_radio_state(msg->state.previous), handle->state); + break; + case MM_MESSAGE_RADIO_SEEK_START: + LOGI("[%s] Seek Started", __FUNCTION__); + break; + default: + break; + } + return 1; +} + + +/* +* Public Implementation +*/ +int radio_create(radio_h *radio) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle; + handle = (radio_s*)malloc( sizeof(radio_s)); + if (handle != NULL) + memset(handle, 0 , sizeof(radio_s)); + else + { + LOGE("[%s] RADIO_ERROR_OUT_OF_MEMORY(0x%08x)" ,__FUNCTION__,RADIO_ERROR_OUT_OF_MEMORY); + return RADIO_ERROR_OUT_OF_MEMORY; + } + int ret = mm_radio_create(&handle->mm_handle); + if( ret != MM_ERROR_NONE) + { + LOGE("[%s] RADIO_ERROR_INVALID_OPERATION(0x%08x)" ,__FUNCTION__,RADIO_ERROR_INVALID_OPERATION); + free(handle); + handle=NULL; + return RADIO_ERROR_INVALID_OPERATION; + } + else + { + *radio = (radio_h)handle; + + ret = mm_radio_set_message_callback(handle->mm_handle, __msg_callback, (void*)handle); + if(ret != MM_ERROR_NONE) + { + LOGW("[%s] Failed to set message callback function (0x%x)" ,__FUNCTION__, ret); + } + ret = mm_radio_realize(handle->mm_handle); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + handle->state = RADIO_STATE_READY; + handle->mute = FALSE; + return RADIO_ERROR_NONE; + } +} + +int radio_destroy(radio_h radio) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + + int ret; + ret = mm_radio_unrealize(handle->mm_handle); + if ( ret!= MM_ERROR_NONE) + { + LOGW("[%s] Failed to unrealize (0x%x)" ,__FUNCTION__, ret); + } + + ret = mm_radio_destroy(handle->mm_handle); + if (ret!= MM_ERROR_NONE) + { + LOGE("[%s] RADIO_ERROR_INVALID_OPERATION (0x%08x)" ,__FUNCTION__,RADIO_ERROR_INVALID_OPERATION); + return RADIO_ERROR_INVALID_OPERATION; + } + else + { + free(handle); + handle= NULL; + return RADIO_ERROR_NONE; + } +} + +int radio_get_state(radio_h radio, radio_state_e *state) +{ + RADIO_INSTANCE_CHECK(radio); + RADIO_NULL_ARG_CHECK(state); + radio_s * handle = (radio_s *) radio; + MMRadioStateType currentStat = MM_RADIO_STATE_NULL; + int ret = mm_radio_get_state(handle->mm_handle, ¤tStat); + if(ret != MM_ERROR_NONE) + { + *state = handle->state; + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + handle->state = __convert_radio_state(currentStat); + *state = handle->state; + return RADIO_ERROR_NONE; + } +} + +int radio_start(radio_h radio) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + RADIO_STATE_CHECK(handle,RADIO_STATE_READY); + + int ret = mm_radio_start(handle->mm_handle); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + handle->state = RADIO_STATE_PLAYING; + return RADIO_ERROR_NONE; + } +} + +int radio_stop(radio_h radio) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + RADIO_STATE_CHECK(handle,RADIO_STATE_PLAYING); + + int ret = mm_radio_stop(handle->mm_handle); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + handle->state = RADIO_STATE_READY; + return RADIO_ERROR_NONE; + } +} + +int radio_seek_up(radio_h radio,radio_seek_completed_cb callback, void *user_data ) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + RADIO_STATE_CHECK(handle,RADIO_STATE_PLAYING); + + if(callback!=NULL) + { + __set_callback(_RADIO_EVENT_TYPE_SEEK_FINISH,radio,callback,user_data); + } + else + { + __unset_callback(_RADIO_EVENT_TYPE_SEEK_FINISH,radio); + } + + int ret = mm_radio_seek(handle->mm_handle, MM_RADIO_SEEK_UP); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + return RADIO_ERROR_NONE; + } +} + +int radio_seek_down(radio_h radio,radio_seek_completed_cb callback, void *user_data ) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + RADIO_STATE_CHECK(handle,RADIO_STATE_PLAYING); + + if(callback!=NULL) + { + __set_callback(_RADIO_EVENT_TYPE_SEEK_FINISH,radio,callback,user_data); + } + else + { + __unset_callback(_RADIO_EVENT_TYPE_SEEK_FINISH,radio); + } + + int ret = mm_radio_seek(handle->mm_handle, MM_RADIO_SEEK_DOWN); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + return RADIO_ERROR_NONE; + } +} + +int radio_set_frequency(radio_h radio, int frequency) +{ + RADIO_INSTANCE_CHECK(radio); + if(frequency < 87500 || frequency > 108000) + { + LOGE("[%s] RADIO_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (87500 ~ 108000)" ,__FUNCTION__,RADIO_ERROR_INVALID_PARAMETER); + return RADIO_ERROR_INVALID_PARAMETER; + } + int freq= frequency; + radio_s * handle = (radio_s *) radio; + int ret = mm_radio_set_frequency(handle->mm_handle, freq); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + return RADIO_ERROR_NONE; + } +} + +int radio_get_frequency(radio_h radio, int *frequency) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + + int freq; + int ret = mm_radio_get_frequency(handle->mm_handle, &freq); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + *frequency = freq; + return RADIO_ERROR_NONE; + } +} + +int radio_get_signal_strength(radio_h radio, int *strength) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + + int _strength; + int ret = mm_radio_get_signal_strength(handle->mm_handle, &_strength); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + *strength = _strength; + return RADIO_ERROR_NONE; + } +} + +int radio_scan_start(radio_h radio, radio_scan_updated_cb callback, void *user_data) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + RADIO_STATE_CHECK(handle,RADIO_STATE_READY); + + if(callback!=NULL) + { + __set_callback(_RADIO_EVENT_TYPE_SCAN_INFO,radio,callback,user_data); + } + else + { + __unset_callback(_RADIO_EVENT_TYPE_SCAN_INFO,radio); + } + + int ret = mm_radio_scan_start(handle->mm_handle); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + handle->state = RADIO_STATE_SCANNING; + return RADIO_ERROR_NONE; + } +} + +int radio_scan_stop(radio_h radio, radio_scan_stopped_cb callback, void *user_data) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + RADIO_STATE_CHECK(handle,RADIO_STATE_SCANNING); + + if(callback!=NULL) + { + __set_callback(_RADIO_EVENT_TYPE_SCAN_STOP,radio,callback,user_data); + } + else + { + __unset_callback(_RADIO_EVENT_TYPE_SCAN_STOP,radio); + } + + int ret = mm_radio_scan_stop(handle->mm_handle); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + handle->state = RADIO_STATE_READY; + return RADIO_ERROR_NONE; + } +} + + +int radio_set_mute(radio_h radio, bool muted) +{ + RADIO_INSTANCE_CHECK(radio); + radio_s * handle = (radio_s *) radio; + + int ret = mm_radio_set_mute(handle->mm_handle, muted); + if(ret != MM_ERROR_NONE) + { + return __convert_error_code(ret,(char*)__FUNCTION__); + } + else + { + handle->mute = muted; + return RADIO_ERROR_NONE; + } +} + +int radio_is_muted(radio_h radio, bool *muted) +{ + RADIO_INSTANCE_CHECK(radio); + RADIO_NULL_ARG_CHECK(muted); + radio_s * handle = (radio_s *) radio; + *muted = handle->mute; + return RADIO_ERROR_NONE; +} + +int radio_set_scan_completed_cb(radio_h radio, radio_scan_completed_cb callback, void *user_data) +{ + return __set_callback(_RADIO_EVENT_TYPE_SCAN_FINISH,radio,callback,user_data); +} + +int radio_unset_scan_completed_cb(radio_h radio) +{ + return __unset_callback(_RADIO_EVENT_TYPE_SCAN_FINISH,radio); +} + +int radio_set_interrupted_cb(radio_h radio, radio_interrupted_cb callback, void *user_data) +{ + return __set_callback(_RADIO_EVENT_TYPE_INTERRUPT,radio,callback,user_data); +} + +int radio_unset_interrupted_cb(radio_h radio) +{ + return __unset_callback(_RADIO_EVENT_TYPE_INTERRUPT,radio); +} -- 2.7.4