#include <glib.h>
#include "iotcon.h"
+#include "iotcon-internal.h"
#include "ic-dbus.h"
#include "ic-utils.h"
#include "icl.h"
API int iotcon_remote_resource_start_caching(iotcon_remote_resource_h resource,
- int caching_interval,
- iotcon_remote_resource_cached_representation_changed_cb cb,
- void *user_data)
+ iotcon_remote_resource_cached_representation_changed_cb cb, void *user_data)
{
- int ret;
+ int ret, time_interval;
unsigned int get_timer_id;
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(ICL_REMOTE_RESOURCE_MAX_TIME_INTERVAL < caching_interval,
- IOTCON_ERROR_INVALID_PARAMETER);
if (resource->caching_handle) {
ERR("Already Start Caching");
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- if (caching_interval <= 0) {
- WARN("Because time interval is negative, it sets default time interval.(10 sec)");
- resource->caching_handle->get_timer_interval
- = ICL_REMOTE_RESOURCE_DEFAULT_TIME_INTERVAL;
- } else {
- resource->caching_handle->get_timer_interval = caching_interval;
- }
-
_caching_get_timer(resource);
/* OBSERVE METHOD */
resource->caching_handle->cb = cb;
resource->caching_handle->user_data = user_data;
- get_timer_id = g_timeout_add_seconds(resource->caching_handle->get_timer_interval,
- _caching_get_timer, resource);
+ ret = iotcon_remote_resource_get_time_interval(&time_interval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_remote_resource_get_time_interval() Fail(%d)", ret);
+ return ret;
+ }
+
+ get_timer_id = g_timeout_add_seconds(time_interval, _caching_get_timer, resource);
resource->caching_handle->get_timer_id = get_timer_id;
return IOTCON_ERROR_NONE;
#include <glib.h>
#include "iotcon.h"
+#include "iotcon-internal.h"
#include "icl.h"
#include "icl-remote-resource.h"
static void _monitoring_presence_cb(iotcon_presence_h presence, iotcon_error_e err,
iotcon_presence_response_h response, void *user_data)
{
- int ret;
+ int ret, time_interval;
unsigned int get_timer_id;
- iotcon_presence_trigger_e trigger;
iotcon_presence_result_e result;
+ iotcon_presence_trigger_e trigger;
iotcon_remote_resource_h resource = user_data;
RET_IF(NULL == resource);
return;
}
+ ret = iotcon_remote_resource_get_time_interval(&time_interval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_remote_resource_get_time_interval() Fail(%d)", ret);
+ return;
+ }
+
g_source_remove(resource->monitoring_handle->get_timer_id);
_monitoring_get_timer(resource);
- get_timer_id = g_timeout_add_seconds(resource->caching_handle->get_timer_interval,
- _monitoring_get_timer, resource);
+ get_timer_id = g_timeout_add_seconds(time_interval, _monitoring_get_timer, resource);
resource->monitoring_handle->get_timer_id = get_timer_id;
}
API int iotcon_remote_resource_start_monitoring(iotcon_remote_resource_h resource,
- int monitoring_interval,
- iotcon_remote_resource_state_changed_cb cb,
- void *user_data)
+ iotcon_remote_resource_state_changed_cb cb, void *user_data)
{
char *host_address;
- int ret;
- iotcon_connectivity_type_e connectivity_type;
+ int ret, time_interval;
unsigned int get_timer_id;
+ iotcon_connectivity_type_e connectivity_type;
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(ICL_REMOTE_RESOURCE_MAX_TIME_INTERVAL < monitoring_interval,
- IOTCON_ERROR_INVALID_PARAMETER);
if (resource->monitoring_handle) {
ERR("Already Start Monitoring");
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- if (monitoring_interval <= 0) {
- WARN("Because time interval is negative, it sets default time interval.(10 sec)");
- resource->monitoring_handle->get_timer_interval
- = ICL_REMOTE_RESOURCE_DEFAULT_TIME_INTERVAL;
- } else {
- resource->monitoring_handle->get_timer_interval = monitoring_interval;
- }
-
_monitoring_get_timer(resource);
/* GET METHOD (Resource Presence) */
resource->monitoring_handle->cb = cb;
resource->monitoring_handle->user_data = user_data;
- get_timer_id = g_timeout_add_seconds(resource->monitoring_handle->get_timer_interval,
- _monitoring_get_timer, resource);
+ ret = iotcon_remote_resource_get_time_interval(&time_interval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_remote_resource_get_time_interval() Fail(%d)", ret);
+ free(resource->monitoring_handle);
+ resource->monitoring_handle = NULL;
+ return ret;
+ }
+
+ get_timer_id = g_timeout_add_seconds(time_interval, _monitoring_get_timer, resource);
resource->monitoring_handle->get_timer_id = get_timer_id;
/* Device Presence */
#include "icl-resource-types.h"
#include "icl-payload.h"
+#define ICL_REMOTE_RESOURCE_DEFAULT_TIME_INTERVAL 10 /* 10 sec */
+#define ICL_REMOTE_RESOURCE_MAX_TIME_INTERVAL 3600 /* 60 min */
+
typedef struct {
iotcon_found_resource_cb cb;
void *user_data;
int timeout_id;
} icl_found_resource_s;
+static int icl_remote_resource_time_interval;
+
+
static iotcon_remote_resource_h _icl_remote_resource_from_gvariant(GVariant *payload,
iotcon_connectivity_type_e connectivity_type);
return resource;
}
+
+API int iotcon_remote_resource_get_time_interval(int *time_interval)
+{
+ RETV_IF(NULL == time_interval, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (0 == icl_remote_resource_time_interval)
+ *time_interval = ICL_REMOTE_RESOURCE_DEFAULT_TIME_INTERVAL;
+ else
+ *time_interval = icl_remote_resource_time_interval;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_remote_resource_set_time_interval(int time_interval)
+{
+ RETV_IF(ICL_REMOTE_RESOURCE_MAX_TIME_INTERVAL < time_interval || time_interval <= 0,
+ IOTCON_ERROR_INVALID_PARAMETER);
+
+ icl_remote_resource_time_interval = time_interval;
+
+ return IOTCON_ERROR_NONE;
+}
+
#include "icl-options.h"
-#define ICL_REMOTE_RESOURCE_DEFAULT_TIME_INTERVAL 10 /* 10 sec */
-#define ICL_REMOTE_RESOURCE_MAX_TIME_INTERVAL 3600 /* 60 min */
-
typedef enum {
ICL_DEVICE_STATE_ALIVE,
ICL_DEVICE_STATE_LOST_SIGNAL,
struct icl_remote_resource_caching {
unsigned int get_timer_id;
- int get_timer_interval;
iotcon_representation_h repr;
iotcon_remote_resource_cached_representation_changed_cb cb;
void *user_data;
struct icl_remote_resource_monitoring {
unsigned int get_timer_id;
- int get_timer_interval;
iotcon_remote_resource_state_e resource_state;
iotcon_remote_resource_state_changed_cb cb;
void *user_data;
*/
int iotcon_stop_presence(void);
+/**
+ * @brief Gets the time interval of monitoring & caching API of remote resource.
+ * @details This API get the time interval of iotcon_remote_resource_start_monitoring(),
+ * and iotcon_remote_resource_start_caching().\n
+ * The functions operate GET method, every saved time interval.
+ * Default time interval is 10 seconds.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[out] time_interval Seconds for time interval
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see iotcon_remote_resource_set_time_interval()
+ * @see iotcon_remote_resource_start_monitoring()
+ * @see iotcon_remote_resource_start_caching()
+ */
+int iotcon_remote_resource_get_time_interval(int *time_interval);
+
+/**
+ * @brief Sets the time interval of monitoring & caching API of remote resource.
+ * @details This API set the time interval of iotcon_remote_resource_start_monitoring(),
+ * and iotcon_remote_resource_start_caching().
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] time_interval Seconds for time interval (must be in range from 1 to 3600)
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see iotcon_remote_resource_get_time_interval()
+ * @see iotcon_remote_resource_start_monitoring()
+ * @see iotcon_remote_resource_start_caching()
+ */
+int iotcon_remote_resource_set_time_interval(int time_interval);
+
#ifdef __cplusplus
}
#endif
/**
* @brief Starts caching of a remote resource.
* @details Use this function to start caching the resource's attribute.\n
- * Default caching time interval is 10 seconds.
- * Internally, it operates GET method, periodically, and it observes the remote resource.
+ * Although, remote resource is not observable, it keeps the representation up-to-date.
+ * Because It checks whether representation is changed, periodically.
+ * The default checking interval is 10 seconds, But it may be changed by a administrator.
*
* @since_tizen 3.0
* @privlevel public
* @privilege %http://tizen.org/privilege/internet
*
* @param[in] resource The handle of the remote resource to be cached
- * @param[in] caching_interval Seconds for caching time interval.\n
- * If value is 0, then it sets 10 seconds(default caching time).
* @param[in] cb The callback function to add into callback list
* @param[in] user_data The user data to pass to the callback function
*
* @see iotcon_remote_resource_cached_representation_changed_cb()
*/
int iotcon_remote_resource_start_caching(iotcon_remote_resource_h resource,
- int caching_interval,
- iotcon_remote_resource_cached_representation_changed_cb cb,
- void *user_data);
+ iotcon_remote_resource_cached_representation_changed_cb cb, void *user_data);
/**
* @brief Stops caching of a remote resource.
/**
* @brief Starts monitoring of a remote resource.
- * @details When remote resource's state are changed, registered callbacks will be called\n
- * in turn. Default monitoring time interval is 10 seconds.
- * Internally, it operates GET method, periodically, and it subscribes the devices's presence.
+ * @details When remote resource's state are changed, registered callbacks will be called
+ * in turn. Internally, it checks the state of resource, periodically. Thus, it may not
+ * receive the state, immediately.
*
* @since_tizen 3.0
* @privlevel public
* @privilege %http://tizen.org/privilege/internet
*
* @param[in] resource The handle of the remote resource
- * @param[in] monitoring_interval Seconds for monitoring time interval.\n
- * If value is 0, then it sets 10 seconds(default monitoring time).
* @param[in] cb The callback function to add into callback list
* @param[in] user_data The user data to pass to the callback function
*
* @see iotcon_remote_resource_state_changed_cb()
*/
int iotcon_remote_resource_start_monitoring(iotcon_remote_resource_h resource,
- int monitoring_interval,
- iotcon_remote_resource_state_changed_cb cb,
- void *user_data);
+ iotcon_remote_resource_state_changed_cb cb, void *user_data);
/**
* @brief Stops monitoring of a remote resource.
}
/* Start Monitoring */
- ret = iotcon_remote_resource_start_monitoring(cloned_resource, 10, _state_changed_cb,
+ ret = iotcon_remote_resource_start_monitoring(cloned_resource, _state_changed_cb,
NULL);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_remote_resource_start_monitoring() Fail(%d)", ret);
}
/* Start Caching */
- ret = iotcon_remote_resource_start_caching(cloned_resource, 10,
+ ret = iotcon_remote_resource_start_caching(cloned_resource,
_representation_changed_cb, NULL);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_remote_resource_start_caching() Fail(%d)", ret);