}
}
+#if 0
static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err,
iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
{
_clear_user_data(user_data);
}
+#endif
+
+static void _on_post(const HeaderOptions& /*headerOptions*/,
+ const OCRepresentation& rep, const int eCode)
+{
+ last_get_result = eCode;
+ int ret;
+ try {
+ if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED ||
+ eCode == OC_STACK_RESOURCE_CHANGED) {
+ LOG_DEBUG("Post request is successful");
+ } else {
+ LOG_ERR("_on_post Response error %d", eCode);
+ }
+ } catch(std::exception& e) {
+ LOG_ERR("Exception %s in on post", e.what());
+ }
+
+}
-static bool _found_resource(std::shared_ptr<OCResource> resource)
+static bool _found_resource(std::shared_ptr<OCResource> resource,
+ void *user_data)
{
int ret;
char *resource_uri_path;
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());
+
+ if (g_strstr_len(resource_host, strlen(resource_host), "tcp")) {
+ LOG_DEBUG("Ignore Resource found for TCP host");
+ g_free(resource_host);
+ return IOTCON_FUNC_CONTINUE;
+ }
+
+ resource_uri_path = g_strdup(resource->uri().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()) {
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) {
+ comp_command_t *cmd = (comp_command_t *)user_data;
+
+ LOG_DEBUG("Resource Type %s", resource_type);
+ LOG_DEBUG("Command Device ID: %s", cmd ? cmd->uuid : "NULL");
+
+ if (cmd != NULL && strcmp(cmd->uuid, resource_device_id) == 0) {
+ OCRepresentation rep;
+
+ LOG_DEBUG("Request to Remote Device");
+
+ LOG_DEBUG("CMD = %s", command2string(cmd->command));
+
+ if (cmd->command == COMP_REQ_CREATE_GROUP) { //request create group
+ rep.setValue("CMD", "1");
+ rep.setValue("name", cmd->arg1);
+ } else if (cmd->command == COMP_REQ_INVITE_DEVICE) { //request invite
+ rep.setValue("CMD", "2");
+ rep.setValue("name", cmd->arg1);
+ rep.setValue("id", cmd->arg2);
+ rep.setValue("PIN", cmd->arg3);
+ } else if (cmd->command == COMP_REQ_EJECT_DEVICE) { //request eject
+ rep.setValue("CMD", "3");
+ rep.setValue("name", cmd->arg1);
+ rep.setValue("id", cmd->arg2);
+ } else if (cmd->command == COMP_REQ_DELETE_GROUP) { //request delete group
+ rep.setValue("CMD", "4");
+ rep.setValue("name", cmd->arg1);
+ } else { /* Send Data */
+ rep.setValue("CMD", "5");
+#ifdef SUPPORT_BASE64_ENCODING
+ uint32_t outSize = 0;
+ size_t b64BufSize = B64ENCODE_OUT_SAFESIZE(
+ (cmd->arg1_len + 1));
+ char* b64Buf = g_malloc0(b64BufSize);
+ if (NULL == b64Buf) {
+ iotcon_remote_resource_destroy(resource_clone);
+ _clear_user_data(cmd);
+ return IOTCON_FUNC_CONTINUE;
+ }
+ b64Encode((const char *)cmd->arg1, cmd->arg1_len,
+ b64Buf, b64BufSize, &outSize);
+ b64Buf[b64BufSize] = '\0';
+ rep.setValue("data", b64Buf);
+ LOG_DEBUG("b64BufSize =%d outSize = %d b64Buf = %s",
+ b64BufSize, outSize, b64Buf);
+ g_free(b64Buf);
+#else
+ rep.setValue("data", cmd->arg1);
+#endif
+ }
+ resource->post(rep, QueryParamsMap(), _on_post);
+ }
}
+
+ g_free(resource_uri_path);
+ g_free(resource_host);
+ g_free(resource_type);
+ g_free(resource_device_id);
}
- else
- {
+ else {
LOG_ERR("Resource is invalid");
}
}
requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=" <<
comp_resource_get_type(resource_type);
+ auto found_cb = std::bind (&_found_resource, std::placeholders::_1,
+ cmd);
LOG_DEBUG("Querying for Resource");
- ret = OCPlatform::findResource("", requestURI.str(),
- CT_ADAPTER_IP,
- &_found_resource);
+ LOG_DEBUG("[Saurav] host address %s", cmd->host ? cmd->host : "NULL");
+ if (cmd) {
+ if (cmd->host)
+ ret = OCPlatform::findResource(cmd->host, requestURI.str(),
+ CT_ADAPTER_IP,
+ found_cb);
+ else
+ ret = OCPlatform::findResource("", requestURI.str(),
+ CT_ADAPTER_IP,
+ found_cb);
+ }
} catch (OCException &e) {
LOG_ERR("Failed to find resource %s", e.reason());
ret = e.code();