mrp_htbl_t *sets;
uint32_t n_sets;
uint32_t current_handle;
+
+ bool monitor; /* if the client has set up a monitor resource */
} client_t;
/* mutable */
request_type_t rtype;
+
+ bool monitor;
+ bool earjack;
} resource_set_data_t;
mrp_get_resource_set_advice(d->rset),
mrp_get_resource_set_grant(d->rset));
-
switch(d->rtype) {
case request_type_acquire:
{
reply.handle = d->handle;
reply.callback_expected = FALSE;
+ /* TODO: get the client and see if there is the monitor
+ * resource present. If yes, tell the availability state changes
+ * through it. */
+
+ /* TODO: check if the d->rset state has actually changed */
+
if (mrp_get_resource_set_grant(d->rset))
reply.sound_command = ASM_COMMAND_PLAY;
else
shared = FALSE;
break;
case ASM_EVENT_EARJACK_UNPLUG:
- mrp_log_info("earjack unplug event");
- resource = "player";
+ resource = "earjack";
shared = TRUE;
break;
case ASM_EVENT_ALARM:
shared = FALSE;
break;
case ASM_EVENT_MONITOR:
- mrp_log_info("monitor request");
- resource = "player";
+ resource = "monitor";
shared = TRUE;
break;
case ASM_EVENT_RICH_CALL:
mrp_log_error("unknown resource type: %d", msg->sound_event);
goto error;
}
-
else {
uint32_t handle = client->current_handle++;
- mrp_resource_set_t *set;
resource_set_data_t *d = mrp_allocz(sizeof(resource_set_data_t));
d->handle = handle;
d->rtype = request_type_server_event;
d->request_id = 0;
- set = mrp_resource_set_create(ctx->resource_client, 0, 0,
- event_cb, d);
-
- if (!set) {
- mrp_log_error("Failed to create resource set!");
- goto error;
+ if (strcmp(resource, "earjack") == 0) {
+ mrp_log_info("earjack status request was received");
+ d->earjack = TRUE;
+ }
+ else if (strcmp(resource, "monitor") == 0) {
+ mrp_log_info("monitor resource was received");
+ /* TODO: tell the available state changes to this pid
+ * via the monitor resource. */
+ client->monitor = TRUE;
+ d->monitor = TRUE;
}
+ else {
+ /* a normal resource request */
+
+ d->rset = mrp_resource_set_create(ctx->resource_client, 0,
+ 0, event_cb, d);
+
+ if (!d->rset) {
+ mrp_log_error("Failed to create resource set!");
+ goto error;
+ }
- d->rset = set;
+ if (mrp_resource_set_add_resource(d->rset,
+ ctx->playback_resource, shared, NULL, TRUE) < 0) {
+ mrp_log_error("Failed to add playback resource!");
+ mrp_resource_set_destroy(d->rset);
+ mrp_free(d);
+ goto error;
+ }
- mrp_resource_set_add_resource(set, ctx->playback_resource, shared, NULL, TRUE);
- mrp_resource_set_add_resource(set, ctx->recording_resource, shared, NULL, TRUE);
+ if (mrp_resource_set_add_resource(d->rset,
+ ctx->recording_resource, shared, NULL, TRUE) < 0) {
+ mrp_log_error("Failed to add recording resource!");
+ mrp_resource_set_destroy(d->rset);
+ mrp_free(d);
+ goto error;
+ }
- mrp_application_class_add_resource_set(resource, ctx->zone, set, 0);
+ if (mrp_application_class_add_resource_set(resource,
+ ctx->zone, d->rset, 0) < 0) {
+ mrp_log_error("Failed to put the rset in a class!");
+ mrp_resource_set_destroy(d->rset);
+ mrp_free(d);
+ goto error;
+ }
+ }
mrp_htbl_insert(client->sets, u_to_p(handle), d);
client->n_sets++;
goto error;
}
+ if (!d->rset) {
+ /* this is a resource request with no associated
+ * murphy resource, meaning a monitor or earjack. */
+
+ if (d->monitor)
+ client->monitor = FALSE;
+
+ /* TODO: what to do with the earjack unregister case? */
+ }
+
/* the resource set id destroyed when it's removed from the
* table */
mrp_htbl_remove(client->sets, u_to_p(msg->handle), TRUE);
return reply;
error:
+ /* TODO: need to write some sort of message back? */
+
noreply:
mrp_free(reply);