int64_t handle;
unsigned int sub_id;
int properties;
+ iotcon_lite_resource_put_request_cb cb;
+ void *cb_data;
};
icl_state_from_gvariant(recv_state, state_iter);
+ if (resource->cb) {
+ if (false == resource->cb(resource, recv_state, resource->cb_data)) {
+ _icl_lite_resource_response_send(repr, oic_request_h, oic_resource_h,
+ IOTCON_RESPONSE_ERROR);
+ iotcon_state_destroy(recv_state);
+ iotcon_representation_destroy(repr);
+ return;
+ }
+ }
+
ret = _icl_lite_resource_set_state(recv_state, resource->state);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icl_lite_resource_set_state() Fail(%d)", ret);
if (IOTCON_ERROR_NONE != ret)
WARN("_icl_lite_resource_notify() Fail(%d)", ret);
}
-
iotcon_representation_destroy(repr);
}
iotcon_resource_types_h res_types,
int properties,
iotcon_state_h state,
+ iotcon_lite_resource_put_request_cb cb,
+ void *user_data,
iotcon_lite_resource_h *resource_handle)
{
int ret, iface;
resource->uri_path = ic_utils_strdup(uri_path);
if (state)
resource->state = icl_state_ref(state);
+ resource->cb = cb;
+ resource->cb_data = user_data;
snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_REQUEST_HANDLER,
signal_number);
...
static iotcon_lite_resource_h _resource;
+static bool _state_changed_cb(iotcon_lite_resource_h resource, iotcon_state_h state, void *user_data)
+{
+ return true;
+}
+
static void _create_light_resource()
{
int ret;
}
ret = iotcon_lite_resource_create("/light/1", resource_types,
- IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, state, &resource);
+ IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, state,
+ _state_changed_cb, NULL, &resource);
if (IOTCON_ERROR_NONE != ret) {
iotcon_state_destroy(state);
iotcon_resource_types_destroy(resource_types);
*/
/**
+ * @brief Specifies the type of function passed to iotcon_lite_resource_create().
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] resource The handle of the lite resource
+ * @param[in] state The state of the lite resource
+ * @param[in] user_data The user data to pass to the function
+ *
+ * @pre The callback must be registered using iotcon_lite_resource_create()
+ *
+ * @return true to accept put request, otherwise false to reject it.
+ *
+ * @see iotcon_lite_resource_create()
+ */
+typedef bool (*iotcon_lite_resource_put_request_cb)(iotcon_lite_resource_h resource,
+ iotcon_state_h state, void *user_data);
+
+
+/**
* @brief Creates a lite resource handle and registers the resource in server
* @details Registers a resource specified by @a uri_path, @a res_types, @a state which have
* @a properties in Iotcon server.\n
* @param[in] res_types The list of type of the resource
* @param[in] properties The property of the resource\n Set of #iotcon_resource_property_e
* @param[in] state The state handle to set
+ * @param[in] cb The callback function to add into callback list
+ * @param[in] user_data The user data to pass to the callback function
* @param[out] resource_handle The handle of the resource
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
- * @post When the resource receive CRUD request, iotcon_request_handler_cb() will be called.
- *
* @see iotcon_lite_resource_destroy()
*/
int iotcon_lite_resource_create(const char *uri_path,
iotcon_resource_types_h res_types,
int properties,
iotcon_state_h state,
+ iotcon_lite_resource_put_request_cb cb,
+ void *user_data,
iotcon_lite_resource_h *resource_handle);
/**
return G_SOURCE_CONTINUE;
}
+static bool _door_state_changed(iotcon_lite_resource_h resource,
+ iotcon_state_h state, void *user_data)
+{
+ FN_CALL;
+ bool opened;
+ int ret;
+
+ ret = iotcon_state_get_bool(state, "opened", &opened);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ return false;
+ }
+ DBG("opened: %d", opened);
+
+ return true;
+}
+
static iotcon_lite_resource_h _create_door_resource(char *uri_path, char *type,
int properties, void *user_data)
{
/* register door resource */
ret = iotcon_lite_resource_create(uri_path, resource_types, properties, state,
- &handle);
+ _door_state_changed, NULL, &handle);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_resource_create() Fail");
iotcon_state_destroy(state);