mrp_res_string_array_t * mrp_res_list_attribute_names(mrp_res_context_t *cx, const mrp_res_resource_t *res) { int i; mrp_res_string_array_t *ret; if (!cx || !res) return NULL; ret = mrp_allocz(sizeof(mrp_res_string_array_t)); if (!ret) return NULL; ret->num_strings = res->priv->num_attributes; ret->strings = mrp_allocz_array(const char *, res->priv->num_attributes); if (!ret->strings) { mrp_free(ret); return NULL; } for (i = 0; i < res->priv->num_attributes; i++) { ret->strings[i] = mrp_strdup(res->priv->attrs[i].name); if (!ret->strings[i]) { ret->num_strings = i; mrp_res_free_string_array(ret); return NULL; } } return ret; }
mrp_res_string_array_t *class_query_response(mrp_msg_t *msg, void **pcursor) { int status; mrp_res_string_array_t *arr = NULL; if (!fetch_status(msg, pcursor, &status) || (status == 0 && !fetch_mrp_str_array(msg, pcursor, RESPROTO_CLASS_NAME, &arr))) { mrp_log_error("ignoring malformed response to class query"); return NULL; } if (status) { mrp_log_error("class query failed with error code %u", status); mrp_res_free_string_array(arr); return NULL; } return arr; }
static void state_callback(mrp_res_context_t *context, mrp_res_error_t err, void *userdata) { int i = 0, j = 0; const mrp_res_string_array_t *app_classes = NULL; const mrp_res_resource_set_t *rs; mrp_res_string_array_t *attributes = NULL; mrp_res_attribute_t *attr; bool system_handles_audio = FALSE; bool system_handles_video = FALSE; mrp_res_resource_t *resource; my_app_data *app_data = (my_app_data *) userdata; if (err != MRP_RES_ERROR_NONE) { printf("error message received from Murphy\n"); return; } switch (context->state) { case MRP_RES_CONNECTED: printf("connected to murphy\n"); if ((app_classes = mrp_res_list_application_classes(context)) != NULL) { printf("listing all application classes in the system\n"); for (i = 0; i < app_classes->num_strings; i++) { printf("app class %d is %s\n", i, app_classes->strings[i]); } } if ((rs = mrp_res_list_resources(context)) != NULL) { mrp_res_string_array_t *resource_names; printf("listing all resources available in the system\n"); resource_names = mrp_res_list_resource_names(rs); if (!resource_names) { printf("No resources available in the system!\n"); return; } for (i = 0; i < resource_names->num_strings; i++) { resource = mrp_res_get_resource_by_name(rs, resource_names->strings[i]); if (!resource) continue; printf("resource %d is %s\n", i, resource->name); if (strcmp(resource->name, "audio_playback") == 0) system_handles_audio = TRUE; if (strcmp(resource->name, "video_playback") == 0) system_handles_video = TRUE; attributes = mrp_res_list_attribute_names(resource); if (!attributes) continue; for (j = 0; j < attributes->num_strings; j++) { attr = mrp_res_get_attribute_by_name(resource, attributes->strings[j]); if (!attr) continue; printf("attr %s has ", attr->name); switch(attr->type) { case mrp_string: printf("type string and value %s\n", attr->string); break; case mrp_int32: printf("type int32 and value %d\n", (int) attr->integer); break; case mrp_uint32: printf("type uint32 and value %u\n", attr->unsignd); break; case mrp_double: printf("type double and value %f\n", attr->floating); break; default: printf("type unknown\n"); break; } } mrp_res_free_string_array(attributes); } mrp_res_free_string_array(resource_names); } if (system_handles_audio && system_handles_video) { printf("system provides all necessary resources\n"); accept_input = TRUE; } break; case MRP_RES_DISCONNECTED: printf("disconnected from murphy\n"); mrp_res_delete_resource_set(app_data->rs); mrp_res_destroy(app_data->cx); exit(1); } }