aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2023-08-10 10:20:37 +0900
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>2023-10-07 11:42:33 +0900
commit886f2ff495ed094a21553a9ec5db4448595e55ec (patch)
treed4fa8a6da9c2fe4e9fb2b49e3d640152af73eeb5
parent02bce99f15d723fe27de02229f0e34c54215404f (diff)
downloadlibhinawa-886f2ff495ed094a21553a9ec5db4448595e55ec.tar.gz
fw_fcp: use enumeration for state of transaction
This commit adds an enumeration to express the state of transaction to obsolete the check of first byte in response buffer for the state. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_fcp.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/fw_fcp.c b/src/fw_fcp.c
index 2411527..9d8ac84 100644
--- a/src/fw_fcp.c
+++ b/src/fw_fcp.c
@@ -275,7 +275,13 @@ gboolean hinawa_fw_fcp_command(HinawaFwFcp *self, const guint8 *cmd, gsize cmd_s
return hinawa_fw_fcp_command_with_tstamp(self, cmd, cmd_size, tstamp, timeout_ms, error);
}
+enum waiter_state {
+ WAITER_STATE_PENDING = 0,
+ WAITER_STATE_RESPONDED,
+};
+
struct waiter {
+ enum waiter_state state;
guint8 *frame;
guint frame_size;
guint tstamp;
@@ -299,6 +305,7 @@ static void handle_responded_signal(HinawaFwFcp *self, guint tstamp, const guint
g_mutex_lock(&w->mutex);
if (w->frame[1] == frame[1] && w->frame[2] == frame[2]) {
+ w->state = WAITER_STATE_RESPONDED;
w->tstamp = tstamp;
if (frame_size <= w->frame_size)
@@ -363,6 +370,7 @@ gboolean hinawa_fw_fcp_avc_transaction_with_tstamp(HinawaFwFcp *self,
priv = hinawa_fw_fcp_get_instance_private(self);
+ w.state = WAITER_STATE_PENDING;
w.frame = *resp;
w.frame_size = *resp_size;
w.tstamp = G_MAXUINT;
@@ -392,7 +400,7 @@ gboolean hinawa_fw_fcp_avc_transaction_with_tstamp(HinawaFwFcp *self,
goto end;
}
deferred:
- while (w.frame[0] == 0xff) {
+ while (w.state == WAITER_STATE_PENDING) {
// NOTE: Timeout at bus-reset, illegally.
if (!g_cond_wait_until(&w.cond, &w.mutex, expiration))
break;
@@ -400,6 +408,7 @@ deferred:
// It's a deffered transaction, wait again.
if (w.frame[0] == AVC_STATUS_INTERIM) {
+ w.state = WAITER_STATE_PENDING;
w.frame[0] = 0x00;
w.frame_size = *resp_size;
// Although the timeout is infinite in 1394 TA specification,
@@ -414,15 +423,21 @@ deferred:
g_signal_handler_disconnect(self, responded_handler_id);
g_mutex_unlock(&w.mutex);
- if (w.frame[0] == 0xff) {
+ switch (w.state) {
+ case WAITER_STATE_RESPONDED:
+ if (w.frame_size > *resp_size) {
+ generate_local_error(error, HINAWA_FW_FCP_ERROR_LARGE_RESP);
+ result = FALSE;
+ } else {
+ *resp_size = w.frame_size;
+ tstamp[2] = w.tstamp;
+ }
+ break;
+ case WAITER_STATE_PENDING:
+ default:
generate_local_error(error, HINAWA_FW_FCP_ERROR_TIMEOUT);
result = FALSE;
- } else if (w.frame_size > *resp_size) {
- generate_local_error(error, HINAWA_FW_FCP_ERROR_LARGE_RESP);
- result = FALSE;
- } else {
- *resp_size = w.frame_size;
- tstamp[2] = w.tstamp;
+ break;
}
end:
g_cond_clear(&w.cond);