CONTEXT_TRIGGER_ERROR_RULE_NOT_ENABLED = (TIZEN_ERROR_CONTEXT | 0X06), /**< Rule is not enabled */
CONTEXT_TRIGGER_ERROR_INVALID_RULE = (TIZEN_ERROR_CONTEXT | 0X07), /**< Invalid rule */
CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST = (TIZEN_ERROR_CONTEXT | 0X08), /**< Rule does not exist */
- CONTEXT_TRIGGER_ERROR_INVALID_DATA = CONTEXT_TRIGGER_ERROR_INVALID_RULE, /**< Invalid data */
- CONTEXT_TRIGGER_ERROR_DATA_EXIST = (TIZEN_ERROR_CONTEXT | 0X09), /**< Data exist */
+ CONTEXT_TRIGGER_ERROR_DATA_EXIST = (TIZEN_ERROR_CONTEXT | 0X09), /**< Data exist (Since 3.0) */
+ CONTEXT_TRIGGER_ERROR_INVALID_DATA = (TIZEN_ERROR_CONTEXT | 0X0a), /**< Invalid data (Since 3.0) */
} context_trigger_error_e;
/**
/**
* @brief Registers a rule.
* @details Using this, applications can register a rule and get the ID of the registered rule.@n
- * A rule only can be enabled, disabled, or removed by the application that has registered the rule.
+ * A rule can only be enabled, disabled, or removed by the application that has registered the rule.
* @since_tizen 2.4
*
* @remarks When registering a new rule, regarding the event and condition items used to compose the rule,
* For details, see context_trigger_rule_event_create() and context_trigger_rule_condition_create().
*
* @param[in] rule The rule to register
- * @param[out] rule_id The ID assigned to the @c rule
+ * @param[out] rule_id The ID assigned to the @a rule
*
* @return 0 on success, otherwise a negative error value
* @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
/**
* @brief Removes a rule.
- * @details This removes the rule designated by the @c rule_id, which is owned by the application.
+ * @details This removes the rule designated by the @a rule_id, which is owned by the application.
* @since_tizen 2.4
*
* @remarks If the rule has been activated, it should be disabled through context_trigger_disable_rule() in advance.
/**
* @brief Enables a rule.
- * @details This activates the rule designated by the @c rule_id, which is owned by the application.
+ * @details This activates the rule designated by the @a rule_id, which is owned by the application.
* @since_tizen 2.4
*
* @param[in] rule_id The ID of the rule to be enabled
/**
* @brief Disables a rule.
- * @details This deactivates the rule designated by the @c rule_id, which is owned by the application.
+ * @details This deactivates the rule designated by the @a rule_id, which is owned by the application.
* @since_tizen 2.4
*
* @param[in] rule_id The ID of the rule to be disabled
* @brief Gets the IDs of the rules owned by the current application.
* @since_tizen 2.4
*
- * @remarks The arrays @c enabled_rule_ids and @c disabled_rule_ids must be released using @c free().
+ * @remarks The arrays @a enabled_rule_ids and @a disabled_rule_ids must be released using @c free().
*
* @param[out] enabled_rule_ids The IDs of the active rules
* @param[out] enabled_rule_count The number of the active rules
* @brief Gets a rule stored in the system by rule ID.
* @since_tizen 2.4
*
- * @remarks The @c rule must be released using context_trigger_rule_destroy().
+ * @remarks The @a rule must be released using context_trigger_rule_destroy().
*
* @param[in] rule_id The ID of the rule to be retrieved
* @param[out] rule The rule retrieved
* the rule can be satisfied if at least one is true.
* @since_tizen 2.4
*
- * @remarks The @c rule must be released using context_trigger_rule_destroy().
+ * @remarks The @a rule must be released using context_trigger_rule_destroy().
*
* @param[in] logical_type The logical operator
* @param[out] rule The rule handle to be initialized
* @privlevel public
* @privilege http://tizen.org/privilege/notification
*
- * @remarks The @c app_control can be @c NULL. In that case, no application will be launched via the notification.
+ * @remarks The @a app_control can be @c NULL. In that case, no application will be launched via the notification.
*
* @param[in] rule The rule
* @param[in] title The title text
* @brief Gets the description of a rule.
* @since_tizen 2.4
*
- * @remarks The @c description must be released using @c free().
+ * @remarks The @a description must be released using @c free().
*
* @param[in] rule The rule
* @param[out] description The description of the rule
* @details An event of a contextual event item, which will be monitored by the system, is created.
* @since_tizen 2.4
*
- * @remarks Regarding the @c event_item, the application may require one of the following privileges:@n
+ * @remarks Regarding the @a event_item, the application may require one of the following privileges:@n
* http://tizen.org/privilege/alarm.set @n
* http://tizen.org/privilege/network.get @n
* http://tizen.org/privilege/telephony @n
* If the application does not have necessary privilege, when registering the corresponding rule,
* context_trigger_add_rule() will return #CONTEXT_TRIGGER_ERROR_PERMISSION_DENIED.
* See #context_trigger_event_e to find the corresponding privilege of each event item.@n
- * The @c entry must be released using context_trigger_rule_entry_destroy().
+ * The @a entry must be released using context_trigger_rule_entry_destroy().
*
* @param[in] event_item The contextual event item
* @param[in] logical_type The logical operator
* @details A condition of a contextual condition item is created.
* @since_tizen 2.4
*
- * @remarks Regarding the @c condition_item, the application may require one of the following privileges:@n
+ * @remarks Regarding the @a condition_item, the application may require one of the following privileges:@n
* http://tizen.org/privilege/network.get @n
* http://tizen.org/privilege/telephony @n
* http://tizen.org/privilege/apphistory.read @n
* If the application does not have necessary privilege, when registering the corresponding rule,
* context_trigger_add_rule() will return #CONTEXT_TRIGGER_ERROR_PERMISSION_DENIED.
* See #context_trigger_condition_e to find the corresponding privilege of each condition item.@n
- * The @c entry must be released using context_trigger_rule_entry_destroy().
+ * The @a entry must be released using context_trigger_rule_entry_destroy().
*
* @param[in] condition_item The contextual condition item
* @param[in] logical_type The logical operator
*/
int context_trigger_rule_entry_add_comparison(context_trigger_rule_entry_h entry, const char* key, const char* comp_operator, const char* event_data_key);
+/**
+ * @brief Defines a custom contextual data item with its template.
+ * @details A contextual data item can be used as an event or a condition of other applications' trigger rules,
+ * in addition to predefined #context_trigger_event_e and #context_trigger_condition_e.
+ * See the programming guide to find the JSON format for the @a attr_template.
+ * @since_tizen 3.0
+ *
+ * @param[in] name The name of a custom contextual data item
+ * @param[in] attr_template The attribute template which explains contextual data schema in JSON format
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
+ * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED Operation failed
+ * @retval #CONTEXT_TRIGGER_ERROR_DATA_EXIST Data exist
+ * @retval #CONTEXT_TRIGGER_ERROR_INVALID_DATA Invalid data
+ *
+ * @see context_trigger_custom_unregister()
+ */
+int context_trigger_custom_register(const char* name, const char* attr_template);
+
+/**
+ * @brief Removes a defined custom contextual data item.
+ * @since_tizen 3.0
+ *
+ * @remarks A custom event/condition data item can only be removed by the application that registered it.
+ *
+ * @param[in] name The name of a custom contextual data item
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
+ * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED Operation failed
+ * @retval #CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED Unsupported event/condition item
+ *
+ * @see context_trigger_custom_register()
+ */
+int context_trigger_custom_unregister(const char* name);
+
+/**
+ * @brief Publishes an instance of a defined custom contextual data.i
+ * @details Using this, an application can publish the latest value of a custom data defined by the same application.
+ * The published data instance triggers the evaluation process of the trigger rules that use the data in their event part.
+ * If a rule uses the custom data as a condition, the last known value is referenced.
+ * See the programming guide to find the JSON format for the @a fact.
+ * @since_tizen 3.0
+ *
+ * @remarks Corresponding contextual data can only be published by the application that registered it.
+ *
+ * @param[in] name The name of custom contextual data item
+ * @param[in] fact The contextual data to be provided in JSON format
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
+ * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED Unsupported event/condition contained
+ * @retval #CONTEXT_TRIGGER_ERROR_INVALID_DATA Invalid data
+ */
+int context_trigger_custom_publish(const char* name, const char* fact);
+
+/**
+ * @brief Creates an event entry with custom event, instead of predefined event item #context_trigger_event_e.
+ * @details An event of a custom contextual event item, which is registered and will be provided by an application/system, is created.
+ * @since_tizen 3.0
+ *
+ * @remarks The @a entry must be released using context_trigger_rule_entry_destroy().
+ *
+ * @param[in] event_item The custom contextual event item
+ * @param[in] provider The id of the package which provides the event item
+ * @param[in] logical_type The logical operator
+ * @param[out] entry The event entry to be initialized
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
+ * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY Memory allocation failed
+ * @retval #CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED Unsupported event contained
+ *
+ * @see context_trigger_rule_event_create()
+ * @see context_trigger_rule_entry_destroy()
+ */
+int context_trigger_rule_custom_event_create(const char* event_item, const char* provider,
+ context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry);
+
+/**
+ * @brief Creates a condition entry with custom condition, instead of predefined condition item #context_trigger_condition_e.
+ * @details A condition of a custom contextual condition item, which is registered and will be provided by provider application/system, is created.
+ * @since_tizen 3.0
+ *
+ * @remarks The @a entry must be released using context_trigger_rule_entry_destroy().
+ *
+ * @param[in] condition_item The custom contextual condition item
+ * @param[in] provider The id of the package which provides the condition item
+ * @param[in] logical_type The logical operator
+ * @param[out] entry The condition entry to be initialized
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
+ * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY Memory allocation failed
+ * @retval #CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED Unsupported condition contained
+ *
+ * @see context_trigger_rule_condition_create()
+ * @see context_trigger_rule_entry_destroy()
+ */
+int context_trigger_rule_custom_condition_create(const char* condition_item, const char* provider,
+ context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
#include <context_trigger.h>
/**
- * @brief Add custom event/condition item with its template.
- * @since_tizen 3.0
- *
- * @param[in] name The name of custom item to register
- * @param[in] attr_template The attribute template in json style
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
- * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #CONTEXT_TRIGGER_ERROR_INVALID_DATA Invalid data
- * @retval #CONTEXT_TRIGGER_ERROR_DATA_EXIST Data exist
- *
- * @see context_trigger_remove_custom_item()
- */
-int context_trigger_add_custom_item(const char* name, const char* attr_template);
-
-/**
- * @brief Remove custom event/condition item.
- * @since_tizen 3.0
- *
- * @param[in] name The name of custom item to be removed
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
- * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED Unsupported event/condition item
- *
- * @see context_trigger_add_custom_item()
- */
-int context_trigger_remove_custom_item(const char* name);
-
-/**
- * @brief Publish custom event/condition data.
- * @since_tizen 3.0
- *
- * @param[in] name The name of custom item to provide data
- * @param[in] fact The fact data in json style to publish
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
- * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED Unsupported event/condition contained
- * @retval #CONTEXT_TRIGGER_ERROR_INVALID_DATA Invalid data
- */
-int context_trigger_publish_custom_item(const char* name, const char* fact);
-
-/**
- * @brief Creates an event entry which uses custom event.
- * @details An event of a contextual event item, which will be provided by an application/system, is created.
- * @since_tizen 3.0
- *
- * @remarks The @c entry must be released using context_trigger_rule_entry_destroy().
- *
- * @param[in] event_item The contextual event item
- * @param[in] provider The id of the package which provide the event item
- * @param[in] logical_type The logical operator
- * @param[out] entry The event entry to be initialized
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
- * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY Memory allocation failed
- * @retval #CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED Unsupported event contained
- *
- * @see context_trigger_rule_entry_destroy()
- */
-int context_trigger_rule_custom_event_create(const char* event_item, const char* provider,
- context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry);
-
-/**
- * @brief Creates a condition entry which uses custom condition.
- * @details A condition of a contextual condition item is created.
- * @since_tizen 3.0
- *
- * @remarks The @c entry must be released using context_trigger_rule_entry_destroy().
- *
- * @param[in] condition_item The contextual condition item
- * @param[in] provider The id of the package which provide the condition item
- * @param[in] logical_type The logical operator
- * @param[out] entry The condition entry to be initialized
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful
- * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY Memory allocation failed
- * @retval #CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED Unsupported condition contained
- *
-
- * @see context_trigger_rule_entry_destroy()
- */
-int context_trigger_rule_custom_condition_create(const char* condition_item, const char* provider,
- context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry);
-
-/**
* @brief Sets a D-Bus method call as the action of a rule.
* @since_tizen 2.4
*
static std::string convert_event_to_string(context_trigger_event_e item);
static std::string convert_condition_to_string(context_trigger_condition_e item);
static std::string convert_logical_type_to_string(context_trigger_logical_type_e logical_type);
+static std::string get_custom_item_subject(const char* provider, const char* item);
+
//static std::string int_to_string(int value);
//static std::string double_to_string(int value);
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
IF_FAIL_RETURN_TAG(error == PMINFO_R_OK, CONTEXT_TRIGGER_ERROR_INVALID_DATA, _E, "No such package");
- std::string subject = provider + CT_CUSTOM_DELIMITER + event_item;
+ std::string subject = get_custom_item_subject(provider, event_item);
error = context_trigger_rule_event_create_internal(subject.c_str(), logical_type, entry, true);
return error;
pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
IF_FAIL_RETURN_TAG(error == PMINFO_R_OK, CONTEXT_TRIGGER_ERROR_INVALID_DATA, _E, "No such package");
- std::string subject = provider + CT_CUSTOM_DELIMITER + condition_item;
+ std::string subject = get_custom_item_subject(provider, condition_item);
error = context_trigger_rule_condition_create_internal(subject.c_str(), logical_type, entry, true);
return error;
}
return error;
}
-SO_EXPORT int context_trigger_add_custom_item(const char* name, const char* attr_template)
+SO_EXPORT int context_trigger_custom_register(const char* name, const char* attr_template)
{
_D("BEGIN");
ASSERT_NOT_NULL(name && attr_template);
IF_FAIL_RETURN_TAG(ret, CONTEXT_TRIGGER_ERROR_INVALID_DATA, _E, "Invalid template");
ctx::Json data;
+ data.set(NULL, CT_CUSTOM_REQ, CT_CUSTOM_ADD);
data.set(NULL, CT_CUSTOM_NAME, name);
data.set(NULL, CT_CUSTOM_ATTRIBUTES, jattr_template);
- int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM_ADD, data, NULL);
+ int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM, data, NULL);
IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to add custom item: %#x", error);
return error;
}
-SO_EXPORT int context_trigger_remove_custom_item(const char* name)
+SO_EXPORT int context_trigger_custom_unregister(const char* name)
{
_D("BEGIN");
ASSERT_NOT_NULL(name);
ctx::Json data;
+ data.set(NULL, CT_CUSTOM_REQ, CT_CUSTOM_REMOVE);
data.set(NULL, CT_CUSTOM_NAME, name);
ctx::Json subj;
- int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE, data, &subj);
+ int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM, data, &subj);
IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to remove custom item: %#x", error);
std::string subject;
return error;
}
-SO_EXPORT int context_trigger_publish_custom_item(const char* name, const char* fact)
+SO_EXPORT int context_trigger_custom_publish(const char* name, const char* fact)
{
_D("BEGIN");
ASSERT_NOT_NULL(name && fact);
IF_FAIL_RETURN_TAG(jfact.valid(), CONTEXT_TRIGGER_ERROR_INVALID_RULE, _E, "Cannot parse fact Json");
ctx::Json data;
+ data.set(NULL, CT_CUSTOM_REQ, CT_CUSTOM_PUBLISH);
data.set(NULL, CT_CUSTOM_NAME, name);
data.set(NULL, CT_CUSTOM_FACT, jfact);
- int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM_PUBLISH, data, NULL);
+ int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM, data, NULL);
IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to publish custom data");
return error;
return str;
}
+std::string get_custom_item_subject(const char* provider, const char* item)
+{
+ std::string subject_name = CT_CUSTOM + std::string("/") + provider + std::string("/") + item;
+ return subject_name;
+}
+
/*
std::string int_to_string(int value)
{