Просмотр исходного кода

flow: simplify implementation of flow interfaces

ambrop7 15 лет назад
Родитель
Сommit
a72cb44424

+ 12 - 44
flow/PacketPassInterface.c

@@ -24,58 +24,26 @@
 
 void _PacketPassInterface_job_operation (PacketPassInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len >= 0)
-    ASSERT(i->buf_len <= i->mtu)
-    ASSERT(i->handler_done)
+    ASSERT(i->state == PPI_STATE_OPERATION_PENDING)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_cancel);
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
     
-    // call operation handler
-    #ifndef NDEBUG
-    DebugIn_GoIn(&i->d_in_operation);
-    DEAD_ENTER(i->d_dead)
-    #endif
-    i->handler_operation(i->user_provider, i->buf, i->buf_len);
-    #ifndef NDEBUG
-    if (DEAD_LEAVE(i->d_dead)) {
-        return;
-    }
-    DebugIn_GoOut(&i->d_in_operation);
-    #endif
+    // set state
+    i->state = PPI_STATE_BUSY;
+    
+    // call handler
+    i->handler_operation(i->user_provider, i->job_operation_data, i->job_operation_len);
+    return;
 }
 
 void _PacketPassInterface_job_done (PacketPassInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len >= 0)
-    ASSERT(i->buf_len <= i->mtu)
-    ASSERT(i->handler_done)
+    ASSERT(i->state == PPI_STATE_DONE_PENDING)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_cancel);
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
     
-    #ifndef NDEBUG
-    i->d_user_busy = 0;
-    #endif
+    // set state
+    i->state = PPI_STATE_NONE;
     
-    // call done handler
-    #ifndef NDEBUG
-    DebugIn_GoIn(&i->d_in_done);
-    DEAD_ENTER(i->d_dead)
-    #endif
+    // call handler
     i->handler_done(i->user_user);
-    #ifndef NDEBUG
-    if (DEAD_LEAVE(i->d_dead)) {
-        return;
-    }
-    DebugIn_GoOut(&i->d_in_done);
-    #endif
+    return;
 }

+ 35 - 65
flow/PacketPassInterface.h

@@ -30,12 +30,15 @@
 #include <stdint.h>
 #include <stddef.h>
 
-#include <misc/dead.h>
 #include <misc/debug.h>
-#include <misc/debugin.h>
 #include <system/DebugObject.h>
 #include <system/BPending.h>
 
+#define PPI_STATE_NONE 1
+#define PPI_STATE_OPERATION_PENDING 2
+#define PPI_STATE_BUSY 3
+#define PPI_STATE_DONE_PENDING 4
+
 typedef void (*PacketPassInterface_handler_send) (void *user, uint8_t *data, int data_len);
 
 typedef void (*PacketPassInterface_handler_cancel) (void *user);
@@ -53,22 +56,18 @@ typedef struct {
     PacketPassInterface_handler_done handler_done;
     void *user_user;
     
-    // jobs
+    // operation job
     BPending job_operation;
+    uint8_t *job_operation_data;
+    int job_operation_len;
+    
+    // done job
     BPending job_done;
     
-    // packet supplied by user
-    uint8_t *buf;
-    int buf_len;
+    // state
+    int state;
     
     DebugObject d_obj;
-    #ifndef NDEBUG
-    DebugIn d_in_operation;
-    DebugIn d_in_cancel;
-    DebugIn d_in_done;
-    dead_t d_dead;
-    int d_user_busy;
-    #endif
 } PacketPassInterface;
 
 static void PacketPassInterface_Init (PacketPassInterface *i, int mtu, PacketPassInterface_handler_send handler_operation, void *user, BPendingGroup *pg);
