--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET(INC_DIR include)
+
+ADD_SUBDIRECTORY(src)
+
+INSTALL(
+ DIRECTORY ${INC_DIR}/ DESTINATION include/appfw
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "${INC_DIR}/*.h"
+ )
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+ DEPENDS clean
+ COMMENT "distribution clean"
+ COMMAND find
+ ARGS .
+ -not -name config.cmake -and \(
+ -name tester.c -or
+ -name Testing -or
+ -name CMakeFiles -or
+ -name cmake.depends -or
+ -name cmake.check_depends -or
+ -name CMakeCache.txt -or
+ -name cmake.check_cache -or
+ -name *.cmake -or
+ -name Makefile -or
+ -name core -or
+ -name core.* -or
+ -name gmon.out -or
+ -name install_manifest.txt -or
+ -name *.pc -or
+ -name *~ \)
+ | grep -v TC | xargs rm -rf
+ TARGET distclean
+ VERBATIM
+)
+
+ENDIF(UNIX)
--- /dev/null
+Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+ Apache License\r
+ Version 2.0, January 2004\r
+ http://www.apache.org/licenses/\r
+\r
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+ 1. Definitions.\r
+\r
+ "License" shall mean the terms and conditions for use, reproduction,\r
+ and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+ "Licensor" shall mean the copyright owner or entity authorized by\r
+ the copyright owner that is granting the License.\r
+\r
+ "Legal Entity" shall mean the union of the acting entity and all\r
+ other entities that control, are controlled by, or are under common\r
+ control with that entity. For the purposes of this definition,\r
+ "control" means (i) the power, direct or indirect, to cause the\r
+ direction or management of such entity, whether by contract or\r
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+ outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+ "You" (or "Your") shall mean an individual or Legal Entity\r
+ exercising permissions granted by this License.\r
+\r
+ "Source" form shall mean the preferred form for making modifications,\r
+ including but not limited to software source code, documentation\r
+ source, and configuration files.\r
+\r
+ "Object" form shall mean any form resulting from mechanical\r
+ transformation or translation of a Source form, including but\r
+ not limited to compiled object code, generated documentation,\r
+ and conversions to other media types.\r
+\r
+ "Work" shall mean the work of authorship, whether in Source or\r
+ Object form, made available under the License, as indicated by a\r
+ copyright notice that is included in or attached to the work\r
+ (an example is provided in the Appendix below).\r
+\r
+ "Derivative Works" shall mean any work, whether in Source or Object\r
+ form, that is based on (or derived from) the Work and for which the\r
+ editorial revisions, annotations, elaborations, or other modifications\r
+ represent, as a whole, an original work of authorship. For the purposes\r
+ of this License, Derivative Works shall not include works that remain\r
+ separable from, or merely link (or bind by name) to the interfaces of,\r
+ the Work and Derivative Works thereof.\r
+\r
+ "Contribution" shall mean any work of authorship, including\r
+ the original version of the Work and any modifications or additions\r
+ to that Work or Derivative Works thereof, that is intentionally\r
+ submitted to Licensor for inclusion in the Work by the copyright owner\r
+ or by an individual or Legal Entity authorized to submit on behalf of\r
+ the copyright owner. For the purposes of this definition, "submitted"\r
+ means any form of electronic, verbal, or written communication sent\r
+ to the Licensor or its representatives, including but not limited to\r
+ communication on electronic mailing lists, source code control systems,\r
+ and issue tracking systems that are managed by, or on behalf of, the\r
+ Licensor for the purpose of discussing and improving the Work, but\r
+ excluding communication that is conspicuously marked or otherwise\r
+ designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+ "Contributor" shall mean Licensor and any individual or Legal Entity\r
+ on behalf of whom a Contribution has been received by Licensor and\r
+ subsequently incorporated within the Work.\r
+\r
+ 2. Grant of Copyright License. Subject to the terms and conditions of\r
+ this License, each Contributor hereby grants to You a perpetual,\r
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+ copyright license to reproduce, prepare Derivative Works of,\r
+ publicly display, publicly perform, sublicense, and distribute the\r
+ Work and such Derivative Works in Source or Object form.\r
+\r
+ 3. Grant of Patent License. Subject to the terms and conditions of\r
+ this License, each Contributor hereby grants to You a perpetual,\r
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+ (except as stated in this section) patent license to make, have made,\r
+ use, offer to sell, sell, import, and otherwise transfer the Work,\r
+ where such license applies only to those patent claims licensable\r
+ by such Contributor that are necessarily infringed by their\r
+ Contribution(s) alone or by combination of their Contribution(s)\r
+ with the Work to which such Contribution(s) was submitted. If You\r
+ institute patent litigation against any entity (including a\r
+ cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+ or a Contribution incorporated within the Work constitutes direct\r
+ or contributory patent infringement, then any patent licenses\r
+ granted to You under this License for that Work shall terminate\r
+ as of the date such litigation is filed.\r
+\r
+ 4. Redistribution. You may reproduce and distribute copies of the\r
+ Work or Derivative Works thereof in any medium, with or without\r
+ modifications, and in Source or Object form, provided that You\r
+ meet the following conditions:\r
+\r
+ (a) You must give any other recipients of the Work or\r
+ Derivative Works a copy of this License; and\r
+\r
+ (b) You must cause any modified files to carry prominent notices\r
+ stating that You changed the files; and\r
+\r
+ (c) You must retain, in the Source form of any Derivative Works\r
+ that You distribute, all copyright, patent, trademark, and\r
+ attribution notices from the Source form of the Work,\r
+ excluding those notices that do not pertain to any part of\r
+ the Derivative Works; and\r
+\r
+ (d) If the Work includes a "NOTICE" text file as part of its\r
+ distribution, then any Derivative Works that You distribute must\r
+ include a readable copy of the attribution notices contained\r
+ within such NOTICE file, excluding those notices that do not\r
+ pertain to any part of the Derivative Works, in at least one\r
+ of the following places: within a NOTICE text file distributed\r
+ as part of the Derivative Works; within the Source form or\r
+ documentation, if provided along with the Derivative Works; or,\r
+ within a display generated by the Derivative Works, if and\r
+ wherever such third-party notices normally appear. The contents\r
+ of the NOTICE file are for informational purposes only and\r
+ do not modify the License. You may add Your own attribution\r
+ notices within Derivative Works that You distribute, alongside\r
+ or as an addendum to the NOTICE text from the Work, provided\r
+ that such additional attribution notices cannot be construed\r
+ as modifying the License.\r
+\r
+ You may add Your own copyright statement to Your modifications and\r
+ may provide additional or different license terms and conditions\r
+ for use, reproduction, or distribution of Your modifications, or\r
+ for any such Derivative Works as a whole, provided Your use,\r
+ reproduction, and distribution of the Work otherwise complies with\r
+ the conditions stated in this License.\r
+\r
+ 5. Submission of Contributions. Unless You explicitly state otherwise,\r
+ any Contribution intentionally submitted for inclusion in the Work\r
+ by You to the Licensor shall be under the terms and conditions of\r
+ this License, without any additional terms or conditions.\r
+ Notwithstanding the above, nothing herein shall supersede or modify\r
+ the terms of any separate license agreement you may have executed\r
+ with Licensor regarding such Contributions.\r
+\r
+ 6. Trademarks. This License does not grant permission to use the trade\r
+ names, trademarks, service marks, or product names of the Licensor,\r
+ except as required for reasonable and customary use in describing the\r
+ origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+ 7. Disclaimer of Warranty. Unless required by applicable law or\r
+ agreed to in writing, Licensor provides the Work (and each\r
+ Contributor provides its Contributions) on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+ implied, including, without limitation, any warranties or conditions\r
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+ PARTICULAR PURPOSE. You are solely responsible for determining the\r
+ appropriateness of using or redistributing the Work and assume any\r
+ risks associated with Your exercise of permissions under this License.\r
+\r
+ 8. Limitation of Liability. In no event and under no legal theory,\r
+ whether in tort (including negligence), contract, or otherwise,\r
+ unless required by applicable law (such as deliberate and grossly\r
+ negligent acts) or agreed to in writing, shall any Contributor be\r
+ liable to You for damages, including any direct, indirect, special,\r
+ incidental, or consequential damages of any character arising as a\r
+ result of this License or out of the use or inability to use the\r
+ Work (including but not limited to damages for loss of goodwill,\r
+ work stoppage, computer failure or malfunction, or any and all\r
+ other commercial damages or losses), even if such Contributor\r
+ has been advised of the possibility of such damages.\r
+\r
+ 9. Accepting Warranty or Additional Liability. While redistributing\r
+ the Work or Derivative Works thereof, You may choose to offer,\r
+ and charge a fee for, acceptance of support, warranty, indemnity,\r
+ or other liability obligations and/or rights consistent with this\r
+ License. However, in accepting such obligations, You may act only\r
+ on Your own behalf and on Your sole responsibility, not on behalf\r
+ of any other Contributor, and only if You agree to indemnify,\r
+ defend, and hold each Contributor harmless for any liability\r
+ incurred by, or claims asserted against, such Contributor by reason\r
+ of your accepting any such warranty or additional liability.\r
+\r
+ END OF TERMS AND CONDITIONS\r
+\r
+ APPENDIX: How to apply the Apache License to your work.\r
+\r
+ To apply the Apache License to your work, attach the following\r
+ boilerplate notice, with the fields enclosed by brackets "[]"\r
+ replaced with your own identifying information. (Don't include\r
+ the brackets!) The text should be enclosed in the appropriate\r
+ comment syntax for the file format. We also recommend that a\r
+ file or class name and description of purpose be included on the\r
+ same "printed page" as the copyright notice for easier\r
+ identification within third-party archives.\r
+\r
+ Copyright [yyyy] [name of copyright owner]\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
--- /dev/null
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@/appfw
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
--- /dev/null
+/*
+ * Copyright (c) 2017 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_APPFW_JOB_SCHEDULER_DOC_H__
+#define __TIZEN_APPFW_JOB_SCHEDULER_DOC_H__
+
+/**
+ * @ingroup CAPI_APPLICATION_MODULE
+ * @defgroup CAPI_JOB_SCHEDULER_MODULE Job scheduler
+ * @brief The @ref CAPI_JOB_SCHEDULER_MODULE API contains the job scheduler library.
+ *
+ * @section CAPI_JOB_SCHEDULER_MODULE_HEADER Required Header
+ * \#include <job_scheduler.h>
+ *
+ * @section CAPI_JOB_SCHEDULER_MODULE_OVERVIEW Overview
+ * It provides functions to define job-execution conditions. It improves the applications' performance and system health.
+ *
+ * @section CAPI_JOB_SCHEDULER_MODULE_FEATURE Related Features
+ * Some job trigger events and some functions are related with the following features:
+ * - http://tizen.org/feature/network.wifi
+ * - http://tizen.org/feature/location.gps
+ * - http://tizen.org/feature/battery
+ * - http://tizen.org/feature/usb.host
+ *
+ * It is recommended to design feature related code in your application for reliability.
+ * You can check if the device supports the related features for this API by using @ref CAPI_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ */
+
+#endif /* __TIZEN_APPFW_JOB_SCHEDULER_DOC_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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_APPFW_JOB_ERROR_H__
+#define __TIZEN_APPFW_JOB_ERROR_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_APPLICATION_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration for job error.
+ * @since_tizen 4.0
+ */
+typedef enum {
+ JOB_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ JOB_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ JOB_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ JOB_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< IO error */
+ JOB_ERROR_NOT_INITIALIZED = TIZEN_ERROR_JOB_SCHEDULER | 0x21, /**< Not initialized */
+ JOB_ERROR_NO_SUCH_JOB = TIZEN_ERROR_JOB_SCHEDULER | 0x22, /**< No such job */
+ JOB_ERROR_ALREADY_EXIST = TIZEN_ERROR_JOB_SCHEDULER | 0x23, /**< Already exist */
+ JOB_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+ JOB_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED /**< Not supported */
+} job_error_e;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_JOB_ERROR_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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_APPFW_JOB_INFO_H__
+#define __TIZEN_APPFW_JOB_INFO_H__
+
+#include <job_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_APPLICATION_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration for the job trigger events.
+ * @since_tizen 4.0
+ */
+typedef enum {
+ JOB_TRIGGER_EVENT_BATTERY_LEVEL_EMPTY, /**< The battery level status: Empty */
+ JOB_TRIGGER_EVENT_BATTERY_LEVEL_CRITICAL, /**< The battery level status: Critical */
+ JOB_TRIGGER_EVENT_BATTERY_LEVEL_LOW, /**< The battery level status: Low */
+ JOB_TRIGGER_EVENT_BATTERY_LEVEL_HIGH, /**< The battery level status: High */
+ JOB_TRIGGER_EVENT_CHARGER_STATE_CONNECTED, /**< The charger state: Connected */
+ JOB_TRIGGER_EVENT_CHARGER_STATE_DISCONNECTED, /**< The charger state: Disconnected */
+ JOB_TRIGGER_EVENT_DISPLAY_STATE_ON, /**< The display state: On */
+ JOB_TRIGGER_EVENT_DISPLAY_STATE_OFF, /**< The display state: Off */
+ JOB_TRIGGER_EVENT_DISPLAY_STATE_DIM, /**< The display state: Dim */
+ JOB_TRIGGER_EVENT_EARJACK_STATE_CONNECTED, /**< The earjack state: Connected */
+ JOB_TRIGGER_EVENT_EARJACK_STATE_DISCONNECTED, /**< The earjack state: Disconnected */
+ JOB_TRIGGER_EVENT_GPS_STATE_DISABLED, /**< The GPS state: Disabled */
+ JOB_TRIGGER_EVENT_GPS_STATE_SEARCHING, /**< The GPS state: Searching */
+ JOB_TRIGGER_EVENT_GPS_STATE_CONNECTED, /**< The GPS state: Connected */
+ JOB_TRIGGER_EVENT_POWERSAVE_MODE_ENABLED, /**< The Power-saving mode: Enabled */
+ JOB_TRIGGER_EVENT_POWERSAVE_MODE_DISABLED, /**< The Power-saving mode: Disabled */
+ JOB_TRIGGER_EVENT_USB_STATE_CONNECTED, /**< The USB state: Connected */
+ JOB_TRIGGER_EVENT_USB_STATE_DISCONNECTED, /**< The USB state: Disconnected */
+ JOB_TRIGGER_EVENT_WIFI_STATE_DISABLED, /**< The WiFi state: Disabled @n Privilege: http://tizen.org/privilege/network.get */
+ JOB_TRIGGER_EVENT_WIFI_STATE_DISCONNECTED, /**< The WiFi state: Disconnected @n Privilege: http://tizen.org/privilege/network.get */
+ JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED, /**< The WiFi state: Connected @n Privilege: http://tizen.org/privilege/network.get */
+} job_trigger_event_e;
+
+/**
+ * @brief The job info handle.
+ * @since_tizen 4.0
+ */
+typedef struct job_info_s *job_info_h;
+
+/**
+ * @brief Creates the job info handle.
+ * @since_tizen 4.0
+ * @remarks The @a job_info must be released by using job_info_destroy().
+ * The job will be started by the periodic interval or the trigger events.
+ * @param[out] job_info The job info handle to be newly created on success
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_OUT_OF_MEMORY Out of memory
+ * @see job_info_destroy()
+ * @see job_info_set_periodic()
+ * @see job_info_add_trigger_event()
+ */
+int job_info_create(job_info_h *job_info);
+
+/**
+ * @brief Destroys the job info handle and releases all its resources.
+ * @since_tizen 4.0
+ * @param[in] job_info The job info handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see job_info_create()
+ */
+int job_info_destroy(job_info_h job_info);
+
+/**
+ * @brief Sets the periodic interval of the job.
+ * @since_tizen 4.0
+ * @remarks The platform does not guarantee the accuracy of the given interval for minimizing the wakeups of the device.
+ * Thus you should not rely on it for timing.
+ * If this function is called after adding the job trigger events by using job_info_add_trigger_event(),
+ * the function returns a negative error value.
+ * @param[in] job_info The job info handle
+ * @param[in] interval The periodic interval (in minutes)
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see job_info_destroy()
+ */
+int job_info_set_periodic(job_info_h job_info, unsigned int interval);
+
+/**
+ * @brief Sets the job to be automatically scheduled after the device reboots.
+ * @since_tizen 4.0
+ * @param[in] job_info The job info handle
+ * @param[in] persistent @c true, if the job needs to be automatically scheduled
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int job_info_set_persistent(job_info_h job_info, bool persistent);
+
+/**
+ * @brief Sets the job not to be repeated.
+ * @since_tizen 4.0
+ * @param[in] job_info The job info handle
+ * @param[in] once @c true, if the job does not need to be repeated
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int job_info_set_once(job_info_h job_info, bool once);
+
+/**
+ * @brief Sets the timeout interval of the requirements.
+ * @since_tizen 4.0
+ * @param[in] job_info The job info handle
+ * @param[in] timeout The timeout interval (ms)
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int job_info_set_requirement_timeout(job_info_h job_info, unsigned int timeout);
+
+/**
+ * @brief Sets that the battery level must not be low to run the job.
+ * @since_tizen 4.0
+ * @param[in] job_info The job info handle
+ * @param[in] battery_not_low @c true, the battery level must not be low.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_IO_ERROR IO error
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_NOT_SUPPORTED Not supported
+ * @pre job_scheduler_init() must be called.
+ * @see job_scheduler_init()
+ */
+int job_info_set_requires_battery_not_low(job_info_h job_info, bool battery_not_low);
+
+/**
+ * @brief Sets that the battery must be charging to run the job.
+ * @since_tizen 4.0
+ * @param[in] job_info The job info handle
+ * @param[in] charging @c true, the battery must be charging.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_IO_ERROR IO error
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_NOT_SUPPORTED Not supported
+ * @pre job_scheduler_init() must be called.
+ * @see job_scheduler_init()
+ */
+int job_info_set_requires_charging(job_info_h job_info, bool charging);
+
+/**
+ * @brief Sets that the WiFi must be connected to run the job.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/network.get
+ * @param[in] job_info The job info handle
+ * @param[in] wifi_connection @c true, the WiFi must be connected.
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_IO_ERROR IO error
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_NOT_SUPPORTED Not supported
+ * @retval #JOB_ERROR_PERMISSION_DENIED Permission denied
+ * @pre job_scheduler_init() must be called.
+ * @see job_scheduler_init()
+ */
+int job_info_set_requires_wifi_connection(job_info_h job_info, bool wifi_connection);
+
+/**
+ * @brief Adds the trigger event to the job info handle.
+ * @since_tizen 4.0
+ * @remarks The periodic interval of the job info handle must be 0.
+ * If the interval of the job info handle is not 0, this function returns a negative error value.
+ * Regarding the @a event, the application may require the following privilege:
+ * http://tizen.org/privilege/network.get @n
+ * If the application does not have the necessary privilege, this function returns #JOB_ERROR_PERMISSION_DENIED.
+ * See #job_trigger_event_e to find the corresponding privilege of each event.
+ * @param[in] job_info The job info handle
+ * @param[in] event The job trigger event
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_IO_ERROR IO error
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_NOT_SUPPORTED Not supported
+ * @retval #JOB_ERROR_ALREADY_EXIST Already exist
+ * @retval #JOB_ERROR_PERMISSION_DENIED Permission denied
+ * @pre job_scheduler_init() must be called.
+ * @see job_scheduler_init()
+ * @see job_info_remove_trigger_event()
+ * @see job_trigger_event_e
+ */
+int job_info_add_trigger_event(job_info_h job_info, job_trigger_event_e event);
+
+/**
+ * @brief Removes the trigger event from the job info handle.
+ * @since_tizen 4.0
+ * @remarks The periodic interval of the job info handle must be 0.
+ * If the interval of the job info handle is not 0, this function returns a negative error value.
+ * @param[in] job_info The job info handle
+ * @param[in] event The job trigger event
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see job_info_add_trigger_event()
+ * @see job_trigger_event_e
+ */
+int job_info_remove_trigger_event(job_info_h job_info, job_trigger_event_e event);
+
+/**
+ * @brief Gets the ID of the job.
+ * @since_tizen 4.0
+ * @remarks The @a job_info must be scheduled by using job_scheduler_schedule().
+ * If the job_info is not scheduled, this function returns a negative error value.
+ * The @a job_id must be released by using free().
+ * @param[in] job_info The job info handle
+ * @param[out] job_id The ID of the job
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_OUT_OF_MEMORY Out of memory
+ * @see job_scheduler_schedule()
+ */
+int job_info_get_job_id(job_info_h job_info, char **job_id);
+
+/**
+ * @brief Clones the given job_info handle.
+ * @since_tizen 4.0
+ * @remarks The newly created job_info handle must be released by using job_info_destroy().
+ * @param[in] job_info The job info handle
+ * @param[out] clone If successful, a newly created job info handle will be returned
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_OUT_OF_MEMORY Out of memory
+ * @see job_info_destroy()
+ */
+int job_info_clone(job_info_h job_info, job_info_h *clone);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_JOB_INFO_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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_APPFW_JOB_SCHEDULER_H__
+#define __TIZEN_APPFW_JOB_SCHEDULER_H__
+
+#include <job_error.h>
+#include <job_info.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_APPLICATION_MODULE
+ * @{
+ */
+
+/**
+ * @brief The job service handle.
+ * @since_tizen 4.0
+ */
+typedef struct job_service_s *job_service_h;
+
+/**
+ * @brief Called when the job starts.
+ * @since_tizen 4.0
+ * @remarks The @a job_info MUST NOT be deallocated by the application.
+ * The @a job_info is managed by the platform and is valid only in the callback.
+ * @param[in] job_info The job info handle
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see job_scheduler_service_add()
+ * @see #job_service_callback_s
+ */
+typedef void (*job_service_start_cb)(job_info_h job_info, void *user_data);
+
+/**
+ * @brief Called when the job stops.
+ * @since_tizen 4.0
+ * @remarks The @a job_info MUST not be deallocated by the application.
+ * The @a job_info is managed by the platform and is valid only in the callback.
+ * @param[in] job_info The job info handle
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see job_scheduler_service_add()
+ * @see #job_service_callback_s
+ */
+typedef void (*job_service_stop_cb)(job_info_h job_info, void *user_data);
+
+/**
+ * @brief The structure type containing the set of callback functions for handling jobs.
+ * @details It is one of the input parameter of the job_scheduler_service_add() function.
+ * @since_tizen 4.0
+ * @see job_scheduler_service_add()
+ * @see job_service_start_cb()
+ * @see job_service_stop_cb()
+ */
+typedef struct {
+ job_service_start_cb start; /**< This callback function is called at the start of the job. */
+ job_service_stop_cb stop; /**< This callback function is called at the stop of the job. */
+} job_service_callback_s;
+
+/**
+ * @brief Called to retrieve the job information.
+ * @since_tizen 4.0
+ * @remarks The @a job_info must not be deallocated by the application.
+ * @param[in] job_info The job_info handle
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true continue with the next iteration of the loop,
+ * otherwise @c false to break out of the loop
+ * @pre job_scheduler_foreach_job() will invoke this callback.
+ * @see job_scheduler_foreach_job()
+ */
+typedef bool (*job_scheduler_foreach_job_cb)(job_info_h job_info, void *user_data);
+
+/**
+ * @brief Initializes the job scheduler.
+ * @since_tizen 4.0
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_IO_ERROR IO error
+ * @retval #JOB_ERROR_OUT_OF_MEMORY Out of memory
+ * @see job_scheduler_finish()
+ */
+int job_scheduler_init(void);
+
+/**
+ * @brief Finalizes the job scheduler.
+ * @since_tizen 4.0
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @see job_scheduler_init()
+ */
+int job_scheduler_finish(void);
+
+/**
+ * @brief Schedules the job.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/appmanager.launch
+ * @param[in] job_info The job info handle
+ * @param[in] job_id The ID of the job
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_IO_ERROR IO error
+ * @retval #JOB_ERROR_ALREADY_EXIST Already exist
+ * @retval #JOB_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #JOB_ERROR_PERMISSION_DENIED Permission denied
+ * @pre job_scheduler_init() MUST be called.
+ * @see job_scheduler_init()
+ * @see job_info_create()
+ */
+int job_scheduler_schedule(job_info_h job_info, const char *job_id);
+
+/**
+ * @brief Cancels the scheduled job.
+ * @since_tizen 4.0
+ * @param[in] job_id The ID of the scheduled job
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_IO_ERROR IO error
+ * @retval #JOB_ERROR_NO_SUCH_JOB No such job
+ * @pre job_scheduler_init() MUST be called.
+ * @see job_scheduler_init()
+ */
+int job_scheduler_cancel(const char *job_id);
+
+/**
+ * @brief Cancels all scheduled jobs.
+ * @since_tizen 4.0
+ * @return @c 0 on success,
+ * otherwise a nagative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_IO_ERROR IO error
+ * @pre job_scheduler_init() MUST be called.
+ * @see job_scheduler_init()
+ */
+int job_scheduler_cancel_all(void);
+
+/**
+ * @brief Notify that the job is finished.
+ * @since_tizen 4.0
+ * @remarks If the job has been launched, the system kept awake for a while.
+ * It is highly recommended to notify that the job is done,
+ * the system thus knows it does not need to be kept awake.
+ * @param[in] job_id The ID of the scheduled job
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_NO_SUCH_JOB No such job
+ * @retval #JOB_ERROR_IO_ERROR IO error
+ * @pre job_scheduler_init() MUST be called.
+ * @see job_scheduler_init()
+ */
+int job_scheduler_notify_job_finished(const char *job_id);
+
+/**
+ * @brief Retrieves all scheduled jobs.
+ * @since_tizen 4.0
+ * @param[in] callback The iteration callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_NO_SUCH_JOB No scheduled jobs
+ * @pre job_scheduler_init() MUST be called.
+ * @see job_scheduler_init()
+ */
+int job_scheduler_foreach_job(job_scheduler_foreach_job_cb callback, void *user_data);
+
+/**
+ * @brief Adds job service handler for receiving the information of the scheduled job.
+ * @since_tizen 4.0
+ * @param[in] job_id The ID of the job
+ * @param[in] callback The set of callback functions to handle jobs
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] job_service The job service handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #JOB_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre job_scheduler_init() MUST be called.
+ * @see job_scheduler_init()
+ * @see job_scheduler_service_remove()
+ * @see job_service_start_cb()
+ * @see job_service_stop_cb()
+ * @see job_scheduler_job_finished()
+ * @see #job_service_callback_s
+ */
+int job_scheduler_service_add(const char *job_id, job_service_callback_s *callback, void *user_data, job_service_h *job_service);
+
+/**
+ * @brief Removes registered job service handler.
+ * @since_tizen 4.0
+ * @param[in] job_service The job service handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #JOB_ERROR_NONE Successful
+ * @retval #JOB_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #JOB_ERROR_NOT_INITIALIZED Not initialzed
+ * @pre job_scheduler_init() MUST be called.
+ * @see job_scheduler_init()
+ * @see job_scheduler_service_add()
+ */
+int job_scheduler_service_remove(job_service_h job_service);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_JOB_SCHEDULER_H__ */
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+Name: capi-appfw-job-scheduler
+Summary: Job Scheduler library
+Version: 0.1.0
+Release: 0
+Group: System/API
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Source1001: capi-appfw-job-scheduler.manifest
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(bundle)
+BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(capi-appfw-app-common)
+BuildRequires: pkgconfig(context-job-scheduler-client)
+BuildRequires: pkgconfig(context-common-client)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(capi-appfw-service-application)
+BuildRequires: pkgconfig(cynara-creds-self)
+BuildRequires: pkgconfig(cynara-session)
+BuildRequires: pkgconfig(cynara-client)
+
+%description
+Job Scheduler library in Tizen C API
+
+%package devel
+Summary: Job Scheduler library in Tizen C API (Development)
+Group: System/API
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+An Application library in SLP C API (Development) package.
+
+
+%prep
+%setup -q
+cp %{SOURCE1001} .
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%cmake -DFULLVER=%{version} \
+ -DMAJORVER=${MAJORVER} \
+ .
+
+%__make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
+%files
+%manifest %{name}.manifest
+%{_libdir}/libcapi-appfw-job-scheduler.so.*
+%license LICENSE
+
+%files devel
+%manifest %{name}.manifest
+%{_includedir}/appfw/*.h
+%{_libdir}/pkgconfig/capi-appfw-job-scheduler.pc
+%{_libdir}/libcapi-appfw-job-scheduler.so
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-appfw-job-scheduler")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR ${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(requires "dlog bundle aul glib-2.0 capi-appfw-app-common context-job-scheduler-client capi-base-common context-common-client capi-appfw-service-application cynara-creds-self cynara-session cynara-client")
+SET(pc_requires "dlog")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${requires})
+FOREACH(flag ${${fw_name}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -Werror")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC ")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -Wall -Werror")
+
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DSLP_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
+
+ADD_LIBRARY(${fw_name} SHARED
+ job_scheduler.c
+ job_info.c
+ job_error.c
+ )
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS} capi-appfw-app-common)
+
+SET_TARGET_PROPERTIES(${fw_name}
+ PROPERTIES
+ VERSION ${FULLVER}
+ SOVERSION ${MAJORVER}
+ CLEAN_DIRECT_OUTPUT 1
+)
+
+INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(
+ DIRECTORY ${INC_DIR}/ DESTINATION include/appfw
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "${INC_DIR}/*.h"
+ )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_requires})
+SET(PC_LDFLAGS -l${fw_name})
+
+CONFIGURE_FILE(
+ ${CMAKE_SOURCE_DIR}/${fw_name}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
--- /dev/null
+/*
+ * Copyright (c) 2017 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 _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "job_error_private.h"
+#include "job_error.h"
+
+static const char *__job_error_to_string(job_error_e error)
+{
+ switch (error) {
+ case JOB_ERROR_NONE:
+ return "None";
+ case JOB_ERROR_INVALID_PARAMETER:
+ return "Invalid parameter";
+ case JOB_ERROR_OUT_OF_MEMORY:
+ return "Out of memory";
+ case JOB_ERROR_IO_ERROR:
+ return "IO error";
+ case JOB_ERROR_NOT_INITIALIZED:
+ return "Not initialized";
+ case JOB_ERROR_NO_SUCH_JOB:
+ return "No such job";
+ case JOB_ERROR_ALREADY_EXIST:
+ return "Already exist";
+ case JOB_ERROR_PERMISSION_DENIED:
+ return "Permission denied";
+ default:
+ return "Unknown";
+ }
+}
+
+int job_error(job_error_e error, const char *function, const int line,
+ const char *description)
+{
+ if (description) {
+ LOGE("[%s][%d] %s(0x%08x) - %s",
+ function, line,
+ __job_error_to_string(error), error,
+ description);
+ } else {
+ LOGE("[%s][%d] %s(0x%08x)",
+ function, line,
+ __job_error_to_string(error), error);
+ }
+
+ return error;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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_APPFW_JOB_ERROR_PRIVATE_H__
+#define __TIZEN_APPFW_JOB_ERROR_PRIVATE_H__
+
+#include <dlog.h>
+
+#include "job_error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_JOB_SCHEDULER"
+
+#ifndef _E
+#define _E LOGE
+#endif
+
+#ifndef _W
+#define _W LOGW
+#endif
+
+#ifndef _I
+#define _I LOGI
+#endif
+
+#ifndef _D
+#define _D LOGD
+#endif
+
+int job_error(job_error_e error, const char *function, const int line,
+ const char *description);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_JOB_ERROR_PRIVATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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 _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <job_scheduler_internal.h>
+#include <job_scheduler_types_internal.h>
+#include <aul_job_scheduler.h>
+#include <bundle_internal.h>
+
+#include "job_error_private.h"
+#include "job_info_private.h"
+#include "job_scheduler_private.h"
+
+#ifdef API
+#undef API
+#endif
+#define API __attribute__((visibility("default")))
+
+#define ARRAY_SIZE(x) ((sizeof(x)) / (sizeof(x[0])))
+
+struct job_info_s {
+ char *job_id;
+ unsigned int interval; /* Periodic */
+ bool persistent;
+ bool once;
+ unsigned int timeout;
+ int battery_not_low;
+ int charging;
+ int wifi_connection;
+ bool trigger_list[JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED + 1];
+};
+
+static const char *trigger_uri[] = {
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_EMPTY] = CTX_SCHED_URI_BATTERY,
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_CRITICAL] = CTX_SCHED_URI_BATTERY,
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_LOW] = CTX_SCHED_URI_BATTERY,
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_HIGH] = CTX_SCHED_URI_BATTERY,
+ [JOB_TRIGGER_EVENT_CHARGER_STATE_CONNECTED] = CTX_SCHED_URI_CHARGER,
+ [JOB_TRIGGER_EVENT_CHARGER_STATE_DISCONNECTED] = CTX_SCHED_URI_CHARGER,
+ [JOB_TRIGGER_EVENT_DISPLAY_STATE_ON] = CTX_SCHED_URI_DISPLAY,
+ [JOB_TRIGGER_EVENT_DISPLAY_STATE_OFF] = CTX_SCHED_URI_DISPLAY,
+ [JOB_TRIGGER_EVENT_DISPLAY_STATE_DIM] = CTX_SCHED_URI_DISPLAY,
+ [JOB_TRIGGER_EVENT_EARJACK_STATE_CONNECTED] = CTX_SCHED_URI_EARJACK,
+ [JOB_TRIGGER_EVENT_EARJACK_STATE_DISCONNECTED] = CTX_SCHED_URI_EARJACK,
+ [JOB_TRIGGER_EVENT_GPS_STATE_DISABLED] = CTX_SCHED_URI_GPS,
+ [JOB_TRIGGER_EVENT_GPS_STATE_SEARCHING] = CTX_SCHED_URI_GPS,
+ [JOB_TRIGGER_EVENT_GPS_STATE_CONNECTED] = CTX_SCHED_URI_GPS,
+ [JOB_TRIGGER_EVENT_POWERSAVE_MODE_ENABLED] = CTX_SCHED_URI_POWERSAVE,
+ [JOB_TRIGGER_EVENT_POWERSAVE_MODE_DISABLED] = CTX_SCHED_URI_POWERSAVE,
+ [JOB_TRIGGER_EVENT_USB_STATE_CONNECTED] = CTX_SCHED_URI_USB,
+ [JOB_TRIGGER_EVENT_USB_STATE_DISCONNECTED] = CTX_SCHED_URI_USB,
+ [JOB_TRIGGER_EVENT_WIFI_STATE_DISABLED] = CTX_SCHED_URI_WIFI,
+ [JOB_TRIGGER_EVENT_WIFI_STATE_DISCONNECTED] = CTX_SCHED_URI_WIFI,
+ [JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED] = CTX_SCHED_URI_WIFI,
+};
+
+API int job_info_create(job_info_h *job_info)
+{
+ struct job_info_s *info;
+
+ if (job_info == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ info = calloc(1, sizeof(struct job_info_s));
+ if (info == NULL) {
+ return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ info->battery_not_low = -1;
+ info->charging = -1;
+ info->wifi_connection = -1;
+
+ *job_info = info;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_destroy(job_info_h job_info)
+{
+ if (job_info == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (job_info->job_id)
+ free(job_info->job_id);
+
+ free(job_info);
+
+ return JOB_ERROR_NONE;
+}
+
+static bool __exist_trigger_event(job_info_h job_info)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(job_info->trigger_list); ++i) {
+ if (job_info->trigger_list[i])
+ return true;
+ }
+
+ return false;
+}
+
+API int job_info_set_periodic(job_info_h job_info, unsigned int interval)
+{
+ if (job_info == NULL || __exist_trigger_event(job_info)) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ job_info->interval = interval;
+
+ return JOB_ERROR_NONE;
+}
+
+int job_info_get_periodic(job_info_h job_info, unsigned int *interval)
+{
+ if (job_info == NULL || interval == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ *interval = job_info->interval;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_set_persistent(job_info_h job_info, bool persistent)
+{
+ if (job_info == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ job_info->persistent = persistent;
+
+ return JOB_ERROR_NONE;
+}
+
+int job_info_get_persistent(job_info_h job_info, bool *persistent)
+{
+ if (job_info == NULL || persistent == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ *persistent = job_info->persistent;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_set_once(job_info_h job_info, bool once)
+{
+ if (job_info == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ job_info->once = once;
+
+ return JOB_ERROR_NONE;
+}
+
+int job_info_is_once(job_info_h job_info, bool *once)
+{
+ if (job_info == NULL || once == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ *once = job_info->once;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_set_requirement_timeout(job_info_h job_info,
+ unsigned int timeout)
+{
+ if (job_info == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ job_info->timeout = timeout;
+
+ return JOB_ERROR_NONE;
+}
+
+int job_info_get_requirement_timeout(job_info_h job_info, unsigned int *timeout)
+{
+ if (job_info == NULL || timeout == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ *timeout = job_info->timeout;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_set_requires_battery_not_low(job_info_h job_info,
+ bool battery_not_low)
+{
+ int r;
+
+ if (job_info == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = job_scheduler_verify_requirement(CTX_SCHED_URI_BATTERY);
+ if (r != JOB_ERROR_NONE)
+ return job_error(r, __FUNCTION__, __LINE__, NULL);
+
+ job_info->battery_not_low = battery_not_low;
+
+ return JOB_ERROR_NONE;
+}
+
+int job_info_is_requires_battery_not_low(job_info_h job_info,
+ int *battery_not_low)
+{
+ if (job_info == NULL || battery_not_low == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ *battery_not_low = job_info->battery_not_low;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_set_requires_charging(job_info_h job_info, bool charging)
+{
+ int r;
+
+ if (job_info == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = job_scheduler_verify_requirement(CTX_SCHED_URI_BATTERY);
+ if (r != JOB_ERROR_NONE)
+ return job_error(r, __FUNCTION__, __LINE__, NULL);
+
+ job_info->charging = charging;
+
+ return JOB_ERROR_NONE;
+}
+
+int job_info_is_requires_charging(job_info_h job_info, int *charging)
+{
+ if (job_info == NULL || charging == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ *charging = job_info->charging;
+
+ return JOB_ERROR_NONE;
+}
+
+static const char *__get_privilege(job_trigger_event_e event)
+{
+ if (event == JOB_TRIGGER_EVENT_WIFI_STATE_DISABLED ||
+ event == JOB_TRIGGER_EVENT_WIFI_STATE_DISCONNECTED ||
+ event == JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED)
+ return "http://tizen.org/privilege/network.get";
+
+ return NULL;
+}
+
+API int job_info_set_requires_wifi_connection(job_info_h job_info,
+ bool wifi_connection)
+{
+ int r;
+ const char *privilege;
+
+ if (job_info == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ privilege = __get_privilege(JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED);
+ r = job_scheduler_verify_privilege(privilege);
+ if (r != JOB_ERROR_NONE)
+ return job_error(r, __FUNCTION__, __LINE__, NULL);
+
+ r = job_scheduler_verify_requirement(CTX_SCHED_URI_WIFI);
+ if (r != JOB_ERROR_NONE)
+ return job_error(r, __FUNCTION__, __LINE__, NULL);
+
+ job_info->wifi_connection = wifi_connection;
+
+ return JOB_ERROR_NONE;
+}
+
+int job_info_is_requires_wifi_connection(job_info_h job_info,
+ int *wifi_connection)
+{
+ if (job_info == NULL || wifi_connection == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ *wifi_connection = job_info->wifi_connection;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_add_trigger_event(job_info_h job_info,
+ job_trigger_event_e event)
+{
+ int r;
+ const char *privilege;
+
+ if (job_info == NULL || job_info->interval > 0 ||
+ event < JOB_TRIGGER_EVENT_BATTERY_LEVEL_EMPTY ||
+ event > JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ privilege = __get_privilege(event);
+ r = job_scheduler_verify_privilege(privilege);
+ if (r != JOB_ERROR_NONE)
+ return job_error(r, __FUNCTION__, __LINE__, NULL);
+
+ r = job_scheduler_verify_trigger(trigger_uri[event]);
+ if (r != JOB_ERROR_NONE)
+ return job_error(r, __FUNCTION__, __LINE__, NULL);
+
+ job_info->trigger_list[event] = true;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_remove_trigger_event(job_info_h job_info,
+ job_trigger_event_e event)
+{
+ if (job_info == NULL || job_info->interval > 0 ||
+ event < JOB_TRIGGER_EVENT_BATTERY_LEVEL_EMPTY ||
+ event > JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ job_info->trigger_list[event] = false;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_clone(job_info_h job_info, job_info_h *clone)
+{
+ struct job_info_s *info;
+ int i;
+
+ if (job_info == NULL || clone == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ info = calloc(1, sizeof(struct job_info_s));
+ if (info == NULL) {
+ return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (job_info->job_id) {
+ info->job_id = strdup(job_info->job_id);
+ if (info->job_id == NULL) {
+ free(info);
+ return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+ __LINE__, NULL);
+ }
+ }
+
+ info->interval = job_info->interval;
+ info->persistent = job_info->persistent;
+ info->once = job_info->once;
+ info->timeout = job_info->timeout;
+ info->battery_not_low = job_info->battery_not_low;
+ info->charging = job_info->charging;
+ info->wifi_connection = job_info->wifi_connection;
+
+ for (i = 0; i < ARRAY_SIZE(job_info->trigger_list); ++i)
+ info->trigger_list[i] = job_info->trigger_list[i];
+
+ *clone = info;
+
+ return JOB_ERROR_NONE;
+}
+
+int job_info_get_trigger_list(job_info_h job_info, bool **trigger_list)
+{
+ if (job_info == NULL || trigger_list == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ *trigger_list = job_info->trigger_list;
+
+ return JOB_ERROR_NONE;
+}
+
+int job_info_set_job_id(job_info_h job_info, const char *job_id)
+{
+ if (job_info == NULL || job_id == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (job_info->job_id)
+ free(job_info->job_id);
+
+ job_info->job_id = strdup(job_id);
+ if (job_info->job_id == NULL) {
+ return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_info_get_job_id(job_info_h job_info, char **job_id)
+{
+ if (job_info == NULL || job_info->job_id == NULL || job_id == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ *job_id = strdup(job_info->job_id);
+ if (*job_id == NULL) {
+ return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+static void __set_requires_value(const char *str, int *value)
+{
+ if (str && strcmp(str, "true") == 0)
+ *value = true;
+ else if (str && strcmp(str, "false") == 0)
+ *value = false;
+ else
+ *value = -1;
+}
+
+static void __set_job_info(job_info_h job_info, bundle *b)
+{
+ int i;
+ const char *val;
+ static const char *key_list[] = {
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_EMPTY] =
+ AUL_K_JOB_TRIG_BATTERY_LEVEL_EMPTY,
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_CRITICAL] =
+ AUL_K_JOB_TRIG_BATTERY_LEVEL_CRITICAL,
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_LOW] =
+ AUL_K_JOB_TRIG_BATTERY_LEVEL_LOW,
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_HIGH] =
+ AUL_K_JOB_TRIG_BATTERY_LEVEL_HIGH,
+ [JOB_TRIGGER_EVENT_CHARGER_STATE_CONNECTED] =
+ AUL_K_JOB_TRIG_CHARGER_STATE_CONNECTED,
+ [JOB_TRIGGER_EVENT_CHARGER_STATE_DISCONNECTED] =
+ AUL_K_JOB_TRIG_CHARGER_STATE_DISCONNECTED,
+ [JOB_TRIGGER_EVENT_DISPLAY_STATE_ON] =
+ AUL_K_JOB_TRIG_DISPLAY_STATE_ON,
+ [JOB_TRIGGER_EVENT_DISPLAY_STATE_OFF] =
+ AUL_K_JOB_TRIG_DISPLAY_STATE_OFF,
+ [JOB_TRIGGER_EVENT_DISPLAY_STATE_DIM] =
+ AUL_K_JOB_TRIG_DISPLAY_STATE_DIM,
+ [JOB_TRIGGER_EVENT_EARJACK_STATE_CONNECTED] =
+ AUL_K_JOB_TRIG_EARJACK_STATE_CONNECTED,
+ [JOB_TRIGGER_EVENT_EARJACK_STATE_DISCONNECTED] =
+ AUL_K_JOB_TRIG_EARJACK_STATE_DISCONNECTED,
+ [JOB_TRIGGER_EVENT_GPS_STATE_DISABLED] =
+ AUL_K_JOB_TRIG_GPS_STATE_DISABLED,
+ [JOB_TRIGGER_EVENT_GPS_STATE_SEARCHING] =
+ AUL_K_JOB_TRIG_GPS_STATE_SEARCHING,
+ [JOB_TRIGGER_EVENT_GPS_STATE_CONNECTED] =
+ AUL_K_JOB_TRIG_GPS_STATE_CONNECTED,
+ [JOB_TRIGGER_EVENT_POWERSAVE_MODE_ENABLED] =
+ AUL_K_JOB_TRIG_POWERSAVE_MODE_ENABLED,
+ [JOB_TRIGGER_EVENT_POWERSAVE_MODE_DISABLED] =
+ AUL_K_JOB_TRIG_POWERSAVE_MODE_DISABLED,
+ [JOB_TRIGGER_EVENT_USB_STATE_CONNECTED] =
+ AUL_K_JOB_TRIG_USB_STATE_CONNECTED,
+ [JOB_TRIGGER_EVENT_USB_STATE_DISCONNECTED] =
+ AUL_K_JOB_TRIG_USB_STATE_DISCONNECTED,
+ [JOB_TRIGGER_EVENT_WIFI_STATE_DISABLED] =
+ AUL_K_JOB_TRIG_WIFI_STATE_DISABLED,
+ [JOB_TRIGGER_EVENT_WIFI_STATE_DISCONNECTED] =
+ AUL_K_JOB_TRIG_WIFI_STATE_DISCONNECTED,
+ [JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED] =
+ AUL_K_JOB_TRIG_WIFI_STATE_CONNECTED,
+ };
+
+ val = bundle_get_val(b, AUL_K_JOB_PERIODIC);
+ if (val && isdigit(*val))
+ job_info->interval = strtoul(val, NULL, 10);
+
+ val = bundle_get_val(b, AUL_K_JOB_PERSISTENT);
+ if (val)
+ job_info->persistent = true;
+
+ val = bundle_get_val(b, AUL_K_JOB_IS_ONCE);
+ if (val)
+ job_info->once = true;
+
+ val = bundle_get_val(b, AUL_K_JOB_REQ_TIMEOUT);
+ if (val && isdigit(*val))
+ job_info->timeout = strtoul(val, NULL, 10);
+
+ val = bundle_get_val(b, AUL_K_JOB_REQ_BATTERY_NOT_LOW);
+ __set_requires_value(val, &job_info->battery_not_low);
+
+ val = bundle_get_val(b, AUL_K_JOB_REQ_CHARGING);
+ __set_requires_value(val, &job_info->charging);
+
+ val = bundle_get_val(b, AUL_K_JOB_REQ_WIFI_CONNECTION);
+ __set_requires_value(val, &job_info->wifi_connection);
+
+ for (i = 0; i < ARRAY_SIZE(key_list); ++i) {
+ val = bundle_get_val(b, key_list[i]);
+ if (val)
+ job_info->trigger_list[i] = true;
+ }
+}
+
+int job_info_create_with_bundle(bundle *b, job_info_h *job_info)
+{
+ struct job_info_s *info;
+
+ if (b == NULL || job_info == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ info = calloc(1, sizeof(struct job_info_s));
+ if (info == NULL) {
+ return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ __set_job_info(info, b);
+
+ *job_info = info;
+
+ return JOB_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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_APPFW_JOB_INFO_PRIVATE_H__
+#define __TIZEN_APPFW_JOB_INFO_PRIVATE_H__
+
+#include <job_scheduler_internal.h>
+#include <bundle_internal.h>
+
+#include "job_info.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int job_info_create_with_bundle(bundle *b, job_info_h *job_info);
+
+int job_info_set_job_id(job_info_h job_info, const char *job_id);
+
+int job_info_get_periodic(job_info_h job_info, unsigned int *periodic);
+
+int job_info_get_persistent(job_info_h job_info, bool *persistent);
+
+int job_info_is_once(job_info_h job_info, bool *once);
+
+int job_info_get_requirement_timeout(job_info_h job_info,
+ unsigned int *timeout);
+
+int job_info_is_requires_battery_not_low(job_info_h job_info,
+ int *battery_not_low);
+
+int job_info_is_requires_charging(job_info_h job_info, int *charging);
+
+int job_info_is_requires_wifi_connection(job_info_h job_info,
+ int *wifi_connection);
+
+/* The type of the trigger_list is (bool (*)[JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED]) */
+int job_info_get_trigger_list(job_info_h job_info, bool **trigger_list);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_JOB_INFO_PRIVATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 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 _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
+#include <aul.h>
+#include <aul_svc.h>
+#include <aul_job_scheduler.h>
+#include <bundle_internal.h>
+#include <job_scheduler_internal.h>
+#include <job_scheduler_types_internal.h>
+#include <app_common.h>
+#include <service_app_internal.h>
+#include <cynara-creds-self.h>
+#include <cynara-session.h>
+#include <cynara-client.h>
+
+#include "job_error_private.h"
+#include "job_info_private.h"
+#include "job_scheduler.h"
+
+#ifdef API
+#undef API
+#endif
+
+#define API __attribute__((visibility("default")))
+
+#define ARRAY_SIZE(x) ((sizeof(x)) / (sizeof(x[0])))
+
+typedef int (*job_add_cb)(ctx_sched_job_h job, job_info_h job_info,
+ void *data);
+
+enum attr_type_e {
+ ATTR_TYPE_STRING,
+ ATTR_TYPE_INTEGER,
+};
+
+struct job_service_s {
+ service_app_job_h handle;
+ job_service_callback_s callback;
+ void *user_data;
+};
+
+struct job_scheduler_s {
+ char *app_id;
+ ctx_sched_h scheduler;
+ GHashTable *job_id_table;
+ GList *job_service_list;
+ bool initialized;
+};
+
+struct job_trigger_map_s {
+ const char *key;
+ const char *uri;
+ const char *attr_name;
+ int attr_type;
+ void *attr_value;
+};
+
+struct job_cynara_s {
+ cynara *handle;
+ char *client;
+ char *user;
+ char *session;
+ bool initialized;
+};
+
+static struct job_cynara_s __cynara;
+static struct job_scheduler_s __handle;
+static struct job_trigger_map_s job_trigger_map[] = {
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_EMPTY] = {
+ .key = AUL_K_JOB_TRIG_BATTERY_LEVEL_EMPTY,
+ .uri = CTX_SCHED_URI_BATTERY,
+ .attr_name = CTX_SCHED_ATTR_NAME_LEVEL,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_EMPTY
+ },
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_CRITICAL] = {
+ .key = AUL_K_JOB_TRIG_BATTERY_LEVEL_CRITICAL,
+ .uri = CTX_SCHED_URI_BATTERY,
+ .attr_name = CTX_SCHED_ATTR_NAME_LEVEL,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_CRITICAL
+ },
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_LOW] = {
+ .key = AUL_K_JOB_TRIG_BATTERY_LEVEL_LOW,
+ .uri = CTX_SCHED_URI_BATTERY,
+ .attr_name = CTX_SCHED_ATTR_NAME_LEVEL,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_LOW
+ },
+ [JOB_TRIGGER_EVENT_BATTERY_LEVEL_HIGH] = {
+ .key = AUL_K_JOB_TRIG_BATTERY_LEVEL_HIGH,
+ .uri = CTX_SCHED_URI_BATTERY,
+ .attr_name = CTX_SCHED_ATTR_NAME_LEVEL,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_HIGH
+ },
+ [JOB_TRIGGER_EVENT_CHARGER_STATE_CONNECTED] = {
+ .key = AUL_K_JOB_TRIG_CHARGER_STATE_CONNECTED,
+ .uri = CTX_SCHED_URI_CHARGER,
+ .attr_name = CTX_SCHED_ATTR_NAME_IS_CONNECTED,
+ .attr_type = ATTR_TYPE_INTEGER,
+ .attr_value = GINT_TO_POINTER(CTX_SCHED_ATTR_VALUE_TRUE)
+ },
+ [JOB_TRIGGER_EVENT_CHARGER_STATE_DISCONNECTED] = {
+ .key = AUL_K_JOB_TRIG_CHARGER_STATE_DISCONNECTED,
+ .uri = CTX_SCHED_URI_CHARGER,
+ .attr_name = CTX_SCHED_ATTR_NAME_IS_CONNECTED,
+ .attr_type = ATTR_TYPE_INTEGER,
+ .attr_value = CTX_SCHED_ATTR_VALUE_FALSE
+ },
+ [JOB_TRIGGER_EVENT_DISPLAY_STATE_ON] = {
+ .key = AUL_K_JOB_TRIG_DISPLAY_STATE_ON,
+ .uri = CTX_SCHED_URI_DISPLAY,
+ .attr_name = CTX_SCHED_ATTR_NAME_STATE,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_ON
+ },
+ [JOB_TRIGGER_EVENT_DISPLAY_STATE_OFF] = {
+ .key = AUL_K_JOB_TRIG_DISPLAY_STATE_OFF,
+ .uri = CTX_SCHED_URI_DISPLAY,
+ .attr_name = CTX_SCHED_ATTR_NAME_STATE,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_OFF
+ },
+ [JOB_TRIGGER_EVENT_DISPLAY_STATE_DIM] = {
+ .key = AUL_K_JOB_TRIG_DISPLAY_STATE_DIM,
+ .uri = CTX_SCHED_URI_DISPLAY,
+ .attr_name = CTX_SCHED_ATTR_NAME_STATE,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_DIM
+ },
+ [JOB_TRIGGER_EVENT_EARJACK_STATE_CONNECTED] = {
+ .key = AUL_K_JOB_TRIG_EARJACK_STATE_CONNECTED,
+ .uri = CTX_SCHED_URI_EARJACK,
+ .attr_name = CTX_SCHED_ATTR_NAME_IS_CONNECTED,
+ .attr_type = ATTR_TYPE_INTEGER,
+ .attr_value = GINT_TO_POINTER(CTX_SCHED_ATTR_VALUE_TRUE)
+ },
+ [JOB_TRIGGER_EVENT_EARJACK_STATE_DISCONNECTED] = {
+ .key = AUL_K_JOB_TRIG_EARJACK_STATE_DISCONNECTED,
+ .uri = CTX_SCHED_URI_EARJACK,
+ .attr_name = CTX_SCHED_ATTR_NAME_IS_CONNECTED,
+ .attr_type = ATTR_TYPE_INTEGER,
+ .attr_value = CTX_SCHED_ATTR_VALUE_FALSE
+ },
+ [JOB_TRIGGER_EVENT_GPS_STATE_DISABLED] = {
+ .key = AUL_K_JOB_TRIG_GPS_STATE_DISABLED,
+ .uri = CTX_SCHED_URI_GPS,
+ .attr_name = CTX_SCHED_ATTR_NAME_STATE,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_DISABLED
+ },
+ [JOB_TRIGGER_EVENT_GPS_STATE_SEARCHING] = {
+ .key = AUL_K_JOB_TRIG_GPS_STATE_SEARCHING,
+ .uri = CTX_SCHED_URI_GPS,
+ .attr_name = CTX_SCHED_ATTR_NAME_STATE,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_SEARCHING
+ },
+ [JOB_TRIGGER_EVENT_GPS_STATE_CONNECTED] = {
+ .key = AUL_K_JOB_TRIG_GPS_STATE_CONNECTED,
+ .uri = CTX_SCHED_URI_GPS,
+ .attr_name = CTX_SCHED_ATTR_NAME_STATE,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_CONNECTED
+ },
+ [JOB_TRIGGER_EVENT_POWERSAVE_MODE_ENABLED] = {
+ .key = AUL_K_JOB_TRIG_POWERSAVE_MODE_ENABLED,
+ .uri = CTX_SCHED_URI_POWERSAVE,
+ .attr_name = CTX_SCHED_ATTR_NAME_IS_ENABLED,
+ .attr_type = ATTR_TYPE_INTEGER,
+ .attr_value = GINT_TO_POINTER(CTX_SCHED_ATTR_VALUE_TRUE)
+ },
+ [JOB_TRIGGER_EVENT_POWERSAVE_MODE_DISABLED] = {
+ .key = AUL_K_JOB_TRIG_POWERSAVE_MODE_DISABLED,
+ .uri = CTX_SCHED_URI_POWERSAVE,
+ .attr_name = CTX_SCHED_ATTR_NAME_IS_ENABLED,
+ .attr_type = ATTR_TYPE_INTEGER,
+ .attr_value = CTX_SCHED_ATTR_VALUE_FALSE
+ },
+ [JOB_TRIGGER_EVENT_USB_STATE_CONNECTED] = {
+ .key = AUL_K_JOB_TRIG_USB_STATE_CONNECTED,
+ .uri = CTX_SCHED_URI_USB,
+ .attr_name = CTX_SCHED_ATTR_NAME_IS_CONNECTED,
+ .attr_type = ATTR_TYPE_INTEGER,
+ .attr_value = GINT_TO_POINTER(CTX_SCHED_ATTR_VALUE_TRUE)
+ },
+ [JOB_TRIGGER_EVENT_USB_STATE_DISCONNECTED] = {
+ .key = AUL_K_JOB_TRIG_USB_STATE_DISCONNECTED,
+ .uri = CTX_SCHED_URI_USB,
+ .attr_name = CTX_SCHED_ATTR_NAME_IS_CONNECTED,
+ .attr_type = ATTR_TYPE_INTEGER,
+ .attr_value = CTX_SCHED_ATTR_VALUE_FALSE
+ },
+ [JOB_TRIGGER_EVENT_WIFI_STATE_DISABLED] = {
+ .key = AUL_K_JOB_TRIG_WIFI_STATE_DISABLED,
+ .uri = CTX_SCHED_URI_WIFI,
+ .attr_name = CTX_SCHED_ATTR_NAME_STATE,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_DISABLED
+ },
+ [JOB_TRIGGER_EVENT_WIFI_STATE_DISCONNECTED] = {
+ .key = AUL_K_JOB_TRIG_WIFI_STATE_DISCONNECTED,
+ .uri = CTX_SCHED_URI_WIFI,
+ .attr_name = CTX_SCHED_ATTR_NAME_STATE,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_UNCONNECTED
+ },
+ [JOB_TRIGGER_EVENT_WIFI_STATE_CONNECTED] = {
+ .key = AUL_K_JOB_TRIG_WIFI_STATE_CONNECTED,
+ .uri = CTX_SCHED_URI_WIFI,
+ .attr_name = CTX_SCHED_ATTR_NAME_STATE,
+ .attr_type = ATTR_TYPE_STRING,
+ .attr_value = CTX_SCHED_ATTR_VALUE_CONNECTED
+ },
+};
+
+static void __destroy_job_service(gpointer data);
+static void __finish_cynara(void);
+
+static bundle *__get_bundle_from_job(ctx_sched_job_h job)
+{
+ bundle *b;
+ bundle_raw *b_raw = NULL;
+ size_t len = 0;
+ int r;
+
+ r = ctx_sched_job_get_user_data(job, (char **)&b_raw, &len);
+ if (r != 0) {
+ _E("Failed to get user data");
+ return NULL;
+ }
+
+ b = bundle_decode(b_raw, len);
+ if (b == NULL)
+ _E("Failed to decode bundle raw(%s)", b_raw);
+
+ free(b_raw);
+
+ return b;
+}
+
+static void __add_job(ctx_sched_job_h job)
+{
+ bundle *b = NULL;
+ const char *app_id;
+ const char *job_id;
+ int id = 0;
+ int r;
+
+ b = __get_bundle_from_job(job);
+ if (b == NULL)
+ return;
+
+ app_id = aul_svc_get_appid(b);
+ if (app_id == NULL || strcmp(app_id, __handle.app_id) != 0)
+ goto end;
+
+ job_id = bundle_get_val(b, AUL_K_JOB_ID);
+ if (job_id == NULL)
+ goto end;
+
+ r = ctx_sched_job_get_id(job, &id);
+ if (r != 0)
+ goto end;
+
+ if (g_hash_table_contains(__handle.job_id_table, job_id)) {
+ g_hash_table_replace(__handle.job_id_table, strdup(job_id),
+ GINT_TO_POINTER(id));
+ } else {
+ g_hash_table_insert(__handle.job_id_table, strdup(job_id),
+ GINT_TO_POINTER(id));
+ }
+
+end:
+ if (b)
+ bundle_free(b);
+}
+
+static bool __foreach_job_cb(ctx_sched_h scheduler, ctx_sched_job_h job,
+ void *user_data)
+{
+ __add_job(job);
+ ctx_sched_job_destroy(job);
+ return true;
+}
+
+static void __start_job_cb(ctx_sched_h scheduler, ctx_sched_job_h job,
+ bool timeout, void *user_data)
+{
+ bundle *b;
+ const char *job_id;
+
+ _D("[__JOB__] Start Job");
+
+ b = __get_bundle_from_job(job);
+ if (b == NULL) {
+ ctx_sched_job_destroy(job);
+ return;
+ }
+
+ job_id = bundle_get_val(b, AUL_K_JOB_ID);
+ if (job_id == NULL) {
+ ctx_sched_job_destroy(job);
+ bundle_free(b);
+ return;
+ }
+
+ if (!g_hash_table_contains(__handle.job_id_table, job_id))
+ __add_job(job);
+
+ service_app_job_raise(SERVICE_APP_JOB_STATUS_START, job_id, b);
+ ctx_sched_job_destroy(job);
+ bundle_free(b);
+}
+
+static void __stop_job_cb(ctx_sched_h scheduler, ctx_sched_job_h job,
+ void *user_data)
+{
+ bundle *b;
+ const char *job_id;
+
+ _D("[__JOB__] Stop Job");
+
+ b = __get_bundle_from_job(job);
+ if (b == NULL) {
+ ctx_sched_job_destroy(job);
+ return;
+ }
+
+ job_id = bundle_get_val(b, AUL_K_JOB_ID);
+ if (job_id == NULL) {
+ ctx_sched_job_destroy(job);
+ bundle_free(b);
+ return;
+ }
+
+ service_app_job_raise(SERVICE_APP_JOB_STATUS_STOP, job_id, b);
+ ctx_sched_job_destroy(job);
+ bundle_free(b);
+}
+
+static int __init_scheduler(ctx_sched_h *scheduler)
+{
+ ctx_sched_h handle = NULL;
+ int r;
+
+ r = ctx_sched_create(&handle);
+ if (r != 0)
+ return r;
+
+ r = ctx_sched_foreach_job(handle, __foreach_job_cb, NULL);
+ if (r != 0 && r != TIZEN_ERROR_NO_DATA) {
+ ctx_sched_destroy(handle);
+ return r;
+ }
+
+ r = ctx_sched_set_job_cb(handle, __start_job_cb, __stop_job_cb, NULL);
+ if (r != 0) {
+ ctx_sched_destroy(handle);
+ return r;
+ }
+
+ *scheduler = handle;
+
+ return 0;
+}
+
+API int job_scheduler_init(void)
+{
+ int r;
+
+ if (__handle.initialized)
+ return JOB_ERROR_NONE;
+
+ r = app_get_id(&__handle.app_id);
+ if (r != APP_ERROR_NONE) {
+ return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ __handle.job_id_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+ free, NULL);
+ if (__handle.job_id_table == NULL) {
+ free(__handle.app_id);
+ return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = __init_scheduler(&__handle.scheduler);
+ if (r != 0) {
+ g_hash_table_destroy(__handle.job_id_table);
+ free(__handle.app_id);
+ return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ __handle.initialized = true;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_scheduler_finish(void)
+{
+ if (!__handle.initialized)
+ return JOB_ERROR_NOT_INITIALIZED;
+
+ if (__handle.job_service_list) {
+ g_list_free_full(__handle.job_service_list,
+ __destroy_job_service);
+ __handle.job_service_list = NULL;
+ }
+
+ if (__handle.job_id_table) {
+ g_hash_table_destroy(__handle.job_id_table);
+ __handle.job_id_table = NULL;
+ }
+
+ if (__handle.scheduler) {
+ ctx_sched_destroy(__handle.scheduler);
+ __handle.scheduler = NULL;
+
+ }
+
+ if (__handle.app_id) {
+ free(__handle.app_id);
+ __handle.app_id = NULL;
+ }
+
+ __finish_cynara();
+
+ __handle.initialized = false;
+
+ return JOB_ERROR_NONE;
+}
+
+static int __job_add_app_control(ctx_sched_job_h job, job_info_h job_info,
+ void *user_data)
+{
+ bundle *b = (bundle *)user_data;
+ int r;
+
+ r = aul_svc_set_operation(b, AUL_SVC_OPERATION_DEFAULT);
+ if (r != AUL_SVC_RET_OK) {
+ _E("Failed to set operation");
+ return JOB_ERROR_OUT_OF_MEMORY;
+ }
+
+ r = aul_svc_set_appid(b, __handle.app_id);
+ if (r != AUL_SVC_RET_OK) {
+ _E("Failed to add appid(%s)", __handle.app_id);
+ return JOB_ERROR_OUT_OF_MEMORY;
+ }
+
+ r = ctx_sched_job_set_app_control(job, b);
+ if (r != 0) {
+ _E("Failed to set app control (%d)", r);
+ return JOB_ERROR_IO_ERROR;
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+static int __job_add_user_data(ctx_sched_job_h job, job_info_h job_info,
+ void *user_data)
+{
+ bundle *b = (bundle *)user_data;
+ bundle_raw *b_raw = NULL;
+ int len = 0;
+ int r;
+
+ r = bundle_encode(b, &b_raw, &len);
+ if (r != BUNDLE_ERROR_NONE) {
+ _E("Failed to encode bundle");
+ return JOB_ERROR_IO_ERROR;
+ }
+
+ r = ctx_sched_job_set_user_data(job, (const char *)b_raw, len);
+ if (r != 0) {
+ _E("Failed to set user data");
+ free(b_raw);
+ return JOB_ERROR_IO_ERROR;
+ }
+ free(b_raw);
+
+ return JOB_ERROR_NONE;
+}
+
+static int __get_id(const char *job_id)
+{
+ gpointer id;
+
+ id = g_hash_table_lookup(__handle.job_id_table, job_id);
+ if (id == NULL)
+ return -1;
+
+ return GPOINTER_TO_INT(id);
+}
+
+static bool __exist_job(const char *job_id)
+{
+ ctx_sched_job_h job = NULL;
+ int id;
+ int r;
+
+ id = __get_id(job_id);
+ if (id < 0)
+ return false;
+
+ r = ctx_sched_get_job(__handle.scheduler, id, &job);
+ if (r != 0) {
+ g_hash_table_remove(__handle.job_id_table, job_id);
+ return false;
+ }
+
+ ctx_sched_job_destroy(job);
+
+ return true;
+}
+
+static int __job_add_persistent(ctx_sched_job_h job, job_info_h job_info,
+ void *data)
+{
+ bundle *b = (bundle *)data;
+ bool persistent = false;
+ int r;
+
+ r = job_info_get_persistent(job_info, &persistent);
+ if (r != JOB_ERROR_NONE)
+ return r;
+
+ r = ctx_sched_job_set_persistent(job, persistent);
+ if (r != 0) {
+ _E("Failed to set persistent (%d)", r);
+ return r;
+ }
+
+ if (persistent)
+ bundle_add(b, AUL_K_JOB_PERSISTENT, "true");
+
+ return JOB_ERROR_NONE;
+}
+
+static int __job_add_one_time(ctx_sched_job_h job, job_info_h job_info,
+ void *data)
+{
+ bundle *b = (bundle *)data;
+ bool once = false;
+ int r;
+
+ r = job_info_is_once(job_info, &once);
+ if (r != JOB_ERROR_NONE)
+ return r;
+
+ r = ctx_sched_job_set_one_time(job, once);
+ if (r != 0) {
+ _E("Failed to set one time (%d)", r);
+ return r;
+ }
+
+ if (once)
+ bundle_add(b, AUL_K_JOB_IS_ONCE, "true");
+
+ return JOB_ERROR_NONE;
+}
+
+static int __job_add_requirement_timeout(ctx_sched_job_h job,
+ job_info_h job_info, void *data)
+{
+ bundle *b = (bundle *)data;
+ unsigned int timeout = 0;
+ char buf[32];
+ int r;
+
+ r = job_info_get_requirement_timeout(job_info, &timeout);
+ if (r != JOB_ERROR_NONE)
+ return r;
+
+ r = ctx_sched_job_set_requirement_timeout(job, timeout);
+ if (r != 0) {
+ _E("Failed to set requirement timeout (%d)", r);
+ return r;
+ }
+
+ if (timeout) {
+ snprintf(buf, sizeof(buf), "%u", timeout);
+ bundle_add(b, AUL_K_JOB_REQ_TIMEOUT, buf);
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+static int __add_str_attr_ne(ctx_sched_job_context_h context,
+ const char *name, const char *value)
+{
+ int r;
+
+ r = ctx_sched_job_context_prepare_attribute_str(context, name);
+ if (r != 0) {
+ _E("Failed to prepare string attribute(%s) - %d", name, r);
+ return r;
+ }
+
+ r = ctx_sched_job_context_attribute_add_ne_str(context, name, value);
+ if (r != 0) {
+ _E("Failed to add string value(%s) - %d", value, r);
+ return r;
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+static int __add_str_attr_eq(ctx_sched_job_context_h context,
+ const char *name, const char *value)
+{
+ int r;
+
+ r = ctx_sched_job_context_prepare_attribute_str(context, name);
+ if (r != 0) {
+ _E("Failed to prepare string attribute(%s) - %d", name, r);
+ return r;
+ }
+
+ r = ctx_sched_job_context_attribute_add_eq_str(context, name, value);
+ if (r != 0) {
+ _E("Failed to add string value(%s) - %d", value, r);
+ return r;
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+static int __add_int_attr_eq(ctx_sched_job_context_h context,
+ const char *name, int value)
+{
+ int r;
+
+ r = ctx_sched_job_context_prepare_attribute_int(context, name);
+ if (r != 0) {
+ _E("Failed to prepare integer attribute(%s) - %d", name, r);
+ return r;
+ }
+
+ r = ctx_sched_job_context_attribute_add_eq_int(context, name, value);
+ if (r != 0) {
+ _E("Failed to add integer value(%s) - %d", value, r);
+ return r;
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+static int __job_add_requires_battery_not_low(ctx_sched_job_h job,
+ job_info_h job_info, void *data)
+{
+ bundle *b = (bundle *)data;
+ ctx_sched_job_context_h requirement = NULL;
+ int battery_not_low = -1;
+ int r;
+
+ r = job_info_is_requires_battery_not_low(job_info, &battery_not_low);
+ if (r != JOB_ERROR_NONE)
+ return r;
+
+ if (battery_not_low == -1)
+ return JOB_ERROR_NONE;
+
+ r = ctx_sched_job_requirement_create(CTX_SCHED_URI_BATTERY, false,
+ &requirement);
+ if (r != 0) {
+ _E("Failed to create requirement (%d)", r);
+ return r;
+ }
+
+ if (battery_not_low) {
+ r = __add_str_attr_eq(requirement, CTX_SCHED_ATTR_NAME_LEVEL,
+ CTX_SCHED_ATTR_VALUE_HIGH);
+ } else {
+ r = __add_str_attr_ne(requirement, CTX_SCHED_ATTR_NAME_LEVEL,
+ CTX_SCHED_ATTR_VALUE_HIGH);
+ }
+ if (r != JOB_ERROR_NONE) {
+ ctx_sched_job_context_destroy(requirement);
+ return r;
+ }
+
+ r = ctx_sched_job_add_requirement(job, requirement);
+ if (r != 0) {
+ _E("Failed to add requirement (%d)", r);
+ ctx_sched_job_context_destroy(requirement);
+ return r;
+ }
+
+ if (battery_not_low)
+ bundle_add(b, AUL_K_JOB_REQ_BATTERY_NOT_LOW, "true");
+ else
+ bundle_add(b, AUL_K_JOB_REQ_BATTERY_NOT_LOW, "false");
+
+ return JOB_ERROR_NONE;
+}
+
+static int __job_add_requires_charging(ctx_sched_job_h job,
+ job_info_h job_info, void *data)
+{
+ bundle *b = (bundle *)data;
+ ctx_sched_job_context_h requirement = NULL;
+ int charging = -1;
+ int r;
+
+ r = job_info_is_requires_charging(job_info, &charging);
+ if (r != JOB_ERROR_NONE)
+ return r;
+
+ if (charging == -1)
+ return JOB_ERROR_NONE;
+
+ r = ctx_sched_job_requirement_create(CTX_SCHED_URI_BATTERY, false,
+ &requirement);
+ if (r != 0) {
+ _E("Failed to create requirement (%d)", r);
+ return r;
+ }
+
+ r = __add_int_attr_eq(requirement, CTX_SCHED_ATTR_NAME_IS_CHARGING,
+ charging);
+ if (r != JOB_ERROR_NONE) {
+ ctx_sched_job_context_destroy(requirement);
+ return r;
+ }
+
+ r = ctx_sched_job_add_requirement(job, requirement);
+ if (r != 0) {
+ _E("Failed to add requirement (%d)", r);
+ ctx_sched_job_context_destroy(requirement);
+ return r;
+ }
+
+ if (charging)
+ bundle_add(b, AUL_K_JOB_REQ_CHARGING, "true");
+ else
+ bundle_add(b, AUL_K_JOB_REQ_CHARGING, "false");
+
+ return JOB_ERROR_NONE;
+}
+
+static int __job_add_requires_wifi_connection(ctx_sched_job_h job,
+ job_info_h job_info, void *data)
+{
+ bundle *b = (bundle *)data;
+ ctx_sched_job_context_h requirement = NULL;
+ int wifi_connection = -1;
+ int r;
+
+ r = job_info_is_requires_wifi_connection(job_info, &wifi_connection);
+ if (r != JOB_ERROR_NONE)
+ return r;
+
+ if (wifi_connection == -1)
+ return JOB_ERROR_NONE;
+
+ r = ctx_sched_job_requirement_create(CTX_SCHED_URI_WIFI, false,
+ &requirement);
+ if (r != 0) {
+ _E("Failed to create requirement (%d)", r);
+ return r;
+ }
+
+ if (wifi_connection) {
+ r = __add_str_attr_eq(requirement, CTX_SCHED_ATTR_NAME_STATE,
+ CTX_SCHED_ATTR_VALUE_CONNECTED);
+ } else {
+ r = __add_str_attr_ne(requirement, CTX_SCHED_ATTR_NAME_STATE,
+ CTX_SCHED_ATTR_VALUE_CONNECTED);
+ }
+ if (r != JOB_ERROR_NONE) {
+ ctx_sched_job_context_destroy(requirement);
+ return r;
+ }
+
+ r = ctx_sched_job_add_requirement(job, requirement);
+ if (r != 0) {
+ _E("Failed to add requirement (%d)", r);
+ ctx_sched_job_context_destroy(requirement);
+ return r;
+ }
+
+ if (wifi_connection)
+ bundle_add(b, AUL_K_JOB_REQ_WIFI_CONNECTION, "true");
+ else
+ bundle_add(b, AUL_K_JOB_REQ_WIFI_CONNECTION, "false");
+
+ return JOB_ERROR_NONE;
+}
+
+static int __add_trigger_event(ctx_sched_job_h job, job_trigger_event_e event,
+ bundle *b)
+{
+ ctx_sched_job_context_h trigger = NULL;
+ int r;
+
+ r = ctx_sched_job_trigger_create(job_trigger_map[event].uri,
+ &trigger);
+ if (r != 0) {
+ _E("Failed to create trigger (%d)", r);
+ return r;
+ }
+
+ if (job_trigger_map[event].attr_type == ATTR_TYPE_INTEGER) {
+ r = __add_int_attr_eq(trigger, job_trigger_map[event].attr_name,
+ GPOINTER_TO_INT(job_trigger_map[event].attr_value));
+ } else {
+ r = __add_str_attr_eq(trigger, job_trigger_map[event].attr_name,
+ (const char *)job_trigger_map[event].attr_value);
+ }
+ if (r != JOB_ERROR_NONE) {
+ ctx_sched_job_context_destroy(trigger);
+ return r;
+ }
+
+ r = ctx_sched_job_add_trigger(job, trigger);
+ if (r != 0) {
+ _E("Failed to add trigger (%d)", r);
+ ctx_sched_job_context_destroy(trigger);
+ return r;
+ }
+
+ bundle_add(b, job_trigger_map[event].key, "true");
+
+ return JOB_ERROR_NONE;
+}
+
+static int __job_add_trigger_events(ctx_sched_job_h job,
+ job_info_h job_info, void *data)
+{
+ bundle *b = (bundle *)data;
+ bool *trigger_list = NULL;
+ unsigned int interval = 0;
+ int i;
+ int r;
+
+ job_info_get_periodic(job_info, &interval);
+ if (interval != 0)
+ return JOB_ERROR_NONE;
+
+ r = job_info_get_trigger_list(job_info, &trigger_list);
+ if (r != JOB_ERROR_NONE)
+ return r;
+
+ for (i = 0; i < ARRAY_SIZE(job_trigger_map); ++i) {
+ if (trigger_list[i]) {
+ _D("[%d] true", i);
+ r = __add_trigger_event(job, i, b);
+ if (r != JOB_ERROR_NONE)
+ return r;
+ }
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+static job_add_cb job_constructor[] = {
+ __job_add_persistent,
+ __job_add_one_time,
+ __job_add_requirement_timeout,
+ __job_add_requires_battery_not_low,
+ __job_add_requires_charging,
+ __job_add_requires_wifi_connection,
+ __job_add_trigger_events,
+ __job_add_app_control,
+ __job_add_user_data,
+};
+
+static ctx_sched_job_h __create_job(job_info_h job_info, const char *job_id)
+{
+ unsigned int interval = 0;
+ ctx_sched_job_h job = NULL;
+ char buf[32];
+ bundle *b;
+ int i;
+ int r;
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("Failed to create bundle");
+ return NULL;
+ }
+
+ r = bundle_add(b, AUL_K_JOB_ID, job_id);
+ if (r != BUNDLE_ERROR_NONE) {
+ _E("Failed to add job id(%s)", job_id);
+ bundle_free(b);
+ return NULL;
+ }
+
+ job_info_get_periodic(job_info, &interval);
+ if (interval == 0) {
+ r = ctx_sched_job_create_on_demand(&job);
+ } else {
+ snprintf(buf, sizeof(buf), "%u", interval);
+ bundle_add(b, AUL_K_JOB_PERIODIC, buf);
+ r = ctx_sched_job_create_periodic(interval, 0, &job);
+ }
+ if (r != 0) {
+ _E("Failed to create job (%d)", r);
+ bundle_free(b);
+ return NULL;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(job_constructor); ++i) {
+ if (job_constructor[i]) {
+ r = job_constructor[i](job, job_info, b);
+ if (r != JOB_ERROR_NONE) {
+ ctx_sched_job_destroy(job);
+ bundle_free(b);
+ return NULL;
+ }
+ }
+ }
+ bundle_free(b);
+
+ return job;
+}
+
+API int job_scheduler_schedule(job_info_h job_info, const char *job_id)
+{
+ ctx_sched_job_h job;
+ int id = 0;
+ int r;
+
+ if (job_info == NULL || job_id == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!__handle.initialized) {
+ return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (__exist_job(job_id)) {
+ return job_error(JOB_ERROR_ALREADY_EXIST, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ job = __create_job(job_info, job_id);
+ if (job == NULL) {
+ return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = job_info_set_job_id(job_info, job_id);
+ if (r != JOB_ERROR_NONE) {
+ ctx_sched_job_destroy(job);
+ return job_error(r, __FUNCTION__, __LINE__, NULL);
+ }
+
+ r = ctx_sched_schedule(__handle.scheduler, job, &id);
+ if (r != 0) {
+ ctx_sched_job_destroy(job);
+ if (r == JOB_ERROR_PERMISSION_DENIED) {
+ return job_error(JOB_ERROR_PERMISSION_DENIED,
+ __FUNCTION__, __LINE__, NULL);
+ } else {
+ return job_error(JOB_ERROR_IO_ERROR,
+ __FUNCTION__, __LINE__, NULL);
+ }
+ }
+ ctx_sched_job_destroy(job);
+ g_hash_table_insert(__handle.job_id_table, strdup(job_id),
+ GINT_TO_POINTER(id));
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_scheduler_cancel(const char *job_id)
+{
+ int id;
+ int r;
+
+ if (job_id == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!__handle.initialized) {
+ return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ id = __get_id(job_id);
+ if (id < 0) {
+ return job_error(JOB_ERROR_NO_SUCH_JOB, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = ctx_sched_cancel(__handle.scheduler, id);
+ if (r != 0) {
+ return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ g_hash_table_remove(__handle.job_id_table, job_id);
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_scheduler_cancel_all(void)
+{
+ int r;
+
+ if (!__handle.initialized) {
+ return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = ctx_sched_cancel_all(__handle.scheduler);
+ if (r != 0) {
+ return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ g_hash_table_remove_all(__handle.job_id_table);
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_scheduler_notify_job_finished(const char *job_id)
+{
+ int id;
+ int r;
+
+ if (job_id == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!__handle.initialized) {
+ return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ id = __get_id(job_id);
+ if (id < 0) {
+ return job_error(JOB_ERROR_NO_SUCH_JOB, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = ctx_sched_job_finished(__handle.scheduler, id);
+ if (r != 0) {
+ return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = service_app_job_finished(job_id);
+ if (r != 0) {
+ return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+static void __foreach_job_id_cb(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ const char *job_id = (const char *)key;
+ int id = GPOINTER_TO_INT(value);
+ GList **list = (GList **)user_data;
+ ctx_sched_job_h job = NULL;
+ job_info_h job_info = NULL;
+ bundle *b;
+ int r;
+
+ r = ctx_sched_get_job(__handle.scheduler, id, &job);
+ if (r != 0) {
+ _E("Failed to get job from job id(%s:%d)", job_id, id);
+ return;
+ }
+
+ b = __get_bundle_from_job(job);
+ if (b == NULL) {
+ ctx_sched_job_destroy(job);
+ return;
+ }
+ ctx_sched_job_destroy(job);
+
+ r = job_info_create_with_bundle(b, &job_info);
+ if (r != JOB_ERROR_NONE) {
+ bundle_free(b);
+ return;
+ }
+ bundle_free(b);
+
+ r = job_info_set_job_id(job_info, job_id);
+ if (r != JOB_ERROR_NONE) {
+ job_info_destroy(job_info);
+ return;
+ }
+
+ *list = g_list_append(*list, job_info);
+}
+
+API int job_scheduler_foreach_job(job_scheduler_foreach_job_cb callback,
+ void *user_data)
+{
+ job_info_h job_info;
+ GList *list = NULL;
+ GList *iter;
+
+ if (callback == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!__handle.initialized) {
+ return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ g_hash_table_foreach(__handle.job_id_table, __foreach_job_id_cb, &list);
+
+ if (list == NULL) {
+ return job_error(JOB_ERROR_NO_SUCH_JOB, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ iter = list;
+ while (iter) {
+ job_info = (job_info_h)iter->data;
+ iter = iter->next;
+ if (!callback(job_info, user_data))
+ break;
+ }
+
+ g_list_free_full(list, (GDestroyNotify)job_info_destroy);
+
+ return JOB_ERROR_NONE;
+}
+
+static int __job_service_cb(int event, const char *job_id, bundle *job_data,
+ void *user_data)
+{
+ struct job_service_s *handle = (struct job_service_s *)user_data;
+ job_info_h job_info = NULL;
+ int r;
+
+ r = job_info_create_with_bundle(job_data, &job_info);
+ if (r != JOB_ERROR_NONE)
+ return -1;
+
+ r = job_info_set_job_id(job_info, job_id);
+ if (r != JOB_ERROR_NONE) {
+ job_info_destroy(job_info);
+ return -1;
+ }
+
+ if (event == SERVICE_APP_JOB_STATUS_START)
+ handle->callback.start(job_info, handle->user_data);
+ else
+ handle->callback.stop(job_info, handle->user_data);
+
+ job_info_destroy(job_info);
+
+ return 0;
+}
+
+static struct job_service_s *__create_job_service(const char *job_id,
+ job_service_callback_s *callback, void *user_data)
+{
+ struct job_service_s *service;
+
+ service = calloc(1, sizeof(struct job_service_s));
+ if (service == NULL) {
+ _E("Out of memory");
+ return NULL;
+ }
+
+ service->handle = service_app_add_job_handler(job_id, __job_service_cb,
+ service);
+ if (service->handle == NULL) {
+ _E("Out of memory");
+ free(service);
+ return NULL;
+ }
+
+ service->callback = *callback;
+ service->user_data = user_data;
+
+ return service;
+}
+
+static void __destroy_job_service(gpointer data)
+{
+ struct job_service_s *service = (struct job_service_s *)data;
+
+ if (service == NULL)
+ return;
+
+ if (service->handle)
+ service_app_remove_job_handler(service->handle);
+
+ free(service);
+}
+
+API int job_scheduler_service_add(const char *job_id,
+ job_service_callback_s *callback, void *user_data,
+ job_service_h *job_service)
+{
+ struct job_service_s *service;
+
+ if (job_service == NULL || job_id == NULL || callback == NULL ||
+ callback->start == NULL || callback->stop == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!__handle.initialized) {
+ return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ service = __create_job_service(job_id, callback, user_data);
+ if (service == NULL) {
+ return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ __handle.job_service_list = g_list_append(__handle.job_service_list,
+ service);
+
+ *job_service = service;
+
+ return JOB_ERROR_NONE;
+}
+
+API int job_scheduler_service_remove(job_service_h job_service)
+{
+ gint index;
+
+ if (job_service == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ index = g_list_index(__handle.job_service_list, job_service);
+ if (index < 0) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!__handle.initialized) {
+ return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ __handle.job_service_list = g_list_remove(__handle.job_service_list,
+ job_service);
+
+ __destroy_job_service(job_service);
+
+ return JOB_ERROR_NONE;
+}
+
+int job_scheduler_verify_requirement(const char *uri)
+{
+ bool supported = false;
+ int r;
+
+ if (uri == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!__handle.initialized) {
+ return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = ctx_sched_job_requirement_is_supported(__handle.scheduler,
+ uri, &supported);
+ if (r != 0) {
+ return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!supported) {
+ return job_error(JOB_ERROR_NOT_SUPPORTED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+int job_scheduler_verify_trigger(const char *uri)
+{
+ bool supported = false;
+ int r;
+
+ if (uri == NULL) {
+ return job_error(JOB_ERROR_INVALID_PARAMETER, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!__handle.initialized) {
+ return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ r = ctx_sched_job_trigger_is_supported(__handle.scheduler,
+ uri, &supported);
+ if (r != 0) {
+ return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ if (!supported) {
+ return job_error(JOB_ERROR_NOT_SUPPORTED, __FUNCTION__,
+ __LINE__, NULL);
+ }
+
+ return JOB_ERROR_NONE;
+}
+
+static int __init_cynara(void)
+{
+ cynara_configuration *conf = NULL;
+ int r;
+
+ if (__cynara.initialized)
+ return 0;
+
+ r = cynara_creds_self_get_client(CLIENT_METHOD_DEFAULT,
+ &__cynara.client);
+ if (r != CYNARA_API_SUCCESS) {
+ _E("Failed to get client");
+ return -1;
+ }
+
+ r = cynara_creds_self_get_user(CLIENT_METHOD_DEFAULT, &__cynara.user);
+ if (r != CYNARA_API_SUCCESS) {
+ _E("Failed to get user");
+ goto err;
+ }
+
+ __cynara.session = cynara_session_from_pid(getpid());
+ if (__cynara.session == NULL) {
+ _E("Failed to get session");
+ goto err;
+ }
+
+ r = cynara_configuration_create(&conf);
+ if (r != CYNARA_API_SUCCESS) {
+ _E("Failed to create cynara configuration");
+ goto err;
+ }
+
+ r = cynara_configuration_set_cache_size(conf, 10);
+ if (r != CYNARA_API_SUCCESS) {
+ _E("Failed to set cache size");
+ goto err;
+ }
+
+ r = cynara_initialize(&__cynara.handle, conf);
+ cynara_configuration_destroy(conf);
+ conf = NULL;
+ if (r != CYNARA_API_SUCCESS) {
+ _E("Failed to initialize cynara");
+ goto err;
+ }
+
+ __cynara.initialized = true;
+
+ _I("Cynara initialized");
+
+ return 0;
+err:
+ if (conf)
+ cynara_configuration_destroy(conf);
+
+ if (__cynara.client) {
+ free(__cynara.client);
+ __cynara.client = NULL;
+ }
+
+ if (__cynara.user) {
+ free(__cynara.user);
+ __cynara.user = NULL;
+ }
+
+ if (__cynara.session) {
+ free(__cynara.session);
+ __cynara.session = NULL;
+ }
+
+ return -1;
+}
+
+static void __finish_cynara(void)
+{
+ if (!__cynara.initialized)
+ return;
+
+ if (__cynara.handle) {
+ cynara_finish(__cynara.handle);
+ __cynara.handle = NULL;
+ }
+
+ if (__cynara.client) {
+ free(__cynara.client);
+ __cynara.client = NULL;
+ }
+
+ if (__cynara.user) {
+ free(__cynara.user);
+ __cynara.user = NULL;
+ }
+
+ if (__cynara.session) {
+ free(__cynara.session);
+ __cynara.session = NULL;
+ }
+
+ __cynara.initialized = false;
+}
+
+int job_scheduler_verify_privilege(const char *priv)
+{
+ int r;
+
+ if (priv == NULL)
+ return JOB_ERROR_NONE;
+
+ r = __init_cynara();
+ if (r != 0)
+ return JOB_ERROR_IO_ERROR;
+
+ r = cynara_check(__cynara.handle, __cynara.client, __cynara.session,
+ __cynara.user, priv);
+ if (r != CYNARA_API_ACCESS_ALLOWED) {
+ _E("Failed to check cynara access (%d)", r);
+ return JOB_ERROR_PERMISSION_DENIED;
+ }
+
+ return JOB_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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_APPFW_JOB_SCHEDULER_PRIVATE_H__
+#define __TIZEN_APPFW_JOB_SCHEDULER_PRIVATE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int job_scheduler_verify_requirement(const char *uri);
+
+int job_scheduler_verify_trigger(const char *uri);
+
+int job_scheduler_verify_privilege(const char *priv);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_JOB_SCHEDULER_PRIVATE_H__ */