/**
* @brief Sets the app-control that will be called when the job's execution criteria is satisfied.
* @param[in] job Job handle
- * @param[in] app_control Serialized app-control
+ * @param[in] app_control App-control (bundle-exported)
* @return @c 0 on success, otherwise a negative error value
*/
int ctx_sched_job_set_app_control(ctx_sched_job_h job, bundle* app_control);
+/**
+ * @brief Sets the notification that will be called when the job's execution criteria is satisfied.
+ * @param[in] job Job handle
+ * @param[in] title Title text
+ * @param[in] content Content body text
+ * @param[in] icon_path Icon file path
+ * @param[in] app_control App-control (bundle-exported)
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int ctx_sched_job_set_notification(ctx_sched_job_h job,
+ const char* title, const char* content, const char* icon_path, bundle* app_control);
+
/**
* @brief Sets the DBus method that will be called when the job's execution criteria is satisfied.
* @param[in] job Job handle
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(capi-system-device)
BuildRequires: pkgconfig(capi-system-runtime-info)
+BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(notification)
BuildRequires: pkgconfig(context-common-server)
BuildRequires: pkgconfig(context-common-client)
return E_SUPPORT;
}
+EXPORT_API int ctx_sched_job_set_notification(ctx_sched_job_h job,
+ const char* title, const char* content, const char* icon_path, bundle* app_control)
+{
+ return E_SUPPORT;
+}
+
EXPORT_API int ctx_sched_job_set_dbus(ctx_sched_job_h job,
const char* bus_name, const char* object_path, const char* interface,
const char* method, GVariant* parameters)
return E_NONE;
}
+EXPORT_API int ctx_sched_job_set_notification(ctx_sched_job_h job,
+ const char* title, const char* content, const char* icon_path, bundle* app_control)
+{
+ IF_FAIL_RETURN(job && title && content, E_PARAM);
+
+ JobAction* action = new(std::nothrow) JobNotification(
+ title, content, icon_path ? icon_path : EMPTY_STR, app_control);
+ ASSERT_ALLOC(action);
+
+ job->jobInfo->setAction(action);
+
+ return E_NONE;
+}
+
EXPORT_API int ctx_sched_job_set_dbus(ctx_sched_job_h job,
const char* bus_name, const char* object_path, const char* interface,
const char* method, GVariant* parameters)
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ActionDBusCaller.h"
-
-using namespace ctx;
-
-GDBusConnection* ActionDBusCaller::__connection = NULL;
-
-static void __async_ready_cb(GObject* obj, GAsyncResult* res, gpointer data)
-{
- GError *gerr = NULL;
- GDBusConnection* conn = static_cast<GDBusConnection*>(data);
- GVariant* param = g_dbus_connection_call_finish(conn, res, &gerr);
-
- if (param)
- g_variant_unref(param);
-
- HANDLE_GERROR(gerr);
-}
-
-ActionDBusCaller::ActionDBusCaller()
-{
-}
-
-ActionDBusCaller::~ActionDBusCaller()
-{
-}
-
-bool ActionDBusCaller::call(const std::string& busName, const std::string& objectPath,
- const std::string& interface, const std::string& methodName, GVariant* param)
-{
- IF_FAIL_RETURN(__connection, false);
-
- g_dbus_connection_call(__connection, busName.c_str(),
- objectPath.c_str(), interface.c_str(), methodName.c_str(), param,
- NULL, G_DBUS_CALL_FLAGS_NONE, CTX_DBUS_TIMEOUT, NULL, __async_ready_cb, __connection);
-
- return true;
-}
-
-bool ActionDBusCaller::call(const std::string& busName, const std::string& objectPath,
- const std::string& interface, const std::string& methodName, GVariant* param, uid_t uid)
-{
- IF_FAIL_RETURN(__connection, false);
-
- //TODO
- return false;
-}
-
-void ActionDBusCaller::setConnection(GDBusConnection* conn)
-{
- __connection = conn;
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __CONTEXT_JOB_SCHEDULER_ACTION_DBUS_CALLER_H__
-#define __CONTEXT_JOB_SCHEDULER_ACTION_DBUS_CALLER_H__
-
-#include <string>
-#include <ContextTypes.h>
-
-namespace ctx {
-
- class ActionDBusCaller {
- public:
- ActionDBusCaller();
- ~ActionDBusCaller();
-
- bool call(const std::string& busName, const std::string& objectPath,
- const std::string& interface, const std::string& methodName,
- GVariant* param);
-
- bool call(const std::string& busName, const std::string& objectPath,
- const std::string& interface, const std::string& methodName,
- GVariant* param, uid_t uid);
-
- static void setConnection(GDBusConnection* conn);
-
- private:
- static GDBusConnection* __connection;
- };
-
-}
-
-#endif /* __CONTEXT_JOB_SCHEDULER_ACTION_DBUS_CALLER_H__ */
* limitations under the License.
*/
+#include <aul_svc.h>
+#include <notification.h>
+#include <notification_internal.h>
+#include <vconf.h>
#include <Conf.h>
#include <JobSchedulerTypesPrivate.h>
#include <JobAction.h>
-#include "ActionDBusCaller.h"
+#include "IPC.h"
#include "ActionState.h"
#include "ClosingState.h"
void ActionState::__callDBusMethod()
{
- ActionDBusCaller caller;
JobDBusCall* action = static_cast<JobDBusCall*>(getJobInfo()->getAction());
bool success = false;
if (getUid() == SYSTEM_UID) {
_D("Call %s.%s", action->getInterface().c_str(), action->getMethodName().c_str());
- success = caller.call(action->getBusName(), action->getObjectPath(),
+ success = IPC::dbusCall(action->getBusName(), action->getObjectPath(),
action->getInterface(), action->getMethodName(), action->getParameters());
} else {
_D("Call %s.%s of %u", action->getInterface().c_str(), action->getMethodName().c_str(), static_cast<unsigned>(getUid()));
- success = caller.call(action->getBusName(), action->getObjectPath(),
- action->getInterface(), action->getMethodName(), action->getParameters(),
- getUid());
+ _W("Not supported yet");
+
+ //TODO: Delegate to the agent daemon
}
IF_FAIL_VOID_TAG(success, _E, "DBus call failed");
}
+static void __aul_svc_result_cb(bundle* b, int requestCode, aul_svc_result_val result, void* data)
+{
+ _D("App-control sent: %d", result);
+}
+
void ActionState::__sendAppControl()
{
- //TODO
+ IF_FAIL_VOID_TAG(getUid() != SYSTEM_UID, _W, "Not a user session");
+
+ _D("Send app-control to %u", static_cast<unsigned>(getUid()));
+
+ bundle* bn = static_cast<JobAppControl*>(getJobInfo()->getAction())->getAppControl();
+ IF_FAIL_VOID_TAG(bn, _E, "App-control not found");
+
+ int pid = aul_svc_run_service_for_uid(bn, 0, __aul_svc_result_cb, NULL, getUid());
+ IF_FAIL_VOID_TAG(pid >= 0, _E, "Sending app-control failed");
+}
+
+static notification_h __create_notification(const std::string& title,
+ const std::string& content, const std::string& iconPath, bundle* appCtrlBundle)
+{
+ notification_h notification = notification_create(NOTIFICATION_TYPE_NOTI);
+
+ if (!title.empty()) {
+ notification_set_text(notification,
+ NOTIFICATION_TEXT_TYPE_TITLE, title.c_str(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ }
+
+ if (!content.empty()) {
+ notification_set_text(notification,
+ NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ }
+
+ if (!iconPath.empty()) {
+ notification_set_image(notification, NOTIFICATION_IMAGE_TYPE_ICON, iconPath.c_str());
+ }
+
+ if (appCtrlBundle) {
+ notification_set_execute_option(notification,
+ NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, appCtrlBundle);
+ } else {
+ notification_set_property(notification, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
+ }
+
+ int sound = 0;
+ vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound);
+ if (sound) {
+ notification_set_sound(notification, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL);
+ }
+
+ int vibration = 0;
+ vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration);
+ if (vibration) {
+ notification_set_vibration(notification,
+ NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
+ }
+
+ return notification;
}
void ActionState::__postNotification()
{
- //TODO
+ IF_FAIL_VOID_TAG(getUid() != SYSTEM_UID, _W, "Not a user session");
+
+ JobNotification* action = static_cast<JobNotification*>(getJobInfo()->getAction());
+
+ notification_h notification = __create_notification(action->getTitle(),
+ action->getContent(), action->getIconPath(), action->getAppControl());
+ IF_FAIL_VOID_TAG(notification, _E, "Notification construction failed");
+
+ int error = notification_post_for_uid(notification, getUid());
+ notification_free(notification);
+
+ IF_FAIL_VOID_TAG(error == NOTIFICATION_ERROR_NONE, _E, "Posting notification failed");
}
void ActionState::__stop()
SET(DEPS "${DEPS} jsoncpp sqlite3 vconf context-common-server")
SET(DEPS "${DEPS} capi-system-info capi-system-device capi-system-runtime-info")
+SET(DEPS "${DEPS} aul notification")
FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
MESSAGE("Sources: ${SRCS}")
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "IPC.h"
+
+using namespace ctx;
+
+GDBusConnection* IPC::__dbusConnection = NULL;
+
+static void __async_ready_cb(GObject* obj, GAsyncResult* res, gpointer data)
+{
+ GError *gerr = NULL;
+ GDBusConnection* conn = static_cast<GDBusConnection*>(data);
+ GVariant* param = g_dbus_connection_call_finish(conn, res, &gerr);
+
+ if (param)
+ g_variant_unref(param);
+
+ HANDLE_GERROR(gerr);
+}
+
+IPC::IPC()
+{
+}
+
+bool IPC::dbusCall(const std::string& busName, const std::string& objectPath,
+ const std::string& interface, const std::string& methodName, GVariant* param)
+{
+ IF_FAIL_RETURN(__dbusConnection, false);
+
+ g_dbus_connection_call(__dbusConnection, busName.c_str(),
+ objectPath.c_str(), interface.c_str(), methodName.c_str(), param,
+ NULL, G_DBUS_CALL_FLAGS_NONE, CTX_DBUS_TIMEOUT, NULL, __async_ready_cb, __dbusConnection);
+
+ return true;
+}
+
+void IPC::setDBus(GDBusConnection* conn)
+{
+ __dbusConnection = conn;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_IPC_H__
+#define __CONTEXT_JOB_SCHEDULER_IPC_H__
+
+#include <string>
+#include <ContextTypes.h>
+
+namespace ctx {
+
+ class IPC {
+ public:
+ static bool dbusCall(const std::string& busName, const std::string& objectPath,
+ const std::string& interface, const std::string& methodName,
+ GVariant* param);
+
+ static void setDBus(GDBusConnection* conn);
+
+ //TODO: Socket
+
+ private:
+ IPC();
+
+ static GDBusConnection* __dbusConnection;
+ };
+
+}
+
+#endif /* __CONTEXT_JOB_SCHEDULER_IPC_H__ */
#include "MethodCallHandler.h"
#include "ContextManager.h"
#include "SchedTimer.h"
-#include "ActionDBusCaller.h"
+#include "IPC.h"
#define SYSTEM_UID 0
{
ContextManager::init();
SchedTimer::init();
- ActionDBusCaller::setConnection(__serviceRunner->getConnection());
+ IPC::setDBus(__serviceRunner->getConnection());
__jobManagers.emplace(SYSTEM_UID, new JobManager(SYSTEM_UID));
return true;
}
static std::string __bundleToString(bundle* bndl)
{
+ if (!bndl)
+ return EMPTY_STR;
+
bundle_raw* encoded = NULL;
int length = 0;
static bundle* __stringToBundle(const std::string& str)
{
+ if (str.empty())
+ return NULL;
+
return bundle_decode(reinterpret_cast<const unsigned char*>(str.c_str()), strlen(str.c_str()));
}