@@ -109,21 +108,14 @@ void PacketPassInterface_Init (PacketPassInterface *i, int mtu, PacketPassInterf
     BPending_Init(&i->job_operation, pg, (BPending_handler)_PacketPassInterface_job_operation, i);
     BPending_Init(&i->job_done, pg, (BPending_handler)_PacketPassInterface_job_done, i);
     
+    // set state
+    i->state = PPI_STATE_NONE;
+    
     DebugObject_Init(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_Init(&i->d_in_operation);
-    DebugIn_Init(&i->d_in_cancel);
-    DebugIn_Init(&i->d_in_done);
-    DEAD_INIT(i->d_dead);
-    i->d_user_busy = 0;
-    #endif
 }
 
 void PacketPassInterface_Free (PacketPassInterface *i)
 {
-    #ifndef NDEBUG
-    DEAD_KILL(i->d_dead);
-    #endif
     DebugObject_Free(&i->d_obj);
     
     // free jobs
@@ -142,18 +134,14 @@ void PacketPassInterface_EnableCancel (PacketPassInterface *i, PacketPassInterfa
 
 void PacketPassInterface_Done (PacketPassInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len >= 0)
-    ASSERT(i->buf_len <= i->mtu)
-    ASSERT(i->handler_done)
-    ASSERT(!BPending_IsSet(&i->job_operation))
+    ASSERT(i->state == PPI_STATE_BUSY)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_cancel);
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
     
+    // schedule done
     BPending_Set(&i->job_done);
+    
+    // set state
+    i->state = PPI_STATE_DONE_PENDING;
 }
 
 int PacketPassInterface_GetMTU (PacketPassInterface *i)
@@ -178,55 +166,37 @@ void PacketPassInterface_Sender_Send (PacketPassInterface *i, uint8_t *data, int
     ASSERT(data_len >= 0)
     ASSERT(data_len <= i->mtu)
     ASSERT(!(data_len > 0) || data)
-    ASSERT(!i->d_user_busy)
+    ASSERT(i->state == PPI_STATE_NONE)
     ASSERT(i->handler_done)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_cancel);
-    #endif
-    
-    i->buf = data;
-    i->buf_len = data_len;
-    
-    #ifndef NDEBUG
-    i->d_user_busy = 1;
-    #endif
     
+    // schedule operation
+    i->job_operation_data = data;
+    i->job_operation_len = data_len;
     BPending_Set(&i->job_operation);
+    
+    // set state
+    i->state = PPI_STATE_OPERATION_PENDING;
 }
 
 void PacketPassInterface_Sender_Cancel (PacketPassInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len >= 0)
-    ASSERT(i->buf_len <= i->mtu)
+    ASSERT(i->state == PPI_STATE_OPERATION_PENDING || i->state == PPI_STATE_BUSY || i->state == PPI_STATE_DONE_PENDING)
     ASSERT(i->handler_cancel)
-    ASSERT(i->handler_done)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_cancel);
-    #endif
     
+    int prev_state = i->state;
+    
+    // unset jobs
     BPending_Unset(&i->job_operation);
     BPending_Unset(&i->job_done);
     
-    #ifndef NDEBUG
-    i->d_user_busy = 0;
-    #endif
+    // set state
+    i->state = PPI_STATE_NONE;
     
-    if (!BPending_IsSet(&i->job_operation) && !BPending_IsSet(&i->job_done)) {
-        #ifndef NDEBUG
-        DebugIn_GoIn(&i->d_in_cancel);
-        DEAD_ENTER(i->d_dead)
-        #endif
+    if (prev_state == PPI_STATE_BUSY) {
         i->handler_cancel(i->user_provider);
-        #ifndef NDEBUG
-        ASSERT(!DEAD_KILLED)
-        DEAD_LEAVE(i->d_dead);
-        DebugIn_GoOut(&i->d_in_cancel);
-        #endif
+        return;
     }
 }
 

+ 13 - 41
flow/PacketRecvInterface.c

@@ -24,54 +24,26 @@
 
 void _PacketRecvInterface_job_operation (PacketRecvInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->handler_done)
+    ASSERT(i->state == PRI_STATE_OPERATION_PENDING)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
     
-    // call operation handler
-    #ifndef NDEBUG
-    DebugIn_GoIn(&i->d_in_operation);
-    DEAD_ENTER(i->d_dead)
-    #endif
-    i->handler_operation(i->user_provider, i->buf);
-    #ifndef NDEBUG
-    if (DEAD_LEAVE(i->d_dead)) {
-        return;
-    }
-    DebugIn_GoOut(&i->d_in_operation);
-    #endif
+    // set state
+    i->state = PRI_STATE_BUSY;
+    
+    // call handler
+    i->handler_operation(i->user_provider, i->job_operation_data);
+    return;
 }
 
 void _PacketRecvInterface_job_done (PacketRecvInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->done_len >= 0)
-    ASSERT(i->done_len <= i->mtu)
-    ASSERT(i->handler_done)
+    ASSERT(i->state == PRI_STATE_DONE_PENDING)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
     
-    #ifndef NDEBUG
-    i->d_user_busy = 0;
-    #endif
+    // set state
+    i->state = PRI_STATE_NONE;
     
