Add a new header file for job scheduler API 62/147262/19
authorHwankyu Jhun <h.jhun@samsung.com>
Sat, 2 Sep 2017 14:33:01 +0000 (23:33 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 25 Sep 2017 05:14:42 +0000 (14:14 +0900)
Adds new definitions
Adds a new API:
 - aul_job_scheduler_update_job_status

Change-Id: Idad36f116487ba77c002002f746cb7d6c7aae4ed
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
include/aul_cmd.h
include/aul_job_scheduler.h [new file with mode: 0644]
src/aul_job_scheduler.c [new file with mode: 0644]

index b475994..d0c9a9a 100644 (file)
@@ -60,6 +60,7 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_app_com.h DESTINATION incl
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_screen_connector.h DESTINATION include/aul)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_window.h DESTINATION include/aul)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_widget.h DESTINATION include/aul)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_job_scheduler.h DESTINATION include/aul)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/aul.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/feature/preexec_list.txt DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
 INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/miregex DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
index de9b305..f39bdf4 100644 (file)
@@ -126,6 +126,7 @@ enum app_cmd {
        APP_GET_INSTANCE_ID_BY_SURFACE_ID = 95,
        UPDATE_SCREEN_VIEWER_STATUS = 96,
        WIDGET_RUNNING_INFO = 97,
+       JOB_STATUS_UPDATE = 98,
 
        APP_CMD_MAX
 };
