Reduce nesting depth in new_handle dispatchers

Signed-off-by: Dan Dennedy <dan@dennedy.org>
This commit is contained in:
Stefan Richter 2008-10-18 01:25:01 +02:00 committed by Dan Dennedy
parent d080bb3d83
commit 0bf8132319
1 changed files with 45 additions and 43 deletions

View File

@ -24,38 +24,37 @@ int raw1394_errcode_to_errno(raw1394_errcode_t errcode)
raw1394handle_t raw1394_new_handle(void) raw1394handle_t raw1394_new_handle(void)
{ {
ieee1394handle_t ieee1394_handle = ieee1394_new_handle(); ieee1394handle_t ieee1394_handle;
fw_handle_t fw_handle = NULL; fw_handle_t fw_handle;
raw1394handle_t handle = NULL; raw1394handle_t handle;
if (ieee1394_handle) {
struct raw1394_portinfo port; struct raw1394_portinfo port;
if (ieee1394_get_port_info(ieee1394_handle, &port, 1) < 1) {
ieee1394_destroy_handle(ieee1394_handle);
ieee1394_handle = NULL;
fw_handle = fw_new_handle();
}
}
else {
fw_handle = fw_new_handle();
}
if (ieee1394_handle || fw_handle) {
handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle)); handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle));
if (ieee1394_handle && handle) { if (!handle)
return NULL;
ieee1394_handle = ieee1394_new_handle();
if (!ieee1394_handle)
goto try_fw;
if (ieee1394_get_port_info(ieee1394_handle, &port, 1) >= 1) {
handle->is_fw = 0; handle->is_fw = 0;
handle->mode.ieee1394 = ieee1394_handle; handle->mode.ieee1394 = ieee1394_handle;
return handle;
} }
else if (handle) { ieee1394_destroy_handle(ieee1394_handle);
try_fw:
fw_handle = fw_new_handle();
if (fw_handle) {
handle->is_fw = 1; handle->is_fw = 1;
handle->mode.fw = fw_handle; handle->mode.fw = fw_handle;
} else if (fw_handle)
fw_destroy_handle(fw_handle);
else if (ieee1394_handle)
ieee1394_destroy_handle(ieee1394_handle);
}
return handle; return handle;
} }
free(handle);
return NULL;
}
void raw1394_destroy_handle(raw1394handle_t handle) void raw1394_destroy_handle(raw1394handle_t handle)
{ {
if (!handle) { if (!handle) {
@ -70,29 +69,32 @@ void raw1394_destroy_handle(raw1394handle_t handle)
raw1394handle_t raw1394_new_handle_on_port(int port) raw1394handle_t raw1394_new_handle_on_port(int port)
{ {
ieee1394handle_t ieee1394_handle = ieee1394_new_handle_on_port(port); ieee1394handle_t ieee1394_handle;
fw_handle_t fw_handle; fw_handle_t fw_handle;
raw1394handle_t handle = NULL; raw1394handle_t handle;
if (ieee1394_handle) {
handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle)); handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle));
if (handle) { if (!handle)
return NULL;
ieee1394_handle = ieee1394_new_handle_on_port(port);
if (ieee1394_handle) {
handle->is_fw = 0; handle->is_fw = 0;
handle->mode.ieee1394 = ieee1394_handle; handle->mode.ieee1394 = ieee1394_handle;
} else return handle;
ieee1394_destroy_handle(ieee1394_handle);
} }
else if ((fw_handle = fw_new_handle_on_port(port))) {
handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle)); fw_handle = fw_new_handle_on_port(port);
if (handle) { if (fw_handle) {
handle->is_fw = 1; handle->is_fw = 1;
handle->mode.fw = fw_handle; handle->mode.fw = fw_handle;
} else
fw_destroy_handle(fw_handle);
}
return handle; return handle;
} }
free(handle);
return NULL;
}
int raw1394_busreset_notify (raw1394handle_t handle, int off_on_switch) int raw1394_busreset_notify (raw1394handle_t handle, int off_on_switch)
{ {
if (!handle) { if (!handle) {