#include "icd-dbus.h"
#include "icd-ioty.h"
+#define ICD_ALL_INTERFACES "0.0.0.0"
+#define ICD_RANDOM_PORT 0
+
int main(int argc, char **argv)
{
guint id;
loop = g_main_loop_new(NULL, FALSE);
id = icd_dbus_init();
- icd_ioty_config(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+ icd_ioty_config(ICD_ALL_INTERFACES, ICD_RANDOM_PORT);
g_main_loop_run(loop);
struct icl_resource {
char *uri;
- char *host;
bool is_observable;
iotcon_resource_types_h types;
int ifaces;
int icl_ioty_convert_interface_flag(iotcon_interface_e src, char **dest);
int icl_ioty_convert_interface_string(const char *src, iotcon_interface_e *dest);
-
#endif /*__IOT_CONNECTIVITY_MANAGER_LIBRARY_IOTIVITY_H__*/
/**
* @brief global context
*/
-static GHashTable *icl_request_cb_hash;
static bool icl_is_init = false;
-static void _free_resource(gpointer data)
-{
- int ret;
- iotcon_resource_h resource = data;
-
- RET_IF(NULL == data);
-
- ret = icl_dbus_unregister_resource(resource->handle);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_dbus_unregister_resource() Fail(%d)", ret);
-
- free(resource);
-}
-
-
-API int iotcon_initialize(const char *addr, unsigned short port)
+API int iotcon_initialize()
{
FN_CALL;
int ret;
RETVM_IF(true == icl_is_init, IOTCON_ERROR_INVALID_PARAMETER, "already initialized");
- RETV_IF(NULL == addr, IOTCON_ERROR_INVALID_PARAMETER);
+
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+ g_type_init();
+#endif
ret = icl_dbus_start();
if (IOTCON_ERROR_NONE != ret) {
return ret;
}
-
- icl_request_cb_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
- _free_resource);
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
- g_type_init();
-#endif
icl_is_init = true;
return IOTCON_ERROR_NONE;
icl_dbus_stop();
- g_hash_table_destroy(icl_request_cb_hash);
- icl_request_cb_hash = NULL;
-
icl_is_init = false;
}
-static gboolean _find_valid_resource(gpointer key, gpointer value, gpointer user_data)
-{
- return (key == user_data);
-}
-
-
-iotcon_resource_h icl_get_resource_handler_data(void *handle)
-{
- return g_hash_table_find(icl_request_cb_hash, _find_valid_resource, handle);
-}
-
-
/* The length of uri should be less than or equal to 36. */
API iotcon_resource_h iotcon_register_resource(const char *uri,
iotcon_resource_types_h res_types,
resource->ifaces = ifaces;
resource->is_observable = properties & IOTCON_OBSERVABLE;
- g_hash_table_insert(icl_request_cb_hash, resource->handle, resource);
-
return resource;
}
API void iotcon_unregister_resource(iotcon_resource_h resource)
{
FN_CALL;
+ int ret;
RET_IF(NULL == resource);
- g_hash_table_remove(icl_request_cb_hash, resource->handle);
+ ret = icl_dbus_unregister_resource(resource->handle);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_dbus_unregister_resource() Fail(%d)", ret);
+ return;
+ }
+ resource->handle = NULL;
+
+ free(resource->uri);
+ resource->uri = NULL;
+ free(resource->types);
+ resource->types = NULL;
+
+ free(resource);
}
#endif
#define API __attribute__((visibility("default")))
-
#define ICL_INTERFACE_MAX (IOTCON_INTERFACE_DEFAULT | IOTCON_INTERFACE_LINK | \
IOTCON_INTERFACE_BATCH | IOTCON_INTERFACE_GROUP)
-iotcon_resource_h icl_get_resource_handler_data(void *handle);
-
#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_H__ */
#ifndef __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__
#define __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__
-#define IOTCON_ALL_INTERFACES "0.0.0.0"
-#define IOTCON_RANDOM_PORT 0
#define IOTCON_MULTICAST_ADDRESS "224.0.1.187"
/**
#include <iotcon-constant.h>
#include <iotcon-representation.h>
-int iotcon_initialize(const char *addr, unsigned short port);
+int iotcon_initialize();
void iotcon_deinitialize();
typedef void (*iotcon_request_handler_cb)(iotcon_request_h request, void *user_data);
GMainLoop *loop;
loop = g_main_loop_new(NULL, FALSE);
- /* initialize address and port */
- iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+ /* iotcon initialize */
+ iotcon_initialize();
/* find door typed resources */
iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, "core.door", &_found_resource, NULL);
loop = g_main_loop_new(NULL, FALSE);
- /* initialize address and port */
- iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+ /* iotcon initialize */
+ iotcon_initialize();
/* set local door resource */
iotcon_error = _set_door_resource();
loop = g_main_loop_new(NULL, FALSE);
- iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+ /* iotcon initialize */
+ iotcon_initialize();
iotcon_get_device_info(IOTCON_MULTICAST_ADDRESS, _get_device_info, NULL);
loop = g_main_loop_new(NULL, FALSE);
- iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+ /* iotcon initialize */
+ iotcon_initialize();
ret = iotcon_register_device_info(device_info);
if (IOTCON_ERROR_NONE != ret) {
GMainLoop *loop;
loop = g_main_loop_new(NULL, FALSE);
- /* initialize address and port */
- iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+ /* iotcon initialize */
+ iotcon_initialize();
/* find room typed resources */
iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, "core.room", &_found_resource, NULL);
loop = g_main_loop_new(NULL, FALSE);
- /* initialize address and port */
- iotcon_initialize(IOTCON_ALL_INTERFACES, IOTCON_RANDOM_PORT);
+ /* iotcon initialize */
+ iotcon_initialize();
/* register room resource */
room_rtypes = iotcon_resource_types_new();