PlatformConfig cfg {
OC::ServiceType::InProc,
- OC::ModeType::Server,
+ OC::ModeType::Both,
(OCTransportAdapter)(OCTransportAdapter::OC_ADAPTER_IP|OCTransportAdapter::OC_ADAPTER_TCP),
OC::QualityOfService::LowQos,
&ps
_clear_user_data(user_data);
}
-static bool _found_resource(iotcon_remote_resource_h resource,
- iotcon_error_e result, void *user_data)
+static bool _found_resource(std::shared_ptr<OCResource> resource)
{
int ret;
+ char *resource_uri_path;
+ char *resource_device_id = NULL;
+ char *resource_host;
+ char *resource_type = NULL;
+ comp_group_type_e group_type;
+ std::string resourceURI;
+ std::string hostAddress;
+ static int resourceCount = 0;
+
+ LOG_DEBUG("Found Resource");
+ try {
+ if(resource) {
+ resource_uri_path = g_strdup(resource->uri().c_str());
+ resource_host = g_strdup(resource->host().c_str());
+ resource_device_id = g_strdup(resource->sid().c_str());
+
+ LOG_DEBUG("Resource URI : %s", resource_uri_path);
+ LOG_DEBUG("Host Address : %s", resource_host);
+ LOG_DEBUG("Resource Device ID : %s", resource_device_id);
+
+ for(auto &resourceTypes : resource->getResourceTypes()) {
+ resource_type = g_strdup(resourceTypes.c_str());
+ LOG_DEBUG("Resource Type : %s", resource_type);
+ }
+
+ if (g_strcmp0(resource_type, "core.comp.group") == 0) {
+ comp_context_t *comp_ctx = comp_context_get_context();
+ if (g_strcmp0(resource_device_id, comp_ctx->device_uuid) == 0)
+ group_type = COMP_GROUP_DEVICE;
+ else
+ group_type = COMP_GROUP_REMOTE_DEVICE;
+
+ char *temp = g_strdup(resource_uri_path);
+ char *ptr = strtok(temp, "/");
+ ptr = strtok(NULL, "/");
+ ptr = strtok(NULL, "/");
+
+ LOG_DEBUG("group name is %s", ptr);
+ comp_group_add_new(resource_uri_path, resource_device_id, ptr,
+ resource_host, resource_type, group_type);
+ found_group_count++;
+
+ g_free(temp);
+ g_free(resource_uri_path);
+ g_free(resource_host);
+ g_free(resource_type);
+ g_free(resource_device_id);
+
+ return IOTCON_FUNC_CONTINUE;
+ } else if (g_strcmp0(resource_type, "core.comp.data") == 0) {
+ }
+ }
+ else
+ {
+ LOG_ERR("Resource is invalid");
+ }
+ }
+ catch(std::exception& e)
+ {
+ LOG_ERR("Exception in foundResource: %s", e.what());
+ }
+
+ return IOTCON_FUNC_CONTINUE;
+#if 0
+ int ret;
char *resource_uri_path = NULL;
iotcon_resource_types_h resource_types;
char *resource_device_id;
}
return IOTCON_FUNC_CONTINUE;
+#endif
}
static gboolean _timeout_cb(gpointer data)
return false;
}
-int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout, void *user_data)
+int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout,
+ void *user_data)
{
int ret;
iotcon_query_h query;
comp_command_t *cmd = (comp_command_t *) user_data;
+ std::ostringstream requestURI;
found_group_count = 0;
+ try {
+ requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=" <<
+ comp_resource_get_type(resource_type);
+
+ LOG_DEBUG("Querying for Resource");
+ ret = OCPlatform::findResource("", requestURI.str(),
+ CT_ADAPTER_IP,
+ &_found_resource);
+ } catch (OCException &e) {
+ LOG_ERR("Failed to find resource %s", e.reason());
+ ret = e.code();
+ }
+
+#if 0
ret = iotcon_set_timeout(timeout);
if (IOTCON_ERROR_NONE != ret) {
LOG_ERR("Failed to set timeout value");
ret = iotcon_find_resource(cmd->host,
IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
query, _found_resource, user_data);
+#endif
cmd->resource_type = resource_type;
cmd->tid = g_timeout_add_seconds(timeout + 1, _timeout_cb, cmd);