#include <octypes.h>
#include <ocstack.h>
#include <ocpayload.h>
+#include <system_info.h>
+#include <system_settings.h>
#include "iotcon.h"
#include "iotcon-internal.h"
#include "icl-ioty-types.h"
#include "icl-ioty.h"
+static const char *ICL_SYSTEM_INFO_PLATFORM_NAME = "http://tizen.org/system/platform.name";
+static const char *ICL_SYSTEM_INFO_PLATFORM_VERSION = "http://tizen.org/feature/platform.version";
+static const char *ICL_SYSTEM_INFO_MANUF_NAME = "http://tizen.org/system/manufacturer";
+static const char *ICL_SYSTEM_INFO_MODEL_NAME = "http://tizen.org/system/model_name";
+static const char *ICL_SYSTEM_INFO_BUILD_STRING = "http://tizen.org/system/build.string";
+
static GMutex icl_csdk_mutex;
static int icl_remote_resource_time_interval = IC_REMOTE_RESOURCE_DEFAULT_TIME_INTERVAL;
static GHashTable *icl_monitoring_table;
ERR("OCStop() Fail(%d)", result);
}
-GThread* icl_ioty_init()
+int icl_ioty_init(GThread **out_thread)
{
FN_CALL;
GError *error;
OCStackResult result = OCInit(NULL, 0, OC_CLIENT_SERVER);
if (OC_STACK_OK != result) {
ERR("OCInit() Fail(%d)", result);
- return NULL;
+ return ic_ioty_parse_oic_error(result);
}
icl_ioty_ocprocess_start();
if (NULL == thread) {
ERR("g_thread_try_new() Fail(%s)", error->message);
g_error_free(error);
- return NULL;
+ return IOTCON_ERROR_SYSTEM;
}
- return thread;
+ *out_thread = thread;
+
+ return IOTCON_ERROR_NONE;
}
static gboolean _icl_ioty_timeout(gpointer user_data)
return IOTCON_ERROR_NONE;
}
+static int _ioty_set_device_info()
+{
+ int ret;
+ char *device_name = NULL;
+ OCDeviceInfo device_info = {0};
+
+ ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
+ if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
+ ERR("system_settings_get_value_string() Fail(%d)", ret);
+ return IOTCON_ERROR_SYSTEM;
+ }
+
+ device_info.deviceName = device_name;
+
+ icl_ioty_csdk_lock();
+ ret = OCSetDeviceInfo(device_info);
+ icl_ioty_csdk_unlock();
+
+ if (OC_STACK_OK != ret) {
+ ERR("OCSetDeviceInfo() Fail(%d)", ret);
+ free(device_name);
+ return ic_ioty_parse_oic_error(ret);
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+static void _icl_ioty_on_device_name_changed_cb(system_settings_key_e key,
+ void *user_data)
+{
+ int ret;
+
+ ret = _ioty_set_device_info();
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_ioty_set_device_info() Fail(%d)", ret);
+ return;
+ }
+}
+
+int icl_ioty_set_device_info()
+{
+ int ret;
+
+ ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_DEVICE_NAME,
+ _icl_ioty_on_device_name_changed_cb, NULL);
+ if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
+ ERR("system_settings_set_changed_cb() Fail(%d)", ret);
+ return IOTCON_ERROR_SYSTEM;
+ }
+
+ ret = _ioty_set_device_info();
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_ioty_set_device_info() Fail(%d)", ret);
+ return ret;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+static void _ioty_free_platform_info(OCPlatformInfo platform_info)
+{
+ free(platform_info.manufacturerName);
+ free(platform_info.manufacturerUrl);
+ free(platform_info.modelNumber);
+ free(platform_info.dateOfManufacture);
+ free(platform_info.platformVersion);
+ free(platform_info.operatingSystemVersion);
+ free(platform_info.hardwareVersion);
+ free(platform_info.firmwareVersion);
+ free(platform_info.supportUrl);
+ free(platform_info.systemTime);
+}
+
+int icl_ioty_set_platform_info()
+{
+ int ret;
+ OCPlatformInfo platform_info = {0};
+
+ ret = system_info_get_platform_string(ICL_SYSTEM_INFO_PLATFORM_NAME,
+ &platform_info.platformID);
+ if (SYSTEM_INFO_ERROR_NONE != ret) {
+ ERR("system_info_get_platform_string() Fail(%d)", ret);
+ _ioty_free_platform_info(platform_info);
+ return IOTCON_ERROR_SYSTEM;
+ }
+
+ ret = system_info_get_platform_string(ICL_SYSTEM_INFO_MANUF_NAME,
+ &platform_info.manufacturerName);
+ if (SYSTEM_INFO_ERROR_NONE != ret) {
+ ERR("system_info_get_platform_string() Fail(%d)", ret);
+ _ioty_free_platform_info(platform_info);
+ return IOTCON_ERROR_SYSTEM;
+ }
+
+ ret = system_info_get_platform_string(ICL_SYSTEM_INFO_MODEL_NAME,
+ &platform_info.modelNumber);
+ if (SYSTEM_INFO_ERROR_NONE != ret) {
+ ERR("system_info_get_platform_string() Fail(%d)", ret);
+ _ioty_free_platform_info(platform_info);
+ return IOTCON_ERROR_SYSTEM;
+ }
+
+ ret = system_info_get_platform_string(ICL_SYSTEM_INFO_PLATFORM_VERSION,
+ &platform_info.platformVersion);
+ if (SYSTEM_INFO_ERROR_NONE != ret) {
+ ERR("system_info_get_platform_string() Fail(%d)", ret);
+ _ioty_free_platform_info(platform_info);
+ return IOTCON_ERROR_SYSTEM;
+ }
+
+ ret = system_info_get_platform_string(ICL_SYSTEM_INFO_BUILD_STRING,
+ &platform_info.firmwareVersion);
+ if (SYSTEM_INFO_ERROR_NONE != ret) {
+ ERR("system_info_get_platform_string() Fail(%d)", ret);
+ _ioty_free_platform_info(platform_info);
+ return IOTCON_ERROR_SYSTEM;
+ }
+
+ /* platform_info.manufacturerUrl */
+ /* platform_info.dateOfManufacture */
+ /* platform_info.operatingSystemVersion */
+ /* platform_info.hardwareVersion */
+ /* platform_info.supportUrl */
+ /* platform_info.systemTime */
+
+ icl_ioty_csdk_lock();
+ ret = OCSetPlatformInfo(platform_info);
+ icl_ioty_csdk_unlock();
+
+ if (OC_STACK_OK != ret) {
+ ERR("OCSetPlatformInfo() Fail(%d)", ret);
+ _ioty_free_platform_info(platform_info);
+ return ic_ioty_parse_oic_error(ret);
+ }
+ _ioty_free_platform_info(platform_info);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
int icl_ioty_add_presence_cb(const char *host_address,
iotcon_connectivity_type_e connectivity_type,
const char *resource_type,