void createResources() { light.state = false; OCResourceHandle fan; OCStackResult res = OCCreateResource(&fan, "core.fan", "oc.mi.def", "/a/fan", OCEntityHandlerFanCb, OC_DISCOVERABLE|OC_OBSERVABLE); OC_LOG_V(INFO, TAG, "Created fan resource with result: %s", getResult(res)); OCResourceHandle light; res = OCCreateResource(&light, "core.light", "oc.mi.def", "/a/light", OCEntityHandlerLightCb, OC_DISCOVERABLE|OC_OBSERVABLE); OC_LOG_V(INFO, TAG, "Created light resource with result: %s", getResult(res)); OCResourceHandle room; if(TEST == TEST_APP_COLL_EH) { res = OCCreateResource(&room, "core.room", "oc.mi.b", "/a/room", OCEntityHandlerRoomCb, OC_DISCOVERABLE); } else { res = OCCreateResource(&room, "core.room", "oc.mi.b", "/a/room", NULL, OC_DISCOVERABLE); } OC_LOG_V(INFO, TAG, "Created room resource with result: %s", getResult(res)); OCBindResourceInterfaceToResource(room, "oc.mi.ll"); OCBindResourceInterfaceToResource(room, "oc.mi.def"); res = OCBindResource(room, light); OC_LOG_V(INFO, TAG, "OC Bind Contained Resource to resource: %s", getResult(res)); res = OCBindResource(room, fan); OC_LOG_V(INFO, TAG, "OC Bind Contained Resource to resource: %s", getResult(res)); }
void things_bind(struct things_resource_s *res, struct things_resource_s *bind) { if (res == NULL || bind == NULL) { THINGS_LOG_E(TAG, "Invalid Resource"); return; } if (res->resource_handle == bind->resource_handle) { THINGS_LOG_D(TAG, "It's identical resource"); return; } iotivity_api_lock(); OCStackResult ret = OCBindResource((OCResourceHandle)(res->resource_handle), (OCResourceHandle)(bind->resource_handle)); iotivity_api_unlock(); if (ret != OC_STACK_OK) { THINGS_LOG_V(TAG, "bind Failed "); } }