diff --git a/include/aul_job_scheduler.h b/include/aul_job_scheduler.h
new file mode 100644 (file)
index 0000000..a937c71
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#define AUL_K_JOB_ID                   "__AUL_JOB_ID__"
+#define AUL_K_JOB_STATUS               "__AUL_JOB_STATUS__"
+#define AUL_K_JOB_REAL_ID              "__AUL_JOB_REAL_ID__"
+
+#define AUL_K_JOB_PERIODIC             "__AUL_JOB_PERIODIC__"
+#define AUL_K_JOB_PERSISTENT           "__AUL_JOB_PERSISTENT__"
+#define AUL_K_JOB_IS_ONCE              "__AUL_JOB_IS_ONCE__"
+
+#define AUL_K_JOB_REQ_TIMEOUT          "__AUL_JOB_REQ_TIMEOUT__"
+#define AUL_K_JOB_REQ_BATTERY_NOT_LOW  "__AUL_JOB_REQ_BATTERY_NOT_LOW__"
+#define AUL_K_JOB_REQ_CHARGING         "__AUL_JOB_REQ_CHARGING__"
+#define AUL_K_JOB_REQ_WIFI_CONNECTION  "__AUL_JOB_REQ_WIFI_CONNECTION__"
+
+#define AUL_K_JOB_TRIG_BATTERY_LEVEL_EMPTY \
+       "__AUL_JOB_TRIG_BATTERY_LEVEL_EMPTY__"
+#define AUL_K_JOB_TRIG_BATTERY_LEVEL_CRITICAL \
+       "__AUL_JOB_TRIG_BATTERY_LEVEL_CRITICAL__"
+#define AUL_K_JOB_TRIG_BATTERY_LEVEL_LOW \
+       "__AUL_JOB_TRIG_BATTERY_LEVEL_LOW__"
+#define AUL_K_JOB_TRIG_BATTERY_LEVEL_HIGH \
+       "__AUL_JOB_TRIG_BATTERY_LEVEL_HIGH__"
+#define AUL_K_JOB_TRIG_CHARGER_STATE_CONNECTED \
+       "__AUL_JOB_TRIG_CHARGER_STATE_CONNECTED__"
+#define AUL_K_JOB_TRIG_CHARGER_STATE_DISCONNECTED \
+       "__AUL_JOB_TRIG_CHARGER_STATE_DISCONNECTED__"
+#define AUL_K_JOB_TRIG_DISPLAY_STATE_ON \
+       "__AUL_JOB_TRIG_DISPLAY_STATE_ON__"
+#define AUL_K_JOB_TRIG_DISPLAY_STATE_OFF \
+       "__AUL_JOB_TRIG_DISPLAY_STATE_OFF__"
+#define AUL_K_JOB_TRIG_DISPLAY_STATE_DIM \
+       "__AUL_JOB_TRIG_DISPLAY_STATE_DIM__"
+#define AUL_K_JOB_TRIG_EARJACK_STATE_CONNECTED \
+       "__AUL_JOB_TRIG_EARJACK_STATE_CONNECTED__"
+#define AUL_K_JOB_TRIG_EARJACK_STATE_DISCONNECTED \
+       "__AUL_JOB_TRIG_EARJACK_STATE_DISCONNECTED__"
+#define AUL_K_JOB_TRIG_GPS_STATE_DISABLED \
+       "__AUL_JOB_TRIG_GPS_STATE_DISABLED__"
+#define AUL_K_JOB_TRIG_GPS_STATE_SEARCHING \
+       "__AUL_JOB_TRIG_GPS_STATE_SEARCHING__"
+#define AUL_K_JOB_TRIG_GPS_STATE_CONNECTED \
+       "__AUL_JOB_TRIG_GPS_STATE_CONNECTED__"
+#define AUL_K_JOB_TRIG_POWERSAVE_MODE_ENABLED \
+       "__AUL_JOB_TRIG_POWERSAVE_MODE_ENABLED__"
+#define AUL_K_JOB_TRIG_POWERSAVE_MODE_DISABLED \
+       "__AUL_JOB_TRIG_POWERSAVE_MODE_DISABLED__"
+#define AUL_K_JOB_TRIG_USB_STATE_CONNECTED \
+       "__AUL_JOB_TRIG_USB_STATE_CONNECTED__"
+#define AUL_K_JOB_TRIG_USB_STATE_DISCONNECTED \
+       "__AUL_JOB_TRIG_USB_STATE_DISCONNECTED__"
+#define AUL_K_JOB_TRIG_WIFI_STATE_DISABLED \
+       "__AUL_JOB_TRIG_WIFI_STATE_DISABLED__"
+#define AUL_K_JOB_TRIG_WIFI_STATE_DISCONNECTED \
+       "__AUL_JOB_TRIG_WIFI_STATE_DISCONNECTED__"
+#define AUL_K_JOB_TRIG_WIFI_STATE_CONNECTED \
+       "__AUL_JOB_TRIG_WIFI_STATE_CONNECTED__"
+
+typedef enum {
+       JOB_STATUS_START,
+       JOB_STATUS_STOPPED,
+       JOB_STATUS_FINISHED,
+} aul_job_status_e;
+
+int aul_job_scheduler_update_job_status(const char *job_id,
+               aul_job_status_e job_status);
diff --git a/src/aul_job_scheduler.c b/src/aul_job_scheduler.c
new file mode 100644 (file)
index 0000000..ca8b23e
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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 <stdbool.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <glib.h>
+#include <bundle_internal.h>
+
+#include "aul_util.h"
+#include "aul_api.h"
+#include "aul_sock.h"
+#include "aul.h"
+#include "aul_job_scheduler.h"
+
+API int aul_job_scheduler_update_job_status(const char *job_id,
+               aul_job_status_e job_status)
+{
+       char buf[12];
+       bundle *b;
+       int r;
+
+       if (job_id == NULL || job_status > JOB_STATUS_FINISHED) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       b = bundle_create();
+       if (b == NULL) {
+               _E("Out of memory");
+               return AUL_R_ERROR;
+       }
+
+       r = bundle_add(b, AUL_K_JOB_ID, job_id);
+       if (r != BUNDLE_ERROR_NONE) {
+               _E("Failed to add job(%s)", job_id);
+               bundle_free(b);
+               return AUL_R_ERROR;
+       }
+
+       snprintf(buf, sizeof(buf), "%u", job_status);
+       r = bundle_add(b, AUL_K_JOB_STATUS, buf);
+       if (r != BUNDLE_ERROR_NONE) {
+               _E("Failed to add job status(%u)", job_status);
+               bundle_free(b);
+               return AUL_R_ERROR;
+       }
+
+       r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), JOB_STATUS_UPDATE,
+                       b, AUL_SOCK_NOREPLY);
+       if (r != 0) {
+               _E("Failed to update job status(%s:%u)", job_id, job_status);
+               bundle_free(b);
+               return r;
+       }
+       bundle_free(b);
+
+       return AUL_R_OK;
+}