-    // call done handler
-    #ifndef NDEBUG
-    DebugIn_GoIn(&i->d_in_done);
-    DEAD_ENTER(i->d_dead)
-    #endif
-    i->handler_done(i->user_user, i->done_len);
-    #ifndef NDEBUG
-    if (DEAD_LEAVE(i->d_dead)) {
-        return;
-    }
-    DebugIn_GoOut(&i->d_in_done);
-    #endif
+    // call handler
+    i->handler_done(i->user_user, i->job_done_len);
+    return;
 }

+ 26 - 40
flow/PacketRecvInterface.h

@@ -30,12 +30,15 @@
 #include <stdint.h>
 #include <stddef.h>
 
-#include <misc/dead.h>
 #include <misc/debug.h>
-#include <misc/debugin.h>
 #include <system/DebugObject.h>
 #include <system/BPending.h>
 
+#define PRI_STATE_NONE 1
+#define PRI_STATE_OPERATION_PENDING 2
+#define PRI_STATE_BUSY 3
+#define PRI_STATE_DONE_PENDING 4
+
 typedef void (*PacketRecvInterface_handler_recv) (void *user, uint8_t *data);
 
 typedef void (*PacketRecvInterface_handler_done) (void *user, int data_len);
@@ -50,23 +53,18 @@ typedef struct {
     PacketRecvInterface_handler_done handler_done;
     void *user_user;
     
-    // jobs
+    // operation job
     BPending job_operation;
-    BPending job_done;
+    uint8_t *job_operation_data;
     
-    // buffer supplied by user
-    uint8_t *buf;
+    // done job
+    BPending job_done;
+    int job_done_len;
     
-    // length supplied by done
-    int done_len;
+    // state
+    int state;
     
     DebugObject d_obj;
-    #ifndef NDEBUG
-    DebugIn d_in_operation;
-    DebugIn d_in_done;
-    dead_t d_dead;
-    int d_user_busy;
-    #endif
 } PacketRecvInterface;
 
 static void PacketRecvInterface_Init (PacketRecvInterface *i, int mtu, PacketRecvInterface_handler_recv handler_operation, void *user, BPendingGroup *pg);
