1/*
2 * Copyright (c) 2009, 2010, 2011, 2012, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 *
9 * A simple sorted linked list for pending flounder RPC messages in the sm backend.
10 * Because there is no obvious correspondence between RPC calls and replies,
11 * but we have continuations to call after we get the reply,
12 * we keep track of them ourselves.
13 * All our flounder RPC calls and replies contain a transaction id, which is used
14 * to look up the correct callback on receiving a RPC reply.
15 *
16 * using a linked list should be more than enough, since we don't expect many concurrent
17 * pending messages.
18 * the list is sorted to prevent duplicate keys
19 */
20
21#ifndef BULK_SM_PENDING_MSG_H
22#define BULK_SM_PENDING_MSG_H
23
24#include <barrelfish/barrelfish.h>
25#include "bulk_sm_impl.h"
26
27//RPC-specific content
28struct pending_assign_pool {
29        struct bulk_continuation continuation;  ///< continuation after completion
30        struct bulk_channel      *channel;      ///< channel under consideration XXX: probably unnecessary
31        struct bulk_pool         *pool;         ///< pool to be added to channel
32};
33
34struct pending_bind {
35        struct bulk_continuation continuation;  ///< continuation after completion
36        errval_t                 bind_error;
37};
38
39struct pending_move {
40        struct bulk_continuation continuation;  ///< continuation after completion
41};
42
43struct pending_copy {
44        struct bulk_continuation continuation;  ///< continuation after completion
45};
46
47struct pending_pass {
48        struct bulk_continuation continuation;  ///< continuation after completion
49};
50
51struct pending_release {
52        struct bulk_continuation continuation;  ///< continuation after completion
53};
54
55union pending_msg_data {
56    struct pending_assign_pool  assign_pool;
57    struct pending_bind         bind;
58    struct pending_move         move;
59    struct pending_copy         copy;
60    struct pending_pass         pass;
61    struct pending_release      release;
62};
63
64
65struct bulk_sm_pending_msg{
66    uint32_t                        tid;        //key
67    struct bulk_sm_pending_msg      *next;      //rest of list (bigger keys)
68    struct bulk_sm_pending_msg      *previous;  //rest of list (smaller keys)
69    union pending_msg_data          data;       //payload
70};
71
72/**
73 * add the data to the tree of pending messages in channel
74 * generates tid automatically
75 *
76 * @param channel:  Channel this message belongs to
77 * @param tid:      will be filled in with transaction id
78 * @param data:     payload for this message
79 */
80errval_t pending_msg_add(struct bulk_channel* channel,
81                         uint32_t *tid,
82                         union pending_msg_data data);
83
84/**
85 * reads pending message
86 *
87 * @param channel:  Channel this message belongs to
88 * @param tid:      transaction id to look up
89 * @param data:     will be filled in with payload for this message
90 * @param remove:   whether item is to be removed from list
91 */
92errval_t pending_msg_get(struct bulk_channel     *channel,
93                         uint32_t                tid,
94                         union pending_msg_data  *data,
95                         bool                    remove);
96
97#endif // BULK_SM_PENDING_MSG_H
98