* limitations under the License.
*/
#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "iotcon.h"
#include "ic-utils.h"
#include "icl.h"
-#include "icl-repr.h"
+#include "icl-representation.h"
#include "icl-dbus.h"
#include "icl-dbus-type.h"
+#include "icl-device.h"
/**
* @brief The maximum length which can be held in a manufacturer name.
iotcon_device_info_cb cb;
void *user_data;
unsigned int id;
+ int timeout_id;
} icl_device_info_s;
typedef struct {
iotcon_platform_info_cb cb;
void *user_data;
unsigned int id;
+ int timeout_id;
} icl_platform_info_s;
-API int iotcon_register_device_info(const char *device_name)
+API int iotcon_device_info_get_property(iotcon_device_info_h device_info,
+ iotcon_device_info_e property, char **value)
{
- int ret, error_code;
- GError *error = NULL;
- GVariant *arg_info;
-
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == device_name, IOTCON_ERROR_INVALID_PARAMETER);
-
- arg_info = icl_dbus_device_info_to_gvariant(device_name);
- ic_dbus_call_register_device_info_sync(icl_dbus_get_object(), arg_info, &ret,
- NULL, &error);
- if (error) {
- ERR("ic_dbus_call_register_device_info_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- g_variant_unref(arg_info);
- return error_code;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
+ RETV_IF(NULL == device_info, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+
+ switch (property) {
+ case IOTCON_DEVICE_INFO_NAME:
+ *value = device_info->device_name;
+ break;
+ case IOTCON_DEVICE_INFO_SPEC_VER:
+ *value = device_info->spec_ver;
+ break;
+ case IOTCON_DEVICE_INFO_ID:
+ *value = device_info->device_id;
+ break;
+ case IOTCON_DEVICE_INFO_DATA_MODEL_VER:
+ *value = device_info->data_model_ver;
+ break;
+ default:
+ ERR("Invalid property(%d)", property);
+ return IOTCON_ERROR_INVALID_PARAMETER;
}
- return ret;
+ return IOTCON_ERROR_NONE;
}
-
static void _icl_device_info_cb(GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
GVariant *parameters,
gpointer user_data)
{
+ char *uri_path;
+ struct icl_device_info info = {0};
icl_device_info_s *cb_container = user_data;
iotcon_device_info_cb cb = cb_container->cb;
- char *device_name, *sid, *spec_version, *data_model_version;
- g_variant_get(parameters, "(&s&s&s&s)", &device_name, &sid, &spec_version,
- &data_model_version);
+ if (cb_container->timeout_id)
+ cb_container->timeout_id = 0;
+
+ g_variant_get(parameters, "(&s&s&s&s&s)", &uri_path, &info.device_name,
+ &info.spec_ver, &info.device_id, &info.data_model_ver);
+
+ /* From iotivity, we can get uri_path. But, the value is always "/oic/d". */
if (cb)
- cb(device_name, sid, spec_version, data_model_version, cb_container->user_data);
+ cb(&info, IOTCON_ERROR_NONE, cb_container->user_data);
}
+static gboolean _icl_timeout_get_device_info(gpointer p)
+{
+ FN_CALL;
+ icl_device_info_s *cb_container = p;
+ struct icl_device_info info = {0};
+
+ if (NULL == cb_container) {
+ ERR("cb_container is NULL");
+ return G_SOURCE_REMOVE;
+ }
+
+ if (cb_container->timeout_id && cb_container->cb)
+ cb_container->cb(&info, IOTCON_ERROR_TIMEOUT, cb_container->user_data);
+
+ icl_dbus_unsubscribe_signal(cb_container->id);
+ cb_container->id = 0;
+
+ return G_SOURCE_REMOVE;
+}
-API int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
+API int iotcon_get_device_info(const char *host_address,
+ iotcon_connectivity_type_e connectivity_type,
+ iotcon_device_info_cb cb,
void *user_data)
{
- GError *error = NULL;
+ int ret, timeout;
unsigned int sub_id;
- int ret, signal_number, error_code;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
+ GError *error = NULL;
icl_device_info_s *cb_container;
+ int64_t signal_number;
+ char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- signal_number = icl_dbus_generate_signal_number();
+ timeout = icl_dbus_get_timeout();
- ic_dbus_call_get_device_info_sync(icl_dbus_get_object(), host_address,
- signal_number, &ret, NULL, &error);
+ ic_dbus_call_get_device_info_sync(icl_dbus_get_object(),
+ ic_utils_dbus_encode_str(host_address),
+ connectivity_type,
+ timeout,
+ &signal_number,
+ &ret,
+ NULL,
+ &error);
if (error) {
ERR("ic_dbus_call_get_device_info_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
return icl_dbus_convert_daemon_error(ret);
}
- snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_DEVICE,
+ snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_DEVICE,
signal_number);
cb_container = calloc(1, sizeof(icl_device_info_s));
_icl_device_info_cb);
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
+ free(cb_container);
return IOTCON_ERROR_DBUS;
}
cb_container->id = sub_id;
+ cb_container->timeout_id = g_timeout_add_seconds(timeout,
+ _icl_timeout_get_device_info, cb_container);
+
return ret;
}
-
-/* The length of manufacturer_name should be less than and equal to 16.
- * The length of manufacturer_url should be less than and equal to 32. */
-API int iotcon_register_platform_info(iotcon_platform_info_s *platform_info)
+API int iotcon_platform_info_get_property(iotcon_platform_info_h platform_info,
+ iotcon_platform_info_e property, char **value)
{
- int ret, error_code;
- GError *error = NULL;
- GVariant *arg_info;
-
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
-
- if (NULL == platform_info->platform_id
- || NULL == platform_info->manuf_name
- || NULL == platform_info->manuf_url
- || NULL == platform_info->model_number
- || NULL == platform_info->date_of_manufacture
- || NULL == platform_info->platform_ver
- || NULL == platform_info->os_ver
- || NULL == platform_info->hardware_ver
- || NULL == platform_info->firmware_ver
- || NULL == platform_info->support_url
- || NULL == platform_info->system_time) {
- ERR("one of parameter is NULL");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- if (platform_info->manuf_name
- && (ICL_MANUFACTURER_NAME_LENGTH_MAX < strlen(platform_info->manuf_name))) {
- ERR("The length of manufacturer_name(%s) is invalid.", platform_info->manuf_name);
+ RETV_IF(NULL == platform_info, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+
+ switch (property) {
+ case IOTCON_PLATFORM_INFO_ID:
+ *value = platform_info->platform_id;
+ break;
+ case IOTCON_PLATFORM_INFO_MANUF_NAME:
+ *value = platform_info->manuf_name;
+ break;
+ case IOTCON_PLATFORM_INFO_MANUF_URL:
+ *value = platform_info->manuf_url;
+ break;
+ case IOTCON_PLATFORM_INFO_MODEL_NUMBER:
+ *value = platform_info->model_number;
+ break;
+ case IOTCON_PLATFORM_INFO_DATE_OF_MANUF:
+ *value = platform_info->date_of_manuf;
+ break;
+ case IOTCON_PLATFORM_INFO_PLATFORM_VER:
+ *value = platform_info->platform_ver;
+ break;
+ case IOTCON_PLATFORM_INFO_OS_VER:
+ *value = platform_info->os_ver;
+ break;
+ case IOTCON_PLATFORM_INFO_HARDWARE_VER:
+ *value = platform_info->hardware_ver;
+ break;
+ case IOTCON_PLATFORM_INFO_FIRMWARE_VER:
+ *value = platform_info->firmware_ver;
+ break;
+ case IOTCON_PLATFORM_INFO_SUPPORT_URL:
+ *value = platform_info->support_url;
+ break;
+ case IOTCON_PLATFORM_INFO_SYSTEM_TIME:
+ *value = platform_info->system_time;
+ break;
+ default:
+ ERR("Invalid property(%d)", property);
return IOTCON_ERROR_INVALID_PARAMETER;
}
- if (platform_info->manuf_url
- && (ICL_MANUFACTURER_URL_LENGTH_MAX < strlen(platform_info->manuf_url))) {
- ERR("The length of manufacturer_url(%s) is invalid.", platform_info->manuf_url);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- arg_info = icl_dbus_platform_info_to_gvariant(platform_info);
- ic_dbus_call_register_platform_info_sync(icl_dbus_get_object(), arg_info, &ret,
- NULL, &error);
- if (error) {
- ERR("ic_dbus_call_register_platform_info_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- g_variant_unref(arg_info);
- return error_code;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- return ret;
+ return IOTCON_ERROR_NONE;
}
gpointer user_data)
{
char *uri_path;
- iotcon_platform_info_s *info = NULL;
+ struct icl_platform_info info = {0};
icl_platform_info_s *cb_container = user_data;
iotcon_platform_info_cb cb = cb_container->cb;
- info = calloc(1, sizeof(iotcon_platform_info_s));
- if (NULL == info) {
- ERR("calloc(client) Fail(%d)", errno);
- return;
- }
+ if (cb_container->timeout_id)
+ cb_container->timeout_id = 0;
g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
&uri_path,
- &info->platform_id,
- &info->manuf_name,
- &info->manuf_url,
- &info->model_number,
- &info->date_of_manufacture,
- &info->platform_ver,
- &info->os_ver,
- &info->hardware_ver,
- &info->firmware_ver,
- &info->support_url,
- &info->system_time);
+ &info.platform_id,
+ &info.manuf_name,
+ &info.manuf_url,
+ &info.model_number,
+ &info.date_of_manuf,
+ &info.platform_ver,
+ &info.os_ver,
+ &info.hardware_ver,
+ &info.firmware_ver,
+ &info.support_url,
+ &info.system_time);
+
+ info.manuf_url = ic_utils_dbus_decode_str(info.manuf_url);
+ info.model_number = ic_utils_dbus_decode_str(info.model_number);
+ info.date_of_manuf = ic_utils_dbus_decode_str(info.date_of_manuf);
+ info.platform_ver = ic_utils_dbus_decode_str(info.platform_ver);
+ info.os_ver = ic_utils_dbus_decode_str(info.os_ver);
+ info.hardware_ver = ic_utils_dbus_decode_str(info.hardware_ver);
+ info.firmware_ver = ic_utils_dbus_decode_str(info.firmware_ver);
+ info.support_url = ic_utils_dbus_decode_str(info.support_url);
+ info.system_time = ic_utils_dbus_decode_str(info.system_time);
/* From iotivity, we can get uri_path. But, the value is always "/oic/p". */
if (cb)
- cb(info, cb_container->user_data);
-
- free(info);
+ cb(&info, IOTCON_ERROR_NONE, cb_container->user_data);
}
+static gboolean _icl_timeout_get_platform_info(gpointer p)
+{
+ FN_CALL;
+ icl_platform_info_s *cb_container = p;
+ struct icl_platform_info info = {0};
+
+ if (NULL == cb_container) {
+ ERR("cb_container is NULL");
+ return G_SOURCE_REMOVE;
+ }
+
+ if (cb_container->timeout_id && cb_container->cb)
+ cb_container->cb(&info, IOTCON_ERROR_TIMEOUT, cb_container->user_data);
-API int iotcon_get_platform_info(const char *host_address, iotcon_platform_info_cb cb,
+ icl_dbus_unsubscribe_signal(cb_container->id);
+ cb_container->id = 0;
+
+ return G_SOURCE_REMOVE;
+}
+
+API int iotcon_get_platform_info(const char *host_address,
+ iotcon_connectivity_type_e connectivity_type,
+ iotcon_platform_info_cb cb,
void *user_data)
{
- GError *error = NULL;
+ int ret, timeout;
unsigned int sub_id;
- int ret, signal_number, error_code;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
+ GError *error = NULL;
icl_platform_info_s *cb_container;
+ int64_t signal_number;
+ char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- signal_number = icl_dbus_generate_signal_number();
+ timeout = icl_dbus_get_timeout();
- ic_dbus_call_get_platform_info_sync(icl_dbus_get_object(), host_address,
- signal_number, &ret, NULL, &error);
+ ic_dbus_call_get_platform_info_sync(icl_dbus_get_object(),
+ ic_utils_dbus_encode_str(host_address),
+ connectivity_type,
+ timeout,
+ &signal_number,
+ &ret,
+ NULL,
+ &error);
if (error) {
ERR("ic_dbus_call_get_platform_info_sync() Fail(%s)", error->message);
- error_code = icl_dbus_convert_dbus_error(error->code);
+ ret = icl_dbus_convert_dbus_error(error->code);
g_error_free(error);
- return error_code;
+ return ret;
}
if (IOTCON_ERROR_NONE != ret) {
return icl_dbus_convert_daemon_error(ret);
}
- snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PLATFORM,
+ snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_PLATFORM,
signal_number);
cb_container = calloc(1, sizeof(icl_platform_info_s));
_icl_platform_info_cb);
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
+ free(cb_container);
return IOTCON_ERROR_DBUS;
}
cb_container->id = sub_id;
+ cb_container->timeout_id = g_timeout_add_seconds(timeout,
+ _icl_timeout_get_platform_info, cb_container);
return ret;
}
-