@@ -100,20 +98,14 @@ void PacketRecvInterface_Init (PacketRecvInterface *i, int mtu, PacketRecvInterf
     BPending_Init(&i->job_operation, pg, (BPending_handler)_PacketRecvInterface_job_operation, i);
     BPending_Init(&i->job_done, pg, (BPending_handler)_PacketRecvInterface_job_done, i);
     
+    // set state
+    i->state = PRI_STATE_NONE;
+    
     DebugObject_Init(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_Init(&i->d_in_operation);
-    DebugIn_Init(&i->d_in_done);
-    DEAD_INIT(i->d_dead);
-    i->d_user_busy = 0;
-    #endif
 }
 
 void PacketRecvInterface_Free (PacketRecvInterface *i)
 {
-    #ifndef NDEBUG
-    DEAD_KILL(i->d_dead);
-    #endif
     DebugObject_Free(&i->d_obj);
     
     // free jobs
@@ -125,17 +117,15 @@ void PacketRecvInterface_Done (PacketRecvInterface *i, int data_len)
 {
     ASSERT(data_len >= 0)
     ASSERT(data_len <= i->mtu)
-    ASSERT(i->d_user_busy)
-    ASSERT(i->handler_done)
-    ASSERT(!BPending_IsSet(&i->job_operation))
+    ASSERT(i->state == PRI_STATE_BUSY)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
-    
-    i->done_len = data_len;
     
+    // schedule done
+    i->job_done_len = data_len;
     BPending_Set(&i->job_done);
+    
+    // set state
+    i->state = PRI_STATE_DONE_PENDING;
 }
 
 int PacketRecvInterface_GetMTU (PacketRecvInterface *i)
@@ -158,20 +148,16 @@ void PacketRecvInterface_Receiver_Init (PacketRecvInterface *i, PacketRecvInterf
 void PacketRecvInterface_Receiver_Recv (PacketRecvInterface *i, uint8_t *data)
 {
     ASSERT(!(i->mtu > 0) || data)
-    ASSERT(!i->d_user_busy)
+    ASSERT(i->state == PRI_STATE_NONE)
     ASSERT(i->handler_done)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    #endif
     
+    // schedule operation
+    i->job_operation_data = data;
     BPending_Set(&i->job_operation);
     
-    i->buf = data;
-    
-    #ifndef NDEBUG
-    i->d_user_busy = 1;
-    #endif
+    // set state
+    i->state = PRI_STATE_OPERATION_PENDING;
 }
 
 #endif

+ 13 - 43
flow/StreamPassInterface.c

@@ -24,56 +24,26 @@
 
 void _StreamPassInterface_job_operation (StreamPassInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len > 0)
-    ASSERT(i->handler_done)
+    ASSERT(i->state == SPI_STATE_OPERATION_PENDING)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
     
-    // call operation handler
-    #ifndef NDEBUG
-    DebugIn_GoIn(&i->d_in_operation);
-    DEAD_ENTER(i->d_dead)
-    #endif
-    i->handler_operation(i->user_provider, i->buf, i->buf_len);
-    #ifndef NDEBUG
-    if (DEAD_LEAVE(i->d_dead)) {
-        return;
-    }
-    DebugIn_GoOut(&i->d_in_operation);
-    #endif
+    // set state
+    i->state = SPI_STATE_BUSY;
+    
+    // call handler
+    i->handler_operation(i->user_provider, i->job_operation_data, i->job_operation_len);
+    return;
 }
 
 void _StreamPassInterface_job_done (StreamPassInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len > 0)
-    ASSERT(i->done_len > 0)
-    ASSERT(i->done_len <= i->buf_len)
-    ASSERT(i->handler_done)
+    ASSERT(i->state == SPI_STATE_DONE_PENDING)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
     
-    #ifndef NDEBUG
-    i->d_user_busy = 0;
-    #endif
+    // set state
+    i->state = SPI_STATE_NONE;
     
-    // call done handler
-    #ifndef NDEBUG
-    DebugIn_GoIn(&i->d_in_done);
-    DEAD_ENTER(i->d_dead)
-    #endif
-    i->handler_done(i->user_user, i->done_len);
-    #ifndef NDEBUG
-    if (DEAD_LEAVE(i->d_dead)) {
-        return;
-    }
-    DebugIn_GoOut(&i->d_in_done);
-    #endif
+    // call handler
+    i->handler_done(i->user_user, i->job_done_len);
+    return;
 }

+ 30 - 45
flow/StreamPassInterface.h

@@ -35,12 +35,15 @@
 #include <stdint.h>
 #include <stddef.h>
 
-#include <misc/dead.h>
 #include <misc/debug.h>
-#include <misc/debugin.h>
 #include <system/DebugObject.h>
 #include <system/BPending.h>
 
+#define SPI_STATE_NONE 1
+#define SPI_STATE_OPERATION_PENDING 2
+#define SPI_STATE_BUSY 3
+#define SPI_STATE_DONE_PENDING 4
+
 typedef void (*StreamPassInterface_handler_send) (void *user, uint8_t *data, int data_len);
 
 typedef void (*StreamPassInterface_handler_done) (void *user, int data_len);
@@ -54,24 +57,19 @@ typedef struct {
     StreamPassInterface_handler_done handler_done;
     void *user_user;
     
-    // jobs
+    // operation job
     BPending job_operation;
-    BPending job_done;
+    uint8_t *job_operation_data;
+    int job_operation_len;
     
-    // packet supplied by user
-    uint8_t *buf;
-    int buf_len;
+    // done job
+    BPending job_done;
+    int job_done_len;
     
-    // length supplied by done
-    int done_len;
+    // state
+    int state;
     
     DebugObject d_obj;
-    #ifndef NDEBUG
-    DebugIn d_in_operation;
-    DebugIn d_in_done;
-    dead_t d_dead;
-    int d_user_busy;
-    #endif
 } StreamPassInterface;
 
 static void StreamPassInterface_Init (StreamPassInterface *i, StreamPassInterface_handler_send handler_operation, void *user, BPendingGroup *pg);
@@ -100,20 +98,14 @@ void StreamPassInterface_Init (StreamPassInterface *i, StreamPassInterface_handl
     BPending_Init(&i->job_operation, pg, (BPending_handler)_StreamPassInterface_job_operation, i);
     BPending_Init(&i->job_done, pg, (BPending_handler)_StreamPassInterface_job_done, i);
     
+    // set state
+    i->state = SPI_STATE_NONE;
+    
     DebugObject_Init(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_Init(&i->d_in_operation);
-    DebugIn_Init(&i->d_in_done);
-    DEAD_INIT(i->d_dead);
-    i->d_user_busy = 0;
-    #endif
 }
 
 void StreamPassInterface_Free (StreamPassInterface *i)
 {
-    #ifndef NDEBUG
-    DEAD_KILL(i->d_dead);
-    #endif
     DebugObject_Free(&i->d_obj);
     
     // free jobs
@@ -123,20 +115,17 @@ void StreamPassInterface_Free (StreamPassInterface *i)
 
 void StreamPassInterface_Done (StreamPassInterface *i, int data_len)
 {
+    ASSERT(i->state == SPI_STATE_BUSY)
     ASSERT(data_len > 0)
-    ASSERT(data_len <= i->buf_len)
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len > 0)
-    ASSERT(i->handler_done)
-    ASSERT(!BPending_IsSet(&i->job_operation))
+    ASSERT(data_len <= i->job_operation_len)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
-    
-    i->done_len = data_len;
     
+    // schedule done
+    i->job_done_len = data_len;
     BPending_Set(&i->job_done);
+    
+    // set state
+    i->state = SPI_STATE_DONE_PENDING;
 }
 
 void StreamPassInterface_Sender_Init (StreamPassInterface *i, StreamPassInterface_handler_done handler_done, void *user)
@@ -153,21 +142,17 @@ void StreamPassInterface_Sender_Send (StreamPassInterface *i, uint8_t *data, int
 {
     ASSERT(data_len > 0)
     ASSERT(data)
-    ASSERT(!i->d_user_busy)
+    ASSERT(i->state == SPI_STATE_NONE)
     ASSERT(i->handler_done)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    #endif
-    
-    i->buf = data;
-    i->buf_len = data_len;
-    
-    #ifndef NDEBUG
-    i->d_user_busy = 1;
-    #endif
     
+    // schedule operation
+    i->job_operation_data = data;
+    i->job_operation_len = data_len;
     BPending_Set(&i->job_operation);
+    
+    // set state
+    i->state = SPI_STATE_OPERATION_PENDING;
 }
 
 #endif

+ 13 - 43
flow/StreamRecvInterface.c

@@ -24,56 +24,26 @@
 
 void _StreamRecvInterface_job_operation (StreamRecvInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len > 0)
-    ASSERT(i->handler_done)
+    ASSERT(i->state == SRI_STATE_OPERATION_PENDING)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
     
-    // call operation handler
-    #ifndef NDEBUG
-    DebugIn_GoIn(&i->d_in_operation);
-    DEAD_ENTER(i->d_dead)
-    #endif
-    i->handler_operation(i->user_provider, i->buf, i->buf_len);
-    #ifndef NDEBUG
-    if (DEAD_LEAVE(i->d_dead)) {
-        return;
-    }
-    DebugIn_GoOut(&i->d_in_operation);
-    #endif
+    // set state
+    i->state = SRI_STATE_BUSY;
+    
+    // call handler
+    i->handler_operation(i->user_provider, i->job_operation_data, i->job_operation_len);
+    return;
 }
 
 void _StreamRecvInterface_job_done (StreamRecvInterface *i)
 {
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len > 0)
-    ASSERT(i->done_len > 0)
-    ASSERT(i->done_len <= i->buf_len)
-    ASSERT(i->handler_done)
+    ASSERT(i->state == SRI_STATE_DONE_PENDING)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
     
-    #ifndef NDEBUG
-    i->d_user_busy = 0;
-    #endif
+    // set state
+    i->state = SRI_STATE_NONE;
     
-    // call done handler
-    #ifndef NDEBUG
-    DebugIn_GoIn(&i->d_in_done);
-    DEAD_ENTER(i->d_dead)
-    #endif
-    i->handler_done(i->user_user, i->done_len);
-    #ifndef NDEBUG
-    if (DEAD_LEAVE(i->d_dead)) {
-        return;
-    }
-    DebugIn_GoOut(&i->d_in_done);
-    #endif
+    // call handler
+    i->handler_done(i->user_user, i->job_done_len);
+    return;
 }

+ 32 - 47
flow/StreamRecvInterface.h

@@ -24,8 +24,8 @@
  * Interface allowing a stream receiver to receive stream data from a stream sender.
  * 
  * Note that this interface behaves exactly the same and has the same code as
- * {@link StreamRecvInterface} if names and its external semantics are disregarded.
- * If you modify this file, you should probably modify {@link StreamRecvInterface}
+ * {@link StreamPassInterface} if names and its external semantics are disregarded.
+ * If you modify this file, you should probably modify {@link StreamPassInterface}
  * too.
  */
 
@@ -35,12 +35,15 @@
 #include <stdint.h>
 #include <stddef.h>
 
-#include <misc/dead.h>
 #include <misc/debug.h>
-#include <misc/debugin.h>
 #include <system/DebugObject.h>
 #include <system/BPending.h>
 
+#define SRI_STATE_NONE 1
+#define SRI_STATE_OPERATION_PENDING 2
+#define SRI_STATE_BUSY 3
+#define SRI_STATE_DONE_PENDING 4
+
 typedef void (*StreamRecvInterface_handler_recv) (void *user, uint8_t *data, int data_len);
 
 typedef void (*StreamRecvInterface_handler_done) (void *user, int data_len);
@@ -54,24 +57,19 @@ typedef struct {
     StreamRecvInterface_handler_done handler_done;
     void *user_user;
     
-    // jobs
+    // operation job
     BPending job_operation;
-    BPending job_done;
+    uint8_t *job_operation_data;
+    int job_operation_len;
     
-    // packet supplied by user
-    uint8_t *buf;
-    int buf_len;
+    // done job
+    BPending job_done;
+    int job_done_len;
     
-    // length supplied by done
-    int done_len;
+    // state
+    int state;
     
     DebugObject d_obj;
-    #ifndef NDEBUG
-    DebugIn d_in_operation;
-    DebugIn d_in_done;
-    dead_t d_dead;
-    int d_user_busy;
-    #endif
 } StreamRecvInterface;
 
 static void StreamRecvInterface_Init (StreamRecvInterface *i, StreamRecvInterface_handler_recv handler_operation, void *user, BPendingGroup *pg);
@@ -100,20 +98,14 @@ void StreamRecvInterface_Init (StreamRecvInterface *i, StreamRecvInterface_handl
     BPending_Init(&i->job_operation, pg, (BPending_handler)_StreamRecvInterface_job_operation, i);
     BPending_Init(&i->job_done, pg, (BPending_handler)_StreamRecvInterface_job_done, i);
     
+    // set state
+    i->state = SRI_STATE_NONE;
+    
     DebugObject_Init(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_Init(&i->d_in_operation);
-    DebugIn_Init(&i->d_in_done);
-    DEAD_INIT(i->d_dead);
-    i->d_user_busy = 0;
-    #endif
 }
 
 void StreamRecvInterface_Free (StreamRecvInterface *i)
 {
-    #ifndef NDEBUG
-    DEAD_KILL(i->d_dead);
-    #endif
     DebugObject_Free(&i->d_obj);
     
     // free jobs
@@ -123,20 +115,17 @@ void StreamRecvInterface_Free (StreamRecvInterface *i)
 
 void StreamRecvInterface_Done (StreamRecvInterface *i, int data_len)
 {
+    ASSERT(i->state == SRI_STATE_BUSY)
     ASSERT(data_len > 0)
-    ASSERT(data_len <= i->buf_len)
-    ASSERT(i->d_user_busy)
-    ASSERT(i->buf_len > 0)
-    ASSERT(i->handler_done)
-    ASSERT(!BPending_IsSet(&i->job_operation))
+    ASSERT(data_len <= i->job_operation_len)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_done);
-    #endif
-    
-    i->done_len = data_len;
     
+    // schedule done
+    i->job_done_len = data_len;
     BPending_Set(&i->job_done);
+    
+    // set state
+    i->state = SRI_STATE_DONE_PENDING;
 }
 
 void StreamRecvInterface_Receiver_Init (StreamRecvInterface *i, StreamRecvInterface_handler_done handler_done, void *user)
@@ -153,21 +142,17 @@ void StreamRecvInterface_Receiver_Recv (StreamRecvInterface *i, uint8_t *data, i
 {
     ASSERT(data_len > 0)
     ASSERT(data)
-    ASSERT(!i->d_user_busy)
+    ASSERT(i->state == SRI_STATE_NONE)
     ASSERT(i->handler_done)
     DebugObject_Access(&i->d_obj);
-    #ifndef NDEBUG
-    DebugIn_AmOut(&i->d_in_operation);
-    #endif
-    
-    i->buf = data;
-    i->buf_len = data_len;
-    
-    #ifndef NDEBUG
-    i->d_user_busy = 1;
-    #endif
     
+    // schedule operation
+    i->job_operation_data = data;
+    i->job_operation_len = data_len;
     BPending_Set(&i->job_operation);
+    
+    // set state
+    i->state = SRI_STATE_OPERATION_PENDING;
 }
 
 #endif